@geops/rvf-mobility-web-component 0.1.43 → 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.
@@ -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;