react-spatial 1.12.0 → 1.12.1

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.
Files changed (50) hide show
  1. package/components/BaseLayerSwitcher/BaseLayerSwitcher.js +51 -51
  2. package/components/BaseLayerSwitcher/BaseLayerSwitcher.js.map +2 -2
  3. package/components/BasicMap/BasicMap.js +80 -80
  4. package/components/BasicMap/BasicMap.js.map +2 -2
  5. package/components/CanvasSaveButton/CanvasSaveButton.js +68 -68
  6. package/components/CanvasSaveButton/CanvasSaveButton.js.map +2 -2
  7. package/components/Copyright/Copyright.js +12 -12
  8. package/components/Copyright/Copyright.js.map +2 -2
  9. package/components/FeatureExportButton/FeatureExportButton.js +5 -5
  10. package/components/FeatureExportButton/FeatureExportButton.js.map +2 -2
  11. package/components/FitExtent/FitExtent.js +15 -15
  12. package/components/FitExtent/FitExtent.js.map +2 -2
  13. package/components/Geolocation/Geolocation.js +96 -96
  14. package/components/Geolocation/Geolocation.js.map +2 -2
  15. package/components/LayerTree/LayerTree.js +172 -172
  16. package/components/LayerTree/LayerTree.js.map +2 -2
  17. package/components/MousePosition/MousePosition.js +27 -27
  18. package/components/MousePosition/MousePosition.js.map +2 -2
  19. package/components/NorthArrow/NorthArrow.js +13 -13
  20. package/components/NorthArrow/NorthArrow.js.map +2 -2
  21. package/components/Overlay/Overlay.js +49 -49
  22. package/components/Overlay/Overlay.js.map +2 -2
  23. package/components/Permalink/Permalink.js +70 -70
  24. package/components/Permalink/Permalink.js.map +2 -2
  25. package/components/Popup/Popup.js +73 -73
  26. package/components/Popup/Popup.js.map +2 -2
  27. package/components/ResizeHandler/ResizeHandler.js +51 -49
  28. package/components/ResizeHandler/ResizeHandler.js.map +2 -2
  29. package/components/RouteSchedule/RouteSchedule.js +86 -74
  30. package/components/RouteSchedule/RouteSchedule.js.map +2 -2
  31. package/components/RouteSchedule/RouteSchedule.scss +0 -20
  32. package/components/ScaleLine/ScaleLine.js +2 -2
  33. package/components/ScaleLine/ScaleLine.js.map +2 -2
  34. package/components/StopsFinder/StopsFinder.js +21 -21
  35. package/components/StopsFinder/StopsFinder.js.map +2 -2
  36. package/components/StopsFinder/StopsFinderOption.js +3 -3
  37. package/components/StopsFinder/StopsFinderOption.js.map +2 -2
  38. package/components/Zoom/Zoom.js +35 -35
  39. package/components/Zoom/Zoom.js.map +2 -2
  40. package/package.json +33 -29
  41. package/propTypes.js +10 -10
  42. package/propTypes.js.map +2 -2
  43. package/utils/GlobalsForOle.js +57 -57
  44. package/utils/GlobalsForOle.js.map +2 -2
  45. package/utils/KML.js +32 -32
  46. package/utils/KML.js.map +2 -2
  47. package/utils/Styles.js +7 -7
  48. package/utils/Styles.js.map +2 -2
  49. package/utils/timeUtils.js +6 -6
  50. package/utils/timeUtils.js.map +2 -2
@@ -1,9 +1,13 @@
1
- import { PureComponent } from "react";
2
- import PropTypes from "prop-types";
1
+ import { getLayersAsFlatArray, Layer } from "mobility-toolbox-js/ol";
3
2
  import OLMap from "ol/Map";
4
3
  import { unByKey } from "ol/Observable";
