From ccf903156024a9cb5a0e3e61338cc6ea03c8fcb8 Mon Sep 17 00:00:00 2001 From: LittleC Date: Sun, 1 Aug 2021 18:10:08 +0800 Subject: [PATCH] :sparkles: line --- src/main.ts | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/main.ts b/src/main.ts index 022d248..03cf198 100644 --- a/src/main.ts +++ b/src/main.ts @@ -61,9 +61,18 @@ window.amapLoaded = function () { zIndex: 1000, collision: false }) + + // 创建连线 + let paths: Record = {} + let pathColors: Record = {} let massItems: AMap.MassData[] = [] for (const item of data) { let s = item.season.split("-")[0].match(/([A-Z]+)[0-9]+/)?.[1] + let detailSeason = item.season.split("-")[0] + paths[detailSeason] ||= [] + paths[detailSeason].push(new AMap.LngLat(item.GDlng, item.Gdlat)) + pathColors[detailSeason] = item.sort % colors.length + const marker = new AMap.LabelMarker({ name: item.name, position: [item.GDlng, item.Gdlat], @@ -112,6 +121,33 @@ window.amapLoaded = function () { map.add(layer) massMarks.setData(massItems) massMarks.setMap(map) + + let polylines = Object.keys(paths).map((k: string) => { + return new AMap.Polyline({ + path: paths[k], + borderWeight: 2, + strokeColor: colors[pathColors[k]], + lineJoin: 'round', + zooms: [15, 19], + strokeOpacity: 0.5, + showDir: true + }) + }) + let showLines = false + map.on('zoomend', () => { + if (map.getZoom() >= 13) { + if (!showLines) { + map.add(polylines) + } + showLines = true + } else { + if (showLines) { + map.remove(polylines) + } + showLines = false + } + }) + // @ts-ignore document.getElementById("root")?.insertAdjacentHTML('beforeend', '
    ' + names.map(v => `