我正在尝试将图标分配给 GeoJSON 中的点。我使用这个片段:
map.addSource('Punti di allerta', {
type: 'geojson',
data: source_attentionpoints,
});
map.addLayer({
'id': 'Punti di allerta',
'type': 'circle',
'source': 'Punti di allerta',
'layout': {
'icon-image': '{% static 'image/webgis/icons/warning50.png' %}',
'icon-size': 0.5
}
});
我看到这两个错误,并且点未呈现:
Error: "layers.Punti di allerta.layout.icon-image: unknown property "icon-image"" Error: "layers.Punti di allerta.layout.icon-size: unknown property "icon-size""
但是如果我使用这个片段而不是之前的片段,我可以毫无问题地看到所有点:
map.addLayer({
'id': 'Punti di allerta',
'type': 'circle',
'source': 'Punti di allerta',
'paint': {
'circle-radius': 8,
'circle-color': 'rgb(0,0,0)',
'circle-opacity': 1.0,
'circle-stroke-width': 4,
'circle-stroke-color': 'rgb(200,200,200)',
'circle-stroke-opacity': 1.0,
'circle-blur': 0,
}
});
我做错了什么?
最佳答案
我发现问题了。我的代码中有两个错误:
'type': 'circle'
而不是'type': 'symbol'
我在添加图层之前需要这个:
map.loadImage( '{% static 'image/webgis/icons/warning50.png' %}', function(error, image) { if (error) throw error; map.addImage('warning', image); } );
关于javascript - MapBox:为点分配图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59703611/