5
- import { Layer, getLayersAsFlatArray } from "mobility-toolbox-js/ol";
4
+ import PropTypes from "prop-types";
5
+ import { PureComponent } from "react";
6
6
  const propTypes = {
7
+ /**
8
+ * Maximum number of decimals allowed for coordinates.
9
+ */
10
+ coordinateDecimals: PropTypes.number,
7
11
  /**
8
12
  * Either 'react-router' history object:
9
13
  * https://github.com/ReactTraining/react-router/blob/master/packages/react-router/docs/api/history.md<br>
@@ -14,21 +18,13 @@ const propTypes = {
14
18
  replace: PropTypes.func
15
19
  }),
16
20
  /**
17
- * Layers provider.
18
- */
19
- layers: PropTypes.arrayOf(PropTypes.instanceOf(Layer)),
20
- /**
21
- * An [ol/map](https://openlayers.org/en/latest/apidoc/module-ol_Map-Map.html).
22
- */
23
- map: PropTypes.instanceOf(OLMap),
24
- /**
25
- * Params to be written in url.
26
- */
27
- params: PropTypes.object,
28
- /**
29
- * Maximum number of decimals allowed for coordinates.
21
+ * Determine if the layer appears in the baselayers permalink parameter or not.
22
+ *
23
+ * @param {object} item The item to hide or not.
24
+ *
25
+ * @return {bool} true if the item is not displayed in the baselayers permalink parameter
30
26
  */
31
- coordinateDecimals: PropTypes.number,
27
+ isBaseLayer: PropTypes.func,
32
28
  /**
33
29
  * Determine if the layer is hidden in the permalink or not.
34
30
  *
@@ -38,13 +34,17 @@ const propTypes = {
38
34
  */
39
35
  isLayerHidden: PropTypes.func,
40
36
  /**
41
- * Determine if the layer appears in the baselayers permalink parameter or not.
42
- *
43
- * @param {object} item The item to hide or not.
44
- *
45
- * @return {bool} true if the item is not displayed in the baselayers permalink parameter
37
+ * Layers provider.
46
38
  */
47
- isBaseLayer: PropTypes.func,
39
+ layers: PropTypes.arrayOf(PropTypes.instanceOf(Layer)),
40
+ /**
41
+ * An [ol/map](https://openlayers.org/en/latest/apidoc/module-ol_Map-Map.html).
42
+ */
43
+ map: PropTypes.instanceOf(OLMap),
44
+ /**
45
+ * Params to be written in url.
46
+ */
47
+ params: PropTypes.object,
48
48
  /**
49
49
  * Custom function to be called when the permalink is updated.
50
50
  * This property has priority over the history parameter and window.history.replaceState calls.
@@ -52,18 +52,18 @@ const propTypes = {
52
52
  replace: PropTypes.func
53
53
  };
54
54
  const defaultProps = {
55
- history: null,
56
- replace: null,
57
- layers: [],
58
- map: null,
59
- params: {},
60
55
  coordinateDecimals: 2,
56
+ history: null,
57
+ isBaseLayer: (layer) => {
58
+ return layer.get("isBaseLayer");
59
+ },
61
60
  isLayerHidden: () => {
62
61
  return false;
63
62
  },
64
- isBaseLayer: (layer) => {
65
- return layer.get("isBaseLayer");
66
- }
63
+ layers: [],
64
+ map: null,
65
+ params: {},
66
+ replace: null
67
67
  };
68
68
  class Permalink extends PureComponent {
69
69
  constructor(props) {
@@ -72,7 +72,7 @@ class Permalink extends PureComponent {
72
72
  this.onPropertyChangeKeys = [];
73
73
  }
74
74
  componentDidMount() {
75
- const { map, layers, isLayerHidden, isBaseLayer } = this.props;
75
+ const { isBaseLayer, isLayerHidden, layers, map } = this.props;
76
76
  if (map) {
77
77
  this.moveEndRef = map.on("moveend", () => {
78
78
  this.onMapMoved();
@@ -117,7 +117,7 @@ class Permalink extends PureComponent {
117
117
  }
118
118
  }
119
119
  componentDidUpdate(prevProps, prevState) {
120
- const { map, layers } = this.props;
120
+ const { layers, map } = this.props;
121
121
  const { revision } = this.state;
122
122
  if (layers !== prevProps.layers || revision !== prevState.revision) {
123
123
  this.updateLayers();
@@ -153,12 +153,46 @@ class Permalink extends PureComponent {
153
153
  z: +`${Math.round(`${parseFloat(mapView.getZoom())}e+2`)}e-2`
154
154
  });
155
155
  }
156
+ render() {
157
+ return null;
158
+ }
156
159
  roundCoord(val) {
157
160
  const { coordinateDecimals } = this.props;
158
161
  return parseFloat(val.toFixed(coordinateDecimals));
159
162
  }
163
+ updateHistory() {
164
+ const { history, params, replace } = this.props;
165
+ const oldParams = new URLSearchParams(window.location.search);
166
+ const parameters = {
167
+ ...Object.fromEntries(oldParams.entries()),
168
+ ...this.state,
169
+ ...params
170
+ };
171
+ delete parameters.revision;
172
+ Object.entries(parameters).forEach(([key, value]) => {
173
+ if (value === void 0 || value === null) {
174
+ delete parameters[key];
175
+ }
176
+ });
177
+ const qStr = new URLSearchParams(parameters).toString().replace(/%2C/g, ",");
178
+ const search = qStr ? `?${qStr}` : "";
179
+ if (!qStr && window.location.search || qStr && search !== window.location.search) {
180
+ if (replace) {
181
+ replace({ parameters, search });
182
+ } else if (history) {
183
+ history.replace({ search });
184
+ } else {
185
+ const { hash } = window.location;
186
+ window.history.replaceState(
187
+ void 0,
188
+ void 0,
189
+ `${search}${hash || ""}`
190
+ );
191
+ }
192
+ }
193
+ }
160
194
  updateLayers() {
161
- const { layers, isLayerHidden, isBaseLayer } = this.props;
195
+ const { isBaseLayer, isLayerHidden, layers } = this.props;
162
196
  const { revision } = this.state;
163
197
  unByKey(this.onPropertyChangeKeys);
164
198
  this.onPropertyChangeKeys = getLayersAsFlatArray(layers).map((layer) => {
@@ -203,43 +237,9 @@ class Permalink extends PureComponent {
203
237
  }).join();
204
238
  }
205
239
  this.setState({
206
- layers: layersParam,
207
- baselayers: baseLayersParam
208
- });
209
- }
210
- updateHistory() {
211
- const { params, history, replace } = this.props;
212
- const oldParams = new URLSearchParams(window.location.search);
213
- const parameters = {
214
- ...Object.fromEntries(oldParams.entries()),
215
- ...this.state,
216
- ...params
217
- };
218
- delete parameters.revision;
219
- Object.entries(parameters).forEach(([key, value]) => {
220
- if (value === void 0 || value === null) {
221
- delete parameters[key];
222
- }
240
+ baselayers: baseLayersParam,
241
+ layers: layersParam
223
242
  });
224
- const qStr = new URLSearchParams(parameters).toString().replace(/%2C/g, ",");
225
- const search = qStr ? `?${qStr}` : "";
226
- if (!qStr && window.location.search || qStr && search !== window.location.search) {
227
- if (replace) {
228
- replace({ parameters, search });
229
- } else if (history) {
230
- history.replace({ search });
231
- } else {
232
- const { hash } = window.location;
233
- window.history.replaceState(
234
- void 0,
235
- void 0,
236
- `${search}${hash || ""}`
237
- );
238
- }
239
- }
240
- }
241
- render() {
242
- return null;
243
243
  }
244
244
  }
245
245
  Permalink.propTypes = propTypes;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/components/Permalink/Permalink.js"],
4
- "sourcesContent": ["import { PureComponent } from \"react\";\nimport PropTypes from \"prop-types\";\nimport OLMap from \"ol/Map\";\nimport { unByKey } from \"ol/Observable\";\nimport { Layer, getLayersAsFlatArray } from \"mobility-toolbox-js/ol\";\n\nconst propTypes = {\n /**\n * Either 'react-router' history object:\n * https://github.com/ReactTraining/react-router/blob/master/packages/react-router/docs/api/history.md<br>\n * or default fallback as HTML5 History:\n * https://developer.mozilla.org/en-US/docs/Web/API/History\n */\n history: PropTypes.shape({\n replace: PropTypes.func,\n }),\n\n /**\n * Layers provider.\n */\n layers: PropTypes.arrayOf(PropTypes.instanceOf(Layer)),\n\n /**\n * An [ol/map](https://openlayers.org/en/latest/apidoc/module-ol_Map-Map.html).\n */\n map: PropTypes.instanceOf(OLMap),\n\n /**\n * Params to be written in url.\n */\n params: PropTypes.object,\n\n /**\n * Maximum number of decimals allowed for coordinates.\n */\n coordinateDecimals: PropTypes.number,\n\n /**\n * Determine if the layer is hidden in the permalink or not.\n *\n * @param {object} item The item to hide or not.\n *\n * @return {bool} true if the item is not displayed in the permalink\n */\n isLayerHidden: PropTypes.func,\n\n /**\n * Determine if the layer appears in the baselayers permalink parameter or not.\n *\n * @param {object} item The item to hide or not.\n *\n * @return {bool} true if the item is not displayed in the baselayers permalink parameter\n */\n isBaseLayer: PropTypes.func,\n\n /**\n * Custom function to be called when the permalink is updated.\n * This property has priority over the history parameter and window.history.replaceState calls.\n */\n replace: PropTypes.func,\n};\n\nconst defaultProps = {\n history: null,\n replace: null,\n layers: [],\n map: null,\n params: {},\n coordinateDecimals: 2,\n isLayerHidden: () => {\n return false;\n },\n isBaseLayer: (layer) => {\n return layer.get(\"isBaseLayer\");\n },\n};\n\n/**\n * This component handles permalink logic. Injecting an\n * __[ol/map](https://openlayers.org/en/latest/apidoc/module-ol_Map-Map.html)__\n * will add the *map center* (x, y) and the *zoom* (z) parameters to the permalink.\n * Injecting layers will add the *baselayers* and/or *layers* parameters. Further parameters can\n * be added using __params__.\n */\nclass Permalink extends PureComponent {\n constructor(props) {\n super(props);\n this.state = { revision: 0 };\n this.onPropertyChangeKeys = [];\n }\n\n componentDidMount() {\n const { map, layers, isLayerHidden, isBaseLayer } = this.props;\n if (map) {\n this.moveEndRef = map.on(\"moveend\", () => {\n this.onMapMoved();\n });\n }\n\n if (layers) {\n // set layer visibility based on 'layers' parameter.\n const urlParams = new URLSearchParams(window.location.search);\n\n if (urlParams.get(\"layers\")) {\n const visibleLayers = urlParams.get(\"layers\").split(\",\");\n getLayersAsFlatArray(layers).forEach((l) => {\n if (visibleLayers.includes(l.key)) {\n if (l.setVisible) {\n l.setVisible(true);\n } else {\n // eslint-disable-next-line no-param-reassign\n l.visible = true;\n }\n } else if (\n !isBaseLayer(l) &&\n !isLayerHidden(l) &&\n !l.children.some((ll) => {\n return ll.visible;\n })\n ) {\n if (l.setVisible) {\n l.setVisible(false);\n } else {\n // eslint-disable-next-line no-param-reassign\n l.visible = false;\n }\n }\n });\n }\n\n // Set baser layer visibility based on 'baseLayers' parameter.\n // Show the first of the list then hide the others\n const visibleBaseLayer = (urlParams.get(\"baselayers\") || \"\").split(\n \",\",\n )[0];\n if (visibleBaseLayer) {\n getLayersAsFlatArray(layers)\n .filter(isBaseLayer)\n .forEach((baseLayer) => {\n const visible = baseLayer.key === visibleBaseLayer;\n if (baseLayer.setVisible) {\n baseLayer.setVisible(visible);\n } else {\n // eslint-disable-next-line no-param-reassign\n baseLayer.visible = visible;\n }\n });\n }\n this.updateLayers();\n }\n }\n\n componentDidUpdate(prevProps, prevState) {\n const { map, layers } = this.props;\n const { revision } = this.state;\n\n if (layers !== prevProps.layers || revision !== prevState.revision) {\n this.updateLayers();\n }\n\n if (map !== prevProps.map) {\n unByKey(this.moveEndRef);\n this.moveEndRef = map.on(\"moveend\", () => {\n return this.onMapMoved();\n });\n }\n\n this.updateHistory();\n }\n\n componentWillUnmount() {\n const { map } = this.props;\n\n if (map) {\n unByKey(this.moveEndRef);\n }\n unByKey(this.onPropertyChangeKeys);\n this.onPropertyChangeKeys = [];\n }\n\n onMapMoved() {\n const { map } = this.props;\n const mapView = map.getView();\n const center = mapView.getCenter();\n const params = {};\n\n if (\n center !== undefined &&\n center[0] !== undefined &&\n center[1] !== undefined\n ) {\n params.x = this.roundCoord(center[0]);\n params.y = this.roundCoord(center[1]);\n }\n\n this.setState({\n ...params,\n // rounds zoom to two digits max.\n z: +`${Math.round(`${parseFloat(mapView.getZoom())}e+2`)}e-2`,\n });\n }\n\n roundCoord(val) {\n const { coordinateDecimals } = this.props;\n return parseFloat(val.toFixed(coordinateDecimals));\n }\n\n updateLayers() {\n const { layers, isLayerHidden, isBaseLayer } = this.props;\n const { revision } = this.state;\n\n unByKey(this.onPropertyChangeKeys);\n this.onPropertyChangeKeys = getLayersAsFlatArray(layers).map((layer) => {\n return layer.on(\"change:visible\", () => {\n this.setState({ revision: revision + 1 });\n });\n });\n\n // layers param\n let layersParam;\n if (layers.length) {\n layersParam = getLayersAsFlatArray(layers)\n .filter((l) => {\n const children = l.children || [];\n const allChildrenHidden = children.every((child) => {\n return isLayerHidden(child);\n });\n const hasVisibleChildren = children.some((child) => {\n return child.visible;\n });\n return (\n !isBaseLayer(l) &&\n !isLayerHidden(l) &&\n l.visible &&\n (!hasVisibleChildren || allChildrenHidden)\n );\n })\n .map((l) => {\n return l.key;\n })\n .join();\n }\n\n // baselayers param\n let baseLayersParam;\n const baseLayers = getLayersAsFlatArray(layers).filter(isBaseLayer);\n if (baseLayers.length) {\n // First baselayers in order of visibility, top layer is first\n const visibleBaseLayers = (\n baseLayers.filter((l) => {\n return l.visible;\n }) || []\n ).reverse();\n const nonVisibleBaseLayers =\n baseLayers.filter((l) => {\n return !l.visible;\n }) || [];\n baseLayersParam = [...visibleBaseLayers, ...nonVisibleBaseLayers]\n .sort((a, b) => {\n if (a.visible === b.visible) {\n return 0;\n }\n if (a.visible && !b.visible) {\n return -1;\n }\n return 1;\n })\n .map((l) => {\n return l.key;\n })\n .join();\n }\n\n // Only add parameters if there is actually some layers added.\n this.setState({\n layers: layersParam,\n baselayers: baseLayersParam,\n });\n }\n\n updateHistory() {\n const { params, history, replace } = this.props;\n const oldParams = new URLSearchParams(window.location.search);\n const parameters = {\n ...Object.fromEntries(oldParams.entries()),\n ...this.state,\n ...params,\n };\n\n delete parameters.revision;\n\n // Remove parameters that are undefined or null\n Object.entries(parameters).forEach(([key, value]) => {\n if (value === undefined || value === null) {\n delete parameters[key];\n }\n });\n\n // We don't encode the , to leave the permalink lisible\n const qStr = new URLSearchParams(parameters)\n .toString()\n .replace(/%2C/g, \",\");\n const search = qStr ? `?${qStr}` : \"\";\n\n if (\n (!qStr && window.location.search) ||\n (qStr && search !== window.location.search)\n ) {\n if (replace) {\n replace({ parameters, search });\n } else if (history) {\n history.replace({ search });\n } else {\n const { hash } = window.location;\n window.history.replaceState(\n undefined,\n undefined,\n `${search}${hash || \"\"}`,\n );\n }\n }\n }\n\n render() {\n return null;\n }\n}\n\nPermalink.propTypes = propTypes;\nPermalink.defaultProps = defaultProps;\n\nexport default Permalink;\n"],
5
- "mappings": "AAAA,SAAS,qBAAqB;AAC9B,OAAO,eAAe;AACtB,OAAO,WAAW;AAClB,SAAS,eAAe;AACxB,SAAS,OAAO,4BAA4B;AAE5C,MAAM,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOhB,SAAS,UAAU,MAAM;AAAA,IACvB,SAAS,UAAU;AAAA,EACrB,CAAC;AAAA;AAAA;AAAA;AAAA,EAKD,QAAQ,UAAU,QAAQ,UAAU,WAAW,KAAK,CAAC;AAAA;AAAA;AAAA;AAAA,EAKrD,KAAK,UAAU,WAAW,KAAK;AAAA;AAAA;AAAA;AAAA,EAK/B,QAAQ,UAAU;AAAA;AAAA;AAAA;AAAA,EAKlB,oBAAoB,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAS9B,eAAe,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASzB,aAAa,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA,EAMvB,SAAS,UAAU;AACrB;AAEA,MAAM,eAAe;AAAA,EACnB,SAAS;AAAA,EACT,SAAS;AAAA,EACT,QAAQ,CAAC;AAAA,EACT,KAAK;AAAA,EACL,QAAQ,CAAC;AAAA,EACT,oBAAoB;AAAA,EACpB,eAAe,MAAM;AACnB,WAAO;AAAA,EACT;AAAA,EACA,aAAa,CAAC,UAAU;AACtB,WAAO,MAAM,IAAI,aAAa;AAAA,EAChC;AACF;AASA,MAAM,kBAAkB,cAAc;AAAA,EACpC,YAAY,OAAO;AACjB,UAAM,KAAK;AACX,SAAK,QAAQ,EAAE,UAAU,EAA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";\nimport { unByKey } from \"ol/Observable\";\nimport PropTypes from \"prop-types\";\nimport { PureComponent } from \"react\";\n\nconst propTypes = {\n /**\n * Maximum number of decimals allowed for coordinates.\n */\n coordinateDecimals: PropTypes.number,\n\n /**\n * Either 'react-router' history object:\n * https://github.com/ReactTraining/react-router/blob/master/packages/react-router/docs/api/history.md<br>\n * or default fallback as HTML5 History:\n * https://developer.mozilla.org/en-US/docs/Web/API/History\n */\n history: PropTypes.shape({\n replace: PropTypes.func,\n }),\n\n /**\n * Determine if the layer appears in the baselayers permalink parameter or not.\n *\n * @param {object} item The item to hide or not.\n *\n * @return {bool} true if the item is not displayed in the baselayers permalink parameter\n */\n isBaseLayer: PropTypes.func,\n\n /**\n * Determine if the layer is hidden in the permalink or not.\n *\n * @param {object} item The item to hide or not.\n *\n * @return {bool} true if the item is not displayed in the permalink\n */\n isLayerHidden: PropTypes.func,\n\n /**\n * Layers provider.\n */\n layers: PropTypes.arrayOf(PropTypes.instanceOf(Layer)),\n\n /**\n * An [ol/map](https://openlayers.org/en/latest/apidoc/module-ol_Map-Map.html).\n */\n map: PropTypes.instanceOf(OLMap),\n\n /**\n * Params to be written in url.\n */\n params: PropTypes.object,\n\n /**\n * Custom function to be called when the permalink is updated.\n * This property has priority over the history parameter and window.history.replaceState calls.\n */\n replace: PropTypes.func,\n};\n\nconst defaultProps = {\n coordinateDecimals: 2,\n history: null,\n isBaseLayer: (layer) => {\n return layer.get(\"isBaseLayer\");\n },\n isLayerHidden: () => {\n return false;\n },\n layers: [],\n map: null,\n params: {},\n replace: null,\n};\n\n/**\n * This component handles permalink logic. Injecting an\n * __[ol/map](https://openlayers.org/en/latest/apidoc/module-ol_Map-Map.html)__\n * will add the *map center* (x, y) and the *zoom* (z) parameters to the permalink.\n * Injecting layers will add the *baselayers* and/or *layers* parameters. Further parameters can\n * be added using __params__.\n */\nclass Permalink extends PureComponent {\n constructor(props) {\n super(props);\n this.state = { revision: 0 };\n this.onPropertyChangeKeys = [];\n }\n\n componentDidMount() {\n const { isBaseLayer, isLayerHidden, layers, map } = this.props;\n if (map) {\n this.moveEndRef = map.on(\"moveend\", () => {\n this.onMapMoved();\n });\n }\n\n if (layers) {\n // set layer visibility based on 'layers' parameter.\n const urlParams = new URLSearchParams(window.location.search);\n\n if (urlParams.get(\"layers\")) {\n const visibleLayers = urlParams.get(\"layers\").split(\",\");\n getLayersAsFlatArray(layers).forEach((l) => {\n if (visibleLayers.includes(l.key)) {\n if (l.setVisible) {\n l.setVisible(true);\n } else {\n // eslint-disable-next-line no-param-reassign\n l.visible = true;\n }\n } else if (\n !isBaseLayer(l) &&\n !isLayerHidden(l) &&\n !l.children.some((ll) => {\n return ll.visible;\n })\n ) {\n if (l.setVisible) {\n l.setVisible(false);\n } else {\n // eslint-disable-next-line no-param-reassign\n l.visible = false;\n }\n }\n });\n }\n\n // Set baser layer visibility based on 'baseLayers' parameter.\n // Show the first of the list then hide the others\n const visibleBaseLayer = (urlParams.get(\"baselayers\") || \"\").split(\n \",\",\n )[0];\n if (visibleBaseLayer) {\n getLayersAsFlatArray(layers)\n .filter(isBaseLayer)\n .forEach((baseLayer) => {\n const visible = baseLayer.key === visibleBaseLayer;\n if (baseLayer.setVisible) {\n baseLayer.setVisible(visible);\n } else {\n // eslint-disable-next-line no-param-reassign\n baseLayer.visible = visible;\n }\n });\n }\n this.updateLayers();\n }\n }\n\n componentDidUpdate(prevProps, prevState) {\n const { layers, map } = this.props;\n const { revision } = this.state;\n\n if (layers !== prevProps.layers || revision !== prevState.revision) {\n this.updateLayers();\n }\n\n if (map !== prevProps.map) {\n unByKey(this.moveEndRef);\n this.moveEndRef = map.on(\"moveend\", () => {\n return this.onMapMoved();\n });\n }\n\n this.updateHistory();\n }\n\n componentWillUnmount() {\n const { map } = this.props;\n\n if (map) {\n unByKey(this.moveEndRef);\n }\n unByKey(this.onPropertyChangeKeys);\n this.onPropertyChangeKeys = [];\n }\n\n onMapMoved() {\n const { map } = this.props;\n const mapView = map.getView();\n const center = mapView.getCenter();\n const params = {};\n\n if (\n center !== undefined &&\n center[0] !== undefined &&\n center[1] !== undefined\n ) {\n params.x = this.roundCoord(center[0]);\n params.y = this.roundCoord(center[1]);\n }\n\n this.setState({\n ...params,\n // rounds zoom to two digits max.\n z: +`${Math.round(`${parseFloat(mapView.getZoom())}e+2`)}e-2`,\n });\n }\n\n render() {\n return null;\n }\n\n roundCoord(val) {\n const { coordinateDecimals } = this.props;\n return parseFloat(val.toFixed(coordinateDecimals));\n }\n\n updateHistory() {\n const { history, params, replace } = this.props;\n const oldParams = new URLSearchParams(window.location.search);\n const parameters = {\n ...Object.fromEntries(oldParams.entries()),\n ...this.state,\n ...params,\n };\n\n delete parameters.revision;\n\n // Remove parameters that are undefined or null\n Object.entries(parameters).forEach(([key, value]) => {\n if (value === undefined || value === null) {\n delete parameters[key];\n }\n });\n\n // We don't encode the , to leave the permalink lisible\n const qStr = new URLSearchParams(parameters)\n .toString()\n .replace(/%2C/g, \",\");\n const search = qStr ? `?${qStr}` : \"\";\n\n if (\n (!qStr && window.location.search) ||\n (qStr && search !== window.location.search)\n ) {\n if (replace) {\n replace({ parameters, search });\n } else if (history) {\n history.replace({ search });\n } else {\n const { hash } = window.location;\n window.history.replaceState(\n undefined,\n undefined,\n `${search}${hash || \"\"}`,\n );\n }\n }\n }\n\n updateLayers() {\n const { isBaseLayer, isLayerHidden, layers } = this.props;\n const { revision } = this.state;\n\n unByKey(this.onPropertyChangeKeys);\n this.onPropertyChangeKeys = getLayersAsFlatArray(layers).map((layer) => {\n return layer.on(\"change:visible\", () => {\n this.setState({ revision: revision + 1 });\n });\n });\n\n // layers param\n let layersParam;\n if (layers.length) {\n layersParam = getLayersAsFlatArray(layers)\n .filter((l) => {\n const children = l.children || [];\n const allChildrenHidden = children.every((child) => {\n return isLayerHidden(child);\n });\n const hasVisibleChildren = children.some((child) => {\n return child.visible;\n });\n return (\n !isBaseLayer(l) &&\n !isLayerHidden(l) &&\n l.visible &&\n (!hasVisibleChildren || allChildrenHidden)\n );\n })\n .map((l) => {\n return l.key;\n })\n .join();\n }\n\n // baselayers param\n let baseLayersParam;\n const baseLayers = getLayersAsFlatArray(layers).filter(isBaseLayer);\n if (baseLayers.length) {\n // First baselayers in order of visibility, top layer is first\n const visibleBaseLayers = (\n baseLayers.filter((l) => {\n return l.visible;\n }) || []\n ).reverse();\n const nonVisibleBaseLayers =\n baseLayers.filter((l) => {\n return !l.visible;\n }) || [];\n baseLayersParam = [...visibleBaseLayers, ...nonVisibleBaseLayers]\n .sort((a, b) => {\n if (a.visible === b.visible) {\n return 0;\n }\n if (a.visible && !b.visible) {\n return -1;\n }\n return 1;\n })\n .map((l) => {\n return l.key;\n })\n .join();\n }\n\n // Only add parameters if there is actually some layers added.\n this.setState({\n baselayers: baseLayersParam,\n layers: layersParam,\n });\n }\n}\n\nPermalink.propTypes = propTypes;\nPermalink.defaultProps = defaultProps;\n\nexport default Permalink;\n"],
5
+ "mappings": "AAAA,SAAS,sBAAsB,aAAa;AAC5C,OAAO,WAAW;AAClB,SAAS,eAAe;AACxB,OAAO,eAAe;AACtB,SAAS,qBAAqB;AAE9B,MAAM,YAAY;AAAA;AAAA;AAAA;AAAA,EAIhB,oBAAoB,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ9B,SAAS,UAAU,MAAM;AAAA,IACvB,SAAS,UAAU;AAAA,EACrB,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASD,aAAa,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASvB,eAAe,UAAU;AAAA;AAAA;AAAA;AAAA,EAKzB,QAAQ,UAAU,QAAQ,UAAU,WAAW,KAAK,CAAC;AAAA;AAAA;AAAA;AAAA,EAKrD,KAAK,UAAU,WAAW,KAAK;AAAA;AAAA;AAAA;AAAA,EAK/B,QAAQ,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA,EAMlB,SAAS,UAAU;AACrB;AAEA,M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AS;AAC3B,iBAAO;AAAA,QACT;AACA,eAAO;AAAA,MACT,CAAC,EACA,IAAI,CAAC,MAAM;AACV,eAAO,EAAE;AAAA,MACX,CAAC,EACA,KAAK;AAAA,IACV;AAGA,SAAK,SAAS;AAAA,MACZ,YAAY;AAAA,MACZ,QAAQ;AAAA,IACV,CAAC;AAAA,EACH;AACF;AAEA,UAAU,YAAY;AACtB,UAAU,eAAe;AAEzB,eAAe;",
6
6
  "names": []
7
7
  }
