ArcGIS JavaScript API异常之onExtentChange事件覆盖onClick事件

利用Esri官方提供的聚合类进行聚合,由于数据较多,为了加快速度,在聚合之前对当期范围进行判断,如果不在当前视图范围的,就不聚合了。

所以,由于Esri官方的类是监听了zoomEnd事件,如下代码

this._zoomEnd = connect.connect(map, "onZoomEnd", this, function () {
                // update resolution
                if (map.spatialReference.isWebMercator()) {
                    this._clusterResolution = map.extent.getWidth() / map.width; // probably a bad default...
                }
                else {
                    //WGS 84坐标,转换为web Mercator
                    var latlng1 = new Point(map.extent.xmax, map.extent.ymax, map.spatialReference); //右上角
                    var latlng2 = new Point(map.extent.xmin, map.extent.ymin, map.spatialReference); //左下角
                    var webMercator1 = webMercatorUtils.geographicToWebMercator(latlng1);
                    var webMercator2 = webMercatorUtils.geographicToWebMercator(latlng2);
                    this._clusterResolution = (webMercator1.x - webMercator2.x) / map.width;
                }
                this.clear();
                this._clusterGraphics();
            });

所以,当限定视图范围聚合时,如果只平移,不触发onZoomEnd事件,新视图范围内心增加的地图区域即不进行聚合计算,也就没有聚合点。

为了解决上述问题,改为监听onExtentChange事件,即可。

this._extentChange = connect.connect(map, "onExtentChange", this, function ()
{
      //同上  
}

为了验证,运行之前就加了断点进行调试。调试时发现,onExtentChange事件覆盖了聚合图层的onClick事件(项目中该事件中弹出该点的Modal窗口,包含一些感兴趣的信息以及需要客户填写的信息),

导致onClick是一些操作被忽视,Modal窗口无法弹出。

Google了好久,发现,调试模式下onClick事件被onExtentChange事件覆盖,如果不调试,就正常了!!!!!

原文地址:https://www.cnblogs.com/DayDreamEveryWhere/p/4791483.html