利用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事件覆蓋,如果不調試,就正常了!!!!!