You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by sh...@apache.org on 2020/09/23 03:54:32 UTC

[incubator-echarts] branch next updated: chore: migrate changes to next branch and fix a bug brought by a typo(apache/incubator-echarts#13213).

This is an automated email from the ASF dual-hosted git repository.

shenyi pushed a commit to branch next
in repository https://gitbox.apache.org/repos/asf/incubator-echarts.git


The following commit(s) were added to refs/heads/next by this push:
     new 91f4964  chore: migrate changes to next branch and fix a bug brought by a typo(apache/incubator-echarts#13213).
     new 7cd58c8  Merge pull request #13214 from plainheart/fix-bmap-typo
91f4964 is described below

commit 91f4964495685fd965f1b1705896a009077844ae
Author: plainheart <yh...@all-my-life.cn>
AuthorDate: Tue Sep 1 10:37:31 2020 +0800

    chore: migrate changes to next branch and fix a bug brought by a typo(apache/incubator-echarts#13213).
---
 extension-src/bmap/BMapCoordSys.ts | 22 ++++++++++++++++++----
 extension-src/bmap/BMapModel.ts    |  7 ++++++-
 extension-src/bmap/BMapView.ts     | 26 ++++++++++++++++----------
 3 files changed, 40 insertions(+), 15 deletions(-)

diff --git a/extension-src/bmap/BMapCoordSys.ts b/extension-src/bmap/BMapCoordSys.ts
index 77ca99e..ffe4393 100644
--- a/extension-src/bmap/BMapCoordSys.ts
+++ b/extension-src/bmap/BMapCoordSys.ts
@@ -181,7 +181,16 @@ BMapCoordSys.create = function (ecModel, api) {
             // Not support IE8
             bmapRoot.classList.add('ec-extension-bmap');
             root.appendChild(bmapRoot);
-            bmap = bmapModel.__bmap = new BMap.Map(bmapRoot);
+
+            // initializes bmap
+            let mapOptions = bmapModel.get('mapOptions');
+            if (mapOptions) {
+                mapOptions = zrUtil.clone(mapOptions);
+                // Not support `mapType`, use `bmap.setMapType(MapType)` instead.
+                delete mapOptions.mapType;
+            }
+
+            bmap = bmapModel.__bmap = new BMap.Map(bmapRoot, mapOptions);
 
             const overlay = new Overlay(viewportRoot);
             bmap.addOverlay(overlay);
@@ -198,8 +207,13 @@ BMapCoordSys.create = function (ecModel, api) {
         const center = bmapModel.get('center');
         const zoom = bmapModel.get('zoom');
         if (center && zoom) {
-            const pt = new BMap.Point(center[0], center[1]);
-            bmap.centerAndZoom(pt, zoom);
+            const bmapCenter = bmap.getCenter();
+            const bmapZoom = bmap.getZoom();
+            const centerOrZoomChanged = bmapModel.centerOrZoomChanged([bmapCenter.lng, bmapCenter.lat], bmapZoom);
+            if (centerOrZoomChanged) {
+                const pt = new BMap.Point(center[0], center[1]);
+                bmap.centerAndZoom(pt, zoom);
+            }
         }
 
         bmapCoordSys = new BMapCoordSys(bmap, api);
@@ -217,4 +231,4 @@ BMapCoordSys.create = function (ecModel, api) {
     });
 };
 
-export default BMapCoordSys;
\ No newline at end of file
+export default BMapCoordSys;
diff --git a/extension-src/bmap/BMapModel.ts b/extension-src/bmap/BMapModel.ts
index 788ffdf..6e0f3e6 100644
--- a/extension-src/bmap/BMapModel.ts
+++ b/extension-src/bmap/BMapModel.ts
@@ -48,10 +48,15 @@ export default echarts.extendComponentModel({
 
         zoom: 5,
 
+        // 2.0 http://lbsyun.baidu.com/custom/index.htm
         mapStyle: {},
 
+        // 3.0 http://lbsyun.baidu.com/index.php?title=open/custom
         mapStyleV2: {},
 
+        // See https://lbsyun.baidu.com/cms/jsapi/reference/jsapi_reference.html#a0b1
+        mapOptions: {},
+
         roam: false
     }
-});
\ No newline at end of file
+});
diff --git a/extension-src/bmap/BMapView.ts b/extension-src/bmap/BMapView.ts
index e67df91..5639329 100644
--- a/extension-src/bmap/BMapView.ts
+++ b/extension-src/bmap/BMapView.ts
@@ -19,7 +19,15 @@
 
 // @ts-nocheck
 import * as echarts from 'echarts';
-import { clone } from 'zrender/src/core/util';
+
+function isEmptyObject(obj) {
+    for (const key in obj) {
+        if (obj.hasOwnProperty(key)) {
+            return false;
+        }
+    }
+    return true;
+}
 
 export default echarts.extendComponentView({
     type: 'bmap',
@@ -66,12 +74,10 @@ export default echarts.extendComponentView({
         }
 
         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('moveend', this._oldMoveHandler);
         bmap.removeEventListener('zoomend', this._oldZoomEndHandler);
         bmap.addEventListener('moving', moveHandler);
-        // bmap.addEventListener('moveend', moveHandler);
+        bmap.addEventListener('moveend', moveHandler);
         bmap.addEventListener('zoomend', zoomEndHandler);
 
         this._oldMoveHandler = moveHandler;
@@ -103,8 +109,8 @@ export default echarts.extendComponentView({
         const mapStyleStr = JSON.stringify(newMapStyle);
         if (JSON.stringify(originalStyle) !== mapStyleStr) {
             // FIXME May have blank tile when dragging if setMapStyle
-            if (Object.keys(newMapStyle).length) {
-                bmap.setMapStyle(clone(newMapStyle));
+            if (!isEmptyObject(newMapStyle)) {
+                bmap.setMapStyle(echarts.util.clone(newMapStyle));
             }
             bMapModel.__mapStyle = JSON.parse(mapStyleStr);
         }
@@ -117,12 +123,12 @@ export default echarts.extendComponentView({
         const mapStyleStr2 = JSON.stringify(newMapStyle2);
         if (JSON.stringify(originalStyle2) !== mapStyleStr2) {
             // FIXME May have blank tile when dragging if setMapStyle
-            if (Object.keys(newMapStyle2).length) {
-                bmap.setMapStyleV2(clone(newMapStyle2));
+            if (!isEmptyObject(newMapStyle2)) {
+                bmap.setMapStyleV2(echarts.util.clone(newMapStyle2));
             }
             bMapModel.__mapStyle2 = JSON.parse(mapStyleStr2);
         }
 
         rendering = false;
     }
-});
\ No newline at end of file
+});


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org