ublo-lib 1.14.0 → 1.14.2

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,12 +1,15 @@
1
1
  import * as React from "react";
2
2
  import { MapContainer, TileLayer } from "react-leaflet";
3
3
  import { useUbloContext } from "ublo/with-ublo";
4
+ import Button from "dt-design-system/es/button";
5
+ import * as Icons from "dt-design-system/es/icons";
4
6
  import MapEvents from "./map-events";
5
7
  import Markers from "./markers";
6
8
  import Helper from "./helper";
7
9
  import Cluster from "./cluster";
8
10
  import MarkerList from "./marker-list";
9
11
  import FullScreenButton from "./full-screen-button";
12
+ import SlopesToggle from "./slopes-toggle";
10
13
  import css from "./editable-map.module.css";
11
14
  import "leaflet/dist/leaflet.css";
12
15
  import { jsx as _jsx } from "react/jsx-runtime";
@@ -15,7 +18,8 @@ const FRANCE_CENTER = [46.807934, 3.645097];
15
18
  const DEFAULT_ZOOM = 6;
16
19
  export default function EditableMap({
17
20
  format,
18
- iconSet
21
+ iconSet,
22
+ hideSlopes
19
23
  }) {
20
24
  const ref = React.useRef();
21
25
  const containerRef = React.useRef();
@@ -29,14 +33,24 @@ export default function EditableMap({
29
33
  isInDialog
30
34
  } = format;
31
35
  const isInZone = element.closest(".cms");
32
- const isEditing = cmsMode === "editing" && isInZone;
33
- const [center, setCenter] = React.useState(presets?.center || FRANCE_CENTER);
34
- const [zoom, setZoom] = React.useState(presets?.zoom ?? DEFAULT_ZOOM);
36
+ const isEditing = isInZone && cmsMode === "editing";
37
+ const defaultCenter = presets?.center || FRANCE_CENTER;
38
+ const defaultZoom = presets?.zoom || DEFAULT_ZOOM;
39
+ const [center, setCenter] = React.useState(defaultCenter);
40
+ const [zoom, setZoom] = React.useState(defaultZoom);
35
41
  const [markers, setMarkers] = React.useState(presets?.markers || []);
42
+ const [showSlopes, setShowSlopes] = React.useState(presets?.showSlopes || false);
36
43
  const scrollWheelZoom = Boolean(cmsMode) || isInDialog || fullScreen;
37
44
  const refreshSize = () => {
38
45
  ref.current.invalidateSize();
39
46
  };
47
+ const resetCenter = () => {
48
+ setCenter(defaultCenter);
49
+ setZoom(defaultZoom);
50
+ ref.current.setView(defaultCenter, defaultZoom, {
51
+ animate: true
52
+ });
53
+ };
40
54
  React.useEffect(() => {
41
55
  if (isInDialog) {
42
56
  window.refreshDialogMapSize = refreshSize;
@@ -47,11 +61,12 @@ export default function EditableMap({
47
61
  const newPresets = {
48
62
  markers,
49
63
  zoom,
50
- center
64
+ center,
65
+ showSlopes
51
66
  };
52
67
  element.setAttribute("data-presets", JSON.stringify(newPresets));
53
68
  }
54
- }, [center, element, isEditing, markers, zoom]);
69
+ }, [center, element, isEditing, markers, showSlopes, zoom]);
55
70
  return _jsxs("div", {
56
71
  ref: containerRef,
57
72
  className: css.container,
@@ -65,6 +80,8 @@ export default function EditableMap({
65
80
  attributionControl: false,
66
81
  children: [_jsx(TileLayer, {
67
82
  url: "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
83
+ }), showSlopes && _jsx(TileLayer, {
84
+ url: "https://tiles.opensnowmap.org/pistes/{z}/{x}/{y}.png"
68
85
  }), _jsx(MapEvents, {
69
86
  mapRef: ref,
70
87
  markers: markers,
@@ -86,6 +103,13 @@ export default function EditableMap({
86
103
  fullScreen: fullScreen,
87
104
  setFullScreen: setFullScreen,
88
105
  containerRef: containerRef
106
+ }), _jsx(Button, {
107
+ className: css.resetCenter,
108
+ onClick: resetCenter,
109
+ children: _jsx(Icons.MdMyLocation, {})
110
+ }), !hideSlopes && _jsx(SlopesToggle, {
111
+ showSlopes: showSlopes,
112
+ setShowSlopes: setShowSlopes
89
113
  }), !isEditing && markers.length > 2 && _jsx(MarkerList, {
90
114
  mapRef: ref,
91
115
  markers: markers,
@@ -11,6 +11,14 @@
11
11
  display: flex;
12
12
  }
13
13
 
14
+ .resetCenter {
15
+ position: absolute;
16
+ bottom: 10px;
17
+ left: 10px;
18
+ user-select: none;
19
+ box-shadow: var(--ds-shadow-100, 0px 3px 6px rgba(0, 0, 0, 0.12));
20
+ }
21
+
14
22
  .map {
15
23
  flex: 1 1 100%;
16
24
  }
@@ -74,8 +82,11 @@
74
82
  font-size: 22px;
75
83
  }
76
84
 
77
- .map :global(.leaflet-tile-pane) {
78
- filter: saturate(0.05) hue-rotate(100deg) contrast(1.2);
85
+ .map :global(.leaflet-tile-pane > :first-child) {
86
+ filter: var(
87
+ --editable-map-filter,
88
+ saturate(0.05) hue-rotate(100deg) contrast(1.2)
89
+ );
79
90
  }
80
91
 
81
92
  .map :global(.marker-cluster) {
@@ -8,7 +8,8 @@ const Map = dynamic(() => import("./editable-map"), {
8
8
  ssr: false
9
9
  });
10
10
  export default function EditableMap({
11
- iconSet = "esf"
11
+ iconSet = "esf",
12
+ hideSlopes
12
13
  }) {
13
14
  const {
14
15
  lang,
@@ -75,7 +76,8 @@ export default function EditableMap({
75
76
  });
76
77
  return formats.map(format => ReactDOM.createPortal(_jsx(Map, {
77
78
  format: format,
78
- iconSet: iconSet
79
+ iconSet: iconSet,
80
+ hideSlopes: hideSlopes
79
81
  }), format.element));
80
82
  }
81
83
  function reloadWindow() {
@@ -0,0 +1,23 @@
1
+ import * as React from "react";
2
+ import Checkbox from "dt-design-system/es/checkbox";
3
+ import css from "./slopes-toggle.module.css";
4
+ import { jsx as _jsx } from "react/jsx-runtime";
5
+ const labels = {
6
+ fr: "Afficher les pistes",
7
+ en: "Show slopes"
8
+ };
9
+ export default function SlopesToggle({
10
+ showSlopes,
11
+ setShowSlopes
12
+ }) {
13
+ const lang = document.documentElement.getAttribute("lang");
14
+ const label = lang === "fr" ? labels.fr : labels.en;
15
+ return _jsx("div", {
16
+ className: css.slopesToggle,
17
+ children: _jsx(Checkbox, {
18
+ label: label,
19
+ value: showSlopes,
20
+ onCheckedChange: setShowSlopes
21
+ })
22
+ });
23
+ }
@@ -0,0 +1,14 @@
1
+ .slopesToggle {
2
+ position: absolute;
3
+ bottom: 10px;
4
+ left: 50px;
5
+ width: fit-content;
6
+ padding: 5px;
7
+ background-color: var(--ds-grey-000, #fff);
8
+ border-radius: var(--ds-radius-200, 8px);
9
+ box-shadow: var(--ds-shadow-100, 0px 3px 6px rgba(0, 0, 0, 0.12));
10
+ }
11
+
12
+ .slopesToggle span {
13
+ width: 24px;
14
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ublo-lib",
3
- "version": "1.14.0",
3
+ "version": "1.14.2",
4
4
  "peerDependencies": {
5
5
  "dt-design-system": "^2.1.0",
6
6
  "leaflet": "^1.9.1",