@opentripplanner/vehicle-rental-overlay 5.0.0 → 6.0.0

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/README.md CHANGED
@@ -1,6 +1,5 @@
1
- ## Usage
1
+ # Vehicle Rental Overlay
2
2
 
3
- ```
3
+ ## Upgrade to OTP2 types
4
4
 
5
- TBD
6
- ```
5
+ Version 5.0.1 is the final version to support OTP1 types for the `stations` prop of `VehicleRentalOverlay`. Starting with version 6.0.0, the `stations` prop will be replaced with `entities`, with a type of `VehicleRentalStation[]`. This updated type can be found in the `@opentripplanner/types/otp2` package.
package/esm/index.js CHANGED
@@ -10,11 +10,16 @@ import { BaseBikeRentalIcon, StationMarker } from "./styled";
10
10
 
11
11
  // TODO: Make configurable?
12
12
  var DETAILED_MARKER_CUTOFF = 16;
13
- var getColorForStation = function getColorForStation(v) {
14
- if (v.isFloatingCar) return "#009cde";
15
- if (v.isFloatingVehicle) return "#f5a729";
16
- // TODO: nicer color to match transitive
17
- if (v.bikesAvailable !== undefined || v.isFloatingBike) return "#f00";
13
+ function entityIsStation(entity) {
14
+ return "availableVehicles" in entity;
15
+ }
16
+ var getColorForEntity = function getColorForEntity(entity) {
17
+ if (entityIsStation(entity)) {
18
+ if (entity.availableVehicles && entity.availableVehicles.total > 0) return "#f00";
19
+ } else {
20
+ if (entity.vehicleType.formFactor.startsWith("SCOOTER")) return "#f5a729";
21
+ if (entity.vehicleType.formFactor === "BICYCLE") return "#009cde";
22
+ }
18
23
  return "gray";
19
24
  };
20
25
  /**
@@ -25,11 +30,11 @@ var getColorForStation = function getColorForStation(v) {
25
30
  var VehicleRentalOverlay = function VehicleRentalOverlay(_ref) {
26
31
  var companies = _ref.companies,
27
32
  configCompanies = _ref.configCompanies,
33
+ entities = _ref.entities,
28
34
  getStationName = _ref.getStationName,
29
35
  id = _ref.id,
30
36
  refreshVehicles = _ref.refreshVehicles,
31
37
  _setLocation = _ref.setLocation,
32
- stations = _ref.stations,
33
38
  visible = _ref.visible;
34
39
  var _useMap = useMap(),
35
40
  map = _useMap.current;
@@ -38,7 +43,7 @@ var VehicleRentalOverlay = function VehicleRentalOverlay(_ref) {
38
43
  zoom = _useState2[0],
39
44
  setZoom = _useState2[1];
40
45
  var layerId = "rental-vehicles-".concat(id);
41
- var _useState3 = useState(null),
46
+ var _useState3 = useState(),
42
47
  _useState4 = _slicedToArray(_useState3, 2),
43
48
  clickedVehicle = _useState4[0],
44
49
  setClickedVehicle = _useState4[1];
@@ -51,51 +56,66 @@ var VehicleRentalOverlay = function VehicleRentalOverlay(_ref) {
51
56
  setInterval(refreshVehicles, 30000);
52
57
  }, [refreshVehicles]);
53
58
  useEffect(function () {
54
- var VEHICLE_LAYERS = [layerId];
55
- VEHICLE_LAYERS.forEach(function (stopLayer) {
56
- map === null || map === void 0 || map.on("mouseenter", stopLayer, function () {
57
- map.getCanvas().style.cursor = "pointer";
58
- });
59
- map === null || map === void 0 || map.on("mouseleave", stopLayer, function () {
60
- map.getCanvas().style.cursor = "";
61
- });
62
- map === null || map === void 0 || map.on("click", stopLayer, function (event) {
63
- var _event$features;
64
- setClickedVehicle((_event$features = event.features) === null || _event$features === void 0 ? void 0 : _event$features[0].properties);
65
- });
66
- });
67
- map.on("zoom", function (e) {
59
+ var mouseEnterFunc = function mouseEnterFunc() {
60
+ map.getCanvas().style.cursor = "pointer";
61
+ };
62
+ var mouseLeaveFunc = function mouseLeaveFunc() {
63
+ map.getCanvas().style.cursor = "";
64
+ };
65
+ var clickFunc = function clickFunc(event) {
66
+ var _event$features;
67
+ var p = (_event$features = event.features) === null || _event$features === void 0 ? void 0 : _event$features[0].properties;
68
+ setClickedVehicle(_objectSpread(_objectSpread({}, p), {}, {
69
+ // the properties field of the GeoJSON Feature object serializes these
70
+ // two objects into JSON strings, so we need to parse them back into objects
71
+ availableSpaces: JSON.parse(p === null || p === void 0 ? void 0 : p.availableSpaces),
72
+ availableVehicles: JSON.parse(p === null || p === void 0 ? void 0 : p.availableVehicles)
73
+ }));
74
+ };
75
+ var zoomFunc = function zoomFunc(e) {
68
76
  // Avoid too many re-renders by only updating state if we are a whole number value different
69
77
  var newZoom = e.viewState.zoom;
70
78
  if (Math.floor(zoom / 2) !== Math.floor(newZoom / 2)) {
71
79
  setZoom(newZoom);
72
80
  }
73
- });
81
+ };
82
+ map === null || map === void 0 || map.on("mouseenter", layerId, mouseEnterFunc);
83
+ map === null || map === void 0 || map.on("mouseleave", layerId, mouseLeaveFunc);
84
+ map === null || map === void 0 || map.on("click", layerId, clickFunc);
85
+ map === null || map === void 0 || map.on("zoom", zoomFunc);
86
+ return function () {
87
+ map === null || map === void 0 || map.off("mouseenter", layerId, mouseEnterFunc);
88
+ map === null || map === void 0 || map.off("mouseleave", layerId, mouseLeaveFunc);
89
+ map === null || map === void 0 || map.off("click", layerId, clickFunc);
90
+ map === null || map === void 0 || map.off("zoom", zoomFunc);
91
+ };
74
92
  }, [map]);
75
93
 
76
94
  // Don't render if no map or no stops are defined.
77
- if (visible === false || !stations || stations.length === 0) {
95
+ if (visible === false || !entities || entities.length === 0) {
78
96
  // Null can't be returned here -- react-map-gl dislikes null values as children
79
97
  return /*#__PURE__*/React.createElement(React.Fragment, null);
80
98
  }
