MapBox:为点分配一个图标

MapBox: assign an icon to the points

我正在尝试为来自 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,
    }
});

我错了什么?

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

  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);
            }
    );