vue+openlayers实现添加标记和当前定位标记

本文介绍如何在地图上实现根据搜索条件定位并添加定位标记的功能,包括清除旧图层、动态调整视图、加载船只和港口图层,以及船舶选中和互动效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

效果图:

watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA6Ii56ZW_5Zyo6Ii55LiK,size_10,color_FFFFFF,t_70,g_se,x_16

实现功能:

根据的搜索的条件在地图上定位显示,并且添加定位标记 

<div v-for="item in serchDataList" :key="item.portId" class="listLine plr30" @click="handleCurrentList(item)">
                    <span :class="{listItem:item.name&&item.ename}" v-show="item.name">{{item.name}}</span>
                   
</div>
handleCurrentList(item){
      this.isShowSerchList = false;
      this.map.removeLayer(this.vectorLayer);//清除船图层
      this.map.removeLayer(this.positionVectorLayer);//清除港口图层
      console.log(item,"当前数据")



      let view = this.map.getView();
      view.animate({
        center: [item.longitude, item.latitude],
        duration: 0
      });
      // 加载当前定数据的图层
      let positionFeaturesMarker = [];
      positionFeaturesMarker.push(
        new Feature({
          geometry: new Point([item.longitude, item.latitude], "XY"),
          type:item.type,//1船,2港口
          shipName: item.name,
          portName:item.name,//港口名称
          portId:item.portId,
          // nature: item.nature,
          // 航速、航向、时间、船首向
          mmsi: item.mmsi,
          csx: item.csx,
          speed: item.speed,
          updateTime: item.updateTime,
          index: 0
        })
      );
      
      let iconStyles = [];
      positionFeaturesMarker.forEach(item => {
        if(item.values_.type=="1"){//船
          iconStyles.push(
            new Style({
              image: new Icon({
                rotation: item.values_.csx / 180 * Math.PI,
                src: this.YXshipIcon
              })
            })
          );
        }else{//港口
          iconStyles.push(
            new Style({
              image: new Icon({
                src: this.gkIcon
              })
            })
          );
        }
        
      });
      let vectorSource = new SourceVec({
        features: positionFeaturesMarker
      });
      this.positionVectorLayer = new LayerVec({
        source: vectorSource,
        style: function(feature) {
          let iconStyle = iconStyles[feature.values_.index];
          return [iconStyle];
        },
        zIndex: 10
      });
      this.map.addLayer(this.positionVectorLayer);
      this.shipChecked(item);
      
    },
    // 船舶选中框
    shipChecked(item) {
      console.log(item,"选中图标")
      if (this.isVector2) {
        this.map.removeLayer(this.vectorLayer2);
      }
      let checkfeaturesMarker = [];
      checkfeaturesMarker.push(
        new Feature({
          geometry: new Point([item.longitude, item.latitude], "XY"),
          index: 0,
        })
      );

      let iconStyles = [];
      checkfeaturesMarker.forEach(() => {
        iconStyles.push(
          new Style({
            image: new Icon({
              src: this.checkShipIcon,
              scale: 1.5,
            }),
          })
        );
      });
      let vectorSource = new SourceVec({
        features: checkfeaturesMarker,
      });
      this.vectorLayer2 = new LayerVec({
        name: "vectorLayer2",
        source: vectorSource,
        style: function (feature) {
          var iconsStyle = iconStyles[feature.values_.index];
          return [iconsStyle];
        },
        zIndex: 111,
      });
      this.map.addLayer(this.vectorLayer2);
      this.map.getView().setCenter([item.longitude, item.latitude]);
      this.isVector2 = true;
    },

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

船长在船上

您的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值