@rio-cloud/rio-uikit 0.16.2-beta.12 → 0.16.2-beta.14
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/Map.d.ts +1 -1
- package/RuleConnector.d.ts +2 -1
- package/RuleContainer.d.ts +3 -2
- package/RulesWrapper.d.ts +2 -1
- package/components/applicationLayout/ApplicationLayoutBodyBottomBar.js +6 -4
- package/components/map/components/Map.js +39 -33
- package/components/map/components/features/ContextMenu.js +1 -1
- package/components/map/components/features/basics/Circle.js +5 -4
- package/components/map/components/features/basics/MapLayerGroup.js +6 -4
- package/components/map/components/features/basics/Polygon.js +5 -4
- package/components/map/components/features/basics/Polyline.js +5 -4
- package/components/map/components/features/basics/marker/Marker.js +125 -120
- package/components/map/components/features/basics/marker/TextMarker.js +15 -43
- package/components/map/components/features/layers/MarkerLayer.js +4 -2
- package/components/map/components/features/layers/baselayers/DefaultRasterLayer.js +2 -1
- package/components/map/components/features/layers/baselayers/useBaseLayer.js +3 -2
- package/components/map/components/features/layers/clustering/ClusterLayer.js +5 -4
- package/components/map/utils/hooks.js +3 -3
- package/components/mapMarker/SingleMapMarker.js +15 -12
- package/components/rules/RuleContainer.js +4 -0
- package/components/rules/RulesWrapper.js +3 -3
- package/hooks/useScrollPosition.js +4 -5
- package/index.d.ts +29 -29
- package/lib/es/Map.d.ts +1 -1
- package/lib/es/RuleConnector.d.ts +2 -1
- package/lib/es/RuleContainer.d.ts +3 -2
- package/lib/es/RulesWrapper.d.ts +2 -1
- package/lib/es/components/applicationLayout/ApplicationLayoutBodyBottomBar.js +9 -4
- package/lib/es/components/map/components/Map.js +39 -33
- package/lib/es/components/map/components/features/ContextMenu.js +1 -1
- package/lib/es/components/map/components/features/basics/Circle.js +5 -4
- package/lib/es/components/map/components/features/basics/MapLayerGroup.js +6 -4
- package/lib/es/components/map/components/features/basics/Polygon.js +5 -4
- package/lib/es/components/map/components/features/basics/Polyline.js +5 -4
- package/lib/es/components/map/components/features/basics/marker/Marker.js +129 -119
- package/lib/es/components/map/components/features/basics/marker/TextMarker.js +15 -42
- package/lib/es/components/map/components/features/layers/MarkerLayer.js +4 -2
- package/lib/es/components/map/components/features/layers/baselayers/DefaultRasterLayer.js +2 -1
- package/lib/es/components/map/components/features/layers/baselayers/useBaseLayer.js +3 -2
- package/lib/es/components/map/components/features/layers/clustering/ClusterLayer.js +5 -4
- package/lib/es/components/map/utils/hooks.js +3 -3
- package/lib/es/components/mapMarker/SingleMapMarker.js +15 -12
- package/lib/es/components/rules/RuleContainer.js +4 -0
- package/lib/es/components/rules/RulesWrapper.js +3 -3
- package/lib/es/hooks/useScrollPosition.js +4 -5
- package/lib/es/index.d.ts +29 -29
- package/lib/es/types.ts +18 -17
- package/lib/es/version.json +1 -1
- package/package.json +1 -1
- package/types.ts +18 -17
- package/version.json +1 -1
package/Map.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { MapProps } from './types';
|
|
|
3
3
|
|
|
4
4
|
export { BoundingBox } from './types';
|
|
5
5
|
|
|
6
|
-
export default class Map extends React.Component<MapProps
|
|
6
|
+
export default class Map extends React.Component<React.PropsWithChildren<MapProps>> {
|
|
7
7
|
static TYPE_DEFAULT = 'DEFAULT';
|
|
8
8
|
static TYPE_FLEET_STYLE = 'FLEET_STYLE';
|
|
9
9
|
static TYPE_SATELLITE = 'SATELLITE';
|
package/RuleConnector.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
declare module '@rio-cloud/rio-uikit/RuleConnector' {
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { RuleConnectorProps } from './types';
|
|
4
|
-
|
|
4
|
+
|
|
5
|
+
export default class RuleConnector extends React.Component<React.PropsWithChildren<RuleConnectorProps>> {
|
|
5
6
|
static START = 'start';
|
|
6
7
|
static CENTER = 'center';
|
|
7
8
|
static END = 'end';
|
package/RuleContainer.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
declare module '@rio-cloud/rio-uikit/RuleContainer' {
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { RuleContainerProps } from './types';
|
|
4
|
-
|
|
5
|
-
}
|
|
4
|
+
|
|
5
|
+
export default class RuleContainer extends React.Component<React.PropsWithChildren<RuleContainerProps>> {}
|
|
6
|
+
}
|
package/RulesWrapper.d.ts
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
3
|
var _excluded = ["className", "buttonAlignment", "useBodyPaddings", "children"];
|
|
4
|
-
import React from 'react';
|
|
4
|
+
import React, { forwardRef } from 'react';
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
6
|
import classNames from 'classnames';
|
|
7
|
-
export var ApplicationLayoutBodyBottomBar = function
|
|
7
|
+
export var ApplicationLayoutBodyBottomBar = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
8
8
|
var className = _ref.className,
|
|
9
9
|
buttonAlignment = _ref.buttonAlignment,
|
|
10
10
|
useBodyPaddings = _ref.useBodyPaddings,
|
|
11
11
|
children = _ref.children,
|
|
12
12
|
remainigProps = _objectWithoutProperties(_ref, _excluded);
|
|
13
13
|
var classes = classNames('ApplicationLayoutBodyBottomBar', buttonAlignment === 'left' && 'justify-content-start', buttonAlignment === 'right' && 'justify-content-end', buttonAlignment !== 'left' && buttonAlignment !== 'right' && 'justify-content-between', useBodyPaddings && 'use-body-padding', className && className);
|
|
14
|
-
return /*#__PURE__*/React.createElement("div", _extends({
|
|
14
|
+
return /*#__PURE__*/React.createElement("div", _extends({
|
|
15
|
+
ref: ref
|
|
16
|
+
}, remainigProps, {
|
|
15
17
|
className: classes
|
|
16
18
|
}), children);
|
|
17
|
-
};
|
|
19
|
+
});
|
|
18
20
|
ApplicationLayoutBodyBottomBar.LEFT = 'left';
|
|
19
21
|
ApplicationLayoutBodyBottomBar.RIGHT = 'right';
|
|
20
22
|
ApplicationLayoutBodyBottomBar.defaultProps = {
|
|
@@ -10,6 +10,7 @@ import isFunction from 'lodash/fp/isFunction';
|
|
|
10
10
|
import map from 'lodash/fp/map';
|
|
11
11
|
import isEmpty from 'lodash/fp/isEmpty';
|
|
12
12
|
import throttle from 'lodash/fp/throttle';
|
|
13
|
+
import cloneDeep from 'lodash/fp/cloneDeep';
|
|
13
14
|
import mapProps from '../utils/proptypes';
|
|
14
15
|
import addEventListener from '../../../utils/addEventListener';
|
|
15
16
|
import '../herePolyfill';
|
|
@@ -59,14 +60,14 @@ var getBounds = function getBounds(boundingBox) {
|
|
|
59
60
|
right = boundingBox.right;
|
|
60
61
|
return new H.geo.Rect(top, left, bottom, right);
|
|
61
62
|
};
|
|
62
|
-
var getLayer = function getLayer(api, layer, language,
|
|
63
|
+
var getLayer = function getLayer(api, layer, language, enableWebGL) {
|
|
63
64
|
switch (layer) {
|
|
64
65
|
case MAP_LAYER_TRAFFIC:
|
|
65
66
|
return /*#__PURE__*/React.createElement(TrafficLayer, {
|
|
66
67
|
api: api,
|
|
67
68
|
language: language,
|
|
68
69
|
key: layer,
|
|
69
|
-
useWebGL:
|
|
70
|
+
useWebGL: enableWebGL
|
|
70
71
|
});
|
|
71
72
|
case MAP_LAYER_INCIDENTS:
|
|
72
73
|
return /*#__PURE__*/React.createElement(IncidentsLayer, {
|
|
@@ -79,17 +80,17 @@ var getLayer = function getLayer(api, layer, language, useWebGL) {
|
|
|
79
80
|
api: api,
|
|
80
81
|
language: language,
|
|
81
82
|
key: layer,
|
|
82
|
-
useWebGL:
|
|
83
|
+
useWebGL: enableWebGL
|
|
83
84
|
});
|
|
84
85
|
default:
|
|
85
86
|
null;
|
|
86
87
|
}
|
|
87
88
|
};
|
|
88
|
-
var getBaseLayer = function getBaseLayer(api, baseLayer, language,
|
|
89
|
+
var getBaseLayer = function getBaseLayer(api, baseLayer, language, enableWebGL, darkMode) {
|
|
89
90
|
switch (baseLayer) {
|
|
90
91
|
case MAP_TYPE_DEFAULT:
|
|
91
92
|
{
|
|
92
|
-
return !darkMode &&
|
|
93
|
+
return !darkMode && enableWebGL ? /*#__PURE__*/React.createElement(DefaultVectorLayer, {
|
|
93
94
|
api: api,
|
|
94
95
|
language: language,
|
|
95
96
|
key: baseLayer
|
|
@@ -173,7 +174,8 @@ var Map = function Map(props) {
|
|
|
173
174
|
onZoomOut = props.onZoomOut,
|
|
174
175
|
mapSettingsTooltip = props.mapSettingsTooltip,
|
|
175
176
|
mapSettings = props.mapSettings,
|
|
176
|
-
|
|
177
|
+
enableWebGL = props.enableWebGL,
|
|
178
|
+
enableDevicePixelRatio = props.enableDevicePixelRatio,
|
|
177
179
|
darkMode = props.darkMode;
|
|
178
180
|
var mapRef = useRef(null);
|
|
179
181
|
var _useState = useState(false),
|
|
@@ -196,26 +198,13 @@ var Map = function Map(props) {
|
|
|
196
198
|
_useState10 = _slicedToArray(_useState9, 2),
|
|
197
199
|
showCluster = _useState10[0],
|
|
198
200
|
setShowCluster = _useState10[1];
|
|
199
|
-
var
|
|
200
|
-
useEffect(function () {
|
|
201
|
-
// Toggle night map only if current map type is default
|
|
202
|
-
if (isDarkMode && baseLayer === MAP_TYPE_DEFAULT) {
|
|
203
|
-
setBaseLayer(MAP_TYPE_NIGHT);
|
|
204
|
-
onMapTypeChange(MAP_TYPE_NIGHT);
|
|
205
|
-
}
|
|
206
|
-
// Toggle back to default map only if current map type is night
|
|
207
|
-
else if (!isDarkMode && baseLayer === MAP_TYPE_NIGHT) {
|
|
208
|
-
setBaseLayer(MAP_TYPE_DEFAULT);
|
|
209
|
-
onMapTypeChange(MAP_TYPE_DEFAULT);
|
|
210
|
-
}
|
|
211
|
-
}, [isDarkMode]);
|
|
212
|
-
var devicePixelRatio = window.devicePixelRatio || 1;
|
|
201
|
+
var devicePixelRatio = enableDevicePixelRatio ? window.devicePixelRatio || 1 : 1;
|
|
213
202
|
useEffect(function () {
|
|
214
203
|
console.debug('initialize here map');
|
|
215
204
|
var bounds = boundingBox && getBounds(boundingBox);
|
|
216
205
|
var platform = getPlatform(credentials);
|
|
217
206
|
var defaultLayers = platform.createDefaultLayers();
|
|
218
|
-
var defaultLayer = getDefaultBaseLayer(defaultLayers, baseLayer,
|
|
207
|
+
var defaultLayer = getDefaultBaseLayer(defaultLayers, baseLayer, enableWebGL);
|
|
219
208
|
|
|
220
209
|
// Instantiate (and display) a map object:
|
|
221
210
|
var mapConfig = {
|
|
@@ -268,7 +257,18 @@ var Map = function Map(props) {
|
|
|
268
257
|
hereMap.dispose();
|
|
269
258
|
}
|
|
270
259
|
};
|
|
271
|
-
}, [
|
|
260
|
+
}, [enableWebGL, enableDevicePixelRatio]);
|
|
261
|
+
var isDarkMode = useDarkMode();
|
|
262
|
+
useEffect(function () {
|
|
263
|
+
// Toggle night map only if current map type is default
|
|
264
|
+
if (isDarkMode && baseLayer === MAP_TYPE_DEFAULT) {
|
|
265
|
+
handleMapTypeChange(MAP_TYPE_NIGHT);
|
|
266
|
+
}
|
|
267
|
+
// Toggle back to default map only if current map type is night
|
|
268
|
+
else if (!isDarkMode && baseLayer === MAP_TYPE_NIGHT) {
|
|
269
|
+
handleMapTypeChange(MAP_TYPE_DEFAULT);
|
|
270
|
+
}
|
|
271
|
+
}, [isDarkMode]);
|
|
272
272
|
|
|
273
273
|
// Update BoundingBox from outside
|
|
274
274
|
useEffect(function () {
|
|
@@ -307,7 +307,7 @@ var Map = function Map(props) {
|
|
|
307
307
|
|
|
308
308
|
// Update MapType from outside
|
|
309
309
|
useEffect(function () {
|
|
310
|
-
return
|
|
310
|
+
return handleMapTypeChange(mapType);
|
|
311
311
|
}, [mapType]);
|
|
312
312
|
|
|
313
313
|
// Update MapLayer from outside
|
|
@@ -322,11 +322,13 @@ var Map = function Map(props) {
|
|
|
322
322
|
var handleMapTypeChange = function handleMapTypeChange(newMapType) {
|
|
323
323
|
setBaseLayer(newMapType);
|
|
324
324
|
onMapTypeChange(newMapType, mapType);
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
325
|
+
if (api) {
|
|
326
|
+
setApi(_objectSpread(_objectSpread({}, api), {}, {
|
|
327
|
+
settings: _objectSpread(_objectSpread({}, api.settings), {}, {
|
|
328
|
+
baseLayer: newMapType
|
|
329
|
+
})
|
|
330
|
+
}));
|
|
331
|
+
}
|
|
330
332
|
};
|
|
331
333
|
var handleMapLayerChange = function handleMapLayerChange(layer) {
|
|
332
334
|
var removeLayer = function removeLayer(layerToRemove) {
|
|
@@ -372,7 +374,9 @@ var Map = function Map(props) {
|
|
|
372
374
|
style: style,
|
|
373
375
|
ref: mapRef
|
|
374
376
|
}, isMapInitialized && /*#__PURE__*/React.createElement(MapContext.Provider, {
|
|
375
|
-
value:
|
|
377
|
+
value: {
|
|
378
|
+
api: api
|
|
379
|
+
}
|
|
376
380
|
}, !hideZoomButtons && /*#__PURE__*/React.createElement(ZoomButtons, {
|
|
377
381
|
onZoomIn: handleZoomIn,
|
|
378
382
|
onZoomOut: handleZoomOut
|
|
@@ -388,8 +392,8 @@ var Map = function Map(props) {
|
|
|
388
392
|
onShowClusterChange: handleShowClusterChange,
|
|
389
393
|
mapSettingsTooltip: mapSettingsTooltip
|
|
390
394
|
}
|
|
391
|
-
}, mapSettings), getBaseLayer(api, baseLayer, language,
|
|
392
|
-
return getLayer(api, layer, language,
|
|
395
|
+
}, mapSettings), getBaseLayer(api, baseLayer, language, enableWebGL, darkMode), map(function (layer) {
|
|
396
|
+
return getLayer(api, layer, language, enableWebGL);
|
|
393
397
|
}, activeLayers), children && /*#__PURE__*/React.createElement("div", {
|
|
394
398
|
className: 'MapElements'
|
|
395
399
|
}, isFunction(children) ? children(api) : enrichChildrenWithApi(children, api))));
|
|
@@ -417,7 +421,8 @@ Map.defaultProps = {
|
|
|
417
421
|
onShowClusterChange: function onShowClusterChange() {},
|
|
418
422
|
onZoomIn: function onZoomIn() {},
|
|
419
423
|
onZoomOut: function onZoomOut() {},
|
|
420
|
-
|
|
424
|
+
enableWebGL: true,
|
|
425
|
+
enableDevicePixelRatio: true,
|
|
421
426
|
darkMode: false
|
|
422
427
|
};
|
|
423
428
|
Map.propTypes = {
|
|
@@ -446,7 +451,8 @@ Map.propTypes = {
|
|
|
446
451
|
getApi: PropTypes.func,
|
|
447
452
|
mapSettingsTooltip: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
|
|
448
453
|
mapSettings: PropTypes.node,
|
|
449
|
-
|
|
454
|
+
enableWebGL: PropTypes.bool,
|
|
455
|
+
enableDevicePixelRatio: PropTypes.bool,
|
|
450
456
|
darkMode: PropTypes.bool
|
|
451
457
|
};
|
|
452
458
|
export default Map;
|
|
@@ -80,7 +80,7 @@ var ContextMenu = function ContextMenu(props) {
|
|
|
80
80
|
contextMenuEvent = props.contextMenuEvent,
|
|
81
81
|
targetPosition = props.targetPosition;
|
|
82
82
|
var mapContext = useContext(MapContext);
|
|
83
|
-
var _ref = api || mapContext,
|
|
83
|
+
var _ref = api || mapContext.api,
|
|
84
84
|
hereMap = _ref.map;
|
|
85
85
|
|
|
86
86
|
// Use a ref to store the target position used when a map object was clicked with a fixed
|
|
@@ -13,7 +13,8 @@ var Circle = function Circle(_ref) {
|
|
|
13
13
|
precision = _ref$precision === void 0 ? 60 : _ref$precision,
|
|
14
14
|
style = _ref.style,
|
|
15
15
|
eventListenerMap = _ref.eventListenerMap;
|
|
16
|
-
var
|
|
16
|
+
var _useContext = useContext(MapContext),
|
|
17
|
+
api = _useContext.api;
|
|
17
18
|
var _useState = useState(),
|
|
18
19
|
_useState2 = _slicedToArray(_useState, 2),
|
|
19
20
|
circle = _useState2[0],
|
|
@@ -24,10 +25,10 @@ var Circle = function Circle(_ref) {
|
|
|
24
25
|
precision: parseFloat(precision)
|
|
25
26
|
});
|
|
26
27
|
setCircle(newCircle);
|
|
27
|
-
|
|
28
|
+
api.group.addObject(newCircle);
|
|
28
29
|
return function () {
|
|
29
|
-
if (
|
|
30
|
-
|
|
30
|
+
if (api.group.getObjects().includes(newCircle)) {
|
|
31
|
+
api.group.removeObject(newCircle);
|
|
31
32
|
}
|
|
32
33
|
newCircle.dispose();
|
|
33
34
|
};
|
|
@@ -26,15 +26,17 @@ var MapLayerGroup = function MapLayerGroup(_ref) {
|
|
|
26
26
|
max: parseFloat(maxZoom)
|
|
27
27
|
});
|
|
28
28
|
newGroup.setVisibility(isVisible);
|
|
29
|
-
context.group.addObject(newGroup);
|
|
29
|
+
context.api.group.addObject(newGroup);
|
|
30
30
|
setGroup(newGroup);
|
|
31
31
|
var newChildApi = _objectSpread(_objectSpread({}, context), {}, {
|
|
32
|
-
|
|
32
|
+
api: _objectSpread(_objectSpread({}, context.api), {}, {
|
|
33
|
+
group: newGroup
|
|
34
|
+
})
|
|
33
35
|
});
|
|
34
36
|
setChildApi(newChildApi);
|
|
35
37
|
return function () {
|
|
36
|
-
if (context.group.getObjects().includes(newGroup)) {
|
|
37
|
-
context.group.removeObject(newGroup);
|
|
38
|
+
if (context.api.group.getObjects().includes(newGroup)) {
|
|
39
|
+
context.api.group.removeObject(newGroup);
|
|
38
40
|
}
|
|
39
41
|
newGroup.dispose();
|
|
40
42
|
};
|
|
@@ -21,7 +21,8 @@ var Polygon = function Polygon(_ref) {
|
|
|
21
21
|
_ref$style = _ref.style,
|
|
22
22
|
style = _ref$style === void 0 ? H.map.SpatialStyle.DEFAULT_STYLE : _ref$style,
|
|
23
23
|
eventListenerMap = _ref.eventListenerMap;
|
|
24
|
-
var
|
|
24
|
+
var _useContext = useContext(MapContext),
|
|
25
|
+
api = _useContext.api;
|
|
25
26
|
var _useState = useState(),
|
|
26
27
|
_useState2 = _slicedToArray(_useState, 2),
|
|
27
28
|
polygon = _useState2[0],
|
|
@@ -30,11 +31,11 @@ var Polygon = function Polygon(_ref) {
|
|
|
30
31
|
var newPolygon = new H.map.Polygon(createGeometry(points), {
|
|
31
32
|
style: style
|
|
32
33
|
});
|
|
33
|
-
|
|
34
|
+
api.group.addObject(newPolygon);
|
|
34
35
|
setPolygon(newPolygon);
|
|
35
36
|
return function () {
|
|
36
|
-
if (
|
|
37
|
-
|
|
37
|
+
if (api.group.getObjects().includes(newPolygon)) {
|
|
38
|
+
api.group.removeObject(newPolygon);
|
|
38
39
|
}
|
|
39
40
|
newPolygon.dispose();
|
|
40
41
|
};
|
|
@@ -18,7 +18,8 @@ var Polyline = function Polyline(_ref) {
|
|
|
18
18
|
_ref$style = _ref.style,
|
|
19
19
|
style = _ref$style === void 0 ? H.map.SpatialStyle.DEFAULT_STYLE : _ref$style,
|
|
20
20
|
eventListenerMap = _ref.eventListenerMap;
|
|
21
|
-
var
|
|
21
|
+
var _useContext = useContext(MapContext),
|
|
22
|
+
api = _useContext.api;
|
|
22
23
|
var _useState = useState(),
|
|
23
24
|
_useState2 = _slicedToArray(_useState, 2),
|
|
24
25
|
polyline = _useState2[0],
|
|
@@ -56,7 +57,7 @@ var Polyline = function Polyline(_ref) {
|
|
|
56
57
|
} else {
|
|
57
58
|
lineGroup.addObjects([line]);
|
|
58
59
|
}
|
|
59
|
-
|
|
60
|
+
api.group.addObject(lineGroup);
|
|
60
61
|
setPolyline(lineGroup);
|
|
61
62
|
return function () {
|
|
62
63
|
// cleanup
|
|
@@ -67,8 +68,8 @@ var Polyline = function Polyline(_ref) {
|
|
|
67
68
|
lineGroup.removeObject(singleLine);
|
|
68
69
|
singleLine.dispose();
|
|
69
70
|
});
|
|
70
|
-
if (
|
|
71
|
-
|
|
71
|
+
if (api.group.getObjects().includes(lineGroup)) {
|
|
72
|
+
api.group.removeObject(lineGroup);
|
|
72
73
|
}
|
|
73
74
|
lineGroup.dispose();
|
|
74
75
|
};
|
|
@@ -1,16 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
|
-
import _inherits from "@babel/runtime/helpers/inherits";
|
|
4
|
-
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
5
|
-
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
6
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
7
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
8
2
|
/* eslint-disable no-undef */
|
|
9
|
-
import React from 'react';
|
|
3
|
+
import React, { useContext, useEffect, useState, useRef } from 'react';
|
|
10
4
|
import ReactDomServer from 'react-dom/server';
|
|
11
5
|
import PropTypes from 'prop-types';
|
|
12
6
|
import mapProps from '../../../../utils/proptypes';
|
|
13
|
-
import { addEventListenerMap, removeEventListenerMap
|
|
7
|
+
import { addEventListenerMap, removeEventListenerMap } from '../../../../utils/eventHandling';
|
|
14
8
|
import MapException from '../../../../exceptions/MapException';
|
|
15
9
|
import { MapContext } from '../../../context';
|
|
16
10
|
export var isHMapIcon = function isHMapIcon(icon) {
|
|
@@ -19,131 +13,142 @@ export var isHMapIcon = function isHMapIcon(icon) {
|
|
|
19
13
|
export var isDomMakerNeeded = function isDomMakerNeeded(icon) {
|
|
20
14
|
return !icon ? false : !isHMapIcon(icon);
|
|
21
15
|
};
|
|
22
|
-
export function getOrCreateIcon(icon) {
|
|
16
|
+
export function getOrCreateIcon(icon, mapType) {
|
|
23
17
|
if (!icon || isHMapIcon(icon) || icon instanceof H.map.DomIcon) {
|
|
24
18
|
return;
|
|
25
19
|
}
|
|
26
|
-
var renderedIcon = /*#__PURE__*/React.isValidElement(icon) ? ReactDomServer.renderToStaticMarkup(icon
|
|
20
|
+
var renderedIcon = /*#__PURE__*/React.isValidElement(icon) ? ReactDomServer.renderToStaticMarkup( /*#__PURE__*/React.cloneElement(icon, {
|
|
21
|
+
mapType: mapType
|
|
22
|
+
})) : icon;
|
|
27
23
|
return new H.map.DomIcon(renderedIcon);
|
|
28
24
|
}
|
|
29
|
-
var
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
25
|
+
var convertPosition = function convertPosition(pos) {
|
|
26
|
+
return Array.isArray(pos) ? new H.geo.MultiPoint(pos) : pos;
|
|
27
|
+
};
|
|
28
|
+
var checkPositionProperties = function checkPositionProperties(position) {
|
|
29
|
+
['lat', 'lng'].forEach(function (propertyName) {
|
|
30
|
+
// eslint-disable-next-line no-prototype-builtins
|
|
31
|
+
if (!position.hasOwnProperty(propertyName)) {
|
|
32
|
+
throw new MapException("Error in Marker: position object requires property \"".concat(propertyName, "\""));
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
var getPosition = function getPosition(position) {
|
|
37
|
+
if (!position) {
|
|
38
|
+
throw new MapException('Error in Marker: invalid position property');
|
|
39
39
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
40
|
+
if (Array.isArray(position)) {
|
|
41
|
+
position.forEach(function (pos) {
|
|
42
|
+
return checkPositionProperties(pos);
|
|
43
|
+
});
|
|
44
|
+
} else {
|
|
45
|
+
checkPositionProperties(position);
|
|
46
|
+
}
|
|
47
|
+
return position;
|
|
48
|
+
};
|
|
49
|
+
var getConvertedPosition = function getConvertedPosition(position) {
|
|
50
|
+
return convertPosition(getPosition(position));
|
|
51
|
+
};
|
|
52
|
+
var setupMarker = function setupMarker(props, api) {
|
|
53
|
+
var position = props.position,
|
|
54
|
+
customData = props.customData,
|
|
55
|
+
icon = props.icon,
|
|
56
|
+
draggable = props.draggable,
|
|
57
|
+
eventListenerMap = props.eventListenerMap;
|
|
58
|
+
var MarkerConstructor = isDomMakerNeeded(icon) ? H.map.DomMarker : H.map.Marker;
|
|
59
|
+
var marker = new MarkerConstructor(getConvertedPosition(position), {
|
|
60
|
+
icon: getOrCreateIcon(icon, api.settings.baseLayer)
|
|
61
|
+
});
|
|
62
|
+
marker.setData(customData);
|
|
63
|
+
marker.draggable = !!draggable;
|
|
64
|
+
api.group.addObject(marker);
|
|
65
|
+
addEventListenerMap(marker, eventListenerMap, api.map);
|
|
66
|
+
return marker;
|
|
67
|
+
};
|
|
68
|
+
var destroyMarker = function destroyMarker(marker, api) {
|
|
69
|
+
removeEventListenerMap(marker);
|
|
70
|
+
if (api.group.getObjects().includes(marker)) {
|
|
71
|
+
api.group.removeObject(marker);
|
|
72
|
+
}
|
|
73
|
+
marker.dispose();
|
|
74
|
+
};
|
|
75
|
+
var Marker = function Marker(props) {
|
|
76
|
+
var position = props.position,
|
|
77
|
+
customData = props.customData,
|
|
78
|
+
icon = props.icon,
|
|
79
|
+
eventListenerMap = props.eventListenerMap;
|
|
80
|
+
var _useContext = useContext(MapContext),
|
|
81
|
+
api = _useContext.api;
|
|
82
|
+
var markerRef = useRef();
|
|
83
|
+
var _useState = useState(api === null || api === void 0 ? void 0 : api.settings.baseLayer),
|
|
84
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
85
|
+
currentBaseLayer = _useState2[0],
|
|
86
|
+
setCurrentBaseLayer = _useState2[1];
|
|
87
|
+
useEffect(function () {
|
|
88
|
+
markerRef.current = setupMarker(props, api);
|
|
89
|
+
return function () {
|
|
90
|
+
if (markerRef.current) {
|
|
91
|
+
destroyMarker(markerRef.current, api);
|
|
92
|
+
markerRef.current = undefined;
|
|
65
93
|
}
|
|
94
|
+
};
|
|
95
|
+
}, []);
|
|
96
|
+
|
|
97
|
+
// Update marker position
|
|
98
|
+
useEffect(function () {
|
|
99
|
+
if (markerRef.current) {
|
|
100
|
+
markerRef.current.setGeometry(getConvertedPosition(position));
|
|
66
101
|
}
|
|
67
|
-
},
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
key: "componentWillUnmount",
|
|
74
|
-
value: function componentWillUnmount() {
|
|
75
|
-
this.destroyMarker();
|
|
76
|
-
}
|
|
77
|
-
}, {
|
|
78
|
-
key: "render",
|
|
79
|
-
value: function render() {
|
|
80
|
-
return null;
|
|
81
|
-
}
|
|
82
|
-
}, {
|
|
83
|
-
key: "setupMarker",
|
|
84
|
-
value: function setupMarker(nextProps) {
|
|
85
|
-
var _this$props2 = this.props,
|
|
86
|
-
customData = _this$props2.customData,
|
|
87
|
-
draggable = _this$props2.draggable;
|
|
88
|
-
var MarkerConstructor = isDomMakerNeeded(nextProps.icon) ? H.map.DomMarker : H.map.Marker;
|
|
89
|
-
this.marker = new MarkerConstructor(this.getConvertedPosition(nextProps), {
|
|
90
|
-
icon: getOrCreateIcon(nextProps.icon)
|
|
91
|
-
});
|
|
92
|
-
this.marker.setData(customData);
|
|
93
|
-
this.marker.draggable = !!draggable;
|
|
94
|
-
this.context.group.addObject(this.marker);
|
|
95
|
-
addEventListenerMap(this.marker, nextProps.eventListenerMap, this.context.map);
|
|
102
|
+
}, [position, markerRef.current]);
|
|
103
|
+
|
|
104
|
+
// Update marker custom data
|
|
105
|
+
useEffect(function () {
|
|
106
|
+
if (markerRef.current) {
|
|
107
|
+
markerRef.current.setData(customData);
|
|
96
108
|
}
|
|
97
|
-
},
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
109
|
+
}, [customData, markerRef.current]);
|
|
110
|
+
|
|
111
|
+
// Update EventListenerMap
|
|
112
|
+
useEffect(function () {
|
|
113
|
+
if (markerRef.current) {
|
|
114
|
+
// use exports to make methods accessible for stubbing
|
|
115
|
+
var mapApi = removeEventListenerMap(markerRef.current);
|
|
116
|
+
addEventListenerMap(markerRef.current, eventListenerMap, mapApi);
|
|
105
117
|
}
|
|
106
|
-
},
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
118
|
+
}, [eventListenerMap, markerRef.current]);
|
|
119
|
+
|
|
120
|
+
// In case the map base layer has changed between day and night, update the marker
|
|
121
|
+
useEffect(function () {
|
|
122
|
+
if (!markerRef.current) {
|
|
123
|
+
return;
|
|
110
124
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
return _this2.checkPositionProperties(pos);
|
|
122
|
-
});
|
|
123
|
-
} else {
|
|
124
|
-
this.checkPositionProperties(position);
|
|
125
|
-
}
|
|
126
|
-
return position;
|
|
125
|
+
var newBaseLayer = api.settings.baseLayer;
|
|
126
|
+
console.log({
|
|
127
|
+
newBaseLayer: newBaseLayer
|
|
128
|
+
});
|
|
129
|
+
if (newBaseLayer !== currentBaseLayer) {
|
|
130
|
+
console.log(newBaseLayer);
|
|
131
|
+
|
|
132
|
+
// Update marker icons
|
|
133
|
+
markerRef.current.setIcon(getOrCreateIcon(icon, newBaseLayer));
|
|
134
|
+
setCurrentBaseLayer(newBaseLayer);
|
|
127
135
|
}
|
|
128
|
-
},
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
throw new MapException("Error in Marker: position object requires property \"".concat(propertyName, "\""));
|
|
135
|
-
}
|
|
136
|
-
});
|
|
136
|
+
}, [api.settings.baseLayer, markerRef.current]);
|
|
137
|
+
|
|
138
|
+
// If icon type changed, we need to change the marker type
|
|
139
|
+
useEffect(function () {
|
|
140
|
+
if (!(markerRef.current && icon)) {
|
|
141
|
+
return;
|
|
137
142
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
143
|
+
if (isDomMakerNeeded(icon)) {
|
|
144
|
+
destroyMarker(markerRef.current, api);
|
|
145
|
+
markerRef.current = setupMarker(props, api);
|
|
146
|
+
} else {
|
|
147
|
+
markerRef.current.setIcon(getOrCreateIcon(icon, api.settings.baseLayer));
|
|
142
148
|
}
|
|
143
|
-
}]);
|
|
144
|
-
return
|
|
145
|
-
}
|
|
146
|
-
Marker.contextType = MapContext;
|
|
149
|
+
}, [icon, markerRef.current]);
|
|
150
|
+
return null;
|
|
151
|
+
};
|
|
147
152
|
Marker.propTypes = {
|
|
148
153
|
position: PropTypes.oneOfType([mapProps.position, mapProps.positions]).isRequired,
|
|
149
154
|
icon: mapProps.icon,
|