@geops/rvf-mobility-web-component 0.1.34 → 0.1.36

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.34",
5
+ "version": "0.1.36",
6
6
  "homepage": "https://rvf-mobility-web-component-geops.vercel.app/",
7
7
  "type": "module",
8
8
  "main": "index.js",
@@ -1,14 +1,32 @@
1
1
  import type { JSX, PreactDOMAttributes } from "preact";
2
2
 
3
- import { Geolocation } from "ol";
3
+ import { Feature, Geolocation } from "ol";
4
+ import { Point } from "ol/geom";
5
+ import VectorLayer from "ol/layer/Vector";
4
6
  import { unByKey } from "ol/Observable";
5
7
  import { fromLonLat } from "ol/proj";
8
+ import VectorSource from "ol/source/Vector";
9
+ import { Icon, Style } from "ol/style";
6
10
  import { useEffect, useMemo } from "preact/hooks";
7
11
 
8
12
  import GeolocationIcon from "../icons/Geolocation";
13
+ // @ts-ecpect-error - svg file not handled by vite
14
+ import locationSvg from "../icons/Geolocation/location.svg";
9
15
  import RvfIconButton from "../RvfIconButton";
10
16
  import useMapContext from "../utils/hooks/useMapContext";
11
17
 
18
+ const point = new Point([0, 0]);
19
+ const feature = new Feature(point);
20
+ const layer = new VectorLayer({
21
+ source: new VectorSource({ features: [feature] }),
22
+ style: new Style({
23
+ image: new Icon({
24
+ anchor: [0.5, 1],
25
+ src: locationSvg,
26
+ }),
27
+ }),
28
+ });
29
+
12
30
  export type GeolocationButtonProps = JSX.HTMLAttributes<HTMLButtonElement> &
13
31
  PreactDOMAttributes;
14
32
 
@@ -32,15 +50,19 @@ function GeolocationButton({ ...props }: GeolocationButtonProps) {
32
50
  geolocation.once("change:position", (evt) => {
33
51
  const position = evt.target.getPosition();
34
52
  if (evt.target.getPosition()) {
53
+ const coord = fromLonLat(position, "EPSG:3857");
35
54
  map.getView().setZoom(TRACKING_ZOOM);
36
- map.getView().setCenter(fromLonLat(position, "EPSG:3857"));
55
+ map.getView().setCenter(coord);
56
+ point.setCoordinates(coord);
37
57
  }
38
58
  }),
39
59
  // then we only center the map.
40
60
  geolocation.on("change:position", (evt) => {
41
61
  const position = evt.target.getPosition();
42
62
  if (evt.target.getPosition()) {
43
- map.getView().setCenter(fromLonLat(position, "EPSG:3857"));
63
+ const coord = fromLonLat(position, "EPSG:3857");
64
+ map.getView().setCenter(coord);
65
+ point.setCoordinates(coord);
44
66
  }
45
67
  }),
46
68
  ];
@@ -52,7 +74,13 @@ function GeolocationButton({ ...props }: GeolocationButtonProps) {
52
74
 
53
75
  useEffect(() => {
54
76
  geolocation.setTracking(isTracking);
55
- }, [geolocation, isTracking]);
77
+ if (isTracking) {
78
+ layer.setMap(map);
79
+ }
80
+ return () => {
81
+ layer.setMap(null);
82
+ };
83
+ }, [map, geolocation, isTracking]);
56
84
 
