@opentripplanner/trip-viewer-overlay 2.0.0-alpha.1 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/index.js +23 -24
- package/esm/index.js.map +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +24 -25
- package/lib/index.js.map +1 -1
- package/package.json +3 -3
- package/src/TripViewerOverlay.story.tsx +14 -19
- package/src/index.tsx +21 -16
- package/tsconfig.tsbuildinfo +1 -3680
package/esm/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import React, { useEffect } from "react";
|
|
2
1
|
import polyline from "@mapbox/polyline";
|
|
3
|
-
import { Layer, Source, useMap } from "react-map-gl";
|
|
4
2
|
import { LngLatBounds } from "maplibre-gl";
|
|
3
|
+
import { Layer, Source, useMap } from "react-map-gl";
|
|
4
|
+
import React, { useEffect, useMemo } from "react";
|
|
5
5
|
|
|
6
6
|
var TripViewerOverlay = function TripViewerOverlay(props) {
|
|
7
7
|
var path = props.path,
|
|
@@ -13,32 +13,31 @@ var TripViewerOverlay = function TripViewerOverlay(props) {
|
|
|
13
13
|
var pts = polyline.decode(geometry.points).map(function (pt) {
|
|
14
14
|
return pt.reverse();
|
|
15
15
|
});
|
|
16
|
+
var bounds = useMemo(function () {
|
|
17
|
+
return pts.reduce(function (bnds, coord) {
|
|
18
|
+
return bnds.extend(coord);
|
|
19
|
+
}, new LngLatBounds(pts[0], pts[0]));
|
|
20
|
+
}, [pts]);
|
|
16
21
|
|
|
17
22
|
var _useMap = useMap(),
|
|
18
|
-
|
|
23
|
+
map = _useMap.current;
|
|
19
24
|
|
|
20
25
|
useEffect(function () {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
bottom: 25,
|
|
29
|
-
left: 15,
|
|
30
|
-
right: 5
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
}, [mainMap]);
|
|
26
|
+
if (bounds.length === 4 && bounds.every(Number.isFinite)) {
|
|
27
|
+
map === null || map === void 0 ? void 0 : map.fitBounds(bounds, {
|
|
28
|
+
duration: 500,
|
|
29
|
+
padding: 200
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}, [map, bounds]);
|
|
34
33
|
if (!visible || !pts) return null;
|
|
35
34
|
var geojson = {
|
|
36
35
|
type: "Feature",
|
|
37
|
-
properties: [],
|
|
38
36
|
geometry: {
|
|
39
37
|
type: "LineString",
|
|
40
38
|
coordinates: pts
|
|
41
|
-
}
|
|
39
|
+
},
|
|
40
|
+
properties: []
|
|
42
41
|
};
|
|
43
42
|
return /*#__PURE__*/React.createElement(Source, {
|
|
44
43
|
id: "route",
|
|
@@ -46,16 +45,16 @@ var TripViewerOverlay = function TripViewerOverlay(props) {
|
|
|
46
45
|
data: geojson
|
|
47
46
|
}, /*#__PURE__*/React.createElement(Layer, {
|
|
48
47
|
id: "route",
|
|
49
|
-
type: "line",
|
|
50
48
|
layout: {
|
|
51
|
-
"line-
|
|
52
|
-
"line-
|
|
49
|
+
"line-cap": "round",
|
|
50
|
+
"line-join": "round"
|
|
53
51
|
},
|
|
54
52
|
paint: {
|
|
55
53
|
"line-color": (path === null || path === void 0 ? void 0 : path.color) || "#00bfff",
|
|
56
|
-
"line-
|
|
57
|
-
"line-
|
|
58
|
-
}
|
|
54
|
+
"line-opacity": (path === null || path === void 0 ? void 0 : path.opacity) || 0.6,
|
|
55
|
+
"line-width": (path === null || path === void 0 ? void 0 : path.weight) || 8
|
|
56
|
+
},
|
|
57
|
+
type: "line"
|
|
59
58
|
}));
|
|
60
59
|
};
|
|
61
60
|
|
package/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.tsx"],"names":["
|
|
1
|
+
{"version":3,"sources":["../src/index.tsx"],"names":["polyline","LngLatBounds","Layer","Source","useMap","React","useEffect","useMemo","TripViewerOverlay","props","path","tripData","visible","geometry","pts","decode","points","map","pt","reverse","bounds","reduce","bnds","coord","extend","current","length","every","Number","isFinite","fitBounds","duration","padding","geojson","type","coordinates","properties","color","opacity","weight"],"mappings":"AAAA,OAAOA,QAAP,MAAqB,kBAArB;AACA,SAASC,YAAT,QAA6B,aAA7B;AACA,SAASC,KAAT,EAAgBC,MAAhB,EAAwBC,MAAxB,QAAsC,cAAtC;AACA,OAAOC,KAAP,IAAgBC,SAAhB,EAA2BC,OAA3B,QAA0C,OAA1C;;AAWA,IAAMC,iBAAiB,GAAG,SAApBA,iBAAoB,CAACC,KAAD,EAA+B;AACvD,MAAQC,IAAR,GAAoCD,KAApC,CAAQC,IAAR;AAAA,MAAcC,QAAd,GAAoCF,KAApC,CAAcE,QAAd;AAAA,MAAwBC,OAAxB,GAAoCH,KAApC,CAAwBG,OAAxB;AACA,MAAI,CAACD,QAAL,EAAe,OAAO,IAAP;AAEf,MAAQE,QAAR,GAAqBF,QAArB,CAAQE,QAAR;AAEA,MAAI,CAACA,QAAL,EAAe,OAAO,IAAP;AAEf,MAAMC,GAAG,GAAGd,QAAQ,CACjBe,MADS,CACFF,QAAQ,CAACG,MADP,EAETC,GAFS,CAEL,UAACC,EAAD;AAAA,WAA0BA,EAAE,CAACC,OAAH,EAA1B;AAAA,GAFK,CAAZ;AAIA,MAAMC,MAAM,GAAGb,OAAO,CAAC,YAAM;AAC3B,WAAOO,GAAG,CAACO,MAAJ,CAAW,UAACC,IAAD,EAAOC,KAAP,EAAiB;AACjC,aAAOD,IAAI,CAACE,MAAL,CAAYD,KAAZ,CAAP;AACD,KAFM,EAEJ,IAAItB,YAAJ,CAAiBa,GAAG,CAAC,CAAD,CAApB,EAAyBA,GAAG,CAAC,CAAD,CAA5B,CAFI,CAAP;AAGD,GAJqB,EAInB,CAACA,GAAD,CAJmB,CAAtB;;AAMA,gBAAyBV,MAAM,EAA/B;AAAA,MAAiBa,GAAjB,WAAQQ,OAAR;;AACAnB,EAAAA,S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AlDD;;AAoDA,eAAe/B,iBAAf","sourcesContent":["import polyline from \"@mapbox/polyline\";\nimport { LngLatBounds } from \"maplibre-gl\";\nimport { Layer, Source, useMap } from \"react-map-gl\";\nimport React, { useEffect, useMemo } from \"react\";\n\ntype Props = {\n path?: {\n color?: string;\n opacity?: number;\n weight?: number;\n };\n tripData: { geometry: { points: string; length: number } };\n visible?: boolean;\n};\nconst TripViewerOverlay = (props: Props): JSX.Element => {\n const { path, tripData, visible } = props;\n if (!tripData) return null;\n\n const { geometry } = tripData;\n\n if (!geometry) return null;\n\n const pts = polyline\n .decode(geometry.points)\n .map((pt: [number, number]) => pt.reverse());\n\n const bounds = useMemo(() => {\n return pts.reduce((bnds, coord) => {\n return bnds.extend(coord);\n }, new LngLatBounds(pts[0], pts[0]));\n }, [pts]);\n\n const { current: map } = useMap();\n useEffect(() => {\n if (bounds.length === 4 && bounds.every(Number.isFinite)) {\n map?.fitBounds(bounds, {\n duration: 500,\n padding: 200\n });\n }\n }, [map, bounds]);\n\n if (!visible || !pts) return null;\n\n const geojson: GeoJSON.Feature = {\n type: \"Feature\",\n geometry: { type: \"LineString\", coordinates: pts },\n properties: []\n };\n\n return (\n <Source id=\"route\" type=\"geojson\" data={geojson}>\n <Layer\n id=\"route\"\n layout={{ \"line-cap\": \"round\", \"line-join\": \"round\" }}\n paint={{\n \"line-color\": path?.color || \"#00bfff\",\n \"line-opacity\": path?.opacity || 0.6,\n \"line-width\": path?.weight || 8\n }}\n type=\"line\"\n />\n </Source>\n );\n};\n\nexport default TripViewerOverlay;\n"],"file":"index.js"}
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":";AAKA,aAAK,KAAK,GAAG;IACX,IAAI,CAAC,EAAE;QACL,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,CAAC;IACF,QAAQ,EAAE;QAAE,QAAQ,EAAE;YAAE,MAAM,EAAE,MAAM,CAAC;YAAC,MAAM,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,CAAC;IAC3D,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AACF,QAAA,MAAM,iBAAiB,UAAW,KAAK,KAAG,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":";AAKA,aAAK,KAAK,GAAG;IACX,IAAI,CAAC,EAAE;QACL,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,CAAC;IACF,QAAQ,EAAE;QAAE,QAAQ,EAAE;YAAE,MAAM,EAAE,MAAM,CAAC;YAAC,MAAM,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,CAAC;IAC3D,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AACF,QAAA,MAAM,iBAAiB,UAAW,KAAK,KAAG,WAkDzC,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -7,13 +7,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports.default = void 0;
|
|
9
9
|
|
|
10
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
11
|
-
|
|
12
10
|
var _polyline = _interopRequireDefault(require("@mapbox/polyline"));
|
|
13
11
|
|
|
12
|
+
var _maplibreGl = require("maplibre-gl");
|
|
13
|
+
|
|
14
14
|
var _reactMapGl = require("react-map-gl");
|
|
15
15
|
|
|
16
|
-
var
|
|
16
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
17
17
|
|
|
18
18
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
19
19
|
|
|
@@ -33,31 +33,30 @@ const TripViewerOverlay = props => {
|
|
|
33
33
|
|
|
34
34
|
const pts = _polyline.default.decode(geometry.points).map(pt => pt.reverse());
|
|
35
35
|
|
|
36
|
+
const bounds = (0, _react.useMemo)(() => {
|
|
37
|
+
return pts.reduce((bnds, coord) => {
|
|
38
|
+
return bnds.extend(coord);
|
|
39
|
+
}, new _maplibreGl.LngLatBounds(pts[0], pts[0]));
|
|
40
|
+
}, [pts]);
|
|
36
41
|
const {
|
|
37
|
-
|
|
42
|
+
current: map
|
|
38
43
|
} = (0, _reactMapGl.useMap)();
|
|
39
44
|
(0, _react.useEffect)(() => {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
bottom: 25,
|
|
48
|
-
left: 15,
|
|
49
|
-
right: 5
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
}, [mainMap]);
|
|
45
|
+
if (bounds.length === 4 && bounds.every(Number.isFinite)) {
|
|
46
|
+
map === null || map === void 0 ? void 0 : map.fitBounds(bounds, {
|
|
47
|
+
duration: 500,
|
|
48
|
+
padding: 200
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}, [map, bounds]);
|
|
53
52
|
if (!visible || !pts) return null;
|
|
54
53
|
const geojson = {
|
|
55
54
|
type: "Feature",
|
|
56
|
-
properties: [],
|
|
57
55
|
geometry: {
|
|
58
56
|
type: "LineString",
|
|
59
57
|
coordinates: pts
|
|
60
|
-
}
|
|
58
|
+
},
|
|
59
|
+
properties: []
|
|
61
60
|
};
|
|
62
61
|
return /*#__PURE__*/_react.default.createElement(_reactMapGl.Source, {
|
|
63
62
|
id: "route",
|
|
@@ -65,16 +64,16 @@ const TripViewerOverlay = props => {
|
|
|
65
64
|
data: geojson
|
|
66
65
|
}, /*#__PURE__*/_react.default.createElement(_reactMapGl.Layer, {
|
|
67
66
|
id: "route",
|
|
68
|
-
type: "line",
|
|
69
67
|
layout: {
|
|
70
|
-
"line-
|
|
71
|
-
"line-
|
|
68
|
+
"line-cap": "round",
|
|
69
|
+
"line-join": "round"
|
|
72
70
|
},
|
|
73
71
|
paint: {
|
|
74
72
|
"line-color": (path === null || path === void 0 ? void 0 : path.color) || "#00bfff",
|
|
75
|
-
"line-
|
|
76
|
-
"line-
|
|
77
|
-
}
|
|
73
|
+
"line-opacity": (path === null || path === void 0 ? void 0 : path.opacity) || 0.6,
|
|
74
|
+
"line-width": (path === null || path === void 0 ? void 0 : path.weight) || 8
|
|
75
|
+
},
|
|
76
|
+
type: "line"
|
|
78
77
|
}));
|
|
79
78
|
};
|
|
80
79
|
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.tsx"],"names":["TripViewerOverlay","props","path","tripData","visible","geometry","pts","polyline","decode","points","map","pt","reverse","
|
|
1
|
+
{"version":3,"sources":["../src/index.tsx"],"names":["TripViewerOverlay","props","path","tripData","visible","geometry","pts","polyline","decode","points","map","pt","reverse","bounds","reduce","bnds","coord","extend","LngLatBounds","current","length","every","Number","isFinite","fitBounds","duration","padding","geojson","type","coordinates","properties","color","opacity","weight"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AACA;;;;;;AAWA,MAAMA,iBAAiB,GAAIC,KAAD,IAA+B;AACvD,QAAM;AAAEC,IAAAA,IAAF;AAAQC,IAAAA,QAAR;AAAkBC,IAAAA;AAAlB,MAA8BH,KAApC;AACA,MAAI,CAACE,QAAL,EAAe,OAAO,IAAP;AAEf,QAAM;AAAEE,IAAAA;AAAF,MAAeF,QAArB;AAEA,MAAI,CAACE,QAAL,EAAe,OAAO,IAAP;;AAEf,QAAMC,GAAG,GAAGC,kBACTC,MADS,CACFH,QAAQ,CAACI,MADP,EAETC,GAFS,CAEJC,EAAD,IA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AM,EAAE;AAAE,kBAAY,OAAd;AAAuB,mBAAa;AAApC,KAFV;AAGE,IAAA,KAAK,EAAE;AACL,oBAAc,CAAAzB,IAAI,SAAJ,IAAAA,IAAI,WAAJ,YAAAA,IAAI,CAAE6B,KAAN,KAAe,SADxB;AAEL,sBAAgB,CAAA7B,IAAI,SAAJ,IAAAA,IAAI,WAAJ,YAAAA,IAAI,CAAE8B,OAAN,KAAiB,GAF5B;AAGL,oBAAc,CAAA9B,IAAI,SAAJ,IAAAA,IAAI,WAAJ,YAAAA,IAAI,CAAE+B,MAAN,KAAgB;AAHzB,KAHT;AAQE,IAAA,IAAI,EAAC;AARP,IADF,CADF;AAcD,CAlDD;;eAoDejC,iB","sourcesContent":["import polyline from \"@mapbox/polyline\";\nimport { LngLatBounds } from \"maplibre-gl\";\nimport { Layer, Source, useMap } from \"react-map-gl\";\nimport React, { useEffect, useMemo } from \"react\";\n\ntype Props = {\n path?: {\n color?: string;\n opacity?: number;\n weight?: number;\n };\n tripData: { geometry: { points: string; length: number } };\n visible?: boolean;\n};\nconst TripViewerOverlay = (props: Props): JSX.Element => {\n const { path, tripData, visible } = props;\n if (!tripData) return null;\n\n const { geometry } = tripData;\n\n if (!geometry) return null;\n\n const pts = polyline\n .decode(geometry.points)\n .map((pt: [number, number]) => pt.reverse());\n\n const bounds = useMemo(() => {\n return pts.reduce((bnds, coord) => {\n return bnds.extend(coord);\n }, new LngLatBounds(pts[0], pts[0]));\n }, [pts]);\n\n const { current: map } = useMap();\n useEffect(() => {\n if (bounds.length === 4 && bounds.every(Number.isFinite)) {\n map?.fitBounds(bounds, {\n duration: 500,\n padding: 200\n });\n }\n }, [map, bounds]);\n\n if (!visible || !pts) return null;\n\n const geojson: GeoJSON.Feature = {\n type: \"Feature\",\n geometry: { type: \"LineString\", coordinates: pts },\n properties: []\n };\n\n return (\n <Source id=\"route\" type=\"geojson\" data={geojson}>\n <Layer\n id=\"route\"\n layout={{ \"line-cap\": \"round\", \"line-join\": \"round\" }}\n paint={{\n \"line-color\": path?.color || \"#00bfff\",\n \"line-opacity\": path?.opacity || 0.6,\n \"line-width\": path?.weight || 8\n }}\n type=\"line\"\n />\n </Source>\n );\n};\n\nexport default TripViewerOverlay;\n"],"file":"index.js"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opentripplanner/trip-viewer-overlay",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "A map overlay to show a trip of a route",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "esm/index.js",
|
|
@@ -20,10 +20,10 @@
|
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@mapbox/polyline": "^1.1.0",
|
|
23
|
-
"@opentripplanner/
|
|
23
|
+
"@opentripplanner/base-map": "^3.0.0",
|
|
24
|
+
"@opentripplanner/core-utils": "^7.0.1"
|
|
24
25
|
},
|
|
25
26
|
"peerDependencies": {
|
|
26
|
-
"@opentripplanner/base-map": "^2.0.0",
|
|
27
27
|
"react": "^16.14.0",
|
|
28
28
|
"react-map-gl": "^7.0.15"
|
|
29
29
|
},
|
|
@@ -1,35 +1,30 @@
|
|
|
1
|
-
import BaseMap from "@opentripplanner/base-map";
|
|
2
1
|
import React from "react";
|
|
3
2
|
|
|
4
3
|
import tripData from "../__mocks__/mock-trip.json";
|
|
5
4
|
import TripViewerOverlay from ".";
|
|
6
|
-
|
|
7
|
-
import "maplibre-gl/dist/maplibre-gl.css";
|
|
5
|
+
import { withMap } from "../../../.storybook/base-map-wrapper";
|
|
8
6
|
|
|
9
7
|
const center: [number, number] = [45.518092, -122.671202];
|
|
10
|
-
const zoom =
|
|
8
|
+
const zoom = 12;
|
|
11
9
|
|
|
12
10
|
export default {
|
|
13
11
|
title: "TripViewerOverlay",
|
|
14
|
-
component: TripViewerOverlay
|
|
12
|
+
component: TripViewerOverlay,
|
|
13
|
+
decorators: [withMap(center, zoom)]
|
|
15
14
|
};
|
|
16
15
|
|
|
17
16
|
export const Default = (): JSX.Element => (
|
|
18
|
-
<
|
|
19
|
-
<TripViewerOverlay tripData={tripData} visible />
|
|
20
|
-
</BaseMap>
|
|
17
|
+
<TripViewerOverlay tripData={tripData} visible />
|
|
21
18
|
);
|
|
22
19
|
|
|
23
20
|
export const WithPathStyling = (): JSX.Element => (
|
|
24
|
-
<
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
/>
|
|
34
|
-
</BaseMap>
|
|
21
|
+
<TripViewerOverlay
|
|
22
|
+
path={{
|
|
23
|
+
color: "#000",
|
|
24
|
+
opacity: 0.2,
|
|
25
|
+
weight: 5
|
|
26
|
+
}}
|
|
27
|
+
tripData={tripData}
|
|
28
|
+
visible
|
|
29
|
+
/>
|
|
35
30
|
);
|
package/src/index.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import React, { useEffect } from "react";
|
|
2
1
|
import polyline from "@mapbox/polyline";
|
|
3
|
-
import { Layer, Source, useMap } from "react-map-gl";
|
|
4
2
|
import { LngLatBounds } from "maplibre-gl";
|
|
3
|
+
import { Layer, Source, useMap } from "react-map-gl";
|
|
4
|
+
import React, { useEffect, useMemo } from "react";
|
|
5
5
|
|
|
6
6
|
type Props = {
|
|
7
7
|
path?: {
|
|
@@ -23,37 +23,42 @@ const TripViewerOverlay = (props: Props): JSX.Element => {
|
|
|
23
23
|
const pts = polyline
|
|
24
24
|
.decode(geometry.points)
|
|
25
25
|
.map((pt: [number, number]) => pt.reverse());
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
|
|
27
|
+
const bounds = useMemo(() => {
|
|
28
|
+
return pts.reduce((bnds, coord) => {
|
|
29
29
|
return bnds.extend(coord);
|
|
30
30
|
}, new LngLatBounds(pts[0], pts[0]));
|
|
31
|
+
}, [pts]);
|
|
31
32
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
const { current: map } = useMap();
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
if (bounds.length === 4 && bounds.every(Number.isFinite)) {
|
|
36
|
+
map?.fitBounds(bounds, {
|
|
37
|
+
duration: 500,
|
|
38
|
+
padding: 200
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}, [map, bounds]);
|
|
37
42
|
|
|
38
43
|
if (!visible || !pts) return null;
|
|
39
44
|
|
|
40
45
|
const geojson: GeoJSON.Feature = {
|
|
41
46
|
type: "Feature",
|
|
42
|
-
|
|
43
|
-
|
|
47
|
+
geometry: { type: "LineString", coordinates: pts },
|
|
48
|
+
properties: []
|
|
44
49
|
};
|
|
45
50
|
|
|
46
51
|
return (
|
|
47
52
|
<Source id="route" type="geojson" data={geojson}>
|
|
48
53
|
<Layer
|
|
49
54
|
id="route"
|
|
50
|
-
|
|
51
|
-
layout={{ "line-join": "round", "line-cap": "round" }}
|
|
55
|
+
layout={{ "line-cap": "round", "line-join": "round" }}
|
|
52
56
|
paint={{
|
|
53
57
|
"line-color": path?.color || "#00bfff",
|
|
54
|
-
"line-
|
|
55
|
-
"line-
|
|
58
|
+
"line-opacity": path?.opacity || 0.6,
|
|
59
|
+
"line-width": path?.weight || 8
|
|
56
60
|
}}
|
|
61
|
+
type="line"
|
|
57
62
|
/>
|
|
58
63
|
</Source>
|
|
59
64
|
);
|