ips.templates.set('pagesmapwidget.map.loadingRows'," <li class='ipsDataItem ipsDataItem_loading mapWidgetRow_loading'>  <div>   <span></span>   <span></span>  </div> </li>");ips.templates.set('pagesmapwidget.map.noLocationMatch'," <li class='ipsType_light'>No locations found</li>");ips.templates.set('pagesmapwidget.map.noTitleMatch'," <li class='ipsType_light'>No records found</li>");ips.templates.set('pagesmapwidget.map.searchError'," <li class='ipsType_light'>Sorry, there was an error searching</li>");ips.templates.set('pagesmapwidget.map.locationRow'," <li data-role='locationMatch' data-corner1='{{corner1}}' data-corner2='{{corner2}}' class='pagesmapwidgetMapbox_locationResult'>{{placeName}}</li>");ips.templates.set('pagesmapwidget.map.titleRow'," <li data-role='titleMatch' data-lat='{{lat}}' data-long='{{long}}' data-id='{{id}}' class='{{typeClass}}'>{{placeName}}</li>");ips.templates.set('pagesmapwidget.map.noLocationRows'," <p class='ipsType_normal ipsType_light ipsType_large ipsType_center ipsSpacer_both ipsSpacer_double'>  {{#lang}}mapWidgetNone{{/lang}} </p>");;
;(function($,_,undefined){"use strict";ips.controller.register('pagesmapwidget.front.widget.map',{_mapReady:false,_map:null,_timer:null,_keypressTimeout:null,_lastQuery:'',_ajax:null,_titleAjax:null,_ignoreMapMovement:false,_currentLanguage:null,_initialURL:null,_ignoredTypes:['point_of_interest','park','airport','natural_feature'],_databaseId:null,_fieldId:null,_categoryId:null,markers:[],initialize:function(){this.on('click','#mapWidgetGeolocate',this.geoLocate);this.on('submit','#search_mapWidget',this.submitSearch);this.on('focus','#search_mapWidget',this.focusSearch);this.on('blur','#search_mapWidget',this.blurSearch);this.on('click','[data-role="locationMatch"]',this.clickLocationMatch);this.on('click','[data-role="titleMatch"]',this.clickTitleMatch);this.on('click','[data-role="clearSearch"]',this.clearSearch);this.on(window,'resize',this.positionResultsPopup)
this.setup();},setup:function(){var self=this;this._initialURL=window.location.href;this._databaseId=this.scope.attr('data-database');this._fieldId=this.scope.attr('data-field');this._categoryId=this.scope.attr('data-category');ips.loader.get(['https://maps.googleapis.com/maps/api/js?key='+ips.getSetting('mapApiKey')]).then(function(){self._setUpMap();self._setUpMapEvents();self._mapReady=true;});if(!navigator.geolocation){this.scope.find('#mapWidgetGeolocate').hide();}},_openResult:function(lat,long,id){var self=this;this._ignoreMapMovement=true;var latLng=new google.maps.LatLng(lat,long);this._map.setCenter(latLng);var maxZoomService=new google.maps.MaxZoomService();var self=this;maxZoomService.getMaxZoomAtLatLng(latLng,(result)=>{self._map.setZoom(result.zoom-1);});this._ignoreMapMovement=false;_.each(this.markers,function(obj){if(obj.realID==id){new google.maps.event.trigger(obj,'click');}});return;},focusSearch:function(e){if(!this._mapReady){Debug.log('map not ready');return;}
clearTimeout(this._keypressTimeout);this._keypressTimeout=setInterval(_.bind(this._doSearch,this),300);if($.trim(this.scope.find('#search_map').val())!==''){this._openResultsList();}else{this.scope.find('[data-role="clearSearch"]').animate({opacity:0});}},blurSearch:function(e){clearTimeout(this._keypressTimeout);},submitSearch:function(e){e.preventDefault();},clearSearch:function(e){if(e){e.preventDefault();}
this._ignoreMapMovement=true;this._map.setCenter(new google.maps.LatLng(37.0902,-95.7129));this._map.setZoom(2);this._ignoreMapMovement=false;if(this.scope.find('[data-role="searchResults"]:visible').length){this._closeResultsList();}
this.scope.find('#search_map').val('');this.scope.find('[data-role="clearSearch"]').animate({opacity:0});this._getResults({});},_doSearch:function(){var self=this;var query=$.trim(this.scope.find('#search_map').val());if(this._lastQuery==query||query==''){return;}
this.positionResultsPopup();this.scope.find('[data-role="clearSearch"]').animate({opacity:1});this._lastQuery=query;this._geocoder.geocode({address:query},_.bind(this._showLocations,this));if(this._titleAjax&&_.isFunction(this._titleAjax.abort)){this._titleAjax.abort();}
this.scope.find('[data-role="titleResults"]').html("<li><span class='ipsType_light'>Searching...</span></li>");this._titleAjax=ips.getAjax()(ips.getSetting('baseURL')+'index.php?app=pagesmapwidget&module=map&controller=results',{data:{title:encodeURIComponent(query),database:this._databaseId,field:this._fieldId,category:this._categoryId}}).done(function(response){var results=[];if(!response.results.length){self.scope.find('[data-role="titleResults"]').html(ips.templates.render('pagesmapwidget.map.noTitleMatch'));return;}
for(var i=0;i<response.results.length;i++){results.push(ips.templates.render('pagesmapwidget.map.titleRow',{placeName:response.results[i].title,lat:response.results[i].lat,long:response.results[i].long,id:response.results[i].id,typeClass:'mapWidget_titleResult'}));}
self.scope.find('[data-role="titleResults"]').html(results.join(''));}).fail(function(){self.scope.find('[data-role="titleResults"]').html(ips.templates.render('pagesmapwidget.map.searchError'));});},positionResultsPopup:function(){var searchBox=this.scope.find('#search_mapWidget');var pos=ips.utils.position.getElemPosition(searchBox);var dims=ips.utils.position.getElemDims(searchBox);var results=this.scope.find('[data-role="searchResults"]');results.css({top:pos.offsetPos.top+dims.outerHeight+'px',left:pos.offsetPos.left+'px',width:dims.outerWidth+'px'});},_showLocations:function(data,status){var results=this.scope.find('[data-role="locationResults"]');var searchBox=this.scope.find('#search_mapWidget');var pos=ips.utils.position.getElemPosition(searchBox);var dims=ips.utils.position.getElemDims(searchBox);results.css({top:pos.offsetPos.top+dims.outerHeight+'px',left:pos.offsetPos.left+'px',width:dims.outerWidth+'px'});if(status!=='OK'||!results.length){results.html(ips.templates.render('pagesmapwidget.map.noLocationMatch'));}else{var resultsList=[];for(var i=0;i<data.length;i++){if(resultsList.length==5){break;}
if(data[i].types.length){for(var j=0;j<data[i].types.length;j++){if(this._ignoredTypes.indexOf(data[i].types[j])!==-1){continue;}}}
var thisLocation=data[i].geometry.viewport.toJSON();resultsList.push(ips.templates.render('pagesmapwidget.map.locationRow',{placeName:(data[i].formatted_address),corner1:thisLocation.north+','+thisLocation.west,corner2:thisLocation.south+','+thisLocation.east}));}
if(!resultsList.length){results.html(ips.templates.render('pagesmapwidget.map.noLocationMatch'));}else{results.html(resultsList.join(''));}}
this._openResultsList(true);},clickLocationMatch:function(e){var corner1=$(e.currentTarget).attr('data-corner1').split(',');var corner2=$(e.currentTarget).attr('data-corner2').split(',');var bound1=new google.maps.LatLng(parseFloat(corner1[0]),parseFloat(corner1[1]));var bound2=new google.maps.LatLng(parseFloat(corner2[0]),parseFloat(corner2[1]));this._map.fitBounds(new google.maps.LatLngBounds(bound1,bound2));var name=$(e.currentTarget).text();this.scope.find('#search_map').val(name).blur();this._closeResultsList();},clickTitleMatch:function(e){var lat=parseFloat($(e.currentTarget).attr('data-lat'));var long=parseFloat($(e.currentTarget).attr('data-long'));var id=$(e.currentTarget).attr('data-id');var name=$(e.currentTarget).text();this.scope.find('#search_map').val(name).blur();this._closeResultsList();this._openResult(lat,long,id);},_openResultsList:function(immediate){this.scope.find('[data-role="searchResults"]').show();},_closeResultsList:function(){this.scope.find('[data-role="searchResults"]').hide();},toggleCheckbox:function(e){if(!this._mapReady){return;}
this._startSearchTimer();},geoLocate:function(e){if(e){e.preventDefault();}
if(!this._mapReady){return;}
if(navigator.geolocation){navigator.geolocation.getCurrentPosition(_.bind(this._locationFound,this),_.bind(this._locationError,this));this.scope.find('#mapWidgetGeolocate').find('[data-role="button"]').hide().end().find('[data-role="loading"]').show();this._closeResultsList();}},_locationFound:function(position){var pos={lat:position.coords.latitude,lng:position.coords.longitude};this._map.setCenter(pos);this.scope.find('#mapWidgetGeolocate').find('[data-role="loading"]').hide().end().find('[data-role="button"]').show();},_locationError:function(){this.scope.find('#mapWidgetGeolocate').html(this._geolocateText);ips.ui.alert.show({type:'alert',message:ips.getString('geolocationError'),icon:'warn'});},zoomStart:function(e){if(!this._ignoreMapMovement){this._closeResultsList();}},zoomEnd:function(e){if(!this._ignoreMapMovement){this._startSearchTimer();}},dragStart:function(e){if(!this._ignoreMapMovement){this._closeResultsList();}},dragEnd:function(e){if(!this._ignoreMapMovement){this._startSearchTimer();}},_startSearchTimer:function(){clearTimeout(this._timer);this._timer=setTimeout(_.bind(this._findResultsByBoundingBox,this),750);},_findResultsByBoundingBox:function(){var self=this;var bounds=this._map.getBounds();var center=this._map.getCenter();var data={minLon:bounds.getSouthWest().lng(),maxLon:bounds.getNorthEast().lng(),minLat:bounds.getSouthWest().lat(),maxLat:bounds.getNorthEast().lat(),centerLat:center.lat,centerLon:center.lng};this._getResults(data);},_getResults:function(data){var self=this;if(this._ajax&&_.isFunction(this._ajax.abort)){this._ajax.abort();}
data.database=this._databaseId;data.field=this._fieldId;data.category=this._categoryId;this._ajax=ips.getAjax()(ips.getSetting('baseURL')+'index.php?app=pagesmapwidget&module=map&controller=results',{data:data}).done(function(response){var countString='mapWidgetCount';self.scope.find('[data-role="recordsFound"]').show().text(ips.pluralize(ips.getString(countString),response.count));if(parseInt(response.count)<1){self.scope.find('[data-role="resultsContainer"]').html(ips.templates.render('pagesmapwidget.map.noLocationRows'));return;}
var html=[];for(var i=0;i<response.results.length;i++){html.push(response.results[i].html);}
self.scope.find('[data-role="resultsContainer"]').html(html.join(''));});},_setUpMapEvents:function(){this._map.addListener('zoomstart',_.bind(this.zoomStart,this));this._map.addListener('zoomend',_.bind(this.zoomEnd,this));this._map.addListener('dragstart',_.bind(this.dragStart,this));this._map.addListener('dragend',_.bind(this.dragEnd,this));},_setUpMap:function(){var mapDiv=this.scope.find('#mapWidget');var map=new google.maps.Map(mapDiv.get(0),{center:{lat:37.0902,lng:-95.7129},zoom:2,fullscreenControl:false,mapTypeControl:false});this._map=map;this._geocoder=new google.maps.Geocoder();var bounds=new google.maps.LatLngBounds();var infowindow=new google.maps.InfoWindow({content:ips.getString('loading')});var markerData=$.parseJSON(mapDiv.attr('data-markers'));for(var id in markerData){var pieces=id.split('-');var type=pieces[0];var realID=pieces[1];var marker=new google.maps.Marker({position:new google.maps.LatLng(markerData[id].lat,markerData[id].long),title:markerData[id].title,typeID:id,id:id,realID:realID,icon:ips.getSetting('mapIcon')});this.markers.push(marker);bounds.extend(marker.getPosition());if(mapDiv.attr('data-contentUrl')){marker.addListener('click',function(){Debug.log(this);infowindow.setContent(ips.getString('loading'))
infowindow.open(map,this);ips.getAjax()(mapDiv.attr('data-contentUrl')+this.realID,{data:{database:this._databaseId,field:this._fieldId,category:this._categoryId}}).done(function(response){infowindow.setContent(response);});});}}
map.setCenter(bounds.getCenter());map.fitBounds(bounds);map.setZoom(map.getZoom()-1);if(map.getZoom()>15){map.setZoom(15);}
var markerCluster=new MarkerClusterer(map,this.markers);}});}(jQuery,_));;
function MarkerClusterer(map,opt_markers,opt_options){this.extend(MarkerClusterer,google.maps.OverlayView);this.map_=map;this.markers_=[];this.clusters_=[];this.sizes=[53,56,66,78,90];this.styles_=[];this.ready_=false;var options=opt_options||{};this.gridSize_=options['gridSize']||60;this.minClusterSize_=options['minimumClusterSize']||2;this.maxZoom_=options['maxZoom']||null;this.styles_=options['styles']||[];this.imagePath_=options['imagePath']||this.MARKER_CLUSTER_IMAGE_PATH_;this.imageExtension_=options['imageExtension']||this.MARKER_CLUSTER_IMAGE_EXTENSION_;this.zoomOnClick_=true;if(options['zoomOnClick']!=undefined){this.zoomOnClick_=options['zoomOnClick'];}
this.averageCenter_=false;if(options['averageCenter']!=undefined){this.averageCenter_=options['averageCenter'];}
this.setupStyles_();this.setMap(map);this.prevZoom_=this.map_.getZoom();var that=this;google.maps.event.addListener(this.map_,'zoom_changed',function(){var zoom=that.map_.getZoom();var minZoom=that.map_.minZoom||0;var maxZoom=Math.min(that.map_.maxZoom||100,that.map_.mapTypes[that.map_.getMapTypeId()].maxZoom);zoom=Math.min(Math.max(zoom,minZoom),maxZoom);if(that.prevZoom_!=zoom){that.prevZoom_=zoom;that.resetViewport();}});google.maps.event.addListener(this.map_,'idle',function(){that.redraw();});if(opt_markers&&(opt_markers.length||Object.keys(opt_markers).length)){this.addMarkers(opt_markers,false);}}
MarkerClusterer.prototype.MARKER_CLUSTER_IMAGE_PATH_='../images/m';MarkerClusterer.prototype.MARKER_CLUSTER_IMAGE_EXTENSION_='png';MarkerClusterer.prototype.extend=function(obj1,obj2){return(function(object){for(var property in object.prototype){this.prototype[property]=object.prototype[property];}
return this;}).apply(obj1,[obj2]);};MarkerClusterer.prototype.onAdd=function(){this.setReady_(true);};MarkerClusterer.prototype.draw=function(){};MarkerClusterer.prototype.setupStyles_=function(){if(this.styles_.length){return;}
for(var i=0,size;size=this.sizes[i];i++){this.styles_.push({url:ips.getSetting('cluster_m'+(i+1)),height:size,width:size});}};MarkerClusterer.prototype.fitMapToMarkers=function(){var markers=this.getMarkers();var bounds=new google.maps.LatLngBounds();for(var i=0,marker;marker=markers[i];i++){bounds.extend(marker.getPosition());}
this.map_.fitBounds(bounds);};MarkerClusterer.prototype.setStyles=function(styles){this.styles_=styles;};MarkerClusterer.prototype.getStyles=function(){return this.styles_;};MarkerClusterer.prototype.isZoomOnClick=function(){return this.zoomOnClick_;};MarkerClusterer.prototype.isAverageCenter=function(){return this.averageCenter_;};MarkerClusterer.prototype.getMarkers=function(){return this.markers_;};MarkerClusterer.prototype.getTotalMarkers=function(){return this.markers_.length;};MarkerClusterer.prototype.setMaxZoom=function(maxZoom){this.maxZoom_=maxZoom;};MarkerClusterer.prototype.getMaxZoom=function(){return this.maxZoom_;};MarkerClusterer.prototype.calculator_=function(markers,numStyles){var index=0;var count=markers.length;var dv=count;while(dv!==0){dv=parseInt(dv / 10,10);index++;}
index=Math.min(index,numStyles);return{text:count,index:index};};MarkerClusterer.prototype.setCalculator=function(calculator){this.calculator_=calculator;};MarkerClusterer.prototype.getCalculator=function(){return this.calculator_;};MarkerClusterer.prototype.addMarkers=function(markers,opt_nodraw){if(markers.length){for(var i=0,marker;marker=markers[i];i++){this.pushMarkerTo_(marker);}}else if(Object.keys(markers).length){for(var marker in markers){this.pushMarkerTo_(markers[marker]);}}
if(!opt_nodraw){this.redraw();}};MarkerClusterer.prototype.pushMarkerTo_=function(marker){marker.isAdded=false;if(marker['draggable']){var that=this;google.maps.event.addListener(marker,'dragend',function(){marker.isAdded=false;that.repaint();});}
this.markers_.push(marker);};MarkerClusterer.prototype.addMarker=function(marker,opt_nodraw){this.pushMarkerTo_(marker);if(!opt_nodraw){this.redraw();}};MarkerClusterer.prototype.removeMarker_=function(marker){var index=-1;if(this.markers_.indexOf){index=this.markers_.indexOf(marker);}else{for(var i=0,m;m=this.markers_[i];i++){if(m==marker){index=i;break;}}}
if(index==-1){return false;}
marker.setMap(null);this.markers_.splice(index,1);return true;};MarkerClusterer.prototype.removeMarker=function(marker,opt_nodraw){var removed=this.removeMarker_(marker);if(!opt_nodraw&&removed){this.resetViewport();this.redraw();return true;}else{return false;}};MarkerClusterer.prototype.removeMarkers=function(markers,opt_nodraw){var removed=false;for(var i=0,marker;marker=markers[i];i++){var r=this.removeMarker_(marker);removed=removed||r;}
if(!opt_nodraw&&removed){this.resetViewport();this.redraw();return true;}};MarkerClusterer.prototype.setReady_=function(ready){if(!this.ready_){this.ready_=ready;this.createClusters_();}};MarkerClusterer.prototype.getTotalClusters=function(){return this.clusters_.length;};MarkerClusterer.prototype.getMap=function(){return this.map_;};MarkerClusterer.prototype.setMap=function(map){this.map_=map;};MarkerClusterer.prototype.getGridSize=function(){return this.gridSize_;};MarkerClusterer.prototype.setGridSize=function(size){this.gridSize_=size;};MarkerClusterer.prototype.getMinClusterSize=function(){return this.minClusterSize_;};MarkerClusterer.prototype.setMinClusterSize=function(size){this.minClusterSize_=size;};MarkerClusterer.prototype.getExtendedBounds=function(bounds){var projection=this.getProjection();var tr=new google.maps.LatLng(bounds.getNorthEast().lat(),bounds.getNorthEast().lng());var bl=new google.maps.LatLng(bounds.getSouthWest().lat(),bounds.getSouthWest().lng());var trPix=projection.fromLatLngToDivPixel(tr);trPix.x+=this.gridSize_;trPix.y-=this.gridSize_;var blPix=projection.fromLatLngToDivPixel(bl);blPix.x-=this.gridSize_;blPix.y+=this.gridSize_;var ne=projection.fromDivPixelToLatLng(trPix);var sw=projection.fromDivPixelToLatLng(blPix);bounds.extend(ne);bounds.extend(sw);return bounds;};MarkerClusterer.prototype.isMarkerInBounds_=function(marker,bounds){return bounds.contains(marker.getPosition());};MarkerClusterer.prototype.clearMarkers=function(){this.resetViewport(true);this.markers_=[];};MarkerClusterer.prototype.resetViewport=function(opt_hide){for(var i=0,cluster;cluster=this.clusters_[i];i++){cluster.remove();}
for(var i=0,marker;marker=this.markers_[i];i++){marker.isAdded=false;if(opt_hide){marker.setMap(null);}}
this.clusters_=[];};MarkerClusterer.prototype.repaint=function(){var oldClusters=this.clusters_.slice();this.clusters_.length=0;this.resetViewport();this.redraw();window.setTimeout(function(){for(var i=0,cluster;cluster=oldClusters[i];i++){cluster.remove();}},0);};MarkerClusterer.prototype.redraw=function(){this.createClusters_();};MarkerClusterer.prototype.distanceBetweenPoints_=function(p1,p2){if(!p1||!p2){return 0;}
var R=6371;var dLat=(p2.lat()-p1.lat())*Math.PI / 180;var dLon=(p2.lng()-p1.lng())*Math.PI / 180;var a=Math.sin(dLat / 2)*Math.sin(dLat / 2)+
Math.cos(p1.lat()*Math.PI / 180)*Math.cos(p2.lat()*Math.PI / 180)*Math.sin(dLon / 2)*Math.sin(dLon / 2);var c=2*Math.atan2(Math.sqrt(a),Math.sqrt(1-a));var d=R*c;return d;};MarkerClusterer.prototype.addToClosestCluster_=function(marker){var distance=40000;var clusterToAddTo=null;var pos=marker.getPosition();for(var i=0,cluster;cluster=this.clusters_[i];i++){var center=cluster.getCenter();if(center){var d=this.distanceBetweenPoints_(center,marker.getPosition());if(d<distance){distance=d;clusterToAddTo=cluster;}}}
if(clusterToAddTo&&clusterToAddTo.isMarkerInClusterBounds(marker)){clusterToAddTo.addMarker(marker);}else{var cluster=new Cluster(this);cluster.addMarker(marker);this.clusters_.push(cluster);}};MarkerClusterer.prototype.createClusters_=function(){if(!this.ready_){return;}
var mapBounds=new google.maps.LatLngBounds(this.map_.getBounds().getSouthWest(),this.map_.getBounds().getNorthEast());var bounds=this.getExtendedBounds(mapBounds);for(var i=0,marker;marker=this.markers_[i];i++){if(!marker.isAdded&&this.isMarkerInBounds_(marker,bounds)){this.addToClosestCluster_(marker);}}};function Cluster(markerClusterer){this.markerClusterer_=markerClusterer;this.map_=markerClusterer.getMap();this.gridSize_=markerClusterer.getGridSize();this.minClusterSize_=markerClusterer.getMinClusterSize();this.averageCenter_=markerClusterer.isAverageCenter();this.center_=null;this.markers_=[];this.bounds_=null;this.clusterIcon_=new ClusterIcon(this,markerClusterer.getStyles(),markerClusterer.getGridSize());}
Cluster.prototype.isMarkerAlreadyAdded=function(marker){if(this.markers_.indexOf){return this.markers_.indexOf(marker)!=-1;}else{for(var i=0,m;m=this.markers_[i];i++){if(m==marker){return true;}}}
return false;};Cluster.prototype.addMarker=function(marker){if(this.isMarkerAlreadyAdded(marker)){return false;}
if(!this.center_){this.center_=marker.getPosition();this.calculateBounds_();}else{if(this.averageCenter_){var l=this.markers_.length+1;var lat=(this.center_.lat()*(l-1)+marker.getPosition().lat())/ l;var lng=(this.center_.lng()*(l-1)+marker.getPosition().lng())/ l;this.center_=new google.maps.LatLng(lat,lng);this.calculateBounds_();}}
marker.isAdded=true;this.markers_.push(marker);var len=this.markers_.length;if(len<this.minClusterSize_&&marker.getMap()!=this.map_){marker.setMap(this.map_);}
if(len==this.minClusterSize_){for(var i=0;i<len;i++){this.markers_[i].setMap(null);}}
if(len>=this.minClusterSize_){marker.setMap(null);}
this.updateIcon();return true;};Cluster.prototype.getMarkerClusterer=function(){return this.markerClusterer_;};Cluster.prototype.getBounds=function(){var bounds=new google.maps.LatLngBounds(this.center_,this.center_);var markers=this.getMarkers();for(var i=0,marker;marker=markers[i];i++){bounds.extend(marker.getPosition());}
return bounds;};Cluster.prototype.remove=function(){this.clusterIcon_.remove();this.markers_.length=0;delete this.markers_;};Cluster.prototype.getSize=function(){return this.markers_.length;};Cluster.prototype.getMarkers=function(){return this.markers_;};Cluster.prototype.getCenter=function(){return this.center_;};Cluster.prototype.calculateBounds_=function(){var bounds=new google.maps.LatLngBounds(this.center_,this.center_);this.bounds_=this.markerClusterer_.getExtendedBounds(bounds);};Cluster.prototype.isMarkerInClusterBounds=function(marker){return this.bounds_.contains(marker.getPosition());};Cluster.prototype.getMap=function(){return this.map_;};Cluster.prototype.updateIcon=function(){var zoom=this.map_.getZoom();var mz=this.markerClusterer_.getMaxZoom();if(mz&&zoom>mz){for(var i=0,marker;marker=this.markers_[i];i++){marker.setMap(this.map_);}
return;}
if(this.markers_.length<this.minClusterSize_){this.clusterIcon_.hide();return;}
var numStyles=this.markerClusterer_.getStyles().length;var sums=this.markerClusterer_.getCalculator()(this.markers_,numStyles);this.clusterIcon_.setCenter(this.center_);this.clusterIcon_.setSums(sums);this.clusterIcon_.show();};function ClusterIcon(cluster,styles,opt_padding){cluster.getMarkerClusterer().extend(ClusterIcon,google.maps.OverlayView);this.styles_=styles;this.padding_=opt_padding||0;this.cluster_=cluster;this.center_=null;this.map_=cluster.getMap();this.div_=null;this.sums_=null;this.visible_=false;this.setMap(this.map_);}
ClusterIcon.prototype.triggerClusterClick=function(){var markerClusterer=this.cluster_.getMarkerClusterer();google.maps.event.trigger(markerClusterer,'clusterclick',this.cluster_);if(markerClusterer.isZoomOnClick()){this.map_.fitBounds(this.cluster_.getBounds());}};ClusterIcon.prototype.onAdd=function(){this.div_=document.createElement('DIV');if(this.visible_){var pos=this.getPosFromLatLng_(this.center_);this.div_.style.cssText=this.createCss(pos);this.div_.innerHTML=this.sums_.text;}
var panes=this.getPanes();panes.overlayMouseTarget.appendChild(this.div_);var that=this;google.maps.event.addDomListener(this.div_,'click',function(){that.triggerClusterClick();});};ClusterIcon.prototype.getPosFromLatLng_=function(latlng){var pos=this.getProjection().fromLatLngToDivPixel(latlng);pos.x-=parseInt(this.width_ / 2,10);pos.y-=parseInt(this.height_ / 2,10);return pos;};ClusterIcon.prototype.draw=function(){if(this.visible_){var pos=this.getPosFromLatLng_(this.center_);this.div_.style.top=pos.y+'px';this.div_.style.left=pos.x+'px';}};ClusterIcon.prototype.hide=function(){if(this.div_){this.div_.style.display='none';}
this.visible_=false;};ClusterIcon.prototype.show=function(){if(this.div_){var pos=this.getPosFromLatLng_(this.center_);this.div_.style.cssText=this.createCss(pos);this.div_.style.display='';}
this.visible_=true;};ClusterIcon.prototype.remove=function(){this.setMap(null);};ClusterIcon.prototype.onRemove=function(){if(this.div_&&this.div_.parentNode){this.hide();this.div_.parentNode.removeChild(this.div_);this.div_=null;}};ClusterIcon.prototype.setSums=function(sums){this.sums_=sums;this.text_=sums.text;this.index_=sums.index;if(this.div_){this.div_.innerHTML=sums.text;}
this.useStyle();};ClusterIcon.prototype.useStyle=function(){var index=Math.max(0,this.sums_.index-1);index=Math.min(this.styles_.length-1,index);var style=this.styles_[index];this.url_=style['url'];this.height_=style['height'];this.width_=style['width'];this.textColor_=style['textColor'];this.anchor_=style['anchor'];this.textSize_=style['textSize'];this.backgroundPosition_=style['backgroundPosition'];};ClusterIcon.prototype.setCenter=function(center){this.center_=center;};ClusterIcon.prototype.createCss=function(pos){var style=[];style.push('background-image:url('+this.url_+');');var backgroundPosition=this.backgroundPosition_?this.backgroundPosition_:'0 0';style.push('background-position:'+backgroundPosition+';');if(typeof this.anchor_==='object'){if(typeof this.anchor_[0]==='number'&&this.anchor_[0]>0&&this.anchor_[0]<this.height_){style.push('height:'+(this.height_-this.anchor_[0])+'px; padding-top:'+this.anchor_[0]+'px;');}else{style.push('height:'+this.height_+'px; line-height:'+this.height_+'px;');}
if(typeof this.anchor_[1]==='number'&&this.anchor_[1]>0&&this.anchor_[1]<this.width_){style.push('width:'+(this.width_-this.anchor_[1])+'px; padding-left:'+this.anchor_[1]+'px;');}else{style.push('width:'+this.width_+'px; text-align:center;');}}else{style.push('height:'+this.height_+'px; line-height:'+
this.height_+'px; width:'+this.width_+'px; text-align:center;');}
var txtColor=this.textColor_?this.textColor_:'black';var txtSize=this.textSize_?this.textSize_:11;style.push('cursor:pointer; top:'+pos.y+'px; left:'+
pos.x+'px; color:'+txtColor+'; position:absolute; font-size:'+
txtSize+'px; font-family:Arial,sans-serif; font-weight:bold');return style.join('');};;