首页 / 浏览问题 / WebGIS / 问题详情
如何给点聚合的集群添加popup弹窗?
26EXP 2023年08月04日
    addMarkerCluster: function () {
      // 实例化markerCluster
      let markers = L.markerClusterGroup({
        spiderfyOnMaxZoom: false,
        showCoverageOnHover: false,
        zoomToBoundsOnClick: false
      });
      // 向markerCluster上添加景点数据
      this.featuresQueryResult.features.forEach((feature) => {
        // 获取景点的经纬度坐标
        let latLng = L.latLng(feature.geometry.coordinates[1], feature.geometry.coordinates[0]);
        // 获取景点的级别
        let levelType = feature.properties.等级;
        // 构建marker标记
        let marker = L.marker(latLng);
        // 给每个景点标记添加级别信息
        marker.levelText = levelType;
        markers.addLayer(marker);
      });
      // 将点聚合图层叠加到底图上
      markers.addTo(this.map);
      this.markerClusterList.push(markers);
      // 为聚合点添加鼠标移入事件
      markers.on('clustermouseover', (event) => {
        this.childMarkers = event.layer.getAllChildMarkers();
      });
      // 为聚合点添加鼠标移出事件
      markers.on('clustermouseout', (event) => {
        // 鼠标移出聚合点时将该数组清空
        this.childMarkers = [];
      });
    },

鼠标移入集群上时会触发clustermouseover事件,如何在这个事件触发时在集群上弹出一个popup弹窗,弹窗中展示我的另一个组件?

我在on事件内部使用event.layer.openPopups();报错,显示没有这个方法,但是openPopups点击进去是有源码的啊?

麻烦您帮忙解决一下!

2 个回答

另外childMarkers中的数据是要传递给另一个组件的

我想实现的是类似于下面图片上的功能

26EXP 2023年08月04日

你好,1、event.layer.openPopups()是无法实现的,你可以打印event.layer看看支持的接口。如果要用弹窗,看接口文档是这样实现的。

2、聚合弹窗参考:http://ask.supermap.com/103027

1,865EXP 2023年08月04日
...