react-spatial 1.2.2 → 1.2.3-beta.3
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/LayerService.js +128 -184
- package/LayerService.js.map +7 -1
- package/components/BaseLayerSwitcher/BaseLayerSwitcher.js +163 -221
- package/components/BaseLayerSwitcher/BaseLayerSwitcher.js.map +7 -1
- package/components/BaseLayerSwitcher/index.js +1 -3
- package/components/BaseLayerSwitcher/index.js.map +7 -1
- package/components/BasicMap/BasicMap.js +147 -285
- package/components/BasicMap/BasicMap.js.map +7 -1
- package/components/BasicMap/index.js +1 -3
- package/components/BasicMap/index.js.map +7 -1
- package/components/CanvasSaveButton/CanvasSaveButton.js +165 -419
- package/components/CanvasSaveButton/CanvasSaveButton.js.map +7 -1
- package/components/CanvasSaveButton/index.js +1 -3
- package/components/CanvasSaveButton/index.js.map +7 -1
- package/components/Copyright/Copyright.js +29 -70
- package/components/Copyright/Copyright.js.map +7 -1
- package/components/Copyright/index.js +1 -3
- package/components/Copyright/index.js.map +7 -1
- package/components/FeatureExportButton/FeatureExportButton.js +40 -106
- package/components/FeatureExportButton/FeatureExportButton.js.map +7 -1
- package/components/FeatureExportButton/index.js +1 -3
- package/components/FeatureExportButton/index.js.map +7 -1
- package/components/FilterButton/FilterButton.js +41 -106
- package/components/FilterButton/FilterButton.js.map +7 -1
- package/components/FilterButton/index.js +1 -3
- package/components/FilterButton/index.js.map +7 -1
- package/components/FitExtent/FitExtent.js +17 -50
- package/components/FitExtent/FitExtent.js.map +7 -1
- package/components/FitExtent/index.js +1 -3
- package/components/FitExtent/index.js.map +7 -1
- package/components/FollowButton/FollowButton.js +41 -111
- package/components/FollowButton/FollowButton.js.map +7 -1
- package/components/FollowButton/index.js +1 -3
- package/components/FollowButton/index.js.map +7 -1
- package/components/Geolocation/Geolocation.js +104 -213
- package/components/Geolocation/Geolocation.js.map +7 -1
- package/components/Geolocation/index.js +1 -3
- package/components/Geolocation/index.js.map +7 -1
- package/components/LayerTree/LayerTree.js +204 -410
- package/components/LayerTree/LayerTree.js.map +7 -1
- package/components/LayerTree/index.js +1 -3
- package/components/LayerTree/index.js.map +7 -1
- package/components/MousePosition/MousePosition.js +61 -130
- package/components/MousePosition/MousePosition.js.map +7 -1
- package/components/MousePosition/index.js +1 -3
- package/components/MousePosition/index.js.map +7 -1
- package/components/NorthArrow/NorthArrow.js +22 -62
- package/components/NorthArrow/NorthArrow.js.map +7 -1
- package/components/NorthArrow/index.js +1 -3
- package/components/NorthArrow/index.js.map +7 -1
- package/components/Overlay/Overlay.js +83 -130
- package/components/Overlay/Overlay.js.map +7 -1
- package/components/Overlay/index.js +1 -3
- package/components/Overlay/index.js.map +7 -1
- package/components/Permalink/Permalink.js +150 -244
- package/components/Permalink/Permalink.js.map +7 -1
- package/components/Permalink/index.js +1 -3
- package/components/Permalink/index.js.map +7 -1
- package/components/Popup/Popup.js +106 -233
- package/components/Popup/Popup.js.map +7 -1
- package/components/Popup/index.js +1 -3
- package/components/Popup/index.js.map +7 -1
- package/components/ResizeHandler/ResizeHandler.js +58 -113
- package/components/ResizeHandler/ResizeHandler.js.map +7 -1
- package/components/ResizeHandler/index.js +1 -3
- package/components/ResizeHandler/index.js.map +7 -1
- package/components/RouteSchedule/RouteSchedule.js +150 -283
- package/components/RouteSchedule/RouteSchedule.js.map +7 -1
- package/components/RouteSchedule/index.js +1 -3
- package/components/RouteSchedule/index.js.map +7 -1
- package/components/ScaleLine/ScaleLine.js +21 -45
- package/components/ScaleLine/ScaleLine.js.map +7 -1
- package/components/ScaleLine/index.js +1 -3
- package/components/ScaleLine/index.js.map +7 -1
- package/components/Search/Search.js +122 -186
- package/components/Search/Search.js.map +7 -1
- package/components/Search/SearchService.js +45 -69
- package/components/Search/SearchService.js.map +7 -1
- package/components/Search/engines/Engine.js +18 -25
- package/components/Search/engines/Engine.js.map +7 -1
- package/components/Search/engines/StopFinder.js +21 -38
- package/components/Search/engines/StopFinder.js.map +7 -1
- package/components/Search/index.js +3 -6
- package/components/Search/index.js.map +7 -1
- package/components/StopsFinder/StopsFinder.js +123 -174
- package/components/StopsFinder/StopsFinder.js.map +7 -1
- package/components/StopsFinder/StopsFinderOption.js +37 -54
- package/components/StopsFinder/StopsFinderOption.js.map +7 -1
- package/components/StopsFinder/index.js +1 -3
- package/components/StopsFinder/index.js.map +7 -1
- package/components/TrackerControl/TrackerControl.js +73 -128
- package/components/TrackerControl/TrackerControl.js.map +7 -1
- package/components/TrackerControl/index.js +1 -3
- package/components/TrackerControl/index.js.map +7 -1
- package/components/Zoom/Zoom.js +69 -112
- package/components/Zoom/Zoom.js.map +7 -1
- package/components/Zoom/index.js +1 -3
- package/components/Zoom/index.js.map +7 -1
- package/package.json +10 -5
- package/propTypes.js +17 -23
- package/propTypes.js.map +7 -1
- package/setupTests.js +2 -4
- package/setupTests.js.map +7 -1
- package/themes/README.md +26 -0
- package/themes/default/components.scss +0 -1
- package/themes/default/examples.scss +0 -1
- package/utils/GlobalsForOle.js +63 -64
- package/utils/GlobalsForOle.js.map +7 -1
- package/utils/KML.js +178 -364
- package/utils/KML.js.map +7 -1
- package/utils/KMLFormat.js +37 -73
- package/utils/KMLFormat.js.map +7 -1
- package/utils/Styles.js +24 -32
- package/utils/Styles.js.map +7 -1
- package/utils/getPolygonPattern.js +11 -44
- package/utils/getPolygonPattern.js.map +7 -1
- package/utils/timeUtils.js +16 -35
- package/utils/timeUtils.js.map +7 -1
- package/LayerService.test.js +0 -160
- package/LayerService.test.js.map +0 -1
- package/Projections.js +0 -16
- package/Projections.js.map +0 -1
- package/components/BaseLayerSwitcher/BaseLayerSwitcher.test.js +0 -88
- package/components/BaseLayerSwitcher/BaseLayerSwitcher.test.js.map +0 -1
- package/components/BaseLayerToggler/BaseLayerToggler.js +0 -490
- package/components/BaseLayerToggler/BaseLayerToggler.js.map +0 -1
- package/components/BaseLayerToggler/BaseLayerToggler.md.scss +0 -9
- package/components/BaseLayerToggler/BaseLayerToggler.scss +0 -49
- package/components/BaseLayerToggler/BaseLayerToggler.test.js +0 -127
- package/components/BaseLayerToggler/BaseLayerToggler.test.js.map +0 -1
- package/components/BaseLayerToggler/index.js +0 -3
- package/components/BaseLayerToggler/index.js.map +0 -1
- package/components/BasicMap/BasicMap.test.js +0 -288
- package/components/BasicMap/BasicMap.test.js.map +0 -1
- package/components/CanvasSaveButton/CanvasSaveButton.test.js +0 -173
- package/components/CanvasSaveButton/CanvasSaveButton.test.js.map +0 -1
- package/components/Copyright/Copyright.test.js +0 -133
- package/components/Copyright/Copyright.test.js.map +0 -1
- package/components/FeatureExportButton/FeatureExportButton.test.js +0 -407
- package/components/FeatureExportButton/FeatureExportButton.test.js.map +0 -1
- package/components/FilterButton/FilterButton.test.js +0 -48
- package/components/FilterButton/FilterButton.test.js.map +0 -1
- package/components/FitExtent/FitExtent.test.js +0 -44
- package/components/FitExtent/FitExtent.test.js.map +0 -1
- package/components/FollowButton/FollowButton.test.js +0 -57
- package/components/FollowButton/FollowButton.test.js.map +0 -1
- package/components/Geolocation/Geolocation.test.js +0 -263
- package/components/Geolocation/Geolocation.test.js.map +0 -1
- package/components/LayerTree/LayerTree.test.js +0 -323
- package/components/LayerTree/LayerTree.test.js.map +0 -1
- package/components/MousePosition/MousePosition.test.js +0 -125
- package/components/MousePosition/MousePosition.test.js.map +0 -1
- package/components/NorthArrow/NorthArrow.test.js +0 -106
- package/components/NorthArrow/NorthArrow.test.js.map +0 -1
- package/components/Overlay/Overlay.test.js +0 -145
- package/components/Overlay/Overlay.test.js.map +0 -1
- package/components/Permalink/Permalink.test.js +0 -267
- package/components/Permalink/Permalink.test.js.map +0 -1
- package/components/Popup/Popup.test.js +0 -291
- package/components/Popup/Popup.test.js.map +0 -1
- package/components/ResizeHandler/ResizeHandler.test.js +0 -410
- package/components/ResizeHandler/ResizeHandler.test.js.map +0 -1
- package/components/RouteSchedule/RouteSchedule.test.js +0 -102
- package/components/RouteSchedule/RouteSchedule.test.js.map +0 -1
- package/components/ScaleLine/ScaleLine.test.js +0 -32
- package/components/ScaleLine/ScaleLine.test.js.map +0 -1
- package/components/Search/Search.test.js +0 -15
- package/components/Search/Search.test.js.map +0 -1
- package/components/StopsFinder/StopsFinder.test.js +0 -19
- package/components/StopsFinder/StopsFinder.test.js.map +0 -1
- package/components/TrackerControl/TrackerControl.test.js +0 -17
- package/components/TrackerControl/TrackerControl.test.js.map +0 -1
- package/components/Zoom/Zoom.test.js +0 -150
- package/components/Zoom/Zoom.test.js.map +0 -1
- package/styleguidist/ComponentsList.js +0 -52
- package/styleguidist/ComponentsList.js.map +0 -1
- package/styleguidist/StyleGuide.js +0 -253
- package/styleguidist/StyleGuide.js.map +0 -1
- package/utils/KML.test.js +0 -163
- package/utils/KML.test.js.map +0 -1
- package/utils/KMLFormat.test.js +0 -22
- package/utils/KMLFormat.test.js.map +0 -1
- package/utils/getPolygonPattern.test.js +0 -66
- package/utils/getPolygonPattern.test.js.map +0 -1
- package/utils/timeUtils.test.js +0 -32
- package/utils/timeUtils.test.js.map +0 -1
|
@@ -1,307 +1,180 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
import { unByKey } from 'ol/Observable';
|
|
10
|
-
|
|
11
|
-
var propTypes = {
|
|
12
|
-
/**
|
|
13
|
-
* React Children.
|
|
14
|
-
*/
|
|
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
|
+
import { getCenter } from "ol/extent";
|
|
7
|
+
import { unByKey } from "ol/Observable";
|
|
8
|
+
const propTypes = {
|
|
15
9
|
children: PropTypes.node.isRequired,
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* An [ol/map](https://openlayers.org/en/latest/apidoc/module-ol_Map-Map.html).
|
|
19
|
-
*/
|
|
20
10
|
map: PropTypes.instanceOf(OLMap).isRequired,
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* An [ol/Feature](https://openlayers.org/en/latest/apidoc/module-ol_Feature-Feature.html).
|
|
24
|
-
*/
|
|
25
11
|
feature: PropTypes.instanceOf(Feature),
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Popup title.
|
|
29
|
-
*/
|
|
30
12
|
header: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* If true, the popup is panned in the map's viewport.
|
|
34
|
-
*/
|
|
35
13
|
panIntoView: PropTypes.bool,
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Custom BoundingClientRect to fit popup into.
|
|
39
|
-
* Use if panIntoView is true. Default is the map's BoundingClientRect.
|
|
40
|
-
*/
|
|
41
14
|
panRect: PropTypes.objectOf(PropTypes.number),
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Coordinate position of the popup.
|
|
45
|
-
*/
|
|
46
15
|
popupCoordinate: PropTypes.arrayOf(PropTypes.number),
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Class name of the popup.
|
|
50
|
-
*/
|
|
51
16
|
className: PropTypes.string,
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Title HTML attributes.
|
|
55
|
-
*/
|
|
56
17
|
titles: PropTypes.shape({
|
|
57
|
-
closeButton: PropTypes.string
|
|
18
|
+
closeButton: PropTypes.string
|
|
58
19
|
}),
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Function triggered on close button click.
|
|
62
|
-
*/
|
|
63
20
|
onCloseClick: PropTypes.func,
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* HTML tabIndex attribute.
|
|
67
|
-
*/
|
|
68
21
|
tabIndex: PropTypes.string,
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Render the header
|
|
72
|
-
*/
|
|
73
22
|
renderHeader: PropTypes.func,
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Render the close button
|
|
77
|
-
*/
|
|
78
23
|
renderCloseButton: PropTypes.func,
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Render the footer
|
|
82
|
-
*/
|
|
83
|
-
renderFooter: PropTypes.func,
|
|
24
|
+
renderFooter: PropTypes.func
|
|
84
25
|
};
|
|
85
|
-
|
|
86
|
-
var defaultProps = {
|
|
26
|
+
const defaultProps = {
|
|
87
27
|
header: null,
|
|
88
28
|
feature: null,
|
|
89
29
|
panIntoView: false,
|
|
90
30
|
panRect: null,
|
|
91
31
|
popupCoordinate: null,
|
|
92
|
-
className:
|
|
93
|
-
tabIndex:
|
|
94
|
-
titles: { closeButton:
|
|
95
|
-
onCloseClick:
|
|
32
|
+
className: "rs-popup",
|
|
33
|
+
tabIndex: "",
|
|
34
|
+
titles: { closeButton: "Close" },
|
|
35
|
+
onCloseClick: () => {
|
|
36
|
+
},
|
|
96
37
|
renderHeader: null,
|
|
97
38
|
renderCloseButton: null,
|
|
98
|
-
renderFooter:
|
|
39
|
+
renderFooter: () => {
|
|
99
40
|
return null;
|
|
100
|
-
}
|
|
41
|
+
}
|
|
101
42
|
};
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
43
|
+
class Popup extends PureComponent {
|
|
44
|
+
static renderHeader(props) {
|
|
45
|
+
const { header, renderCloseButton } = props;
|
|
46
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
47
|
+
className: "rs-popup-header"
|
|
48
|
+
}, header, (renderCloseButton || Popup.renderCloseButton)(props));
|
|
49
|
+
}
|
|
50
|
+
static renderCloseButton({ onCloseClick, titles }) {
|
|
51
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
52
|
+
role: "button",
|
|
53
|
+
tabIndex: 0,
|
|
54
|
+
className: "rs-popup-close-bt",
|
|
55
|
+
title: titles.closeButton,
|
|
56
|
+
"aria-label": titles.closeButton,
|
|
57
|
+
onClick: () => {
|
|
58
|
+
return onCloseClick();
|
|
59
|
+
},
|
|
60
|
+
onKeyPress: (evt) => {
|
|
61
|
+
return evt.which === 13 && onCloseClick();
|
|
62
|
+
}
|
|
63
|
+
}, /* @__PURE__ */ React.createElement(MdClose, {
|
|
64
|
+
focusable: false
|
|
65
|
+
}));
|
|
66
|
+
}
|
|
67
|
+
constructor(props) {
|
|
68
|
+
super(props);
|
|
111
69
|
this.state = {
|
|
112
70
|
popupElement: null,
|
|
113
71
|
top: 0,
|
|
114
|
-
left: 0
|
|
72
|
+
left: 0
|
|
115
73
|
};
|
|
116
74
|
this.postrenderKey = null;
|
|
117
75
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
Popup.prototype = Object.create( PureComponent && PureComponent.prototype );
|
|
121
|
-
Popup.prototype.constructor = Popup;
|
|
122
|
-
|
|
123
|
-
Popup.renderHeader = function renderHeader (props) {
|
|
124
|
-
var header = props.header;
|
|
125
|
-
var renderCloseButton = props.renderCloseButton;
|
|
126
|
-
return (
|
|
127
|
-
React.createElement( 'div', { className: "rs-popup-header" },
|
|
128
|
-
header,
|
|
129
|
-
(renderCloseButton || Popup.renderCloseButton)(props)
|
|
130
|
-
)
|
|
131
|
-
);
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
Popup.renderCloseButton = function renderCloseButton (ref) {
|
|
135
|
-
var onCloseClick = ref.onCloseClick;
|
|
136
|
-
var titles = ref.titles;
|
|
137
|
-
|
|
138
|
-
return (
|
|
139
|
-
React.createElement( 'div', {
|
|
140
|
-
role: "button", tabIndex: 0, className: "rs-popup-close-bt", title: titles.closeButton, 'aria-label': titles.closeButton, onClick: function () {
|
|
141
|
-
return onCloseClick();
|
|
142
|
-
}, onKeyPress: function (evt) {
|
|
143
|
-
return evt.which === 13 && onCloseClick();
|
|
144
|
-
} },
|
|
145
|
-
React.createElement( MdClose, { focusable: false })
|
|
146
|
-
)
|
|
147
|
-
);
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
Popup.prototype.componentDidMount = function componentDidMount () {
|
|
151
|
-
var this$1 = this;
|
|
152
|
-
|
|
153
|
-
var ref = this.props;
|
|
154
|
-
var map = ref.map;
|
|
76
|
+
componentDidMount() {
|
|
77
|
+
const { map } = this.props;
|
|
155
78
|
this.updatePixelPosition();
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
this$1.updatePixelPosition();
|
|
79
|
+
this.postrenderKey = map.on("postrender", () => {
|
|
80
|
+
this.updatePixelPosition();
|
|
159
81
|
});
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
var panIntoView = ref.panIntoView;
|
|
166
|
-
var popupCoordinate = ref.popupCoordinate;
|
|
167
|
-
var ref$1 = this.state;
|
|
168
|
-
var popupElement = ref$1.popupElement;
|
|
169
|
-
if (
|
|
170
|
-
feature !== prevProps.feature ||
|
|
171
|
-
popupCoordinate !== prevProps.popupCoordinate
|
|
172
|
-
) {
|
|
82
|
+
}
|
|
83
|
+
componentDidUpdate(prevProps, prevState) {
|
|
84
|
+
const { feature, panIntoView, popupCoordinate } = this.props;
|
|
85
|
+
const { popupElement } = this.state;
|
|
86
|
+
if (feature !== prevProps.feature || popupCoordinate !== prevProps.popupCoordinate) {
|
|
173
87
|
this.updatePixelPosition();
|
|
174
88
|
}
|
|
175
|
-
|
|
176
|
-
if (
|
|
177
|
-
panIntoView &&
|
|
178
|
-
popupElement &&
|
|
179
|
-
popupElement !== prevState.popupElement
|
|
180
|
-
) {
|
|
89
|
+
if (panIntoView && popupElement && popupElement !== prevState.popupElement) {
|
|
181
90
|
this.panIntoView();
|
|
182
91
|
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
Popup.prototype.componentWillUnmount = function componentWillUnmount () {
|
|
92
|
+
}
|
|
93
|
+
componentWillUnmount() {
|
|
186
94
|
unByKey(this.postrenderKey);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
var mapRect = panRect || map.getTarget().getBoundingClientRect();
|
|
197
|
-
var popupRect = popupElement.getBoundingClientRect();
|
|
198
|
-
var ref$2 = map.getView().getCenter();
|
|
199
|
-
var x = ref$2[0];
|
|
200
|
-
var y = ref$2[1];
|
|
201
|
-
var res = map.getView().getResolution();
|
|
202
|
-
var newCenter = [x, y];
|
|
203
|
-
|
|
95
|
+
}
|
|
96
|
+
panIntoView() {
|
|
97
|
+
const { map, panRect } = this.props;
|
|
98
|
+
const { popupElement } = this.state;
|
|
99
|
+
const mapRect = panRect || map.getTarget().getBoundingClientRect();
|
|
100
|
+
const popupRect = popupElement.getBoundingClientRect();
|
|
101
|
+
const [x, y] = map.getView().getCenter();
|
|
102
|
+
const res = map.getView().getResolution();
|
|
103
|
+
const newCenter = [x, y];
|
|
204
104
|
if (mapRect.top > popupRect.top) {
|
|
205
105
|
newCenter[1] = y + (mapRect.top - popupRect.top) * res;
|
|
206
106
|
}
|
|
207
|
-
|
|
208
107
|
if (mapRect.left > popupRect.left) {
|
|
209
108
|
newCenter[0] = x - (mapRect.left - popupRect.left) * res;
|
|
210
109
|
}
|
|
211
|
-
|
|
212
110
|
if (mapRect.right < popupRect.right) {
|
|
213
111
|
newCenter[0] = x + (popupRect.right - mapRect.right) * res;
|
|
214
112
|
}
|
|
215
|
-
|
|
216
113
|
if (mapRect.bottom < popupRect.bottom) {
|
|
217
114
|
newCenter[1] = y - (popupRect.bottom - mapRect.bottom) * res;
|
|
218
115
|
}
|
|
219
|
-
|
|
220
116
|
if (newCenter[0] !== x || newCenter[1] !== y) {
|
|
221
117
|
map.getView().animate({ center: newCenter, duration: 500 });
|
|
222
118
|
}
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
var map = ref.map;
|
|
228
|
-
var feature = ref.feature;
|
|
229
|
-
var popupCoordinate = ref.popupCoordinate;
|
|
230
|
-
var coord = popupCoordinate;
|
|
231
|
-
|
|
119
|
+
}
|
|
120
|
+
updatePixelPosition() {
|
|
121
|
+
const { map, feature, popupCoordinate } = this.props;
|
|
122
|
+
let coord = popupCoordinate;
|
|
232
123
|
if (feature && !coord) {
|
|
233
124
|
coord = getCenter(feature.getGeometry().getExtent());
|
|
234
125
|
}
|
|
235
|
-
|
|
236
126
|
if (coord) {
|
|
237
|
-
|
|
238
|
-
|
|
127
|
+
const pos = map.getPixelFromCoordinate(coord);
|
|
239
128
|
if (pos && pos.length === 2) {
|
|
240
129
|
this.setState({
|
|
241
130
|
left: pos[0],
|
|
242
|
-
top: pos[1]
|
|
131
|
+
top: pos[1]
|
|
243
132
|
});
|
|
244
133
|
}
|
|
245
134
|
}
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
var renderFooter = ref.renderFooter;
|
|
260
|
-
var rest = objectWithoutProperties( ref, ["feature", "popupCoordinate", "children", "header", "titles", "tabIndex", "renderHeader", "renderFooter"] );
|
|
261
|
-
var other = rest;
|
|
262
|
-
|
|
135
|
+
}
|
|
136
|
+
render() {
|
|
137
|
+
const {
|
|
138
|
+
feature,
|
|
139
|
+
popupCoordinate,
|
|
140
|
+
children,
|
|
141
|
+
header,
|
|
142
|
+
titles,
|
|
143
|
+
tabIndex,
|
|
144
|
+
renderHeader,
|
|
145
|
+
renderFooter,
|
|
146
|
+
...other
|
|
147
|
+
} = this.props;
|
|
263
148
|
if (!feature && !popupCoordinate) {
|
|
264
149
|
return null;
|
|
265
150
|
}
|
|
266
|
-
|
|
267
151
|
delete other.panIntoView;
|
|
268
152
|
delete other.panRect;
|
|
269
153
|
delete other.map;
|
|
270
154
|
delete other.header;
|
|
271
155
|
delete other.onCloseClick;
|
|
272
156
|
delete other.renderCloseButton;
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
)
|
|
295
|
-
)
|
|
296
|
-
);
|
|
297
|
-
};
|
|
298
|
-
|
|
299
|
-
return Popup;
|
|
300
|
-
}(PureComponent));
|
|
301
|
-
|
|
157
|
+
const { top, left } = this.state;
|
|
158
|
+
const key = feature ? feature.getId() : popupCoordinate.join();
|
|
159
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
160
|
+
className: "rs-popup",
|
|
161
|
+
style: {
|
|
162
|
+
left,
|
|
163
|
+
top
|
|
164
|
+
},
|
|
165
|
+
...other
|
|
166
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
167
|
+
className: "rs-popup-container",
|
|
168
|
+
tabIndex,
|
|
169
|
+
key,
|
|
170
|
+
ref: (popupElement) => {
|
|
171
|
+
this.setState({ popupElement });
|
|
172
|
+
}
|
|
173
|
+
}, (renderHeader || Popup.renderHeader)(this.props), /* @__PURE__ */ React.createElement("div", {
|
|
174
|
+
className: "rs-popup-body"
|
|
175
|
+
}, children), renderFooter(this.props)));
|
|
176
|
+
}
|
|
177
|
+
}
|
|
302
178
|
Popup.propTypes = propTypes;
|
|
303
179
|
Popup.defaultProps = defaultProps;
|
|
304
|
-
|
|
305
180
|
export default Popup;
|
|
306
|
-
|
|
307
|
-
//# sourceMappingURL=Popup.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{"version":3,"file":"Popup.js","sources":["../../../src/components/Popup/Popup.js"],"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"],"names":["const","super","this","let"],"mappings":";AAAA,OAAO,KAAK,IAAI,aAAa,QAAQ,OAAO,CAAC;AAC7C,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC;AACA,SAAS,OAAO,QAAQ,gBAAgB,CAAC;AACzC,OAAO,KAAK,MAAM,QAAQ,CAAC;AAC3B,OAAO,OAAO,MAAM,YAAY,CAAC;AACjC,SAAS,SAAS,QAAQ,WAAW,CAAC;AAC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KAAK,CAAC;"}
|
|
1
|
+
{
|
|
2
|
+
"version": 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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K,KAAK,IAAI,KAAK;AAI3B,UAAM,MAAM,UAAU,QAAQ,MAAM,IAAI,gBAAgB,KAAK;AAC7D,WACE,oCAAC;AAAA,MACC,WAAU;AAAA,MACV,OAAO;AAAA,QACL;AAAA,QACA;AAAA,MACF;AAAA,MAEC,GAAG;AAAA,OAEJ,oCAAC;AAAA,MACC,WAAU;AAAA,MACV;AAAA,MACA;AAAA,MACA,KAAK,CAAC,iBAAiB;AACrB,aAAK,SAAS,EAAE,aAAa,CAAC;AAAA,MAChC;AAAA,QAEE,gBAAgB,MAAM,cAAc,KAAK,KAAK,GAChD,oCAAC;AAAA,MAAI,WAAU;AAAA,OAAiB,QAAS,GACxC,aAAa,KAAK,KAAK,CAC1B,CACF;AAAA,EAEJ;AACF;AAEA,MAAM,YAAY;AAClB,MAAM,eAAe;AAErB,eAAe;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/Popup/index.js"],
|
|
4
|
+
"sourcesContent": ["export { default } from './Popup';\n"],
|
|
5
|
+
"mappings": "AAAA,wBAAwB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|