为每组坐标绘制具有不同样式的开放图层图层
Draw an openLayers layer with different style for each set of coordinates
我有一个从服务器得到的刺痛,我需要循环它。这个字符串实际上是我想使用 openLayers 在地图上可视化的位置的地理。下面是返回字符串的示例:
{crs:
{"type":"name",
"properties":{
"name":"ESPG:4326"
},
},
"features":[{"properties":{
"image":"IMAGE1"},
"type":"Feature",
"geometry":{
"type":"Point",
"coordinates":[0,0]
}},{"properties":{
"image":"IMAGE2"},
"type":"Feature",
"geometry":{
"type":"Point",
"coordinates":[10,10]
}},{"properties":{
"image":"IMAGE3"},
"type":"Feature",
"geometry":{
"type":"Point",
"coordinates":[75,99]
}}]
,type:"FeatureCollection"
}
如您所见,features
的每个feature
都有一些properties
和一个geometry
。我想创建一个新layer
(ol.layer.Vector),对于特征的每个元素,它将绘制一个具有相应坐标和图像的点。使用以下代码,我设法使用预定义的图像绘制地图中的所有点。我想我应该遍历这个字符串并获取坐标和图像,并以某种方式创建一个图层(或许多图层?任何想法??谢谢!
//map is the actual map where the images load
//responseText is the String that I get from the server
//predefinedImage is actually a predefined image that I use as icon for the points.
//If I complitelly remove the "style" from geojson_layer it sets the image to a default value.
var geoJSONsource = new ol.source.Vector({
features: (new ol.format.GeoJSON()).readFeatures(responseText)
});
geojson_layer = new ol.layer.Vector({
source: geoJSONsource,
style: predefinedImage
});
map.addLayer(geojson_layer);
这可能有助于您:
https://gis.stackexchange.com/a/95389/77349
但是,您应该修改此行:
externalGraphic: 'marker.png',
到类似的东西
externalGraphic: this.image,
希望这有帮助!
相关文章:
- 更改图层中单个矢量特征的图标
- 谷歌地图热图图层点半径
- 谷歌地图-更改图层图标大小
- 如何通过ID获取图层对象
- CS5隐藏图层的速度非常慢
- 开放图层导出为 KML 并保留我的地图样式
- 传单问题:使折线的图层组不可单击
- 如何在开放层 3 中设置矢量图层选择的样式
- OL3:如何获取矢量图层的现有样式属性(例如填充颜色、描边颜色等)
- Google Maps JavaScript API:动态样式KML图层
- 如何在 OL3 中使用 SLD 设置图层样式
- 使用 Geoserver 中的 Javascript 动态设置 WMS 图层样式
- 更改融合表图层选项样式选项
- 动态更改已加载的 WMS 图层的样式
- 传单不设置图层样式
- 打开图层中的矢量样式3
- 在Mapbox中,你如何从iOS上的样式切换图层
- 基于SLD的WMS图层选择-如何设置点击点的新样式
- 开放图层 3:如何设置矢量要素的填充样式
- 为每组坐标绘制具有不同样式的开放图层图层