vue项目的模糊搜索功能

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('请输入关键字')
      }
    },
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值