openlayers 添加图标并转态判断
emeResponseHttp.getwater(data).then(res => {
let li = [];
res.result.forEach(item => {
if (item.lng && item.lat) {
li.push({
xy: [item.lng, item.lat],
list: item
});
}
});
let ass18 = {
openes: li,
src: window.SITE_CONFIG.imgPreUrl + "/images/open/yj/water/3.png",
scale: 0.7,
type: 10
};
this.vectorLayer22 = this.addIconMarkers(ass18);
this.icingMap.addLayer(this.vectorLayer22);
});
addIconMarkers(addIconList) {
let startMarkerList = [];
addIconList.openes.forEach((item, index) => {
let startMarker = new Feature({
type: "icon",
geometry: new Point(item.xy),
properties: {
list: item.list,
type: addIconList.type
}
});
startMarkerList.push(startMarker);
});
let vectorLayer = new VectorLayer({
source: new VectorSource({
features: startMarkerList
}),
zIndex: 10,
style: function(feature) {
let data = feature.getProperties().properties;
return new Style({
image: new Icon({
src: addIconList.src,
scale: addIconList.scale
})
});
}
});
return vectorLayer;
},