Javascript 映射框:为点指定图标
我正在尝试从GeoJSON为点分配一个图标。我使用这个片段:Javascript 映射框:为点指定图标,javascript,mapbox,mapbox-gl-js,Javascript,Mapbox,Mapbox Gl Js,我正在尝试从GeoJSON为点分配一个图标。我使用这个片段: map.addSource('Punti di allerta', { type: 'geojson', data: source_attentionpoints, }); map.addLayer({ 'id': 'Punti di allerta', 'type': 'circle', 'source': 'Punti di
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
}
});
我看到这两个错误,并且没有渲染点:
错误:“layers.Punti di allerta.layout.icon-image:未知属性
“图标图像”错误:“layers.Punti di allerta.layout.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);
}
);
我发现了问题所在。我的代码中有两个错误:
'type':'circle'
而不是'type':'symbol'
map.loadImage(
'{% static 'image/webgis/icons/warning50.png' %}',
function(error, image) {
if (error) throw error;
map.addImage('warning', image);
}
);