@google/markerclusterer
Advanced tools
Comparing version 2.0.1 to 2.0.2
@@ -49,2 +49,4 @@ /** | ||
* is shown. | ||
* 'zIndex': (number) the z-index of a cluster. | ||
* Default: google.maps.Marker.MAX_ZINDEX + 1 | ||
* 'styles': (object) An object that has style properties: | ||
@@ -110,2 +112,7 @@ * 'url': (string) The image url. | ||
* @type {number} | ||
*/ | ||
this.zIndex_ = options["zIndex"] || google.maps.Marker.MAX_ZINDEX + 1; | ||
/** | ||
* @type {number} | ||
* @private | ||
@@ -266,2 +273,16 @@ */ | ||
/** | ||
* @param {number} zIndex | ||
*/ | ||
setZIndex(zIndex) { | ||
this.zIndex_ = zIndex; | ||
} | ||
/** | ||
* @return {number} | ||
*/ | ||
getZIndex() { | ||
return this.zIndex_; | ||
} | ||
/** | ||
* Sets the styles. | ||
@@ -1087,3 +1108,2 @@ * | ||
this.div_.style.left = pos.x + "px"; | ||
this.div_.style.zIndex = google.maps.Marker.MAX_ZINDEX + 1; | ||
} | ||
@@ -1184,2 +1204,3 @@ } | ||
var style = []; | ||
style.push("z-index:" + this.markerClusterer_.getZIndex() + ";"); | ||
style.push("background-image:url(" + this.url_ + ");"); | ||
@@ -1186,0 +1207,0 @@ var backgroundPosition = this.backgroundPosition_ |
@@ -1,1 +0,1 @@ | ||
var MarkerClusterer=function(){"use strict";class t{constructor(e,s,i){this.extend(t,google.maps.OverlayView),this.map_=e,this.MARKER_CLUSTER_IMAGE_PATH_="../images/m",this.MARKER_CLUSTER_IMAGE_EXTENSION_="png",this.markers_=[],this.clusters_=[],this.sizes=[53,56,66,78,90],this.styles_=[],this.ready_=!1;var r=i||{};this.gridSize_=r.gridSize||60,this.minClusterSize_=r.minimumClusterSize||2,this.maxZoom_=r.maxZoom||null,this.styles_=r.styles||[],this.imagePath_=r.imagePath||this.MARKER_CLUSTER_IMAGE_PATH_,this.imageExtension_=r.imageExtension||this.MARKER_CLUSTER_IMAGE_EXTENSION_,this.zoomOnClick_=!0,null!=r.zoomOnClick&&(this.zoomOnClick_=r.zoomOnClick),this.averageCenter_=!1,null!=r.averageCenter&&(this.averageCenter_=r.averageCenter),this.setupStyles_(),this.setMap(e),this.prevZoom_=this.map_.getZoom();var h=this;google.maps.event.addListener(this.map_,"zoom_changed",(function(){var t=h.map_.getZoom(),e=h.map_.minZoom||0,s=Math.min(h.map_.maxZoom||100,h.map_.mapTypes[h.map_.getMapTypeId()].maxZoom);t=Math.min(Math.max(t,e),s),h.prevZoom_!=t&&(h.prevZoom_=t,h.resetViewport())})),google.maps.event.addListener(this.map_,"idle",(function(){h.redraw()})),s&&(s.length||Object.keys(s).length)&&this.addMarkers(s,!1)}extend(t,e){return function(t){for(var e in t.prototype)this.prototype[e]=t.prototype[e];return this}.apply(t,[e])}onAdd(){this.setReady_(!0)}draw(){}setupStyles_(){if(!this.styles_.length)for(var t,e=0;t=this.sizes[e];e++)this.styles_.push({url:this.imagePath_+(e+1)+"."+this.imageExtension_,height:t,width:t})}fitMapToMarkers(){for(var t,e=this.getMarkers(),s=new google.maps.LatLngBounds,i=0;t=e[i];i++)s.extend(t.getPosition());this.map_.fitBounds(s)}setStyles(t){this.styles_=t}getStyles(){return this.styles_}isZoomOnClick(){return this.zoomOnClick_}isAverageCenter(){return this.averageCenter_}getMarkers(){return this.markers_}getTotalMarkers(){return this.markers_.length}setMaxZoom(t){this.maxZoom_=t}getMaxZoom(){return this.maxZoom_}calculator_(t,e){for(var s=0,i=t.length,r=i;0!==r;)r=parseInt(r/10,10),s++;return{text:i,index:s=Math.min(s,e)}}setCalculator(t){this.calculator_=t}getCalculator(){return this.calculator_}addMarkers(t,e){if(t.length)for(let e,s=0;e=t[s];s++)this.pushMarkerTo_(e);else if(Object.keys(t).length)for(let e in t)this.pushMarkerTo_(t[e]);e||this.redraw()}pushMarkerTo_(t){if(t.isAdded=!1,t.draggable){var e=this;google.maps.event.addListener(t,"dragend",(function(){t.isAdded=!1,e.repaint()}))}this.markers_.push(t)}addMarker(t,e){this.pushMarkerTo_(t),e||this.redraw()}removeMarker_(t){var e=-1;if(this.markers_.indexOf)e=this.markers_.indexOf(t);else for(var s,i=0;s=this.markers_[i];i++)if(s==t){e=i;break}return-1!=e&&(t.setMap(null),this.markers_.splice(e,1),!0)}removeMarker(t,e){var s=this.removeMarker_(t);return!(e||!s)&&(this.resetViewport(),this.redraw(),!0)}removeMarkers(t,e){for(var s,i=t===this.getMarkers()?t.slice():t,r=!1,h=0;s=i[h];h++){var a=this.removeMarker_(s);r=r||a}if(!e&&r)return this.resetViewport(),this.redraw(),!0}setReady_(t){this.ready_||(this.ready_=t,this.createClusters_())}getTotalClusters(){return this.clusters_.length}getMap(){return this.map_}setMap(t){this.map_=t}getGridSize(){return this.gridSize_}setGridSize(t){this.gridSize_=t}getMinClusterSize(){return this.minClusterSize_}setMinClusterSize(t){this.minClusterSize_=t}getExtendedBounds(t){var e=this.getProjection(),s=new google.maps.LatLng(t.getNorthEast().lat(),t.getNorthEast().lng()),i=new google.maps.LatLng(t.getSouthWest().lat(),t.getSouthWest().lng()),r=e.fromLatLngToDivPixel(s);r.x+=this.gridSize_,r.y-=this.gridSize_;var h=e.fromLatLngToDivPixel(i);h.x-=this.gridSize_,h.y+=this.gridSize_;var a=e.fromDivPixelToLatLng(r),n=e.fromDivPixelToLatLng(h);return t.extend(a),t.extend(n),t}isMarkerInBounds_(t,e){return e.contains(t.getPosition())}clearMarkers(){this.resetViewport(!0),this.markers_=[]}resetViewport(t){for(let t,e=0;t=this.clusters_[e];e++)t.remove();for(let e,s=0;e=this.markers_[s];s++)e.isAdded=!1,t&&e.setMap(null);this.clusters_=[]}repaint(){var t=this.clusters_.slice();this.clusters_.length=0,this.resetViewport(),this.redraw(),setTimeout((function(){for(var e,s=0;e=t[s];s++)e.remove()}),0)}redraw(){this.createClusters_()}distanceBetweenPoints_(t,e){if(!t||!e)return 0;var s=(e.lat()-t.lat())*Math.PI/180,i=(e.lng()-t.lng())*Math.PI/180,r=Math.sin(s/2)*Math.sin(s/2)+Math.cos(t.lat()*Math.PI/180)*Math.cos(e.lat()*Math.PI/180)*Math.sin(i/2)*Math.sin(i/2);return 6371*(2*Math.atan2(Math.sqrt(r),Math.sqrt(1-r)))}addToClosestCluster_(t){for(var s,i=4e4,r=null,h=0;s=this.clusters_[h];h++){var a=s.getCenter();if(a){var n=this.distanceBetweenPoints_(a,t.getPosition());n<i&&(i=n,r=s)}}if(r&&r.isMarkerInClusterBounds(t))r.addMarker(t);else{var o=new e(this);o.addMarker(t),this.clusters_.push(o)}}createClusters_(){if(this.ready_)for(var t,e=new google.maps.LatLngBounds(this.map_.getBounds().getSouthWest(),this.map_.getBounds().getNorthEast()),s=this.getExtendedBounds(e),i=0;t=this.markers_[i];i++)!t.isAdded&&this.isMarkerInBounds_(t,s)&&this.addToClosestCluster_(t)}}class e{constructor(t){this.markerClusterer_=t,this.map_=t.getMap(),this.gridSize_=t.getGridSize(),this.minClusterSize_=t.getMinClusterSize(),this.averageCenter_=t.isAverageCenter(),this.center_=null,this.markers_=[],this.bounds_=null,this.clusterIcon_=new s(this,t.getStyles(),t.getGridSize())}isMarkerAlreadyAdded(t){if(this.markers_.indexOf)return-1!=this.markers_.indexOf(t);for(var e,s=0;e=this.markers_[s];s++)if(e==t)return!0;return!1}addMarker(t){if(this.isMarkerAlreadyAdded(t))return!1;if(this.center_){if(this.averageCenter_){var e=this.markers_.length+1,s=(this.center_.lat()*(e-1)+t.getPosition().lat())/e,i=(this.center_.lng()*(e-1)+t.getPosition().lng())/e;this.center_=new google.maps.LatLng(s,i),this.calculateBounds_()}}else this.center_=t.getPosition(),this.calculateBounds_();t.isAdded=!0,this.markers_.push(t);var r=this.markers_.length;if(r<this.minClusterSize_&&t.getMap()!=this.map_&&t.setMap(this.map_),r==this.minClusterSize_)for(var h=0;h<r;h++)this.markers_[h].setMap(null);return r>=this.minClusterSize_&&t.setMap(null),this.updateIcon(),!0}getMarkerClusterer(){return this.markerClusterer_}getBounds(){for(var t,e=new google.maps.LatLngBounds(this.center_,this.center_),s=this.getMarkers(),i=0;t=s[i];i++)e.extend(t.getPosition());return e}remove(){this.clusterIcon_.remove(),this.markers_.length=0,delete this.markers_}getSize(){return this.markers_.length}getMarkers(){return this.markers_}getCenter(){return this.center_}calculateBounds_(){var t=new google.maps.LatLngBounds(this.center_,this.center_);this.bounds_=this.markerClusterer_.getExtendedBounds(t)}isMarkerInClusterBounds(t){return this.bounds_.contains(t.getPosition())}getMap(){return this.map_}updateIcon(){var t=this.map_.getZoom(),e=this.markerClusterer_.getMaxZoom();if(e&&t>e)for(var s,i=0;s=this.markers_[i];i++)s.setMap(this.map_);else if(this.markers_.length<this.minClusterSize_)this.clusterIcon_.hide();else{var r=this.markerClusterer_.getStyles().length,h=this.markerClusterer_.getCalculator()(this.markers_,r);this.clusterIcon_.setCenter(this.center_),this.clusterIcon_.setSums(h),this.clusterIcon_.show()}}}class s{constructor(t,e,i){t.getMarkerClusterer().extend(s,google.maps.OverlayView),this.styles_=e,this.padding_=i||0,this.cluster_=t,this.center_=null,this.map_=t.getMap(),this.div_=null,this.sums_=null,this.visible_=!1,this.setMap(this.map_)}triggerClusterClick(){var t=this.cluster_.getBounds(),e=this.cluster_.getMarkerClusterer();google.maps.event.trigger(e.map_,"clusterclick",this.cluster_),e.isZoomOnClick()&&(this.map_.fitBounds(t),this.map_.setCenter(t.getCenter()))}onAdd(){if(this.div_=document.createElement("DIV"),this.visible_){var t=this.getPosFromLatLng_(this.center_);this.div_.style.cssText=this.createCss(t),this.div_.innerHTML=this.sums_.text}this.getPanes().overlayMouseTarget.appendChild(this.div_);var e=this;google.maps.event.addDomListener(this.div_,"click",(function(){e.triggerClusterClick()}))}getPosFromLatLng_(t){var e=this.getProjection().fromLatLngToDivPixel(t);return e.x-=parseInt(this.width_/2,10),e.y-=parseInt(this.height_/2,10),e}draw(){if(this.visible_){var t=this.getPosFromLatLng_(this.center_);this.div_.style.top=t.y+"px",this.div_.style.left=t.x+"px",this.div_.style.zIndex=google.maps.Marker.MAX_ZINDEX+1}}hide(){this.div_&&(this.div_.style.display="none"),this.visible_=!1}show(){if(this.div_){var t=this.getPosFromLatLng_(this.center_);this.div_.style.cssText=this.createCss(t),this.div_.style.display=""}this.visible_=!0}remove(){this.setMap(null)}onRemove(){this.div_&&this.div_.parentNode&&(this.hide(),this.div_.parentNode.removeChild(this.div_),this.div_=null)}setSums(t){this.sums_=t,this.text_=t.text,this.index_=t.index,this.div_&&(this.div_.innerHTML=t.text),this.useStyle()}useStyle(){var t=Math.max(0,this.sums_.index-1);t=Math.min(this.styles_.length-1,t);var e=this.styles_[t];this.url_=e.url,this.height_=e.height,this.width_=e.width,this.textColor_=e.textColor,this.anchor_=e.anchor,this.textSize_=e.textSize,this.backgroundPosition_=e.backgroundPosition}setCenter(t){this.center_=t}createCss(t){var e=[];e.push("background-image:url("+this.url_+");");var s=this.backgroundPosition_?this.backgroundPosition_:"0 0";e.push("background-position:"+s+";"),"object"==typeof this.anchor_?("number"==typeof this.anchor_[0]&&this.anchor_[0]>0&&this.anchor_[0]<this.height_?e.push("height:"+(this.height_-this.anchor_[0])+"px; padding-top:"+this.anchor_[0]+"px;"):e.push("height:"+this.height_+"px; line-height:"+this.height_+"px;"),"number"==typeof this.anchor_[1]&&this.anchor_[1]>0&&this.anchor_[1]<this.width_?e.push("width:"+(this.width_-this.anchor_[1])+"px; padding-left:"+this.anchor_[1]+"px;"):e.push("width:"+this.width_+"px; text-align:center;")):e.push("height:"+this.height_+"px; line-height:"+this.height_+"px; width:"+this.width_+"px; text-align:center;");var i=this.textColor_?this.textColor_:"black",r=this.textSize_?this.textSize_:11;return e.push("cursor:pointer; top:"+t.y+"px; left:"+t.x+"px; color:"+i+"; position:absolute; font-size:"+r+"px; font-family:Arial,sans-serif; font-weight:bold"),e.join("")}}return t}(); | ||
var MarkerClusterer=function(){"use strict";class t{constructor(e,s,i){this.extend(t,google.maps.OverlayView),this.map_=e,this.MARKER_CLUSTER_IMAGE_PATH_="../images/m",this.MARKER_CLUSTER_IMAGE_EXTENSION_="png",this.markers_=[],this.clusters_=[],this.sizes=[53,56,66,78,90],this.styles_=[],this.ready_=!1;var r=i||{};this.zIndex_=r.zIndex||google.maps.Marker.MAX_ZINDEX+1,this.gridSize_=r.gridSize||60,this.minClusterSize_=r.minimumClusterSize||2,this.maxZoom_=r.maxZoom||null,this.styles_=r.styles||[],this.imagePath_=r.imagePath||this.MARKER_CLUSTER_IMAGE_PATH_,this.imageExtension_=r.imageExtension||this.MARKER_CLUSTER_IMAGE_EXTENSION_,this.zoomOnClick_=!0,null!=r.zoomOnClick&&(this.zoomOnClick_=r.zoomOnClick),this.averageCenter_=!1,null!=r.averageCenter&&(this.averageCenter_=r.averageCenter),this.setupStyles_(),this.setMap(e),this.prevZoom_=this.map_.getZoom();var h=this;google.maps.event.addListener(this.map_,"zoom_changed",(function(){var t=h.map_.getZoom(),e=h.map_.minZoom||0,s=Math.min(h.map_.maxZoom||100,h.map_.mapTypes[h.map_.getMapTypeId()].maxZoom);t=Math.min(Math.max(t,e),s),h.prevZoom_!=t&&(h.prevZoom_=t,h.resetViewport())})),google.maps.event.addListener(this.map_,"idle",(function(){h.redraw()})),s&&(s.length||Object.keys(s).length)&&this.addMarkers(s,!1)}extend(t,e){return function(t){for(var e in t.prototype)this.prototype[e]=t.prototype[e];return this}.apply(t,[e])}onAdd(){this.setReady_(!0)}draw(){}setupStyles_(){if(!this.styles_.length)for(var t,e=0;t=this.sizes[e];e++)this.styles_.push({url:this.imagePath_+(e+1)+"."+this.imageExtension_,height:t,width:t})}fitMapToMarkers(){for(var t,e=this.getMarkers(),s=new google.maps.LatLngBounds,i=0;t=e[i];i++)s.extend(t.getPosition());this.map_.fitBounds(s)}setZIndex(t){this.zIndex_=t}getZIndex(){return this.zIndex_}setStyles(t){this.styles_=t}getStyles(){return this.styles_}isZoomOnClick(){return this.zoomOnClick_}isAverageCenter(){return this.averageCenter_}getMarkers(){return this.markers_}getTotalMarkers(){return this.markers_.length}setMaxZoom(t){this.maxZoom_=t}getMaxZoom(){return this.maxZoom_}calculator_(t,e){for(var s=0,i=t.length,r=i;0!==r;)r=parseInt(r/10,10),s++;return{text:i,index:s=Math.min(s,e)}}setCalculator(t){this.calculator_=t}getCalculator(){return this.calculator_}addMarkers(t,e){if(t.length)for(let e,s=0;e=t[s];s++)this.pushMarkerTo_(e);else if(Object.keys(t).length)for(let e in t)this.pushMarkerTo_(t[e]);e||this.redraw()}pushMarkerTo_(t){if(t.isAdded=!1,t.draggable){var e=this;google.maps.event.addListener(t,"dragend",(function(){t.isAdded=!1,e.repaint()}))}this.markers_.push(t)}addMarker(t,e){this.pushMarkerTo_(t),e||this.redraw()}removeMarker_(t){var e=-1;if(this.markers_.indexOf)e=this.markers_.indexOf(t);else for(var s,i=0;s=this.markers_[i];i++)if(s==t){e=i;break}return-1!=e&&(t.setMap(null),this.markers_.splice(e,1),!0)}removeMarker(t,e){var s=this.removeMarker_(t);return!(e||!s)&&(this.resetViewport(),this.redraw(),!0)}removeMarkers(t,e){for(var s,i=t===this.getMarkers()?t.slice():t,r=!1,h=0;s=i[h];h++){var a=this.removeMarker_(s);r=r||a}if(!e&&r)return this.resetViewport(),this.redraw(),!0}setReady_(t){this.ready_||(this.ready_=t,this.createClusters_())}getTotalClusters(){return this.clusters_.length}getMap(){return this.map_}setMap(t){this.map_=t}getGridSize(){return this.gridSize_}setGridSize(t){this.gridSize_=t}getMinClusterSize(){return this.minClusterSize_}setMinClusterSize(t){this.minClusterSize_=t}getExtendedBounds(t){var e=this.getProjection(),s=new google.maps.LatLng(t.getNorthEast().lat(),t.getNorthEast().lng()),i=new google.maps.LatLng(t.getSouthWest().lat(),t.getSouthWest().lng()),r=e.fromLatLngToDivPixel(s);r.x+=this.gridSize_,r.y-=this.gridSize_;var h=e.fromLatLngToDivPixel(i);h.x-=this.gridSize_,h.y+=this.gridSize_;var a=e.fromDivPixelToLatLng(r),n=e.fromDivPixelToLatLng(h);return t.extend(a),t.extend(n),t}isMarkerInBounds_(t,e){return e.contains(t.getPosition())}clearMarkers(){this.resetViewport(!0),this.markers_=[]}resetViewport(t){for(let t,e=0;t=this.clusters_[e];e++)t.remove();for(let e,s=0;e=this.markers_[s];s++)e.isAdded=!1,t&&e.setMap(null);this.clusters_=[]}repaint(){var t=this.clusters_.slice();this.clusters_.length=0,this.resetViewport(),this.redraw(),setTimeout((function(){for(var e,s=0;e=t[s];s++)e.remove()}),0)}redraw(){this.createClusters_()}distanceBetweenPoints_(t,e){if(!t||!e)return 0;var s=(e.lat()-t.lat())*Math.PI/180,i=(e.lng()-t.lng())*Math.PI/180,r=Math.sin(s/2)*Math.sin(s/2)+Math.cos(t.lat()*Math.PI/180)*Math.cos(e.lat()*Math.PI/180)*Math.sin(i/2)*Math.sin(i/2);return 6371*(2*Math.atan2(Math.sqrt(r),Math.sqrt(1-r)))}addToClosestCluster_(t){for(var s,i=4e4,r=null,h=0;s=this.clusters_[h];h++){var a=s.getCenter();if(a){var n=this.distanceBetweenPoints_(a,t.getPosition());n<i&&(i=n,r=s)}}if(r&&r.isMarkerInClusterBounds(t))r.addMarker(t);else{var o=new e(this);o.addMarker(t),this.clusters_.push(o)}}createClusters_(){if(this.ready_)for(var t,e=new google.maps.LatLngBounds(this.map_.getBounds().getSouthWest(),this.map_.getBounds().getNorthEast()),s=this.getExtendedBounds(e),i=0;t=this.markers_[i];i++)!t.isAdded&&this.isMarkerInBounds_(t,s)&&this.addToClosestCluster_(t)}}class e{constructor(t){this.markerClusterer_=t,this.map_=t.getMap(),this.gridSize_=t.getGridSize(),this.minClusterSize_=t.getMinClusterSize(),this.averageCenter_=t.isAverageCenter(),this.center_=null,this.markers_=[],this.bounds_=null,this.clusterIcon_=new s(this,t.getStyles(),t.getGridSize())}isMarkerAlreadyAdded(t){if(this.markers_.indexOf)return-1!=this.markers_.indexOf(t);for(var e,s=0;e=this.markers_[s];s++)if(e==t)return!0;return!1}addMarker(t){if(this.isMarkerAlreadyAdded(t))return!1;if(this.center_){if(this.averageCenter_){var e=this.markers_.length+1,s=(this.center_.lat()*(e-1)+t.getPosition().lat())/e,i=(this.center_.lng()*(e-1)+t.getPosition().lng())/e;this.center_=new google.maps.LatLng(s,i),this.calculateBounds_()}}else this.center_=t.getPosition(),this.calculateBounds_();t.isAdded=!0,this.markers_.push(t);var r=this.markers_.length;if(r<this.minClusterSize_&&t.getMap()!=this.map_&&t.setMap(this.map_),r==this.minClusterSize_)for(var h=0;h<r;h++)this.markers_[h].setMap(null);return r>=this.minClusterSize_&&t.setMap(null),this.updateIcon(),!0}getMarkerClusterer(){return this.markerClusterer_}getBounds(){for(var t,e=new google.maps.LatLngBounds(this.center_,this.center_),s=this.getMarkers(),i=0;t=s[i];i++)e.extend(t.getPosition());return e}remove(){this.clusterIcon_.remove(),this.markers_.length=0,delete this.markers_}getSize(){return this.markers_.length}getMarkers(){return this.markers_}getCenter(){return this.center_}calculateBounds_(){var t=new google.maps.LatLngBounds(this.center_,this.center_);this.bounds_=this.markerClusterer_.getExtendedBounds(t)}isMarkerInClusterBounds(t){return this.bounds_.contains(t.getPosition())}getMap(){return this.map_}updateIcon(){var t=this.map_.getZoom(),e=this.markerClusterer_.getMaxZoom();if(e&&t>e)for(var s,i=0;s=this.markers_[i];i++)s.setMap(this.map_);else if(this.markers_.length<this.minClusterSize_)this.clusterIcon_.hide();else{var r=this.markerClusterer_.getStyles().length,h=this.markerClusterer_.getCalculator()(this.markers_,r);this.clusterIcon_.setCenter(this.center_),this.clusterIcon_.setSums(h),this.clusterIcon_.show()}}}class s{constructor(t,e,i){t.getMarkerClusterer().extend(s,google.maps.OverlayView),this.styles_=e,this.padding_=i||0,this.cluster_=t,this.center_=null,this.map_=t.getMap(),this.div_=null,this.sums_=null,this.visible_=!1,this.setMap(this.map_)}triggerClusterClick(){var t=this.cluster_.getBounds(),e=this.cluster_.getMarkerClusterer();google.maps.event.trigger(e.map_,"clusterclick",this.cluster_),e.isZoomOnClick()&&(this.map_.fitBounds(t),this.map_.setCenter(t.getCenter()))}onAdd(){if(this.div_=document.createElement("DIV"),this.visible_){var t=this.getPosFromLatLng_(this.center_);this.div_.style.cssText=this.createCss(t),this.div_.innerHTML=this.sums_.text}this.getPanes().overlayMouseTarget.appendChild(this.div_);var e=this;google.maps.event.addDomListener(this.div_,"click",(function(){e.triggerClusterClick()}))}getPosFromLatLng_(t){var e=this.getProjection().fromLatLngToDivPixel(t);return e.x-=parseInt(this.width_/2,10),e.y-=parseInt(this.height_/2,10),e}draw(){if(this.visible_){var t=this.getPosFromLatLng_(this.center_);this.div_.style.top=t.y+"px",this.div_.style.left=t.x+"px"}}hide(){this.div_&&(this.div_.style.display="none"),this.visible_=!1}show(){if(this.div_){var t=this.getPosFromLatLng_(this.center_);this.div_.style.cssText=this.createCss(t),this.div_.style.display=""}this.visible_=!0}remove(){this.setMap(null)}onRemove(){this.div_&&this.div_.parentNode&&(this.hide(),this.div_.parentNode.removeChild(this.div_),this.div_=null)}setSums(t){this.sums_=t,this.text_=t.text,this.index_=t.index,this.div_&&(this.div_.innerHTML=t.text),this.useStyle()}useStyle(){var t=Math.max(0,this.sums_.index-1);t=Math.min(this.styles_.length-1,t);var e=this.styles_[t];this.url_=e.url,this.height_=e.height,this.width_=e.width,this.textColor_=e.textColor,this.anchor_=e.anchor,this.textSize_=e.textSize,this.backgroundPosition_=e.backgroundPosition}setCenter(t){this.center_=t}createCss(t){var e=[];e.push("z-index:"+this.markerClusterer_.getZIndex()+";"),e.push("background-image:url("+this.url_+");");var s=this.backgroundPosition_?this.backgroundPosition_:"0 0";e.push("background-position:"+s+";"),"object"==typeof this.anchor_?("number"==typeof this.anchor_[0]&&this.anchor_[0]>0&&this.anchor_[0]<this.height_?e.push("height:"+(this.height_-this.anchor_[0])+"px; padding-top:"+this.anchor_[0]+"px;"):e.push("height:"+this.height_+"px; line-height:"+this.height_+"px;"),"number"==typeof this.anchor_[1]&&this.anchor_[1]>0&&this.anchor_[1]<this.width_?e.push("width:"+(this.width_-this.anchor_[1])+"px; padding-left:"+this.anchor_[1]+"px;"):e.push("width:"+this.width_+"px; text-align:center;")):e.push("height:"+this.height_+"px; line-height:"+this.height_+"px; width:"+this.width_+"px; text-align:center;");var i=this.textColor_?this.textColor_:"black",r=this.textSize_?this.textSize_:11;return e.push("cursor:pointer; top:"+t.y+"px; left:"+t.x+"px; color:"+i+"; position:absolute; font-size:"+r+"px; font-family:Arial,sans-serif; font-weight:bold"),e.join("")}}return t}(); |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).MarkerClusterer=e()}(this,(function(){"use strict";class t{constructor(e,s,i){this.extend(t,google.maps.OverlayView),this.map_=e,this.MARKER_CLUSTER_IMAGE_PATH_="../images/m",this.MARKER_CLUSTER_IMAGE_EXTENSION_="png",this.markers_=[],this.clusters_=[],this.sizes=[53,56,66,78,90],this.styles_=[],this.ready_=!1;var r=i||{};this.gridSize_=r.gridSize||60,this.minClusterSize_=r.minimumClusterSize||2,this.maxZoom_=r.maxZoom||null,this.styles_=r.styles||[],this.imagePath_=r.imagePath||this.MARKER_CLUSTER_IMAGE_PATH_,this.imageExtension_=r.imageExtension||this.MARKER_CLUSTER_IMAGE_EXTENSION_,this.zoomOnClick_=!0,null!=r.zoomOnClick&&(this.zoomOnClick_=r.zoomOnClick),this.averageCenter_=!1,null!=r.averageCenter&&(this.averageCenter_=r.averageCenter),this.setupStyles_(),this.setMap(e),this.prevZoom_=this.map_.getZoom();var h=this;google.maps.event.addListener(this.map_,"zoom_changed",(function(){var t=h.map_.getZoom(),e=h.map_.minZoom||0,s=Math.min(h.map_.maxZoom||100,h.map_.mapTypes[h.map_.getMapTypeId()].maxZoom);t=Math.min(Math.max(t,e),s),h.prevZoom_!=t&&(h.prevZoom_=t,h.resetViewport())})),google.maps.event.addListener(this.map_,"idle",(function(){h.redraw()})),s&&(s.length||Object.keys(s).length)&&this.addMarkers(s,!1)}extend(t,e){return function(t){for(var e in t.prototype)this.prototype[e]=t.prototype[e];return this}.apply(t,[e])}onAdd(){this.setReady_(!0)}draw(){}setupStyles_(){if(!this.styles_.length)for(var t,e=0;t=this.sizes[e];e++)this.styles_.push({url:this.imagePath_+(e+1)+"."+this.imageExtension_,height:t,width:t})}fitMapToMarkers(){for(var t,e=this.getMarkers(),s=new google.maps.LatLngBounds,i=0;t=e[i];i++)s.extend(t.getPosition());this.map_.fitBounds(s)}setStyles(t){this.styles_=t}getStyles(){return this.styles_}isZoomOnClick(){return this.zoomOnClick_}isAverageCenter(){return this.averageCenter_}getMarkers(){return this.markers_}getTotalMarkers(){return this.markers_.length}setMaxZoom(t){this.maxZoom_=t}getMaxZoom(){return this.maxZoom_}calculator_(t,e){for(var s=0,i=t.length,r=i;0!==r;)r=parseInt(r/10,10),s++;return{text:i,index:s=Math.min(s,e)}}setCalculator(t){this.calculator_=t}getCalculator(){return this.calculator_}addMarkers(t,e){if(t.length)for(let e,s=0;e=t[s];s++)this.pushMarkerTo_(e);else if(Object.keys(t).length)for(let e in t)this.pushMarkerTo_(t[e]);e||this.redraw()}pushMarkerTo_(t){if(t.isAdded=!1,t.draggable){var e=this;google.maps.event.addListener(t,"dragend",(function(){t.isAdded=!1,e.repaint()}))}this.markers_.push(t)}addMarker(t,e){this.pushMarkerTo_(t),e||this.redraw()}removeMarker_(t){var e=-1;if(this.markers_.indexOf)e=this.markers_.indexOf(t);else for(var s,i=0;s=this.markers_[i];i++)if(s==t){e=i;break}return-1!=e&&(t.setMap(null),this.markers_.splice(e,1),!0)}removeMarker(t,e){var s=this.removeMarker_(t);return!(e||!s)&&(this.resetViewport(),this.redraw(),!0)}removeMarkers(t,e){for(var s,i=t===this.getMarkers()?t.slice():t,r=!1,h=0;s=i[h];h++){var a=this.removeMarker_(s);r=r||a}if(!e&&r)return this.resetViewport(),this.redraw(),!0}setReady_(t){this.ready_||(this.ready_=t,this.createClusters_())}getTotalClusters(){return this.clusters_.length}getMap(){return this.map_}setMap(t){this.map_=t}getGridSize(){return this.gridSize_}setGridSize(t){this.gridSize_=t}getMinClusterSize(){return this.minClusterSize_}setMinClusterSize(t){this.minClusterSize_=t}getExtendedBounds(t){var e=this.getProjection(),s=new google.maps.LatLng(t.getNorthEast().lat(),t.getNorthEast().lng()),i=new google.maps.LatLng(t.getSouthWest().lat(),t.getSouthWest().lng()),r=e.fromLatLngToDivPixel(s);r.x+=this.gridSize_,r.y-=this.gridSize_;var h=e.fromLatLngToDivPixel(i);h.x-=this.gridSize_,h.y+=this.gridSize_;var a=e.fromDivPixelToLatLng(r),n=e.fromDivPixelToLatLng(h);return t.extend(a),t.extend(n),t}isMarkerInBounds_(t,e){return e.contains(t.getPosition())}clearMarkers(){this.resetViewport(!0),this.markers_=[]}resetViewport(t){for(let t,e=0;t=this.clusters_[e];e++)t.remove();for(let e,s=0;e=this.markers_[s];s++)e.isAdded=!1,t&&e.setMap(null);this.clusters_=[]}repaint(){var t=this.clusters_.slice();this.clusters_.length=0,this.resetViewport(),this.redraw(),setTimeout((function(){for(var e,s=0;e=t[s];s++)e.remove()}),0)}redraw(){this.createClusters_()}distanceBetweenPoints_(t,e){if(!t||!e)return 0;var s=(e.lat()-t.lat())*Math.PI/180,i=(e.lng()-t.lng())*Math.PI/180,r=Math.sin(s/2)*Math.sin(s/2)+Math.cos(t.lat()*Math.PI/180)*Math.cos(e.lat()*Math.PI/180)*Math.sin(i/2)*Math.sin(i/2);return 6371*(2*Math.atan2(Math.sqrt(r),Math.sqrt(1-r)))}addToClosestCluster_(t){for(var s,i=4e4,r=null,h=0;s=this.clusters_[h];h++){var a=s.getCenter();if(a){var n=this.distanceBetweenPoints_(a,t.getPosition());n<i&&(i=n,r=s)}}if(r&&r.isMarkerInClusterBounds(t))r.addMarker(t);else{var o=new e(this);o.addMarker(t),this.clusters_.push(o)}}createClusters_(){if(this.ready_)for(var t,e=new google.maps.LatLngBounds(this.map_.getBounds().getSouthWest(),this.map_.getBounds().getNorthEast()),s=this.getExtendedBounds(e),i=0;t=this.markers_[i];i++)!t.isAdded&&this.isMarkerInBounds_(t,s)&&this.addToClosestCluster_(t)}}class e{constructor(t){this.markerClusterer_=t,this.map_=t.getMap(),this.gridSize_=t.getGridSize(),this.minClusterSize_=t.getMinClusterSize(),this.averageCenter_=t.isAverageCenter(),this.center_=null,this.markers_=[],this.bounds_=null,this.clusterIcon_=new s(this,t.getStyles(),t.getGridSize())}isMarkerAlreadyAdded(t){if(this.markers_.indexOf)return-1!=this.markers_.indexOf(t);for(var e,s=0;e=this.markers_[s];s++)if(e==t)return!0;return!1}addMarker(t){if(this.isMarkerAlreadyAdded(t))return!1;if(this.center_){if(this.averageCenter_){var e=this.markers_.length+1,s=(this.center_.lat()*(e-1)+t.getPosition().lat())/e,i=(this.center_.lng()*(e-1)+t.getPosition().lng())/e;this.center_=new google.maps.LatLng(s,i),this.calculateBounds_()}}else this.center_=t.getPosition(),this.calculateBounds_();t.isAdded=!0,this.markers_.push(t);var r=this.markers_.length;if(r<this.minClusterSize_&&t.getMap()!=this.map_&&t.setMap(this.map_),r==this.minClusterSize_)for(var h=0;h<r;h++)this.markers_[h].setMap(null);return r>=this.minClusterSize_&&t.setMap(null),this.updateIcon(),!0}getMarkerClusterer(){return this.markerClusterer_}getBounds(){for(var t,e=new google.maps.LatLngBounds(this.center_,this.center_),s=this.getMarkers(),i=0;t=s[i];i++)e.extend(t.getPosition());return e}remove(){this.clusterIcon_.remove(),this.markers_.length=0,delete this.markers_}getSize(){return this.markers_.length}getMarkers(){return this.markers_}getCenter(){return this.center_}calculateBounds_(){var t=new google.maps.LatLngBounds(this.center_,this.center_);this.bounds_=this.markerClusterer_.getExtendedBounds(t)}isMarkerInClusterBounds(t){return this.bounds_.contains(t.getPosition())}getMap(){return this.map_}updateIcon(){var t=this.map_.getZoom(),e=this.markerClusterer_.getMaxZoom();if(e&&t>e)for(var s,i=0;s=this.markers_[i];i++)s.setMap(this.map_);else if(this.markers_.length<this.minClusterSize_)this.clusterIcon_.hide();else{var r=this.markerClusterer_.getStyles().length,h=this.markerClusterer_.getCalculator()(this.markers_,r);this.clusterIcon_.setCenter(this.center_),this.clusterIcon_.setSums(h),this.clusterIcon_.show()}}}class s{constructor(t,e,i){t.getMarkerClusterer().extend(s,google.maps.OverlayView),this.styles_=e,this.padding_=i||0,this.cluster_=t,this.center_=null,this.map_=t.getMap(),this.div_=null,this.sums_=null,this.visible_=!1,this.setMap(this.map_)}triggerClusterClick(){var t=this.cluster_.getBounds(),e=this.cluster_.getMarkerClusterer();google.maps.event.trigger(e.map_,"clusterclick",this.cluster_),e.isZoomOnClick()&&(this.map_.fitBounds(t),this.map_.setCenter(t.getCenter()))}onAdd(){if(this.div_=document.createElement("DIV"),this.visible_){var t=this.getPosFromLatLng_(this.center_);this.div_.style.cssText=this.createCss(t),this.div_.innerHTML=this.sums_.text}this.getPanes().overlayMouseTarget.appendChild(this.div_);var e=this;google.maps.event.addDomListener(this.div_,"click",(function(){e.triggerClusterClick()}))}getPosFromLatLng_(t){var e=this.getProjection().fromLatLngToDivPixel(t);return e.x-=parseInt(this.width_/2,10),e.y-=parseInt(this.height_/2,10),e}draw(){if(this.visible_){var t=this.getPosFromLatLng_(this.center_);this.div_.style.top=t.y+"px",this.div_.style.left=t.x+"px",this.div_.style.zIndex=google.maps.Marker.MAX_ZINDEX+1}}hide(){this.div_&&(this.div_.style.display="none"),this.visible_=!1}show(){if(this.div_){var t=this.getPosFromLatLng_(this.center_);this.div_.style.cssText=this.createCss(t),this.div_.style.display=""}this.visible_=!0}remove(){this.setMap(null)}onRemove(){this.div_&&this.div_.parentNode&&(this.hide(),this.div_.parentNode.removeChild(this.div_),this.div_=null)}setSums(t){this.sums_=t,this.text_=t.text,this.index_=t.index,this.div_&&(this.div_.innerHTML=t.text),this.useStyle()}useStyle(){var t=Math.max(0,this.sums_.index-1);t=Math.min(this.styles_.length-1,t);var e=this.styles_[t];this.url_=e.url,this.height_=e.height,this.width_=e.width,this.textColor_=e.textColor,this.anchor_=e.anchor,this.textSize_=e.textSize,this.backgroundPosition_=e.backgroundPosition}setCenter(t){this.center_=t}createCss(t){var e=[];e.push("background-image:url("+this.url_+");");var s=this.backgroundPosition_?this.backgroundPosition_:"0 0";e.push("background-position:"+s+";"),"object"==typeof this.anchor_?("number"==typeof this.anchor_[0]&&this.anchor_[0]>0&&this.anchor_[0]<this.height_?e.push("height:"+(this.height_-this.anchor_[0])+"px; padding-top:"+this.anchor_[0]+"px;"):e.push("height:"+this.height_+"px; line-height:"+this.height_+"px;"),"number"==typeof this.anchor_[1]&&this.anchor_[1]>0&&this.anchor_[1]<this.width_?e.push("width:"+(this.width_-this.anchor_[1])+"px; padding-left:"+this.anchor_[1]+"px;"):e.push("width:"+this.width_+"px; text-align:center;")):e.push("height:"+this.height_+"px; line-height:"+this.height_+"px; width:"+this.width_+"px; text-align:center;");var i=this.textColor_?this.textColor_:"black",r=this.textSize_?this.textSize_:11;return e.push("cursor:pointer; top:"+t.y+"px; left:"+t.x+"px; color:"+i+"; position:absolute; font-size:"+r+"px; font-family:Arial,sans-serif; font-weight:bold"),e.join("")}}return t})); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).MarkerClusterer=e()}(this,(function(){"use strict";class t{constructor(e,s,i){this.extend(t,google.maps.OverlayView),this.map_=e,this.MARKER_CLUSTER_IMAGE_PATH_="../images/m",this.MARKER_CLUSTER_IMAGE_EXTENSION_="png",this.markers_=[],this.clusters_=[],this.sizes=[53,56,66,78,90],this.styles_=[],this.ready_=!1;var r=i||{};this.zIndex_=r.zIndex||google.maps.Marker.MAX_ZINDEX+1,this.gridSize_=r.gridSize||60,this.minClusterSize_=r.minimumClusterSize||2,this.maxZoom_=r.maxZoom||null,this.styles_=r.styles||[],this.imagePath_=r.imagePath||this.MARKER_CLUSTER_IMAGE_PATH_,this.imageExtension_=r.imageExtension||this.MARKER_CLUSTER_IMAGE_EXTENSION_,this.zoomOnClick_=!0,null!=r.zoomOnClick&&(this.zoomOnClick_=r.zoomOnClick),this.averageCenter_=!1,null!=r.averageCenter&&(this.averageCenter_=r.averageCenter),this.setupStyles_(),this.setMap(e),this.prevZoom_=this.map_.getZoom();var h=this;google.maps.event.addListener(this.map_,"zoom_changed",(function(){var t=h.map_.getZoom(),e=h.map_.minZoom||0,s=Math.min(h.map_.maxZoom||100,h.map_.mapTypes[h.map_.getMapTypeId()].maxZoom);t=Math.min(Math.max(t,e),s),h.prevZoom_!=t&&(h.prevZoom_=t,h.resetViewport())})),google.maps.event.addListener(this.map_,"idle",(function(){h.redraw()})),s&&(s.length||Object.keys(s).length)&&this.addMarkers(s,!1)}extend(t,e){return function(t){for(var e in t.prototype)this.prototype[e]=t.prototype[e];return this}.apply(t,[e])}onAdd(){this.setReady_(!0)}draw(){}setupStyles_(){if(!this.styles_.length)for(var t,e=0;t=this.sizes[e];e++)this.styles_.push({url:this.imagePath_+(e+1)+"."+this.imageExtension_,height:t,width:t})}fitMapToMarkers(){for(var t,e=this.getMarkers(),s=new google.maps.LatLngBounds,i=0;t=e[i];i++)s.extend(t.getPosition());this.map_.fitBounds(s)}setZIndex(t){this.zIndex_=t}getZIndex(){return this.zIndex_}setStyles(t){this.styles_=t}getStyles(){return this.styles_}isZoomOnClick(){return this.zoomOnClick_}isAverageCenter(){return this.averageCenter_}getMarkers(){return this.markers_}getTotalMarkers(){return this.markers_.length}setMaxZoom(t){this.maxZoom_=t}getMaxZoom(){return this.maxZoom_}calculator_(t,e){for(var s=0,i=t.length,r=i;0!==r;)r=parseInt(r/10,10),s++;return{text:i,index:s=Math.min(s,e)}}setCalculator(t){this.calculator_=t}getCalculator(){return this.calculator_}addMarkers(t,e){if(t.length)for(let e,s=0;e=t[s];s++)this.pushMarkerTo_(e);else if(Object.keys(t).length)for(let e in t)this.pushMarkerTo_(t[e]);e||this.redraw()}pushMarkerTo_(t){if(t.isAdded=!1,t.draggable){var e=this;google.maps.event.addListener(t,"dragend",(function(){t.isAdded=!1,e.repaint()}))}this.markers_.push(t)}addMarker(t,e){this.pushMarkerTo_(t),e||this.redraw()}removeMarker_(t){var e=-1;if(this.markers_.indexOf)e=this.markers_.indexOf(t);else for(var s,i=0;s=this.markers_[i];i++)if(s==t){e=i;break}return-1!=e&&(t.setMap(null),this.markers_.splice(e,1),!0)}removeMarker(t,e){var s=this.removeMarker_(t);return!(e||!s)&&(this.resetViewport(),this.redraw(),!0)}removeMarkers(t,e){for(var s,i=t===this.getMarkers()?t.slice():t,r=!1,h=0;s=i[h];h++){var a=this.removeMarker_(s);r=r||a}if(!e&&r)return this.resetViewport(),this.redraw(),!0}setReady_(t){this.ready_||(this.ready_=t,this.createClusters_())}getTotalClusters(){return this.clusters_.length}getMap(){return this.map_}setMap(t){this.map_=t}getGridSize(){return this.gridSize_}setGridSize(t){this.gridSize_=t}getMinClusterSize(){return this.minClusterSize_}setMinClusterSize(t){this.minClusterSize_=t}getExtendedBounds(t){var e=this.getProjection(),s=new google.maps.LatLng(t.getNorthEast().lat(),t.getNorthEast().lng()),i=new google.maps.LatLng(t.getSouthWest().lat(),t.getSouthWest().lng()),r=e.fromLatLngToDivPixel(s);r.x+=this.gridSize_,r.y-=this.gridSize_;var h=e.fromLatLngToDivPixel(i);h.x-=this.gridSize_,h.y+=this.gridSize_;var a=e.fromDivPixelToLatLng(r),n=e.fromDivPixelToLatLng(h);return t.extend(a),t.extend(n),t}isMarkerInBounds_(t,e){return e.contains(t.getPosition())}clearMarkers(){this.resetViewport(!0),this.markers_=[]}resetViewport(t){for(let t,e=0;t=this.clusters_[e];e++)t.remove();for(let e,s=0;e=this.markers_[s];s++)e.isAdded=!1,t&&e.setMap(null);this.clusters_=[]}repaint(){var t=this.clusters_.slice();this.clusters_.length=0,this.resetViewport(),this.redraw(),setTimeout((function(){for(var e,s=0;e=t[s];s++)e.remove()}),0)}redraw(){this.createClusters_()}distanceBetweenPoints_(t,e){if(!t||!e)return 0;var s=(e.lat()-t.lat())*Math.PI/180,i=(e.lng()-t.lng())*Math.PI/180,r=Math.sin(s/2)*Math.sin(s/2)+Math.cos(t.lat()*Math.PI/180)*Math.cos(e.lat()*Math.PI/180)*Math.sin(i/2)*Math.sin(i/2);return 6371*(2*Math.atan2(Math.sqrt(r),Math.sqrt(1-r)))}addToClosestCluster_(t){for(var s,i=4e4,r=null,h=0;s=this.clusters_[h];h++){var a=s.getCenter();if(a){var n=this.distanceBetweenPoints_(a,t.getPosition());n<i&&(i=n,r=s)}}if(r&&r.isMarkerInClusterBounds(t))r.addMarker(t);else{var o=new e(this);o.addMarker(t),this.clusters_.push(o)}}createClusters_(){if(this.ready_)for(var t,e=new google.maps.LatLngBounds(this.map_.getBounds().getSouthWest(),this.map_.getBounds().getNorthEast()),s=this.getExtendedBounds(e),i=0;t=this.markers_[i];i++)!t.isAdded&&this.isMarkerInBounds_(t,s)&&this.addToClosestCluster_(t)}}class e{constructor(t){this.markerClusterer_=t,this.map_=t.getMap(),this.gridSize_=t.getGridSize(),this.minClusterSize_=t.getMinClusterSize(),this.averageCenter_=t.isAverageCenter(),this.center_=null,this.markers_=[],this.bounds_=null,this.clusterIcon_=new s(this,t.getStyles(),t.getGridSize())}isMarkerAlreadyAdded(t){if(this.markers_.indexOf)return-1!=this.markers_.indexOf(t);for(var e,s=0;e=this.markers_[s];s++)if(e==t)return!0;return!1}addMarker(t){if(this.isMarkerAlreadyAdded(t))return!1;if(this.center_){if(this.averageCenter_){var e=this.markers_.length+1,s=(this.center_.lat()*(e-1)+t.getPosition().lat())/e,i=(this.center_.lng()*(e-1)+t.getPosition().lng())/e;this.center_=new google.maps.LatLng(s,i),this.calculateBounds_()}}else this.center_=t.getPosition(),this.calculateBounds_();t.isAdded=!0,this.markers_.push(t);var r=this.markers_.length;if(r<this.minClusterSize_&&t.getMap()!=this.map_&&t.setMap(this.map_),r==this.minClusterSize_)for(var h=0;h<r;h++)this.markers_[h].setMap(null);return r>=this.minClusterSize_&&t.setMap(null),this.updateIcon(),!0}getMarkerClusterer(){return this.markerClusterer_}getBounds(){for(var t,e=new google.maps.LatLngBounds(this.center_,this.center_),s=this.getMarkers(),i=0;t=s[i];i++)e.extend(t.getPosition());return e}remove(){this.clusterIcon_.remove(),this.markers_.length=0,delete this.markers_}getSize(){return this.markers_.length}getMarkers(){return this.markers_}getCenter(){return this.center_}calculateBounds_(){var t=new google.maps.LatLngBounds(this.center_,this.center_);this.bounds_=this.markerClusterer_.getExtendedBounds(t)}isMarkerInClusterBounds(t){return this.bounds_.contains(t.getPosition())}getMap(){return this.map_}updateIcon(){var t=this.map_.getZoom(),e=this.markerClusterer_.getMaxZoom();if(e&&t>e)for(var s,i=0;s=this.markers_[i];i++)s.setMap(this.map_);else if(this.markers_.length<this.minClusterSize_)this.clusterIcon_.hide();else{var r=this.markerClusterer_.getStyles().length,h=this.markerClusterer_.getCalculator()(this.markers_,r);this.clusterIcon_.setCenter(this.center_),this.clusterIcon_.setSums(h),this.clusterIcon_.show()}}}class s{constructor(t,e,i){t.getMarkerClusterer().extend(s,google.maps.OverlayView),this.styles_=e,this.padding_=i||0,this.cluster_=t,this.center_=null,this.map_=t.getMap(),this.div_=null,this.sums_=null,this.visible_=!1,this.setMap(this.map_)}triggerClusterClick(){var t=this.cluster_.getBounds(),e=this.cluster_.getMarkerClusterer();google.maps.event.trigger(e.map_,"clusterclick",this.cluster_),e.isZoomOnClick()&&(this.map_.fitBounds(t),this.map_.setCenter(t.getCenter()))}onAdd(){if(this.div_=document.createElement("DIV"),this.visible_){var t=this.getPosFromLatLng_(this.center_);this.div_.style.cssText=this.createCss(t),this.div_.innerHTML=this.sums_.text}this.getPanes().overlayMouseTarget.appendChild(this.div_);var e=this;google.maps.event.addDomListener(this.div_,"click",(function(){e.triggerClusterClick()}))}getPosFromLatLng_(t){var e=this.getProjection().fromLatLngToDivPixel(t);return e.x-=parseInt(this.width_/2,10),e.y-=parseInt(this.height_/2,10),e}draw(){if(this.visible_){var t=this.getPosFromLatLng_(this.center_);this.div_.style.top=t.y+"px",this.div_.style.left=t.x+"px"}}hide(){this.div_&&(this.div_.style.display="none"),this.visible_=!1}show(){if(this.div_){var t=this.getPosFromLatLng_(this.center_);this.div_.style.cssText=this.createCss(t),this.div_.style.display=""}this.visible_=!0}remove(){this.setMap(null)}onRemove(){this.div_&&this.div_.parentNode&&(this.hide(),this.div_.parentNode.removeChild(this.div_),this.div_=null)}setSums(t){this.sums_=t,this.text_=t.text,this.index_=t.index,this.div_&&(this.div_.innerHTML=t.text),this.useStyle()}useStyle(){var t=Math.max(0,this.sums_.index-1);t=Math.min(this.styles_.length-1,t);var e=this.styles_[t];this.url_=e.url,this.height_=e.height,this.width_=e.width,this.textColor_=e.textColor,this.anchor_=e.anchor,this.textSize_=e.textSize,this.backgroundPosition_=e.backgroundPosition}setCenter(t){this.center_=t}createCss(t){var e=[];e.push("z-index:"+this.markerClusterer_.getZIndex()+";"),e.push("background-image:url("+this.url_+");");var s=this.backgroundPosition_?this.backgroundPosition_:"0 0";e.push("background-position:"+s+";"),"object"==typeof this.anchor_?("number"==typeof this.anchor_[0]&&this.anchor_[0]>0&&this.anchor_[0]<this.height_?e.push("height:"+(this.height_-this.anchor_[0])+"px; padding-top:"+this.anchor_[0]+"px;"):e.push("height:"+this.height_+"px; line-height:"+this.height_+"px;"),"number"==typeof this.anchor_[1]&&this.anchor_[1]>0&&this.anchor_[1]<this.width_?e.push("width:"+(this.width_-this.anchor_[1])+"px; padding-left:"+this.anchor_[1]+"px;"):e.push("width:"+this.width_+"px; text-align:center;")):e.push("height:"+this.height_+"px; line-height:"+this.height_+"px; width:"+this.width_+"px; text-align:center;");var i=this.textColor_?this.textColor_:"black",r=this.textSize_?this.textSize_:11;return e.push("cursor:pointer; top:"+t.y+"px; left:"+t.x+"px; color:"+i+"; position:absolute; font-size:"+r+"px; font-family:Arial,sans-serif; font-weight:bold"),e.join("")}}return t})); |
{ | ||
"name": "@google/markerclusterer", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"description": "The library creates and manages per-zoom-level clusters for large amounts of markers.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -49,2 +49,4 @@ /** | ||
* is shown. | ||
* 'zIndex': (number) the z-index of a cluster. | ||
* Default: google.maps.Marker.MAX_ZINDEX + 1 | ||
* 'styles': (object) An object that has style properties: | ||
@@ -110,2 +112,7 @@ * 'url': (string) The image url. | ||
* @type {number} | ||
*/ | ||
this.zIndex_ = options["zIndex"] || google.maps.Marker.MAX_ZINDEX + 1; | ||
/** | ||
* @type {number} | ||
* @private | ||
@@ -266,2 +273,16 @@ */ | ||
/** | ||
* @param {number} zIndex | ||
*/ | ||
setZIndex(zIndex) { | ||
this.zIndex_ = zIndex; | ||
} | ||
/** | ||
* @return {number} | ||
*/ | ||
getZIndex() { | ||
return this.zIndex_; | ||
} | ||
/** | ||
* Sets the styles. | ||
@@ -1087,3 +1108,2 @@ * | ||
this.div_.style.left = pos.x + "px"; | ||
this.div_.style.zIndex = google.maps.Marker.MAX_ZINDEX + 1; | ||
} | ||
@@ -1184,2 +1204,3 @@ } | ||
var style = []; | ||
style.push("z-index:" + this.markerClusterer_.getZIndex() + ";"); | ||
style.push("background-image:url(" + this.url_ + ");"); | ||
@@ -1186,0 +1207,0 @@ var backgroundPosition = this.backgroundPosition_ |
85269
2343