繁体   English   中英

Mapbox 非聚集圆圈更改为图标

[英]Mapbox unclustered circle change to icon

如何将其更改为图标而不是带有颜色的圆圈? 我尝试使用“布局”和“选项”而不是“绘画”。 我也在这里查看,但没有找到任何适合此的东西。 我还是 Mapbox/Leaflet 的新手。

                 map.addLayer({
                 id: 'unclustered-point',
                 type: 'circle',
                 source: 'people',
                 filter: ['!', ['has', 'point_count']],
                 paint: {
                 'circle-color': '#21ba45',
                 'circle-radius': 11,
                 'circle-stroke-width': 3,
                 'circle-stroke-color': '#fff'
                 }
                 });

为了在 Mapbox 中使用图标,您需要先加载图像(png、webp 或 jpg 格式):

map.loadImage(
  './marker-icon.png', // Path to your image here
  (error, image) => {
  if (error) throw error;
     map.addImage('icon_name', image);
});  

然后,您必须将图层类型从circle更改为symbol

fill适用于表单但不适用于图像,因此您必须改用layout 这是一个例子:

map.addLayer({
  'id': 'layer_id',
  'type': 'symbol',
  'source': {
    'type': 'geojson',
    'data': data
  },
  'layout': {
    'icon-image': 'icon_name', // The name has to match with the image loaded
    'icon-size': 0.85,
    "icon-allow-overlap": false // This can be 'true' if you want to display all the markers 
    },
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM