leaflet-echarts3.min.js
3.9 KB
!function(e,t){"function"==typeof define&&define.amd?define(["leaflet"],t):"object"==typeof module&&module.exports?module.exports=t(require("leaflet"),require("echarts")):"undefined"!=typeof e&&e.L&&e.echarts&&(LeafletEcharts=t(L,echarts))}(this,function(e,t){function n(e,t){this._lmap=e,this.dimensions=["lng","lat"],this._mapOffset=[0,0],this._api=t}var i,a;t.extendComponentModel({type:"lmap",defaultOption:{mapOptions:{center:[37.550339,104.114129],zoom:5}}}),t.extendComponentView({type:"lmap",render:function(e,t,n){}});e.EchartLayer=e.Class.extend({includes:[e.Mixin.Events],_echartsContainer:null,_map:null,_ec:null,_ecModel:null,_resizing:!1,initialize:function(e,t){this._ec=e,this._echartsContainer=t?t:e.getDom()},getMap:function(){return this._map},setModel:function(e){this._ecModel=e},onAdd:function(e){this._map=e;e.getSize();e.getPanes().overlayPane.appendChild(this._echartsContainer),e.on("moveend",this._moveend,this),e.on("resize",this._resize,this)},_resize:function(){var e=this._map._getMapPanePos();this._mapOffset=[-parseInt(e.x)||0,-parseInt(e.y)||0],this._echartsContainer.style.left=this._mapOffset[0]+"px",this._echartsContainer.style.top=this._mapOffset[1]+"px";var t=this._map.getSize();this._echartsContainer.style.height=t.y+"px",this._echartsContainer.style.width=t.x+"px",this._resizing=!0},_moveend:function(){var e=this._map._getMapPanePos();this._mapOffset=[-parseInt(e.x)||0,-parseInt(e.y)||0],this._echartsContainer.style.left=this._mapOffset[0]+"px",this._echartsContainer.style.top=this._mapOffset[1]+"px",1==this._resizing?(this._resizing=!1,this._ec.resize()):this._ec.dispatchAction({type:"mapMoveEnd"})},onRemove:function(e){e.getPanes().overlayPane.removeChild(this._root),e.off("viewreset",this._viewreset,this),e.off("resize",this._resize,this)}}),n.prototype.dimensions=["lng","lat"],n.prototype.setMapOffset=function(e){this._mapOffset=e},n.prototype.getLMap=function(){return this._lmap},n.prototype.dataToPoint=function(t){var n=new e.latLng(t[1],t[0]),i=this._lmap.latLngToContainerPoint(n),a=this._mapOffset;return[i.x-a[0],i.y-a[1]]},n.prototype.pointToData=function(e){var t=this._mapOffset,e=this._lmap.containerPointToLatLng({x:e[0]+t[0],y:e[1]+t[1]});return[e.lat,e.lng]},n.prototype.getViewRect=function(){var e=this._api;return new t.graphic.BoundingRect(0,0,e.getWidth(),e.getHeight())},n.prototype.getRoamTransform=function(){return t.matrix.create()},n.dimensions=n.prototype.dimensions;var o;return n.create=function(t,s){var r;t.eachComponent("lmap",function(t){if(r)throw new Error("Only one lmap component can exist");var p;if(!i){var h=s.getDom();if(p=s.getZr().painter.getViewportRoot(),"undefined"==typeof e)throw new Error("LMap api is not loaded");var h=s.getDom(),f=h.querySelector(".ec-extension-lmap");f&&(p.style.left="0px",p.style.top="0px",h.removeChild(f)),f=document.createElement("div"),f.style.cssText="width:100%;height:100%",f.classList.add("ec-extension-lmap"),h.appendChild(f);var c=t.get("mapOptions");i=t.__lmap=new e.map(f,c)}if(!o){var l=o=new e.EchartLayer(a,p);i.addLayer(l)}o.setModel(t),r=new n(i,s),r.setMapOffset(t.__mapOffset||[0,0]),t.coordinateSystem=r}),t.eachComponent("geo",function(t){if(r||(r=new n(i,s),r.setMapOffset(t.__mapOffset||[0,0])),!o){var p=o=new e.EchartLayer(a);i.addLayer(p)}o.setModel(t)}),t.eachSeries(function(e){var t=e.get("coordinateSystem");"geo"!==t&&"lmap"!==t||(e.coordinateSystem=r)})},t.registerCoordinateSystem("lmap",n),t.registerAction({type:"mapMoveEnd",event:"mapMoveEnd",update:"updateLayout"},function(e,t){t.eachComponent("lmap",function(e){})}),{initMap:function(n,o){var s=i=e.map(n,o),r=document.createElement("div"),p=s.getSize();r.style.position="absolute",r.style.height=p.y+"px",r.style.width=p.x+"px",r.style.top=0,r.style.left=0;a=t.init(r);return s},getEcharts:function(){return a},getEchartLayer:function(){return o},getLMap:function(){return i},initEcharts:function(e){var n=a=t.init(e);return n}}});