【问题标题】:How to show the marker quantity in cluster如何在集群中显示标记数量
【发布时间】:2018-12-26 07:19:49
【问题描述】:

我正在尝试做这样的事情https://developer.here.com/api-explorer/maps-js/v3.0/clustering/marker-clustering

我需要更改图标,但保留代表群集中标记数量的数字。

我可以更改图标,但无法保留数量。

【问题讨论】:

    标签: javascript here-api


    【解决方案1】:

    我可以这样做:

    拥有一个带有

    的 SVG
     <text id="!" font-family="Montserrat-SemiBold, Montserrat" font-size="13" font-weight="500" fill="#ECECEC">
                            <tspan x="3.193" y="15">{text}!</tspan>
                        </text>
    

    然后是自定义主题:

    CustomTheme = {
                    getClusterPresentation: cluster => {
                        const weight = cluster.getWeight();
                        const radius = weight * 5;
    
                        const svgString = icons.alertClusterPresentation
                            .replace(/\{text\}/g, weight.toString());
                        const clusterMarker = new H.map.Marker(cluster.getPosition(), {
                            icon: new H.map.Icon(svgString, {
                                size: { w: radius, h: radius },
                                crossOrigin: false,
                            }),
                            // Set min/max zoom with values from the cluster,
                            // otherwise clusters will be shown at all zoom levels:
                            min: cluster.getMinZoom(),
                            max: cluster.getMaxZoom(),
                        });
                        return clusterMarker;
                    },
    

    非常感谢!

    【讨论】:

      【解决方案2】:

      市场上有很多基于四叉树算法的库。

      参考这个:-

      https://en.wikipedia.org/wiki/Quadtree

      https://github.com/googlemaps/js-marker-clusterer

      【讨论】:

        猜你喜欢
        • 2023-03-19
        • 1970-01-01
        • 2021-02-25
        • 1970-01-01
        • 1970-01-01
        • 2014-02-24
        • 2017-09-13
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多