/* * 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=t||self).bmap={},t.echarts)}(this,function(t,e){"use strict";function d(t,e){this._bmap=t,this.dimensions=["lng","lat"],this._mapOffset=[0,0],this._api=e,this._projection=new BMap.MercatorProjection}function o(i,a){return a=a||[0,0],e.util.map([0,1],function(t){var e=a[t],o=i[t]/2,n=[],r=[];return n[t]=e-o,r[t]=e+o,n[1-t]=r[1-t]=a[1-t],Math.abs(this.dataToPoint(n)[t]-this.dataToPoint(r)[t])},this)}var y;d.prototype.dimensions=["lng","lat"],d.prototype.setZoom=function(t){this._zoom=t},d.prototype.setCenter=function(t){this._center=this._projection.lngLatToPoint(new BMap.Point(t[0],t[1]))},d.prototype.setMapOffset=function(t){this._mapOffset=t},d.prototype.getBMap=function(){return this._bmap},d.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]]},d.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]},d.prototype.getViewRect=function(){var t=this._api;return new e.graphic.BoundingRect(0,0,t.getWidth(),t.getHeight())},d.prototype.getRoamTransform=function(){return e.matrix.create()},d.prototype.prepareCustoms=function(){var t=this.getViewRect();return{coordSys:{type:"bmap",x:t.x,y:t.y,width:t.width,height:t.height},api:{coord:e.util.bind(this.dataToPoint,this),size:e.util.bind(o,this)}}},d.dimensions=d.prototype.dimensions,d.create=function(t,l){var m,f=l.getDom();t.eachComponent("bmap",function(t){var e,o,n,r=l.getZr().painter,i=r.getViewportRoot();if("undefined"==typeof BMap)throw new Error("BMap api is not loaded");function a(t){this._root=t}if(y=y||((a.prototype=new BMap.Overlay).initialize=function(t){return t.getPanes().labelPane.appendChild(this._root),this._root},a.prototype.draw=function(){},a),m)throw new Error("Only one bmap component can exist");t.__bmap||((o=f.querySelector(".ec-extension-bmap"))&&(i.style.left="0px",i.style.top="0px",f.removeChild(o)),(o=document.createElement("div")).style.cssText="width:100%;height:100%",o.classList.add("ec-extension-bmap"),f.appendChild(o),e=t.__bmap=new BMap.Map(o),n=new y(i),e.addOverlay(n),r.getViewportRootOffset=function(){return{offsetLeft:0,offsetTop:0}}),e=t.__bmap;var p,s=t.get("center"),c=t.get("zoom");s&&c&&(p=new BMap.Point(s[0],s[1]),e.centerAndZoom(p,c)),(m=new d(e,l)).setMapOffset(t.__mapOffset||[0,0]),m.setZoom(c),m.setCenter(s),t.coordinateSystem=m}),t.eachSeries(function(t){"bmap"===t.get("coordinateSystem")&&(t.coordinateSystem=m)})},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,n,r=this.option;return o=t,n=r.center,!(o&&n&&o[0]===n[0]&&o[1]===n[1]&&e===r.zoom)},defaultOption:{center:[104.114129,37.550339],zoom:5,mapStyle:{},mapStyleV2:{},roam:!1}});var s={"[object Function]":!0,"[object RegExp]":!0,"[object Date]":!0,"[object Error]":!0,"[object CanvasGradient]":!0,"[object CanvasPattern]":!0,"[object Image]":!0,"[object Canvas]":!0},c={"[object Int8Array]":!0,"[object Uint8Array]":!0,"[object Uint8ClampedArray]":!0,"[object Int16Array]":!0,"[object Uint16Array]":!0,"[object Int32Array]":!0,"[object Uint32Array]":!0,"[object Float32Array]":!0,"[object Float64Array]":!0},l=Object.prototype.toString,n=Array.prototype.slice,r=function(){}.constructor,i=r?r.prototype:null;function h(t){if(null==t||"object"!=typeof t)return t;var e,o=t,n=l.call(t);if("[object Array]"===n){if(!m(t)){o=[];for(var r=0,i=t.length;r