echarts
Version:
Apache ECharts is a powerful, interactive charting and data visualization library for browser
22 lines (19 loc) • 6.24 kB
JavaScript
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("echarts")):"function"==typeof define&&define.amd?define(["exports","echarts"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).bmap={},t.echarts)}(this,function(t,e){"use strict";var o="bmap",n={type:o,__bmap:void 0,__mapOffset:void 0,__mapStyle:void 0,__mapStyle2:void 0,coordinateSystem:void 0,getBMap:function(){return this.__bmap},setCenterAndZoom:function(t,e){this.option.center=t,this.option.zoom=e},centerOrZoomChanged:function(t,e){var o,n,i=this.option;return o=t,n=i.center,!(o&&n&&o[0]===n[0]&&o[1]===n[1]&&e===i.zoom)},defaultOption:{center:[104.114129,37.550339],zoom:5,mapStyle:{},mapStyleV2:{},mapOptions:{},roam:!1}};e.extendComponentModel(n);var i=o;var r,a=function(){function t(t,e){this.dimensions=["lng","lat"],this.type=i,this._mapOffset=[0,0],this._projection=new BMap.MercatorProjection,this._bmap=t,this._api=e}return t.prototype.setZoom=function(t){this._zoom=t},t.prototype.setCenter=function(t){this._center=this._projection.lngLatToPoint(new BMap.Point(t[0],t[1]))},t.prototype.setMapOffset=function(t){this._mapOffset=t},t.prototype.getBMap=function(){return this._bmap},t.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]]},t.prototype.pointToData=function(t){var e=this._mapOffset,o=this._bmap.overlayPixelToPoint({x:t[0]+e[0],y:t[1]+e[1]});return[o.lng,o.lat]},t.prototype.containPoint=function(t){return!0},t.prototype.getViewRect=function(){var t=this._api;return new e.graphic.BoundingRect(0,0,t.getWidth(),t.getHeight())},t.prototype.getRoamTransform=function(){return e.matrix.create()},t.prototype.prepareCustoms=function(){var t=this.getViewRect();return{coordSys:{type:i,x:t.x,y:t.y,width:t.width,height:t.height},api:{coord:e.util.bind(this.dataToPoint,this),size:e.util.bind(p,this)}}},t.prototype.convertToPixel=function(t,e,o){return this.dataToPoint(o)},t.prototype.convertFromPixel=function(t,e,o){return this.pointToData(o)},t.dimensions=["lng","lat"],t}();function p(t,o){return o=o||[0,0],e.util.map([0,1],function(e){var n=o[e],i=t[e]/2,r=[],a=[];return r[e]=n-i,a[e]=n+i,r[1-e]=a[1-e]=o[1-e],Math.abs(this.dataToPoint(r)[e]-this.dataToPoint(a)[e])},this)}function s(t){for(var e in t)if(t.hasOwnProperty(e))return!1;return!0}a.prototype.dimensions=["lng","lat"],a.create=function(t,n){var p,s=n.getDom();return t.eachComponent(o,function(t){var o,i=n.getZr().painter,l=i.getViewportRoot();if("undefined"==typeof BMap)throw new Error("BMap api is not loaded");if(r=r||function(){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}(),p)throw new Error("Only one bmap component can exist");if(!t.__bmap){var m=s.querySelector(".ec-extension-bmap");m&&(l.style.left="0px",l.style.top="0px",s.removeChild(m)),(m=document.createElement("div")).className="ec-extension-bmap",m.style.cssText="position:absolute;width:100%;height:100%",s.appendChild(m);var d=t.get("mapOptions");d&&delete(d=e.util.clone(d)).mapType,o=t.__bmap=new BMap.Map(m,d);var c=new r(l);o.addOverlay(c),i.getViewportRootOffset=function(){return{offsetLeft:0,offsetTop:0}}}o=t.__bmap;var f=t.get("center"),u=t.get("zoom");if(f&&u){var h=o.getCenter(),y=o.getZoom();if(t.centerOrZoomChanged([h.lng,h.lat],y)){var v=new BMap.Point(f[0],f[1]);o.centerAndZoom(v,u)}}(p=new a(o,n)).setMapOffset(t.__mapOffset||[0,0]),p.setZoom(u),p.setCenter(f),t.coordinateSystem=p}),t.eachSeries(function(t){t.get("coordinateSystem")===i&&(t.coordinateSystem=p)}),p&&[p]},e.registerCoordinateSystem("bmap",a);var l={type:o,_oldMoveHandler:void 0,_oldZoomEndHandler:void 0,render:function(t,o,n){var i=!0,r=t.getBMap(),a=n.getZr().painter.getViewportRoot(),p=t.coordinateSystem,l=function(){if(!i){var e=a.parentNode.parentNode.parentNode,o=[-parseInt(e.style.left,10)||0,-parseInt(e.style.top,10)||0],r=a.style,s=o[0]+"px",l=o[1]+"px";r.left!==s&&(r.left=s),r.top!==l&&(r.top=l),p.setMapOffset(o),t.__mapOffset=o,n.dispatchAction({type:"bmapRoam",animation:{duration:0}})}};function m(){i||n.dispatchAction({type:"bmapRoam",animation:{duration:0}})}r.removeEventListener("moving",this._oldMoveHandler),r.removeEventListener("moveend",this._oldMoveHandler),r.removeEventListener("zoomend",this._oldZoomEndHandler),r.addEventListener("moving",l),r.addEventListener("moveend",l),r.addEventListener("zoomend",m),this._oldMoveHandler=l,this._oldZoomEndHandler=m;var d=t.get("roam");d&&"scale"!==d?r.enableDragging():r.disableDragging(),d&&"move"!==d?(r.enableScrollWheelZoom(),r.enableDoubleClickZoom(),r.enablePinchToZoom()):(r.disableScrollWheelZoom(),r.disableDoubleClickZoom(),r.disablePinchToZoom());var c=t.__mapStyle,f=t.get("mapStyle")||{},u=JSON.stringify(f);JSON.stringify(c)!==u&&(s(f)||r.setMapStyle(e.util.clone(f)),t.__mapStyle=JSON.parse(u));var h=t.__mapStyle2,y=t.get("mapStyleV2")||{},v=JSON.stringify(y);JSON.stringify(h)!==v&&(s(y)||r.setMapStyleV2(e.util.clone(y)),t.__mapStyle2=JSON.parse(v)),i=!1}};e.extendComponentView(l),e.registerAction({type:"bmapRoam",event:"bmapRoam",update:"updateLayout"},function(t,e){e.eachComponent(o,function(t){var e=t.getBMap(),o=e.getCenter();t.setCenterAndZoom([o.lng,o.lat],e.getZoom())})});t.version="1.0.0",Object.defineProperty(t,"__esModule",{value:!0})});