react-spatial 1.5.4 → 1.5.5
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/components/BaseLayerSwitcher/BaseLayerSwitcher.js +94 -63
- package/components/BaseLayerSwitcher/BaseLayerSwitcher.js.map +1 -1
- package/components/BaseLayerSwitcher/index.js.map +1 -1
- package/components/BasicMap/BasicMap.js +60 -15
- package/components/BasicMap/BasicMap.js.map +2 -2
- package/components/BasicMap/index.js.map +1 -1
- package/components/CanvasSaveButton/CanvasSaveButton.js +93 -11
- package/components/CanvasSaveButton/CanvasSaveButton.js.map +1 -1
- package/components/CanvasSaveButton/index.js.map +1 -1
- package/components/Copyright/Copyright.js +19 -5
- package/components/Copyright/Copyright.js.map +1 -1
- package/components/Copyright/index.js.map +1 -1
- package/components/FeatureExportButton/FeatureExportButton.js +30 -12
- package/components/FeatureExportButton/FeatureExportButton.js.map +1 -1
- package/components/FeatureExportButton/index.js.map +1 -1
- package/components/FitExtent/FitExtent.js +24 -8
- package/components/FitExtent/FitExtent.js.map +1 -1
- package/components/FitExtent/index.js.map +1 -1
- package/components/Geolocation/Geolocation.js +47 -14
- package/components/Geolocation/Geolocation.js.map +1 -1
- package/components/Geolocation/index.js.map +1 -1
- package/components/LayerTree/LayerTree.js +155 -46
- package/components/LayerTree/LayerTree.js.map +1 -1
- package/components/LayerTree/index.js.map +1 -1
- package/components/MousePosition/MousePosition.js +48 -16
- package/components/MousePosition/MousePosition.js.map +1 -1
- package/components/MousePosition/index.js.map +1 -1
- package/components/NorthArrow/NorthArrow.js +21 -5
- package/components/NorthArrow/NorthArrow.js.map +1 -1
- package/components/NorthArrow/index.js.map +1 -1
- package/components/Overlay/Overlay.js +72 -44
- package/components/Overlay/Overlay.js.map +1 -1
- package/components/Overlay/index.js.map +1 -1
- package/components/Permalink/Permalink.js +37 -0
- package/components/Permalink/Permalink.js.map +1 -1
- package/components/Permalink/index.js.map +1 -1
- package/components/Popup/Popup.js +84 -33
- package/components/Popup/Popup.js.map +1 -1
- package/components/Popup/index.js.map +1 -1
- package/components/ResizeHandler/ResizeHandler.js +1 -0
- package/components/ResizeHandler/ResizeHandler.js.map +1 -1
- package/components/ResizeHandler/index.js.map +1 -1
- package/components/RouteSchedule/RouteSchedule.js +121 -76
- package/components/RouteSchedule/RouteSchedule.js.map +2 -2
- package/components/RouteSchedule/index.js.map +1 -1
- package/components/ScaleLine/ScaleLine.js +8 -5
- package/components/ScaleLine/ScaleLine.js.map +1 -1
- package/components/ScaleLine/index.js.map +1 -1
- package/components/StopsFinder/StopsFinder.js +96 -51
- package/components/StopsFinder/StopsFinder.js.map +1 -1
- package/components/StopsFinder/StopsFinderOption.js +2 -9
- package/components/StopsFinder/StopsFinderOption.js.map +1 -1
- package/components/StopsFinder/index.js.map +1 -1
- package/components/Zoom/Zoom.js +48 -29
- package/components/Zoom/Zoom.js.map +1 -1
- package/components/Zoom/index.js.map +1 -1
- package/package.json +32 -31
- package/propTypes.js +19 -1
- package/propTypes.js.map +2 -2
- package/utils/KML.js +8 -0
- package/utils/KML.js.map +1 -1
- package/utils/KMLFormat.js +32 -4
- package/utils/KMLFormat.js.map +1 -1
- package/utils/getPolygonPattern.js.map +1 -1
- package/utils/timeUtils.js.map +1 -1
|
@@ -3,23 +3,105 @@ import PropTypes from "prop-types";
|
|
|
3
3
|
import { Layer, getLayersAsFlatArray } from "mobility-toolbox-js/ol";
|
|
4
4
|
import { unByKey } from "ol/Observable";
|
|
5
5
|
const propTypes = {
|
|
6
|
+
/**
|
|
7
|
+
* Layers provider.
|
|
8
|
+
*/
|
|
6
9
|
layers: PropTypes.arrayOf(PropTypes.instanceOf(Layer)),
|
|
10
|
+
/**
|
|
11
|
+
* CSS class to apply on the container.
|
|
12
|
+
*/
|
|
7
13
|
className: PropTypes.string,
|
|
14
|
+
/**
|
|
15
|
+
* Padding left to apply on each level.
|
|
16
|
+
*/
|
|
8
17
|
padding: PropTypes.number,
|
|
18
|
+
/**
|
|
19
|
+
* Determine if the item is hidden in the tree or not.
|
|
20
|
+
*
|
|
21
|
+
* @param {object} item The item to hide or not.
|
|
22
|
+
*
|
|
23
|
+
* @return {bool} true if the item is not displayed in the tree
|
|
24
|
+
*/
|
|
9
25
|
isItemHidden: PropTypes.func,
|
|
26
|
+
/**
|
|
27
|
+
* Determine the className used by the div containing the parent and its children.
|
|
28
|
+
*/
|
|
10
29
|
getParentClassName: PropTypes.func,
|
|
30
|
+
/**
|
|
31
|
+
* Custom function to render an item in the tree.
|
|
32
|
+
*
|
|
33
|
+
* @param {object} item The item to render.
|
|
34
|
+
*
|
|
35
|
+
* @return {node} A jsx node.
|
|
36
|
+
*/
|
|
11
37
|
renderItem: PropTypes.func,
|
|
38
|
+
/**
|
|
39
|
+
* Custom function to render only the content of an item in the tree.
|
|
40
|
+
* inputProps und toggleProps can be used when calling the default renderItemContent function
|
|
41
|
+
* (comp.renderItemContent(layer, inputProps, toggleProps)) to overwrite the default input and label props
|
|
42
|
+
*
|
|
43
|
+
* @param {Layer} layer The layer the item content is created for
|
|
44
|
+
* @param {LayerTree} comp The LayerTree component.
|
|
45
|
+
*
|
|
46
|
+
* @return {node} A jsx node.
|
|
47
|
+
*/
|
|
12
48
|
renderItemContent: PropTypes.func,
|
|
49
|
+
/**
|
|
50
|
+
* Custom function to render custom content before the list of children of an item.
|
|
51
|
+
*
|
|
52
|
+
* @param {object} item The item to render.
|
|
53
|
+
*
|
|
54
|
+
* @return {node} A jsx node.
|
|
55
|
+
*/
|
|
13
56
|
renderBeforeItem: PropTypes.func,
|
|
57
|
+
/**
|
|
58
|
+
* Custom function to render custom content after the list of children of an item.
|
|
59
|
+
*
|
|
60
|
+
* @param {object} item The item to render.
|
|
61
|
+
*
|
|
62
|
+
* @return {node} A jsx node.
|
|
63
|
+
*/
|
|
14
64
|
renderAfterItem: PropTypes.func,
|
|
65
|
+
/**
|
|
66
|
+
* Custom function to render the label.
|
|
67
|
+
*
|
|
68
|
+
* @param {string} item The label to render.
|
|
69
|
+
* @param {LayerTree} comp The LayerTree component.
|
|
70
|
+
*
|
|
71
|
+
* @return {node} A jsx node.
|
|
72
|
+
*/
|
|
15
73
|
renderLabel: PropTypes.func,
|
|
74
|
+
/**
|
|
75
|
+
* Object holding title for the layer tree's buttons.
|
|
76
|
+
*/
|
|
16
77
|
titles: PropTypes.shape({
|
|
78
|
+
/**
|
|
79
|
+
* aria-label on checkbox to show layer.
|
|
80
|
+
*/
|
|
17
81
|
layerShow: PropTypes.string,
|
|
82
|
+
/**
|
|
83
|
+
* aria-label on checkbox to hide layer.
|
|
84
|
+
*/
|
|
18
85
|
layerHide: PropTypes.string,
|
|
86
|
+
/**
|
|
87
|
+
* title on button to show sublayers.
|
|
88
|
+
*/
|
|
19
89
|
subLayerShow: PropTypes.string,
|
|
90
|
+
/**
|
|
91
|
+
* title on button to show sublayers.
|
|
92
|
+
*/
|
|
20
93
|
subLayerHide: PropTypes.string
|
|
21
94
|
}),
|
|
95
|
+
/**
|
|
96
|
+
* Boolean determining whether children collapse/expand when their parent is toggled
|
|
97
|
+
* @param {...(boolean|function)} expandChildren Boolean or function returning a boolean.
|
|
98
|
+
* @return {boolean} True or false
|
|
99
|
+
*/
|
|
22
100
|
expandChildren: PropTypes.oneOfType([PropTypes.bool, PropTypes.func]),
|
|
101
|
+
/**
|
|
102
|
+
* Translation function.
|
|
103
|
+
* @param {function} Translation function returning the translated string.
|
|
104
|
+
*/
|
|
23
105
|
t: PropTypes.func
|
|
24
106
|
};
|
|
25
107
|
const defaultProps = {
|
|
@@ -103,6 +185,13 @@ class LayerTree extends Component {
|
|
|
103
185
|
}
|
|
104
186
|
this.setState({ expandedLayers });
|
|
105
187
|
}
|
|
188
|
+
/**
|
|
189
|
+
* Get the always expanded ancestors (isAlwaysExpanded=true) of the given layers
|
|
190
|
+
* together with the (given) initially expanded layers
|
|
191
|
+
*
|
|
192
|
+
* @param {Layer} layers Initially expanded layers
|
|
193
|
+
* @return {Array.<Layer>} Initially expanded layers and all its always expanded ancestors
|
|
194
|
+
*/
|
|
106
195
|
getExpandedLayers(layers) {
|
|
107
196
|
const { isItemHidden } = this.props;
|
|
108
197
|
const children = layers.flatMap((l) => {
|
|
@@ -163,26 +252,37 @@ class LayerTree extends Component {
|
|
|
163
252
|
tabIndex = -1;
|
|
164
253
|
}
|
|
165
254
|
const inputType = layer.get("group") ? "radio" : "checkbox";
|
|
166
|
-
return
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
255
|
+
return (
|
|
256
|
+
// eslint-disable-next-line jsx-a11y/label-has-associated-control,jsx-a11y/no-noninteractive-element-interactions
|
|
257
|
+
/* @__PURE__ */ React.createElement(
|
|
258
|
+
"label",
|
|
259
|
+
{
|
|
260
|
+
className: `rs-layer-tree-input rs-layer-tree-input-${inputType} rs-${inputType}`,
|
|
261
|
+
tabIndex,
|
|
262
|
+
title: layer.visible ? titles.layerHide : titles.layerShow,
|
|
263
|
+
"aria-label": layer.visible ? titles.layerHide : titles.layerShow,
|
|
264
|
+
onKeyPress: (e) => {
|
|
265
|
+
if (e.which === 13) {
|
|
266
|
+
this.onInputClick(layer);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
},
|
|
270
|
+
/* @__PURE__ */ React.createElement(
|
|
271
|
+
"input",
|
|
272
|
+
{
|
|
273
|
+
type: inputType,
|
|
274
|
+
tabIndex: -1,
|
|
275
|
+
checked: layer.visible,
|
|
276
|
+
readOnly: true,
|
|
277
|
+
onClick: () => {
|
|
278
|
+
return this.onInputClick(layer);
|
|
279
|
+
},
|
|
280
|
+
...inputProps
|
|
281
|
+
}
|
|
282
|
+
),
|
|
283
|
+
/* @__PURE__ */ React.createElement("span", null)
|
|
284
|
+
)
|
|
285
|
+
);
|
|
186
286
|
}
|
|
187
287
|
renderArrow(layer) {
|
|
188
288
|
const { isItemHidden } = this.props;
|
|
@@ -192,10 +292,15 @@ class LayerTree extends Component {
|
|
|
192
292
|
}).length || layer.get("isAlwaysExpanded")) {
|
|
193
293
|
return null;
|
|
194
294
|
}
|
|
195
|
-
return /* @__PURE__ */ React.createElement(
|
|
196
|
-
|
|
197
|
-
|
|
295
|
+
return /* @__PURE__ */ React.createElement(
|
|
296
|
+
"div",
|
|
297
|
+
{
|
|
298
|
+
className: `rs-layer-tree-arrow rs-layer-tree-arrow-${!expandedLayers.includes(layer) ? "collapsed" : "expanded"}`
|
|
299
|
+
}
|
|
300
|
+
);
|
|
198
301
|
}
|
|
302
|
+
// Render a button which expands/collapse the layer if there is children
|
|
303
|
+
// or simulate a click on the input otherwise.
|
|
199
304
|
renderToggleButton(layer, toggleProps) {
|
|
200
305
|
const { t, titles, isItemHidden, renderLabel } = this.props;
|
|
201
306
|
const { expandedLayers } = this.state;
|
|
@@ -208,17 +313,22 @@ class LayerTree extends Component {
|
|
|
208
313
|
);
|
|
209
314
|
};
|
|
210
315
|
const title = `${t(layer.name)} ${expandedLayers.includes(layer) ? titles.subLayerHide : titles.subLayerShow}`;
|
|
211
|
-
return /* @__PURE__ */ React.createElement(
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
316
|
+
return /* @__PURE__ */ React.createElement(
|
|
317
|
+
"div",
|
|
318
|
+
{
|
|
319
|
+
role: "button",
|
|
320
|
+
tabIndex: 0,
|
|
321
|
+
className: "rs-layer-tree-toggle",
|
|
322
|
+
title,
|
|
323
|
+
"aria-expanded": expandedLayers.includes(layer),
|
|
324
|
+
"aria-label": title,
|
|
325
|
+
onClick: onInputClick,
|
|
326
|
+
onKeyPress: onInputClick,
|
|
327
|
+
...toggleProps
|
|
328
|
+
},
|
|
329
|
+
/* @__PURE__ */ React.createElement("div", null, renderLabel(layer, this)),
|
|
330
|
+
this.renderArrow(layer)
|
|
331
|
+
);
|
|
222
332
|
}
|
|
223
333
|
renderItemContent(layer, inputProps = {}, toggleProps = {}) {
|
|
224
334
|
return /* @__PURE__ */ React.createElement(React.Fragment, null, this.renderInput(layer, inputProps), this.renderToggleButton(layer, toggleProps));
|
|
@@ -242,15 +352,16 @@ class LayerTree extends Component {
|
|
|
242
352
|
if (renderItem) {
|
|
243
353
|
return renderItem(layer, this.onInputClick, this.onToggle);
|
|
244
354
|
}
|
|
245
|
-
return /* @__PURE__ */ React.createElement("div", {
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
}
|
|
253
|
-
|
|
355
|
+
return /* @__PURE__ */ React.createElement("div", { className: getParentClassName(), key: layer.key }, /* @__PURE__ */ React.createElement(
|
|
356
|
+
"div",
|
|
357
|
+
{
|
|
358
|
+
className: `rs-layer-tree-item ${layer.visible ? "rs-visible" : ""}`,
|
|
359
|
+
style: {
|
|
360
|
+
paddingLeft: `${padding * level}px`
|
|
361
|
+
}
|
|
362
|
+
},
|
|
363
|
+
renderItemContent ? renderItemContent(layer, this) : this.renderItemContent(layer)
|
|
364
|
+
), renderBeforeItem && renderBeforeItem(layer, level, this), [...children].reverse().map((child) => {
|
|
254
365
|
return this.renderItem(child, level + 1);
|
|
255
366
|
}), renderAfterItem && renderAfterItem(layer, level, this));
|
|
256
367
|
}
|
|
@@ -268,9 +379,7 @@ class LayerTree extends Component {
|
|
|
268
379
|
}
|
|
269
380
|
render() {
|
|
270
381
|
const { className } = this.props;
|
|
271
|
-
return /* @__PURE__ */ React.createElement("div", {
|
|
272
|
-
className
|
|
273
|
-
}, this.renderTree());
|
|
382
|
+
return /* @__PURE__ */ React.createElement("div", { className }, this.renderTree());
|
|
274
383
|
}
|
|
275
384
|
}
|
|
276
385
|
LayerTree.propTypes = propTypes;
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/LayerTree/LayerTree.js"],
|
|
4
4
|
"sourcesContent": ["import React, { Component } from 'react';\nimport PropTypes from 'prop-types';\nimport { Layer, getLayersAsFlatArray } from 'mobility-toolbox-js/ol';\nimport { unByKey } from 'ol/Observable';\n\nconst propTypes = {\n /**\n * Layers provider.\n */\n layers: PropTypes.arrayOf(PropTypes.instanceOf(Layer)),\n\n /**\n * CSS class to apply on the container.\n */\n className: PropTypes.string,\n\n /**\n * Padding left to apply on each level.\n */\n padding: PropTypes.number,\n\n /**\n * Determine if the item is hidden in the tree 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 tree\n */\n isItemHidden: PropTypes.func,\n\n /**\n * Determine the className used by the div containing the parent and its children.\n */\n getParentClassName: PropTypes.func,\n\n /**\n * Custom function to render an item in the tree.\n *\n * @param {object} item The item to render.\n *\n * @return {node} A jsx node.\n */\n renderItem: PropTypes.func,\n\n /**\n * Custom function to render only the content of an item in the tree.\n * inputProps und toggleProps can be used when calling the default renderItemContent function\n * (comp.renderItemContent(layer, inputProps, toggleProps)) to overwrite the default input and label props\n *\n * @param {Layer} layer The layer the item content is created for\n * @param {LayerTree} comp The LayerTree component.\n *\n * @return {node} A jsx node.\n */\n renderItemContent: PropTypes.func,\n\n /**\n * Custom function to render custom content before the list of children of an item.\n *\n * @param {object} item The item to render.\n *\n * @return {node} A jsx node.\n */\n renderBeforeItem: PropTypes.func,\n\n /**\n * Custom function to render custom content after the list of children of an item.\n *\n * @param {object} item The item to render.\n *\n * @return {node} A jsx node.\n */\n renderAfterItem: PropTypes.func,\n\n /**\n * Custom function to render the label.\n *\n * @param {string} item The label to render.\n * @param {LayerTree} comp The LayerTree component.\n *\n * @return {node} A jsx node.\n */\n renderLabel: PropTypes.func,\n\n /**\n * Object holding title for the layer tree's buttons.\n */\n titles: PropTypes.shape({\n /**\n * aria-label on checkbox to show layer.\n */\n layerShow: PropTypes.string,\n /**\n * aria-label on checkbox to hide layer.\n */\n layerHide: PropTypes.string,\n /**\n * title on button to show sublayers.\n */\n subLayerShow: PropTypes.string,\n /**\n * title on button to show sublayers.\n */\n subLayerHide: PropTypes.string,\n }),\n\n /**\n * Boolean determining whether children collapse/expand when their parent is toggled\n * @param {...(boolean|function)} expandChildren Boolean or function returning a boolean.\n * @return {boolean} True or false\n */\n expandChildren: PropTypes.oneOfType([PropTypes.bool, PropTypes.func]),\n\n /**\n * Translation function.\n * @param {function} Translation function returning the translated string.\n */\n t: PropTypes.func,\n};\n\nconst defaultProps = {\n layers: [],\n className: 'rs-layer-tree',\n padding: 30,\n isItemHidden: () => {\n return false;\n },\n getParentClassName: () => {\n return undefined;\n },\n renderItem: null,\n renderItemContent: null,\n renderBeforeItem: null,\n renderAfterItem: null,\n renderLabel: (layer, layerComp) => {\n const { t } = layerComp.props;\n return t(layer.name);\n },\n titles: {\n layerShow: 'Show layer',\n layerHide: 'Hide layer',\n subLayerShow: 'Show sublayer',\n subLayerHide: 'Hide sublayer',\n },\n t: (s) => {\n return s;\n },\n expandChildren: false,\n};\n\n/**\n * The LayerTree component renders an interface for toggling\n * [mobility-toolbox-js layers](https://mobility-toolbox-js.geops.io/api/identifiers%20html#ol-layers)\n * and their corresponding child layers.\n */\n\nclass LayerTree extends Component {\n constructor(props) {\n super(props);\n\n const { layers, isItemHidden } = this.props;\n const initialExpandedLayers = layers\n ? this.getExpandedLayers(\n layers.filter((l) => {\n return (\n !isItemHidden(l) &&\n (l.children || [])\n .filter((child) => {\n return child.visible;\n })\n .filter((c) => {\n return !isItemHidden(c);\n }).length\n );\n }),\n )\n : [];\n\n this.state = {\n rootLayer: new Layer(),\n expandedLayers: initialExpandedLayers,\n revision: 0,\n };\n // this.updateLayers = this.updateLayers.bind(this);\n this.olKeys = [];\n }\n\n componentDidMount() {\n this.updateLayers();\n }\n\n componentDidUpdate(prevProps) {\n const { layers } = this.props;\n\n if (layers !== prevProps.layers) {\n this.updateLayers();\n }\n }\n\n componentWillUnmount() {\n unByKey(this.olKeys);\n this.olKeys = [];\n }\n\n onInputClick(layer, toggle = false) {\n if (toggle) {\n this.onToggle(layer);\n } else if (layer.setVisible) {\n layer.setVisible(!layer.visible);\n } else {\n // eslint-disable-next-line no-param-reassign\n layer.visible = !layer.visible;\n }\n }\n\n onToggle(layer) {\n const { expandedLayers } = this.state;\n const pos = expandedLayers.indexOf(layer);\n if (pos > -1) {\n expandedLayers.splice(pos, 1);\n } else {\n expandedLayers.push(...this.getExpandedLayers([layer]));\n }\n this.setState({ expandedLayers });\n }\n\n /**\n * Get the always expanded ancestors (isAlwaysExpanded=true) of the given layers\n * together with the (given) initially expanded layers\n *\n * @param {Layer} layers Initially expanded layers\n * @return {Array.<Layer>} Initially expanded layers and all its always expanded ancestors\n */\n getExpandedLayers(layers) {\n const { isItemHidden } = this.props;\n const children = layers.flatMap((l) => {\n return l.children.filter((c) => {\n return !isItemHidden(c) && c.get('isAlwaysExpanded');\n });\n });\n\n if (!children.length) {\n return layers;\n }\n return [...layers, this.getExpandedLayers(children)].flat();\n }\n\n updateLayers() {\n const { layers, expandChildren } = this.props;\n\n // Update the root layer\n let rootLayer = new Layer();\n if (Array.isArray(layers)) {\n if (layers.length === 1) {\n [rootLayer] = layers;\n }\n rootLayer = new Layer({ children: layers });\n } else {\n rootLayer = layers;\n }\n\n getLayersAsFlatArray(rootLayer).forEach((layer) => {\n this.olKeys.push(\n layer.on('propertychange', () => {\n const { revision } = this.state;\n this.setState({ revision: revision + 1 });\n }),\n );\n });\n\n const state = { rootLayer };\n if (\n typeof expandChildren === 'function'\n ? expandChildren(layers)\n : expandChildren\n ) {\n state.expandedLayers = rootLayer.children.flatMap((l) => {\n return this.expandLayer(l);\n });\n }\n\n this.setState(state);\n }\n\n expandLayer(layer, expLayers = []) {\n const { isItemHidden } = this.props;\n if (layer.visible && !isItemHidden(layer)) {\n const children = layer.children\n .filter((c) => {\n return !isItemHidden(c) && !c.get('isAlwaysExpanded');\n })\n .flatMap((c) => {\n return this.expandLayer(c, expLayers);\n });\n return [...expLayers, ...children, layer];\n }\n return expLayers;\n }\n\n renderInput(layer, inputProps) {\n const { titles, isItemHidden } = this.props;\n let tabIndex = 0;\n\n if (\n !(layer.children || []).filter((c) => {\n return !isItemHidden(c);\n }).length\n ) {\n // We forbid focus on keypress event for first level layers and layers without children.\n tabIndex = -1;\n }\n\n const inputType = layer.get('group') ? 'radio' : 'checkbox';\n return (\n // eslint-disable-next-line jsx-a11y/label-has-associated-control,jsx-a11y/no-noninteractive-element-interactions\n <label\n className={`rs-layer-tree-input rs-layer-tree-input-${inputType} rs-${inputType}`}\n tabIndex={tabIndex}\n title={layer.visible ? titles.layerHide : titles.layerShow}\n aria-label={layer.visible ? titles.layerHide : titles.layerShow}\n onKeyPress={(e) => {\n if (e.which === 13) {\n this.onInputClick(layer);\n }\n }}\n >\n <input\n type={inputType}\n tabIndex={-1}\n checked={layer.visible}\n readOnly\n onClick={() => {\n return this.onInputClick(layer);\n }}\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...inputProps}\n />\n <span />\n </label>\n );\n }\n\n renderArrow(layer) {\n const { isItemHidden } = this.props;\n const { expandedLayers } = this.state;\n\n if (\n !(layer.children || []).filter((c) => {\n return !isItemHidden(c);\n }).length ||\n layer.get('isAlwaysExpanded')\n ) {\n return null;\n }\n\n return (\n <div\n className={`rs-layer-tree-arrow rs-layer-tree-arrow-${\n !expandedLayers.includes(layer) ? 'collapsed' : 'expanded'\n }`}\n />\n );\n }\n\n // Render a button which expands/collapse the layer if there is children\n // or simulate a click on the input otherwise.\n renderToggleButton(layer, toggleProps) {\n const { t, titles, isItemHidden, renderLabel } = this.props;\n const { expandedLayers } = this.state;\n\n const onInputClick = () => {\n this.onInputClick(\n layer,\n (layer.children || []).filter((c) => {\n return !isItemHidden(c);\n }).length && !layer.get('isAlwaysExpanded'),\n );\n };\n const title = `${t(layer.name)} ${\n expandedLayers.includes(layer) ? titles.subLayerHide : titles.subLayerShow\n }`;\n\n return (\n <div\n role=\"button\"\n tabIndex={0}\n className=\"rs-layer-tree-toggle\"\n title={title}\n aria-expanded={expandedLayers.includes(layer)}\n aria-label={title}\n onClick={onInputClick}\n onKeyPress={onInputClick}\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...toggleProps}\n >\n <div>{renderLabel(layer, this)}</div>\n {this.renderArrow(layer)}\n </div>\n );\n }\n\n renderItemContent(layer, inputProps = {}, toggleProps = {}) {\n return (\n <>\n {this.renderInput(layer, inputProps)}\n {this.renderToggleButton(layer, toggleProps)}\n </>\n );\n }\n\n renderItem(layer, level) {\n const { isItemHidden } = this.props;\n const { expandedLayers } = this.state;\n const {\n renderItem,\n renderItemContent,\n renderBeforeItem,\n renderAfterItem,\n padding,\n getParentClassName,\n } = this.props;\n\n const children = expandedLayers.includes(layer)\n ? [\n ...(layer.children || []).filter((c) => {\n return !isItemHidden(c);\n }),\n ]\n : [];\n\n if (renderItem) {\n return renderItem(layer, this.onInputClick, this.onToggle);\n }\n\n return (\n <div className={getParentClassName()} key={layer.key}>\n <div\n className={`rs-layer-tree-item ${layer.visible ? 'rs-visible' : ''}`}\n style={{\n paddingLeft: `${padding * level}px`,\n }}\n >\n {renderItemContent\n ? renderItemContent(layer, this)\n : this.renderItemContent(layer)}\n </div>\n {renderBeforeItem && renderBeforeItem(layer, level, this)}\n {[...children].reverse().map((child) => {\n return this.renderItem(child, level + 1);\n })}\n {renderAfterItem && renderAfterItem(layer, level, this)}\n </div>\n );\n }\n\n renderTree() {\n const { isItemHidden } = this.props;\n const { rootLayer } = this.state;\n\n if (!rootLayer?.children?.length) {\n return null;\n }\n\n return (\n <>\n {rootLayer.children\n .filter((l) => {\n return !isItemHidden(l);\n })\n .reverse()\n .map((l) => {\n return this.renderItem(l, 0);\n })}\n </>\n );\n }\n\n render() {\n const { className } = this.props;\n return <div className={className}>{this.renderTree()}</div>;\n }\n}\n\nLayerTree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DACG,UAAU,SACR,OAAO,CAAC,MAAM;AACb,aAAO,CAAC,aAAa,CAAC;AAAA,IACxB,CAAC,EACA,QAAQ,EACR,IAAI,CAAC,MAAM;AACV,aAAO,KAAK,WAAW,GAAG,CAAC;AAAA,IAC7B,CAAC,CACL;AAAA,EAEJ;AAAA,EAEA,SAAS;AACP,UAAM,EAAE,UAAU,IAAI,KAAK;AAC3B,WAAO,oCAAC,SAAI,aAAuB,KAAK,WAAW,CAAE;AAAA,EACvD;AACF;AAEA,UAAU,YAAY;AACtB,UAAU,eAAe;AAEzB,eAAe;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -4,19 +4,53 @@ import OLMap from "ol/Map";
|
|
|
4
4
|
import { createStringXY } from "ol/coordinate";
|
|
5
5
|
import OLMousePosition from "ol/control/MousePosition";
|
|
6
6
|
const propTypes = {
|
|
7
|
+
/**
|
|
8
|
+
* An [ol/map](https://openlayers.org/en/latest/apidoc/module-ol_Map-Map.html).
|
|
9
|
+
*/
|
|
7
10
|
map: PropTypes.instanceOf(OLMap).isRequired,
|
|
11
|
+
/**
|
|
12
|
+
* List of projections to display.
|
|
13
|
+
*/
|
|
8
14
|
projections: PropTypes.arrayOf(
|
|
9
15
|
PropTypes.shape({
|
|
16
|
+
/**
|
|
17
|
+
* The label to display in the select box.
|
|
18
|
+
*/
|
|
10
19
|
label: PropTypes.string.isRequired,
|
|
20
|
+
/**
|
|
21
|
+
* The value used to create the options´s projection of the MousePosition control.
|
|
22
|
+
* See [doc](https://openlayers.org/en/latest/apidoc/module-ol_control_MousePosition.html).
|
|
23
|
+
*/
|
|
11
24
|
value: PropTypes.string.isRequired,
|
|
25
|
+
/**
|
|
26
|
+
* A function following the [CoordinateFormat](https://openlayers.org/en/latest/apidoc/module-ol_coordinate.html#~CoordinateFormat).
|
|
27
|
+
*/
|
|
12
28
|
format: PropTypes.func
|
|
13
29
|
})
|
|
14
30
|
),
|
|
31
|
+
/**
|
|
32
|
+
* The initially selected projection
|
|
33
|
+
*/
|
|
15
34
|
projectionValue: PropTypes.shape({
|
|
35
|
+
/**
|
|
36
|
+
* The label to display in the select box.
|
|
37
|
+
*/
|
|
16
38
|
label: PropTypes.string.isRequired,
|
|
39
|
+
/**
|
|
40
|
+
* The value used to create the options´s projection of the MousePosition control.
|
|
41
|
+
* See [doc](https://openlayers.org/en/latest/apidoc/module-ol_control_MousePosition.html).
|
|
42
|
+
*/
|
|
17
43
|
value: PropTypes.string.isRequired,
|
|
44
|
+
/**
|
|
45
|
+
* A function following the [CoordinateFormat](https://openlayers.org/en/latest/apidoc/module-ol_coordinate.html#~CoordinateFormat).
|
|
46
|
+
*/
|
|
18
47
|
format: PropTypes.func
|
|
19
48
|
}),
|
|
49
|
+
/**
|
|
50
|
+
* Function triggered on projection's change event.
|
|
51
|
+
* @param {Event} event The change event object.
|
|
52
|
+
* @param {Object} projection The selected projection object.
|
|
53
|
+
*/
|
|
20
54
|
onChange: PropTypes.func
|
|
21
55
|
};
|
|
22
56
|
const defaultProps = {
|
|
@@ -88,22 +122,20 @@ function MousePosition({
|
|
|
88
122
|
if (!projection || !projections || !projections.length) {
|
|
89
123
|
return null;
|
|
90
124
|
}
|
|
91
|
-
return
|
|
92
|
-
|
|
93
|
-
...other
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
className: "rs-coordinates"
|
|
106
|
-
}));
|
|
125
|
+
return (
|
|
126
|
+
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
127
|
+
/* @__PURE__ */ React.createElement("div", { className: "rs-mouse-position", ...other }, /* @__PURE__ */ React.createElement(
|
|
128
|
+
"select",
|
|
129
|
+
{
|
|
130
|
+
className: "rs-select",
|
|
131
|
+
value: projection.value,
|
|
132
|
+
onChange: onChangeCb
|
|
133
|
+
},
|
|
134
|
+
projections.map((option) => {
|
|
135
|
+
return /* @__PURE__ */ React.createElement("option", { key: option.value, value: option.value }, option.label);
|
|
136
|
+
})
|
|
137
|
+
), /* @__PURE__ */ React.createElement("span", { ref, className: "rs-coordinates" }))
|
|
138
|
+
);
|
|
107
139
|
}
|
|
108
140
|
MousePosition.propTypes = propTypes;
|
|
109
141
|
MousePosition.defaultProps = defaultProps;
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/MousePosition/MousePosition.js"],
|
|
4
4
|
"sourcesContent": ["import React, { useState, useRef, useEffect, useCallback } from 'react';\nimport PropTypes from 'prop-types';\nimport OLMap from 'ol/Map';\nimport { createStringXY } from 'ol/coordinate';\nimport OLMousePosition from 'ol/control/MousePosition';\n\nconst propTypes = {\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 * List of projections to display.\n */\n projections: PropTypes.arrayOf(\n PropTypes.shape({\n /**\n * The label to display in the select box.\n */\n label: PropTypes.string.isRequired,\n\n /**\n * The value used to create the options\u00B4s projection of the MousePosition control.\n * See [doc](https://openlayers.org/en/latest/apidoc/module-ol_control_MousePosition.html).\n */\n value: PropTypes.string.isRequired,\n\n /**\n * A function following the [CoordinateFormat](https://openlayers.org/en/latest/apidoc/module-ol_coordinate.html#~CoordinateFormat).\n */\n format: PropTypes.func,\n }),\n ),\n\n /**\n * The initially selected projection\n */\n projectionValue: PropTypes.shape({\n /**\n * The label to display in the select box.\n */\n label: PropTypes.string.isRequired,\n\n /**\n * The value used to create the options\u00B4s projection of the MousePosition control.\n * See [doc](https://openlayers.org/en/latest/apidoc/module-ol_control_MousePosition.html).\n */\n value: PropTypes.string.isRequired,\n\n /**\n * A function following the [CoordinateFormat](https://openlayers.org/en/latest/apidoc/module-ol_coordinate.html#~CoordinateFormat).\n */\n format: PropTypes.func,\n }),\n\n /**\n * Function triggered on projection's change event.\n * @param {Event} event The change event object.\n * @param {Object} projection The selected projection object.\n */\n onChange: PropTypes.func,\n};\n\nconst defaultProps = {\n onChange: () => {},\n projections: [\n {\n label: 'EPSG:4326',\n value: 'EPSG:4326',\n },\n {\n label: 'EPSG:3857',\n value: 'EPSG:3857',\n },\n ],\n projectionValue: null,\n};\n\n/**\n * The MousePosition component renders a select box with map projection options\n * and the cursor position in coordinates using the selected projection.\n */\nfunction MousePosition({\n map,\n projections,\n projectionValue,\n onChange,\n ...other\n}) {\n const [projection, setProjection] = useState(\n projections &&\n ((projectionValue &&\n projections.find((p) => {\n return p.value === projectionValue.value;\n })) ||\n projections[0]),\n );\n const [control, setControl] = useState();\n const ref = useRef();\n\n useEffect(() => {\n const mousePosition = new OLMousePosition({\n target: ref.current,\n undefinedHTML: ' ',\n className: '',\n });\n map.addControl(mousePosition);\n setControl(mousePosition);\n\n return () => {\n map.removeControl(mousePosition);\n };\n }, [map]);\n\n useEffect(() => {\n if (!projection || !control) {\n return;\n }\n control.setProjection(projection.value);\n control.setCoordinateFormat(projection.format || createStringXY(4));\n }, [projection, control]);\n\n useEffect(() => {\n if (projections) {\n const proj =\n (projectionValue &&\n projections.find((p) => {\n return p.value === projectionValue.value;\n })) ||\n projections[0];\n setProjection(proj);\n }\n }, [projections, projectionValue]);\n\n const onChangeCb = useCallback(\n (evt) => {\n const newProj = projections.find((opt) => {\n return evt.target.value === opt.value;\n });\n setProjection(newProj);\n onChange(evt, newProj);\n },\n [onChange, projections],\n );\n\n if (!projection || !projections || !projections.length) {\n return null;\n }\n\n return (\n // eslint-disable-next-line react/jsx-props-no-spreading\n <div className=\"rs-mouse-position\" {...other}>\n <select\n className=\"rs-select\"\n value={projection.value}\n onChange={onChangeCb}\n >\n {projections.map((option) => {\n return (\n <option key={option.value} value={option.value}>\n {option.label}\n </option>\n );\n })}\n </select>\n <span ref={ref} className=\"rs-coordinates\" />\n </div>\n );\n}\n\nMousePosition.propTypes = propTypes;\nMousePosition.defaultProps = defaultProps;\n\nexport default React.memo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,cAAc,WAAW,KAAK;AACtC,YAAQ,oBAAoB,WAAW,UAAU,eAAe,CAAC,CAAC;AAAA,EACpE,GAAG,CAAC,YAAY,OAAO,CAAC;AAExB,YAAU,MAAM;AACd,QAAI,aAAa;AACf,YAAM,OACH,mBACC,YAAY,KAAK,CAAC,MAAM;AACtB,eAAO,EAAE,UAAU,gBAAgB;AAAA,MACrC,CAAC,KACH,YAAY,CAAC;AACf,oBAAc,IAAI;AAAA,IACpB;AAAA,EACF,GAAG,CAAC,aAAa,eAAe,CAAC;AAEjC,QAAM,aAAa;AAAA,IACjB,CAAC,QAAQ;AACP,YAAM,UAAU,YAAY,KAAK,CAAC,QAAQ;AACxC,eAAO,IAAI,OAAO,UAAU,IAAI;AAAA,MAClC,CAAC;AACD,oBAAc,OAAO;AACrB,eAAS,KAAK,OAAO;AAAA,IACvB;AAAA,IACA,CAAC,UAAU,WAAW;AAAA,EACxB;AAEA,MAAI,CAAC,cAAc,CAAC,eAAe,CAAC,YAAY,QAAQ;AACtD,WAAO;AAAA,EACT;AAEA;AAAA;AAAA,IAEE,oCAAC,SAAI,WAAU,qBAAqB,GAAG,SACrC;AAAA,MAAC;AAAA;AAAA,QACC,WAAU;AAAA,QACV,OAAO,WAAW;AAAA,QAClB,UAAU;AAAA;AAAA,MAET,YAAY,IAAI,CAAC,WAAW;AAC3B,eACE,oCAAC,YAAO,KAAK,OAAO,OAAO,OAAO,OAAO,SACtC,OAAO,KACV;AAAA,MAEJ,CAAC;AAAA,IACH,GACA,oCAAC,UAAK,KAAU,WAAU,kBAAiB,CAC7C;AAAA;AAEJ;AAEA,cAAc,YAAY;AAC1B,cAAc,eAAe;AAE7B,eAAe,MAAM,KAAK,aAAa;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -6,9 +6,21 @@ import { toDegrees } from "ol/math";
|
|
|
6
6
|
import NorthArrowSimple from "../../images/northArrow.svg";
|
|
7
7
|
import NorthArrowCircle from "../../images/northArrowCircle.svg";
|
|
8
8
|
const propTypes = {
|
|
9
|
+
/**
|
|
10
|
+
* An [ol/map](https://openlayers.org/en/latest/apidoc/module-ol_Map-Map.html).
|
|
11
|
+
*/
|
|
9
12
|
map: PropTypes.instanceOf(OLMap).isRequired,
|
|
13
|
+
/**
|
|
14
|
+
* Rotation of the north arrow in degrees.
|
|
15
|
+
*/
|
|
10
16
|
rotationOffset: PropTypes.number,
|
|
17
|
+
/**
|
|
18
|
+
* Display circle around the north arrow. Not used if pass children.
|
|
19
|
+
*/
|
|
11
20
|
circled: PropTypes.bool,
|
|
21
|
+
/**
|
|
22
|
+
* Children content of the north arrow.
|
|
23
|
+
*/
|
|
12
24
|
children: PropTypes.node
|
|
13
25
|
};
|
|
14
26
|
const defaultProps = {
|
|
@@ -32,11 +44,15 @@ function NorthArrow({ map, rotationOffset, circled, children, ...other }) {
|
|
|
32
44
|
unByKey(key);
|
|
33
45
|
};
|
|
34
46
|
}, [map, rotationOffset]);
|
|
35
|
-
return /* @__PURE__ */ React.createElement(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
47
|
+
return /* @__PURE__ */ React.createElement(
|
|
48
|
+
"div",
|
|
49
|
+
{
|
|
50
|
+
className: "rs-north-arrow",
|
|
51
|
+
...other,
|
|
52
|
+
style: { transform: `rotate(${rotation}deg)` }
|
|
53
|
+
},
|
|
54
|
+
children || (circled ? /* @__PURE__ */ React.createElement(NorthArrowCircle, null) : /* @__PURE__ */ React.createElement(NorthArrowSimple, null))
|
|
55
|
+
);
|
|
40
56
|
}
|
|
41
57
|
NorthArrow.propTypes = propTypes;
|
|
42
58
|
NorthArrow.defaultProps = defaultProps;
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/NorthArrow/NorthArrow.js"],
|
|
4
4
|
"sourcesContent": ["import React, { useEffect, useState } from 'react';\nimport PropTypes from 'prop-types';\nimport OLMap from 'ol/Map';\nimport { unByKey } from 'ol/Observable';\nimport { toDegrees } from 'ol/math';\nimport NorthArrowSimple from '../../images/northArrow.svg';\nimport NorthArrowCircle from '../../images/northArrowCircle.svg';\n\nconst propTypes = {\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 * Rotation of the north arrow in degrees.\n */\n rotationOffset: PropTypes.number,\n\n /**\n * Display circle around the north arrow. Not used if pass children.\n */\n circled: PropTypes.bool,\n\n /**\n * Children content of the north arrow.\n */\n children: PropTypes.node,\n};\n\nconst defaultProps = {\n rotationOffset: 0,\n circled: false,\n children: null,\n};\n\nconst getRotation = (map, rotationOffset) => {\n return toDegrees(map.getView().getRotation()) + rotationOffset;\n};\n\n/**\n * This NorthArrow component inserts an arrow pointing north into an\n * [ol/map](https://openlayers.org/en/latest/apidoc/module-ol_Map-Map.html).\n */\nfunction NorthArrow({ map, rotationOffset, circled, children, ...other }) {\n const [rotation, setRotation] = useState(rotationOffset);\n\n useEffect(() => {\n if (!map) {\n return null;\n }\n const key = map.on('postrender', () => {\n setRotation(getRotation(map, rotationOffset));\n });\n return () => {\n unByKey(key);\n };\n }, [map, rotationOffset]);\n\n return (\n <div\n className=\"rs-north-arrow\"\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...other}\n style={{ transform: `rotate(${rotation}deg)` }}\n >\n {children || (circled ? <NorthArrowCircle /> : <NorthArrowSimple />)}\n </div>\n );\n}\n\nNorthArrow.propTypes = propTypes;\nNorthArrow.defaultProps = defaultProps;\n\nexport default React.memo(NorthArrow);\n"],
|
|
5
|
-
"mappings": "AAAA,OAAO,SAAS,WAAW,gBAAgB;AAC3C,OAAO,eAAe;AACtB,OAAO,WAAW;AAClB,SAAS,eAAe;AACxB,SAAS,iBAAiB;AAC1B,OAAO,sBAAsB;AAC7B,OAAO,sBAAsB;AAE7B,MAAM,YAAY;AAAA,EAIhB,KAAK,UAAU,WAAW,KAAK,EAAE;AAAA,EAKjC,gBAA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