@opentripplanner/trip-viewer-overlay 1.1.0 → 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 -105
- 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 +69 -76
- package/lib/index.js.map +1 -1
- package/package.json +7 -7
- 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,110 +1,63 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
4
|
-
|
|
5
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
6
|
-
|
|
7
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
8
|
-
|
|
9
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
10
|
-
|
|
11
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
12
|
-
|
|
13
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
14
|
-
|
|
15
|
-
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); }; }
|
|
16
|
-
|
|
17
|
-
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
18
|
-
|
|
19
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
20
|
-
|
|
21
|
-
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; } }
|
|
22
|
-
|
|
23
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
24
|
-
|
|
25
|
-
import coreUtils from "@opentripplanner/core-utils";
|
|
26
|
-
import PropTypes from "prop-types";
|
|
27
|
-
import React from "react";
|
|
28
|
-
import { FeatureGroup, MapLayer, Polyline, withLeaflet } from "react-leaflet";
|
|
1
|
+
import React, { useEffect } from "react";
|
|
29
2
|
import polyline from "@mapbox/polyline";
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
var
|
|
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
|
-
|
|
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
|
|
60
41
|
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
})));
|
|
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
|
|
78
58
|
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return TripViewerOverlay;
|
|
82
|
-
}(MapLayer);
|
|
83
|
-
|
|
84
|
-
TripViewerOverlay.propTypes = {
|
|
85
|
-
/**
|
|
86
|
-
* Leaflet path properties to use to style the polyline that represents the
|
|
87
|
-
* trip.
|
|
88
|
-
*
|
|
89
|
-
* See https://leafletjs.com/reference-1.6.0.html#path
|
|
90
|
-
*/
|
|
91
|
-
leafletPath: coreUtils.types.leafletPathType,
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* This represents data about a trip as obtained from a transit index.
|
|
95
|
-
* Typically a trip has more data than these items, so this is only a list of
|
|
96
|
-
* the properties that this component actually uses.
|
|
97
|
-
*/
|
|
98
|
-
tripData: PropTypes.shape({
|
|
99
|
-
geometry: coreUtils.types.encodedPolylineType
|
|
100
|
-
})
|
|
59
|
+
}));
|
|
101
60
|
};
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
color: "#00bfff",
|
|
105
|
-
opacity: 0.6,
|
|
106
|
-
weight: 8
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
export default withLeaflet(TripViewerOverlay);
|
|
61
|
+
|
|
62
|
+
export default TripViewerOverlay;
|
|
110
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,YAA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I,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
|
@@ -1,90 +1,83 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
3
5
|
Object.defineProperty(exports, "__esModule", {
|
|
4
6
|
value: true
|
|
5
7
|
});
|
|
6
8
|
exports.default = void 0;
|
|
7
9
|
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
-
|
|
12
|
-
var _react = _interopRequireDefault(require("react"));
|
|
13
|
-
|
|
14
|
-
var _reactLeaflet = require("react-leaflet");
|
|
10
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
15
11
|
|
|
16
12
|
var _polyline = _interopRequireDefault(require("@mapbox/polyline"));
|
|
17
13
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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;;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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": "^
|
|
23
|
-
"prop-types": "^15.7.2"
|
|
23
|
+
"@opentripplanner/core-utils": "^4.5.0"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
|
-
"@opentripplanner/base-map": "^
|
|
27
|
-
"react": "^16.
|
|
28
|
-
"react-
|
|
26
|
+
"@opentripplanner/base-map": "^2.0.0",
|
|
27
|
+
"react": "^16.14.0",
|
|
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