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