From f4bd2eab40b89e866a121a8f0403b3b90422a154 Mon Sep 17 00:00:00 2001 From: ParryQiu Date: Fri, 28 Aug 2020 15:15:59 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=8E=BB=E9=99=A4?= =?UTF-8?q?=E9=87=8D=E5=A4=8D=E7=82=B9=E8=AE=A1=E7=AE=97=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E7=9A=84=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/line/path/demo/road_light.js | 101 +++++++++++++----- packages/layers/src/utils/extrude_polyline.ts | 17 +-- 2 files changed, 88 insertions(+), 30 deletions(-) diff --git a/examples/line/path/demo/road_light.js b/examples/line/path/demo/road_light.js index 6a3e19d77d..83d0af9a52 100644 --- a/examples/line/path/demo/road_light.js +++ b/examples/line/path/demo/road_light.js @@ -1,27 +1,80 @@ -import { Scene, LineLayer } from '@antv/l7'; -import { Mapbox } from '@antv/l7-maps'; +import { + Scene, + LineLayer +} from '@antv/l7'; +import { + Mapbox +} from '@antv/l7-maps'; +import { + GaodeMap +} from "@antv/l7-maps"; -const scene = new Scene({ - id: 'map', - map: new Mapbox({ - center: [ 116.3956, 39.9392 ], - pitch: 0, - zoom: 10, - rotation: 0, - style: 'light' +let mapData = [{ + path: [ + [118.186546, 39.666597], + [118.186546, 39.666597], + [118.186546, 39.666597], + [118.186546, 39.666597], + [118.186747, 39.664297], + [118.186751, 39.664301], + [118.186751, 39.664301], + [118.186751, 39.664301], + [118.186751, 39.664301], + [118.186751, 39.664301], + [118.195929, 39.670589], + [118.195929, 39.670589], + [118.195929, 39.670589], + [118.195929, 39.670589], + [118.142168, 39.646454], + [118.142168, 39.646453], + [118.142168, 39.646453], + [118.142168, 39.646453], + [118.437412, 39.88825], + [118.437412, 39.88825], + [118.437412, 39.88825], + [118.437412, 39.88825], + [118.437412, 39.88825], + [118.437412, 39.88825], + [118.437412, 39.88825], + [118.437412, 39.88825], + [118.437412, 39.88825], + [118.437412, 39.88825], + [118.437412, 39.88825], + [118.437412, 39.88825], + [118.437412, 39.88825], + [118.437412, 39.88825], + [118.437412, 39.88825], + [118.437412, 39.88825] + ] +}]; + +let map = new Scene({ + id: "map", + map: new GaodeMap({ + center: [118.142858, 39.674508], + zoom: 14, + type: "amap", + style: "light", + pitch: 0 }) }); -scene.on('loaded', () => { - fetch( - 'https://gw.alipayobjects.com/os/basement_prod/0d2f0113-f48b-4db9-8adc-a3937243d5a3.json' - ) - .then(res => res.json()) - .then(data => { - const layer = new LineLayer({}) - .source(data) - .size(1.5) - .shape('line') - .color('标准名称', [ '#5B8FF9', '#5CCEA1', '#5D7092' ]); - scene.addLayer(layer); - }); -}); +let line = new LineLayer() + .source(mapData, { + parser: { + type: "json", + coordinates: "path" + } + }) + .size(5, 10) + .shape("line") + .color("#25d8b7") + .select({ + color: "#eb4c44", + zIndex: 999 + }) + .animate({ + interval: 1, + duration: 5, + trailLength: 2 + }); +map.addLayer(line); diff --git a/packages/layers/src/utils/extrude_polyline.ts b/packages/layers/src/utils/extrude_polyline.ts index e44e0bf972..4c0a668e2e 100644 --- a/packages/layers/src/utils/extrude_polyline.ts +++ b/packages/layers/src/utils/extrude_polyline.ts @@ -34,12 +34,17 @@ function isPointEqual(a: vec2, b: vec2) { } function getArrayUnique(matrix: number[][]) { - const result: number[][] = []; - matrix.map((item) => { - item.sort((a, b) => b - a); - result.push(item); - }); - return result; + const map = new Map(); + for (let i = 0; i < matrix.length; i++) { + const key = matrix[0].toString() + '-' + matrix[1].toString(); + if (map.get(key)) { + matrix.splice(i, 1); + i++; + } else { + map.set(key, key); + } + } + return matrix; } export interface IExtrudeLineOption { From 02a181a4066eee10243275d6fd9ad9bb4e579194 Mon Sep 17 00:00:00 2001 From: ParryQiu Date: Fri, 28 Aug 2020 15:26:02 +0800 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=8E=BB=E9=99=A4?= =?UTF-8?q?=E9=87=8D=E5=A4=8D=E7=82=B9=E8=AE=A1=E7=AE=97=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E7=9A=84=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/line/path/demo/road_light.js | 92 +++++++-------------------- 1 file changed, 22 insertions(+), 70 deletions(-) diff --git a/examples/line/path/demo/road_light.js b/examples/line/path/demo/road_light.js index 83d0af9a52..779ac51a8d 100644 --- a/examples/line/path/demo/road_light.js +++ b/examples/line/path/demo/road_light.js @@ -5,76 +5,28 @@ import { import { Mapbox } from '@antv/l7-maps'; -import { - GaodeMap -} from "@antv/l7-maps"; -let mapData = [{ - path: [ - [118.186546, 39.666597], - [118.186546, 39.666597], - [118.186546, 39.666597], - [118.186546, 39.666597], - [118.186747, 39.664297], - [118.186751, 39.664301], - [118.186751, 39.664301], - [118.186751, 39.664301], - [118.186751, 39.664301], - [118.186751, 39.664301], - [118.195929, 39.670589], - [118.195929, 39.670589], - [118.195929, 39.670589], - [118.195929, 39.670589], - [118.142168, 39.646454], - [118.142168, 39.646453], - [118.142168, 39.646453], - [118.142168, 39.646453], - [118.437412, 39.88825], - [118.437412, 39.88825], - [118.437412, 39.88825], - [118.437412, 39.88825], - [118.437412, 39.88825], - [118.437412, 39.88825], - [118.437412, 39.88825], - [118.437412, 39.88825], - [118.437412, 39.88825], - [118.437412, 39.88825], - [118.437412, 39.88825], - [118.437412, 39.88825], - [118.437412, 39.88825], - [118.437412, 39.88825], - [118.437412, 39.88825], - [118.437412, 39.88825] - ] -}]; - -let map = new Scene({ - id: "map", - map: new GaodeMap({ - center: [118.142858, 39.674508], - zoom: 14, - type: "amap", - style: "light", - pitch: 0 +const scene = new Scene({ + id: 'map', + map: new Mapbox({ + center: [116.3956, 39.9392], + pitch: 0, + zoom: 10, + rotation: 0, + style: 'light' }) }); -let line = new LineLayer() - .source(mapData, { - parser: { - type: "json", - coordinates: "path" - } - }) - .size(5, 10) - .shape("line") - .color("#25d8b7") - .select({ - color: "#eb4c44", - zIndex: 999 - }) - .animate({ - interval: 1, - duration: 5, - trailLength: 2 - }); -map.addLayer(line); +scene.on('loaded', () => { + fetch( + 'https://gw.alipayobjects.com/os/basement_prod/0d2f0113-f48b-4db9-8adc-a3937243d5a3.json' + ) + .then(res => res.json()) + .then(data => { + const layer = new LineLayer({}) + .source(data) + .size(1.5) + .shape('line') + .color('标准名称', ['#5B8FF9', '#5CCEA1', '#5D7092']); + scene.addLayer(layer); + }); +}); From 9d2e91853aa54750d0059615aa0f2736c1bd6e7b Mon Sep 17 00:00:00 2001 From: ParryQiu Date: Fri, 28 Aug 2020 16:19:16 +0800 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20ExtrudePolyLine?= =?UTF-8?q?=20=E5=AF=B9=E5=BA=94=E7=9A=84=E5=8D=95=E5=85=83=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/line/path/demo/road_light.js | 8 ++++---- .../layers/src/utils/__tests__/extrude_polyline.spec.ts | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/line/path/demo/road_light.js b/examples/line/path/demo/road_light.js index 779ac51a8d..743ce809b4 100644 --- a/examples/line/path/demo/road_light.js +++ b/examples/line/path/demo/road_light.js @@ -9,7 +9,7 @@ import { const scene = new Scene({ id: 'map', map: new Mapbox({ - center: [116.3956, 39.9392], + center: [ 116.3956, 39.9392 ], pitch: 0, zoom: 10, rotation: 0, @@ -18,15 +18,15 @@ const scene = new Scene({ }); scene.on('loaded', () => { fetch( - 'https://gw.alipayobjects.com/os/basement_prod/0d2f0113-f48b-4db9-8adc-a3937243d5a3.json' - ) + 'https://gw.alipayobjects.com/os/basement_prod/0d2f0113-f48b-4db9-8adc-a3937243d5a3.json' + ) .then(res => res.json()) .then(data => { const layer = new LineLayer({}) .source(data) .size(1.5) .shape('line') - .color('标准名称', ['#5B8FF9', '#5CCEA1', '#5D7092']); + .color('标准名称', [ '#5B8FF9', '#5CCEA1', '#5D7092' ]); scene.addLayer(layer); }); }); diff --git a/packages/layers/src/utils/__tests__/extrude_polyline.spec.ts b/packages/layers/src/utils/__tests__/extrude_polyline.spec.ts index c2ce9a7eb7..9cea6c49ce 100644 --- a/packages/layers/src/utils/__tests__/extrude_polyline.spec.ts +++ b/packages/layers/src/utils/__tests__/extrude_polyline.spec.ts @@ -18,6 +18,6 @@ describe('extrude polyline', () => { coord[1] = lat; }); const mesh = extrude.extrude(coords); - expect(mesh.indices.length).toBe(12); + expect(mesh.indices.length).toBe(6); }); });