@mapcomponents/react-maplibre 1.0.5 → 1.0.7
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/.eslintrc.cjs +1 -0
- package/CHANGELOG.md +13 -0
- package/dist/index.cjs.js +52 -13
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +52 -13
- package/dist/index.esm.js.map +1 -1
- package/package.json +2 -2
package/dist/index.esm.js
CHANGED
|
@@ -2410,15 +2410,6 @@ function useLayer(props) {
|
|
|
2410
2410
|
console.error('Failed to add layer:', error);
|
|
2411
2411
|
}
|
|
2412
2412
|
setLayer(function () { var _a; return (_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.map.getLayer(layerId.current); });
|
|
2413
|
-
if (typeof props.onHover !== 'undefined') {
|
|
2414
|
-
mapHook.map.on('mousemove', layerId.current, props.onHover, mapHook.componentId);
|
|
2415
|
-
}
|
|
2416
|
-
if (typeof props.onClick !== 'undefined') {
|
|
2417
|
-
mapHook.map.on('click', layerId.current, props.onClick, mapHook.componentId);
|
|
2418
|
-
}
|
|
2419
|
-
if (typeof props.onLeave !== 'undefined') {
|
|
2420
|
-
mapHook.map.on('mouseleave', layerId.current, props.onLeave, mapHook.componentId);
|
|
2421
|
-
}
|
|
2422
2413
|
// recreate layer if style has changed
|
|
2423
2414
|
var styledataEventHandler = function () {
|
|
2424
2415
|
var _a;
|
|
@@ -2539,6 +2530,48 @@ function useLayer(props) {
|
|
|
2539
2530
|
}
|
|
2540
2531
|
};
|
|
2541
2532
|
}, [mapHook.map, (_a = props.options) === null || _a === void 0 ? void 0 : _a.source]);
|
|
2533
|
+
// Reload onClick-handlers when they change
|
|
2534
|
+
useEffect(function () {
|
|
2535
|
+
var _a, _b, _c;
|
|
2536
|
+
if (!props.onClick || !(mapHook === null || mapHook === void 0 ? void 0 : mapHook.map) || !((_b = (_a = mapHook === null || mapHook === void 0 ? void 0 : mapHook.map) === null || _a === void 0 ? void 0 : _a.getLayer) === null || _b === void 0 ? void 0 : _b.call(_a, layerId.current)))
|
|
2537
|
+
return;
|
|
2538
|
+
var onClickHandler = props.onClick;
|
|
2539
|
+
(_c = mapHook.map) === null || _c === void 0 ? void 0 : _c.on('click', layerId.current, onClickHandler);
|
|
2540
|
+
return function () {
|
|
2541
|
+
var _a;
|
|
2542
|
+
if (onClickHandler && (mapHook === null || mapHook === void 0 ? void 0 : mapHook.map)) {
|
|
2543
|
+
(_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.off('click', layerId.current, onClickHandler);
|
|
2544
|
+
}
|
|
2545
|
+
};
|
|
2546
|
+
}, [mapHook.map, props.onClick]);
|
|
2547
|
+
// Reload onHover-handlers when they change
|
|
2548
|
+
useEffect(function () {
|
|
2549
|
+
var _a, _b, _c;
|
|
2550
|
+
if (!props.onHover || !(mapHook === null || mapHook === void 0 ? void 0 : mapHook.map) || !((_b = (_a = mapHook === null || mapHook === void 0 ? void 0 : mapHook.map) === null || _a === void 0 ? void 0 : _a.getLayer) === null || _b === void 0 ? void 0 : _b.call(_a, layerId.current)))
|
|
2551
|
+
return;
|
|
2552
|
+
var onHoverHandler = props.onHover;
|
|
2553
|
+
(_c = mapHook.map) === null || _c === void 0 ? void 0 : _c.on('mousemove', layerId.current, onHoverHandler);
|
|
2554
|
+
return function () {
|
|
2555
|
+
var _a;
|
|
2556
|
+
if (onHoverHandler && (mapHook === null || mapHook === void 0 ? void 0 : mapHook.map)) {
|
|
2557
|
+
(_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.off('mousemove', layerId.current, onHoverHandler);
|
|
2558
|
+
}
|
|
2559
|
+
};
|
|
2560
|
+
}, [mapHook.map, props.onHover]);
|
|
2561
|
+
// Reload onLeave-handlers when they change
|
|
2562
|
+
useEffect(function () {
|
|
2563
|
+
var _a, _b, _c;
|
|
2564
|
+
if (!props.onLeave || !(mapHook === null || mapHook === void 0 ? void 0 : mapHook.map) || !((_b = (_a = mapHook === null || mapHook === void 0 ? void 0 : mapHook.map) === null || _a === void 0 ? void 0 : _a.getLayer) === null || _b === void 0 ? void 0 : _b.call(_a, layerId.current)))
|
|
2565
|
+
return;
|
|
2566
|
+
var onLeaveHandler = props.onLeave;
|
|
2567
|
+
(_c = mapHook.map) === null || _c === void 0 ? void 0 : _c.on('mouseleave', layerId.current, onLeaveHandler);
|
|
2568
|
+
return function () {
|
|
2569
|
+
var _a;
|
|
2570
|
+
if (onLeaveHandler && (mapHook === null || mapHook === void 0 ? void 0 : mapHook.map)) {
|
|
2571
|
+
(_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.off('mouseleave', layerId.current, onLeaveHandler);
|
|
2572
|
+
}
|
|
2573
|
+
};
|
|
2574
|
+
}, [mapHook.map, props.onLeave]);
|
|
2542
2575
|
return {
|
|
2543
2576
|
map: mapHook.map,
|
|
2544
2577
|
layer: layer,
|
|
@@ -2655,7 +2688,7 @@ function useSource(props) {
|
|
|
2655
2688
|
var removeSource = useCallback(function () {
|
|
2656
2689
|
var _a, _b;
|
|
2657
2690
|
if (mapHook.map && ((_b = (_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.style) === null || _b === void 0 ? void 0 : _b._layers)) {
|
|
2658
|
-
for (var _i = 0, _c = Object.entries(mapHook.map.
|
|
2691
|
+
for (var _i = 0, _c = Object.entries(mapHook.map.style._layers); _i < _c.length; _i++) {
|
|
2659
2692
|
var _d = _c[_i], layerId = _d[0], layer = _d[1];
|
|
2660
2693
|
if (layer.source === sourceId.current) {
|
|
2661
2694
|
mapHook.map.removeLayer(layerId);
|
|
@@ -2731,7 +2764,7 @@ function useSource(props) {
|
|
|
2731
2764
|
* @component
|
|
2732
2765
|
*/
|
|
2733
2766
|
var MlGeoJsonLayer = function (props) {
|
|
2734
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
2767
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
2735
2768
|
var layerType = props.type || getDefaulLayerTypeByGeometry(props.geojson);
|
|
2736
2769
|
var layerId = useRef(props.layerId || 'MlGeoJsonLayer-' + v4());
|
|
2737
2770
|
var labelLayerId = "label-".concat(layerId.current);
|
|
@@ -2754,7 +2787,10 @@ var MlGeoJsonLayer = function (props) {
|
|
|
2754
2787
|
useLayer({
|
|
2755
2788
|
mapId: props.mapId,
|
|
2756
2789
|
layerId: layerId.current,
|
|
2757
|
-
options: __assign(__assign({
|
|
2790
|
+
options: __assign(__assign({}, (typeof ((_c = props === null || props === void 0 ? void 0 : props.options) === null || _c === void 0 ? void 0 : _c.source) !== 'undefined' &&
|
|
2791
|
+
typeof ((_d = props === null || props === void 0 ? void 0 : props.options) === null || _d === void 0 ? void 0 : _d.source) === 'string'
|
|
2792
|
+
? { source: props.options.source }
|
|
2793
|
+
: { source: 'source-' + layerId.current })), { paint: __assign(__assign({}, (props.paint || getDefaultPaintPropsByType(layerType, props.defaultPaintOverrides))), (_e = props === null || props === void 0 ? void 0 : props.options) === null || _e === void 0 ? void 0 : _e.paint), layout: __assign(__assign({}, ((props === null || props === void 0 ? void 0 : props.layout) || {})), (_f = props === null || props === void 0 ? void 0 : props.options) === null || _f === void 0 ? void 0 : _f.layout), type: layerType }),
|
|
2758
2794
|
insertBeforeLayer: props.insertBeforeLayer,
|
|
2759
2795
|
onHover: props.onHover,
|
|
2760
2796
|
onClick: props.onClick,
|
|
@@ -2764,7 +2800,10 @@ var MlGeoJsonLayer = function (props) {
|
|
|
2764
2800
|
// Using it with geojson and options.source undefined will cause it to return without creating a layer.
|
|
2765
2801
|
useLayer({
|
|
2766
2802
|
mapId: props.mapId,
|
|
2767
|
-
options: __assign(__assign(__assign(
|
|
2803
|
+
options: __assign(__assign(__assign(__assign(__assign({}, (typeof ((_g = props === null || props === void 0 ? void 0 : props.options) === null || _g === void 0 ? void 0 : _g.source) !== 'undefined' &&
|
|
2804
|
+
typeof ((_h = props === null || props === void 0 ? void 0 : props.options) === null || _h === void 0 ? void 0 : _h.source) === 'string'
|
|
2805
|
+
? { source: props.options.source }
|
|
2806
|
+
: { source: 'source-' + layerId.current })), { id: labelLayerId, type: 'symbol', maxzoom: 24, minzoom: 1 }), ((props === null || props === void 0 ? void 0 : props.labelOptions) ? props.labelOptions : {})), (((_j = props === null || props === void 0 ? void 0 : props.options) === null || _j === void 0 ? void 0 : _j.filter) ? { filter: props.options.filter } : {})), { layout: __assign(__assign({ 'text-font': ['Open Sans Regular'], 'text-field': "{".concat(props.labelProp, "}"), 'text-size': 12, 'text-anchor': 'top' }, (((_k = props === null || props === void 0 ? void 0 : props.labelOptions) === null || _k === void 0 ? void 0 : _k.layout) ? props.labelOptions.layout : {})), (((_l = props === null || props === void 0 ? void 0 : props.layout) === null || _l === void 0 ? void 0 : _l.visibility) ? { visibility: props.layout.visibility } : {})), paint: __assign({ 'text-halo-width': 1, 'text-halo-color': '#fefefe', 'text-color': '#121212' }, (((_m = props === null || props === void 0 ? void 0 : props.labelOptions) === null || _m === void 0 ? void 0 : _m.paint) ? props.labelOptions.paint : {})) }),
|
|
2768
2807
|
});
|
|
2769
2808
|
return React__default.createElement(React__default.Fragment, null);
|
|
2770
2809
|
};
|