81
99
  var vehiclesGeoJSON = {
82
100
  type: "FeatureCollection",
83
- features: stations.filter(function (vehicle) {
101
+ features: entities.filter(function (entity) {
102
+ return !!entity;
103
+ }).filter(function (entity) {
84
104
  return (
85
105
  // Include specified companies only if companies is specified and network info is available
86
- !companies || !vehicle.networks || companies.includes(vehicle.networks[0])
106
+ !companies || !entity.rentalNetwork.networkId || companies.includes(entity.rentalNetwork.networkId)
87
107
  );
88
- }).map(function (vehicle) {
108
+ }).map(function (entity) {
89
109
  return {
90
110
  type: "Feature",
91
111
  geometry: {
92
112
  type: "Point",
93
- coordinates: [vehicle.x, vehicle.y]
113
+ coordinates: [entity.lon, entity.lat]
94
114
  },
95
- properties: _objectSpread(_objectSpread({}, vehicle), {}, {
96
- networks: JSON.stringify(vehicle.networks),
97
- "stroke-width": vehicle.isFloatingBike || vehicle.isFloatingVehicle ? 1 : 2,
98
- color: getColorForStation(vehicle)
115
+ properties: _objectSpread(_objectSpread({}, entity), {}, {
116
+ networks: entity.rentalNetwork.networkId,
117
+ "stroke-width": entityIsStation(entity) ? 1 : 2,
118
+ color: getColorForEntity(entity)
99
119
  })
100
120
  };
101
121
  })
@@ -112,13 +132,15 @@ var VehicleRentalOverlay = function VehicleRentalOverlay(_ref) {
112
132
  "circle-stroke-width": ["get", "stroke-width"]
113
133
  },
114
134
  type: "circle"
115
- })), zoom >= DETAILED_MARKER_CUTOFF && stations.map(function (station) {
135
+ })), zoom >= DETAILED_MARKER_CUTOFF && entities.filter(function (entity) {
136
+ return !!entity;
137
+ }).map(function (entity) {
116
138
  return /*#__PURE__*/React.createElement(MarkerWithPopup, {
117
- key: station.id,
139
+ key: entity.id,
118
140
  popupContents: /*#__PURE__*/React.createElement(StationPopup, {
119
141
  configCompanies: configCompanies,
120
142
  setLocation: function setLocation(location) {
121
- setClickedVehicle(null);
143
+ setClickedVehicle(undefined);
122
144
  _setLocation(location);
123
145
  },
124
146
  getEntityName:
@@ -126,21 +148,21 @@ var VehicleRentalOverlay = function VehicleRentalOverlay(_ref) {
126
148
  getStationName && function (s, cc) {
127
149
  return getStationName(cc, s);
128
150
  },
129
- entity: station
151
+ entity: entity
130
152
  }),
131
- position: [station.y, station.x]
132
- }, station.bikesAvailable !== undefined && !station.isFloatingBike && !station.isFloatingVehicle && station.spacesAvailable !== undefined ? /*#__PURE__*/React.createElement(BaseBikeRentalIcon, {
133
- percent: (station === null || station === void 0 ? void 0 : station.bikesAvailable) / ((station === null || station === void 0 ? void 0 : station.bikesAvailable) + (station === null || station === void 0 ? void 0 : station.spacesAvailable))
153
+ position: [entity.lat, entity.lon]
154
+ }, entityIsStation(entity) && entity.availableSpaces !== undefined && entity.availableVehicles !== undefined && entity.availableVehicles.total > 0 ? /*#__PURE__*/React.createElement(BaseBikeRentalIcon, {
155
+ percent: (entity === null || entity === void 0 ? void 0 : entity.availableVehicles.total) / ((entity === null || entity === void 0 ? void 0 : entity.availableVehicles.total) + (entity === null || entity === void 0 ? void 0 : entity.availableSpaces.total))
134
156
  }) : /*#__PURE__*/React.createElement(StationMarker, {
135
157
  width: 12,
136
- color: getColorForStation(station)
158
+ color: getColorForEntity(entity)
137
159
  }));
138
160
  }), clickedVehicle && /*#__PURE__*/React.createElement(Popup, {
139
- latitude: clickedVehicle.y,
140
- longitude: clickedVehicle.x,
161
+ latitude: clickedVehicle.lat,
162
+ longitude: clickedVehicle.lon,
141
163
  maxWidth: "100%",
142
164
  onClose: function onClose() {
143
- setClickedVehicle(null);
165
+ setClickedVehicle(undefined);
144
166
  }
145
167
  }, /*#__PURE__*/React.createElement(StationPopup, {
146
168
  configCompanies: configCompanies,
@@ -150,12 +172,10 @@ var VehicleRentalOverlay = function VehicleRentalOverlay(_ref) {
150
172
  return getStationName(cc, s);
151
173
  },
152
174
  setLocation: function setLocation(location) {
153
- setClickedVehicle(null);
175
+ setClickedVehicle(undefined);
154
176
  _setLocation(location);
155
177
  },
156
- entity: _objectSpread(_objectSpread({}, clickedVehicle), {}, {
157
- networks: JSON.parse(clickedVehicle.networks)
158
- })
178
+ entity: clickedVehicle
159
179
  })));
160
180
  };
161
181
  export default VehicleRentalOverlay;
package/esm/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["MarkerWithPopup","Popup","React","useEffect","useState","Layer","Source","useMap","StationPopup","BaseBikeRentalIcon","StationMarker","DETAILED_MARKER_CUTOFF","getColorForStation","v","isFloatingCar","isFloatingVehicle","bikesAvailable","undefined","isFloatingBike","VehicleRentalOverlay","_ref","companies","configCompanies","getStationName","id","refreshVehicles","setLocation","stations","visible","_useMap","map","current","_useState","getZoom","_useState2","_slicedToArray","zoom","setZoom","layerId","concat","_useState3","_useState4","clickedVehicle","setClickedVehicle","setInterval","VEHICLE_LAYERS","forEach","stopLayer","on","getCanvas","style","cursor","event","_event$features","features","properties","e","newZoom","viewState","Math","floor","length","createElement","Fragment","vehiclesGeoJSON","type","filter","vehicle","networks","includes","geometry","coordinates","x","y","_objectSpread","JSON","stringify","color","data","paint","station","key","popupContents","location","getEntityName","s","cc","entity","position","spacesAvailable","percent","width","latitude","longitude","maxWidth","onClose","parse"],"sources":["../src/index.tsx"],"sourcesContent":["import { MarkerWithPopup, Popup } from \"@opentripplanner/base-map\";\nimport {\n Company,\n ConfiguredCompany,\n MapLocationActionArg,\n Station\n} from \"@opentripplanner/types\";\nimport React, { useEffect, useState } from \"react\";\nimport {\n Layer,\n Source,\n useMap,\n ViewStateChangeEvent\n} from \"react-map-gl/maplibre\";\n\nimport StationPopup from \"@opentripplanner/map-popup\";\nimport { BaseBikeRentalIcon, StationMarker } from \"./styled\";\n\n// TODO: Make configurable?\nconst DETAILED_MARKER_CUTOFF = 16;\n\nconst getColorForStation = (v: Station) => {\n if (v.isFloatingCar) return \"#009cde\";\n if (v.isFloatingVehicle) return \"#f5a729\";\n // TODO: nicer color to match transitive\n if (v.bikesAvailable !== undefined || v.isFloatingBike) return \"#f00\";\n return \"gray\";\n};\n\ntype Props = {\n /**\n * A list of companies that are applicable to just this instance of the\n * overlay.\n */\n companies?: string[];\n /**\n * The entire companies config array.\n */\n configCompanies: ConfiguredCompany[];\n /**\n * An id, used to make this layer uniquely identifiable\n */\n id: string;\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?: (configCompanies: Company[], station: Station) => string;\n /**\n * If specified, a function that will be triggered every 30 seconds whenever this layer is\n * visible.\n */\n refreshVehicles?: () => void;\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?: (arg: MapLocationActionArg) => void;\n /**\n * A list of the vehicle rental stations specific to this overlay instance.\n */\n stations: Station[];\n /**\n * Whether the overlay is currently visible.\n */\n visible?: boolean;\n /**\n * TODO: Add props for overriding symbols?\n */\n};\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 */\nconst VehicleRentalOverlay = ({\n companies,\n configCompanies,\n getStationName,\n id,\n refreshVehicles,\n setLocation,\n stations,\n visible\n}: Props): JSX.Element => {\n const { current: map } = useMap();\n const [zoom, setZoom] = useState(map?.getZoom());\n\n const layerId = `rental-vehicles-${id}`;\n const [clickedVehicle, setClickedVehicle] = useState(null);\n\n useEffect(() => {\n // TODO: Make 30s configurable?\n if (!refreshVehicles || typeof refreshVehicles !== \"function\") {\n return;\n }\n\n refreshVehicles();\n setInterval(refreshVehicles, 30_000);\n }, [refreshVehicles]);\n\n useEffect(() => {\n const VEHICLE_LAYERS = [layerId];\n VEHICLE_LAYERS.forEach(stopLayer => {\n map?.on(\"mouseenter\", stopLayer, () => {\n map.getCanvas().style.cursor = \"pointer\";\n });\n map?.on(\"mouseleave\", stopLayer, () => {\n map.getCanvas().style.cursor = \"\";\n });\n map?.on(\"click\", stopLayer, event => {\n setClickedVehicle(event.features?.[0].properties);\n });\n });\n map.on(\"zoom\", (e: ViewStateChangeEvent) => {\n // Avoid too many re-renders by only updating state if we are a whole number value different\n const { zoom: newZoom } = e.viewState;\n if (Math.floor(zoom / 2) !== Math.floor(newZoom / 2)) {\n setZoom(newZoom);\n }\n });\n }, [map]);\n\n // Don't render if no map or no stops are defined.\n if (visible === false || !stations || stations.length === 0) {\n // Null can't be returned here -- react-map-gl dislikes null values as children\n return <></>;\n }\n\n const vehiclesGeoJSON: GeoJSON.FeatureCollection = {\n type: \"FeatureCollection\",\n features: stations\n .filter(\n vehicle =>\n // Include specified companies only if companies is specified and network info is available\n !companies ||\n !vehicle.networks ||\n companies.includes(vehicle.networks[0])\n )\n .map(vehicle => ({\n type: \"Feature\",\n geometry: { type: \"Point\", coordinates: [vehicle.x, vehicle.y] },\n properties: {\n ...vehicle,\n networks: JSON.stringify(vehicle.networks),\n \"stroke-width\":\n vehicle.isFloatingBike || vehicle.isFloatingVehicle ? 1 : 2,\n color: getColorForStation(vehicle)\n }\n }))\n };\n\n return (\n <>\n {zoom < DETAILED_MARKER_CUTOFF && (\n <Source type=\"geojson\" data={vehiclesGeoJSON}>\n <Layer\n id={layerId}\n paint={{\n \"circle-color\": [\"get\", \"color\"],\n \"circle-opacity\": 0.9,\n \"circle-stroke-color\": \"#333\",\n \"circle-stroke-width\": [\"get\", \"stroke-width\"]\n }}\n type=\"circle\"\n />\n {/* this is where we add the symbols layer. add a second layer that gets swapped in and out dynamically */}\n </Source>\n )}\n {zoom >= DETAILED_MARKER_CUTOFF &&\n stations.map(station => (\n <MarkerWithPopup\n key={station.id}\n popupContents={\n <StationPopup\n configCompanies={configCompanies}\n setLocation={location => {\n setClickedVehicle(null);\n setLocation(location);\n }}\n getEntityName={\n // @ts-expect-error no stop support. Avoid a breaking change\n getStationName && ((s, cc) => getStationName(cc, s))\n }\n entity={station}\n />\n }\n position={[station.y, station.x]}\n >\n {station.bikesAvailable !== undefined &&\n !station.isFloatingBike &&\n !station.isFloatingVehicle &&\n station.spacesAvailable !== undefined ? (\n <BaseBikeRentalIcon\n percent={\n station?.bikesAvailable /\n (station?.bikesAvailable + station?.spacesAvailable)\n }\n />\n ) : (\n <StationMarker width={12} color={getColorForStation(station)} />\n )}\n </MarkerWithPopup>\n ))}\n {clickedVehicle && (\n <Popup\n latitude={clickedVehicle.y}\n longitude={clickedVehicle.x}\n maxWidth=\"100%\"\n onClose={() => {\n setClickedVehicle(null);\n }}\n >\n <StationPopup\n configCompanies={configCompanies}\n getEntityName={\n // @ts-expect-error no stop support. Avoid a breaking change\n getStationName && ((s, cc) => getStationName(cc, s))\n }\n setLocation={location => {\n setClickedVehicle(null);\n setLocation(location);\n }}\n entity={{\n ...clickedVehicle,\n networks: JSON.parse(clickedVehicle.networks)\n }}\n />\n </Popup>\n )}\n </>\n );\n};\nexport default VehicleRentalOverlay;\nexport { StationPopup };\n"],"mappings":";;;;AAAA,SAASA,eAAe,EAAEC,KAAK,QAAQ,2BAA2B;AAOlE,OAAOC,KAAK,IAAIC,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AAClD,SACEC,KAAK,EACLC,MAAM,EACNC,MAAM,QAED,uBAAuB;AAE9B,OAAOC,YAAY,MAAM,4BAA4B;AACrD,SAASC,kBAAkB,EAAEC,aAAa,QAAQ,UAAU;;AAE5D;AACA,IAAMC,sBAAsB,GAAG,EAAE;AAEjC,IAAMC,kBAAkB,GAAG,SAArBA,kBAAkBA,CAAIC,CAAU,EAAK;EACzC,IAAIA,CAAC,CAACC,aAAa,EAAE,OAAO,SAAS;EACrC,IAAID,CAAC,CAACE,iBAAiB,EAAE,OAAO,SAAS;EACzC;EACA,IAAIF,CAAC,CAACG,cAAc,KAAKC,SAAS,IAAIJ,CAAC,CAACK,cAAc,EAAE,OAAO,MAAM;EACrE,OAAO,MAAM;AACf,CAAC;AA0DD;AACA;AACA;AACA;AACA;AACA,IAAMC,oBAAoB,GAAG,SAAvBA,oBAAoBA,CAAAC,IAAA,EASA;EAAA,IARxBC,SAAS,GAAAD,IAAA,CAATC,SAAS;IACTC,eAAe,GAAAF,IAAA,CAAfE,eAAe;IACfC,cAAc,GAAAH,IAAA,CAAdG,cAAc;IACdC,EAAE,GAAAJ,IAAA,CAAFI,EAAE;IACFC,eAAe,GAAAL,IAAA,CAAfK,eAAe;IACfC,YAAW,GAAAN,IAAA,CAAXM,WAAW;IACXC,QAAQ,GAAAP,IAAA,CAARO,QAAQ;IACRC,OAAO,GAAAR,IAAA,CAAPQ,OAAO;EAEP,IAAAC,OAAA,GAAyBtB,MAAM,CAAC,CAAC;IAAhBuB,GAAG,GAAAD,OAAA,CAAZE,OAAO;EACf,IAAAC,SAAA,GAAwB5B,QAAQ,CAAC0B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,CAAC;IACvB,CAAE;IACFI,MAAM,EAAAb,aAAA,CAAAA,aAAA,KACDhC,cAAc;MACjB0B,QAAQ,EAAEO,IAAI,CAACqB,KAAK,CAACtD,cAAc,CAAC0B,QAAQ;IAAC;EAC7C,CACH,CACI,CAET,CAAC;AAEP,CAAC;AACD,eAAejD,oBAAoB;AACnC,SAASX,YAAY","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["MarkerWithPopup","Popup","React","useEffect","useState","Layer","Source","useMap","StationPopup","BaseBikeRentalIcon","StationMarker","DETAILED_MARKER_CUTOFF","entityIsStation","entity","getColorForEntity","availableVehicles","total","vehicleType","formFactor","startsWith","VehicleRentalOverlay","_ref","companies","configCompanies","entities","getStationName","id","refreshVehicles","setLocation","visible","_useMap","map","current","_useState","getZoom","_useState2","_slicedToArray","zoom","setZoom","layerId","concat","_useState3","_useState4","clickedVehicle","setClickedVehicle","setInterval","mouseEnterFunc","getCanvas","style","cursor","mouseLeaveFunc","clickFunc","event","_event$features","p","features","properties","_objectSpread","availableSpaces","JSON","parse","zoomFunc","e","newZoom","viewState","Math","floor","on","off","length","createElement","Fragment","vehiclesGeoJSON","type","filter","rentalNetwork","networkId","includes","geometry","coordinates","lon","lat","networks","color","data","paint","key","popupContents","location","undefined","getEntityName","s","cc","position","percent","width","latitude","longitude","maxWidth","onClose"],"sources":["../src/index.tsx"],"sourcesContent":["import { MarkerWithPopup, Popup } from \"@opentripplanner/base-map\";\nimport {\n Company,\n ConfiguredCompany,\n MapLocationActionArg\n} from \"@opentripplanner/types\";\nimport {\n RentalVehicle,\n VehicleRentalStation\n} from \"@opentripplanner/types/otp2\";\nimport { Geometry } from \"geojson\";\nimport React, { useEffect, useState } from \"react\";\nimport { Layer, Source, useMap } from \"react-map-gl/maplibre\";\n\nimport StationPopup from \"@opentripplanner/map-popup\";\nimport { BaseBikeRentalIcon, StationMarker } from \"./styled\";\n\n// TODO: Make configurable?\nconst DETAILED_MARKER_CUTOFF = 16;\n\nfunction entityIsStation(\n entity: VehicleRentalStation | RentalVehicle\n): entity is VehicleRentalStation {\n return \"availableVehicles\" in entity;\n}\n\nconst getColorForEntity = (entity: VehicleRentalStation | RentalVehicle) => {\n if (entityIsStation(entity)) {\n if (entity.availableVehicles && entity.availableVehicles.total > 0)\n return \"#f00\";\n } else {\n if (entity.vehicleType.formFactor.startsWith(\"SCOOTER\")) return \"#f5a729\";\n if (entity.vehicleType.formFactor === \"BICYCLE\") return \"#009cde\";\n }\n return \"gray\";\n};\n\ntype Props = {\n /**\n * A list of companies that are applicable to just this instance of the\n * overlay.\n */\n companies?: string[];\n /**\n * The entire companies config array.\n */\n configCompanies: ConfiguredCompany[];\n /**\n * The entities to be represented in the overlay. They can be a combination of VehicleRentalStation type\n * (for stationary stations) and RentalVehicle type (for floating vehicles)\n */\n entities?: (VehicleRentalStation | RentalVehicle)[];\n /**\n * An id, used to make this layer uniquely identifiable\n */\n id: string;\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?: (\n configCompanies: Company[],\n station: VehicleRentalStation\n ) => string;\n /**\n * If specified, a function that will be triggered every 30 seconds whenever this layer is\n * visible.\n */\n refreshVehicles?: () => void;\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?: (arg: MapLocationActionArg) => void;\n /**\n * Whether the overlay is currently visible.\n */\n visible?: boolean;\n /**\n * TODO: Add props for overriding symbols?\n */\n};\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 */\nconst VehicleRentalOverlay = ({\n companies,\n configCompanies,\n entities,\n getStationName,\n id,\n refreshVehicles,\n setLocation,\n visible\n}: Props): JSX.Element => {\n const { current: map } = useMap();\n const [zoom, setZoom] = useState(map?.getZoom());\n\n const layerId = `rental-vehicles-${id}`;\n const [clickedVehicle, setClickedVehicle] = useState<\n RentalVehicle | VehicleRentalStation | undefined\n >();\n\n useEffect(() => {\n // TODO: Make 30s configurable?\n if (!refreshVehicles || typeof refreshVehicles !== \"function\") {\n return;\n }\n\n refreshVehicles();\n setInterval(refreshVehicles, 30_000);\n }, [refreshVehicles]);\n\n useEffect(() => {\n const mouseEnterFunc = () => {\n map.getCanvas().style.cursor = \"pointer\";\n };\n const mouseLeaveFunc = () => {\n map.getCanvas().style.cursor = \"\";\n };\n const clickFunc = event => {\n const p = event.features?.[0].properties;\n setClickedVehicle({\n ...p,\n // the properties field of the GeoJSON Feature object serializes these\n // two objects into JSON strings, so we need to parse them back into objects\n availableSpaces: JSON.parse(p?.availableSpaces),\n availableVehicles: JSON.parse(p?.availableVehicles)\n } as RentalVehicle | VehicleRentalStation);\n };\n const zoomFunc = e => {\n // Avoid too many re-renders by only updating state if we are a whole number value different\n const { zoom: newZoom } = e.viewState;\n if (Math.floor(zoom / 2) !== Math.floor(newZoom / 2)) {\n setZoom(newZoom);\n }\n };\n\n map?.on(\"mouseenter\", layerId, mouseEnterFunc);\n map?.on(\"mouseleave\", layerId, mouseLeaveFunc);\n map?.on(\"click\", layerId, clickFunc);\n map?.on(\"zoom\", zoomFunc);\n\n return () => {\n map?.off(\"mouseenter\", layerId, mouseEnterFunc);\n map?.off(\"mouseleave\", layerId, mouseLeaveFunc);\n map?.off(\"click\", layerId, clickFunc);\n map?.off(\"zoom\", zoomFunc);\n };\n }, [map]);\n\n // Don't render if no map or no stops are defined.\n if (visible === false || !entities || entities.length === 0) {\n // Null can't be returned here -- react-map-gl dislikes null values as children\n return <></>;\n }\n\n const vehiclesGeoJSON: GeoJSON.FeatureCollection<\n Geometry,\n VehicleRentalStation | RentalVehicle\n > = {\n type: \"FeatureCollection\",\n features: entities\n .filter(entity => !!entity)\n .filter(\n entity =>\n // Include specified companies only if companies is specified and network info is available\n !companies ||\n !entity.rentalNetwork.networkId ||\n companies.includes(entity.rentalNetwork.networkId)\n )\n .map(entity => ({\n type: \"Feature\",\n geometry: { type: \"Point\", coordinates: [entity.lon, entity.lat] },\n properties: {\n ...entity,\n networks: entity.rentalNetwork.networkId,\n \"stroke-width\": entityIsStation(entity) ? 1 : 2,\n color: getColorForEntity(entity)\n }\n }))\n };\n\n return (\n <>\n {zoom < DETAILED_MARKER_CUTOFF && (\n <Source type=\"geojson\" data={vehiclesGeoJSON}>\n <Layer\n id={layerId}\n paint={{\n \"circle-color\": [\"get\", \"color\"],\n \"circle-opacity\": 0.9,\n \"circle-stroke-color\": \"#333\",\n \"circle-stroke-width\": [\"get\", \"stroke-width\"]\n }}\n type=\"circle\"\n />\n {/* this is where we add the symbols layer. add a second layer that gets swapped in and out dynamically */}\n </Source>\n )}\n {zoom >= DETAILED_MARKER_CUTOFF &&\n entities\n .filter(entity => !!entity)\n .map(entity => (\n <MarkerWithPopup\n key={entity.id}\n popupContents={\n <StationPopup\n configCompanies={configCompanies}\n setLocation={location => {\n setClickedVehicle(undefined);\n setLocation(location);\n }}\n getEntityName={\n // @ts-expect-error no stop support. Avoid a breaking change\n getStationName && ((s, cc) => getStationName(cc, s))\n }\n entity={entity}\n />\n }\n position={[entity.lat, entity.lon]}\n >\n {entityIsStation(entity) &&\n entity.availableSpaces !== undefined &&\n entity.availableVehicles !== undefined &&\n entity.availableVehicles.total > 0 ? (\n <BaseBikeRentalIcon\n percent={\n entity?.availableVehicles.total /\n (entity?.availableVehicles.total +\n entity?.availableSpaces.total)\n }\n />\n ) : (\n <StationMarker width={12} color={getColorForEntity(entity)} />\n )}\n </MarkerWithPopup>\n ))}\n {clickedVehicle && (\n <Popup\n latitude={clickedVehicle.lat}\n longitude={clickedVehicle.lon}\n maxWidth=\"100%\"\n onClose={() => {\n setClickedVehicle(undefined);\n }}\n >\n <StationPopup\n configCompanies={configCompanies}\n getEntityName={\n // @ts-expect-error no stop support. Avoid a breaking change\n getStationName && ((s, cc) => getStationName(cc, s))\n }\n setLocation={location => {\n setClickedVehicle(undefined);\n setLocation(location);\n }}\n entity={clickedVehicle}\n />\n </Popup>\n )}\n </>\n );\n};\nexport default VehicleRentalOverlay;\nexport { StationPopup };\n"],"mappings":";;;;AAAA,SAASA,eAAe,EAAEC,KAAK,QAAQ,2BAA2B;AAWlE,OAAOC,KAAK,IAAIC,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AAClD,SAASC,KAAK,EAAEC,MAAM,EAAEC,MAAM,QAAQ,uBAAuB;AAE7D,OAAOC,YAAY,MAAM,4BAA4B;AACrD,SAASC,kBAAkB,EAAEC,aAAa,QAAQ,UAAU;;AAE5D;AACA,IAAMC,sBAAsB,GAAG,EAAE;AAEjC,SAASC,eAAeA,CACtBC,MAA4C,EACZ;EAChC,OAAO,mBAAmB,IAAIA,MAAM;AACtC;AAEA,IAAMC,iBAAiB,GAAG,SAApBA,iBAAiBA,CAAID,MAA4C,EAAK;EAC1E,IAAID,eAAe,CAACC,MAAM,CAAC,EAAE;IAC3B,IAAIA,MAAM,CAACE,iBAAiB,IAAIF,MAAM,CAACE,iBAAiB,CAACC,KAAK,GAAG,CAAC,EAChE,OAAO,MAAM;EACjB,CAAC,MAAM;IACL,IAAIH,MAAM,CAACI,WAAW,CAACC,UAAU,CAACC,UAAU,CAAC,SAAS,CAAC,EAAE,OAAO,SAAS;IACzE,IAAIN,MAAM,CAACI,WAAW,CAACC,UAAU,KAAK,SAAS,EAAE,OAAO,SAAS;EACnE;EACA,OAAO,MAAM;AACf,CAAC;AA8DD;AACA;AACA;AACA;AACA;AACA,IAAME,oBAAoB,GAAG,SAAvBA,oBAAoBA,CAAAC,IAAA,EASA;EAAA,IARxBC,SAAS,GAAAD,IAAA,CAATC,SAAS;IACTC,eAAe,GAAAF,IAAA,CAAfE,eAAe;IACfC,QAAQ,GAAAH,IAAA,CAARG,QAAQ;IACRC,cAAc,GAAAJ,IAAA,CAAdI,cAAc;IACdC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5C,iBAAiB,CAAC6C,SAAS,CAAC;MAC5B7D,YAAW,CAAC4D,QAAQ,CAAC;IACvB,CAAE;IACF3E,MAAM,EAAE8B;EAAe,CACxB,CACI,CAET,CAAC;AAEP,CAAC;AACD,eAAevB,oBAAoB;AACnC,SAASZ,YAAY","ignoreList":[]}
package/lib/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  /// <reference types="react" />
2
- import { Company, ConfiguredCompany, MapLocationActionArg, Station } from "@opentripplanner/types";
2
+ import { Company, ConfiguredCompany, MapLocationActionArg } from "@opentripplanner/types";
3
+ import { RentalVehicle, VehicleRentalStation } from "@opentripplanner/types/otp2";
3
4
  import StationPopup from "@opentripplanner/map-popup";
