-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathMarkerManager.min.js
More file actions
1 lines (1 loc) · 2.77 KB
/
Copy pathMarkerManager.min.js
File metadata and controls
1 lines (1 loc) · 2.77 KB
1
var BMapLib=window.BMapLib=BMapLib||{};!function(){var t,o=t=o||{version:"1.5.1"};o.guid="$BAIDU$",window[o.guid]=window[o.guid]||{},o.object=o.object||{},o.extend=o.object.extend=function(t,o){for(var r in o)o.hasOwnProperty(r)&&(t[r]=o[r]);return t},t.undope=!0;var r=BMapLib.MarkerManager=function(t,o){this._opts=o||{},this._map=t,this._zoom=t.getZoom(),this._numMarkers=[],"number"==typeof o.maxZoom?this._opts.maxZoom=this._opts.maxZoom:this._opts.maxZoom=19,"number"==typeof o.borderPadding?this._opts.borderPadding=o.borderPadding:this._opts.borderPadding=0;var r=this;this._map.addEventListener("zoomend",function(){r._showMarkers()}),this._map.addEventListener("dragend",function(){r._showMarkers()})};r.prototype.addMarker=function(t,o,r){o=o&&o>0?o:1,r=r&&r<=19?r:this._opts.maxZoom,t.minZoom=o,t.maxZoom=r,t.bAdded=!1,this._numMarkers.push(t),t.enableDragging()},r.prototype.addMarkers=function(t,o,r){for(var e=t.length;e--;)this.addMarker(t[e],o,r)},r.prototype.removeMarker=function(t){t instanceof BMap.Marker&&(this._map.removeOverlay(t),this._removeMarkerFromArray(t))},r.prototype.getMarkerCount=function(t){t=Math.floor(t);for(var o=this._numMarkers.length,r=this._numMarkers,e=0,i=o;i--;)e=r[i].bInBounds&&r[i].minZoom<=t&&r[i].maxZoom>=t?++e:e;return this._visible?e:0},r.prototype.show=function(){for(var t=this._numMarkers.length;t--;)this._numMarkers[t].bInBounds&&this._numMarkers[t].show();this._visible=!0},r.prototype.hide=function(){for(var t=this._numMarkers.length;t--;)this._numMarkers[t].bInBounds&&this._numMarkers[t].hide();this._visible=!1},r.prototype.toggle=function(){this._visible?this.hide():this.show()},r.prototype.showMarkers=function(){this._visible=!0,this._showMarkers()},r.prototype.clearMarkers=function(){for(var t=this._numMarkers.length;t--;)this._numMarkers[t].bInBounds&&this._map.removeOverlay(this._numMarkers[t]);this._numMarkers.length=0},o.object.extend(r.prototype,{_showMarkers:function(){for(var t=this._numMarkers.length,o=Math.floor(this._map.getZoom()),r=this._numMarkers,e=this._getRealBounds(),i=t;i--;)e.containsPoint(r[i].getPosition())&&o>=r[i].minZoom&&o<=r[i].maxZoom?(r[i].bInBounds=!0,r[i].bAdded?this._visible&&r[i].show():(this._map.addOverlay(r[i]),!this._visible&&r[i].hide(),r[i].bAdded=!0)):r[i].bAdded&&(r[i].bInBounds=!1,r[i].hide())},_getRealBounds:function(){var t=this._map.getBounds(),o=this._map.pointToPixel(t.getSouthWest()),r=this._map.pointToPixel(t.getNorthEast()),e={x:o.x-this._opts.borderPadding,y:o.y+this._opts.borderPadding},i={x:r.x+this._opts.borderPadding,y:r.y-this._opts.borderPadding},s=this._map.pixelToPoint(e),n=this._map.pixelToPoint(i);return new BMap.Bounds(s,n)},_removeMarkerFromArray:function(t){var o=this._numMarkers.length,r=o,e=0;for(r=o;r--;)t===this._numMarkers[r]&&(this._numMarkers.splice(r--,1),e++);return e}})}();