(function() { var d = window.ZDC; d.MarkerCluster = d.MarkerCluster = function(f, t) { function r(a, b) { for (var c in b) try { b[c].constructor == Object ? a[c] = r(a[c], b[c]) : b.hasOwnProperty(c) && (a[c] = b[c]) } catch (g) { a[c] = b[c] } return a } this.indexOf = function(a, b, c) { c = c || 0; for (var g = a.length; c < g; c++) if (a[c] === b) return c; return -1 } ; this.miriLon = f.getMapType().latLonPerPx.lon; this.miriLat = f.getMapType().latLonPerPx.lat; this.clusters = []; this.markers = []; this.markerNo = 0; this.options = { markers: [], maxZoom: f.getMapType().zoomRange.length - 1, cluster: function(a, e) { var c = 36 , g = "clusterermarker1.png" , h = "font-family:arial; color:#FFFFFF; font-size:20px; font-weight: bold;"; 5 <= a && (c = 40, g = "clusterermarker2.png", h = "font-family:arial; color:#FFFFFF; font-size:22px; font-weight: bold;"); 10 <= a && (c = 44, g = "clusterermarker3.png", h = "font-family:arial; color:#FFFFFF; font-size:22px; font-weight: bold;"); 50 <= a && (c = 48, g = "clusterermarker4.png", h = "font-family:arial; color:#FFFFFF; font-size:24px; font-weight: bold;"); 100 <= a && (c = 58, g = "clusterermarker5.png", h = "font-family:arial; color:#FFFFFF; font-size:24px ;font-weight: bold;"); g = d._MAP_SERVER_IMG + g; c = { html: '
' + a + "
", size: new d.WH(c,c), offset: d.Pixel(-c / 2, -c / 2) }; return new d.UserWidget(e,c) }, textStyle: null, method: "distance", radius: 10 }; r(this.options, t); this.clusters = []; var b = this; // add 2020/02/20 Mlab.HuuPhuoc [ var me = this; // add 2020/02/20 Mlab.HuuPhuoc ] this.addClusterEventHandle = function(a) { for (var b = [], c = 0; c < a.markers.length; c++) b.push(a.markers[c].getLatLon()); var g = f.getAdjustZoom(b, { fix: !1 }); d.addListener(a.owner, d.USERWIDGET_MOUSEDOWN, function() { // add 2020/02/20 Mlab.HuuPhuoc [ if (typeof me['options']['onClusterMouseDown'] == "function") { me.options.onClusterMouseDown(a, f, g); return; } // add 2020/02/20 Mlab.HuuPhuoc ] f.moveLatLon(g.latlon); f.setZoom(g.zoom) }) } ; this.kmeans = { mkIdx: [], getMarkerInBox: function() { this.mkIdx = []; f.getLatLonBox(); for (var a = 0; a < b.markers.length; a++) b.markers[a].hidden(), this.mkIdx.push(a) }, addCluster: function() { for (var a = f.getLatLonBox(), e = a.getMin(), a = a.getMax(), c = b.options, g = 0; g < c.radius; g++) { var h = (Math.random() * (a.lat - e.lat) + e.lat).toFixed(7) , k = (Math.random() * (a.lon - e.lon) + e.lon).toFixed(7) , h = { owner: null, latlon: new d.LatLon(h,k), markers: [] }; b.clusters.push(h) } }, updateCluster: function() { for (var a = 0; a < b.clusters.length; a++) b.clusters[a].markers = []; for (var e = 0; e < this.mkIdx.length; e++) { for (var c = Infinity, g, d = b.markers[this.mkIdx[e]], a = 0; a < b.clusters.length; a++) { var f = d.getLatLon().lat - b.clusters[a].latlon.lat , l = d.getLatLon().lon - b.clusters[a].latlon.lon , f = Math.sqrt(Math.pow(f, 2) + Math.pow(l, 2)); f < c && (c = f, g = b.clusters[a]) } g.markers.push(d); d.group = g } this.updateCenter() }, updateCenter: function() { for (var a = !0, e = 0; e < b.clusters.length; e++) { var c = 0 , g = 0 , f = b.clusters[e]; if (0 < f.markers.length) { for (var k = 0; k < f.markers.length; k++) var l = f.markers[k].getLatLon() , c = c + parseFloat(l.lat) , g = g + parseFloat(l.lon); c /= f.markers.length; g /= f.markers.length; c = c.toFixed(7); g = g.toFixed(7); if (f.latlon.lat != c || f.latlon.lon != g) a = !1; f.latlon = new d.LatLon(c,g) } } a ? this.drawCluster() : this.updateCluster() }, drawCluster: function() { if (0 < b.clusters.length) { for (var a = [], e = 0; e < b.clusters.length; e++) { var c = b.clusters[e]; if (1 < c.markers.length) { var d = new b.options.cluster(c.markers.length,c.latlon); f.addWidget(d); d.open(); c.owner = d; a.push(c); b.addClusterEventHandle(c) } else 1 == c.markers.length && c.markers[0].visible() } b.clusters = a } }, cluster: function() { 0 < b.options.radius && (this.getMarkerInBox(), this.addCluster(), this.updateCluster()) }, clear: function() { if (0 < b.clusters.length) { for (var a = 0; a < b.clusters.length; a++) null != b.clusters[a] && f.removeWidget(b.clusters[a].owner); b.clusters = []; if (0 < b.markers.length) for (a = 0; a < b.markers.length; a++) b.markers[a].visible() } } }; this.distance = { mkIdx: [], radius: 0, getRarius: function() { var a = b.options , e = b.miriLat , c = b.miriLon , g = f.getZoom() , e = a.radius * e[f.getMapType().zoomRange[g]] , a = a.radius * c[f.getMapType().zoomRange[g]]; this.radius = Math.sqrt(Math.pow(e, 2) + Math.pow(a, 2)); this.radius = d.msTodeg(this.radius) }, getRelation: function() { this.mkIdx = []; if (0 < b.markers.length) { for (var a = 0; a < b.markers.length; a++) b.markers[a].relateds = [], b.markers[a].inCluster = !1, this.mkIdx.push(a); for (a = 0; a < this.mkIdx.length - 1; a++) for (var e = b.markers[this.mkIdx[a]].getLatLon(), c = a + 1; c < this.mkIdx.length; c++) { var d = b.markers[this.mkIdx[c]].getLatLon() , f = e.lon - d.lon; Math.sqrt(Math.pow(e.lat - d.lat, 2) + Math.pow(f, 2)) <= this.radius && (b.markers[this.mkIdx[a]].relateds.push(this.mkIdx[c]), b.markers[this.mkIdx[c]].relateds.push(this.mkIdx[a])) } } }, createCluster: function() { this.mkIdx.sort(function(a, c) { return b.markers[c].relateds.length == b.markers[a].relateds.length ? b.markers[a].markerNo - b.markers[c].markerNo : b.markers[c].relateds.length - b.markers[a].relateds.length }); for (var a = null, e = 0; e < this.mkIdx.length; e++) if (0 < b.markers[this.mkIdx[e]].relateds.length && 0 == b.markers[this.mkIdx[e]].inCluster) { a = b.markers[this.mkIdx[e]]; break } if (null != a) { e = new b.options.cluster(a.relateds.length + 1,a.getLatLon()); f.addWidget(e); e.open(); e = { owner: e, markers: [] }; a.inCluster = !0; a.hidden(); e.markers.push(a); for (var c = 0; c < a.relateds.length; c++) { var d = a.relateds[c]; e.markers.push(b.markers[d]); b.markers[d].hidden(); b.markers[d].inCluster = !0; for (var h = b.markers[d].relateds.length, k = 0; k < h; k++) { var l = b.markers[d].relateds[k]; if (!b.markers[l].inCluster) { var n = b.indexOf(b.markers[l].relateds, d); b.markers[l].relateds.splice(n, 1) } } } b.clusters.push(e); b.addClusterEventHandle(e); this.createCluster() } }, cluster: function() { this.getRarius(); this.getRelation(); this.createCluster() }, clear: function() { if (0 < b.clusters.length) { for (var a = 0; a < b.clusters.length; a++) null != b.clusters[a].owner && f.removeWidget(b.clusters[a].owner); b.clusters = []; if (0 < b.markers.length) for (a = 0; a < b.markers.length; a++) b.markers[a].visible() } } }; this.clusterer = { boundSize: { lat: 0, lon: 0 }, getBoundSize: function() { var a = f.getZoom() , e = b.options , c = b.miriLon; this.boundSize = { lat: d.msTodeg(e.radius * b.miriLat[f.getMapType().zoomRange[a]] / 2), lon: d.msTodeg(e.radius * c[f.getMapType().zoomRange[a]] / 2) } }, createCluster: function() { for (var a = 0; a < b.markers.length; a++) b.markers[a].isClustering = !1; for (a = 0; a < b.markers.length - 1; a++) { var e = b.markers[a]; if (!e.isClustering) { for (var c = e.getLatLon(), g = new d.LatLon(parseFloat(c.lat) - this.boundSize.lat,parseFloat(c.lon) + this.boundSize.lon), h = new d.LatLon(parseFloat(c.lat) + this.boundSize.lat,parseFloat(c.lon) + this.boundSize.lon), k = new d.LatLon(parseFloat(c.lat) + this.boundSize.lat,parseFloat(c.lon) - this.boundSize.lon), l = new d.LatLon(parseFloat(c.lat) - this.boundSize.lat,parseFloat(c.lon) - this.boundSize.lon), n = [], q = a + 1; q < b.markers.length; q++) { var p = b.markers[q]; if (!p.isClustering) { var m = p.getLatLon() , m = new d.LatLonBox(new d.LatLon(parseFloat(m.lat) - this.boundSize.lat,parseFloat(m.lon) - this.boundSize.lon),new d.LatLon(parseFloat(m.lat) + this.boundSize.lat,parseFloat(m.lon) + this.boundSize.lon)); if (d.getLineCrossRectLatLons(g, h, m) || d.getLineCrossRectLatLons(h, k, m) || d.getLineCrossRectLatLons(k, l, m) || d.getLineCrossRectLatLons(l, g, m)) p.isClustering = !0, p.hidden(), n.push(p) } } 0 < n.length && (n.push(e), c = new b.options.cluster(n.length,c), f.addWidget(c), c.open(), e.hidden(), e.isClustering = !0, e = { owner: c, markers: n }, b.clusters.push(e), b.addClusterEventHandle(e)) } } }, cluster: function() { this.getBoundSize(); this.createCluster() }, clear: function() { if (0 < b.clusters.length) { for (var a = 0; a < b.clusters.length; a++) null != b.clusters[a].owner && f.removeWidget(b.clusters[a].owner); b.clusters = []; if (0 < b.markers.length) for (a = 0; a < b.markers.length; a++) b.markers[a].visible() } } }; d.MarkerCluster.prototype.addMarkers = d.MarkerCluster.prototype.addMarkers = this.addMarkers = function(a) { for (var b = 0; b < a.length; b++) a[b].markerNo = this.markerNo, f && f.addWidget(a[b]), this.markers.push(a[b]), this.markerNo++ } ; d.MarkerCluster.prototype.setMethod = d.MarkerCluster.prototype.setMethod = this.setMethod = function(a) { a != this.options.method && (this.options.method = a) } ; d.MarkerCluster.prototype.setRadius = d.MarkerCluster.prototype.setRadius = this.setRadius = function(a) { a != this.options.radius && (this.options.radius = a) } ; d.MarkerCluster.prototype.setMaxZoom = d.MarkerCluster.prototype.setMaxZoom = this.setMaxZoom = function(a) { a != this.options.maxZoom && (f.getZoom(), this.options.maxZoom = a) } ; d.MarkerCluster.prototype.getClusterMarker = d.MarkerCluster.prototype.getClusterMarker = this.getClusterMarker = function() { return this.clusters } ; d.MarkerCluster.prototype.getMaxZoom = d.MarkerCluster.prototype.getMaxZoom = this.getMaxZoom = function() { return this.options.maxZoom } ; d.MarkerCluster.prototype.redraw = d.MarkerCluster.prototype.redraw = this.redraw = function() { this.kmeans.clear(); this.distance.clear(); this.clusterer.clear(); this.draw() } ; d.MarkerCluster.prototype.draw = d.MarkerCluster.prototype.draw = this.draw = function() { var a = f.getZoom(); 0 >= this.options.radius || a > this.options.maxZoom || 0 >= this.markers.length || ("k-means" == this.options.method && this.kmeans.cluster(), "distance" == this.options.method && this.distance.cluster(), "box" == this.options.method && this.clusterer.cluster()) } ; d.MarkerCluster.prototype.removeMarker = d.MarkerCluster.prototype.removeMarker = this.removeMarker = function() { this.options.markers = []; for (var a = 0; a < this.markers.length; a++) f.removeWidget(this.markers[a]); this.markers = b.markers = []; this.redraw() } ; this.options.markers && 0 < this.options.markers.length && (this.addMarkers(this.options.markers), this.redraw()); d.addListener(f, d.MAP_CHG_ZOOM, function() { b.redraw() }) } } )();