vue模糊搜索
关键代码如下:
<el-input placeholder="请输入关键信息" v-model="keyword" class="input-with-select" @keyup.enter.native="findKey"
clearable @change="getCompany()">
<!-- @change="pageNum=1,getCompany()" -->
<el-button class="icon_search" slot="append" icon="el-icon-search" @click="findKey"></el-button>
</el-input>
//查询
findKey () {
if (!this.keyword) {
this.$message.error('请输入查询条件')
} else {
this.getCompany();//
}
},
getCompany () {
let mapExtent = this.map.getView().calculateExtent(this.map.getSize()).join(",");
let strParams = {}
strParams = {
keyWord: this.keyword,
level: "11",
mapBound: mapExtent,
queryType: "2", //搜索类型(1:普通搜索,2:视野内搜索,3:周边搜索,4:普通建议词搜索,5:公交规划建议词搜索,6:公交规划起止点搜索(只搜索公交站),7: 纯POI搜索(不搜公交线),10:拉框搜索
count: "50",
start: "0"
}
let params = {
postStr: JSON.stringify(strParams),
type: "query",
tk: '17d1619c13e4508bc1945bd59de4edf8'
}
if (this.keyword) {
$.ajax({
url: this.url,
type: 'GET',
data: params,
dataType: 'json',
success: response => {
this.map.getLayerById("searchResultLayer").getSource().clear()
if (response.count > 0) {
this.map.getView().on('change:resolution', this.hideList);//地图分辨率改变时触发
this.map.on("moveend", this.hideList);//地图拖动时触发
this.resultInfo = response.pois.length
console.log(this.resultInfo)
this.listData = response.pois
// console.log(response.pois)
let featureArray = []
response.pois.forEach((element, index) => {
let coord = element.lonlat.split(" ")
let feature = new Feature({
type: 'poiMarker',
id: index + 1,
properties: {
name: element.name,
address: element.address
},
geometry: new Point([Number(coord[0]), Number(coord[1])])
});
feature.setStyle(
new Style({
image: new Circle({
radius: 10,
fill: new Fill({
color: '#008000'
}),
stroke: new Stroke({
color: '#008000',
width: 2
})
}),
text: new Text({
text: (index + 1).toString(),
fill: new Fill({
color: "#fff"
})
})
})
)
featureArray.push(feature)
});
this.map.getLayerById("searchResultLayer").getSource().addFeatures(featureArray)
} else {
this.map.getLayerById("searchResultLayer").getSource().clear()
this.listData = []
this.$message('暂无搜索结果')
}
}
})
} else {
this.map.getLayerById("searchResultLayer").getSource().clear()
this.listData = []
this.$message('请输入关键字')
}
},