From d8ebb5fd074a38ff93dc21dfd3b9d2b7478e5c47 Mon Sep 17 00:00:00 2001 From: 100pah Date: Tue, 6 Apr 2021 01:55:27 +0800 Subject: [PATCH] fix: [geo] svg fix converter and add test case. --- src/coord/geo/Geo.ts | 2 +- src/coord/geo/Region.ts | 6 +-- test/geo-svg.html | 107 ++++++++++++++++++++++++++++++++++++++-- 3 files changed, 106 insertions(+), 9 deletions(-) diff --git a/src/coord/geo/Geo.ts b/src/coord/geo/Geo.ts index a2e96cc2e..aa15eba1e 100644 --- a/src/coord/geo/Geo.ts +++ b/src/coord/geo/Geo.ts @@ -56,7 +56,7 @@ class Geo extends View { readonly resourceType: GeoResource['type']; // Only store specified name coord via `addGeoCoord`. - private _nameCoordMap: zrUtil.HashMap; + private _nameCoordMap: zrUtil.HashMap = zrUtil.createHashMap(); private _regionsMap: zrUtil.HashMap; private _invertLongitute: boolean; readonly regions: Region[]; diff --git a/src/coord/geo/Region.ts b/src/coord/geo/Region.ts index df482e378..2e5248ed9 100644 --- a/src/coord/geo/Region.ts +++ b/src/coord/geo/Region.ts @@ -42,7 +42,7 @@ export class Region { /** * Get center point in data unit. That is, * for GeoJSONRegion, the unit is lat/lng, - * for GeoSVGRegion, the unit is pixel but based on root. + * for GeoSVGRegion, the unit is SVG local coord. */ getCenter(): number[] { return; @@ -239,8 +239,8 @@ export class GeoSVGRegion extends Region { const el = this._elOnlyForCalculate; const rect = el.getBoundingRect(); const center = [ - rect.x + rect.width, - rect.y + rect.height + rect.x + rect.width / 2, + rect.y + rect.height / 2 ]; const mat = matrix.identity(TMP_TRANSFORM); diff --git a/test/geo-svg.html b/test/geo-svg.html index 38a625109..9f0f5e943 100644 --- a/test/geo-svg.html +++ b/test/geo-svg.html @@ -39,6 +39,7 @@ under the License.
+
@@ -174,14 +175,13 @@ under the License. // layoutCenter: ['30%', 40], // layoutSize: 40, // boundingCoords - zoom: 1, - aspectScale: 1 + // zoom: 1, + // aspectScale: 1 } }; var chart = testHelper.create(echarts, 'main_simple_geo_svg', { title: [ - 'simple geo geoSVG location:', 'Should be a square and 80% of canvas height.', 'At the center of the canvas.' ], @@ -202,6 +202,101 @@ under the License. + + + + + +