@@ -1,19 +1,19 @@
1
- import React, { PureComponent } from "react";
2
- import PropTypes from "prop-types";
3
- import { MdClose } from "react-icons/md";
4
- import OLMap from "ol/Map";
5
- import Feature from "ol/Feature";
6
1
  import { getCenter } from "ol/extent";
2
+ import Feature from "ol/Feature";
3
+ import OLMap from "ol/Map";
7
4
  import { unByKey } from "ol/Observable";
5
+ import PropTypes from "prop-types";
6
+ import React, { PureComponent } from "react";
7
+ import { MdClose } from "react-icons/md";
8
8
  const propTypes = {
9
9
  /**
10
10
  * React Children.
11
11
  */
12
12
  children: PropTypes.node.isRequired,
13
13
  /**
14
- * An [ol/map](https://openlayers.org/en/latest/apidoc/module-ol_Map-Map.html).
14
+ * Class name of the popup.
15
15
  */
16
- map: PropTypes.instanceOf(OLMap).isRequired,
16
+ className: PropTypes.string,
17
17
  /**
18
18
  * An [ol/Feature](https://openlayers.org/en/latest/apidoc/module-ol_Feature-Feature.html).
19
19
  */
@@ -22,6 +22,14 @@ const propTypes = {
22
22
  * Popup title.
23
23
  */
24
24
  header: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),
25
+ /**
26
+ * An [ol/map](https://openlayers.org/en/latest/apidoc/module-ol_Map-Map.html).
27
+ */
28
+ map: PropTypes.instanceOf(OLMap).isRequired,
29
+ /**
30
+ * Function triggered on close button click.
31
+ */
32
+ onCloseClick: PropTypes.func,
25
33
  /**
26
34
  * If true, the popup is panned in the map's viewport.
27
35
  */
@@ -36,85 +44,77 @@ const propTypes = {
36
44
  */
37
45
  popupCoordinate: PropTypes.arrayOf(PropTypes.number),
38
46
  /**
39
- * Class name of the popup.
40
- */
41
- className: PropTypes.string,
42
- /**
43
- * Title HTML attributes.
44
- */
45
- titles: PropTypes.shape({
46
- closeButton: PropTypes.string
47
- }),
48
- /**
49
- * Function triggered on close button click.
47
+ * Render the close button
50
48
  */
51
- onCloseClick: PropTypes.func,
49
+ renderCloseButton: PropTypes.func,
52
50
  /**
53
- * HTML tabIndex attribute.
51
+ * Render the footer
54
52
  */
55
- tabIndex: PropTypes.string,
53
+ renderFooter: PropTypes.func,
56
54
  /**
57
55
  * Render the header
58
56
  */
59
57
  renderHeader: PropTypes.func,
60
58
  /**
61
- * Render the close button
59
+ * HTML tabIndex attribute.
62
60
  */
63
- renderCloseButton: PropTypes.func,
61
+ tabIndex: PropTypes.string,
64
62
  /**
65
- * Render the footer
63
+ * Title HTML attributes.
66
64
  */
67
- renderFooter: PropTypes.func
65
+ titles: PropTypes.shape({
66
+ closeButton: PropTypes.string
67
+ })
68
68
  };
69
69
  const defaultProps = {
70
- header: null,
70
+ className: "rs-popup",
71
71
  feature: null,
72
+ header: null,
73
+ onCloseClick: () => {
74
+ },
72
75
  panIntoView: false,
73
76
  panRect: null,
74
77
  popupCoordinate: null,
75
- className: "rs-popup",
76
- tabIndex: "",
77
- titles: { closeButton: "Close" },
78
- onCloseClick: () => {
79
- },
80
- renderHeader: null,
81
78
  renderCloseButton: null,
82
79
  renderFooter: () => {
83
80
  return null;
84
- }
81
+ },
82
+ renderHeader: null,
83
+ tabIndex: "",
84
+ titles: { closeButton: "Close" }
85
85
  };