57
85
  return (
58
86
  <RvfIconButton
@@ -0,0 +1,124 @@
1
+ import type { Map, MapBrowserEvent } from "ol";
2
+ import type { Options } from "ol/control/Control";
3
+
4
+ import { Control } from "ol/control";
5
+ import { EventsKey } from "ol/events";
6
+ import { DragPan } from "ol/interaction";
7
+ import { unByKey } from "ol/Observable";
8
+
9
+ type DragPanWarningOptions = {
10
+ className?: string;
11
+ } & Options;
12
+
13
+ class DragPanWarning extends Control {
14
+ dragPan?: DragPan;
15
+
16
+ icon: HTMLDivElement;
17
+
18
+ onPointerDragRef?: EventsKey;
19
+
20
+ text: HTMLParagraphElement;
21
+
22
+ constructor(options: DragPanWarningOptions = {}) {
23
+ const element = document.createElement("div");
24
+ element.className =
25
+ options.className !== undefined
26
+ ? options.className
27
+ : "ol-drag-pan-warning";
28
+ element.style.display = "none";
29
+ element.style.pointerEvents = "auto";
30
+
31
+ super({
32
+ element,
33
+ render: options.render,
34
+ target: options.target,
35
+ });
36
+
37
+ this.icon = document.createElement("div");
38
+ this.icon.className = `${element.className}-icon`;
39
+
40
+ // sbb icons: sbb/two-finger-tap-large.svg';
41
+ this.icon.innerHTML = `
42
+ <svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 48 48">
43
+ <path fill="none" stroke="currentColor" stroke-width="2" d="M22.999,25 L22.997,13.002 C22.997,11.896 23.893,11 24.999,11 C26.105,11 27.001,11.896 27.001,13.002 L26.999,26.002 M31,25.003 C31,23.897 31.896,23.001 33.002,23.001 C34.11,23.001 35.006,23.897 35.006,25.003 C35.006,25.003 35,26.125 35,32.001 C35,37.875 33.2,41.001 33.2,41.001 L19,41.001 C19,41.001 12.21,29.483 11.586,28.419 C10.962,27.355 10.804,26.369 11.586,25.587 C12.37,24.805 13.636,24.805 14.418,25.587 L18.998,30.169 L19,30.169 L19,25.001 L18.996,15.003 C18.996,13.897 19.894,13.001 21,13.001 C22.106,13.001 23.002,13.897 23.002,15.003 L23,26.015 M26.9942,22.997 C26.9942,21.891 27.8902,20.995 28.9962,20.995 C30.1042,20.995 31.0002,21.891 31.0002,22.997 L31.0002,26.001 M30,16.3046 C30.632,15.3606 31,14.2246 31,13.0006 C31,9.6846 28.314,7.0006 25,7.0006 C23.208,7.0006 21.616,7.8026 20.518,9.0486 C17.432,9.2986 15,11.8506 15,15.0006 C15,16.2166 15.368,17.3426 15.988,18.2866"/>
44
+ </svg>
45
+ `;
46
+ this.element.appendChild(this.icon);
47
+
48
+ this.text = document.createElement("p");
49
+ this.text.className = `${element.className}-text`;
50
+ this.text.innerHTML = "Benutzen Sie 2 Finger um die Karte zu bedienen.";
51
+ this.element.appendChild(this.text);
52
+
53
+ this.dragPan = undefined;
54
+ this.onPointerDragRef = undefined;
55
+ this.onPointerDrag = this.onPointerDrag.bind(this);
56
+ this.onTouchEnd = this.onTouchEnd.bind(this);
57
+ }
58
+
59
+ onPointerDrag(event: MapBrowserEvent<PointerEvent>) {
60
+ // Show the warning on next pointerdrag events.
61
+ if (event.activePointers?.length !== 1) {
62
+ return true;
63
+ }
64
+ this.element.style.display = "flex";
65
+ document.addEventListener("touchend", this.onTouchEnd, { once: true });
66
+ return false;
67
+ }
68
+
69
+ onTouchEnd() {
70
+ unByKey(this.onPointerDragRef);
71
+ this.element.style.display = "none";
72
+ }
73
+
74
+ setMap(map: Map) {
75
+ super.setMap(map);
76
+ document.removeEventListener("touchend", this.onTouchEnd);
77
+ unByKey(this.onPointerDragRef);
78
+
79
+ if (map) {
80
+ const viewport = map.getViewport();
81
+
82
+ // We allow default scroll behavior for touch events.
83
+ viewport.style.touchAction = "pan-x pan-y";
84
+
85
+ // Deactivate drag pan only on touch events.
86
+ this.dragPan = map
87
+ .getInteractions()
88
+ .getArray()
89
+ .find((interaction) => {
90
+ return interaction instanceof DragPan;
91
+ }) as DragPan;
92
+
93
+ if (!this.dragPan) {
94
+ console.error(
95
+ "Impossible to find the DragPan interaction, DragPanWarning will not work as expected.",
96
+ );
97
+ return;
98
+ }
99
+
100
+ this.listenerKeys.push(
101
+ // @ts-expect-error - we need to listen to pointerdown events
102
+ map.on("pointerdown", (evt: MapBrowserEvent<PointerEvent>) => {
103
+ document.removeEventListener("touchend", this.onTouchEnd);
104
+
105
+ if (
106
+ evt.originalEvent.pointerType !== "touch" ||
107
+ // @ts-expect-error - condition_ is a private method
108
+ !this.dragPan?.condition_(evt)
109
+ ) {
110
+ this.element.style.display = "none";
111
+ return true;
112
+ }
113
+
114
+ this.onPointerDragRef = map.on("pointerdrag", this.onPointerDrag);
115
+
116
+ return true;
117
+ }),
118
+ );
119
+ this.element.addEventListener("click", this.onTouchEnd);
120
+ }
121
+ }
122
+ }
123
+
124
+ export default DragPanWarning;
@@ -0,0 +1,50 @@
1
+ import { MouseWheelZoom } from "ol/interaction";
2
+ import { useEffect, useState } from "preact/hooks";
3
+
4
+ import useMapContext from "../utils/hooks/useMapContext";
5
+ import DragPanWarning from "./DragPanWarning";
6
+
7
+ function RvfEmbedNavigation() {
8
+ const { map } = useMapContext();
9
+ const [target, setTarget] = useState(null);
10
+
11
+ useEffect(() => {
12
+ let dragPanWarningControl = null;
13
+
14
+ if (!map || !target) {
15
+ return;
16
+ }
17
+ // Deactivates mouse wheel zoom
18
+ map.getInteractions().forEach((interaction) => {
19
+ if (interaction instanceof MouseWheelZoom) {
20
+ interaction.setActive(false);
21
+ }
22
+ });
23
+
24
+ dragPanWarningControl = new DragPanWarning({ target: target });
25
+ map.addControl(dragPanWarningControl);
26
+
27
+ return () => {
28
+ if (dragPanWarningControl) {
29
+ map.removeControl(dragPanWarningControl);
30
+ }
31
+
32
+ // Deactivates mouse wheel zoom
33
+ map.getInteractions().forEach((interaction) => {
34
+ if (interaction instanceof MouseWheelZoom) {
35
+ interaction.setActive(true);
36
+ }
37
+ });
38
+ };
39
+ }, [map, target]);
40
+
41
+ return (
42
+ <div
43
+ ref={(node) => {
44
+ return setTarget(node);
45
+ }}
46
+ ></div>
47
+ );
48
+ }
49
+
50
+ export default RvfEmbedNavigation;
@@ -0,0 +1 @@
1
+ export { default } from "./RvfEmbedNavigation";
@@ -29,6 +29,7 @@ import NotificationLayer from "../NotificationLayer";
29
29
  import Overlay from "../Overlay";
30
30
  import RealtimeLayer from "../RealtimeLayer";
31
31
  import RouteSchedule from "../RouteSchedule";
32
+ import RvfEmbedNavigation from "../RvfEmbedNavigation/RvfEmbedNavigation";
32
33
  import RvfExportMenu from "../RvfExportMenu";
33
34
  import RvfExportMenuButton from "../RvfExportMenuButton";
34
35
  import RvfFeatureDetails from "../RvfFeatureDetails";
@@ -80,6 +81,7 @@ const PRIORITY_FROM_TYPE = {
80
81
 
81
82
  export type RvfMobilityMapProps = {
82
83
  details: string;
84
+ embed: string;
83
85
  layers: string; // list of visible layers on load
84
86
  layertree: string;
85
87
  print: string;
@@ -153,6 +155,7 @@ function RvfMobilityMap({
153
155
  baselayer = "de.rvf",
154
156
  center = null,
155
157
  details = "true",
158
+ embed = "false",
156
159
  extent = bbox,
157
160
  geolocation = "true",
158
161
  layers = null,
@@ -241,6 +244,10 @@ function RvfMobilityMap({
241
244
  return details === "true";
242
245
  }, [details]);
243
246
 
247
+ const isEmbed = useMemo(() => {
248
+ return embed === "true";
249
+ }, [embed]);
250
+
244
251
  // Apply initial visibility of layers
245
252
  useInitialLayersVisiblity(map, layers);
246
253
 
@@ -331,6 +338,7 @@ function RvfMobilityMap({
331
338
  baselayer,
332
339
  center,
333
340
  details,
341
+ embed,
334
342
  extent,
335
343
  geolocation,
336
344
  layers,
@@ -356,6 +364,7 @@ function RvfMobilityMap({
356
364
  );
357
365
  }, [
358
366
  baselayer,
367
+ embed,
359
368
  layers,
360
369
  center,
361
370
  geolocation,
@@ -526,6 +535,8 @@ function RvfMobilityMap({
526
535
  <Map className="relative flex-1 overflow-visible ">
527
536
  <BaseLayer {...baseLayerProps} />
528
537
  <SingleClickListener />
538
+ {isEmbed && <RvfEmbedNavigation />}
539
+
529
540
  <RvfSelectedFeatureHighlightLayer />
530
541
 
531
542
  {hasRealtime && (
@@ -0,0 +1,13 @@
1
+
2
+ .ol-drag-pan-warning {
3
+ position: absolute;
4
+ inset: 0;
5
+ display: flex;
6
+ background-color: rgba(0, 0, 0, 0.6);
7
+ color: white;
8
+ align-items: center;
9
+ justify-content: center;
10
+ flex-direction: column;
11
+ padding: 25px;
12
+ z-index: 100000;
13
+ }
@@ -0,0 +1,28 @@
1
+ import { memo } from "preact/compat";
2
+ import { useCallback } from "preact/hooks";
3
+
4
+ import StopsSearch from "../StopsSearch";
5
+ import centerOnStation from "../utils/centerOnStation";
6
+ import { RVF_EXTENT_4326 } from "../utils/constants";
7
+ import useMapContext from "../utils/hooks/useMapContext";
8
+
9
+ function RvfSearch() {
10
+ const { apikey, map, stopsurl } = useMapContext();
11
+
12
+ const onSelect = useCallback(
13
+ (selected) => {
14
+ return centerOnStation(selected, map);
15
+ },
16
+ [map],
17
+ );
18
+
19
+ return (
20
+ <StopsSearch
21
+ apikey={apikey}
22
+ bbox={RVF_EXTENT_4326.join(",")}
23
+ onselect={onSelect}
24
+ url={stopsurl}
25
+ />
26
+ );
27
+ }
28
+ export default memo(RvfSearch);
@@ -0,0 +1 @@
1
+ export { default } from "./RvfSearch";
@@ -1 +1 @@
1
- export { default } from "./Search";
1
+ export { default } from "../RvfSearch";
@@ -10,9 +10,9 @@ import {
10
10
  useRef,
11
11
  useState,
12
12
  } from "preact/hooks";
13
- import { FaSearch } from "react-icons/fa";
14
- import { MdClose } from "react-icons/md";
15
13
 
14
+ import Cancel from "../icons/Cancel";
15
+ import Search from "../icons/Search";
16
16
  // @ts-expect-error tailwind must be added for the search web component
17
17
  import tailwind from "../style.css";
18
18
  import i18n from "../utils/i18n";
@@ -203,8 +203,8 @@ function StopsSearch({
203
203
  }
204
204
  ref={myRef}
205
205
  >
206
- <div className={"flex items-center "}>
207
- <FaSearch className="size-4" />
206
+ <div className={"flex items-center text-grey"}>
207
+ <Search className="size-4" />
208
208
  </div>
209
209
  <div className={"flex grow overflow-hidden border-b-2 border-solid"}>
210
210
  <input
@@ -234,13 +234,13 @@ function StopsSearch({
234
234
  setResults(undefined);
235
235
  }}
236
236
  >
237
- <MdClose className="size-4" />
237
+ <Cancel className="size-4 text-grey" />
238
238
  </button>
239
239
  )}
240
240
  </div>
241
241
  </div>
242
242
 
243
- <div className="-mt-4px flex grow overflow-auto rounded-md rounded-t-none bg-white shadow">
243
+ <div className="flex grow overflow-auto rounded-md rounded-t-none bg-white shadow">
244
244
  {results && results.length === 0 && (
245
245
  <div
246
246
  className={
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <svg width="24px" height="24px" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
3
+ <title>iconfont/location</title>
4
+ <g id="iconfont/location" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
5
+ <path d="M12,1.42108547e-14 C17.5228474,1.42108547e-14 22,4.47715241 22,10 C22,13.3716045 20.1975984,16.6760073 17.2259527,19.8127445 C16.2070021,20.8883035 15.118253,21.8681776 14.0291768,22.735405 C13.6473986,23.0394136 13.2921737,23.3081093 12.9722093,23.5391947 C12.777224,23.6800174 12.6351454,23.77842 12.5547002,23.8320502 C12.2188008,24.0559831 11.7811992,24.0559831 11.4452998,23.8320502 C11.3648546,23.77842 11.222776,23.6800174 11.0277907,23.5391947 C10.7078263,23.3081093 10.3526014,23.0394136 9.97082322,22.735405 C8.88174698,21.8681776 7.7929979,20.8883035 6.77404732,19.8127445 C3.80240157,16.6760073 2,13.3716045 2,10 C2,4.47715241 6.47715256,1.42108547e-14 12,1.42108547e-14 Z M12,2 C7.58172205,2 4,5.58172193 4,10 C4,12.7533953 5.57259843,15.6364924 8.22595268,18.4372552 C9.1757521,19.4398213 10.196378,20.3583846 11.2166768,21.1708447 C11.4951711,21.3926087 11.7576885,21.5936102 12,21.7726167 C12.2423115,21.5936102 12.5048289,21.3926087 12.7833232,21.1708447 C13.803622,20.3583846 14.8242479,19.4398213 15.7740473,18.4372552 C18.4274016,15.6364924 20,12.7533953 20,10 C20,5.58172193 16.418278,2 12,2 Z M12,5.99999987 C14.209139,5.99999987 16,7.79086087 16,9.99999987 C16,12.2091389 14.209139,13.9999999 12,13.9999999 C9.790861,13.9999999 8,12.2091389 8,9.99999987 C8,7.79086087 9.790861,5.99999987 12,5.99999987 Z M12,7.99999987 C10.8954305,7.99999987 10,8.89543037 10,9.99999987 C10,11.1045694 10.8954305,11.9999999 12,11.9999999 C13.1045695,11.9999999 14,11.1045694 14,9.99999987 C14,8.89543037 13.1045695,7.99999987 12,7.99999987 Z" id="Combined-Shape" fill="#E3000B" fill-rule="nonzero"></path>
6
+ </g>
7
+ </svg>
@@ -0,0 +1,39 @@
1
+ function Search({ ...props }) {
2
+ return (
3
+ <svg
4
+ height="24px"
5
+ version="1.1"
6
+ viewBox="0 0 24 24"
7
+ width="24px"
8
+ xmlns="http://www.w3.org/2000/svg"
9
+ {...props}
10
+ >
11
+ <title>iconfont/search</title>
12
+ <defs>
13
+ <polygon id="path-1" points="0 0 20 0 20 20 0 20"></polygon>
14
+ </defs>
15
+ <g
16
+ fill="none"
17
+ fillRule="evenodd"
18
+ id="iconfont/search"
19
+ stroke="none"
20
+ strokeWidth="1"
21
+ >
22
+ <g id="Group-3-Copy" transform="translate(2, 2)">
23
+ <mask fill="white" id="mask-2">
24
+ <use xlinkHref="#path-1"></use>
25
+ </mask>
26
+ <g id="Clip-2"></g>
27
+ <path
28
+ d="M14.0345333,13.8617333 C14.0025333,13.8864 13.9718667,13.9137333 13.9432,13.9430667 C13.9138667,13.9724 13.8865333,14.0030667 13.8632,14.0350667 C12.6038667,15.2517333 10.8892,15.9997333 8.99986667,15.9997333 C5.13386667,15.9997333 1.99986667,12.8657333 1.99986667,8.99973333 C1.99986667,5.13373333 5.13386667,1.99973333 8.99986667,1.99973333 C12.8658667,1.99973333 15.9998667,5.13373333 15.9998667,8.99973333 C15.9998667,10.8890667 15.2512,12.6037333 14.0345333,13.8617333 M19.7072,18.2930667 L16.0318667,14.6177333 C17.2632,13.0784 17.9998667,11.1250667 17.9998667,8.99973333 C17.9998667,4.02973333 13.9705333,-0.000266666667 8.99986667,-0.000266666667 C4.0292,-0.000266666667 -0.000133333333,4.02973333 -0.000133333333,8.99973333 C-0.000133333333,13.9704 4.0292,17.9997333 8.99986667,17.9997333 C11.1252,17.9997333 13.0785333,17.2637333 14.6178667,16.0317333 L18.2932,19.7070667 C18.6832,20.0977333 19.3165333,20.0977333 19.7072,19.7070667 C20.0978667,19.3164 20.0978667,18.6837333 19.7072,18.2930667"
29
+ fill="currentColor"
30
+ id="Fill-1"
31
+ mask="url(#mask-2)"
32
+ ></path>
33
+ </g>
34
+ </g>
35
+ </svg>
36
+ );
37
+ }
38
+
39
+ export default Search;
@@ -0,0 +1 @@
1
+ export { default } from "./Search";
@@ -0,0 +1,16 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <svg width="24px" height="24px" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
3
+ <title>iconfont/search</title>
4
+ <defs>
5
+ <polygon id="path-1" points="0 0 20 0 20 20 0 20"></polygon>
6
+ </defs>
7
+ <g id="iconfont/search" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
8
+ <g id="Group-3-Copy" transform="translate(2, 2)">
9
+ <mask id="mask-2" fill="white">
10
+ <use xlink:href="#path-1"></use>
11
+ </mask>
12
+ <g id="Clip-2"></g>
13
+ <path d="M14.0345333,13.8617333 C14.0025333,13.8864 13.9718667,13.9137333 13.9432,13.9430667 C13.9138667,13.9724 13.8865333,14.0030667 13.8632,14.0350667 C12.6038667,15.2517333 10.8892,15.9997333 8.99986667,15.9997333 C5.13386667,15.9997333 1.99986667,12.8657333 1.99986667,8.99973333 C1.99986667,5.13373333 5.13386667,1.99973333 8.99986667,1.99973333 C12.8658667,1.99973333 15.9998667,5.13373333 15.9998667,8.99973333 C15.9998667,10.8890667 15.2512,12.6037333 14.0345333,13.8617333 M19.7072,18.2930667 L16.0318667,14.6177333 C17.2632,13.0784 17.9998667,11.1250667 17.9998667,8.99973333 C17.9998667,4.02973333 13.9705333,-0.000266666667 8.99986667,-0.000266666667 C4.0292,-0.000266666667 -0.000133333333,4.02973333 -0.000133333333,8.99973333 C-0.000133333333,13.9704 4.0292,17.9997333 8.99986667,17.9997333 C11.1252,17.9997333 13.0785333,17.2637333 14.6178667,16.0317333 L18.2932,19.7070667 C18.6832,20.0977333 19.3165333,20.0977333 19.7072,19.7070667 C20.0978667,19.3164 20.0978667,18.6837333 19.7072,18.2930667" id="Fill-1" fill="#000000" mask="url(#mask-2)"></path>
14
+ </g>
15
+ </g>
16
+ </svg>
package/src/index.tsx CHANGED
@@ -30,6 +30,7 @@ register(
30
30
  "tenant",
31
31
  "zoom",
32
32
  "permalink",
33
+ "embed",
33
34
  ],
34
35
  { shadow: true },
35
36
  );