@opentripplanner/vehicle-rental-overlay 1.3.1 → 1.4.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 +86 -31
- package/esm/index.js.map +1 -1
- package/i18n/en-US.yml +14 -0
- package/i18n/fr.yml +14 -0
- package/lib/index.js +87 -21
- package/lib/index.js.map +1 -1
- package/package.json +4 -3
- package/src/VehicleRentalOverlay.story.js +28 -48
- package/src/index.js +80 -19
- package/esm/leaflet-layer-control-interface.js +0 -90
- package/esm/leaflet-layer-control-interface.js.map +0 -1
- package/lib/leaflet-layer-control-interface.js +0 -85
- package/lib/leaflet-layer-control-interface.js.map +0 -1
- package/src/leaflet-layer-control-interface.tsx +0 -81
package/esm/index.js
CHANGED
|
@@ -8,14 +8,23 @@ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflec
|
|
|
8
8
|
|
|
9
9
|
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; } }
|
|
10
10
|
|
|
11
|
+
import flatten from "flat";
|
|
11
12
|
import { Styled as BaseMapStyled } from "@opentripplanner/base-map";
|
|
12
13
|
import coreUtils from "@opentripplanner/core-utils";
|
|
13
14
|
import FromToLocationPicker from "@opentripplanner/from-to-location-picker";
|
|
14
15
|
import ZoomBasedMarkers from "@opentripplanner/zoom-based-markers";
|
|
15
16
|
import PropTypes from "prop-types";
|
|
16
17
|
import React from "react";
|
|
18
|
+
import { FormattedMessage } from "react-intl";
|
|
17
19
|
import { FeatureGroup, MapLayer, Popup, withLeaflet } from "react-leaflet";
|
|
18
|
-
import { GenericMarker, HubAndFloatingBike, SharedBikeCircle } from "./DefaultMarkers";
|
|
20
|
+
import { GenericMarker, HubAndFloatingBike, SharedBikeCircle } from "./DefaultMarkers"; // Load the default messages.
|
|
21
|
+
|
|
22
|
+
import defaultEnglishMessages from "../i18n/en-US.yml"; // HACK: We should flatten the messages loaded above because
|
|
23
|
+
// the YAML loaders behave differently between webpack and our version of jest:
|
|
24
|
+
// - the yaml loader for webpack returns a nested object,
|
|
25
|
+
// - the yaml loader for jest returns messages with flattened ids.
|
|
26
|
+
|
|
27
|
+
var defaultMessages = flatten(defaultEnglishMessages);
|
|
19
28
|
/**
|
|
20
29
|
* This vehicle rental overlay can be used to render vehicle rentals of various
|
|
21
30
|
* types. This layer can be configured to show different styles of markers at
|
|
@@ -27,16 +36,12 @@ var VehicleRentalOverlay = /*#__PURE__*/function (_MapLayer) {
|
|
|
27
36
|
|
|
28
37
|
var _super = _createSuper(VehicleRentalOverlay);
|
|
29
38
|
|
|
30
|
-
function VehicleRentalOverlay() {
|
|
39
|
+
function VehicleRentalOverlay(props) {
|
|
31
40
|
var _this;
|
|
32
41
|
|
|
33
42
|
_classCallCheck(this, VehicleRentalOverlay);
|
|
34
43
|
|
|
35
|
-
|
|
36
|
-
args[_key] = arguments[_key];
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
_this = _super.call.apply(_super, [this].concat(args));
|
|
44
|
+
_this = _super.call(this, props);
|
|
40
45
|
|
|
41
46
|
_this.renderSymbolWithPopup = function (_Symbol) {
|
|
42
47
|
var SymbolWrapper = function SymbolWrapper(_ref) {
|
|
@@ -85,6 +90,24 @@ var VehicleRentalOverlay = /*#__PURE__*/function (_MapLayer) {
|
|
|
85
90
|
});
|
|
86
91
|
};
|
|
87
92
|
|
|
93
|
+
_this.onOverlayAdded = function () {
|
|
94
|
+
_this.startRefreshing();
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
_this.onOverlayRemoved = function () {
|
|
98
|
+
_this.stopRefreshing();
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
_this.onViewportChanged = function (viewport) {
|
|
102
|
+
var newZoom = viewport.zoom;
|
|
103
|
+
|
|
104
|
+
if (_this.state.zoom !== newZoom) {
|
|
105
|
+
_this.setState({
|
|
106
|
+
zoom: newZoom
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
88
111
|
_this.renderPopupForStation = function (station) {
|
|
89
112
|
var stationIsHub = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
90
113
|
var _this$props = _this.props,
|
|
@@ -97,14 +120,38 @@ var VehicleRentalOverlay = /*#__PURE__*/function (_MapLayer) {
|
|
|
97
120
|
lon: station.x,
|
|
98
121
|
name: stationName
|
|
99
122
|
};
|
|
100
|
-
return /*#__PURE__*/React.createElement(Popup, null, /*#__PURE__*/React.createElement(BaseMapStyled.MapOverlayPopup, null, /*#__PURE__*/React.createElement(BaseMapStyled.PopupTitle, null, stationName), stationIsHub && /*#__PURE__*/React.createElement(BaseMapStyled.PopupRow, null, /*#__PURE__*/React.createElement("div", null,
|
|
123
|
+
return /*#__PURE__*/React.createElement(Popup, null, /*#__PURE__*/React.createElement(BaseMapStyled.MapOverlayPopup, null, /*#__PURE__*/React.createElement(BaseMapStyled.PopupTitle, null, stationName), stationIsHub && /*#__PURE__*/React.createElement(BaseMapStyled.PopupRow, null, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(FormattedMessage, {
|
|
124
|
+
defaultMessage: defaultMessages["otpUi.VehicleRentalOverlay.availableBikes"],
|
|
125
|
+
description: "Label text for the number of bikes available",
|
|
126
|
+
id: "otpUi.VehicleRentalOverlay.availableBikes",
|
|
127
|
+
values: {
|
|
128
|
+
value: station.bikesAvailable
|
|
129
|
+
}
|
|
130
|
+
})), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(FormattedMessage, {
|
|
131
|
+
defaultMessage: defaultMessages["otpUi.VehicleRentalOverlay.availableDocks"],
|
|
132
|
+
description: "Label text for the number of docks available",
|
|
133
|
+
id: "otpUi.VehicleRentalOverlay.availableDocks",
|
|
134
|
+
values: {
|
|
135
|
+
value: station.spacesAvailable
|
|
136
|
+
}
|
|
137
|
+
}))), /*#__PURE__*/React.createElement(BaseMapStyled.PopupRow, null, /*#__PURE__*/React.createElement(FromToLocationPicker, {
|
|
138
|
+
label: true,
|
|
101
139
|
location: location,
|
|
102
140
|
setLocation: setLocation
|
|
103
141
|
}))));
|
|
104
142
|
};
|
|
105
143
|
|
|
144
|
+
_this.state = {
|
|
145
|
+
zoom: null
|
|
146
|
+
};
|
|
106
147
|
return _this;
|
|
107
148
|
}
|
|
149
|
+
/**
|
|
150
|
+
* This helper method will be passed to the ZoomBasedMarkers symbolTransform prop.
|
|
151
|
+
* It creates a component that inserts a popup
|
|
152
|
+
* as a child of the specified symbol from the mapSymbols prop.
|
|
153
|
+
*/
|
|
154
|
+
|
|
108
155
|
|
|
109
156
|
_createClass(VehicleRentalOverlay, [{
|
|
110
157
|
key: "createLeafletElement",
|
|
@@ -131,26 +178,38 @@ var VehicleRentalOverlay = /*#__PURE__*/function (_MapLayer) {
|
|
|
131
178
|
value: function stopRefreshing() {
|
|
132
179
|
if (this.refreshTimer) clearInterval(this.refreshTimer);
|
|
133
180
|
}
|
|
181
|
+
/**
|
|
182
|
+
* When the layer is added (or toggled on, or its visibility becomes true),
|
|
183
|
+
* start refreshing vehicle positions.
|
|
184
|
+
*/
|
|
185
|
+
|
|
134
186
|
}, {
|
|
135
187
|
key: "componentDidMount",
|
|
136
|
-
value:
|
|
137
|
-
|
|
188
|
+
value:
|
|
189
|
+
/**
|
|
190
|
+
* Upon mounting, see whether the vehicles should be fetched,
|
|
191
|
+
* and also call the register overlay prop that the
|
|
192
|
+
* @opentripplanner/base-map package has injected to listen to zoom/position changes.
|
|
193
|
+
*/
|
|
194
|
+
function componentDidMount() {
|
|
195
|
+
var _this$props2 = this.props,
|
|
196
|
+
leaflet = _this$props2.leaflet,
|
|
197
|
+
registerOverlay = _this$props2.registerOverlay,
|
|
198
|
+
visible = _this$props2.visible;
|
|
199
|
+
this.setState({
|
|
200
|
+
zoom: leaflet.map.getZoom()
|
|
201
|
+
});
|
|
138
202
|
if (visible) this.startRefreshing();
|
|
203
|
+
|
|
204
|
+
if (typeof registerOverlay === "function") {
|
|
205
|
+
registerOverlay(this);
|
|
206
|
+
}
|
|
139
207
|
}
|
|
140
208
|
}, {
|
|
141
209
|
key: "componentWillUnmount",
|
|
142
210
|
value: function componentWillUnmount() {
|
|
143
211
|
this.stopRefreshing();
|
|
144
212
|
}
|
|
145
|
-
}, {
|
|
146
|
-
key: "componentDidUpdate",
|
|
147
|
-
value: function componentDidUpdate(prevProps) {
|
|
148
|
-
if (!prevProps.visible && this.props.visible) {
|
|
149
|
-
this.startRefreshing();
|
|
150
|
-
} else if (prevProps.visible && !this.props.visible) {
|
|
151
|
-
this.stopRefreshing();
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
213
|
/**
|
|
155
214
|
* Render some popup html for a station. This contains custom logic for
|
|
156
215
|
* displaying rental vehicles in the TriMet MOD website that might not be
|
|
@@ -160,19 +219,17 @@ var VehicleRentalOverlay = /*#__PURE__*/function (_MapLayer) {
|
|
|
160
219
|
}, {
|
|
161
220
|
key: "render",
|
|
162
221
|
value: function render() {
|
|
163
|
-
var _this$
|
|
164
|
-
companies = _this$
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
222
|
+
var _this$props3 = this.props,
|
|
223
|
+
companies = _this$props3.companies,
|
|
224
|
+
leaflet = _this$props3.leaflet,
|
|
225
|
+
mapSymbols = _this$props3.mapSymbols,
|
|
226
|
+
stations = _this$props3.stations;
|
|
227
|
+
var _this$state$zoom = this.state.zoom,
|
|
228
|
+
zoom = _this$state$zoom === void 0 ? leaflet.map.getZoom() : _this$state$zoom; // Render an empty FeatureGroup if the rental vehicles should not be visible
|
|
168
229
|
// on the map. Otherwise previous stations may still be shown due to some
|
|
169
230
|
// react-leaflet internals, maybe? Also, do not return null because that will
|
|
170
231
|
// prevent the overlay from appearing in the layer controls.
|
|
171
232
|
|
|
172
|
-
if (!visible) {
|
|
173
|
-
return /*#__PURE__*/React.createElement(FeatureGroup, null);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
233
|
var filteredStations = stations;
|
|
177
234
|
|
|
178
235
|
if (companies) {
|
|
@@ -185,10 +242,8 @@ var VehicleRentalOverlay = /*#__PURE__*/function (_MapLayer) {
|
|
|
185
242
|
|
|
186
243
|
if (!filteredStations || filteredStations.length === 0) {
|
|
187
244
|
return /*#__PURE__*/React.createElement(FeatureGroup, null);
|
|
188
|
-
} //
|
|
189
|
-
|
|
245
|
+
} // Convert map symbols for this overlay to zoomBasedSymbolType.
|
|
190
246
|
|
|
191
|
-
var zoom = this.props.leaflet.map.getZoom(); // Convert map symbols for this overlay to zoomBasedSymbolType.
|
|
192
247
|
|
|
193
248
|
var symbols = this.convertToZoomMarkerSymbols(mapSymbols);
|
|
194
249
|
return /*#__PURE__*/React.createElement(FeatureGroup, null, /*#__PURE__*/React.createElement(ZoomBasedMarkers, {
|
package/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.js"],"names":["Styled","BaseMapStyled","coreUtils","FromToLocationPicker","ZoomBasedMarkers","PropTypes","React","FeatureGroup","MapLayer","Popup","withLeaflet","GenericMarker","HubAndFloatingBike","SharedBikeCircle","VehicleRentalOverlay","renderSymbolWithPopup","Symbol","SymbolWrapper","station","entity","zoom","renderPopupForStation","bikesAvailable","undefined","isFloatingBike","propTypes","types","stationType","isRequired","number","convertToZoomMarkerSymbols","mapSymbols","map","mapSymbol","symbol","type","minZoom","stationIsHub","props","configCompanies","getStationName","setLocation","stationName","location","lat","y","lon","x","name","spacesAvailable","refreshVehicles","refreshTimer","setInterval","clearInterval","visible","startRefreshing","stopRefreshing","prevProps","companies","stations","filteredStations","filter","networks","value","includes","length","leaflet","getZoom","symbols","arrayOf","companyType","string","func","vehicleRentalMapOverlaySymbolsType","bool","defaultProps","stationNetworks","itinerary","getCompaniesLabelFromNetworks","id","isFloatingCar","isFloatingVehicle"],"mappings":";;;;;;;;;;A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WAAW,CAACI,oBAAD,CAA1B","sourcesContent":["import { Styled as BaseMapStyled } from \"@opentripplanner/base-map\";\nimport coreUtils from \"@opentripplanner/core-utils\";\nimport FromToLocationPicker from \"@opentripplanner/from-to-location-picker\";\nimport ZoomBasedMarkers from \"@opentripplanner/zoom-based-markers\";\nimport PropTypes from \"prop-types\";\nimport React from \"react\";\nimport { FeatureGroup, MapLayer, Popup, withLeaflet } from \"react-leaflet\";\n\nimport {\n GenericMarker,\n HubAndFloatingBike,\n SharedBikeCircle\n} from \"./DefaultMarkers\";\n\n/**\n * This vehicle rental overlay can be used to render vehicle rentals of various\n * types. This layer can be configured to show different styles of markers at\n * different zoom levels.\n */\nclass VehicleRentalOverlay extends MapLayer {\n /**\n * This helper method will be passed to the ZoomBasedMarkers symbolTransform prop.\n * It creates a component that inserts a popup\n * as a child of the specified symbol from the mapSymbols prop.\n */\n renderSymbolWithPopup = Symbol => {\n const SymbolWrapper = ({ entity: station, zoom }) => (\n <Symbol entity={station} zoom={zoom}>\n {this.renderPopupForStation(\n station,\n station.bikesAvailable !== undefined && !station.isFloatingBike\n )}\n </Symbol>\n );\n SymbolWrapper.propTypes = {\n entity: coreUtils.types.stationType.isRequired,\n zoom: PropTypes.number.isRequired\n };\n\n return SymbolWrapper;\n };\n\n /**\n * Convert map symbols to zoomBasedSymbolType.\n */\n convertToZoomMarkerSymbols = mapSymbols =>\n mapSymbols.map(mapSymbol => {\n // If mapSymbol uses zoomBasedSymbolType, use it as is.\n if (mapSymbol.symbol) {\n return mapSymbol;\n }\n\n // Otherwise, convert into zoomBasedType (no support for symbols by type).\n let symbol;\n switch (mapSymbol.type) {\n case \"circle\":\n symbol = SharedBikeCircle(mapSymbol);\n break;\n case \"hubAndFloatingBike\":\n symbol = HubAndFloatingBike;\n break;\n default:\n symbol = GenericMarker(mapSymbol);\n }\n\n return {\n minZoom: mapSymbol.minZoom,\n symbol\n };\n });\n\n createLeafletElement() {}\n\n updateLeafletElement() {}\n\n startRefreshing() {\n const { refreshVehicles } = this.props;\n\n // Create the timer only if refreshVehicles is a valid function.\n if (typeof refreshVehicles === \"function\") {\n // initial station retrieval\n refreshVehicles();\n\n // set up timer to refresh stations periodically\n this.refreshTimer = setInterval(() => {\n refreshVehicles();\n }, 30000); // defaults to every 30 sec. TODO: make this configurable?\n }\n }\n\n stopRefreshing() {\n if (this.refreshTimer) clearInterval(this.refreshTimer);\n }\n\n componentDidMount() {\n const { visible } = this.props;\n if (visible) this.startRefreshing();\n }\n\n componentWillUnmount() {\n this.stopRefreshing();\n }\n\n componentDidUpdate(prevProps) {\n if (!prevProps.visible && this.props.visible) {\n this.startRefreshing();\n } else if (prevProps.visible && !this.props.visible) {\n this.stopRefreshing();\n }\n }\n\n /**\n * Render some popup html for a station. This contains custom logic for\n * displaying rental vehicles in the TriMet MOD website that might not be\n * applicable to other regions.\n */\n renderPopupForStation = (station, stationIsHub = false) => {\n const { configCompanies, getStationName, setLocation } = this.props;\n const stationName = getStationName(configCompanies, station);\n const location = {\n lat: station.y,\n lon: station.x,\n name: stationName\n };\n return (\n <Popup>\n <BaseMapStyled.MapOverlayPopup>\n <BaseMapStyled.PopupTitle>{stationName}</BaseMapStyled.PopupTitle>\n\n {/* render dock info if it is available */}\n {stationIsHub && (\n <BaseMapStyled.PopupRow>\n <div>Available bikes: {station.bikesAvailable}</div>\n <div>Available docks: {station.spacesAvailable}</div>\n </BaseMapStyled.PopupRow>\n )}\n\n {/* Set as from/to toolbar */}\n <BaseMapStyled.PopupRow>\n <b>Plan a trip:</b>\n <FromToLocationPicker\n location={location}\n setLocation={setLocation}\n />\n </BaseMapStyled.PopupRow>\n </BaseMapStyled.MapOverlayPopup>\n </Popup>\n );\n };\n\n render() {\n const { companies, mapSymbols, stations, visible } = this.props;\n // Render an empty FeatureGroup if the rental vehicles should not be visible\n // on the map. Otherwise previous stations may still be shown due to some\n // react-leaflet internals, maybe? Also, do not return null because that will\n // prevent the overlay from appearing in the layer controls.\n if (!visible) {\n return <FeatureGroup />;\n }\n\n let filteredStations = stations;\n if (companies) {\n filteredStations = stations.filter(\n station =>\n station.networks.filter(value => companies.includes(value)).length > 0\n );\n }\n\n if (!filteredStations || filteredStations.length === 0) {\n return <FeatureGroup />;\n }\n\n // get zoom to check which symbol to render\n const zoom = this.props.leaflet.map.getZoom();\n\n // Convert map symbols for this overlay to zoomBasedSymbolType.\n const symbols = this.convertToZoomMarkerSymbols(mapSymbols);\n\n return (\n <FeatureGroup>\n <ZoomBasedMarkers\n entities={filteredStations}\n symbols={symbols}\n symbolTransform={this.renderSymbolWithPopup}\n zoom={zoom}\n />\n </FeatureGroup>\n );\n }\n}\n\nVehicleRentalOverlay.props = {\n /**\n * The entire companies config array.\n */\n configCompanies: PropTypes.arrayOf(coreUtils.types.companyType.isRequired)\n .isRequired,\n /**\n * A list of companies that are applicable to just this instance of the\n * overlay.\n */\n companies: PropTypes.arrayOf(PropTypes.string.isRequired),\n /**\n * An optional custom function to create a string name of a particular vehicle\n * rental station. This function takes two arguments of the configCompanies\n * prop and a vehicle rental station. The function must return a string.\n */\n getStationName: PropTypes.func,\n /**\n * A configuration of what map markers or symbols to show at various\n * zoom levels.\n */\n mapSymbols: coreUtils.types.vehicleRentalMapOverlaySymbolsType,\n /**\n * If specified, a function that will be triggered every 30 seconds whenever this layer is\n * visible.\n */\n refreshVehicles: PropTypes.func,\n /**\n * A callback for when a user clicks on setting this stop as either the from\n * or to location of a new search.\n *\n * This will be dispatched with the following argument:\n *\n * ```js\n * {\n * location: {\n * lat: number,\n * lon: number,\n * name: string\n * },\n * locationType: \"from\" or \"to\"\n * }\n * ```\n */\n setLocation: PropTypes.func.isRequired,\n /**\n * A list of the vehicle rental stations specific to this overlay instance.\n */\n stations: PropTypes.arrayOf(coreUtils.types.stationType),\n /**\n * Whether the overlay is currently visible.\n */\n visible: PropTypes.bool\n};\n\nVehicleRentalOverlay.defaultProps = {\n getStationName: (configCompanies, station) => {\n const stationNetworks = coreUtils.itinerary.getCompaniesLabelFromNetworks(\n station.networks,\n configCompanies\n );\n let stationName = station.name || station.id;\n if (station.isFloatingBike) {\n stationName = `Free-floating bike: ${stationName}`;\n } else if (station.isFloatingCar) {\n stationName = `${stationNetworks} ${stationName}`;\n } else if (station.isFloatingVehicle) {\n // assumes that all floating vehicles are E-scooters\n stationName = `${stationNetworks} E-scooter`;\n }\n return stationName;\n },\n mapSymbols: [\n {\n zoom: 0,\n symbol: GenericMarker\n }\n ],\n refreshVehicles: null,\n stations: [],\n visible: false\n};\n\nexport default withLeaflet(VehicleRentalOverlay);\n"],"file":"index.js"}
|
|
1
|
+
{"version":3,"sources":["../src/index.js"],"names":["flatten","Styled","BaseMapStyled","coreUtils","FromToLocationPicker","ZoomBasedMarkers","PropTypes","React","FormattedMessage","FeatureGroup","MapLayer","Popup","withLeaflet","GenericMarker","HubAndFloatingBike","SharedBikeCircle","defaultEnglishMessages","defaultMessages","VehicleRentalOverlay","props","renderSymbolWithPopup","Symbol","SymbolWrapper","station","entity","zoom","renderPopupForStation","bikesAvailable","undefined","isFloatingBike","propTypes","types","stationType","isRequired","number","convertToZoomMarkerSymbols","mapSymbols","map","mapSymbol","symbol","type","minZoom","onOverlayAdded","startRefreshing","onOverlayRemoved","stopRefreshing","onViewportChanged","viewport","newZoom","state","setState","stationIsHub","configCompanies","getStationName","setLocation","stationName","location","lat","y","lon","x","name","value","spacesAvailable","refreshVehicles","refreshTimer","setInterval","clearInterval","leaflet","registerOverlay","visible","getZoom","companies","stations","filteredStations","filter","networks","includes","length","symbols","arrayOf","companyType","string","func","vehicleRentalMapOverlaySymbolsType","bool","defaultProps","stationNetworks","itinerary","getCompaniesLabelFromNetworks","id","isFloatingCar","isFloatingVehicle"],"mappings":";;;;;;;;;;AAAA,OAAOA,OAAP,MAAoB,MAApB;AACA,SAASC,MAAM,IAAIC,aAAnB,QAAwC,2BAAxC;AACA,OAAOC,SAAP,MAAsB,6BAAtB;AACA,OAAOC,oBAAP,MAAiC,0CAAjC;AACA,OAAOC,gBAAP,MA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S,CAAC0E,OAAV,CAAkB7E,SAAS,CAAC4B,KAAV,CAAgBC,WAAlC,CAhDiB;;AAiD3B;AACF;AACA;AACEsC,EAAAA,OAAO,EAAEhE,SAAS,CAAC+E;AApDQ,CAA7B;AAuDAnE,oBAAoB,CAACoE,YAArB,GAAoC;AAClCjC,EAAAA,cAAc,EAAE,wBAACD,eAAD,EAAkB7B,OAAlB,EAA8B;AAC5C,QAAMgE,eAAe,GAAGpF,SAAS,CAACqF,SAAV,CAAoBC,6BAApB,CACtBlE,OAAO,CAACqD,QADc,EAEtBxB,eAFsB,CAAxB;AAIA,QAAIG,WAAW,GAAGhC,OAAO,CAACsC,IAAR,IAAgBtC,OAAO,CAACmE,EAA1C;;AACA,QAAInE,OAAO,CAACM,cAAZ,EAA4B;AAC1B0B,MAAAA,WAAW,iCAA0BA,WAA1B,CAAX;AACD,KAFD,MAEO,IAAIhC,OAAO,CAACoE,aAAZ,EAA2B;AAChCpC,MAAAA,WAAW,aAAMgC,eAAN,cAAyBhC,WAAzB,CAAX;AACD,KAFM,MAEA,IAAIhC,OAAO,CAACqE,iBAAZ,EAA+B;AACpC;AACArC,MAAAA,WAAW,aAAMgC,eAAN,eAAX;AACD;;AACD,WAAOhC,WAAP;AACD,GAhBiC;AAiBlCnB,EAAAA,UAAU,EAAE,CACV;AACEX,IAAAA,IAAI,EAAE,CADR;AAEEc,IAAAA,MAAM,EAAE1B;AAFV,GADU,CAjBsB;AAuBlCmD,EAAAA,eAAe,EAAE,IAvBiB;AAwBlCS,EAAAA,QAAQ,EAAE,EAxBwB;AAyBlCH,EAAAA,OAAO,EAAE;AAzByB,CAApC;AA4BA,eAAe1D,WAAW,CAACM,oBAAD,CAA1B","sourcesContent":["import flatten from \"flat\";\nimport { Styled as BaseMapStyled } from \"@opentripplanner/base-map\";\nimport coreUtils from \"@opentripplanner/core-utils\";\nimport FromToLocationPicker from \"@opentripplanner/from-to-location-picker\";\nimport ZoomBasedMarkers from \"@opentripplanner/zoom-based-markers\";\nimport PropTypes from \"prop-types\";\nimport React from \"react\";\nimport { FormattedMessage } from \"react-intl\";\nimport { FeatureGroup, MapLayer, Popup, withLeaflet } from \"react-leaflet\";\n\nimport {\n GenericMarker,\n HubAndFloatingBike,\n SharedBikeCircle\n} from \"./DefaultMarkers\";\n\n// Load the default messages.\nimport defaultEnglishMessages from \"../i18n/en-US.yml\";\n\n// HACK: We should flatten the messages loaded above because\n// the YAML loaders behave differently between webpack and our version of jest:\n// - the yaml loader for webpack returns a nested object,\n// - the yaml loader for jest returns messages with flattened ids.\nconst defaultMessages = flatten(defaultEnglishMessages);\n\n/**\n * This vehicle rental overlay can be used to render vehicle rentals of various\n * types. This layer can be configured to show different styles of markers at\n * different zoom levels.\n */\nclass VehicleRentalOverlay extends MapLayer {\n constructor(props) {\n super(props);\n this.state = {\n zoom: null\n };\n }\n\n /**\n * This helper method will be passed to the ZoomBasedMarkers symbolTransform prop.\n * It creates a component that inserts a popup\n * as a child of the specified symbol from the mapSymbols prop.\n */\n renderSymbolWithPopup = Symbol => {\n const SymbolWrapper = ({ entity: station, zoom }) => (\n <Symbol entity={station} zoom={zoom}>\n {this.renderPopupForStation(\n station,\n station.bikesAvailable !== undefined && !station.isFloatingBike\n )}\n </Symbol>\n );\n SymbolWrapper.propTypes = {\n entity: coreUtils.types.stationType.isRequired,\n zoom: PropTypes.number.isRequired\n };\n\n return SymbolWrapper;\n };\n\n /**\n * Convert map symbols to zoomBasedSymbolType.\n */\n convertToZoomMarkerSymbols = mapSymbols =>\n mapSymbols.map(mapSymbol => {\n // If mapSymbol uses zoomBasedSymbolType, use it as is.\n if (mapSymbol.symbol) {\n return mapSymbol;\n }\n\n // Otherwise, convert into zoomBasedType (no support for symbols by type).\n let symbol;\n switch (mapSymbol.type) {\n case \"circle\":\n symbol = SharedBikeCircle(mapSymbol);\n break;\n case \"hubAndFloatingBike\":\n symbol = HubAndFloatingBike;\n break;\n default:\n symbol = GenericMarker(mapSymbol);\n }\n\n return {\n minZoom: mapSymbol.minZoom,\n symbol\n };\n });\n\n createLeafletElement() {}\n\n updateLeafletElement() {}\n\n startRefreshing() {\n const { refreshVehicles } = this.props;\n\n // Create the timer only if refreshVehicles is a valid function.\n if (typeof refreshVehicles === \"function\") {\n // initial station retrieval\n refreshVehicles();\n\n // set up timer to refresh stations periodically\n this.refreshTimer = setInterval(() => {\n refreshVehicles();\n }, 30000); // defaults to every 30 sec. TODO: make this configurable?\n }\n }\n\n stopRefreshing() {\n if (this.refreshTimer) clearInterval(this.refreshTimer);\n }\n\n /**\n * When the layer is added (or toggled on, or its visibility becomes true),\n * start refreshing vehicle positions.\n */\n onOverlayAdded = () => {\n this.startRefreshing();\n };\n\n /**\n * When the layer is removed (or toggled off, or its visibility becomes false),\n * stop refreshing vehicle positions.\n */\n onOverlayRemoved = () => {\n this.stopRefreshing();\n };\n\n /**\n * Listen to changes on the BaseMap's center or zoom.\n * @param viewport The viewport data. See https://github.com/PaulLeCam/react-leaflet/blob/master/example/components/viewport.js for details.\n */\n onViewportChanged = viewport => {\n const { zoom: newZoom } = viewport;\n if (this.state.zoom !== newZoom) {\n this.setState({ zoom: newZoom });\n }\n };\n\n /**\n * Upon mounting, see whether the vehicles should be fetched,\n * and also call the register overlay prop that the\n * @opentripplanner/base-map package has injected to listen to zoom/position changes.\n */\n componentDidMount() {\n const { leaflet, registerOverlay, visible } = this.props;\n this.setState({\n zoom: leaflet.map.getZoom()\n });\n if (visible) this.startRefreshing();\n if (typeof registerOverlay === \"function\") {\n registerOverlay(this);\n }\n }\n\n componentWillUnmount() {\n this.stopRefreshing();\n }\n\n /**\n * Render some popup html for a station. This contains custom logic for\n * displaying rental vehicles in the TriMet MOD website that might not be\n * applicable to other regions.\n */\n renderPopupForStation = (station, stationIsHub = false) => {\n const { configCompanies, getStationName, setLocation } = this.props;\n const stationName = getStationName(configCompanies, station);\n const location = {\n lat: station.y,\n lon: station.x,\n name: stationName\n };\n return (\n <Popup>\n <BaseMapStyled.MapOverlayPopup>\n <BaseMapStyled.PopupTitle>{stationName}</BaseMapStyled.PopupTitle>\n\n {/* render dock info if it is available */}\n {stationIsHub && (\n <BaseMapStyled.PopupRow>\n <div>\n <FormattedMessage\n defaultMessage={\n defaultMessages[\"otpUi.VehicleRentalOverlay.availableBikes\"]\n }\n description=\"Label text for the number of bikes available\"\n id=\"otpUi.VehicleRentalOverlay.availableBikes\"\n values={{ value: station.bikesAvailable }}\n />\n </div>\n <div>\n <FormattedMessage\n defaultMessage={\n defaultMessages[\"otpUi.VehicleRentalOverlay.availableDocks\"]\n }\n description=\"Label text for the number of docks available\"\n id=\"otpUi.VehicleRentalOverlay.availableDocks\"\n values={{ value: station.spacesAvailable }}\n />\n </div>\n </BaseMapStyled.PopupRow>\n )}\n\n {/* Set as from/to toolbar */}\n <BaseMapStyled.PopupRow>\n <FromToLocationPicker\n label\n location={location}\n setLocation={setLocation}\n />\n </BaseMapStyled.PopupRow>\n </BaseMapStyled.MapOverlayPopup>\n </Popup>\n );\n };\n\n render() {\n const { companies, leaflet, mapSymbols, stations } = this.props;\n const { zoom = leaflet.map.getZoom() } = this.state;\n // Render an empty FeatureGroup if the rental vehicles should not be visible\n // on the map. Otherwise previous stations may still be shown due to some\n // react-leaflet internals, maybe? Also, do not return null because that will\n // prevent the overlay from appearing in the layer controls.\n\n let filteredStations = stations;\n if (companies) {\n filteredStations = stations.filter(\n station =>\n station.networks.filter(value => companies.includes(value)).length > 0\n );\n }\n\n if (!filteredStations || filteredStations.length === 0) {\n return <FeatureGroup />;\n }\n\n // Convert map symbols for this overlay to zoomBasedSymbolType.\n const symbols = this.convertToZoomMarkerSymbols(mapSymbols);\n\n return (\n <FeatureGroup>\n <ZoomBasedMarkers\n entities={filteredStations}\n symbols={symbols}\n symbolTransform={this.renderSymbolWithPopup}\n zoom={zoom}\n />\n </FeatureGroup>\n );\n }\n}\n\nVehicleRentalOverlay.props = {\n /**\n * The entire companies config array.\n */\n configCompanies: PropTypes.arrayOf(coreUtils.types.companyType.isRequired)\n .isRequired,\n /**\n * A list of companies that are applicable to just this instance of the\n * overlay.\n */\n companies: PropTypes.arrayOf(PropTypes.string.isRequired),\n /**\n * An optional custom function to create a string name of a particular vehicle\n * rental station. This function takes two arguments of the configCompanies\n * prop and a vehicle rental station. The function must return a string.\n */\n getStationName: PropTypes.func,\n /**\n * A configuration of what map markers or symbols to show at various\n * zoom levels.\n */\n mapSymbols: coreUtils.types.vehicleRentalMapOverlaySymbolsType,\n /**\n * If specified, a function that will be triggered every 30 seconds whenever this layer is\n * visible.\n */\n refreshVehicles: PropTypes.func,\n /**\n * A callback for when a user clicks on setting this stop as either the from\n * or to location of a new search.\n *\n * This will be dispatched with the following argument:\n *\n * ```js\n * {\n * location: {\n * lat: number,\n * lon: number,\n * name: string\n * },\n * locationType: \"from\" or \"to\"\n * }\n * ```\n */\n setLocation: PropTypes.func.isRequired,\n /**\n * A list of the vehicle rental stations specific to this overlay instance.\n */\n stations: PropTypes.arrayOf(coreUtils.types.stationType),\n /**\n * Whether the overlay is currently visible.\n */\n visible: PropTypes.bool\n};\n\nVehicleRentalOverlay.defaultProps = {\n getStationName: (configCompanies, station) => {\n const stationNetworks = coreUtils.itinerary.getCompaniesLabelFromNetworks(\n station.networks,\n configCompanies\n );\n let stationName = station.name || station.id;\n if (station.isFloatingBike) {\n stationName = `Free-floating bike: ${stationName}`;\n } else if (station.isFloatingCar) {\n stationName = `${stationNetworks} ${stationName}`;\n } else if (station.isFloatingVehicle) {\n // assumes that all floating vehicles are E-scooters\n stationName = `${stationNetworks} E-scooter`;\n }\n return stationName;\n },\n mapSymbols: [\n {\n zoom: 0,\n symbol: GenericMarker\n }\n ],\n refreshVehicles: null,\n stations: [],\n visible: false\n};\n\nexport default withLeaflet(VehicleRentalOverlay);\n"],"file":"index.js"}
|
package/i18n/en-US.yml
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Default messages for the VehicleRentalOverlay component.
|
|
2
|
+
# To use from a react-intl application:
|
|
3
|
+
# - merge the content of this file into the messages object
|
|
4
|
+
# that has your other localized strings,
|
|
5
|
+
# - flatten the ids, i.e. convert a structure such as
|
|
6
|
+
# otpUi > VehicleRentalOverlay > availableBikes
|
|
7
|
+
# into "otpUi.VehicleRentalOverlay.availableBikes".
|
|
8
|
+
# - pass the resulting object to the messages prop of IntlProvider.
|
|
9
|
+
#
|
|
10
|
+
|
|
11
|
+
otpUi:
|
|
12
|
+
VehicleRentalOverlay:
|
|
13
|
+
availableBikes: "Available bikes: {value}"
|
|
14
|
+
availableDocks: "Available docks: {value}"
|
package/i18n/fr.yml
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Default messages for the VehicleRentalOverlay component.
|
|
2
|
+
# To use from a react-intl application:
|
|
3
|
+
# - merge the content of this file into the messages object
|
|
4
|
+
# that has your other localized strings,
|
|
5
|
+
# - flatten the ids, i.e. convert a structure such as
|
|
6
|
+
# otpUi > VehicleRentalOverlay > availableBikes
|
|
7
|
+
# into "otpUi.VehicleRentalOverlay.availableBikes".
|
|
8
|
+
# - pass the resulting object to the messages prop of IntlProvider.
|
|
9
|
+
#
|
|
10
|
+
|
|
11
|
+
otpUi:
|
|
12
|
+
VehicleRentalOverlay:
|
|
13
|
+
availableBikes: "Vélos disponibles : {value}"
|
|
14
|
+
availableDocks: "Bornes disponibles : {value}"
|
package/lib/index.js
CHANGED
|
@@ -7,6 +7,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports.default = void 0;
|
|
9
9
|
|
|
10
|
+
var _flat = _interopRequireDefault(require("flat"));
|
|
11
|
+
|
|
10
12
|
var _baseMap = require("@opentripplanner/base-map");
|
|
11
13
|
|
|
12
14
|
var _coreUtils = _interopRequireDefault(require("@opentripplanner/core-utils"));
|
|
@@ -19,18 +21,29 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
|
19
21
|
|
|
20
22
|
var _react = _interopRequireDefault(require("react"));
|
|
21
23
|
|
|
24
|
+
var _reactIntl = require("react-intl");
|
|
25
|
+
|
|
22
26
|
var _reactLeaflet = require("react-leaflet");
|
|
23
27
|
|
|
24
28
|
var _DefaultMarkers = require("./DefaultMarkers");
|
|
25
29
|
|
|
30
|
+
var _enUS = _interopRequireDefault(require("../i18n/en-US.yml"));
|
|
31
|
+
|
|
32
|
+
// Load the default messages.
|
|
33
|
+
// HACK: We should flatten the messages loaded above because
|
|
34
|
+
// the YAML loaders behave differently between webpack and our version of jest:
|
|
35
|
+
// - the yaml loader for webpack returns a nested object,
|
|
36
|
+
// - the yaml loader for jest returns messages with flattened ids.
|
|
37
|
+
const defaultMessages = (0, _flat.default)(_enUS.default);
|
|
26
38
|
/**
|
|
27
39
|
* This vehicle rental overlay can be used to render vehicle rentals of various
|
|
28
40
|
* types. This layer can be configured to show different styles of markers at
|
|
29
41
|
* different zoom levels.
|
|
30
42
|
*/
|
|
43
|
+
|
|
31
44
|
class VehicleRentalOverlay extends _reactLeaflet.MapLayer {
|
|
32
|
-
constructor(
|
|
33
|
-
super(
|
|
45
|
+
constructor(props) {
|
|
46
|
+
super(props);
|
|
34
47
|
|
|
35
48
|
this.renderSymbolWithPopup = Symbol => {
|
|
36
49
|
const SymbolWrapper = ({
|
|
@@ -76,6 +89,26 @@ class VehicleRentalOverlay extends _reactLeaflet.MapLayer {
|
|
|
76
89
|
};
|
|
77
90
|
});
|
|
78
91
|
|
|
92
|
+
this.onOverlayAdded = () => {
|
|
93
|
+
this.startRefreshing();
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
this.onOverlayRemoved = () => {
|
|
97
|
+
this.stopRefreshing();
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
this.onViewportChanged = viewport => {
|
|
101
|
+
const {
|
|
102
|
+
zoom: newZoom
|
|
103
|
+
} = viewport;
|
|
104
|
+
|
|
105
|
+
if (this.state.zoom !== newZoom) {
|
|
106
|
+
this.setState({
|
|
107
|
+
zoom: newZoom
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
|
|
79
112
|
this.renderPopupForStation = (station, stationIsHub = false) => {
|
|
80
113
|
const {
|
|
81
114
|
configCompanies,
|
|
@@ -88,12 +121,37 @@ class VehicleRentalOverlay extends _reactLeaflet.MapLayer {
|
|
|
88
121
|
lon: station.x,
|
|
89
122
|
name: stationName
|
|
90
123
|
};
|
|
91
|
-
return /*#__PURE__*/_react.default.createElement(_reactLeaflet.Popup, null, /*#__PURE__*/_react.default.createElement(_baseMap.Styled.MapOverlayPopup, null, /*#__PURE__*/_react.default.createElement(_baseMap.Styled.PopupTitle, null, stationName), stationIsHub && /*#__PURE__*/_react.default.createElement(_baseMap.Styled.PopupRow, null, /*#__PURE__*/_react.default.createElement("div", null,
|
|
124
|
+
return /*#__PURE__*/_react.default.createElement(_reactLeaflet.Popup, null, /*#__PURE__*/_react.default.createElement(_baseMap.Styled.MapOverlayPopup, null, /*#__PURE__*/_react.default.createElement(_baseMap.Styled.PopupTitle, null, stationName), stationIsHub && /*#__PURE__*/_react.default.createElement(_baseMap.Styled.PopupRow, null, /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
|
|
125
|
+
defaultMessage: defaultMessages["otpUi.VehicleRentalOverlay.availableBikes"],
|
|
126
|
+
description: "Label text for the number of bikes available",
|
|
127
|
+
id: "otpUi.VehicleRentalOverlay.availableBikes",
|
|
128
|
+
values: {
|
|
129
|
+
value: station.bikesAvailable
|
|
130
|
+
}
|
|
131
|
+
})), /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
|
|
132
|
+
defaultMessage: defaultMessages["otpUi.VehicleRentalOverlay.availableDocks"],
|
|
133
|
+
description: "Label text for the number of docks available",
|
|
134
|
+
id: "otpUi.VehicleRentalOverlay.availableDocks",
|
|
135
|
+
values: {
|
|
136
|
+
value: station.spacesAvailable
|
|
137
|
+
}
|
|
138
|
+
}))), /*#__PURE__*/_react.default.createElement(_baseMap.Styled.PopupRow, null, /*#__PURE__*/_react.default.createElement(_fromToLocationPicker.default, {
|
|
139
|
+
label: true,
|
|
92
140
|
location: location,
|
|
93
141
|
setLocation: setLocation
|
|
94
142
|
}))));
|
|
95
143
|
};
|
|
144
|
+
|
|
145
|
+
this.state = {
|
|
146
|
+
zoom: null
|
|
147
|
+
};
|
|
96
148
|
}
|
|
149
|
+
/**
|
|
150
|
+
* This helper method will be passed to the ZoomBasedMarkers symbolTransform prop.
|
|
151
|
+
* It creates a component that inserts a popup
|
|
152
|
+
* as a child of the specified symbol from the mapSymbols prop.
|
|
153
|
+
*/
|
|
154
|
+
|
|
97
155
|
|
|
98
156
|
createLeafletElement() {}
|
|
99
157
|
|
|
@@ -117,25 +175,36 @@ class VehicleRentalOverlay extends _reactLeaflet.MapLayer {
|
|
|
117
175
|
stopRefreshing() {
|
|
118
176
|
if (this.refreshTimer) clearInterval(this.refreshTimer);
|
|
119
177
|
}
|
|
178
|
+
/**
|
|
179
|
+
* When the layer is added (or toggled on, or its visibility becomes true),
|
|
180
|
+
* start refreshing vehicle positions.
|
|
181
|
+
*/
|
|
182
|
+
|
|
120
183
|
|
|
184
|
+
/**
|
|
185
|
+
* Upon mounting, see whether the vehicles should be fetched,
|
|
186
|
+
* and also call the register overlay prop that the
|
|
187
|
+
* @opentripplanner/base-map package has injected to listen to zoom/position changes.
|
|
188
|
+
*/
|
|
121
189
|
componentDidMount() {
|
|
122
190
|
const {
|
|
191
|
+
leaflet,
|
|
192
|
+
registerOverlay,
|
|
123
193
|
visible
|
|
124
194
|
} = this.props;
|
|
195
|
+
this.setState({
|
|
196
|
+
zoom: leaflet.map.getZoom()
|
|
197
|
+
});
|
|
125
198
|
if (visible) this.startRefreshing();
|
|
199
|
+
|
|
200
|
+
if (typeof registerOverlay === "function") {
|
|
201
|
+
registerOverlay(this);
|
|
202
|
+
}
|
|
126
203
|
}
|
|
127
204
|
|
|
128
205
|
componentWillUnmount() {
|
|
129
206
|
this.stopRefreshing();
|
|
130
207
|
}
|
|
131
|
-
|
|
132
|
-
componentDidUpdate(prevProps) {
|
|
133
|
-
if (!prevProps.visible && this.props.visible) {
|
|
134
|
-
this.startRefreshing();
|
|
135
|
-
} else if (prevProps.visible && !this.props.visible) {
|
|
136
|
-
this.stopRefreshing();
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
208
|
/**
|
|
140
209
|
* Render some popup html for a station. This contains custom logic for
|
|
141
210
|
* displaying rental vehicles in the TriMet MOD website that might not be
|
|
@@ -146,18 +215,17 @@ class VehicleRentalOverlay extends _reactLeaflet.MapLayer {
|
|
|
146
215
|
render() {
|
|
147
216
|
const {
|
|
148
217
|
companies,
|
|
218
|
+
leaflet,
|
|
149
219
|
mapSymbols,
|
|
150
|
-
stations
|
|
151
|
-
|
|
152
|
-
|
|
220
|
+
stations
|
|
221
|
+
} = this.props;
|
|
222
|
+
const {
|
|
223
|
+
zoom = leaflet.map.getZoom()
|
|
224
|
+
} = this.state; // Render an empty FeatureGroup if the rental vehicles should not be visible
|
|
153
225
|
// on the map. Otherwise previous stations may still be shown due to some
|
|
154
226
|
// react-leaflet internals, maybe? Also, do not return null because that will
|
|
155
227
|
// prevent the overlay from appearing in the layer controls.
|
|
156
228
|
|
|
157
|
-
if (!visible) {
|
|
158
|
-
return /*#__PURE__*/_react.default.createElement(_reactLeaflet.FeatureGroup, null);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
229
|
let filteredStations = stations;
|
|
162
230
|
|
|
163
231
|
if (companies) {
|
|
@@ -166,10 +234,8 @@ class VehicleRentalOverlay extends _reactLeaflet.MapLayer {
|
|
|
166
234
|
|
|
167
235
|
if (!filteredStations || filteredStations.length === 0) {
|
|
168
236
|
return /*#__PURE__*/_react.default.createElement(_reactLeaflet.FeatureGroup, null);
|
|
169
|
-
} //
|
|
170
|
-
|
|
237
|
+
} // Convert map symbols for this overlay to zoomBasedSymbolType.
|
|
171
238
|
|
|
172
|
-
const zoom = this.props.leaflet.map.getZoom(); // Convert map symbols for this overlay to zoomBasedSymbolType.
|
|
173
239
|
|
|
174
240
|
const symbols = this.convertToZoomMarkerSymbols(mapSymbols);
|
|
175
241
|
return /*#__PURE__*/_react.default.createElement(_reactLeaflet.FeatureGroup, null, /*#__PURE__*/_react.default.createElement(_zoomBasedMarkers.default, {
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.js"],"names":["VehicleRentalOverlay","MapLayer","renderSymbolWithPopup","Symbol","SymbolWrapper","entity","station","zoom","renderPopupForStation","bikesAvailable","undefined","isFloatingBike","propTypes","coreUtils","types","stationType","isRequired","PropTypes","number","convertToZoomMarkerSymbols","mapSymbols","map","mapSymbol","symbol","type","HubAndFloatingBike","minZoom","stationIsHub","configCompanies","getStationName","setLocation","props","stationName","location","lat","y","lon","x","name","spacesAvailable","createLeafletElement","updateLeafletElement","startRefreshing","refreshVehicles","refreshTimer","setInterval","stopRefreshing","clearInterval","componentDidMount","visible","componentWillUnmount","componentDidUpdate","prevProps","render","companies","stations","filteredStations","filter","networks","value","includes","length","leaflet","getZoom","symbols","arrayOf","companyType","string","func","vehicleRentalMapOverlaySymbolsType","bool","defaultProps","stationNetworks","itinerary","getCompaniesLabelFromNetworks","id","isFloatingCar","isFloatingVehicle","GenericMarker"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AAMA;AACA;AACA;AACA;AACA;AACA,MAAMA,oBAAN,SAAmCC,sBAAnC,CAA4C;AAAA;AAAA;;AAAA,SAM1CC,qBAN0C,GAMlBC,MAAM,IAAI;AAChC,YAAMC,aAAa,GAAG,CAAC;AAAEC,QAAAA,MAAM,EAAEC,OAAV;AAAmBC,QAAAA;AAAnB,OAAD,kBACpB,6BAAC,MAAD;AAAQ,QAAA,MAAM,EAAED,OAAhB;AAAyB,QAAA,IAAI,EAAEC;AAA/B,SACG,KAAKC,qBAAL,CACCF,OADD,EAECA,OAAO,CAACG,c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Y,EAAhD;AACD,KAFM,MAEA,IAAI1B,OAAO,CAACuE,iBAAZ,EAA+B;AACpC;AACA7C,MAAAA,WAAW,GAAI,GAAEwC,eAAgB,YAAjC;AACD;;AACD,WAAOxC,WAAP;AACD,GAhBiC;AAiBlCZ,EAAAA,UAAU,EAAE,CACV;AACEb,IAAAA,IAAI,EAAE,CADR;AAEEgB,IAAAA,MAAM,EAAEuD;AAFV,GADU,CAjBsB;AAuBlCnC,EAAAA,eAAe,EAAE,IAvBiB;AAwBlCY,EAAAA,QAAQ,EAAE,EAxBwB;AAyBlCN,EAAAA,OAAO,EAAE;AAzByB,CAApC;;eA4Be,+BAAYjD,oBAAZ,C","sourcesContent":["import { Styled as BaseMapStyled } from \"@opentripplanner/base-map\";\nimport coreUtils from \"@opentripplanner/core-utils\";\nimport FromToLocationPicker from \"@opentripplanner/from-to-location-picker\";\nimport ZoomBasedMarkers from \"@opentripplanner/zoom-based-markers\";\nimport PropTypes from \"prop-types\";\nimport React from \"react\";\nimport { FeatureGroup, MapLayer, Popup, withLeaflet } from \"react-leaflet\";\n\nimport {\n GenericMarker,\n HubAndFloatingBike,\n SharedBikeCircle\n} from \"./DefaultMarkers\";\n\n/**\n * This vehicle rental overlay can be used to render vehicle rentals of various\n * types. This layer can be configured to show different styles of markers at\n * different zoom levels.\n */\nclass VehicleRentalOverlay extends MapLayer {\n /**\n * This helper method will be passed to the ZoomBasedMarkers symbolTransform prop.\n * It creates a component that inserts a popup\n * as a child of the specified symbol from the mapSymbols prop.\n */\n renderSymbolWithPopup = Symbol => {\n const SymbolWrapper = ({ entity: station, zoom }) => (\n <Symbol entity={station} zoom={zoom}>\n {this.renderPopupForStation(\n station,\n station.bikesAvailable !== undefined && !station.isFloatingBike\n )}\n </Symbol>\n );\n SymbolWrapper.propTypes = {\n entity: coreUtils.types.stationType.isRequired,\n zoom: PropTypes.number.isRequired\n };\n\n return SymbolWrapper;\n };\n\n /**\n * Convert map symbols to zoomBasedSymbolType.\n */\n convertToZoomMarkerSymbols = mapSymbols =>\n mapSymbols.map(mapSymbol => {\n // If mapSymbol uses zoomBasedSymbolType, use it as is.\n if (mapSymbol.symbol) {\n return mapSymbol;\n }\n\n // Otherwise, convert into zoomBasedType (no support for symbols by type).\n let symbol;\n switch (mapSymbol.type) {\n case \"circle\":\n symbol = SharedBikeCircle(mapSymbol);\n break;\n case \"hubAndFloatingBike\":\n symbol = HubAndFloatingBike;\n break;\n default:\n symbol = GenericMarker(mapSymbol);\n }\n\n return {\n minZoom: mapSymbol.minZoom,\n symbol\n };\n });\n\n createLeafletElement() {}\n\n updateLeafletElement() {}\n\n startRefreshing() {\n const { refreshVehicles } = this.props;\n\n // Create the timer only if refreshVehicles is a valid function.\n if (typeof refreshVehicles === \"function\") {\n // initial station retrieval\n refreshVehicles();\n\n // set up timer to refresh stations periodically\n this.refreshTimer = setInterval(() => {\n refreshVehicles();\n }, 30000); // defaults to every 30 sec. TODO: make this configurable?\n }\n }\n\n stopRefreshing() {\n if (this.refreshTimer) clearInterval(this.refreshTimer);\n }\n\n componentDidMount() {\n const { visible } = this.props;\n if (visible) this.startRefreshing();\n }\n\n componentWillUnmount() {\n this.stopRefreshing();\n }\n\n componentDidUpdate(prevProps) {\n if (!prevProps.visible && this.props.visible) {\n this.startRefreshing();\n } else if (prevProps.visible && !this.props.visible) {\n this.stopRefreshing();\n }\n }\n\n /**\n * Render some popup html for a station. This contains custom logic for\n * displaying rental vehicles in the TriMet MOD website that might not be\n * applicable to other regions.\n */\n renderPopupForStation = (station, stationIsHub = false) => {\n const { configCompanies, getStationName, setLocation } = this.props;\n const stationName = getStationName(configCompanies, station);\n const location = {\n lat: station.y,\n lon: station.x,\n name: stationName\n };\n return (\n <Popup>\n <BaseMapStyled.MapOverlayPopup>\n <BaseMapStyled.PopupTitle>{stationName}</BaseMapStyled.PopupTitle>\n\n {/* render dock info if it is available */}\n {stationIsHub && (\n <BaseMapStyled.PopupRow>\n <div>Available bikes: {station.bikesAvailable}</div>\n <div>Available docks: {station.spacesAvailable}</div>\n </BaseMapStyled.PopupRow>\n )}\n\n {/* Set as from/to toolbar */}\n <BaseMapStyled.PopupRow>\n <b>Plan a trip:</b>\n <FromToLocationPicker\n location={location}\n setLocation={setLocation}\n />\n </BaseMapStyled.PopupRow>\n </BaseMapStyled.MapOverlayPopup>\n </Popup>\n );\n };\n\n render() {\n const { companies, mapSymbols, stations, visible } = this.props;\n // Render an empty FeatureGroup if the rental vehicles should not be visible\n // on the map. Otherwise previous stations may still be shown due to some\n // react-leaflet internals, maybe? Also, do not return null because that will\n // prevent the overlay from appearing in the layer controls.\n if (!visible) {\n return <FeatureGroup />;\n }\n\n let filteredStations = stations;\n if (companies) {\n filteredStations = stations.filter(\n station =>\n station.networks.filter(value => companies.includes(value)).length > 0\n );\n }\n\n if (!filteredStations || filteredStations.length === 0) {\n return <FeatureGroup />;\n }\n\n // get zoom to check which symbol to render\n const zoom = this.props.leaflet.map.getZoom();\n\n // Convert map symbols for this overlay to zoomBasedSymbolType.\n const symbols = this.convertToZoomMarkerSymbols(mapSymbols);\n\n return (\n <FeatureGroup>\n <ZoomBasedMarkers\n entities={filteredStations}\n symbols={symbols}\n symbolTransform={this.renderSymbolWithPopup}\n zoom={zoom}\n />\n </FeatureGroup>\n );\n }\n}\n\nVehicleRentalOverlay.props = {\n /**\n * The entire companies config array.\n */\n configCompanies: PropTypes.arrayOf(coreUtils.types.companyType.isRequired)\n .isRequired,\n /**\n * A list of companies that are applicable to just this instance of the\n * overlay.\n */\n companies: PropTypes.arrayOf(PropTypes.string.isRequired),\n /**\n * An optional custom function to create a string name of a particular vehicle\n * rental station. This function takes two arguments of the configCompanies\n * prop and a vehicle rental station. The function must return a string.\n */\n getStationName: PropTypes.func,\n /**\n * A configuration of what map markers or symbols to show at various\n * zoom levels.\n */\n mapSymbols: coreUtils.types.vehicleRentalMapOverlaySymbolsType,\n /**\n * If specified, a function that will be triggered every 30 seconds whenever this layer is\n * visible.\n */\n refreshVehicles: PropTypes.func,\n /**\n * A callback for when a user clicks on setting this stop as either the from\n * or to location of a new search.\n *\n * This will be dispatched with the following argument:\n *\n * ```js\n * {\n * location: {\n * lat: number,\n * lon: number,\n * name: string\n * },\n * locationType: \"from\" or \"to\"\n * }\n * ```\n */\n setLocation: PropTypes.func.isRequired,\n /**\n * A list of the vehicle rental stations specific to this overlay instance.\n */\n stations: PropTypes.arrayOf(coreUtils.types.stationType),\n /**\n * Whether the overlay is currently visible.\n */\n visible: PropTypes.bool\n};\n\nVehicleRentalOverlay.defaultProps = {\n getStationName: (configCompanies, station) => {\n const stationNetworks = coreUtils.itinerary.getCompaniesLabelFromNetworks(\n station.networks,\n configCompanies\n );\n let stationName = station.name || station.id;\n if (station.isFloatingBike) {\n stationName = `Free-floating bike: ${stationName}`;\n } else if (station.isFloatingCar) {\n stationName = `${stationNetworks} ${stationName}`;\n } else if (station.isFloatingVehicle) {\n // assumes that all floating vehicles are E-scooters\n stationName = `${stationNetworks} E-scooter`;\n }\n return stationName;\n },\n mapSymbols: [\n {\n zoom: 0,\n symbol: GenericMarker\n }\n ],\n refreshVehicles: null,\n stations: [],\n visible: false\n};\n\nexport default withLeaflet(VehicleRentalOverlay);\n"],"file":"index.js"}
|
|
1
|
+
{"version":3,"sources":["../src/index.js"],"names":["defaultMessages","defaultEnglishMessages","VehicleRentalOverlay","MapLayer","constructor","props","renderSymbolWithPopup","Symbol","SymbolWrapper","entity","station","zoom","renderPopupForStation","bikesAvailable","undefined","isFloatingBike","propTypes","coreUtils","types","stationType","isRequired","PropTypes","number","convertToZoomMarkerSymbols","mapSymbols","map","mapSymbol","symbol","type","HubAndFloatingBike","minZoom","onOverlayAdded","startRefreshing","onOverlayRemoved","stopRefreshing","onViewportChanged","viewport","newZoom","state","setState","stationIsHub","configCompanies","getStationName","setLocation","stationName","location","lat","y","lon","x","name","value","spacesAvailable","createLeafletElement","updateLeafletElement","refreshVehicles","refreshTimer","setInterval","clearInterval","componentDidMount","leaflet","registerOverlay","visible","getZoom","componentWillUnmount","render","companies","stations","filteredStations","filter","networks","includes","length","symbols","arrayOf","companyType","string","func","vehicleRentalMapOverlaySymbolsType","bool","defaultProps","stationNetworks","itinerary","getCompaniesLabelFromNetworks","id","isFloatingCar","isFloatingVehicle","GenericMarker"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AAOA;;AADA;AAGA;AACA;AACA;AACA;AACA,MAAMA,eAAe,GAAG,mBAAQC,aAAR,CAAxB;AAEA;AACA;AACA;AACA;AACA;;AACA,MAAMC,oBAAN,SAAmCC,sBAAnC,CAA4C;AAC1CC,EAAAA,WAAW,CAACC,KAAD,EAAQ;AACjB,UAAMA,KAAN;;AADiB,SAYnBC,qBAZmB,GAYKC,MAAM,IAAI;AAChC,YAAMC,aAAa,GAAG,CAAC;AAAEC,QAAAA,MAAM,EAAEC,OAAV;AAAmBC,QAAAA;AAAnB,OAAD,kBACpB,6BAAC,MAAD;AAAQ,QAAA,MAAM,EAAED,OAAhB;AAAyB,QAAA,IAAI,EAAEC;AAA/B,SACG,KAAKC,qBAAL,CACCF,OADD,EAECA,OAAO,CAACG,cAAR,KAA2BC,SAA3B,IAAwC,CAACJ,OAAO,CAACK,cAFlD,CADH,CADF;;AAQAP,MAAAA,aAAa,CAACQ,SAAd,GAA0B;AACxBP,QAAAA,MAAM,EAAEQ,mBAAUC,KAAV,CAAgBC,WAAhB,CAA4BC,UADZ;AAExBT,QAAAA,IAAI,EAAEU,mBAAUC,MAAV,CAAiBF;AAFC,OAA1B;AAKA,aAAOZ,aAAP;AACD,KA3BkB;;AAAA,SAgCnBe,0BAhCmB,GAgCUC,UAAU,IACrCA,UAAU,CAACC,GAAX,CAAeC,SAAS,IAAI;AAC1B;AACA,UAAIA,SAAS,CAACC,MAAd,EAAsB;AACpB,eAAOD,SAAP;AACD,OAJyB,CAM1B;;;AACA,UAAIC,MAAJ;;AACA,cAAQD,SAAS,CAACE,IAAlB;AACE,aAAK,QA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,OAAO,CAAC4D,QADc,EAEtB7B,eAFsB,CAAxB;;AAIA,QAAIG,WAAW,GAAGlC,OAAO,CAACwC,IAAR,IAAgBxC,OAAO,CAAC0E,EAA1C;;AACA,QAAI1E,OAAO,CAACK,cAAZ,EAA4B;AAC1B6B,MAAAA,WAAW,GAAI,uBAAsBA,WAAY,EAAjD;AACD,KAFD,MAEO,IAAIlC,OAAO,CAAC2E,aAAZ,EAA2B;AAChCzC,MAAAA,WAAW,GAAI,GAAEqC,eAAgB,IAAGrC,WAAY,EAAhD;AACD,KAFM,MAEA,IAAIlC,OAAO,CAAC4E,iBAAZ,EAA+B;AACpC;AACA1C,MAAAA,WAAW,GAAI,GAAEqC,eAAgB,YAAjC;AACD;;AACD,WAAOrC,WAAP;AACD,GAhBiC;AAiBlCpB,EAAAA,UAAU,EAAE,CACV;AACEb,IAAAA,IAAI,EAAE,CADR;AAEEgB,IAAAA,MAAM,EAAE4D;AAFV,GADU,CAjBsB;AAuBlChC,EAAAA,eAAe,EAAE,IAvBiB;AAwBlCY,EAAAA,QAAQ,EAAE,EAxBwB;AAyBlCL,EAAAA,OAAO,EAAE;AAzByB,CAApC;;eA4Be,+BAAY5D,oBAAZ,C","sourcesContent":["import flatten from \"flat\";\nimport { Styled as BaseMapStyled } from \"@opentripplanner/base-map\";\nimport coreUtils from \"@opentripplanner/core-utils\";\nimport FromToLocationPicker from \"@opentripplanner/from-to-location-picker\";\nimport ZoomBasedMarkers from \"@opentripplanner/zoom-based-markers\";\nimport PropTypes from \"prop-types\";\nimport React from \"react\";\nimport { FormattedMessage } from \"react-intl\";\nimport { FeatureGroup, MapLayer, Popup, withLeaflet } from \"react-leaflet\";\n\nimport {\n GenericMarker,\n HubAndFloatingBike,\n SharedBikeCircle\n} from \"./DefaultMarkers\";\n\n// Load the default messages.\nimport defaultEnglishMessages from \"../i18n/en-US.yml\";\n\n// HACK: We should flatten the messages loaded above because\n// the YAML loaders behave differently between webpack and our version of jest:\n// - the yaml loader for webpack returns a nested object,\n// - the yaml loader for jest returns messages with flattened ids.\nconst defaultMessages = flatten(defaultEnglishMessages);\n\n/**\n * This vehicle rental overlay can be used to render vehicle rentals of various\n * types. This layer can be configured to show different styles of markers at\n * different zoom levels.\n */\nclass VehicleRentalOverlay extends MapLayer {\n constructor(props) {\n super(props);\n this.state = {\n zoom: null\n };\n }\n\n /**\n * This helper method will be passed to the ZoomBasedMarkers symbolTransform prop.\n * It creates a component that inserts a popup\n * as a child of the specified symbol from the mapSymbols prop.\n */\n renderSymbolWithPopup = Symbol => {\n const SymbolWrapper = ({ entity: station, zoom }) => (\n <Symbol entity={station} zoom={zoom}>\n {this.renderPopupForStation(\n station,\n station.bikesAvailable !== undefined && !station.isFloatingBike\n )}\n </Symbol>\n );\n SymbolWrapper.propTypes = {\n entity: coreUtils.types.stationType.isRequired,\n zoom: PropTypes.number.isRequired\n };\n\n return SymbolWrapper;\n };\n\n /**\n * Convert map symbols to zoomBasedSymbolType.\n */\n convertToZoomMarkerSymbols = mapSymbols =>\n mapSymbols.map(mapSymbol => {\n // If mapSymbol uses zoomBasedSymbolType, use it as is.\n if (mapSymbol.symbol) {\n return mapSymbol;\n }\n\n // Otherwise, convert into zoomBasedType (no support for symbols by type).\n let symbol;\n switch (mapSymbol.type) {\n case \"circle\":\n symbol = SharedBikeCircle(mapSymbol);\n break;\n case \"hubAndFloatingBike\":\n symbol = HubAndFloatingBike;\n break;\n default:\n symbol = GenericMarker(mapSymbol);\n }\n\n return {\n minZoom: mapSymbol.minZoom,\n symbol\n };\n });\n\n createLeafletElement() {}\n\n updateLeafletElement() {}\n\n startRefreshing() {\n const { refreshVehicles } = this.props;\n\n // Create the timer only if refreshVehicles is a valid function.\n if (typeof refreshVehicles === \"function\") {\n // initial station retrieval\n refreshVehicles();\n\n // set up timer to refresh stations periodically\n this.refreshTimer = setInterval(() => {\n refreshVehicles();\n }, 30000); // defaults to every 30 sec. TODO: make this configurable?\n }\n }\n\n stopRefreshing() {\n if (this.refreshTimer) clearInterval(this.refreshTimer);\n }\n\n /**\n * When the layer is added (or toggled on, or its visibility becomes true),\n * start refreshing vehicle positions.\n */\n onOverlayAdded = () => {\n this.startRefreshing();\n };\n\n /**\n * When the layer is removed (or toggled off, or its visibility becomes false),\n * stop refreshing vehicle positions.\n */\n onOverlayRemoved = () => {\n this.stopRefreshing();\n };\n\n /**\n * Listen to changes on the BaseMap's center or zoom.\n * @param viewport The viewport data. See https://github.com/PaulLeCam/react-leaflet/blob/master/example/components/viewport.js for details.\n */\n onViewportChanged = viewport => {\n const { zoom: newZoom } = viewport;\n if (this.state.zoom !== newZoom) {\n this.setState({ zoom: newZoom });\n }\n };\n\n /**\n * Upon mounting, see whether the vehicles should be fetched,\n * and also call the register overlay prop that the\n * @opentripplanner/base-map package has injected to listen to zoom/position changes.\n */\n componentDidMount() {\n const { leaflet, registerOverlay, visible } = this.props;\n this.setState({\n zoom: leaflet.map.getZoom()\n });\n if (visible) this.startRefreshing();\n if (typeof registerOverlay === \"function\") {\n registerOverlay(this);\n }\n }\n\n componentWillUnmount() {\n this.stopRefreshing();\n }\n\n /**\n * Render some popup html for a station. This contains custom logic for\n * displaying rental vehicles in the TriMet MOD website that might not be\n * applicable to other regions.\n */\n renderPopupForStation = (station, stationIsHub = false) => {\n const { configCompanies, getStationName, setLocation } = this.props;\n const stationName = getStationName(configCompanies, station);\n const location = {\n lat: station.y,\n lon: station.x,\n name: stationName\n };\n return (\n <Popup>\n <BaseMapStyled.MapOverlayPopup>\n <BaseMapStyled.PopupTitle>{stationName}</BaseMapStyled.PopupTitle>\n\n {/* render dock info if it is available */}\n {stationIsHub && (\n <BaseMapStyled.PopupRow>\n <div>\n <FormattedMessage\n defaultMessage={\n defaultMessages[\"otpUi.VehicleRentalOverlay.availableBikes\"]\n }\n description=\"Label text for the number of bikes available\"\n id=\"otpUi.VehicleRentalOverlay.availableBikes\"\n values={{ value: station.bikesAvailable }}\n />\n </div>\n <div>\n <FormattedMessage\n defaultMessage={\n defaultMessages[\"otpUi.VehicleRentalOverlay.availableDocks\"]\n }\n description=\"Label text for the number of docks available\"\n id=\"otpUi.VehicleRentalOverlay.availableDocks\"\n values={{ value: station.spacesAvailable }}\n />\n </div>\n </BaseMapStyled.PopupRow>\n )}\n\n {/* Set as from/to toolbar */}\n <BaseMapStyled.PopupRow>\n <FromToLocationPicker\n label\n location={location}\n setLocation={setLocation}\n />\n </BaseMapStyled.PopupRow>\n </BaseMapStyled.MapOverlayPopup>\n </Popup>\n );\n };\n\n render() {\n const { companies, leaflet, mapSymbols, stations } = this.props;\n const { zoom = leaflet.map.getZoom() } = this.state;\n // Render an empty FeatureGroup if the rental vehicles should not be visible\n // on the map. Otherwise previous stations may still be shown due to some\n // react-leaflet internals, maybe? Also, do not return null because that will\n // prevent the overlay from appearing in the layer controls.\n\n let filteredStations = stations;\n if (companies) {\n filteredStations = stations.filter(\n station =>\n station.networks.filter(value => companies.includes(value)).length > 0\n );\n }\n\n if (!filteredStations || filteredStations.length === 0) {\n return <FeatureGroup />;\n }\n\n // Convert map symbols for this overlay to zoomBasedSymbolType.\n const symbols = this.convertToZoomMarkerSymbols(mapSymbols);\n\n return (\n <FeatureGroup>\n <ZoomBasedMarkers\n entities={filteredStations}\n symbols={symbols}\n symbolTransform={this.renderSymbolWithPopup}\n zoom={zoom}\n />\n </FeatureGroup>\n );\n }\n}\n\nVehicleRentalOverlay.props = {\n /**\n * The entire companies config array.\n */\n configCompanies: PropTypes.arrayOf(coreUtils.types.companyType.isRequired)\n .isRequired,\n /**\n * A list of companies that are applicable to just this instance of the\n * overlay.\n */\n companies: PropTypes.arrayOf(PropTypes.string.isRequired),\n /**\n * An optional custom function to create a string name of a particular vehicle\n * rental station. This function takes two arguments of the configCompanies\n * prop and a vehicle rental station. The function must return a string.\n */\n getStationName: PropTypes.func,\n /**\n * A configuration of what map markers or symbols to show at various\n * zoom levels.\n */\n mapSymbols: coreUtils.types.vehicleRentalMapOverlaySymbolsType,\n /**\n * If specified, a function that will be triggered every 30 seconds whenever this layer is\n * visible.\n */\n refreshVehicles: PropTypes.func,\n /**\n * A callback for when a user clicks on setting this stop as either the from\n * or to location of a new search.\n *\n * This will be dispatched with the following argument:\n *\n * ```js\n * {\n * location: {\n * lat: number,\n * lon: number,\n * name: string\n * },\n * locationType: \"from\" or \"to\"\n * }\n * ```\n */\n setLocation: PropTypes.func.isRequired,\n /**\n * A list of the vehicle rental stations specific to this overlay instance.\n */\n stations: PropTypes.arrayOf(coreUtils.types.stationType),\n /**\n * Whether the overlay is currently visible.\n */\n visible: PropTypes.bool\n};\n\nVehicleRentalOverlay.defaultProps = {\n getStationName: (configCompanies, station) => {\n const stationNetworks = coreUtils.itinerary.getCompaniesLabelFromNetworks(\n station.networks,\n configCompanies\n );\n let stationName = station.name || station.id;\n if (station.isFloatingBike) {\n stationName = `Free-floating bike: ${stationName}`;\n } else if (station.isFloatingCar) {\n stationName = `${stationNetworks} ${stationName}`;\n } else if (station.isFloatingVehicle) {\n // assumes that all floating vehicles are E-scooters\n stationName = `${stationNetworks} E-scooter`;\n }\n return stationName;\n },\n mapSymbols: [\n {\n zoom: 0,\n symbol: GenericMarker\n }\n ],\n refreshVehicles: null,\n stations: [],\n visible: false\n};\n\nexport default withLeaflet(VehicleRentalOverlay);\n"],"file":"index.js"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opentripplanner/vehicle-rental-overlay",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"description": "A map overlay to show vehicle rentals from a specific company",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "esm/index.js",
|
|
@@ -18,11 +18,11 @@
|
|
|
18
18
|
"url": "git+https://github.com/opentripplanner/otp-ui.git"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@opentripplanner/base-map": "^2.0.0",
|
|
22
21
|
"@opentripplanner/core-utils": "^4.5.0",
|
|
23
|
-
"@opentripplanner/from-to-location-picker": "^1.
|
|
22
|
+
"@opentripplanner/from-to-location-picker": "^2.1.0",
|
|
24
23
|
"@opentripplanner/zoom-based-markers": "^1.2.1",
|
|
25
24
|
"@styled-icons/fa-solid": "^10.34.0",
|
|
25
|
+
"flat": "^5.0.2",
|
|
26
26
|
"lodash.memoize": "^4.1.2",
|
|
27
27
|
"prop-types": "^15.7.2"
|
|
28
28
|
},
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"@opentripplanner/base-map": "^2.0.0",
|
|
31
31
|
"react": "^16.14.0",
|
|
32
32
|
"react-dom": "^16.8.6",
|
|
33
|
+
"react-intl": "^5.24.6",
|
|
33
34
|
"react-leaflet": "^2.6.1",
|
|
34
35
|
"styled-components": "^5.3.0"
|
|
35
36
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import BaseMap from "@opentripplanner/base-map";
|
|
2
2
|
import coreUtils from "@opentripplanner/core-utils";
|
|
3
3
|
import PropTypes from "prop-types";
|
|
4
|
-
import React
|
|
4
|
+
import React from "react";
|
|
5
5
|
import { CircleMarker } from "react-leaflet";
|
|
6
6
|
import { action } from "@storybook/addon-actions";
|
|
7
7
|
import { boolean } from "@storybook/addon-knobs";
|
|
@@ -11,7 +11,6 @@ import bikeRentalStations from "../__mocks__/bike-rental-stations.json";
|
|
|
11
11
|
import carRentalStations from "../__mocks__/car-rental-stations.json";
|
|
12
12
|
import eScooterStations from "../__mocks__/e-scooter-rental-stations.json";
|
|
13
13
|
import { HubAndFloatingBike } from "./DefaultMarkers";
|
|
14
|
-
import LeafletLayerControlInterface from "./leaflet-layer-control-interface";
|
|
15
14
|
|
|
16
15
|
import "../../../node_modules/leaflet/dist/leaflet.css";
|
|
17
16
|
|
|
@@ -165,51 +164,32 @@ const EScooterMapSymbols = [
|
|
|
165
164
|
];
|
|
166
165
|
const setLocation = action("setLocation");
|
|
167
166
|
|
|
168
|
-
|
|
169
|
-
constructor() {
|
|
170
|
-
super();
|
|
171
|
-
this.state = { zoom: 13 };
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
onViewportChanged = ({ zoom }) => {
|
|
175
|
-
const { zoom: stateZoom } = this.state;
|
|
176
|
-
if (zoom !== stateZoom) {
|
|
177
|
-
this.setState({ zoom });
|
|
178
|
-
}
|
|
179
|
-
};
|
|
167
|
+
const INITIAL_ZOOM = 13;
|
|
180
168
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
stations={stations}
|
|
206
|
-
visible={visible}
|
|
207
|
-
zoom={zoom}
|
|
208
|
-
/>
|
|
209
|
-
</BaseMap>
|
|
210
|
-
);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
169
|
+
const ZoomControlledMapWithVehicleRentalOverlay = ({
|
|
170
|
+
companies,
|
|
171
|
+
getStationName,
|
|
172
|
+
mapSymbols,
|
|
173
|
+
refreshVehicles,
|
|
174
|
+
stations,
|
|
175
|
+
visible
|
|
176
|
+
}) => (
|
|
177
|
+
// Caution, <BaseMap> must be a direct parent of <VehicleRentalOverlay>.
|
|
178
|
+
// Therefore, do not place <BaseMap> in a decorator at this time.
|
|
179
|
+
<BaseMap center={center} zoom={INITIAL_ZOOM}>
|
|
180
|
+
<VehicleRentalOverlay
|
|
181
|
+
configCompanies={configCompanies}
|
|
182
|
+
companies={companies}
|
|
183
|
+
getStationName={getStationName}
|
|
184
|
+
setLocation={setLocation}
|
|
185
|
+
mapSymbols={mapSymbols}
|
|
186
|
+
name="Rentals"
|
|
187
|
+
refreshVehicles={refreshVehicles}
|
|
188
|
+
stations={stations}
|
|
189
|
+
visible={visible}
|
|
190
|
+
/>
|
|
191
|
+
</BaseMap>
|
|
192
|
+
);
|
|
213
193
|
|
|
214
194
|
ZoomControlledMapWithVehicleRentalOverlay.propTypes = {
|
|
215
195
|
companies: PropTypes.arrayOf(PropTypes.string.isRequired),
|
|
@@ -225,7 +205,7 @@ ZoomControlledMapWithVehicleRentalOverlay.defaultProps = {
|
|
|
225
205
|
companies: null,
|
|
226
206
|
getStationName: undefined,
|
|
227
207
|
mapSymbols: null,
|
|
228
|
-
visible:
|
|
208
|
+
visible: true
|
|
229
209
|
};
|
|
230
210
|
|
|
231
211
|
function customStationName(_, station) {
|
|
@@ -249,7 +229,7 @@ export const RentalBicycles = () => (
|
|
|
249
229
|
export const RentalBicyclesVisibilityControlledByKnob = () => {
|
|
250
230
|
const isOverlayVisible = boolean(
|
|
251
231
|
"Toggle visibility of vehicle rental overlay",
|
|
252
|
-
|
|
232
|
+
false
|
|
253
233
|
);
|
|
254
234
|
return (
|
|
255
235
|
<ZoomControlledMapWithVehicleRentalOverlay
|
package/src/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import flatten from "flat";
|
|
1
2
|
import { Styled as BaseMapStyled } from "@opentripplanner/base-map";
|
|
2
3
|
import coreUtils from "@opentripplanner/core-utils";
|
|
3
4
|
import FromToLocationPicker from "@opentripplanner/from-to-location-picker";
|
|
4
5
|
import ZoomBasedMarkers from "@opentripplanner/zoom-based-markers";
|
|
5
6
|
import PropTypes from "prop-types";
|
|
6
7
|
import React from "react";
|
|
8
|
+
import { FormattedMessage } from "react-intl";
|
|
7
9
|
import { FeatureGroup, MapLayer, Popup, withLeaflet } from "react-leaflet";
|
|
8
10
|
|
|
9
11
|
import {
|
|
@@ -12,12 +14,28 @@ import {
|
|
|
12
14
|
SharedBikeCircle
|
|
13
15
|
} from "./DefaultMarkers";
|
|
14
16
|
|
|
17
|
+
// Load the default messages.
|
|
18
|
+
import defaultEnglishMessages from "../i18n/en-US.yml";
|
|
19
|
+
|
|
20
|
+
// HACK: We should flatten the messages loaded above because
|
|
21
|
+
// the YAML loaders behave differently between webpack and our version of jest:
|
|
22
|
+
// - the yaml loader for webpack returns a nested object,
|
|
23
|
+
// - the yaml loader for jest returns messages with flattened ids.
|
|
24
|
+
const defaultMessages = flatten(defaultEnglishMessages);
|
|
25
|
+
|
|
15
26
|
/**
|
|
16
27
|
* This vehicle rental overlay can be used to render vehicle rentals of various
|
|
17
28
|
* types. This layer can be configured to show different styles of markers at
|
|
18
29
|
* different zoom levels.
|
|
19
30
|
*/
|
|
20
31
|
class VehicleRentalOverlay extends MapLayer {
|
|
32
|
+
constructor(props) {
|
|
33
|
+
super(props);
|
|
34
|
+
this.state = {
|
|
35
|
+
zoom: null
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
21
39
|
/**
|
|
22
40
|
* This helper method will be passed to the ZoomBasedMarkers symbolTransform prop.
|
|
23
41
|
* It creates a component that inserts a popup
|
|
@@ -92,23 +110,53 @@ class VehicleRentalOverlay extends MapLayer {
|
|
|
92
110
|
if (this.refreshTimer) clearInterval(this.refreshTimer);
|
|
93
111
|
}
|
|
94
112
|
|
|
113
|
+
/**
|
|
114
|
+
* When the layer is added (or toggled on, or its visibility becomes true),
|
|
115
|
+
* start refreshing vehicle positions.
|
|
116
|
+
*/
|
|
117
|
+
onOverlayAdded = () => {
|
|
118
|
+
this.startRefreshing();
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* When the layer is removed (or toggled off, or its visibility becomes false),
|
|
123
|
+
* stop refreshing vehicle positions.
|
|
124
|
+
*/
|
|
125
|
+
onOverlayRemoved = () => {
|
|
126
|
+
this.stopRefreshing();
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Listen to changes on the BaseMap's center or zoom.
|
|
131
|
+
* @param viewport The viewport data. See https://github.com/PaulLeCam/react-leaflet/blob/master/example/components/viewport.js for details.
|
|
132
|
+
*/
|
|
133
|
+
onViewportChanged = viewport => {
|
|
134
|
+
const { zoom: newZoom } = viewport;
|
|
135
|
+
if (this.state.zoom !== newZoom) {
|
|
136
|
+
this.setState({ zoom: newZoom });
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Upon mounting, see whether the vehicles should be fetched,
|
|
142
|
+
* and also call the register overlay prop that the
|
|
143
|
+
* @opentripplanner/base-map package has injected to listen to zoom/position changes.
|
|
144
|
+
*/
|
|
95
145
|
componentDidMount() {
|
|
96
|
-
const { visible } = this.props;
|
|
146
|
+
const { leaflet, registerOverlay, visible } = this.props;
|
|
147
|
+
this.setState({
|
|
148
|
+
zoom: leaflet.map.getZoom()
|
|
149
|
+
});
|
|
97
150
|
if (visible) this.startRefreshing();
|
|
151
|
+
if (typeof registerOverlay === "function") {
|
|
152
|
+
registerOverlay(this);
|
|
153
|
+
}
|
|
98
154
|
}
|
|
99
155
|
|
|
100
156
|
componentWillUnmount() {
|
|
101
157
|
this.stopRefreshing();
|
|
102
158
|
}
|
|
103
159
|
|
|
104
|
-
componentDidUpdate(prevProps) {
|
|
105
|
-
if (!prevProps.visible && this.props.visible) {
|
|
106
|
-
this.startRefreshing();
|
|
107
|
-
} else if (prevProps.visible && !this.props.visible) {
|
|
108
|
-
this.stopRefreshing();
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
160
|
/**
|
|
113
161
|
* Render some popup html for a station. This contains custom logic for
|
|
114
162
|
* displaying rental vehicles in the TriMet MOD website that might not be
|
|
@@ -130,15 +178,33 @@ class VehicleRentalOverlay extends MapLayer {
|
|
|
130
178
|
{/* render dock info if it is available */}
|
|
131
179
|
{stationIsHub && (
|
|
132
180
|
<BaseMapStyled.PopupRow>
|
|
133
|
-
<div>
|
|
134
|
-
|
|
181
|
+
<div>
|
|
182
|
+
<FormattedMessage
|
|
183
|
+
defaultMessage={
|
|
184
|
+
defaultMessages["otpUi.VehicleRentalOverlay.availableBikes"]
|
|
185
|
+
}
|
|
186
|
+
description="Label text for the number of bikes available"
|
|
187
|
+
id="otpUi.VehicleRentalOverlay.availableBikes"
|
|
188
|
+
values={{ value: station.bikesAvailable }}
|
|
189
|
+
/>
|
|
190
|
+
</div>
|
|
191
|
+
<div>
|
|
192
|
+
<FormattedMessage
|
|
193
|
+
defaultMessage={
|
|
194
|
+
defaultMessages["otpUi.VehicleRentalOverlay.availableDocks"]
|
|
195
|
+
}
|
|
196
|
+
description="Label text for the number of docks available"
|
|
197
|
+
id="otpUi.VehicleRentalOverlay.availableDocks"
|
|
198
|
+
values={{ value: station.spacesAvailable }}
|
|
199
|
+
/>
|
|
200
|
+
</div>
|
|
135
201
|
</BaseMapStyled.PopupRow>
|
|
136
202
|
)}
|
|
137
203
|
|
|
138
204
|
{/* Set as from/to toolbar */}
|
|
139
205
|
<BaseMapStyled.PopupRow>
|
|
140
|
-
<b>Plan a trip:</b>
|
|
141
206
|
<FromToLocationPicker
|
|
207
|
+
label
|
|
142
208
|
location={location}
|
|
143
209
|
setLocation={setLocation}
|
|
144
210
|
/>
|
|
@@ -149,14 +215,12 @@ class VehicleRentalOverlay extends MapLayer {
|
|
|
149
215
|
};
|
|
150
216
|
|
|
151
217
|
render() {
|
|
152
|
-
const { companies, mapSymbols, stations
|
|
218
|
+
const { companies, leaflet, mapSymbols, stations } = this.props;
|
|
219
|
+
const { zoom = leaflet.map.getZoom() } = this.state;
|
|
153
220
|
// Render an empty FeatureGroup if the rental vehicles should not be visible
|
|
154
221
|
// on the map. Otherwise previous stations may still be shown due to some
|
|
155
222
|
// react-leaflet internals, maybe? Also, do not return null because that will
|
|
156
223
|
// prevent the overlay from appearing in the layer controls.
|
|
157
|
-
if (!visible) {
|
|
158
|
-
return <FeatureGroup />;
|
|
159
|
-
}
|
|
160
224
|
|
|
161
225
|
let filteredStations = stations;
|
|
162
226
|
if (companies) {
|
|
@@ -170,9 +234,6 @@ class VehicleRentalOverlay extends MapLayer {
|
|
|
170
234
|
return <FeatureGroup />;
|
|
171
235
|
}
|
|
172
236
|
|
|
173
|
-
// get zoom to check which symbol to render
|
|
174
|
-
const zoom = this.props.leaflet.map.getZoom();
|
|
175
|
-
|
|
176
237
|
// Convert map symbols for this overlay to zoomBasedSymbolType.
|
|
177
238
|
const symbols = this.convertToZoomMarkerSymbols(mapSymbols);
|
|
178
239
|
|
|
@@ -1,90 +0,0 @@
|
|
|
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 React, { Component } from "react";
|
|
13
|
-
import VehicleRentalOverlay from ".";
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* This class is a necessary intermediary to handle events proxied from the
|
|
17
|
-
* parent @opentripplanner/base-map component handlers to this component.
|
|
18
|
-
* Without this interface, there would be no way to detect when a user would
|
|
19
|
-
* hide this layer from view on the Leaflet map. The visible property influences
|
|
20
|
-
* and sets the Leaflet Layer Control which then is handled by the
|
|
21
|
-
* @opentripplanner/base-map component and then delivered to the
|
|
22
|
-
* `onOverlayAdded` and `onOverlayRemoved` handlers which then finally set this
|
|
23
|
-
* component's state which is then finally used by the vehicle rental overlay
|
|
24
|
-
* to properly manage the requesting of vehicle rentals.
|
|
25
|
-
*/
|
|
26
|
-
var LeafletLayerControlInterface = /*#__PURE__*/function (_Component) {
|
|
27
|
-
_inherits(LeafletLayerControlInterface, _Component);
|
|
28
|
-
|
|
29
|
-
var _super = _createSuper(LeafletLayerControlInterface);
|
|
30
|
-
|
|
31
|
-
function LeafletLayerControlInterface(props) {
|
|
32
|
-
var _this;
|
|
33
|
-
|
|
34
|
-
_classCallCheck(this, LeafletLayerControlInterface);
|
|
35
|
-
|
|
36
|
-
_this = _super.call(this, props);
|
|
37
|
-
|
|
38
|
-
_this.onOverlayAdded = function () {
|
|
39
|
-
_this.setState({
|
|
40
|
-
visible: true
|
|
41
|
-
});
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
_this.onOverlayRemoved = function () {
|
|
45
|
-
_this.setState({
|
|
46
|
-
visible: false
|
|
47
|
-
});
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
_this.state = {
|
|
51
|
-
visible: props.visible
|
|
52
|
-
};
|
|
53
|
-
return _this;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Upon mounting, this class calls the register overlay property that the
|
|
57
|
-
* @opentripplanner/base-map package has injected into the props.
|
|
58
|
-
*/
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
_createClass(LeafletLayerControlInterface, [{
|
|
62
|
-
key: "componentDidMount",
|
|
63
|
-
value: function componentDidMount() {
|
|
64
|
-
var registerOverlay = this.props.registerOverlay;
|
|
65
|
-
registerOverlay(this);
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* A handler function for when this layer is toggled on by the user via the
|
|
69
|
-
* leaflet layer control.
|
|
70
|
-
*/
|
|
71
|
-
|
|
72
|
-
}, {
|
|
73
|
-
key: "render",
|
|
74
|
-
value: function render() {
|
|
75
|
-
var visible = this.state.visible;
|
|
76
|
-
return (
|
|
77
|
-
/*#__PURE__*/
|
|
78
|
-
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
79
|
-
React.createElement(VehicleRentalOverlay, _extends({}, this.props, {
|
|
80
|
-
visible: visible
|
|
81
|
-
}))
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
}]);
|
|
85
|
-
|
|
86
|
-
return LeafletLayerControlInterface;
|
|
87
|
-
}(Component);
|
|
88
|
-
|
|
89
|
-
export { LeafletLayerControlInterface as default };
|
|
90
|
-
//# sourceMappingURL=leaflet-layer-control-interface.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/leaflet-layer-control-interface.tsx"],"names":["React","Component","VehicleRentalOverlay","LeafletLayerControlInterface","props","onOverlayAdded","setState","visible","onOverlayRemoved","state","registerOverlay"],"mappings":";;;;;;;;;;;AAAA,OAAOA,KAAP,IAAgBC,SAAhB,QAAiC,OAAjC;AAEA,OAAOC,oBAAP,MAAiC,GAAjC;;AA0BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;IACqBC,4B;;;;;AAInB,wCAAYC,KAAZ,EAA0B;AAAA;;AAAA;;AACxB,8BAAMA,KAAN;;AADwB,UAkB1BC,cAlB0B,GAkBT,YAAM;AACrB,YAAKC,QAAL,CAAc;AAAEC,QAAAA,OAAO,EAAE;AAAX,OAAd;AACD,KApByB;;AAAA,UA0B1BC,gBA1B0B,GA0BP,YAAM;AACvB,YAAKF,QAAL,CAAc;AAAEC,QAAAA,OAAO,EAAE;AAAX,OAAd;AACD,KA5ByB;;AAExB,UAAKE,KAAL,GAAa;AAAEF,MAAAA,OAAO,EAAEH,KAAK,CAACG;AAAjB,KAAb;AAFwB;AAGzB;AAED;AACF;AACA;AACA;;;;;WACE,6BAAoB;AAClB,UAAQG,eAAR,GAA4B,KAAKN,KAAjC,CAAQM,eAAR;AACAA,MAAAA,eAAe,CAAC,IAAD,CAAf;AACD;AAED;AACF;AACA;AACA;;;;WAaE,kBAAS;AACP,UAAQH,OAAR,GAAoB,KAAKE,KAAzB,CAAQF,OAAR;AACA;AAAA;AACE;AACA,4BAAC,oBAAD,eAA0B,KAAKH,KAA/B;AAAsC,UAAA,OAAO,EAAEG;AAA/C;AAFF;AAID;;;;EAxCuDN,S;;SAArCE,4B","sourcesContent":["import React, { Component } from \"react\";\n\nimport VehicleRentalOverlay from \".\";\n\ntype Props = {\n /**\n * This method is created by the @opentripplanner/base-map package when\n * mounting user-defined layers. This will allow the component to subscribe to\n * various leaflet events that then get forwarded on to this component.\n */\n registerOverlay: (component: Component) => void;\n /**\n * Whether or not to initially display the rental vehicles. Once the component\n * is mounted the subscribed events of a user toggling on or off the layer via\n * the layer control item will subsequently control the display of the\n * component.\n */\n visible?: boolean;\n};\n\ntype State = {\n /**\n * An internal state variable used to determine whether or not to display the\n * rental vehicles for this layer.\n */\n visible: boolean;\n};\n\n/**\n * This class is a necessary intermediary to handle events proxied from the\n * parent @opentripplanner/base-map component handlers to this component.\n * Without this interface, there would be no way to detect when a user would\n * hide this layer from view on the Leaflet map. The visible property influences\n * and sets the Leaflet Layer Control which then is handled by the\n * @opentripplanner/base-map component and then delivered to the\n * `onOverlayAdded` and `onOverlayRemoved` handlers which then finally set this\n * component's state which is then finally used by the vehicle rental overlay\n * to properly manage the requesting of vehicle rentals.\n */\nexport default class LeafletLayerControlInterface extends Component<\n Props,\n State\n> {\n constructor(props: Props) {\n super(props);\n this.state = { visible: props.visible };\n }\n\n /**\n * Upon mounting, this class calls the register overlay property that the\n * @opentripplanner/base-map package has injected into the props.\n */\n componentDidMount() {\n const { registerOverlay } = this.props;\n registerOverlay(this);\n }\n\n /**\n * A handler function for when this layer is toggled on by the user via the\n * leaflet layer control.\n */\n onOverlayAdded = () => {\n this.setState({ visible: true });\n };\n\n /**\n * A handler function for when this layer is toggled off by the user via the\n * leaflet layer control.\n */\n onOverlayRemoved = () => {\n this.setState({ visible: false });\n };\n\n render() {\n const { visible } = this.state;\n return (\n // eslint-disable-next-line react/jsx-props-no-spreading\n <VehicleRentalOverlay {...this.props} visible={visible} />\n );\n }\n}\n"],"file":"leaflet-layer-control-interface.js"}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.default = void 0;
|
|
9
|
-
|
|
10
|
-
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
11
|
-
|
|
12
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
13
|
-
|
|
14
|
-
var _ = _interopRequireDefault(require("."));
|
|
15
|
-
|
|
16
|
-
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); }
|
|
17
|
-
|
|
18
|
-
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; }
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* This class is a necessary intermediary to handle events proxied from the
|
|
22
|
-
* parent @opentripplanner/base-map component handlers to this component.
|
|
23
|
-
* Without this interface, there would be no way to detect when a user would
|
|
24
|
-
* hide this layer from view on the Leaflet map. The visible property influences
|
|
25
|
-
* and sets the Leaflet Layer Control which then is handled by the
|
|
26
|
-
* @opentripplanner/base-map component and then delivered to the
|
|
27
|
-
* `onOverlayAdded` and `onOverlayRemoved` handlers which then finally set this
|
|
28
|
-
* component's state which is then finally used by the vehicle rental overlay
|
|
29
|
-
* to properly manage the requesting of vehicle rentals.
|
|
30
|
-
*/
|
|
31
|
-
class LeafletLayerControlInterface extends _react.Component {
|
|
32
|
-
constructor(props) {
|
|
33
|
-
super(props);
|
|
34
|
-
|
|
35
|
-
this.onOverlayAdded = () => {
|
|
36
|
-
this.setState({
|
|
37
|
-
visible: true
|
|
38
|
-
});
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
this.onOverlayRemoved = () => {
|
|
42
|
-
this.setState({
|
|
43
|
-
visible: false
|
|
44
|
-
});
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
this.state = {
|
|
48
|
-
visible: props.visible
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Upon mounting, this class calls the register overlay property that the
|
|
53
|
-
* @opentripplanner/base-map package has injected into the props.
|
|
54
|
-
*/
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
componentDidMount() {
|
|
58
|
-
const {
|
|
59
|
-
registerOverlay
|
|
60
|
-
} = this.props;
|
|
61
|
-
registerOverlay(this);
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* A handler function for when this layer is toggled on by the user via the
|
|
65
|
-
* leaflet layer control.
|
|
66
|
-
*/
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
render() {
|
|
70
|
-
const {
|
|
71
|
-
visible
|
|
72
|
-
} = this.state;
|
|
73
|
-
return (
|
|
74
|
-
/*#__PURE__*/
|
|
75
|
-
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
76
|
-
_react.default.createElement(_.default, (0, _extends2.default)({}, this.props, {
|
|
77
|
-
visible: visible
|
|
78
|
-
}))
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
exports.default = LeafletLayerControlInterface;
|
|
85
|
-
//# sourceMappingURL=leaflet-layer-control-interface.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/leaflet-layer-control-interface.tsx"],"names":["LeafletLayerControlInterface","Component","constructor","props","onOverlayAdded","setState","visible","onOverlayRemoved","state","componentDidMount","registerOverlay","render"],"mappings":";;;;;;;;;;;AAAA;;AAEA;;;;;;AA0BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,MAAMA,4BAAN,SAA2CC,gBAA3C,CAGb;AACAC,EAAAA,WAAW,CAACC,KAAD,EAAe;AACxB,UAAMA,KAAN;;AADwB,SAkB1BC,cAlB0B,GAkBT,MAAM;AACrB,WAAKC,QAAL,CAAc;AAAEC,QAAAA,OAAO,EAAE;AAAX,OAAd;AACD,KApByB;;AAAA,SA0B1BC,gBA1B0B,GA0BP,MAAM;AACvB,WAAKF,QAAL,CAAc;AAAEC,QAAAA,OAAO,EAAE;AAAX,OAAd;AACD,KA5ByB;;AAExB,SAAKE,KAAL,GAAa;AAAEF,MAAAA,OAAO,EAAEH,KAAK,CAACG;AAAjB,KAAb;AACD;AAED;AACF;AACA;AACA;;;AACEG,EAAAA,iBAAiB,GAAG;AAClB,UAAM;AAAEC,MAAAA;AAAF,QAAsB,KAAKP,KAAjC;AACAO,IAAAA,eAAe,CAAC,IAAD,CAAf;AACD;AAED;AACF;AACA;AACA;;;AAaEC,EAAAA,MAAM,GAAG;AACP,UAAM;AAAEL,MAAAA;AAAF,QAAc,KAAKE,KAAzB;AACA;AAAA;AACE;AACA,mCAAC,SAAD,6BAA0B,KAAKL,KAA/B;AAAsC,QAAA,OAAO,EAAEG;AAA/C;AAFF;AAID;;AArCD","sourcesContent":["import React, { Component } from \"react\";\n\nimport VehicleRentalOverlay from \".\";\n\ntype Props = {\n /**\n * This method is created by the @opentripplanner/base-map package when\n * mounting user-defined layers. This will allow the component to subscribe to\n * various leaflet events that then get forwarded on to this component.\n */\n registerOverlay: (component: Component) => void;\n /**\n * Whether or not to initially display the rental vehicles. Once the component\n * is mounted the subscribed events of a user toggling on or off the layer via\n * the layer control item will subsequently control the display of the\n * component.\n */\n visible?: boolean;\n};\n\ntype State = {\n /**\n * An internal state variable used to determine whether or not to display the\n * rental vehicles for this layer.\n */\n visible: boolean;\n};\n\n/**\n * This class is a necessary intermediary to handle events proxied from the\n * parent @opentripplanner/base-map component handlers to this component.\n * Without this interface, there would be no way to detect when a user would\n * hide this layer from view on the Leaflet map. The visible property influences\n * and sets the Leaflet Layer Control which then is handled by the\n * @opentripplanner/base-map component and then delivered to the\n * `onOverlayAdded` and `onOverlayRemoved` handlers which then finally set this\n * component's state which is then finally used by the vehicle rental overlay\n * to properly manage the requesting of vehicle rentals.\n */\nexport default class LeafletLayerControlInterface extends Component<\n Props,\n State\n> {\n constructor(props: Props) {\n super(props);\n this.state = { visible: props.visible };\n }\n\n /**\n * Upon mounting, this class calls the register overlay property that the\n * @opentripplanner/base-map package has injected into the props.\n */\n componentDidMount() {\n const { registerOverlay } = this.props;\n registerOverlay(this);\n }\n\n /**\n * A handler function for when this layer is toggled on by the user via the\n * leaflet layer control.\n */\n onOverlayAdded = () => {\n this.setState({ visible: true });\n };\n\n /**\n * A handler function for when this layer is toggled off by the user via the\n * leaflet layer control.\n */\n onOverlayRemoved = () => {\n this.setState({ visible: false });\n };\n\n render() {\n const { visible } = this.state;\n return (\n // eslint-disable-next-line react/jsx-props-no-spreading\n <VehicleRentalOverlay {...this.props} visible={visible} />\n );\n }\n}\n"],"file":"leaflet-layer-control-interface.js"}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import React, { Component } from "react";
|
|
2
|
-
|
|
3
|
-
import VehicleRentalOverlay from ".";
|
|
4
|
-
|
|
5
|
-
type Props = {
|
|
6
|
-
/**
|
|
7
|
-
* This method is created by the @opentripplanner/base-map package when
|
|
8
|
-
* mounting user-defined layers. This will allow the component to subscribe to
|
|
9
|
-
* various leaflet events that then get forwarded on to this component.
|
|
10
|
-
*/
|
|
11
|
-
registerOverlay: (component: Component) => void;
|
|
12
|
-
/**
|
|
13
|
-
* Whether or not to initially display the rental vehicles. Once the component
|
|
14
|
-
* is mounted the subscribed events of a user toggling on or off the layer via
|
|
15
|
-
* the layer control item will subsequently control the display of the
|
|
16
|
-
* component.
|
|
17
|
-
*/
|
|
18
|
-
visible?: boolean;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
type State = {
|
|
22
|
-
/**
|
|
23
|
-
* An internal state variable used to determine whether or not to display the
|
|
24
|
-
* rental vehicles for this layer.
|
|
25
|
-
*/
|
|
26
|
-
visible: boolean;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* This class is a necessary intermediary to handle events proxied from the
|
|
31
|
-
* parent @opentripplanner/base-map component handlers to this component.
|
|
32
|
-
* Without this interface, there would be no way to detect when a user would
|
|
33
|
-
* hide this layer from view on the Leaflet map. The visible property influences
|
|
34
|
-
* and sets the Leaflet Layer Control which then is handled by the
|
|
35
|
-
* @opentripplanner/base-map component and then delivered to the
|
|
36
|
-
* `onOverlayAdded` and `onOverlayRemoved` handlers which then finally set this
|
|
37
|
-
* component's state which is then finally used by the vehicle rental overlay
|
|
38
|
-
* to properly manage the requesting of vehicle rentals.
|
|
39
|
-
*/
|
|
40
|
-
export default class LeafletLayerControlInterface extends Component<
|
|
41
|
-
Props,
|
|
42
|
-
State
|
|
43
|
-
> {
|
|
44
|
-
constructor(props: Props) {
|
|
45
|
-
super(props);
|
|
46
|
-
this.state = { visible: props.visible };
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Upon mounting, this class calls the register overlay property that the
|
|
51
|
-
* @opentripplanner/base-map package has injected into the props.
|
|
52
|
-
*/
|
|
53
|
-
componentDidMount() {
|
|
54
|
-
const { registerOverlay } = this.props;
|
|
55
|
-
registerOverlay(this);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* A handler function for when this layer is toggled on by the user via the
|
|
60
|
-
* leaflet layer control.
|
|
61
|
-
*/
|
|
62
|
-
onOverlayAdded = () => {
|
|
63
|
-
this.setState({ visible: true });
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* A handler function for when this layer is toggled off by the user via the
|
|
68
|
-
* leaflet layer control.
|
|
69
|
-
*/
|
|
70
|
-
onOverlayRemoved = () => {
|
|
71
|
-
this.setState({ visible: false });
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
render() {
|
|
75
|
-
const { visible } = this.state;
|
|
76
|
-
return (
|
|
77
|
-
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
78
|
-
<VehicleRentalOverlay {...this.props} visible={visible} />
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
}
|