效果图:
实现功能:
根据的搜索的条件在地图上定位显示,并且添加定位标记
<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;
},