每 2 秒我创建一个新的图像源并为该源创建一个新图层:
map.addSource("source_" + photo_id, {
"type": "image",
"url": photo_url,
"coordinates": [... ]
})
map.addLayer({
"id": "layer_" + photo_id,
"source": "source_" + photo_id,
"type": "raster",
"paint": {"raster-opacity": 0.6}
})
这意味着每张照片都会创建一个新图层。
我想知道,是否可以在同一图层上添加多个照片源以避免这种多层创建?
map.getSource('photoSource').updateImage(...)
不起作用,因为我希望以前的所有照片也保留在地图上
基本上我的目标是将地图上的照片分成组,以便稍后能够删除特定组的照片,并且这可以通过一个图层中的多个源来实现。
使用表达式语法这是 100% 可能的。
{
'type': 'Feature',
'geometry': {
'type': 'Point',
'coordinates': [this.long, this.lat]
},
'properties': {
'icon': 'bus-generic'
}}
如果您有属性,则可以查询它并在图层定义中使用它来显示不同的图标:
map.addLayer({
'id': 'bus-layer',
'type': 'symbol',
'source': 'bus-source', // reference the data source
'layout': {
'icon-image': ['get', 'icon'], // reference the icon in properties
'icon-size': 0.2,
}
});
请参阅此处的示例!https://docs.mapbox.com/mapbox-gl-js/example/add-image-missing- generated/ https://docs.mapbox.com/mapbox-gl-js/example/add-image-missing-generated/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)