86
86
  class Popup extends PureComponent {
87
- static renderHeader(props) {
88
- const { header, renderCloseButton } = props;
89
- return /* @__PURE__ */ React.createElement("div", { className: "rs-popup-header" }, header, (renderCloseButton || Popup.renderCloseButton)(props));
87
+ constructor(props) {
88
+ super(props);
89
+ this.state = {
90
+ left: 0,
91
+ popupElement: null,
92
+ top: 0
93
+ };
94
+ this.postrenderKey = null;
90
95
  }
91
96
  static renderCloseButton({ onCloseClick, titles }) {
92
97
  return /* @__PURE__ */ React.createElement(
93
98
  "div",
94
99
  {
95
- role: "button",
96
- tabIndex: 0,
97
- className: "rs-popup-close-bt",
98
- title: titles.closeButton,
99
100
  "aria-label": titles.closeButton,
101
+ className: "rs-popup-close-bt",
100
102
  onClick: () => {
101
103
  return onCloseClick();
102
104
  },
103
105
  onKeyPress: (evt) => {
104
106
  return evt.which === 13 && onCloseClick();
105
- }
107
+ },
108
+ role: "button",
109
+ tabIndex: 0,
110
+ title: titles.closeButton
106
111
  },
107
112
  /* @__PURE__ */ React.createElement(MdClose, { focusable: false })
108
113
  );
109
114
  }
110
- constructor(props) {
111
- super(props);
112
- this.state = {
113
- popupElement: null,
114
- top: 0,
115
- left: 0
116
- };
117
- this.postrenderKey = null;
115
+ static renderHeader(props) {
116
+ const { header, renderCloseButton } = props;
117
+ return /* @__PURE__ */ React.createElement("div", { className: "rs-popup-header" }, header, (renderCloseButton || Popup.renderCloseButton)(props));
118
118
  }
119
119
  componentDidMount() {
120
120
  const { map } = this.props;
@@ -160,32 +160,16 @@ class Popup extends PureComponent {
160
160
  map.getView().animate({ center: newCenter, duration: 500 });
161
161
  }
162
162
  }
163
- updatePixelPosition() {
164
- const { map, feature, popupCoordinate } = this.props;
165
- let coord = popupCoordinate;
166
- if (feature && !coord) {
167
- coord = getCenter(feature.getGeometry().getExtent());
168
- }
169
- if (coord) {
170
- const pos = map.getPixelFromCoordinate(coord);
171
- if (pos && pos.length === 2) {
172
- this.setState({
173
- left: pos[0],
174
- top: pos[1]
175
- });
176
- }
177
- }
178
- }
179
163
  render() {
180
164
  const {
181
- feature,
182
- popupCoordinate,
183
165
  children,
166
+ feature,
184
167
  header,
185
- titles,
186
- tabIndex,
187
- renderHeader,
168
+ popupCoordinate,
188
169
  renderFooter,
170
+ renderHeader,
171
+ tabIndex,
172
+ titles,
189
173
  ...other
190
174
  } = this.props;
191
175
  if (!feature && !popupCoordinate) {
@@ -197,7 +181,7 @@ class Popup extends PureComponent {
197
181
  delete other.header;
198
182
  delete other.onCloseClick;
199
183
  delete other.renderCloseButton;
200
- const { top, left } = this.state;
184
+ const { left, top } = this.state;
201
185
  const key = feature ? feature.getId() : popupCoordinate.join();
202
186
  return /* @__PURE__ */ React.createElement(
203
187
  "div",
@@ -213,11 +197,11 @@ class Popup extends PureComponent {
213
197
  "div",
214
198
  {
215
199
  className: "rs-popup-container",
216
- tabIndex,
217
200
  key,
218
201
  ref: (popupElement) => {
219
202
  this.setState({ popupElement });
220
- }
203
+ },
204
+ tabIndex
221
205
  },
222
206
  (renderHeader || Popup.renderHeader)(this.props),
223
207
  /* @__PURE__ */ React.createElement("div", { className: "rs-popup-body" }, children),
@@ -225,6 +209,22 @@ class Popup extends PureComponent {
225
209
  )
226
210
  );
227
211
  }
212
+ updatePixelPosition() {
213
+ const { feature, map, popupCoordinate } = this.props;
214
+ let coord = popupCoordinate;
215
+ if (feature && !coord) {
216
+ coord = getCenter(feature.getGeometry().getExtent());
217
+ }
218
+ if (coord) {
219
+ const pos = map.getPixelFromCoordinate(coord);
220
+ if (pos && pos.length === 2) {
221
+ this.setState({
222
+ left: pos[0],
223
+ top: pos[1]
224
+ });
225
+ }
226
+ }
227
+ }
228
228
  }
229
229
  Popup.propTypes = propTypes;
230
230
  Popup.defaultProps = defaultProps;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/components/Popup/Popup.js"],
4
- "sourcesContent": ["import React, { PureComponent } from \"react\";\nimport PropTypes from \"prop-types\";\n\nimport { MdClose } from \"react-icons/md\";\nimport OLMap from \"ol/Map\";\nimport Feature from \"ol/Feature\";\nimport { getCenter } from \"ol/extent\";\nimport { unByKey } from \"ol/Observable\";\n\nconst propTypes = {\n /**\n * React Children.\n */\n children: PropTypes.node.isRequired,\n\n /**\n * An [ol/map](https://openlayers.org/en/latest/apidoc/module-ol_Map-Map.html).\n */\n map: PropTypes.instanceOf(OLMap).isRequired,\n\n /**\n * An [ol/Feature](https://openlayers.org/en/latest/apidoc/module-ol_Feature-Feature.html).\n */\n feature: PropTypes.instanceOf(Feature),\n\n /**\n * Popup title.\n */\n header: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),\n\n /**\n * If true, the popup is panned in the map's viewport.\n */\n panIntoView: PropTypes.bool,\n\n /**\n * Custom BoundingClientRect to fit popup into.\n * Use if panIntoView is true. Default is the map's BoundingClientRect.\n */\n panRect: PropTypes.objectOf(PropTypes.number),\n\n /**\n * Coordinate position of the popup.\n */\n popupCoordinate: PropTypes.arrayOf(PropTypes.number),\n\n /**\n * Class name of the popup.\n */\n className: PropTypes.string,\n\n /**\n * Title HTML attributes.\n */\n titles: PropTypes.shape({\n closeButton: PropTypes.string,\n }),\n\n /**\n * Function triggered on close button click.\n */\n onCloseClick: PropTypes.func,\n\n /**\n * HTML tabIndex attribute.\n */\n tabIndex: PropTypes.string,\n\n /**\n * Render the header\n */\n renderHeader: PropTypes.func,\n\n /**\n * Render the close button\n */\n renderCloseButton: PropTypes.func,\n\n /**\n * Render the footer\n */\n renderFooter: PropTypes.func,\n};\n\nconst defaultProps = {\n header: null,\n feature: null,\n panIntoView: false,\n panRect: null,\n popupCoordinate: null,\n className: \"rs-popup\",\n tabIndex: \"\",\n titles: { closeButton: \"Close\" },\n onCloseClick: () => {},\n renderHeader: null,\n renderCloseButton: null,\n renderFooter: () => {\n return null;\n },\n};\n\n/**\n * The Popup component renders a popup over an\n * [ol/Feature](https://openlayers.org/en/latest/apidoc/module-ol_Feature-Feature.html)\n * on click.\n */\nclass Popup extends PureComponent {\n static renderHeader(props) {\n const { header, renderCloseButton } = props;\n return (\n <div className=\"rs-popup-header\">\n {header}\n {(renderCloseButton || Popup.renderCloseButton)(props)}\n </div>\n );\n }\n\n static renderCloseButton({ onCloseClick, titles }) {\n return (\n <div\n role=\"button\"\n tabIndex={0}\n className=\"rs-popup-close-bt\"\n title={titles.closeButton}\n aria-label={titles.closeButton}\n onClick={() => {\n return onCloseClick();\n }}\n onKeyPress={(evt) => {\n return evt.which === 13 && onCloseClick();\n }}\n >\n <MdClose focusable={false} />\n </div>\n );\n }\n\n constructor(props) {\n super(props);\n this.state = {\n popupElement: null,\n top: 0,\n left: 0,\n };\n this.postrenderKey = null;\n }\n\n componentDidMount() {\n const { map } = this.props;\n this.updatePixelPosition();\n\n this.postrenderKey = map.on(\"postrender\", () => {\n this.updatePixelPosition();\n });\n }\n\n componentDidUpdate(prevProps, prevState) {\n const { feature, panIntoView, popupCoordinate } = this.props;\n const { popupElement } = this.state;\n if (\n feature !== prevProps.feature ||\n popupCoordinate !== prevProps.popupCoordinate\n ) {\n this.updatePixelPosition();\n }\n\n if (\n panIntoView &&\n popupElement &&\n popupElement !== prevState.popupElement\n ) {\n this.panIntoView();\n }\n }\n\n componentWillUnmount() {\n unByKey(this.postrenderKey);\n }\n\n panIntoView() {\n const { map, panRect } = this.props;\n const { popupElement } = this.state;\n\n const mapRect = panRect || map.getTarget().getBoundingClientRect();\n const popupRect = popupElement.getBoundingClientRect();\n const [x, y] = map.getView().getCenter();\n const res = map.getView().getResolution();\n const newCenter = [x, y];\n\n if (mapRect.top > popupRect.top) {\n newCenter[1] = y + (mapRect.top - popupRect.top) * res;\n }\n\n if (mapRect.left > popupRect.left) {\n newCenter[0] = x - (mapRect.left - popupRect.left) * res;\n }\n\n if (mapRect.right < popupRect.right) {\n newCenter[0] = x + (popupRect.right - mapRect.right) * res;\n }\n\n if (mapRect.bottom < popupRect.bottom) {\n newCenter[1] = y - (popupRect.bottom - mapRect.bottom) * res;\n }\n\n if (newCenter[0] !== x || newCenter[1] !== y) {\n map.getView().animate({ center: newCenter, duration: 500 });\n }\n }\n\n updatePixelPosition() {\n const { map, feature, popupCoordinate } = this.props;\n let coord = popupCoordinate;\n\n if (feature && !coord) {\n coord = getCenter(feature.getGeometry().getExtent());\n }\n\n if (coord) {\n const pos = map.getPixelFromCoordinate(coord);\n\n if (pos && pos.length === 2) {\n this.setState({\n left: pos[0],\n top: pos[1],\n });\n }\n }\n }\n\n render() {\n const {\n feature,\n popupCoordinate,\n children,\n header,\n titles,\n tabIndex,\n renderHeader,\n renderFooter,\n ...other\n } = this.props;\n\n if (!feature && !popupCoordinate) {\n return null;\n }\n\n delete other.panIntoView;\n delete other.panRect;\n delete other.map;\n delete other.header;\n delete other.onCloseClick;\n delete other.renderCloseButton;\n\n const { top, left } = this.state;\n\n // force re-render if the feature or the coordinate changes.\n // this is needed to update the popupElement ref\n const key = feature ? feature.getId() : popupCoordinate.join();\n return (\n <div\n className=\"rs-popup\"\n style={{\n left,\n top,\n }}\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...other}\n >\n <div\n className=\"rs-popup-container\"\n tabIndex={tabIndex}\n key={key}\n ref={(popupElement) => {\n this.setState({ popupElement });\n }}\n >\n {(renderHeader || Popup.renderHeader)(this.props)}\n <div className=\"rs-popup-body\">{children}</div>\n {renderFooter(this.props)}\n </div>\n </div>\n );\n }\n}\n\nPopup.propTypes = propTypes;\nPopup.defaultProps = defaultProps;\n\nexport default Popup;\n"],
5
- "mappings": "AAAA,OAAO,SAAS,qBAAqB;AACrC,OAAO,eAAe;AAEtB,SAAS,eAAe;AACxB,OAAO,WAAW;AAClB,OAAO,aAAa;AACpB,SAAS,iBAAiB;AAC1B,SAAS,eAAe;AAExB,MAAM,YAAY;AAAA;AAAA;AAAA;AAAA,EAIhB,UAAU,UAAU,KAAK;AAAA;AAAA;AAAA;AAAA,EAKzB,KAAK,UAAU,WAAW,KAAK,EAAE;AAAA;AAAA;AAAA;AAAA,EAKjC,SAAS,UAAU,WAAW,OAAO;AAAA;AAAA;AAAA;AAAA,EAKrC,QAAQ,UAAU,UAAU,CAAC,UAAU,QAAQ,UAAU,OAAO,CAAC;AAAA;AAAA;AAAA;AAAA,EAKjE,aAAa,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA,EAMvB,SAAS,UAAU,SAAS,UAAU,MAAM;AAAA;AAAA;AAAA;AAAA,EAK5C,iBAAiB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AA;AAAA,QACC,WAAU;AAAA,QACV,OAAO;AAAA,UACL;AAAA,UACA;AAAA,QACF;AAAA,QAEC,GAAG;AAAA;AAAA,MAEJ;AAAA,QAAC;AAAA;AAAA,UACC,WAAU;AAAA,UACV;AAAA,UACA;AAAA,UACA,KAAK,CAAC,iBAAiB;AACrB,iBAAK,SAAS,EAAE,aAAa,CAAC;AAAA,UAChC;AAAA;AAAA,SAEE,gBAAgB,MAAM,cAAc,KAAK,KAAK;AAAA,QAChD,oCAAC,SAAI,WAAU,mBAAiB,QAAS;AAAA,QACxC,aAAa,KAAK,KAAK;AAAA,MAC1B;AAAA,IACF;AAAA,EAEJ;AACF;AAEA,MAAM,YAAY;AAClB,MAAM,eAAe;AAErB,eAAe;",
4
+ "sourcesContent": ["import { getCenter } from \"ol/extent\";\nimport Feature from \"ol/Feature\";\nimport OLMap from \"ol/Map\";\nimport { unByKey } from \"ol/Observable\";\nimport PropTypes from \"prop-types\";\nimport React, { PureComponent } from \"react\";\nimport { MdClose } from \"react-icons/md\";\n\nconst propTypes = {\n /**\n * React Children.\n */\n children: PropTypes.node.isRequired,\n\n /**\n * Class name of the popup.\n */\n className: PropTypes.string,\n\n /**\n * An [ol/Feature](https://openlayers.org/en/latest/apidoc/module-ol_Feature-Feature.html).\n */\n feature: PropTypes.instanceOf(Feature),\n\n /**\n * Popup title.\n */\n header: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),\n\n /**\n * An [ol/map](https://openlayers.org/en/latest/apidoc/module-ol_Map-Map.html).\n */\n map: PropTypes.instanceOf(OLMap).isRequired,\n\n /**\n * Function triggered on close button click.\n */\n onCloseClick: PropTypes.func,\n\n /**\n * If true, the popup is panned in the map's viewport.\n */\n panIntoView: PropTypes.bool,\n\n /**\n * Custom BoundingClientRect to fit popup into.\n * Use if panIntoView is true. Default is the map's BoundingClientRect.\n */\n panRect: PropTypes.objectOf(PropTypes.number),\n\n /**\n * Coordinate position of the popup.\n */\n popupCoordinate: PropTypes.arrayOf(PropTypes.number),\n\n /**\n * Render the close button\n */\n renderCloseButton: PropTypes.func,\n\n /**\n * Render the footer\n */\n renderFooter: PropTypes.func,\n\n /**\n * Render the header\n */\n renderHeader: PropTypes.func,\n\n /**\n * HTML tabIndex attribute.\n */\n tabIndex: PropTypes.string,\n\n /**\n * Title HTML attributes.\n */\n titles: PropTypes.shape({\n closeButton: PropTypes.string,\n }),\n};\n\nconst defaultProps = {\n className: \"rs-popup\",\n feature: null,\n header: null,\n onCloseClick: () => {},\n panIntoView: false,\n panRect: null,\n popupCoordinate: null,\n renderCloseButton: null,\n renderFooter: () => {\n return null;\n },\n renderHeader: null,\n tabIndex: \"\",\n titles: { closeButton: \"Close\" },\n};\n\n/**\n * The Popup component renders a popup over an\n * [ol/Feature](https://openlayers.org/en/latest/apidoc/module-ol_Feature-Feature.html)\n * on click.\n */\nclass Popup extends PureComponent {\n constructor(props) {\n super(props);\n this.state = {\n left: 0,\n popupElement: null,\n top: 0,\n };\n this.postrenderKey = null;\n }\n\n static renderCloseButton({ onCloseClick, titles }) {\n return (\n <div\n aria-label={titles.closeButton}\n className=\"rs-popup-close-bt\"\n onClick={() => {\n return onCloseClick();\n }}\n onKeyPress={(evt) => {\n return evt.which === 13 && onCloseClick();\n }}\n role=\"button\"\n tabIndex={0}\n title={titles.closeButton}\n >\n <MdClose focusable={false} />\n </div>\n );\n }\n\n static renderHeader(props) {\n const { header, renderCloseButton } = props;\n return (\n <div className=\"rs-popup-header\">\n {header}\n {(renderCloseButton || Popup.renderCloseButton)(props)}\n </div>\n );\n }\n\n componentDidMount() {\n const { map } = this.props;\n this.updatePixelPosition();\n\n this.postrenderKey = map.on(\"postrender\", () => {\n this.updatePixelPosition();\n });\n }\n\n componentDidUpdate(prevProps, prevState) {\n const { feature, panIntoView, popupCoordinate } = this.props;\n const { popupElement } = this.state;\n if (\n feature !== prevProps.feature ||\n popupCoordinate !== prevProps.popupCoordinate\n ) {\n this.updatePixelPosition();\n }\n\n if (\n panIntoView &&\n popupElement &&\n popupElement !== prevState.popupElement\n ) {\n this.panIntoView();\n }\n }\n\n componentWillUnmount() {\n unByKey(this.postrenderKey);\n }\n\n panIntoView() {\n const { map, panRect } = this.props;\n const { popupElement } = this.state;\n\n const mapRect = panRect || map.getTarget().getBoundingClientRect();\n const popupRect = popupElement.getBoundingClientRect();\n const [x, y] = map.getView().getCenter();\n const res = map.getView().getResolution();\n const newCenter = [x, y];\n\n if (mapRect.top > popupRect.top) {\n newCenter[1] = y + (mapRect.top - popupRect.top) * res;\n }\n\n if (mapRect.left > popupRect.left) {\n newCenter[0] = x - (mapRect.left - popupRect.left) * res;\n }\n\n if (mapRect.right < popupRect.right) {\n newCenter[0] = x + (popupRect.right - mapRect.right) * res;\n }\n\n if (mapRect.bottom < popupRect.bottom) {\n newCenter[1] = y - (popupRect.bottom - mapRect.bottom) * res;\n }\n\n if (newCenter[0] !== x || newCenter[1] !== y) {\n map.getView().animate({ center: newCenter, duration: 500 });\n }\n }\n\n render() {\n const {\n children,\n feature,\n header,\n popupCoordinate,\n renderFooter,\n renderHeader,\n tabIndex,\n titles,\n ...other\n } = this.props;\n\n if (!feature && !popupCoordinate) {\n return null;\n }\n\n delete other.panIntoView;\n delete other.panRect;\n delete other.map;\n delete other.header;\n delete other.onCloseClick;\n delete other.renderCloseButton;\n\n const { left, top } = this.state;\n\n // force re-render if the feature or the coordinate changes.\n // this is needed to update the popupElement ref\n const key = feature ? feature.getId() : popupCoordinate.join();\n return (\n <div\n className=\"rs-popup\"\n style={{\n left,\n top,\n }}\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...other}\n >\n <div\n className=\"rs-popup-container\"\n key={key}\n ref={(popupElement) => {\n this.setState({ popupElement });\n }}\n tabIndex={tabIndex}\n >\n {(renderHeader || Popup.renderHeader)(this.props)}\n <div className=\"rs-popup-body\">{children}</div>\n {renderFooter(this.props)}\n </div>\n </div>\n );\n }\n\n updatePixelPosition() {\n const { feature, map, popupCoordinate } = this.props;\n let coord = popupCoordinate;\n\n if (feature && !coord) {\n coord = getCenter(feature.getGeometry().getExtent());\n }\n\n if (coord) {\n const pos = map.getPixelFromCoordinate(coord);\n\n if (pos && pos.length === 2) {\n this.setState({\n left: pos[0],\n top: pos[1],\n });\n }\n }\n }\n}\n\nPopup.propTypes = propTypes;\nPopup.defaultProps = defaultProps;\n\nexport default Popup;\n"],
5
+ "mappings": "AAAA,SAAS,iBAAiB;AAC1B,OAAO,aAAa;AACpB,OAAO,WAAW;AAClB,SAAS,eAAe;AACxB,OAAO,eAAe;AACtB,OAAO,SAAS,qBAAqB;AACrC,SAAS,eAAe;AAExB,MAAM,YAAY;AAAA;AAAA;AAAA;AAAA,EAIhB,UAAU,UAAU,KAAK;AAAA;AAAA;AAAA;AAAA,EAKzB,WAAW,UAAU;AAAA;AAAA;AAAA;AAAA,EAKrB,SAAS,UAAU,WAAW,OAAO;AAAA;AAAA;AAAA;AAAA,EAKrC,QAAQ,UAAU,UAAU,CAAC,UAAU,QAAQ,UAAU,OAAO,CAAC;AAAA;AAAA;AAAA;AAAA,EAKjE,KAAK,UAAU,WAAW,KAAK,EAAE;AAAA;AAAA;AAAA;AAAA,EAKjC,cAAc,UAAU;AAAA;AAAA;AAAA;AAAA,EAKxB,aAAa,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA,EAMvB,SAAS,UAAU,SAAS,UAAU,MAAM;AAAA;AAAA;AAAA;AAAA,EAK5C,iBAAiB,UAAU,QAAQ,UAAU,MAAM;AAAA;AAAA;AAAA;AAAA,EAKnD,mBAAmB,UAAU;AAAA;AAAA;AAAA;AAAA,EAK7B,cAAc,UAAU;AAAA;AAAA;AAAA;AAAA,EAKxB,cAAc,UAAU;AAAA;AAAA;AAAA;AAAA,EAKxB,UAAU,UAAU;AAAA;AAAA;AAAA;AAAA,EAKpB,QAAQ,UAAU,MAAM;AAAA,IACtB,aAAa,UAAU;AAAA,EACzB,CAAC;AACH;AAEA,MAAM,eAAe;AAAA,EACnB,WAAW;AAAA,EACX,SAAS;A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