!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("echarts")):"function"==typeof define&&define.amd?define(["exports","echarts"],e):e(t.bmap={},t.echarts)}(this,function(t,e){"use strict";function o(t,e){this._bmap=t,this.dimensions=["lng","lat"],this._mapoffset=[0,0],this._api=e,this._projection=new bmap.mercatorprojection}function n(t,o){return o=o||[0,0],e.util.map([0,1],function(e){var n=o[e],i=t[e]/2,a=[],r=[];return a[e]=n-i,r[e]=n+i,a[1-e]=r[1-e]=o[1-e],math.abs(this.datatopoint(a)[e]-this.datatopoint(r)[e])},this)}function i(){function t(t){this._root=t}return t.prototype=new bmap.overlay,t.prototype.initialize=function(t){return t.getpanes().labelpane.appendchild(this._root),this._root},t.prototype.draw=function(){},t}function a(t,e){return t&&e&&t[0]===e[0]&&t[1]===e[1]}o.prototype.dimensions=["lng","lat"],o.prototype.setzoom=function(t){this._zoom=t},o.prototype.setcenter=function(t){this._center=this._projection.lnglattopoint(new bmap.point(t[0],t[1]))},o.prototype.setmapoffset=function(t){this._mapoffset=t},o.prototype.getbmap=function(){return this._bmap},o.prototype.datatopoint=function(t){var e=new bmap.point(t[0],t[1]),o=this._bmap.pointtooverlaypixel(e),n=this._mapoffset;return[o.x-n[0],o.y-n[1]]},o.prototype.pointtodata=function(t){var e=this._mapoffset;return[(t=this._bmap.overlaypixeltopoint({x:t[0]+e[0],y:t[1]+e[1]})).lng,t.lat]},o.prototype.getviewrect=function(){var t=this._api;return new e.graphic.boundingrect(0,0,t.getwidth(),t.getheight())},o.prototype.getroamtransform=function(){return e.matrix.create()},o.prototype.preparecustoms=function(t){var o=this.getviewrect();return{coordsys:{type:"bmap",x:o.x,y:o.y,width:o.width,height:o.height},api:{coord:e.util.bind(this.datatopoint,this),size:e.util.bind(n,this)}}};var r;o.dimensions=o.prototype.dimensions,o.create=function(t,e){var n,a=e.getdom();t.eachcomponent("bmap",function(t){var p=e.getzr().painter,s=p.getviewportroot();if("undefined"==typeof bmap)throw new error("bmap api is not loaded");if(r=r||i(),n)throw new error("only one bmap component can exist");if(!t.__bmap){var m=a.queryselector(".ec-extension-bmap");m&&(s.style.left="0px",s.style.top="0px",a.removechild(m)),(m=document.createelement("div")).style.csstext="width:100%;height:100%",m.classlist.add("ec-extension-bmap"),a.appendchild(m);var c=t.__bmap=new bmap.map(m),d=new r(s);c.addoverlay(d),p.getviewportrootoffset=function(){return{offsetleft:0,offsettop:0}}}var c=t.__bmap,f=t.get("center"),l=t.get("zoom");if(f&&l){var h=new bmap.point(f[0],f[1]);c.centerandzoom(h,l)}(n=new o(c,e)).setmapoffset(t.__mapoffset||[0,0]),n.setzoom(l),n.setcenter(f),t.coordinatesystem=n}),t.eachseries(function(t){"bmap"===t.get("coordinatesystem")&&(t.coordinatesystem=n)})},e.extendcomponentmodel({type:"bmap",getbmap:function(){return this.__bmap},setcenterandzoom:function(t,e){this.option.center=t,this.option.zoom=e},centerorzoomchanged:function(t,e){var o=this.option;return!(a(t,o.center)&&e===o.zoom)},defaultoption:{center:[104.114129,37.550339],zoom:5,mapstyle:{},roam:!1}}),e.extendcomponentview({type:"bmap",render:function(t,e,o){function n(){i||o.dispatchaction({type:"bmaproam"})}var i=!0,a=t.getbmap(),r=o.getzr().painter.getviewportroot(),p=t.coordinatesystem,s=function(e,n){if(!i){var a=r.parentnode.parentnode.parentnode,s=[-parseint(a.style.left,10)||0,-parseint(a.style.top,10)||0];r.style.left=s[0]+"px",r.style.top=s[1]+"px",p.setmapoffset(s),t.__mapoffset=s,o.dispatchaction({type:"bmaproam"})}};a.removeeventlistener("moving",this._oldmovehandler),a.removeeventlistener("zoomend",this._oldzoomendhandler),a.addeventlistener("moving",s),a.addeventlistener("zoomend",n),this._oldmovehandler=s,this._oldzoomendhandler=n;var m=t.get("roam");m&&"scale"!==m?a.enabledragging():a.disabledragging(),m&&"move"!==m?(a.enablescrollwheelzoom(),a.enabledoubleclickzoom(),a.enablepinchtozoom()):(a.disablescrollwheelzoom(),a.disabledoubleclickzoom(),a.disablepinchtozoom());var c=t.__mapstyle,d=t.get("mapstyle")||{},f=json.stringify(d);json.stringify(c)!==f&&(object.keys(d).length&&a.setmapstyle(d),t.__mapstyle=json.parse(f)),i=!1}}),e.registercoordinatesystem("bmap",o),e.registeraction({type:"bmaproam",event:"bmaproam",update:"updatelayout"},function(t,e){e.eachcomponent("bmap",function(t){var e=t.getbmap(),o=e.getcenter();t.setcenterandzoom([o.lng,o.lat],e.getzoom())})});t.version="1.0.0"});