@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 CHANGED
@@ -1,97 +1,63 @@
1
- import _extends from "@babel/runtime/helpers/extends";
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
- * An overlay that will display the geometry of a trip.
19
- */
20
-
21
- var TripViewerOverlay = /*#__PURE__*/function (_MapLayer) {
22
- _inherits(TripViewerOverlay, _MapLayer);
23
-
24
- var _super = _createSuper(TripViewerOverlay);
25
-
26
- function TripViewerOverlay() {
27
- _classCallCheck(this, TripViewerOverlay);
28
-
29
- return _super.apply(this, arguments);
30
- }
31
-
32
- _createClass(TripViewerOverlay, [{
33
- key: "componentDidMount",
34
- value: function componentDidMount() {} // TODO: determine why the default MapLayer componentWillUnmount() method throws an error
35
-
36
- }, {
37
- key: "componentWillUnmount",
38
- value: function componentWillUnmount() {}
39
- }, {
40
- key: "componentDidUpdate",
41
- value: function componentDidUpdate(prevProps) {
42
- var oldGeometry = prevProps.tripData && prevProps.tripData.geometry;
43
- var newGeometry = this.props.tripData && this.props.tripData.geometry;
44
- if (oldGeometry === newGeometry || !newGeometry) return;
45
- var pts = polyline.decode(newGeometry.points);
46
- this.props.leaflet.map.fitBounds(pts);
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
- key: "createLeafletElement",
50
- value: function createLeafletElement() {}
51
- }, {
52
- key: "updateLeafletElement",
53
- value: function updateLeafletElement() {}
54
- }, {
55
- key: "render",
56
- value: function render() {
57
- var _this$props = this.props,
58
- leafletPath = _this$props.leafletPath,
59
- tripData = _this$props.tripData;
60
- if (!tripData || !tripData.geometry) return /*#__PURE__*/React.createElement(FeatureGroup, null);
61
- var pts = polyline.decode(tripData.geometry.points);
62
- return /*#__PURE__*/React.createElement(FeatureGroup, null, /*#__PURE__*/React.createElement(Polyline, _extends({}, leafletPath, {
63
- positions: pts
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
- export default withLeaflet(TripViewerOverlay);
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.js"],"names":["coreUtils","PropTypes","React","FeatureGroup","MapLayer","Polyline","withLeaflet","polyline","TripViewerOverlay","prevProps","oldGeometry","tripData","geometry","newGeometry","props","pts","decode","points","leaflet","map","fitBounds","leafletPath","propT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AAS,EAAEN;AAAtC,SAFF,CADF;AAMD;;;;EA9B6BX,Q;;AAiChCI,iBAAiB,CAACc,SAAlB,GAA8B;AAC5B;AACF;AACA;AACA;AACA;AACA;AACED,EAAAA,WAAW,EAAErB,SAAS,CAACuB,KAAV,CAAgBC,eAPD;;AAQ5B;AACF;AACA;AACA;AACA;AACEb,EAAAA,QAAQ,EAAEV,SAAS,CAACwB,KAAV,CAAgB;AACxBb,IAAAA,QAAQ,EAAEZ,SAAS,CAACuB,KAAV,CAAgBG;AADF,GAAhB;AAbkB,CAA9B;AAkBAlB,iBAAiB,CAACmB,YAAlB,GAAiC;AAC/BN,EAAAA,WAAW,EAAE;AACXO,IAAAA,KAAK,EAAE,SADI;AAEXC,IAAAA,OAAO,EAAE,GAFE;AAGXC,IAAAA,MAAM,EAAE;AAHG;AADkB,CAAjC;AAQA,eAAexB,WAAW,CAACE,iBAAD,CAA1B","sourcesContent":["import coreUtils from \"@opentripplanner/core-utils\";\nimport PropTypes from \"prop-types\";\nimport React from \"react\";\nimport { FeatureGroup, MapLayer, Polyline, withLeaflet } from \"react-leaflet\";\n\nimport polyline from \"@mapbox/polyline\";\n\n/**\n * An overlay that will display the geometry of a trip.\n */\nclass TripViewerOverlay extends MapLayer {\n componentDidMount() {}\n\n // TODO: determine why the default MapLayer componentWillUnmount() method throws an error\n componentWillUnmount() {}\n\n componentDidUpdate(prevProps) {\n const oldGeometry = prevProps.tripData && prevProps.tripData.geometry;\n const newGeometry = this.props.tripData && this.props.tripData.geometry;\n if (oldGeometry === newGeometry || !newGeometry) return;\n const pts = polyline.decode(newGeometry.points);\n this.props.leaflet.map.fitBounds(pts);\n }\n\n createLeafletElement() {}\n\n updateLeafletElement() {}\n\n render() {\n const { leafletPath, tripData } = this.props;\n\n if (!tripData || !tripData.geometry) return <FeatureGroup />;\n\n const pts = polyline.decode(tripData.geometry.points);\n return (\n <FeatureGroup>\n {/* eslint-disable-next-line react/jsx-props-no-spreading */}\n <Polyline {...leafletPath} positions={pts} />\n </FeatureGroup>\n );\n }\n}\n\nTripViewerOverlay.propTypes = {\n /**\n * Leaflet path properties to use to style the polyline that represents the\n * trip.\n *\n * See https://leafletjs.com/reference-1.6.0.html#path\n */\n leafletPath: coreUtils.types.leafletPathType,\n /**\n * This represents data about a trip as obtained from a transit index.\n * Typically a trip has more data than these items, so this is only a list of\n * the properties that this component actually uses.\n */\n tripData: PropTypes.shape({\n geometry: coreUtils.types.encodedPolylineType\n })\n};\n\nTripViewerOverlay.defaultProps = {\n leafletPath: {\n color: \"#00bfff\",\n opacity: 0.6,\n weight: 8\n }\n};\n\nexport default withLeaflet(TripViewerOverlay);\n"],"file":"index.js"}
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,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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 _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
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
- * An overlay that will display the geometry of a trip.
24
- */
25
- class TripViewerOverlay extends _reactLeaflet.MapLayer {
26
- componentDidMount() {} // TODO: determine why the default MapLayer componentWillUnmount() method throws an error
27
-
28
-
29
- componentWillUnmount() {}
30
-
31
- componentDidUpdate(prevProps) {
32
- const oldGeometry = prevProps.tripData && prevProps.tripData.geometry;
33
- const newGeometry = this.props.tripData && this.props.tripData.geometry;
34
- if (oldGeometry === newGeometry || !newGeometry) return;
35
-
36
- const pts = _polyline.default.decode(newGeometry.points);
37
-
38
- this.props.leaflet.map.fitBounds(pts);
39
- }
40
-
41
- createLeafletElement() {}
42
-
43
- updateLeafletElement() {}
44
-
45
- render() {
46
- const {
47
- leafletPath,
48
- tripData
49
- } = this.props;
50
- if (!tripData || !tripData.geometry) return /*#__PURE__*/_react.default.createElement(_reactLeaflet.FeatureGroup, null);
51
-
52
- const pts = _polyline.default.decode(tripData.geometry.points);
53
-
54
- return /*#__PURE__*/_react.default.createElement(_reactLeaflet.FeatureGroup, null, /*#__PURE__*/_react.default.createElement(_reactLeaflet.Polyline, (0, _extends2.default)({}, leafletPath, {
55
- positions: pts
56
- })));
57
- }
58
-
59
- }
60
-
61
- TripViewerOverlay.propTypes = {
62
- /**
63
- * Leaflet path properties to use to style the polyline that represents the
64
- * trip.
65
- *
66
- * See https://leafletjs.com/reference-1.6.0.html#path
67
- */
68
- leafletPath: _coreUtils.default.types.leafletPathType,
69
-
70
- /**
71
- * This represents data about a trip as obtained from a transit index.
72
- * Typically a trip has more data than these items, so this is only a list of
73
- * the properties that this component actually uses.
74
- */
75
- tripData: _propTypes.default.shape({
76
- geometry: _coreUtils.default.types.encodedPolylineType
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.js"],"names":["TripViewerOverlay","MapLayer","componentDidMount","componentWillUnmount","componentDidUpdate","prevProps","oldGeometry","tripData","geometry","newGeometry","props","pts","polyline","decode","points","leaflet","map","fitBounds","createLeafletElement","updateLeafletElement","render","leafletPath","propTypes","coreUtils","types","leafletPathType","PropTypes","shape","encodedPolylineType","defaultProps","color","opacity","weight"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AAEA;;AAEA;AACA;AACA;AACA,MAAMA,iBAAN,SAAgCC,sBAAhC,CAAyC;AACvCC,EAAAA,iBAAiB,GAAG,CAAE,CADiB,CAGvC;;;AACAC,EAAAA,oBAAoB,GAAG,CAAE;;AAEzBC,EAAAA,kBAAkB,CAACC,SAAD,EAAY;AAC5B,UAAMC,WAAW,GAAGD,SAAS,CAACE,QAAV,IAAsBF,SAAS,CAACE,QAAV,CAAmBC,QAA7D;AACA,UAAMC,WAAW,GAAG,KAAKC,KAAL,CAAWH,QAAX,IAAuB,KAAKG,KAA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coreUtils from \"@opentripplanner/core-utils\";\nimport PropTypes from \"prop-types\";\nimport React from \"react\";\nimport { FeatureGroup, MapLayer, Polyline, withLeaflet } from \"react-leaflet\";\n\nimport polyline from \"@mapbox/polyline\";\n\n/**\n * An overlay that will display the geometry of a trip.\n */\nclass TripViewerOverlay extends MapLayer {\n componentDidMount() {}\n\n // TODO: determine why the default MapLayer componentWillUnmount() method throws an error\n componentWillUnmount() {}\n\n componentDidUpdate(prevProps) {\n const oldGeometry = prevProps.tripData && prevProps.tripData.geometry;\n const newGeometry = this.props.tripData && this.props.tripData.geometry;\n if (oldGeometry === newGeometry || !newGeometry) return;\n const pts = polyline.decode(newGeometry.points);\n this.props.leaflet.map.fitBounds(pts);\n }\n\n createLeafletElement() {}\n\n updateLeafletElement() {}\n\n render() {\n const { leafletPath, tripData } = this.props;\n\n if (!tripData || !tripData.geometry) return <FeatureGroup />;\n\n const pts = polyline.decode(tripData.geometry.points);\n return (\n <FeatureGroup>\n {/* eslint-disable-next-line react/jsx-props-no-spreading */}\n <Polyline {...leafletPath} positions={pts} />\n </FeatureGroup>\n );\n }\n}\n\nTripViewerOverlay.propTypes = {\n /**\n * Leaflet path properties to use to style the polyline that represents the\n * trip.\n *\n * See https://leafletjs.com/reference-1.6.0.html#path\n */\n leafletPath: coreUtils.types.leafletPathType,\n /**\n * This represents data about a trip as obtained from a transit index.\n * Typically a trip has more data than these items, so this is only a list of\n * the properties that this component actually uses.\n */\n tripData: PropTypes.shape({\n geometry: coreUtils.types.encodedPolylineType\n })\n};\n\nTripViewerOverlay.defaultProps = {\n leafletPath: {\n color: \"#00bfff\",\n opacity: 0.6,\n weight: 8\n }\n};\n\nexport default withLeaflet(TripViewerOverlay);\n"],"file":"index.js"}
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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ADyB;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": "1.1.1",
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.1.0",
23
- "prop-types": "^15.7.2"
23
+ "@opentripplanner/core-utils": "^4.5.0"
24
24
  },
25
25
  "peerDependencies": {
26
- "@opentripplanner/base-map": "^1.2.0",
26
+ "@opentripplanner/base-map": "^2.0.0",
27
27
  "react": "^16.14.0",
28
- "react-leaflet": "^2.6.1"
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 "../../../node_modules/leaflet/dist/leaflet.css";
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
- leafletPath={{
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
@@ -0,0 +1,15 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "composite": true,
5
+ "outDir": "./lib",
6
+ "rootDir": "./src",
7
+ "skipLibCheck": true
8
+ },
9
+ "include": ["src/**/*"],
10
+ "references": [
11
+ {
12
+ "path": "../types"
13
+ }
14
+ ]
15
+ }