@geops/rvf-mobility-web-component 0.1.44 → 0.1.45

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/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@geops/rvf-mobility-web-component",
3
3
  "license": "UNLICENSED",
4
4
  "description": "Web components for rvf in the domains of mobility and logistics.",
5
- "version": "0.1.44",
5
+ "version": "0.1.45",
6
6
  "homepage": "https://rvf-mobility-web-component-geops.vercel.app/",
7
7
  "type": "module",
8
8
  "main": "index.js",
@@ -12,7 +12,7 @@
12
12
  "jspdf": "^2.5.2",
13
13
  "lodash.debounce": "^4.0.8",
14
14
  "maplibre-gl": "^4.7.1",
15
- "mobility-toolbox-js": "3.3.0-beta.32",
15
+ "mobility-toolbox-js": "3.3.1",
16
16
  "ol": "^10.3.1",
17
17
  "preact": "^10.25.4",
18
18
  "preact-custom-element": "^4.3.0",
@@ -155,7 +155,7 @@ const realtimeLayerProps = {
155
155
  function RvfMobilityMap({
156
156
  apikey = "5cc87b12d7c5370001c1d655820abcc37dfd4d968d7bab5b2a74a935",
157
157
  // baselayer = "review-geops-tgma-085vyz.de.rvf",
158
- baselayer = "de.rvf_moco",
158
+ baselayer = "de.rvf",
159
159
  center = null,
160
160
  details = "true",
161
161
  embed = "false",
@@ -3,6 +3,7 @@ import type { Options } from "ol/layer/Group";
3
3
  import { FeatureCollection, Point } from "geojson";
4
4
  import { GeoJSONSource } from "maplibre-gl";
5
5
  import { MaplibreStyleLayer } from "mobility-toolbox-js/ol";
6
+ import { Extent } from "ol/extent";
6
7
  import { Group } from "ol/layer";
7
8
  import { unByKey } from "ol/Observable";
8
9
  import { transformExtent } from "ol/proj";
@@ -19,6 +20,7 @@ import {
19
20
  CAR_FORM_FACTOR,
20
21
  CARGOBIKE_FORM_FACTOR,
21
22
  LAYER_PROP_IS_EXPORTING,
23
+ RVF_EXTENT_4326,
22
24
  RVF_LAYERS_NAMES,
23
25
  RVF_LAYERS_TITLES,
24
26
  SCOOTER_FORM_FACTOR,
@@ -44,18 +46,17 @@ export type GroupOptions = Options & Record<string, unknown>;
44
46
 
45
47
  const fetchStations = async (
46
48
  typeName: string,
47
- feedIds: string[],
48
49
  abortController: AbortController,
50
+ extent4326: Extent = RVF_EXTENT_4326,
49
51
  ) => {
50
52
  const stations = (await fetchSharingWFS(
51
53
  typeName,
52
54
  abortController,
55
+ extent4326,
53
56
  )) as FeatureCollection<Point, SharingStationWFS>;
54
57
 
55
58
  const featureCollection = {
56
- features: stations.features.filter((feature) => {
57
- return feedIds ? feedIds.includes(feature.properties.feed_id) : true;
58
- }),
59
+ features: stations.features,
59
60
  type: "FeatureCollection",
60
61
  };
61
62
 
@@ -110,8 +111,8 @@ function RvfSharedMobilityLayerGroup(props: GroupOptions) {
110
111
  // Fill stations data
111
112
  const stations = await fetchStations(
112
113
  WFS_STATIONS_TYPE,
113
- null,
114
114
  abortController,
115
+ extent,
115
116
  );
116
117
  const bikeStationsData: FeatureCollection<Point, SharingStationWFS> = {
117
118
  features: [],
@@ -1,152 +0,0 @@
1
- import { Feature, getUid } from "ol";
2
- import { GeoJSON } from "ol/format";
3
- import { Point } from "ol/geom";
4
- import VectorLayer, { Options } from "ol/layer/Vector";
5
- import { bbox as bboxStrategy } from "ol/loadingstrategy.js";
6
- import { Cluster, Vector } from "ol/source";
7
- import { Circle, Fill, Stroke, Style, Text } from "ol/style";
8
-
9
- import { LAYER_PROP_IS_EXPORTING } from "./constants";
10
- import { iconStyleByFormFactor } from "./createMobiDataBwWfsLayer";
11
-
12
- export const getCircleStyle = (color: string) => {
13
- return new Style({
14
- image: new Circle({
15
- declutterMode: "declutter",
16
- displacement: [-12, 12],
17
- fill: new Fill({
18
- color: "white",
19
- }),
20
- radius: 9,
21
- stroke: new Stroke({
22
- color: color,
23
- width: 1,
24
- }),
25
- }),
26
- text: new Text({
27
- declutterMode: "declutter",
28
- fill: new Fill({
29
- color: color,
30
- }),
31
- font: "bolder 10px arial",
32
- offsetX: -12,
33
- offsetY: -11,
34
- }),
35
- });
36
- };
37
-
38
- function createFreeFloatMobilityLayer(
39
- name: string,
40
- color: string,
41
- formFactor: string,
42
- layerOptions: Options = {
43
- minZoom: 17.99,
44
- },
45
- ): VectorLayer<Vector<Feature<Point>>> {
46
- // Exemple how to get a specific form factor
47
- //api.mobidata-bw.de/geoserver/MobiData-BW/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=MobiData-BW%3Asharing_vehicles&CQL_FILTER=form_factor%20%3D%20%27scooter%27&maxFeatures=20000&outputFormat=csv
48
- const source = new Vector({
49
- format: new GeoJSON(),
50
- loader: function (extent, resolution, projection, success, failure) {
51
- const url =
52
- "https://api.mobidata-bw.de/geoserver/MobiData-BW/" +
53
- name +
54
- "/ows" +
55
- "?service=WFS&" +
56
- "version=1.1.0&request=GetFeature&typename=" +
57
- "MobiData-BW:" +
58
- name +
59
- "&" +
60
- "outputFormat=application/json" +
61
- "bbox=" +
62
- extent.join(",") +
63
- ",EPSG:3857";
64
- const xhr = new XMLHttpRequest();
65
- xhr.open("GET", url);
66
- const onError = function () {
67
- source.removeLoadedExtent(extent);
68
- failure();
69
- };
70
- xhr.onerror = onError;
71
- xhr.onload = function () {
72
- if (xhr.status == 200) {
73
- const features = source
74
- .getFormat()
75
- .readFeatures(xhr.responseText, {
76
- dataProjection: "EPSG:4326",
77
- featureProjection: "EPSG:3857",
78
- })
79
- ?.filter((feature) => {
80
- if (formFactor) {
81
- return feature.get("form_factor") === formFactor;
82
- }
83
- return true;
84
- });
85
-
86
- features?.forEach((feature) => {
87
- // The WFS returns everytime a different id for the same vehicle, so we set the vehicle_id as id.
88
- // and remove the previous feature with the same id.
89
- const vehicleId = feature.get("vehicle_id");
90
- if (vehicleId) {
91
- feature.setId(vehicleId);
92
- const featuresToRemove = source.getFeatures().filter((feat) => {
93
- return feat.getId() === feature.getId();
94
- });
95
- source.removeFeatures(featuresToRemove);
96
- }
97
- });
98
- source.addFeatures(features);
99
- success(features);
100
- } else {
101
- onError();
102
- }
103
- };
104
- xhr.send();
105
- },
106
- strategy: bboxStrategy,
107
- });
108
-
109
- const style = getCircleStyle(color);
110
-
111
- const clusterSource = new Cluster({
112
- distance: 40,
113
- source: source,
114
- });
115
-
116
- const styleFunction = (feature) => {
117
- if (layer.get(LAYER_PROP_IS_EXPORTING)) {
118
- return null;
119
- }
120
- const circleStyle = style.clone();
121
-
122
- const featuresCount = feature.get("features").length;
123
- circleStyle.getText().setText(featuresCount);
124
-
125
- const formFactor =
126
- feature.get("features")?.[0].get?.("form_factor") || "scooter";
127
-
128
- const styles = [iconStyleByFormFactor[formFactor], circleStyle];
129
-
130
- styles.forEach((style) => {
131
- style.setZIndex(parseInt(getUid(feature), 10));
132
- });
133
-
134
- return styles;
135
- };
136
-
137
- const layer = new VectorLayer({
138
- // @ts-expect-error - custom properties
139
- isQueryable: true,
140
- source: clusterSource,
141
- style: styleFunction,
142
- ...layerOptions,
143
- });
144
-
145
- clusterSource.on("addfeature", function (event) {
146
- event.feature?.setStyle(styleFunction);
147
- });
148
-
149
- return layer;
150
- }
151
-
152
- export default createFreeFloatMobilityLayer;
@@ -1,155 +0,0 @@
1
- import { Feature, getUid } from "ol";
2
- import { GeoJSON } from "ol/format";
3
- import { Point } from "ol/geom";
4
- import VectorLayer, { Options } from "ol/layer/Vector";
5
- import { bbox as bboxStrategy } from "ol/loadingstrategy.js";
6
- import { Vector } from "ol/source";
7
- import { Circle, Fill, Icon, Stroke, Style, Text } from "ol/style";
8
-
9
- // @ts-expect-error - load svg as data url
10
- import bicycle from "../icons/Bike/rvf_shared_bike.svg";
11
- // @ts-expect-error - load svg as data url
12
- import car from "../icons/Car/rvf_shared_car.svg";
13
- // @ts-expect-error - load svg as data url
14
- import cargo_bicycle from "../icons/CargoBike/rvf_shared_cargo_bike.svg";
15
- // @ts-expect-error - load svg as data url
16
- import scooter from "../icons/Scooter/rvf_shared_scooter.svg";
17
- import { LAYER_PROP_IS_EXPORTING, PROVIDER_BY_FEED_ID } from "./constants";
18
-
19
- const iconByFormFactor = {
20
- bicycle,
21
- car,
22
- cargo_bicycle,
23
- scooter,
24
- };
25
-
26
- export const iconStyleByFormFactor = {};
27
- Object.entries(iconByFormFactor).forEach(([key, value]) => {
28
- iconStyleByFormFactor[key] = new Style({
29
- image: new Icon({
30
- src: value,
31
- }),
32
- });
33
- });
34
-
35
- export const getCircleStyle = (color: string) => {
36
- return new Style({
37
- image: new Circle({
38
- displacement: [12, 12],
39
- fill: new Fill({
40
- color: "white",
41
- }),
42
- radius: 9,
43
- stroke: new Stroke({
44
- color: color,
45
- width: 1,
46
- }),
47
- }),
48
- text: new Text({
49
- fill: new Fill({
50
- color: color,
51
- }),
52
- font: "bolder 10px arial",
53
- offsetX: 12,
54
- offsetY: -11,
55
- }),
56
- });
57
- };
58
-
59
- const getCompanyNameTextStyle = (feedId: string) => {
60
- const offsetY =
61
- feedId === "naturenergie_sharing" || feedId === "gruene_flotte_freiburg"
62
- ? 25
63
- : 20;
64
- return new Style({
65
- text: new Text({
66
- declutterMode: "declutter",
67
- fill: new Fill({ color: "rgba(6, 76, 10, 1)" }),
68
- font: "bold 12px/1.1 source-sans-pro",
69
- offsetY,
70
- stroke: new Stroke({ color: "white", width: 4 }),
71
- text: PROVIDER_BY_FEED_ID[feedId] || feedId,
72
- // textBaseline: "middle",
73
- }),
74
- });
75
- };
76
-
77
- function createMobiDataBwWfsLayer(
78
- name: string,
79
- color: string,
80
- layerOptions: Options = {
81
- minZoom: 0,
82
- },
83
- ): VectorLayer<Vector<Feature<Point>>> {
84
- const source = new Vector({
85
- format: new GeoJSON({
86
- dataProjection: "EPSG:4326",
87
- featureProjection: "EPSG:3857",
88
- }),
89
- strategy: bboxStrategy,
90
- url: function (extent) {
91
- return (
92
- "https://api.mobidata-bw.de/geoserver/MobiData-BW/" +
93
- name +
94
- "/ows" +
95
- "?service=WFS&" +
96
- "version=1.1.0&request=GetFeature&typename=" +
97
- "MobiData-BW:" +
98
- name +
99
- "&" +
100
- "outputFormat=application/json&" +
101
- "bbox=" +
102
- extent.join(",") +
103
- ",EPSG:3857"
104
- );
105
- },
106
- });
107
-
108
- const style = getCircleStyle(color);
109
-
110
- const layer = new VectorLayer({
111
- // @ts-expect-error - custom properties
112
- isQueryable: true,
113
- // declutter: true,
114
- source: source,
115
- ...layerOptions,
116
- });
117
-
118
- const styleFunction = (feature: Feature) => {
119
- if (layer.get(LAYER_PROP_IS_EXPORTING)) {
120
- return null;
121
- }
122
- const circleStyle = style.clone();
123
-
124
- const numVehiclesAvailable = feature
125
- .get("num_vehicles_available")
126
- ?.toString();
127
- circleStyle.getText().setText(numVehiclesAvailable);
128
-
129
- const formFactor = (feature.getId() as string)
130
- .split(".")[0]
131
- .replace("sharing_stations_", "");
132
-
133
- const feedId = feature.get("feed_id").replace("-", "_"); // to handle id's like gruene-flotte_freiburg
134
-
135
- const styles = [
136
- iconStyleByFormFactor[formFactor],
137
- getCompanyNameTextStyle(feedId),
138
- circleStyle,
139
- ];
140
-
141
- styles.forEach((style) => {
142
- style.setZIndex(parseInt(getUid(feature), 10));
143
- });
144
-
145
- return styles;
146
- };
147
-
148
- source.on("addfeature", function (event) {
149
- const feature = event.feature;
150
- feature.setStyle(styleFunction);
151
- });
152
- return layer;
153
- }
154
-
155
- export default createMobiDataBwWfsLayer;