如何使用过滤器将自定义图标添加到maplibre非聚集标记

问题描述 投票:0回答:1

我正在使用maplibre gl添加制造商集群,当标记不聚类时,我想根据该功能的geojson属性中存在的id将特定图像添加到单个标记。

https://maplibre.org/maplibre-gl-js-docs/example/cluster/

这是简单的聚类示例,有人可以帮忙吗?

geojson mapbox-gl markerclusterer maplibre-gl
1个回答
0
投票

你可以这样处理

   this.map.loadImage(
        "example.com" // or base 64,
        (error, image) => {
          if (error) throw error;
          this.map.addImage("shop", image);
        }
      );

and then use it in this way:

   this.map.addLayer({
      id: "unclustered-point",
      type: "symbol",
      source: "cluster-source",
      filter: ["!", ["has", "point_count"]],
      layout: {
        "icon-image": "shop", // the name of that image that you added 
        "icon-size": 0.5, // Size of the icon
        "icon-allow-overlap": true,
      },
    });
© www.soinside.com 2019 - 2024. All rights reserved.