4
5
  type Props = {
5
6
  /**
@@ -11,6 +12,11 @@ type Props = {
11
12
  * The entire companies config array.
12
13
  */
13
14
  configCompanies: ConfiguredCompany[];
15
+ /**
16
+ * The entities to be represented in the overlay. They can be a combination of VehicleRentalStation type
17
+ * (for stationary stations) and RentalVehicle type (for floating vehicles)
18
+ */
19
+ entities?: (VehicleRentalStation | RentalVehicle)[];
14
20
  /**
15
21
  * An id, used to make this layer uniquely identifiable
16
22
  */
@@ -20,7 +26,7 @@ type Props = {
20
26
  * rental station. This function takes two arguments of the configCompanies
21
27
  * prop and a vehicle rental station. The function must return a string.
22
28
  */
23
- getStationName?: (configCompanies: Company[], station: Station) => string;
29
+ getStationName?: (configCompanies: Company[], station: VehicleRentalStation) => string;
24
30
  /**
25
31
  * If specified, a function that will be triggered every 30 seconds whenever this layer is
26
32
  * visible.
@@ -44,10 +50,6 @@ type Props = {
44
50
  * ```
45
51
  */
46
52
  setLocation?: (arg: MapLocationActionArg) => void;
47
- /**
48
- * A list of the vehicle rental stations specific to this overlay instance.
49
- */
50
- stations: Station[];
51
53
  /**
52
54
  * Whether the overlay is currently visible.
53
55
  */
@@ -58,7 +60,7 @@ type Props = {
58
60
  * types. This layer can be configured to show different styles of markers at
59
61
  * different zoom levels.
60
62
  */
61
- declare const VehicleRentalOverlay: ({ companies, configCompanies, getStationName, id, refreshVehicles, setLocation, stations, visible }: Props) => JSX.Element;
63
+ declare const VehicleRentalOverlay: ({ companies, configCompanies, entities, getStationName, id, refreshVehicles, setLocation, visible }: Props) => JSX.Element;
62
64
  export default VehicleRentalOverlay;
63
65
  export { StationPopup };
64
66
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":";AACA,OAAO,EACL,OAAO,EACP,iBAAiB,EACjB,oBAAoB,EACpB,OAAO,EACR,MAAM,wBAAwB,CAAC;AAShC,OAAO,YAAY,MAAM,4BAA4B,CAAC;AActD,KAAK,KAAK,GAAG;IACX;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB;;OAEG;IACH,eAAe,EAAE,iBAAiB,EAAE,CAAC;IACrC;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IACX;;;;OAIG;IACH,cAAc,CAAC,EAAE,CAAC,eAAe,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,OAAO,KAAK,MAAM,CAAC;IAC1E;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,IAAI,CAAC;IAC7B;;;;;;;;;;;;;;;;OAgBG;IACH,WAAW,CAAC,EAAE,CAAC,GAAG,EAAE,oBAAoB,KAAK,IAAI,CAAC;IAClD;;OAEG;IACH,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CAInB,CAAC;AAEF;;;;GAIG;AACH,QAAA,MAAM,oBAAoB,wGASvB,KAAK,KAAG,WAoJV,CAAC;AACF,eAAe,oBAAoB,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":";AACA,OAAO,EACL,OAAO,EACP,iBAAiB,EACjB,oBAAoB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