Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/411.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 映射框:为点指定图标_Javascript_Mapbox_Mapbox Gl Js - Fatal编程技术网

Javascript 映射框:为点指定图标

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

我正在尝试从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
        }
    });
我看到这两个错误,并且没有渲染点:

错误:“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);
            }
    );