MapBox:为点分配图标

Mas*_*aca 0 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 allerta',
        'layout': {
            'icon-image': '{% static 'image/webgis/icons/warning50.png' %}',
            'icon-size': 0.5
        }
    });
Run Code Online (Sandbox Code Playgroud)

我看到这两个错误并且点没有呈现:

错误:“layers.Punti di allerta.layout.icon-image:未知属性“icon-image””错误:“layers.Punti di allerta.layout.icon-size:未知属性“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,
    }
});
Run Code Online (Sandbox Code Playgroud)

我有什么错吗?

Mas*_*aca 5

我已经找到问题了。我的代码中有两个错误:

  1. 'type': 'circle'代替'type': 'symbol'
  2. 我在 add.Layer 之前需要这个:

    map.loadImage(
        '{% static 'image/webgis/icons/warning50.png' %}',
        function(error, image) {
            if (error) throw error;
            map.addImage('warning', image);
            }
    );
    
    Run Code Online (Sandbox Code Playgroud)