(function(global,base_factory){typeofexports==='object'&&typeofmodule!=='undefined'?base_factory(exports,require('echarts')):typeofdefine==='function'&&define.amd?define(['exports','echarts'],base_factory):(base_factory((global.bmap={}),global.echarts));}(this,(function(exports,echarts){'use strict';/** 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**Unlessrequiredbyapplicablelaworagreedtoinwriting,*softwaredistributedundertheLicenseisdistributedonan*"AS IS"BASIS,WITHOUTWARRANTIESORCONDITIONSOFANY*KIND,eitherexpressorimplied.SeetheLicenseforthe*specificlanguagegoverningpermissionsandlimitations*undertheLicense.*//*globalBMap*/function BMapCoordSys(bmap, api) { this._bmap = bmap; this.dimensions = ['lng', 'lat']; this._mapOffset = [0, 0]; this._api = api; this._projection = new BMap.MercatorProjection();}BMapCoordSys.prototype.dimensions = ['lng', 'lat'];BMapCoordSys.prototype.setZoom = function (zoom) { this._zoom = zoom;};BMapCoordSys.prototype.setCenter = function (center) { this._center = this._projection.lngLatToPoint(new BMap.Point(center[0], center[1]));};BMapCoordSys.prototype.setMapOffset = function (mapOffset) { this._mapOffset = mapOffset;};BMapCoordSys.prototype.getBMap = function () { return this._bmap;};BMapCoordSys.prototype.dataToPoint = function (data) { var point = new BMap.Point(data[0], data[1]); //TODOmercatorprojectionistooooooooslow// var mercatorPoint = this._projection.lngLatToPoint(point);// var width = this._api.getZr().getWidth();// var height = this._api.getZr().getHeight();// var divider = Math.pow(2, 18 - 10);// return [// Math.round((mercatorPoint.x - this._center.x) / divider + width / 2),// Math.round((this._center.y - mercatorPoint.y) / divider + height / 2)// ];varpx=this._bmap.pointToOverlayPixel(point);varmapOffset=this._mapOffset;return[px.x-mapOffset[0],px.y-mapOffset[1]];};BMapCoordSys.prototype.pointToData=function(pt){varmapOffset=this._mapOffset;varpt=this._bmap.overlayPixelToPoint({x:pt[0]+mapOffset[0],y:pt[1]+mapOffset[1]});return[pt.lng,pt.lat];};BMapCoordSys.prototype.getViewRect=function(){varapi=this._api;returnnewecharts.graphic.BoundingRect(0,0,api.getWidth(),api.getHeight());};BMapCoordSys.prototype.getRoamTransform=function(){returnecharts.matrix.create();};BMapCoordSys.prototype.prepareCustoms=function(data){varrect=this.getViewRect();return{coordSys:{// The name exposed to user is always 'cartesian2d' but not 'grid'.type:'bmap',x:rect.x,y:rect.y,width:rect.width,height:rect.height},api:{coord:echarts.util.bind(this.dataToPoint,this),size:echarts.util.bind(dataToCoordSize,this)}};};functiondataToCoordSize(dataSize,dataItem){dataItem=dataItem||[0,0];returnecharts.util.map([0,1],function(dimIdx){varval=dataItem[dimIdx];varhalfSize=dataSize[dimIdx]/2;varp1=[];varp2=[];p1[dimIdx]=val-halfSize;p2[dimIdx]=val+halfSize;p1[1-dimIdx]=p2[1-dimIdx]=dataItem[1-dimIdx];returnMath.abs(this.dataToPoint(p1)[dimIdx]-this.dataToPoint(p2)[dimIdx]);},this);}varOverlay;// For deciding which dimensions to use when creating list dataBMapCoordSys.dimensions=BMapCoordSys.prototype.dimensions;functioncreateOverlayCtor(){functionOverlay(root){this._root=root;}Overlay.prototype=newBMap.Overlay();/** * 初始化 * * @param {BMap.Map} map * @override */Overlay.prototype.initialize=function(map){map.getPanes().labelPane.appendChild(this._root);returnthis._root;};/** * @override */Overlay.prototype.draw=function(){};returnOverlay;}BMapCoordSys.create=function(ecModel,api){varbmapCoordSys;varroot=api.getDom();// TODO DisposeecModel.eachComponent('bmap',function(bmapModel){varpainter=api.getZr().painter;varviewportRoot=painter.getViewportRoot();if(typeofBMap==='undefined'){thrownewError('BMap api is not loaded');}Overlay=Overlay||createOverlayCtor();if(bmapCoordSys){thrownewError('Only one bmap component can exist');}if(!bmapModel.__bmap){// Not support IE8varbmapRoot=root.querySelector('.ec-extension-bmap');if(bmapRoot){// Reset viewport left and top, which will be changed// in moving handler in BMapViewviewportRoot.style.left='0px';viewportRoot.style.top='0px';root.removeChild(bmapRoot);}bmapRoot=document.createElement('div');bmapRoot.style.cssText='width:100%;height:100%';// Not support IE8bmapRoot.classList.add('ec-extension-bmap');root.appendChild(bmapRoot);varbmap=bmapModel.__bmap=newBMap.Map(bmapRoot);varoverlay=newOverlay(viewportRoot);bmap.addOverlay(overlay);// Overridepainter.getViewportRootOffset=function(){return{offsetLeft:0,offsetTop:0};};}varbmap=bmapModel.__bmap;// Set bmap options// centerAndZoom before layout and rendervarcenter=bmapModel.get('center');varzoom=bmapModel.get('zoom');if(center&&zoom){varpt=newBMap.Point(center[0],center[1]);bmap.centerAndZoom(pt,zoom);}bmapCoordSys=newBMapCoordSys(bmap,api);bmapCoordSys.setMapOffset(bmapModel.__mapOffset||[0,0]);bmapCoordSys.setZoom(zoom);bmapCoordSys.setCenter(center);bmapModel.coordinateSystem=bmapCoordSys;});ecModel.eachSeries(function(seriesModel){if(seriesModel.get('coordinateSystem')==='bmap'){seriesModel.coordinateSystem=bmapCoordSys;}});};/** 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**Unlessrequiredbyapplicablelaworagreedtoinwriting,*softwaredistributedundertheLicenseisdistributedonan*"AS IS"BASIS,WITHOUTWARRANTIESORCONDITIONSOFANY*KIND,eitherexpressorimplied.SeetheLicenseforthe*specificlanguagegoverningpermissionsandlimitations*undertheLicense.*/function v2Equal(a, b) { return a && b && a[0] === b[0] && a[1] === b[1];}echarts.extendComponentModel({ type: 'bmap', getBMap: function () { //__bmapisinjectedwhencreatingBMapCoordSysreturnthis.__bmap;},setCenterAndZoom:function(center,zoom){this.option.center=center;this.option.zoom=zoom;},centerOrZoomChanged:function(center,zoom){varoption=this.option;return!(v2Equal(center,option.center)&&zoom===option.zoom);},defaultOption:{center:[104.114129,37.550339],zoom:5,mapStyle:{},roam:false}});/** 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**Unlessrequiredbyapplicablelaworagreedtoinwriting,*softwaredistributedundertheLicenseisdistributedonan*"AS IS"BASIS,WITHOUTWARRANTIESORCONDITIONSOFANY*KIND,eitherexpressorimplied.SeetheLicenseforthe*specificlanguagegoverningpermissionsandlimitations*undertheLicense.*/echarts.extendComponentView({ type: 'bmap', render: function (bMapModel, ecModel, api) { var rendering = true; var bmap = bMapModel.getBMap(); var viewportRoot = api.getZr().painter.getViewportRoot(); var coordSys = bMapModel.coordinateSystem; var moveHandler = function (type, target) { if (rendering) { return; } var offsetEl = viewportRoot.parentNode.parentNode.parentNode; var mapOffset = [ -parseInt(offsetEl.style.left, 10) || 0, -parseInt(offsetEl.style.top, 10) || 0]; viewportRoot.style.left = mapOffset[0] + 'px'; viewportRoot.style.top = mapOffset[1] + 'px'; coordSys.setMapOffset(mapOffset); bMapModel.__mapOffset = mapOffset; api.dispatchAction({ type: 'bmapRoam' }); }; function zoomEndHandler() { if (rendering) { return; } api.dispatchAction({ type: 'bmapRoam' }); } bmap.removeEventListener('moving', this._oldMoveHandler); //FIXME// Moveend may be triggered by centerAndZoom method when creating coordSys next time// bmap.removeEventListener('moveend', this._oldMoveHandler);bmap.removeEventListener('zoomend',this._oldZoomEndHandler);bmap.addEventListener('moving',moveHandler);// bmap.addEventListener('moveend', moveHandler);bmap.addEventListener('zoomend',zoomEndHandler);this._oldMoveHandler=moveHandler;this._oldZoomEndHandler=zoomEndHandler;varroam=bMapModel.get('roam');if(roam&&roam!=='scale'){bmap.enableDragging();}else{bmap.disableDragging();}if(roam&&roam!=='move'){bmap.enableScrollWheelZoom();bmap.enableDoubleClickZoom();bmap.enablePinchToZoom();}else{bmap.disableScrollWheelZoom();bmap.disableDoubleClickZoom();bmap.disablePinchToZoom();}varoriginalStyle=bMapModel.__mapStyle;varnewMapStyle=bMapModel.get('mapStyle')||{};// FIXME, Not use JSON methodsvarmapStyleStr=JSON.stringify(newMapStyle);if(JSON.stringify(originalStyle)!==mapStyleStr){// FIXME May have blank tile when dragging if setMapStyleif(Object.keys(newMapStyle).length){bmap.setMapStyle(newMapStyle);}bMapModel.__mapStyle=JSON.parse(mapStyleStr);}rendering=false;}});/** 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**Unlessrequiredbyapplicablelaworagreedtoinwriting,*softwaredistributedundertheLicenseisdistributedonan*"AS IS"BASIS,WITHOUTWARRANTIESORCONDITIONSOFANY*KIND,eitherexpressorimplied.SeetheLicenseforthe*specificlanguagegoverningpermissionsandlimitations*undertheLicense.*//***BMapcomponentextension*/echarts.registerCoordinateSystem('bmap', BMapCoordSys);//Actionecharts.registerAction({type:'bmapRoam',event:'bmapRoam',update:'updateLayout'},function(payload,ecModel){ecModel.eachComponent('bmap',function(bMapModel){varbmap=bMapModel.getBMap();varcenter=bmap.getCenter();bMapModel.setCenterAndZoom([center.lng,center.lat],bmap.getZoom());});});varversion='1.0.0';exports.version=version;})));//# sourceMappingURL=bmap.js.map