@opentripplanner/trip-viewer-overlay 1.1.1 → 2.0.0-alpha.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 +58 -92
- package/esm/index.js.map +1 -1
- package/lib/index.d.ts +18 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +67 -74
- package/lib/index.js.map +1 -1
- package/package.json +6 -6
- package/src/{TripViewerOverlay.story.js → TripViewerOverlay.story.tsx} +7 -8
- package/src/index.tsx +62 -0
- package/tsconfig.json +15 -0
- package/tsconfig.tsbuildinfo +3680 -0
- package/src/index.js +0 -70
package/esm/index.js
CHANGED
|
@@ -1,97 +1,63 @@
|
|
|
1
|
-
import
|
|
2
|
-
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
3
|
-
import _createClass from "@babel/runtime/helpers/createClass";
|
|
4
|
-
import _inherits from "@babel/runtime/helpers/inherits";
|
|
5
|
-
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
6
|
-
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
7
|
-
|
|
8
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
9
|
-
|
|
10
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
11
|
-
|
|
12
|
-
import coreUtils from "@opentripplanner/core-utils";
|
|
13
|
-
import PropTypes from "prop-types";
|
|
14
|
-
import React from "react";
|
|
15
|
-
import { FeatureGroup, MapLayer, Polyline, withLeaflet } from "react-leaflet";
|
|
1
|
+
import React, { useEffect } from "react";
|
|
16
2
|
import polyline from "@mapbox/polyline";
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
var
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
3
|
+
import { Layer, Source, useMap } from "react-map-gl";
|
|
4
|
+
import { LngLatBounds } from "maplibre-gl";
|
|
5
|
+
|
|
6
|
+
var TripViewerOverlay = function TripViewerOverlay(props) {
|
|
7
|
+
var path = props.path,
|
|
8
|
+
tripData = props.tripData,
|
|
9
|
+
visible = props.visible;
|
|
10
|
+
if (!tripData) return null;
|
|
11
|
+
var geometry = tripData.geometry;
|
|
12
|
+
if (!geometry) return null;
|
|
13
|
+
var pts = polyline.decode(geometry.points).map(function (pt) {
|
|
14
|
+
return pt.reverse();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
var _useMap = useMap(),
|
|
18
|
+
mainMap = _useMap.mainMap;
|
|
19
|
+
|
|
20
|
+
useEffect(function () {
|
|
21
|
+
var bounds = pts.reduce(function (bnds, coord) {
|
|
22
|
+
return bnds.extend(coord);
|
|
23
|
+
}, new LngLatBounds(pts[0], pts[0]));
|
|
24
|
+
mainMap === null || mainMap === void 0 ? void 0 : mainMap.fitBounds(bounds, {
|
|
25
|
+
duration: 100,
|
|
26
|
+
padding: {
|
|
27
|
+
top: 10,
|
|
28
|
+
bottom: 25,
|
|
29
|
+
left: 15,
|
|
30
|
+
right: 5
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}, [mainMap]);
|
|
34
|
+
if (!visible || !pts) return null;
|
|
35
|
+
var geojson = {
|
|
36
|
+
type: "Feature",
|
|
37
|
+
properties: [],
|
|
38
|
+
geometry: {
|
|
39
|
+
type: "LineString",
|
|
40
|
+
coordinates: pts
|
|
47
41
|
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
})));
|
|
42
|
+
};
|
|
43
|
+
return /*#__PURE__*/React.createElement(Source, {
|
|
44
|
+
id: "route",
|
|
45
|
+
type: "geojson",
|
|
46
|
+
data: geojson
|
|
47
|
+
}, /*#__PURE__*/React.createElement(Layer, {
|
|
48
|
+
id: "route",
|
|
49
|
+
type: "line",
|
|
50
|
+
layout: {
|
|
51
|
+
"line-join": "round",
|
|
52
|
+
"line-cap": "round"
|
|
53
|
+
},
|
|
54
|
+
paint: {
|
|
55
|
+
"line-color": (path === null || path === void 0 ? void 0 : path.color) || "#00bfff",
|
|
56
|
+
"line-width": (path === null || path === void 0 ? void 0 : path.weight) || 8,
|
|
57
|
+
"line-opacity": (path === null || path === void 0 ? void 0 : path.opacity) || 0.6
|
|
65
58
|
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return TripViewerOverlay;
|
|
69
|
-
}(MapLayer);
|
|
70
|
-
|
|
71
|
-
TripViewerOverlay.propTypes = {
|
|
72
|
-
/**
|
|
73
|
-
* Leaflet path properties to use to style the polyline that represents the
|
|
74
|
-
* trip.
|
|
75
|
-
*
|
|
76
|
-
* See https://leafletjs.com/reference-1.6.0.html#path
|
|
77
|
-
*/
|
|
78
|
-
leafletPath: coreUtils.types.leafletPathType,
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* This represents data about a trip as obtained from a transit index.
|
|
82
|
-
* Typically a trip has more data than these items, so this is only a list of
|
|
83
|
-
* the properties that this component actually uses.
|
|
84
|
-
*/
|
|
85
|
-
tripData: PropTypes.shape({
|
|
86
|
-
geometry: coreUtils.types.encodedPolylineType
|
|
87
|
-
})
|
|
88
|
-
};
|
|
89
|
-
TripViewerOverlay.defaultProps = {
|
|
90
|
-
leafletPath: {
|
|
91
|
-
color: "#00bfff",
|
|
92
|
-
opacity: 0.6,
|
|
93
|
-
weight: 8
|
|
94
|
-
}
|
|
59
|
+
}));
|
|
95
60
|
};
|
|
96
|
-
|
|
61
|
+
|
|
62
|
+
export default TripViewerOverlay;
|
|
97
63
|
//# sourceMappingURL=index.js.map
|
package/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.
|
|
1
|
+
{"version":3,"sources":["../src/index.tsx"],"names":["React","useEffect","polyline","Layer","Source","useMap","LngLatBounds","TripViewerOverlay","props","path","tripData","visible","geometry","pts","decode","points","map","pt","reverse","mainMap","bounds","reduce","bnds","coord","extend","fitBounds","duration","padding","top","bottom","left","right","geojson","type","properties","coordinates","color","weight","opacity"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,SAAhB,QAAiC,OAAjC;AACA,OAAOC,QAAP,MAAqB,kBAArB;AACA,SAASC,KAAT,EAAgBC,MAAhB,EAAwBC,MAAxB,QAAsC,cAAtC;AACA,SAASC,YAAT,QAA6B,aAA7B;;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,GAAGX,QAAQ,CACjBY,MADS,CACFF,QAAQ,CAACG,MADP,EAETC,GAFS,CAEL,UAACC,EAAD;AAAA,WAA0BA,EAAE,CAACC,OAAH,EAA1B;AAAA,GAFK,CAAZ;;AAGA,gBAAoBb,MAAM,EAA1B;AAAA,MAAQc,OAAR,WAAQA,OAAR;;AACAlB,EAAAA,SAAS,CAAC,YAAM;AACd,QAAMmB,MAAM,GAAGP,GAAG,CAACQ,MAAJ,CAAW,UAACC,IAAD,EAAOC,KAAP,EAAiB;AACzC,aAAOD,IAAI,CAACE,MAAL,CAAYD,KAAZ,CAAP;AACD,KAFc,EAEZ,IAAIjB,YAAJ,CAAiBO,GAAG,CAAC,CAAD,CAApB,EAAyBA,GAAG,CAAC,CAAD,CAA5B,CAFY,CAAf;AAIAM,IAAAA,OAAO,SAAP,IAAAA,OAAO,WAAP,YAAAA,OAAO,CAAEM,SAAT,CAAmBL,MAAnB,EAA2B;AACzBM,MAAAA,QAAQ,EAAE,GADe;AAEzBC,MAAAA,OAAO,EAAE;AAAEC,QAAAA,GAAG,EAAE,EAAP;AAAWC,QAAAA,MAAM,EAAE,EAAnB;AAAuBC,QAAAA,IAAI,EAAE,EAA7B;AAAiCC,QAAAA,KAAK,EAAE;AAAxC;AAFgB,KAA3B;AAID,GATQ,EASN,CAACZ,OAAD,CATM,CAAT;AAWA,MAAI,CAACR,OAAD,IAAY,CAACE,GAAjB,EAAsB,OAAO,IAAP;AAEtB,MAAMmB,OAAwB,GAAG;AAC/BC,IAAAA,IAAI,EAAE,SADyB;AAE/BC,IAAAA,UAAU,EAAE,EAFmB;AAG/BtB,IAAAA,QAAQ,EAAE;AAAEqB,MAAAA,IAAI,EAAE,YAAR;AAAsBE,MAAAA,WAAW,EAAEtB;AAAnC;AAHqB,GAAjC;AAMA,sBACE,oBAAC,MAAD;AAAQ,IAAA,EAAE,EAAC,OAAX;AAAmB,IAAA,IAAI,EAAC,SAAxB;AAAkC,IAAA,IAAI,EAAEmB;AAAxC,kBACE,oBAAC,KAAD;AACE,IAAA,EAAE,EAAC,OADL;AAEE,IAAA,IAAI,EAAC,MAFP;AAGE,IAAA,MAAM,EAAE;AAAE,mBAAa,OAAf;AAAwB,kBAAY;AAApC,KAHV;AAIE,IAAA,KAAK,EAAE;AACL,oBAAc,CAAAvB,IAAI,SAAJ,IAAAA,IAAI,WAAJ,YAAAA,IAAI,CAAE2B,KAAN,KAAe,SADxB;AAEL,oBAAc,CAAA3B,IAAI,SAAJ,IAAAA,IAAI,WAAJ,YAAAA,IAAI,CAAE4B,MAAN,KAAgB,CAFzB;AAGL,sBAAgB,CAAA5B,IAAI,SAAJ,IAAAA,IAAI,WAAJ,YAAAA,IAAI,CAAE6B,OAAN,KAAiB;AAH5B;AAJT,IADF,CADF;AAcD,CA7CD;;AA+CA,eAAe/B,iBAAf","sourcesContent":["import React, { useEffect } from \"react\";\nimport polyline from \"@mapbox/polyline\";\nimport { Layer, Source, useMap } from \"react-map-gl\";\nimport { LngLatBounds } from \"maplibre-gl\";\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 const { mainMap } = useMap();\n useEffect(() => {\n const bounds = pts.reduce((bnds, coord) => {\n return bnds.extend(coord);\n }, new LngLatBounds(pts[0], pts[0]));\n\n mainMap?.fitBounds(bounds, {\n duration: 100,\n padding: { top: 10, bottom: 25, left: 15, right: 5 }\n });\n }, [mainMap]);\n\n if (!visible || !pts) return null;\n\n const geojson: GeoJSON.Feature = {\n type: \"Feature\",\n properties: [],\n geometry: { type: \"LineString\", coordinates: pts }\n };\n\n return (\n <Source id=\"route\" type=\"geojson\" data={geojson}>\n <Layer\n id=\"route\"\n type=\"line\"\n layout={{ \"line-join\": \"round\", \"line-cap\": \"round\" }}\n paint={{\n \"line-color\": path?.color || \"#00bfff\",\n \"line-width\": path?.weight || 8,\n \"line-opacity\": path?.opacity || 0.6\n }}\n />\n </Source>\n );\n};\n\nexport default TripViewerOverlay;\n"],"file":"index.js"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
declare type Props = {
|
|
3
|
+
path?: {
|
|
4
|
+
color?: string;
|
|
5
|
+
opacity?: number;
|
|
6
|
+
weight?: number;
|
|
7
|
+
};
|
|
8
|
+
tripData: {
|
|
9
|
+
geometry: {
|
|
10
|
+
points: string;
|
|
11
|
+
length: number;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
visible?: boolean;
|
|
15
|
+
};
|
|
16
|
+
declare const TripViewerOverlay: (props: Props) => JSX.Element;
|
|
17
|
+
export default TripViewerOverlay;
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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,WA6CzC,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -7,84 +7,77 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports.default = void 0;
|
|
9
9
|
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
var _coreUtils = _interopRequireDefault(require("@opentripplanner/core-utils"));
|
|
13
|
-
|
|
14
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
15
|
-
|
|
16
|
-
var _react = _interopRequireDefault(require("react"));
|
|
17
|
-
|
|
18
|
-
var _reactLeaflet = require("react-leaflet");
|
|
10
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
19
11
|
|
|
20
12
|
var _polyline = _interopRequireDefault(require("@mapbox/polyline"));
|
|
21
13
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
14
|
+
var _reactMapGl = require("react-map-gl");
|
|
15
|
+
|
|
16
|
+
var _maplibreGl = require("maplibre-gl");
|
|
17
|
+
|
|
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
|
+
|
|
20
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
21
|
+
|
|
22
|
+
const TripViewerOverlay = props => {
|
|
23
|
+
const {
|
|
24
|
+
path,
|
|
25
|
+
tripData,
|
|
26
|
+
visible
|
|
27
|
+
} = props;
|
|
28
|
+
if (!tripData) return null;
|
|
29
|
+
const {
|
|
30
|
+
geometry
|
|
31
|
+
} = tripData;
|
|
32
|
+
if (!geometry) return null;
|
|
33
|
+
|
|
34
|
+
const pts = _polyline.default.decode(geometry.points).map(pt => pt.reverse());
|
|
35
|
+
|
|
36
|
+
const {
|
|
37
|
+
mainMap
|
|
38
|
+
} = (0, _reactMapGl.useMap)();
|
|
39
|
+
(0, _react.useEffect)(() => {
|
|
40
|
+
const bounds = pts.reduce((bnds, coord) => {
|
|
41
|
+
return bnds.extend(coord);
|
|
42
|
+
}, new _maplibreGl.LngLatBounds(pts[0], pts[0]));
|
|
43
|
+
mainMap === null || mainMap === void 0 ? void 0 : mainMap.fitBounds(bounds, {
|
|
44
|
+
duration: 100,
|
|
45
|
+
padding: {
|
|
46
|
+
top: 10,
|
|
47
|
+
bottom: 25,
|
|
48
|
+
left: 15,
|
|
49
|
+
right: 5
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}, [mainMap]);
|
|
53
|
+
if (!visible || !pts) return null;
|
|
54
|
+
const geojson = {
|
|
55
|
+
type: "Feature",
|
|
56
|
+
properties: [],
|
|
57
|
+
geometry: {
|
|
58
|
+
type: "LineString",
|
|
59
|
+
coordinates: pts
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
return /*#__PURE__*/_react.default.createElement(_reactMapGl.Source, {
|
|
63
|
+
id: "route",
|
|
64
|
+
type: "geojson",
|
|
65
|
+
data: geojson
|
|
66
|
+
}, /*#__PURE__*/_react.default.createElement(_reactMapGl.Layer, {
|
|
67
|
+
id: "route",
|
|
68
|
+
type: "line",
|
|
69
|
+
layout: {
|
|
70
|
+
"line-join": "round",
|
|
71
|
+
"line-cap": "round"
|
|
72
|
+
},
|
|
73
|
+
paint: {
|
|
74
|
+
"line-color": (path === null || path === void 0 ? void 0 : path.color) || "#00bfff",
|
|
75
|
+
"line-width": (path === null || path === void 0 ? void 0 : path.weight) || 8,
|
|
76
|
+
"line-opacity": (path === null || path === void 0 ? void 0 : path.opacity) || 0.6
|
|
77
|
+
}
|
|
78
|
+
}));
|
|
78
79
|
};
|
|
79
|
-
TripViewerOverlay.defaultProps = {
|
|
80
|
-
leafletPath: {
|
|
81
|
-
color: "#00bfff",
|
|
82
|
-
opacity: 0.6,
|
|
83
|
-
weight: 8
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
var _default = (0, _reactLeaflet.withLeaflet)(TripViewerOverlay);
|
|
88
80
|
|
|
81
|
+
var _default = TripViewerOverlay;
|
|
89
82
|
exports.default = _default;
|
|
90
83
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.
|
|
1
|
+
{"version":3,"sources":["../src/index.tsx"],"names":["TripViewerOverlay","props","path","tripData","visible","geometry","pts","polyline","decode","points","map","pt","reverse","mainMap","bounds","reduce","bnds","coord","extend","LngLatBounds","fitBounds","duration","padding","top","bottom","left","right","geojson","type","properties","coordinates","color","weight","opacity"],"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,IAA0BA,EAAE,CAACC,OAAH,EAFrB,CAAZ;;AAGA,QAAM;AAAEC,IAAAA;AAAF,MAAc,yBAApB;AACA,wBAAU,MAAM;AACd,UAAMC,MAAM,GAAGR,GAAG,CAACS,MAAJ,CAAW,CAACC,IAAD,EAAOC,KAAP,KAAiB;AACzC,aAAOD,IAAI,CAACE,MAAL,CAAYD,KAAZ,CAAP;AACD,KAFc,EAEZ,IAAIE,wBAAJ,CAAiBb,GAAG,CAAC,CAAD,CAApB,EAAyBA,GAAG,CAAC,CAAD,CAA5B,CAFY,CAAf;AAIAO,IAAAA,OAAO,SAAP,IAAAA,OAAO,WAAP,YAAAA,OAAO,CAAEO,SAAT,CAAmBN,MAAnB,EAA2B;AACzBO,MAAAA,QAAQ,EAAE,GADe;AAEzBC,MAAAA,OAAO,EAAE;AAAEC,QAAAA,GAAG,EAAE,EAAP;AAAWC,QAAAA,MAAM,EAAE,EAAnB;AAAuBC,QAAAA,IAAI,EAAE,EAA7B;AAAiCC,QAAAA,KAAK,EAAE;AAAxC;AAFgB,KAA3B;AAID,GATD,EASG,CAACb,OAAD,CATH;AAWA,MAAI,CAACT,OAAD,IAAY,CAACE,GAAjB,EAAsB,OAAO,IAAP;AAEtB,QAAMqB,OAAwB,GAAG;AAC/BC,IAAAA,IAAI,EAAE,SADyB;AAE/BC,IAAAA,UAAU,EAAE,EAFmB;AAG/BxB,IAAAA,QAAQ,EAAE;AAAEuB,MAAAA,IAAI,EAAE,YAAR;AAAsBE,MAAAA,WAAW,EAAExB;AAAnC;AAHqB,GAAjC;AAMA,sBACE,6BAAC,kBAAD;AAAQ,IAAA,EAAE,EAAC,OAAX;AAAmB,IAAA,IAAI,EAAC,SAAxB;AAAkC,IAAA,IAAI,EAAEqB;AAAxC,kBACE,6BAAC,iBAAD;AACE,IAAA,EAAE,EAAC,OADL;AAEE,IAAA,IAAI,EAAC,MAFP;AAGE,IAAA,MAAM,EAAE;AAAE,mBAAa,OAAf;AAAwB,kBAAY;AAApC,KAHV;AAIE,IAAA,KAAK,EAAE;AACL,oBAAc,CAAAzB,IAAI,SAAJ,IAAAA,IAAI,WAAJ,YAAAA,IAAI,CAAE6B,KAAN,KAAe,SADxB;AAEL,oBAAc,CAAA7B,IAAI,SAAJ,IAAAA,IAAI,WAAJ,YAAAA,IAAI,CAAE8B,MAAN,KAAgB,CAFzB;AAGL,sBAAgB,CAAA9B,IAAI,SAAJ,IAAAA,IAAI,WAAJ,YAAAA,IAAI,CAAE+B,OAAN,KAAiB;AAH5B;AAJT,IADF,CADF;AAcD,CA7CD;;eA+CejC,iB","sourcesContent":["import React, { useEffect } from \"react\";\nimport polyline from \"@mapbox/polyline\";\nimport { Layer, Source, useMap } from \"react-map-gl\";\nimport { LngLatBounds } from \"maplibre-gl\";\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 const { mainMap } = useMap();\n useEffect(() => {\n const bounds = pts.reduce((bnds, coord) => {\n return bnds.extend(coord);\n }, new LngLatBounds(pts[0], pts[0]));\n\n mainMap?.fitBounds(bounds, {\n duration: 100,\n padding: { top: 10, bottom: 25, left: 15, right: 5 }\n });\n }, [mainMap]);\n\n if (!visible || !pts) return null;\n\n const geojson: GeoJSON.Feature = {\n type: \"Feature\",\n properties: [],\n geometry: { type: \"LineString\", coordinates: pts }\n };\n\n return (\n <Source id=\"route\" type=\"geojson\" data={geojson}>\n <Layer\n id=\"route\"\n type=\"line\"\n layout={{ \"line-join\": \"round\", \"line-cap\": \"round\" }}\n paint={{\n \"line-color\": path?.color || \"#00bfff\",\n \"line-width\": path?.weight || 8,\n \"line-opacity\": path?.opacity || 0.6\n }}\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": "
|
|
3
|
+
"version": "2.0.0-alpha.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",
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"homepage": "https://github.com/opentripplanner/otp-ui#readme",
|
|
10
10
|
"scripts": {
|
|
11
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
11
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
12
|
+
"tsc": "tsc"
|
|
12
13
|
},
|
|
13
14
|
"repository": {
|
|
14
15
|
"type": "git",
|
|
@@ -19,13 +20,12 @@
|
|
|
19
20
|
},
|
|
20
21
|
"dependencies": {
|
|
21
22
|
"@mapbox/polyline": "^1.1.0",
|
|
22
|
-
"@opentripplanner/core-utils": "^4.
|
|
23
|
-
"prop-types": "^15.7.2"
|
|
23
|
+
"@opentripplanner/core-utils": "^4.5.0"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
|
-
"@opentripplanner/base-map": "^
|
|
26
|
+
"@opentripplanner/base-map": "^2.0.0",
|
|
27
27
|
"react": "^16.14.0",
|
|
28
|
-
"react-
|
|
28
|
+
"react-map-gl": "^7.0.15"
|
|
29
29
|
},
|
|
30
30
|
"gitHead": "0af1b7cda60bd4252b219dcf893e01c2acb2ed5d"
|
|
31
31
|
}
|
|
@@ -4,9 +4,9 @@ import React from "react";
|
|
|
4
4
|
import tripData from "../__mocks__/mock-trip.json";
|
|
5
5
|
import TripViewerOverlay from ".";
|
|
6
6
|
|
|
7
|
-
import "
|
|
7
|
+
import "maplibre-gl/dist/maplibre-gl.css";
|
|
8
8
|
|
|
9
|
-
const center = [45.518092, -122.671202];
|
|
9
|
+
const center: [number, number] = [45.518092, -122.671202];
|
|
10
10
|
const zoom = 13;
|
|
11
11
|
|
|
12
12
|
export default {
|
|
@@ -14,18 +14,17 @@ export default {
|
|
|
14
14
|
component: TripViewerOverlay
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
-
export const Default = () => (
|
|
18
|
-
<BaseMap center={center} zoom={zoom}>
|
|
17
|
+
export const Default = (): JSX.Element => (
|
|
18
|
+
<BaseMap forceMaxHeight center={center} zoom={zoom}>
|
|
19
19
|
<TripViewerOverlay tripData={tripData} visible />
|
|
20
20
|
</BaseMap>
|
|
21
21
|
);
|
|
22
22
|
|
|
23
|
-
export const WithPathStyling = () => (
|
|
24
|
-
<BaseMap center={center} zoom={zoom}>
|
|
23
|
+
export const WithPathStyling = (): JSX.Element => (
|
|
24
|
+
<BaseMap forceMaxHeight center={center} zoom={zoom}>
|
|
25
25
|
<TripViewerOverlay
|
|
26
|
-
|
|
26
|
+
path={{
|
|
27
27
|
color: "#000",
|
|
28
|
-
dashArray: "2 3 5 7 11",
|
|
29
28
|
opacity: 0.2,
|
|
30
29
|
weight: 5
|
|
31
30
|
}}
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import React, { useEffect } from "react";
|
|
2
|
+
import polyline from "@mapbox/polyline";
|
|
3
|
+
import { Layer, Source, useMap } from "react-map-gl";
|
|
4
|
+
import { LngLatBounds } from "maplibre-gl";
|
|
5
|
+
|
|
6
|
+
type Props = {
|
|
7
|
+
path?: {
|
|
8
|
+
color?: string;
|
|
9
|
+
opacity?: number;
|
|
10
|
+
weight?: number;
|
|
11
|
+
};
|
|
12
|
+
tripData: { geometry: { points: string; length: number } };
|
|
13
|
+
visible?: boolean;
|
|
14
|
+
};
|
|
15
|
+
const TripViewerOverlay = (props: Props): JSX.Element => {
|
|
16
|
+
const { path, tripData, visible } = props;
|
|
17
|
+
if (!tripData) return null;
|
|
18
|
+
|
|
19
|
+
const { geometry } = tripData;
|
|
20
|
+
|
|
21
|
+
if (!geometry) return null;
|
|
22
|
+
|
|
23
|
+
const pts = polyline
|
|
24
|
+
.decode(geometry.points)
|
|
25
|
+
.map((pt: [number, number]) => pt.reverse());
|
|
26
|
+
const { mainMap } = useMap();
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
const bounds = pts.reduce((bnds, coord) => {
|
|
29
|
+
return bnds.extend(coord);
|
|
30
|
+
}, new LngLatBounds(pts[0], pts[0]));
|
|
31
|
+
|
|
32
|
+
mainMap?.fitBounds(bounds, {
|
|
33
|
+
duration: 100,
|
|
34
|
+
padding: { top: 10, bottom: 25, left: 15, right: 5 }
|
|
35
|
+
});
|
|
36
|
+
}, [mainMap]);
|
|
37
|
+
|
|
38
|
+
if (!visible || !pts) return null;
|
|
39
|
+
|
|
40
|
+
const geojson: GeoJSON.Feature = {
|
|
41
|
+
type: "Feature",
|
|
42
|
+
properties: [],
|
|
43
|
+
geometry: { type: "LineString", coordinates: pts }
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<Source id="route" type="geojson" data={geojson}>
|
|
48
|
+
<Layer
|
|
49
|
+
id="route"
|
|
50
|
+
type="line"
|
|
51
|
+
layout={{ "line-join": "round", "line-cap": "round" }}
|
|
52
|
+
paint={{
|
|
53
|
+
"line-color": path?.color || "#00bfff",
|
|
54
|
+
"line-width": path?.weight || 8,
|
|
55
|
+
"line-opacity": path?.opacity || 0.6
|
|
56
|
+
}}
|
|
57
|
+
/>
|
|
58
|
+
</Source>
|
|
59
|
+
);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export default TripViewerOverlay;
|
package/tsconfig.json
ADDED