主要思路就是在地图上添加一个位置(点要素),设置这个(位置)点的样式为一个Icon图片
var vectorSource = new VectorSource();//新建矢量图层//WKT转Feature之前有文章写到
let wkt = "Point(11584213.17 3588634.87)";
let format = new WKT();
//获取wkt要素
let feature = format.readFeature(wkt);
//新建图标样式
var iconStyle = new Style({image: new Icon({name:markName,crossOrigin: 'anonymous',src: url//Icon的url(如 https://openlayers.org/en/v4.6.5/examples/data/icon.png)})
});
//设置Icon
feature.setStyle(iconStyle);
vectorSource.addFeature(feature);var vectorLayer = new VectorLayer({source: vectorSource
});map.addLayer(vectorLayer );
更多icon设置请参考(OpenLayers v6.7.0 API - Class: Icon)
结果:
QQ群(GIS开发交流、数据共享、软件使用):993836992