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 2022/01/13 04:38:10 UTC

[echarts] branch enhance-map updated: fix(map): fix linestring decode. add test

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

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


The following commit(s) were added to refs/heads/enhance-map by this push:
     new 2ee85a7  fix(map): fix linestring decode. add test
2ee85a7 is described below

commit 2ee85a73127a1a3b7de6236b1e92a01c9daf08b6
Author: pissang <bm...@gmail.com>
AuthorDate: Thu Jan 13 12:20:30 2022 +0800

    fix(map): fix linestring decode. add test
---
 src/coord/geo/parseGeoJson.ts |  3 ++-
 test/data/map/decode.js       | 14 +++++++---
 test/data/map/encode.js       | 10 ++++---
 test/geojson-test.html        | 63 +++++++++++++++++++++++++------------------
 4 files changed, 57 insertions(+), 33 deletions(-)

diff --git a/src/coord/geo/parseGeoJson.ts b/src/coord/geo/parseGeoJson.ts
index bc52c0b..c1993ee 100644
--- a/src/coord/geo/parseGeoJson.ts
+++ b/src/coord/geo/parseGeoJson.ts
@@ -50,7 +50,8 @@ function decode(json: GeoJSONCompressed | GeoJSON): GeoJSON {
 
         switch (geometry.type) {
             case 'LineString':
-                decodeRing(coordinates as string, encodeOffsets as number[], encodeScale);
+                (geometry as any).coordinates =
+                    decodeRing(coordinates as string, encodeOffsets as number[], encodeScale);
                 break;
             case 'Polygon':
                 decodeRings(coordinates as string[], encodeOffsets as number[][], encodeScale);
diff --git a/test/data/map/decode.js b/test/data/map/decode.js
index a0b6e80..6f61e70 100644
--- a/test/data/map/decode.js
+++ b/test/data/map/decode.js
@@ -41,14 +41,16 @@ function decode(json) {
 
         switch (geometry.type) {
             case 'LineString':
-                decodeRing(coordinates, encodeOffsets, encodeScale);
+                geometry.coordinates = decodeRing(coordinates, encodeOffsets, encodeScale);
                 break;
             case 'Polygon':
             case 'MultiLineString':
                 decodeRings(coordinates, encodeOffsets, encodeScale);
                 break;
             case 'MultiPolygon':
-                zrUtil.each(coordinates, (rings, idx) => decodeRings(rings, encodeOffsets[idx], encodeScale));
+                zrUtil.each(coordinates, function (rings, idx) {
+                    return decodeRings(rings, encodeOffsets[idx], encodeScale)
+                });
         }
     });
     // Has been decoded
@@ -89,4 +91,10 @@ function decodeRing(coordinate, encodeOffsets, encodeScale) {
     return result;
 }
 
-module.exports = decode;
\ No newline at end of file
+// Export for testing.
+if (typeof module !== 'undefined') {
+    module.exports = decode;
+}
+else {
+    window.decodeGeoJSON = decode;
+}
\ No newline at end of file
diff --git a/test/data/map/encode.js b/test/data/map/encode.js
index db29768..3855043 100644
--- a/test/data/map/encode.js
+++ b/test/data/map/encode.js
@@ -100,6 +100,10 @@ function encodePoint(val, prev){
     return String.fromCharCode(delta + 64);
 }
 
-
-
-module.exports = encode;
\ No newline at end of file
+// Export for testing.
+if (typeof module !== 'undefined') {
+    module.exports = encode;
+}
+else {
+    window.encodeGeoJSON = encode;
+}
\ No newline at end of file
diff --git a/test/geojson-test.html b/test/geojson-test.html
index 262fa92..b75d7b0 100644
--- a/test/geojson-test.html
+++ b/test/geojson-test.html
@@ -23,6 +23,7 @@ under the License.
     <head>
         <meta charset="utf-8">
         <meta name="viewport" content="width=device-width, initial-scale=1" />
+        <script src="data/map/encode.js"></script>
         <script src="lib/simpleRequire.js"></script>
         <script src="lib/config.js"></script>
         <script src="lib/jquery.min.js"></script>
@@ -76,13 +77,21 @@ under the License.
         require([
             'echarts',
         ], function (echarts) {
-            echarts.registerMap('Polygon', createGeoJSONFromGeo('Polygon', {
+
+            function cloneJSON(json) {
+                return JSON.parse(JSON.stringify(json));
+            }
+            function prepareAndRegisterMap(name, json) {
+                echarts.registerMap(name, createGeoJSONFromGeo(name, cloneJSON(json)));
+                echarts.registerMap(name + 'Compressed', encode(createGeoJSONFromGeo(name + 'Compressed', cloneJSON(json))));
+            }
+            prepareAndRegisterMap('Polygon', {
                 "type": "Polygon",
                 "coordinates": [
                     [[30, 10], [40, 40], [20, 40], [10, 20], [30, 10]]
                 ]
-            }));
-            echarts.registerMap('MultiPolygon', createGeoJSONFromGeo('MultiPolygon', {
+            });
+            prepareAndRegisterMap('MultiPolygon', {
                 "type": "MultiPolygon",
                 "coordinates": [
                     [
@@ -92,21 +101,21 @@ under the License.
                         [[15, 5], [40, 10], [10, 20], [5, 10], [15, 5]]
                     ]
                 ]
-            }));
-            echarts.registerMap('LineString', createGeoJSONFromGeo('LineString', {
+            });
+            prepareAndRegisterMap('LineString', {
                 "type": "LineString",
                 "coordinates": [
                     [30, 10], [10, 30], [40, 40]
                 ]
-            }));
-            echarts.registerMap('MultiLineString', createGeoJSONFromGeo('MultiLineString', {
+            });
+            prepareAndRegisterMap('MultiLineString', {
                 "type": "MultiLineString",
                 "coordinates": [
                     [[10, 10], [20, 20], [10, 40]],
                     [[40, 40], [30, 30], [40, 20], [30, 10]]
                 ]
-            }));
-            echarts.registerMap('HoleyMultiPolygon', createGeoJSONFromGeo('HoleyMultiPolygon', {
+            });
+            prepareAndRegisterMap('HoleyMultiPolygon', {
                 "type": "MultiPolygon",
                 "coordinates": [
                     [
@@ -117,24 +126,26 @@ under the License.
                         [[30, 20], [20, 15], [20, 25], [30, 20]]
                     ]
                 ]
-            }));
+            });
             ['Polygon', 'MultiPolygon', 'LineString', 'MultiLineString', 'HoleyMultiPolygon'].forEach(map => {
-                const dom = document.createElement('div');
-                dom.className = 'chart';
-                document.querySelector('#geometries').appendChild(dom);
-                const chart = echarts.init(dom);
-                chart.setOption({
-                    title: {
-                        text: map,
-                        textStyle: {
-                            fontSize: 14
-                        }
-                    },
-                    series: [{
-                        type: 'map',
-                        map: map
-                    }]
-                });
+                ['', 'Compressed'].forEach(isCompressed => {
+                    const dom = document.createElement('div');
+                    dom.className = 'chart';
+                    document.querySelector('#geometries').appendChild(dom);
+                    const chart = echarts.init(dom);
+                    chart.setOption({
+                        title: {
+                            text: map + isCompressed,
+                            textStyle: {
+                                fontSize: 14
+                            }
+                        },
+                        series: [{
+                            type: 'map',
+                            map: map
+                        }]
+                    });
+                })
             });
         });
         </script>

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