MaxDragonheart
MaxDragonheart

Reputation: 1290

MapBox: assign an icon to the points

I'm trying to assign an icon to the points from a GeoJSON. I use this snippet:

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

I see this two errors and the points are not rendered:

Error: "layers.Punti di allerta.layout.icon-image: unknown property "icon-image"" Error: "layers.Punti di allerta.layout.icon-size: unknown property "icon-size""

But if I use this snippet instead of the previous I can see all points without problems:

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

What I've wrong?

Upvotes: 0

Views: 998

Answers (1)

MaxDragonheart
MaxDragonheart

Reputation: 1290

I've found the problem. There are two errors inside my code:

  1. 'type': 'circle' instead of 'type': 'symbol'
  2. I need this before add.Layer:

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

Upvotes: 5

Related Questions