@orioro/react-maplibre-util 0.3.2 → 0.4.0
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/CHANGELOG.md +11 -0
- package/dist/LayeredMap/LayeredMap.d.ts +1 -0
- package/dist/LayeredMap/parseMapViews.d.ts +1 -0
- package/dist/index.mjs +22 -7
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
# @orioro/react-maplibre-util
|
2
2
|
|
3
|
+
## 0.4.0
|
4
|
+
|
5
|
+
### Minor Changes
|
6
|
+
|
7
|
+
- implement proof-of-concept of hover interaction on legend
|
8
|
+
|
9
|
+
### Patch Changes
|
10
|
+
|
11
|
+
- Updated dependencies
|
12
|
+
- @orioro/react-chart-util@0.2.0
|
13
|
+
|
3
14
|
## 0.3.2
|
4
15
|
|
5
16
|
### Patch Changes
|
@@ -2,6 +2,7 @@ import React from 'react';
|
|
2
2
|
import { MapInstance } from 'react-map-gl/maplibre';
|
3
3
|
import { LayeredMapProps } from '../types';
|
4
4
|
import { augmentFeature, getSrcLayer, getSrcViewByLayerId } from './parseMapViews';
|
5
|
+
export declare function useLayeredMap(): null;
|
5
6
|
export declare const LayeredMap: React.ForwardRefExoticComponent<Omit<LayeredMapProps, "ref"> & React.RefAttributes<{
|
6
7
|
map: MapInstance;
|
7
8
|
augmentFeature: (feature: Parameters<typeof augmentFeature>[1]) => ReturnType<typeof augmentFeature>;
|
@@ -41,5 +41,6 @@ export declare function augmentFeature(parsed: MapViewsParseResult, feature: Geo
|
|
41
41
|
properties: import("geojson").GeoJsonProperties;
|
42
42
|
bbox?: import("geojson").BBox | undefined;
|
43
43
|
};
|
44
|
+
export declare function fmtLayerAbsoluteId(viewId: string, layerRelativeId: string): string;
|
44
45
|
export declare function parseMapViews(orderedViews: MapView[], { existingLayers }?: ParseMapViewsOptions): MapViewsParseResult;
|
45
46
|
export {};
|
package/dist/index.mjs
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { __assign, __spreadArray, __rest, __makeTemplateObject } from 'tslib';
|
2
|
-
import React, { forwardRef, useRef, useMemo, useImperativeHandle, useState, useCallback, useLayoutEffect, useEffect, createRef } from 'react';
|
2
|
+
import React, { forwardRef, useContext, createContext, useRef, useMemo, useImperativeHandle, useState, useCallback, useLayoutEffect, useEffect, createRef } from 'react';
|
3
3
|
import { Map, Source, Layer, useMap, useControl } from 'react-map-gl/maplibre';
|
4
4
|
import { isPlainObject, uniq, uniqBy, pick, omit } from 'lodash-es';
|
5
5
|
import { Flex, useRefByKey, useLocalState, DropdownMenu } from '@orioro/react-ui-core';
|
@@ -53,7 +53,9 @@ function sortLayers(layers, _a) {
|
|
53
53
|
}).map(function (layer, index, sortedLayers) {
|
54
54
|
if (index === sortedLayers.length - 1) {
|
55
55
|
// is last layer
|
56
|
-
return layer
|
56
|
+
return __assign(__assign({}, layer), {
|
57
|
+
beforeId: null
|
58
|
+
});
|
57
59
|
} else {
|
58
60
|
var beforeId = sortedLayers[index + 1].id;
|
59
61
|
//
|
@@ -99,6 +101,9 @@ function augmentFeature(parsed, feature) {
|
|
99
101
|
mapView: mapView
|
100
102
|
});
|
101
103
|
}
|
104
|
+
function fmtLayerAbsoluteId(viewId, layerRelativeId) {
|
105
|
+
return "".concat(viewId, "__").concat(layerRelativeId);
|
106
|
+
}
|
102
107
|
function parseMapViews(orderedViews, _a) {
|
103
108
|
var _b = _a === void 0 ? {} : _a,
|
104
109
|
existingLayers = _b.existingLayers;
|
@@ -120,7 +125,8 @@ function parseMapViews(orderedViews, _a) {
|
|
120
125
|
if (!layer) {
|
121
126
|
return acc;
|
122
127
|
}
|
123
|
-
var layerId = layer.absoluteId ? layer.absoluteId :
|
128
|
+
var layerId = layer.absoluteId ? layer.absoluteId : fmtLayerAbsoluteId(viewId, layerRelativeId);
|
129
|
+
// : `${viewId}__${layerRelativeId}`
|
124
130
|
return {
|
125
131
|
interactiveLayerIds: layer.interactive ? __spreadArray(__spreadArray([], acc.interactiveLayerIds, true), [layerId], false) : acc.interactiveLayerIds,
|
126
132
|
_layers: __spreadArray(__spreadArray([], acc._layers, true), [__assign(__assign({}, layer), {
|
@@ -173,6 +179,10 @@ var VIEW_AUGMENTED_EVENT_HANDLERS = ['onMouseDown', 'onMouseUp', 'onMouseOver',
|
|
173
179
|
// 'onMouseEnter',
|
174
180
|
// 'onMouseLeave',
|
175
181
|
'onMouseMove', 'onMouseOut', 'onClick', 'onDblClick', 'onContextMenu'];
|
182
|
+
var LayeredMapContext = /*#__PURE__*/createContext(null);
|
183
|
+
function useLayeredMap() {
|
184
|
+
return useContext(LayeredMapContext);
|
185
|
+
}
|
176
186
|
function useViewAugmentedEventHandlers(props, parsedMapViews) {
|
177
187
|
var handlers = Object.fromEntries(VIEW_AUGMENTED_EVENT_HANDLERS.map(function (handlerName) {
|
178
188
|
return typeof props[handlerName] === 'function' ? [handlerName, function (evt) {
|
@@ -209,7 +219,7 @@ var LayeredMap = /*#__PURE__*/forwardRef(function LayeredMapInner(_a, layeredMap
|
|
209
219
|
};
|
210
220
|
}, [views, mapRef.current]);
|
211
221
|
var evtHandlers = useViewAugmentedEventHandlers(mapProps, parsed);
|
212
|
-
|
222
|
+
var imperativeHandle = useMemo(function () {
|
213
223
|
return {
|
214
224
|
map: mapRef.current,
|
215
225
|
augmentFeature: augmentFeature.bind(null, parsed),
|
@@ -217,10 +227,15 @@ var LayeredMap = /*#__PURE__*/forwardRef(function LayeredMapInner(_a, layeredMap
|
|
217
227
|
getSrcLayer: getSrcLayer.bind(null, parsed)
|
218
228
|
};
|
219
229
|
}, [mapRef.current, parsed]);
|
230
|
+
useImperativeHandle(layeredMapRef, function () {
|
231
|
+
return imperativeHandle;
|
232
|
+
}, [imperativeHandle]);
|
220
233
|
return /*#__PURE__*/React.createElement(Map, __assign({
|
221
234
|
ref: mapRef,
|
222
235
|
interactiveLayerIds: __spreadArray(__spreadArray([], interactiveLayerIdsInput, true), parsed.interactiveLayerIds, true)
|
223
|
-
}, mapProps, evtHandlers),
|
236
|
+
}, mapProps, evtHandlers), /*#__PURE__*/React.createElement(LayeredMapContext.Provider, {
|
237
|
+
value: imperativeHandle
|
238
|
+
}, children, parsed.sources.map(function (_a) {
|
224
239
|
var id = _a.id;
|
225
240
|
_a.viewId;
|
226
241
|
var source = __rest(_a, ["id", "viewId"]);
|
@@ -235,7 +250,7 @@ var LayeredMap = /*#__PURE__*/forwardRef(function LayeredMapInner(_a, layeredMap
|
|
235
250
|
key: id,
|
236
251
|
id: id
|
237
252
|
}, layer));
|
238
|
-
}));
|
253
|
+
})));
|
239
254
|
});
|
240
255
|
|
241
256
|
var Container = styled.div(templateObject_1$2 || (templateObject_1$2 = __makeTemplateObject(["\n pointer-events: none;\n position: absolute;\n z-index: 2;\n\n background: rgba(0, 0, 0, 0.5);\n border-radius: 16px;\n box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);\n backdrop-filter: blur(5px);\n -webkit-backdrop-filter: blur(5px);\n border: 1px solid rgba(0, 0, 0, 0.3);\n\n // background-color: black;\n color: white;\n border-radius: 5px;\n font-size: 0.9rem;\n\n max-width: 300px;\n\n hyphens: auto;\n word-break: break-word; /* Avoids overflow */\n overflow-wrap: break-word; /* Ensures long words break */\n white-space: normal;\n"], ["\n pointer-events: none;\n position: absolute;\n z-index: 2;\n\n background: rgba(0, 0, 0, 0.5);\n border-radius: 16px;\n box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);\n backdrop-filter: blur(5px);\n -webkit-backdrop-filter: blur(5px);\n border: 1px solid rgba(0, 0, 0, 0.3);\n\n // background-color: black;\n color: white;\n border-radius: 5px;\n font-size: 0.9rem;\n\n max-width: 300px;\n\n hyphens: auto;\n word-break: break-word; /* Avoids overflow */\n overflow-wrap: break-word; /* Ensures long words break */\n white-space: normal;\n"])));
|
@@ -1361,4 +1376,4 @@ function InspectControl(props) {
|
|
1361
1376
|
return null;
|
1362
1377
|
}
|
1363
1378
|
|
1364
|
-
export { $naturalBreaks, ControlContainer, HoverTooltip, InspectControl, LayeredMap, MapWindow, SyncedMaps, TerrainControl, applyReactStyle, augmentFeature, ensureAddLayer, ensureAddSource, ensureRemoveLayer, ensureRemoveSource, fitGeometry, getSrcLayer, getSrcViewByLayerId, hoverParseEvent, makeSyncedMaps, mapSetFeaturesState, naturalBreakBounds, parseMapViews, scaleNaturalBreaks, sortLayers, useClientRect, useHover, withHover };
|
1379
|
+
export { $naturalBreaks, ControlContainer, HoverTooltip, InspectControl, LayeredMap, MapWindow, SyncedMaps, TerrainControl, applyReactStyle, augmentFeature, ensureAddLayer, ensureAddSource, ensureRemoveLayer, ensureRemoveSource, fitGeometry, fmtLayerAbsoluteId, getSrcLayer, getSrcViewByLayerId, hoverParseEvent, makeSyncedMaps, mapSetFeaturesState, naturalBreakBounds, parseMapViews, scaleNaturalBreaks, sortLayers, useClientRect, useHover, useLayeredMap, withHover };
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@orioro/react-maplibre-util",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.4.0",
|
4
4
|
"packageManager": "yarn@4.0.2",
|
5
5
|
"type": "module",
|
6
6
|
"main": "dist/index.mjs",
|
@@ -50,7 +50,7 @@
|
|
50
50
|
"@maplibre/maplibre-gl-inspect": "^1.7.1",
|
51
51
|
"@mdi/js": "^7.4.47",
|
52
52
|
"@mdi/react": "^1.6.1",
|
53
|
-
"@orioro/react-chart-util": "^0.
|
53
|
+
"@orioro/react-chart-util": "^0.2.0",
|
54
54
|
"@orioro/react-select": "^3.0.2",
|
55
55
|
"@orioro/react-ui-core": "^0.0.6",
|
56
56
|
"@orioro/resolve": "^0.1.2",
|