@orioro/react-maplibre-util 0.0.1
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/README.md +1 -0
- package/dist/GeocoderCtrl_MapLibre/GeocoderCtrl.d.ts +16 -0
- package/dist/GeocoderCtrl_MapLibre/GeocoderCtrl.stories_.d.ts +11 -0
- package/dist/GeocoderCtrl_MapLibre/GeocoderCtrl_ref.d.ts +21 -0
- package/dist/GeocoderCtrl_MapLibre/mapboxGeocoderApi.d.ts +10 -0
- package/dist/GeocoderCtrl_MapLibre/nominatimGeocoderApi.d.ts +2 -0
- package/dist/HoverTooltip/HoverTooltip.d.ts +14 -0
- package/dist/HoverTooltip/index.d.ts +1 -0
- package/dist/LayeredMap/LayeredMap.d.ts +10 -0
- package/dist/LayeredMap/index.d.ts +2 -0
- package/dist/MapWindow/MapWindow.d.ts +72 -0
- package/dist/MapWindow/index.d.ts +1 -0
- package/dist/MapWindow/syncMaps.d.ts +8 -0
- package/dist/MapWindow/useSyncedMaps.d.ts +3 -0
- package/dist/MapWindow/util.d.ts +4 -0
- package/dist/MapboxGeocoder/MapboxGeocoder.d.ts +2 -0
- package/dist/MapboxGeocoder/MapboxGeocoder.stories_.d.ts +11 -0
- package/dist/MapboxGeocoder/mapboxGeocoderApi.d.ts +9 -0
- package/dist/SyncedMaps/GhostCursor.d.ts +2 -0
- package/dist/SyncedMaps/SyncedMaps.d.ts +309 -0
- package/dist/SyncedMaps/index.d.ts +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.mjs +825 -0
- package/dist/scales/index.d.ts +1 -0
- package/dist/scales/naturalBreaks/autoK.d.ts +5 -0
- package/dist/scales/naturalBreaks/index.d.ts +17 -0
- package/dist/tmpMapView/MapView.d.ts +3 -0
- package/dist/types.d.ts +27 -0
- package/dist/useHover/index.d.ts +2 -0
- package/dist/useHover/useHover.d.ts +21 -0
- package/dist/useHover/withHover.d.ts +2 -0
- package/dist/util/fitGeometry.d.ts +2 -0
- package/dist/util/index.d.ts +1 -0
- package/package.json +54 -0
package/dist/index.mjs
ADDED
@@ -0,0 +1,825 @@
|
|
1
|
+
import { __assign, __spreadArray, __rest, __makeTemplateObject } from 'tslib';
|
2
|
+
import React, { forwardRef, useRef, useMemo, useImperativeHandle, useEffect, useState, useCallback, createRef } from 'react';
|
3
|
+
import { Map, Source, Layer, useMap } from 'react-map-gl/maplibre';
|
4
|
+
import { isPlainObject, uniqBy, uniq, pick } from 'lodash-es';
|
5
|
+
import { Flex, useRefByKey } from '@orioro/react-ui-core';
|
6
|
+
import styled from 'styled-components';
|
7
|
+
import { mergeRefs } from 'react-merge-refs';
|
8
|
+
import { ckmeans } from 'simple-statistics';
|
9
|
+
import { schemeYlOrRd } from 'd3-scale-chromatic';
|
10
|
+
import { maxIndex, range, variance, sum } from 'd3';
|
11
|
+
import { bbox } from '@turf/turf';
|
12
|
+
|
13
|
+
function sortLayers(layers, _a) {
|
14
|
+
var existingLayers = _a.existingLayers;
|
15
|
+
var existingLayersById = existingLayers ? Object.fromEntries(existingLayers.map(function (layer) {
|
16
|
+
return [layer.id, layer];
|
17
|
+
})) : {};
|
18
|
+
//
|
19
|
+
// Apply ordering to layers
|
20
|
+
//
|
21
|
+
// About layer ordering:
|
22
|
+
// - Later in the list → Rendered on top (higher z-index).
|
23
|
+
// - Earlier in the list → Rendered below.
|
24
|
+
//
|
25
|
+
return layers.map(function (layer, index) {
|
26
|
+
return __assign(__assign({}, layer), {
|
27
|
+
//
|
28
|
+
// Allow for zIndex overriding
|
29
|
+
// In case no zIndex is set, respect the order in which
|
30
|
+
// layers were provided.
|
31
|
+
//
|
32
|
+
// Layers that come after are rendered on top of previous layers
|
33
|
+
//
|
34
|
+
zIndex: typeof layer.zIndex === 'number' ? layer.zIndex : index
|
35
|
+
});
|
36
|
+
})
|
37
|
+
//
|
38
|
+
// Order layers in ascending zIndex order, so that
|
39
|
+
// layers with higher zIndex are rendered later and on top of
|
40
|
+
// previous ones
|
41
|
+
//
|
42
|
+
.sort(function (layerA, layerB) {
|
43
|
+
return layerA.zIndex >= layerB.zIndex ? 1 : -1;
|
44
|
+
}).map(function (layer, index, sortedLayers) {
|
45
|
+
if (index === sortedLayers.length - 1) {
|
46
|
+
// is last layer
|
47
|
+
return layer;
|
48
|
+
} else {
|
49
|
+
var beforeId = sortedLayers[index + 1].id;
|
50
|
+
//
|
51
|
+
// If the layer this layer should be placed before exists,
|
52
|
+
// set beforeId. Otherwise, ignore beforeId.
|
53
|
+
//
|
54
|
+
// This handles the scenario in which layers are being added
|
55
|
+
// simultaneously
|
56
|
+
//
|
57
|
+
return existingLayersById[beforeId] ? __assign(__assign({}, layer), {
|
58
|
+
beforeId: beforeId
|
59
|
+
}) : layer;
|
60
|
+
}
|
61
|
+
});
|
62
|
+
}
|
63
|
+
function getSrcLayer(parsed, layerId) {
|
64
|
+
return parsed.layers.find(function (layer) {
|
65
|
+
return layer.id === layerId;
|
66
|
+
}) || null;
|
67
|
+
}
|
68
|
+
/**
|
69
|
+
* Given a layerId, attempts to retrieve the source mapView
|
70
|
+
*
|
71
|
+
* @param {MapViewsParseResult} parsed [description]
|
72
|
+
* @param {string} layerId [description]
|
73
|
+
* @param {[type]} [description]
|
74
|
+
* @return {MapView} [description]
|
75
|
+
*/
|
76
|
+
function getSrcViewByLayerId(parsed, layerId) {
|
77
|
+
var layer = getSrcLayer(parsed, layerId);
|
78
|
+
return layer ? parsed.srcMapViews.find(function (view) {
|
79
|
+
return view.id === layer.viewId;
|
80
|
+
}) || null : null;
|
81
|
+
}
|
82
|
+
function augmentFeature(parsed, feature) {
|
83
|
+
//
|
84
|
+
// Augment the feature with the mapView property
|
85
|
+
//
|
86
|
+
var mapView = getSrcViewByLayerId(parsed, feature.layer.id);
|
87
|
+
var layer = getSrcLayer(parsed, feature.layer.id);
|
88
|
+
return __assign(__assign({}, feature), {
|
89
|
+
layer: layer,
|
90
|
+
mapView: mapView
|
91
|
+
});
|
92
|
+
}
|
93
|
+
function parseMapViews(orderedViews, _a) {
|
94
|
+
var _b = _a === void 0 ? {} : _a,
|
95
|
+
existingLayers = _b.existingLayers;
|
96
|
+
var parsed = orderedViews.reduce(function (acc, _a) {
|
97
|
+
var viewId = _a.id,
|
98
|
+
sources = _a.sources,
|
99
|
+
layers = _a.layers;
|
100
|
+
var _sources = isPlainObject(sources) ? Object.entries(sources).reduce(function (acc, _a) {
|
101
|
+
var sourceRelativeId = _a[0],
|
102
|
+
source = _a[1];
|
103
|
+
return !source ? acc : __spreadArray(__spreadArray([], acc, true), [__assign(__assign({}, source), {
|
104
|
+
viewId: viewId,
|
105
|
+
id: source.absoluteId ? source.absoluteId : "".concat(viewId, "__").concat(sourceRelativeId)
|
106
|
+
})], false);
|
107
|
+
}, []) : [];
|
108
|
+
var _b = isPlainObject(layers) ? Object.entries(layers).reduce(function (acc, _a) {
|
109
|
+
var layerRelativeId = _a[0],
|
110
|
+
layer = _a[1];
|
111
|
+
if (!layer) {
|
112
|
+
return acc;
|
113
|
+
}
|
114
|
+
var layerId = layer.absoluteId ? layer.absoluteId : "".concat(viewId, "__").concat(layerRelativeId);
|
115
|
+
return {
|
116
|
+
interactiveLayerIds: layer.interactive ? __spreadArray(__spreadArray([], acc.interactiveLayerIds, true), [layerId], false) : acc.interactiveLayerIds,
|
117
|
+
_layers: __spreadArray(__spreadArray([], acc._layers, true), [__assign(__assign({}, layer), {
|
118
|
+
viewId: viewId,
|
119
|
+
id: layerId,
|
120
|
+
source: layer.absoluteSourceId ? layer.absoluteSourceId : "".concat(viewId, "__").concat(layer.source)
|
121
|
+
})], false)
|
122
|
+
};
|
123
|
+
}, {
|
124
|
+
interactiveLayerIds: [],
|
125
|
+
_layers: []
|
126
|
+
}) : {
|
127
|
+
_layers: [],
|
128
|
+
interactiveLayerIds: []
|
129
|
+
},
|
130
|
+
_layers = _b._layers,
|
131
|
+
interactiveLayerIds = _b.interactiveLayerIds;
|
132
|
+
return {
|
133
|
+
sources: __spreadArray(__spreadArray([], acc.sources, true), _sources, true),
|
134
|
+
layers: __spreadArray(__spreadArray([], acc.layers, true), _layers, true),
|
135
|
+
interactiveLayerIds: __spreadArray(__spreadArray([], acc.interactiveLayerIds, true), interactiveLayerIds, true)
|
136
|
+
};
|
137
|
+
}, {
|
138
|
+
sources: [],
|
139
|
+
layers: [],
|
140
|
+
interactiveLayerIds: []
|
141
|
+
});
|
142
|
+
return {
|
143
|
+
srcMapViews: orderedViews,
|
144
|
+
sources: uniqBy(parsed.sources, 'id'),
|
145
|
+
layers: sortLayers(uniqBy(parsed.layers, 'id'), {
|
146
|
+
existingLayers: existingLayers
|
147
|
+
}),
|
148
|
+
interactiveLayerIds: uniq(parsed.interactiveLayerIds)
|
149
|
+
};
|
150
|
+
}
|
151
|
+
|
152
|
+
// import { mergeRefs } from 'react-merge-refs'
|
153
|
+
//
|
154
|
+
// Augment mouse events with info from original view
|
155
|
+
//
|
156
|
+
var VIEW_AUGMENTED_EVENT_HANDLERS = ['onMouseDown', 'onMouseUp', 'onMouseOver',
|
157
|
+
//
|
158
|
+
// There is no notion of mouseenter/mouseleave
|
159
|
+
// in maplibre.gl
|
160
|
+
//
|
161
|
+
// https://github.com/mapbox/mapbox-gl-js/issues/10594
|
162
|
+
// https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/MapEventType/#mouseout
|
163
|
+
//
|
164
|
+
// 'onMouseEnter',
|
165
|
+
// 'onMouseLeave',
|
166
|
+
'onMouseMove', 'onMouseOut', 'onClick', 'onDblClick', 'onContextMenu'];
|
167
|
+
function useViewAugmentedEventHandlers(props, parsedMapViews) {
|
168
|
+
var handlers = Object.fromEntries(VIEW_AUGMENTED_EVENT_HANDLERS.map(function (handlerName) {
|
169
|
+
return typeof props[handlerName] === 'function' ? [handlerName, function (evt) {
|
170
|
+
var _a;
|
171
|
+
return props[handlerName](__assign(__assign({}, evt), {
|
172
|
+
features: (_a = evt.features) === null || _a === void 0 ? void 0 : _a.map(function (feat) {
|
173
|
+
return augmentFeature(parsedMapViews, feat);
|
174
|
+
})
|
175
|
+
}));
|
176
|
+
}] : null;
|
177
|
+
}).filter(Boolean));
|
178
|
+
return handlers;
|
179
|
+
}
|
180
|
+
var LayeredMap = /*#__PURE__*/forwardRef(function LayeredMapInner(_a, layeredMapRef) {
|
181
|
+
var views = _a.views,
|
182
|
+
_b = _a.interactiveLayerIds,
|
183
|
+
interactiveLayerIdsInput = _b === void 0 ? [] : _b,
|
184
|
+
children = _a.children;
|
185
|
+
_a.hover;
|
186
|
+
var mapProps = __rest(_a, ["views", "interactiveLayerIds", "children", "hover"]);
|
187
|
+
var mapRef = useRef(null);
|
188
|
+
//
|
189
|
+
// Parse sources, layers and interactiveLayerIds from
|
190
|
+
// views spec
|
191
|
+
//
|
192
|
+
var parsed = useMemo(function () {
|
193
|
+
var _a;
|
194
|
+
return views ? parseMapViews(views, {
|
195
|
+
existingLayers: mapRef.current ? ((_a = mapRef.current.getStyle()) === null || _a === void 0 ? void 0 : _a.layers) || null : null
|
196
|
+
}) : {
|
197
|
+
srcMapViews: [],
|
198
|
+
sources: [],
|
199
|
+
layers: [],
|
200
|
+
interactiveLayerIds: []
|
201
|
+
};
|
202
|
+
}, [views, mapRef.current]);
|
203
|
+
var evtHandlers = useViewAugmentedEventHandlers(mapProps, parsed);
|
204
|
+
useImperativeHandle(layeredMapRef, function () {
|
205
|
+
return {
|
206
|
+
map: mapRef.current,
|
207
|
+
augmentFeature: augmentFeature.bind(null, parsed),
|
208
|
+
getSrcViewByLayerId: getSrcViewByLayerId.bind(null, parsed),
|
209
|
+
getSrcLayer: getSrcLayer.bind(null, parsed)
|
210
|
+
};
|
211
|
+
}, [mapRef.current, parsed]);
|
212
|
+
return /*#__PURE__*/React.createElement(Map, __assign({
|
213
|
+
ref: mapRef,
|
214
|
+
interactiveLayerIds: __spreadArray(__spreadArray([], interactiveLayerIdsInput, true), parsed.interactiveLayerIds, true)
|
215
|
+
}, mapProps, evtHandlers), children, parsed.sources.map(function (_a) {
|
216
|
+
var id = _a.id;
|
217
|
+
_a.viewId;
|
218
|
+
var source = __rest(_a, ["id", "viewId"]);
|
219
|
+
return /*#__PURE__*/React.createElement(Source, __assign({
|
220
|
+
key: id,
|
221
|
+
id: id
|
222
|
+
}, source));
|
223
|
+
}), parsed.layers.map(function (_a) {
|
224
|
+
var id = _a.id,
|
225
|
+
layer = __rest(_a, ["id"]);
|
226
|
+
return /*#__PURE__*/React.createElement(Layer, __assign({
|
227
|
+
key: id,
|
228
|
+
id: id
|
229
|
+
}, layer));
|
230
|
+
}));
|
231
|
+
});
|
232
|
+
|
233
|
+
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"])));
|
234
|
+
var DataSectionHeading = styled.h3(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n margin: 0;\n line-height: 1.2;\n font-size: 1rem;\n"], ["\n margin: 0;\n line-height: 1.2;\n font-size: 1rem;\n"])));
|
235
|
+
var DataSectionContainer = styled(Flex)(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n padding: 15px 10px;\n"], ["\n padding: 15px 10px;\n"])));
|
236
|
+
var EntriesList = styled.ul(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n padding: 0;\n list-style: none;\n margin-bottom: 0;\n > li + li {\n margin-top: 4px;\n }\n // padding: 10px;\n"], ["\n padding: 0;\n list-style: none;\n margin-bottom: 0;\n > li + li {\n margin-top: 4px;\n }\n // padding: 10px;\n"])));
|
237
|
+
function DataSection(_a) {
|
238
|
+
var title = _a.title,
|
239
|
+
entries = _a.entries,
|
240
|
+
props = __rest(_a, ["title", "entries"]);
|
241
|
+
return entries.length > 0 && ( /*#__PURE__*/React.createElement(DataSectionContainer, __assign({
|
242
|
+
direction: "column",
|
243
|
+
gap: "10px"
|
244
|
+
}, props), title && /*#__PURE__*/React.createElement(DataSectionHeading, null, title), /*#__PURE__*/React.createElement(EntriesList, null, entries.map(function (_a, index) {
|
245
|
+
var label = _a[0],
|
246
|
+
value = _a[1];
|
247
|
+
return /*#__PURE__*/React.createElement("li", {
|
248
|
+
key: index
|
249
|
+
}, typeof label === 'string' ? /*#__PURE__*/React.createElement("span", null, label, ": ") : label, typeof value === 'string' ? ( /*#__PURE__*/React.createElement("span", {
|
250
|
+
style: {
|
251
|
+
fontWeight: 'bold'
|
252
|
+
}
|
253
|
+
}, value)) : value);
|
254
|
+
}))));
|
255
|
+
}
|
256
|
+
function HoverTooltip(_a) {
|
257
|
+
var position = _a.position,
|
258
|
+
children = _a.children,
|
259
|
+
dataSections = _a.dataSections,
|
260
|
+
_b = _a.style,
|
261
|
+
style = _b === void 0 ? {} : _b;
|
262
|
+
return /*#__PURE__*/React.createElement(Container, {
|
263
|
+
style: __assign({
|
264
|
+
left: position[0] + 15,
|
265
|
+
top: position[1] - 20
|
266
|
+
}, style)
|
267
|
+
}, Array.isArray(dataSections) && dataSections.length > 0 && ( /*#__PURE__*/React.createElement(Flex, {
|
268
|
+
direction: "column"
|
269
|
+
}, dataSections.map(function (section, index) {
|
270
|
+
return /*#__PURE__*/React.createElement(React.Fragment, {
|
271
|
+
key: index
|
272
|
+
}, /*#__PURE__*/React.createElement(DataSection, __assign({}, section)), index === dataSections.length - 1 ? null : ( /*#__PURE__*/React.createElement("div", {
|
273
|
+
style: {
|
274
|
+
width: '100%',
|
275
|
+
margin: 0,
|
276
|
+
borderBottom: '1px solid currentColor'
|
277
|
+
// marginBottom: 'none',
|
278
|
+
}
|
279
|
+
})));
|
280
|
+
}))), children);
|
281
|
+
}
|
282
|
+
var templateObject_1$2, templateObject_2, templateObject_3, templateObject_4;
|
283
|
+
|
284
|
+
function syncMaps(mainMap, targetMap, _a) {
|
285
|
+
var centerOffsetPixels = _a.centerOffsetPixels;
|
286
|
+
var center = mainMap.getCenter();
|
287
|
+
var zoom = mainMap.getZoom();
|
288
|
+
var bearing = mainMap.getBearing();
|
289
|
+
var pitch = mainMap.getPitch();
|
290
|
+
if (!centerOffsetPixels || !mainMap || !targetMap) {
|
291
|
+
console.warn('could not sync maps, missing centerOffsetPixels || mainMap || targetMap');
|
292
|
+
return;
|
293
|
+
}
|
294
|
+
// Convert the center to a pixel point
|
295
|
+
var centerPoint = mainMap.project(center);
|
296
|
+
// Apply the offset
|
297
|
+
var offsetPoint = {
|
298
|
+
x: centerPoint.x + centerOffsetPixels.x,
|
299
|
+
y: centerPoint.y + centerOffsetPixels.y
|
300
|
+
};
|
301
|
+
// Convert the offset pixel back to a lngLat
|
302
|
+
var newCenter = mainMap.unproject(offsetPoint);
|
303
|
+
// Move the mini-map to the new center
|
304
|
+
targetMap.jumpTo({
|
305
|
+
center: newCenter,
|
306
|
+
zoom: zoom,
|
307
|
+
bearing: bearing,
|
308
|
+
pitch: pitch
|
309
|
+
});
|
310
|
+
}
|
311
|
+
|
312
|
+
function useSyncedMaps(mainMapRef, otherMapRef, options, deps) {
|
313
|
+
useEffect(function () {
|
314
|
+
var _a, _b;
|
315
|
+
var mainMap = (_a = mainMapRef.current) === null || _a === void 0 ? void 0 : _a.getMap();
|
316
|
+
var otherMap = (_b = otherMapRef.current) === null || _b === void 0 ? void 0 : _b.getMap();
|
317
|
+
if (!mainMap || !otherMap) {
|
318
|
+
return;
|
319
|
+
}
|
320
|
+
var _syncMainToOther = function _syncMainToOther() {
|
321
|
+
syncMaps(mainMap, otherMap, options);
|
322
|
+
};
|
323
|
+
mainMap.on('move', _syncMainToOther);
|
324
|
+
_syncMainToOther();
|
325
|
+
// const _syncOtherToMain = () => {
|
326
|
+
// syncMaps(otherMap, mainMap, options)
|
327
|
+
// }
|
328
|
+
// otherMap.on('move', _syncOtherToMain)
|
329
|
+
return function () {
|
330
|
+
mainMap.off('move', _syncMainToOther);
|
331
|
+
// otherMap.off('move', _syncOtherToMain)
|
332
|
+
};
|
333
|
+
}, __spreadArray(__spreadArray([], deps, true), [options], false));
|
334
|
+
}
|
335
|
+
|
336
|
+
function getCenterOffsetPixels(mainMapContainer, targetMapContainer) {
|
337
|
+
var mainRect = mainMapContainer.getBoundingClientRect();
|
338
|
+
var targetRect = targetMapContainer.getBoundingClientRect();
|
339
|
+
var mainCenter = {
|
340
|
+
x: mainRect.left + mainRect.width / 2,
|
341
|
+
y: mainRect.top + mainRect.height / 2
|
342
|
+
};
|
343
|
+
var targetCenter = {
|
344
|
+
x: targetRect.left + targetRect.width / 2,
|
345
|
+
y: targetRect.top + targetRect.height / 2
|
346
|
+
};
|
347
|
+
return {
|
348
|
+
x: targetCenter.x - mainCenter.x,
|
349
|
+
y: targetCenter.y - mainCenter.y
|
350
|
+
};
|
351
|
+
}
|
352
|
+
|
353
|
+
var MapWindow = /*#__PURE__*/forwardRef(function MapWindowInner(_a, externalRef) {
|
354
|
+
var externalOnLoad = _a.onLoad,
|
355
|
+
mapProps = __rest(_a, ["onLoad"]);
|
356
|
+
var mapRef = /*#__PURE__*/createRef(null);
|
357
|
+
var mergedRef = mergeRefs([externalRef, mapRef]);
|
358
|
+
var _b = useState(null),
|
359
|
+
centerOffsetPixels = _b[0],
|
360
|
+
setCenterOffsetPixels = _b[1];
|
361
|
+
var _c = useState(false),
|
362
|
+
mapReady = _c[0],
|
363
|
+
setMapReady = _c[1];
|
364
|
+
var parentMapRef = useMap();
|
365
|
+
console.log('parentMapRef', parentMapRef);
|
366
|
+
useSyncedMaps(parentMapRef, mapRef, {
|
367
|
+
centerOffsetPixels: centerOffsetPixels
|
368
|
+
}, [centerOffsetPixels, mapReady]);
|
369
|
+
var _onLoad = useCallback(function (e) {
|
370
|
+
var _a, _b, _c, _d, _e;
|
371
|
+
var parentMap = (_a = parentMapRef.current) === null || _a === void 0 ? void 0 : _a.getMap();
|
372
|
+
var parentEl = (_c = (_b = parentMapRef.current) === null || _b === void 0 ? void 0 : _b.getContainer) === null || _c === void 0 ? void 0 : _c.call(_b);
|
373
|
+
var selfMap = e.target;
|
374
|
+
var selfEl = (_e = (_d = e.target) === null || _d === void 0 ? void 0 : _d.getContainer) === null || _e === void 0 ? void 0 : _e.call(_d);
|
375
|
+
//
|
376
|
+
// TODO: probably we need to check for parentMap load event as well.
|
377
|
+
//
|
378
|
+
if (!parentMap || !selfMap || !parentEl || !selfEl) {
|
379
|
+
console.log('MISSING', {
|
380
|
+
parentMap: parentMap,
|
381
|
+
selfMap: selfMap,
|
382
|
+
parentEl: parentEl,
|
383
|
+
selfEl: selfEl
|
384
|
+
});
|
385
|
+
return;
|
386
|
+
}
|
387
|
+
setCenterOffsetPixels(getCenterOffsetPixels(parentEl, selfEl));
|
388
|
+
setMapReady(true);
|
389
|
+
if (typeof externalOnLoad === 'function') {
|
390
|
+
externalOnLoad(e);
|
391
|
+
}
|
392
|
+
}, [setCenterOffsetPixels, setMapReady]);
|
393
|
+
return /*#__PURE__*/React.createElement(Map, __assign({
|
394
|
+
attributionControl: false
|
395
|
+
}, mapProps, {
|
396
|
+
onLoad: _onLoad,
|
397
|
+
ref: mergedRef
|
398
|
+
}));
|
399
|
+
});
|
400
|
+
|
401
|
+
var GhostCursor = styled.div(templateObject_1$1 || (templateObject_1$1 = __makeTemplateObject(["\n --synced-maps-ghost-cursor-size: 24px;\n position: absolute;\n\n height: 0;\n width: 0;\n color: inherit;\n\n &::before {\n content: '';\n display: block;\n background-color: currentColor;\n width: 1px;\n height: var(--synced-maps-ghost-cursor-size);\n position: absolute;\n top: calc(-1 * (var(--synced-maps-ghost-cursor-size) / 2));\n left: 0;\n }\n\n &::after {\n content: '';\n display: block;\n background-color: currentColor;\n height: 1px;\n width: var(--synced-maps-ghost-cursor-size);\n position: absolute;\n left: calc(-1 * (var(--synced-maps-ghost-cursor-size) / 2));\n top: 0;\n }\n"], ["\n --synced-maps-ghost-cursor-size: 24px;\n position: absolute;\n\n height: 0;\n width: 0;\n color: inherit;\n\n &::before {\n content: '';\n display: block;\n background-color: currentColor;\n width: 1px;\n height: var(--synced-maps-ghost-cursor-size);\n position: absolute;\n top: calc(-1 * (var(--synced-maps-ghost-cursor-size) / 2));\n left: 0;\n }\n\n &::after {\n content: '';\n display: block;\n background-color: currentColor;\n height: 1px;\n width: var(--synced-maps-ghost-cursor-size);\n position: absolute;\n left: calc(-1 * (var(--synced-maps-ghost-cursor-size) / 2));\n top: 0;\n }\n"])));
|
402
|
+
var templateObject_1$1;
|
403
|
+
|
404
|
+
function parseHoverInfo(index, event) {
|
405
|
+
return {
|
406
|
+
index: index,
|
407
|
+
point: [event.point.x, event.point.y],
|
408
|
+
coordinates: [event.lngLat.lng, event.lngLat.lat],
|
409
|
+
event: event
|
410
|
+
};
|
411
|
+
}
|
412
|
+
var SingleMapContainer = styled.div(templateObject_1 || (templateObject_1 = __makeTemplateObject([""], [""])));
|
413
|
+
function makeSyncedMaps(_a) {
|
414
|
+
var components = _a.components;
|
415
|
+
var MapComponent = components.Map;
|
416
|
+
return /*#__PURE__*/forwardRef(function SyncedMaps(_a, ref) {
|
417
|
+
var maps = _a.maps,
|
418
|
+
style = _a.style,
|
419
|
+
initialViewState = _a.initialViewState,
|
420
|
+
children = _a.children,
|
421
|
+
getTooltip = _a.tooltip,
|
422
|
+
baseMapProps = __rest(_a, ["maps", "style", "initialViewState", "children", "tooltip"]);
|
423
|
+
var _b = useRefByKey(),
|
424
|
+
mapInstanceRefs = _b[0],
|
425
|
+
setMapInstanceRef = _b[1];
|
426
|
+
var containerRef = useRef(null);
|
427
|
+
var _c = useState(initialViewState),
|
428
|
+
viewState = _c[0],
|
429
|
+
setViewState = _c[1];
|
430
|
+
var onSyncMove = useCallback(function (evt) {
|
431
|
+
return setViewState(evt.viewState);
|
432
|
+
}, []);
|
433
|
+
var _d = useState(false),
|
434
|
+
isDragging = _d[0],
|
435
|
+
setIsDragging = _d[1];
|
436
|
+
var onDragStart = useCallback(function () {
|
437
|
+
return setIsDragging(true);
|
438
|
+
}, [setIsDragging]);
|
439
|
+
var onDragEnd = useCallback(function () {
|
440
|
+
return setIsDragging(false);
|
441
|
+
}, [setIsDragging]);
|
442
|
+
var _e = useState(null),
|
443
|
+
hoverInfo = _e[0],
|
444
|
+
setHoverInfo = _e[1];
|
445
|
+
var _f = useState(null),
|
446
|
+
tooltips = _f[0],
|
447
|
+
setTooltips = _f[1];
|
448
|
+
var _onMouseMove = useCallback(function (index, event) {
|
449
|
+
var nextHoverInfo = parseHoverInfo(index, event);
|
450
|
+
setHoverInfo(nextHoverInfo);
|
451
|
+
setTooltips(typeof getTooltip === 'function' ? maps.map(function (_a, index) {
|
452
|
+
var _b = _a.tooltip,
|
453
|
+
tooltip = _b === void 0 ? true : _b;
|
454
|
+
if (!tooltip) {
|
455
|
+
return null;
|
456
|
+
}
|
457
|
+
return getTooltip(nextHoverInfo, mapInstanceRefs[index]) || null;
|
458
|
+
}) : null);
|
459
|
+
}, [maps]);
|
460
|
+
//
|
461
|
+
// Expose map instances
|
462
|
+
//
|
463
|
+
useImperativeHandle(ref, function () {
|
464
|
+
return {
|
465
|
+
mapInstances: mapInstanceRefs
|
466
|
+
};
|
467
|
+
}, [mapInstanceRefs]);
|
468
|
+
return /*#__PURE__*/React.createElement(Flex, {
|
469
|
+
ref: containerRef,
|
470
|
+
direction: "row",
|
471
|
+
style: __assign({
|
472
|
+
position: 'relative'
|
473
|
+
}, style || {})
|
474
|
+
}, maps.map(function (mapProps, index) {
|
475
|
+
return /*#__PURE__*/React.createElement(SingleMapContainer, {
|
476
|
+
key: mapProps.id || index,
|
477
|
+
style: {
|
478
|
+
position: 'absolute',
|
479
|
+
top: 0,
|
480
|
+
height: '100%',
|
481
|
+
left: "calc(".concat(index, " * (100% / ").concat(maps.length, "))"),
|
482
|
+
width: "calc(100% / ".concat(maps.length, ")")
|
483
|
+
}
|
484
|
+
}, !isDragging && hoverInfo && hoverInfo.index !== index ? ( /*#__PURE__*/React.createElement(GhostCursor, {
|
485
|
+
style: {
|
486
|
+
position: 'absolute',
|
487
|
+
left: hoverInfo.point[0],
|
488
|
+
top: hoverInfo.point[1],
|
489
|
+
zIndex: 2
|
490
|
+
}
|
491
|
+
})) : null, !isDragging && Array.isArray(tooltips) && tooltips[index], /*#__PURE__*/React.createElement(MapComponent, __assign({
|
492
|
+
ref: setMapInstanceRef(index),
|
493
|
+
cursor: isDragging ? 'grabbing' : 'default'
|
494
|
+
}, baseMapProps, mapProps, viewState || {}, {
|
495
|
+
style: __assign(__assign({}, mapProps.style || {}), {
|
496
|
+
position: 'absolute',
|
497
|
+
top: 0,
|
498
|
+
left: 0,
|
499
|
+
width: '100%',
|
500
|
+
height: '100%'
|
501
|
+
}),
|
502
|
+
onMove: onSyncMove,
|
503
|
+
onDragStart: onDragStart,
|
504
|
+
onDragEnd: onDragEnd,
|
505
|
+
onMouseMove: function onMouseMove(event) {
|
506
|
+
return _onMouseMove(index, event);
|
507
|
+
},
|
508
|
+
//
|
509
|
+
// There is no notion of mouseenter/mouseleave
|
510
|
+
// in maplibre.gl.
|
511
|
+
//
|
512
|
+
// Use onMouseOut instead
|
513
|
+
//
|
514
|
+
// https://github.com/mapbox/mapbox-gl-js/issues/10594
|
515
|
+
// https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/MapEventType/#mouseout
|
516
|
+
//
|
517
|
+
onMouseOut: function onMouseOut() {
|
518
|
+
setHoverInfo(null);
|
519
|
+
setTooltips(null);
|
520
|
+
}
|
521
|
+
})));
|
522
|
+
}), children);
|
523
|
+
});
|
524
|
+
}
|
525
|
+
var SyncedMaps = makeSyncedMaps({
|
526
|
+
components: {
|
527
|
+
Map: Map
|
528
|
+
}
|
529
|
+
});
|
530
|
+
var templateObject_1;
|
531
|
+
|
532
|
+
function hoverParseEvent(event) {
|
533
|
+
return {
|
534
|
+
point: [event.point.x, event.point.y],
|
535
|
+
coordinates: [event.lngLat.lng, event.lngLat.lat],
|
536
|
+
features: event.features
|
537
|
+
};
|
538
|
+
}
|
539
|
+
var DEFAULT_PROPS = {
|
540
|
+
parseEvent: hoverParseEvent
|
541
|
+
};
|
542
|
+
function useHover(props, deps) {
|
543
|
+
var _a;
|
544
|
+
if (props === void 0) {
|
545
|
+
props = DEFAULT_PROPS;
|
546
|
+
}
|
547
|
+
props = __assign(__assign({}, DEFAULT_PROPS), props);
|
548
|
+
var _b = useState(false),
|
549
|
+
isDragging = _b[0],
|
550
|
+
setIsDragging = _b[1];
|
551
|
+
var onDragStart = useCallback(function () {
|
552
|
+
return setIsDragging(true);
|
553
|
+
}, [setIsDragging]);
|
554
|
+
var onDragEnd = useCallback(function () {
|
555
|
+
return setIsDragging(false);
|
556
|
+
}, [setIsDragging]);
|
557
|
+
var _c = useState(null),
|
558
|
+
tooltip = _c[0],
|
559
|
+
setTooltip = _c[1];
|
560
|
+
var _d = useState(null),
|
561
|
+
hoverInfo = _d[0],
|
562
|
+
setHoverInfo = _d[1];
|
563
|
+
var onMouseMove = useCallback(function (event) {
|
564
|
+
var nextHoverInfo = props.parseEvent(event);
|
565
|
+
setHoverInfo(nextHoverInfo);
|
566
|
+
setTooltip(props.tooltip ? props.tooltip(nextHoverInfo) : null);
|
567
|
+
}, __spreadArray(__spreadArray([], deps, true), [props.tooltip], false));
|
568
|
+
//
|
569
|
+
// There is no notion of mouseenter/mouseleave
|
570
|
+
// in maplibre.gl.
|
571
|
+
//
|
572
|
+
// Use onMouseOut instead
|
573
|
+
//
|
574
|
+
// https://github.com/mapbox/mapbox-gl-js/issues/10594
|
575
|
+
// https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/MapEventType/#mouseout
|
576
|
+
//
|
577
|
+
var onMouseOut = useCallback(function () {
|
578
|
+
setHoverInfo(null);
|
579
|
+
setTooltip(null);
|
580
|
+
}, [setHoverInfo, setTooltip]);
|
581
|
+
return [{
|
582
|
+
onMouseMove: onMouseMove,
|
583
|
+
onMouseOut: onMouseOut,
|
584
|
+
onDragStart: onDragStart,
|
585
|
+
onDragEnd: onDragEnd,
|
586
|
+
cursor: isDragging ? 'grabbing' : ((_a = hoverInfo === null || hoverInfo === void 0 ? void 0 : hoverInfo.features) === null || _a === void 0 ? void 0 : _a.length) > 0 ? 'default' : 'grab',
|
587
|
+
children: isDragging ? null : /*#__PURE__*/React.createElement(React.Fragment, null, tooltip)
|
588
|
+
}, hoverInfo, isDragging];
|
589
|
+
}
|
590
|
+
|
591
|
+
function _iterableToArrayLimit(r, l) {
|
592
|
+
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
593
|
+
if (null != t) {
|
594
|
+
var e,
|
595
|
+
n,
|
596
|
+
i,
|
597
|
+
u,
|
598
|
+
a = [],
|
599
|
+
f = !0,
|
600
|
+
o = !1;
|
601
|
+
try {
|
602
|
+
if (i = (t = t.call(r)).next, 0 === l) {
|
603
|
+
if (Object(t) !== t) return;
|
604
|
+
f = !1;
|
605
|
+
} else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
|
606
|
+
} catch (r) {
|
607
|
+
o = !0, n = r;
|
608
|
+
} finally {
|
609
|
+
try {
|
610
|
+
if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
|
611
|
+
} finally {
|
612
|
+
if (o) throw n;
|
613
|
+
}
|
614
|
+
}
|
615
|
+
return a;
|
616
|
+
}
|
617
|
+
}
|
618
|
+
function _extends() {
|
619
|
+
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
620
|
+
for (var i = 1; i < arguments.length; i++) {
|
621
|
+
var source = arguments[i];
|
622
|
+
for (var key in source) {
|
623
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
624
|
+
target[key] = source[key];
|
625
|
+
}
|
626
|
+
}
|
627
|
+
}
|
628
|
+
return target;
|
629
|
+
};
|
630
|
+
return _extends.apply(this, arguments);
|
631
|
+
}
|
632
|
+
function _objectWithoutPropertiesLoose(source, excluded) {
|
633
|
+
if (source == null) return {};
|
634
|
+
var target = {};
|
635
|
+
var sourceKeys = Object.keys(source);
|
636
|
+
var key, i;
|
637
|
+
for (i = 0; i < sourceKeys.length; i++) {
|
638
|
+
key = sourceKeys[i];
|
639
|
+
if (excluded.indexOf(key) >= 0) continue;
|
640
|
+
target[key] = source[key];
|
641
|
+
}
|
642
|
+
return target;
|
643
|
+
}
|
644
|
+
function _objectWithoutProperties(source, excluded) {
|
645
|
+
if (source == null) return {};
|
646
|
+
var target = _objectWithoutPropertiesLoose(source, excluded);
|
647
|
+
var key, i;
|
648
|
+
if (Object.getOwnPropertySymbols) {
|
649
|
+
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
|
650
|
+
for (i = 0; i < sourceSymbolKeys.length; i++) {
|
651
|
+
key = sourceSymbolKeys[i];
|
652
|
+
if (excluded.indexOf(key) >= 0) continue;
|
653
|
+
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
654
|
+
target[key] = source[key];
|
655
|
+
}
|
656
|
+
}
|
657
|
+
return target;
|
658
|
+
}
|
659
|
+
function _slicedToArray(arr, i) {
|
660
|
+
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
661
|
+
}
|
662
|
+
function _arrayWithHoles(arr) {
|
663
|
+
if (Array.isArray(arr)) return arr;
|
664
|
+
}
|
665
|
+
function _unsupportedIterableToArray(o, minLen) {
|
666
|
+
if (!o) return;
|
667
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
668
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
669
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
670
|
+
if (n === "Map" || n === "Set") return Array.from(o);
|
671
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
672
|
+
}
|
673
|
+
function _arrayLikeToArray(arr, len) {
|
674
|
+
if (len == null || len > arr.length) len = arr.length;
|
675
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
676
|
+
return arr2;
|
677
|
+
}
|
678
|
+
function _nonIterableRest() {
|
679
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
680
|
+
}
|
681
|
+
|
682
|
+
var _excluded = ["cursor", "onMouseMove", "onDragStart", "onDragEnd", "children"];
|
683
|
+
function useMergedCallback(cbA, cbB) {
|
684
|
+
return useCallback(function () {
|
685
|
+
if (typeof cbA === 'function') {
|
686
|
+
cbA.apply(void 0, arguments);
|
687
|
+
}
|
688
|
+
if (typeof cbB === 'function') {
|
689
|
+
cbB.apply(void 0, arguments);
|
690
|
+
}
|
691
|
+
}, [cbA, cbB]);
|
692
|
+
}
|
693
|
+
function withHover(Component, withHoverProps) {
|
694
|
+
return /*#__PURE__*/forwardRef(function WithHover(_ref, ref) {
|
695
|
+
var cursor = _ref.cursor,
|
696
|
+
onMouseMove = _ref.onMouseMove,
|
697
|
+
onDragStart = _ref.onDragStart,
|
698
|
+
onDragEnd = _ref.onDragEnd,
|
699
|
+
children = _ref.children,
|
700
|
+
restProps = _objectWithoutProperties(_ref, _excluded);
|
701
|
+
//
|
702
|
+
// Hover stuff
|
703
|
+
//
|
704
|
+
var _useHover = useHover(withHoverProps, []),
|
705
|
+
_useHover2 = _slicedToArray(_useHover, 1),
|
706
|
+
hoverProps = _useHover2[0];
|
707
|
+
return /*#__PURE__*/React.createElement(Component, _extends({}, restProps, {
|
708
|
+
ref: ref,
|
709
|
+
cursor: cursor || hoverProps.cursor,
|
710
|
+
onMouseMove: useMergedCallback(onMouseMove, hoverProps.onMouseMove),
|
711
|
+
onDragStart: useMergedCallback(onDragStart, hoverProps.onDragStart),
|
712
|
+
onDragEnd: useMergedCallback(onDragEnd, hoverProps.onDragEnd)
|
713
|
+
}), hoverProps.children, children);
|
714
|
+
});
|
715
|
+
}
|
716
|
+
|
717
|
+
var DEFAULT_MIN_K = 3;
|
718
|
+
var DEFAULT_MAX_K = 9;
|
719
|
+
//
|
720
|
+
// https://observablehq.com/@visionscarto/natural-breaks
|
721
|
+
//
|
722
|
+
var elbowiness = function elbowiness(numbers, _a) {
|
723
|
+
_a[0];
|
724
|
+
var maxK = _a[1];
|
725
|
+
var intrass = __spreadArray([null], range(1, maxK + 1).map(function (k) {
|
726
|
+
return k === 1 ? variance(numbers) : sum(ckmeans(numbers, k), function (v) {
|
727
|
+
return variance(v);
|
728
|
+
});
|
729
|
+
}), true);
|
730
|
+
return range(0, intrass.length - 1).map(function (k) {
|
731
|
+
return k < 2 ? NaN : Math.log(intrass[k - 1]) + Math.log(intrass[k + 1]) - 2 * Math.log(intrass[k]);
|
732
|
+
});
|
733
|
+
};
|
734
|
+
function within(value, _a) {
|
735
|
+
var min = _a[0],
|
736
|
+
max = _a[1];
|
737
|
+
return Math.max(min, Math.min(max, value));
|
738
|
+
}
|
739
|
+
var autoK = function autoK(numbers, _a) {
|
740
|
+
var _b = _a === void 0 ? [DEFAULT_MIN_K, DEFAULT_MAX_K] : _a,
|
741
|
+
minK = _b[0],
|
742
|
+
maxK = _b[1];
|
743
|
+
return within(maxIndex(elbowiness(numbers, [minK, maxK]), function (score, k) {
|
744
|
+
return score / (1 + Math.sqrt(k));
|
745
|
+
}), [minK, maxK]);
|
746
|
+
};
|
747
|
+
|
748
|
+
// import greenlet from 'greenlet'
|
749
|
+
var DEFAULT_COLOR_SCALE = schemeYlOrRd;
|
750
|
+
function naturalBreakBounds(values, k) {
|
751
|
+
var groups = ckmeans(values, k);
|
752
|
+
var bounds = groups.map(function (group) {
|
753
|
+
return [group[0], group[group.length - 1]];
|
754
|
+
});
|
755
|
+
return bounds;
|
756
|
+
}
|
757
|
+
var DEFAULT_COLOR = 'transparent';
|
758
|
+
function scaleNaturalBreaks(_a) {
|
759
|
+
var values = _a.values,
|
760
|
+
k = _a.k,
|
761
|
+
_b = _a.defaultColor,
|
762
|
+
defaultColor = _b === void 0 ? DEFAULT_COLOR : _b,
|
763
|
+
_c = _a.minK,
|
764
|
+
minK = _c === void 0 ? DEFAULT_MIN_K : _c,
|
765
|
+
_d = _a.maxK,
|
766
|
+
maxK = _d === void 0 ? DEFAULT_MAX_K : _d,
|
767
|
+
_e = _a.scalesByK,
|
768
|
+
scalesByK = _e === void 0 ? DEFAULT_COLOR_SCALE : _e;
|
769
|
+
try {
|
770
|
+
values = values.filter(function (v) {
|
771
|
+
return typeof v === 'number' && !Number.isNaN(v);
|
772
|
+
});
|
773
|
+
k = typeof k === 'number' ? within(k, [minK, maxK]) : autoK(values, [minK, maxK]);
|
774
|
+
var bounds = naturalBreakBounds(values, k);
|
775
|
+
var scale_1 = scalesByK[k];
|
776
|
+
//
|
777
|
+
// Will produce an array such as:
|
778
|
+
// [
|
779
|
+
// "below_10",
|
780
|
+
// 10,
|
781
|
+
// "between_10_20",
|
782
|
+
// 20,
|
783
|
+
// "between_20_30",
|
784
|
+
// 30,
|
785
|
+
// "above_30"
|
786
|
+
// ]
|
787
|
+
//
|
788
|
+
var steps = bounds.map(function (_a, index) {
|
789
|
+
var min = _a[0],
|
790
|
+
max = _a[1];
|
791
|
+
var color = scale_1[index];
|
792
|
+
return index === 0 ? [defaultColor, min, color] : [min, color];
|
793
|
+
}).flat(1);
|
794
|
+
return steps;
|
795
|
+
} catch (err) {
|
796
|
+
console.error(err);
|
797
|
+
return null;
|
798
|
+
}
|
799
|
+
}
|
800
|
+
var $naturalBreaks = function $naturalBreaks(_a) {
|
801
|
+
var values = _a[0],
|
802
|
+
opt = _a[1];
|
803
|
+
var breaks = scaleNaturalBreaks(__assign({
|
804
|
+
values: values
|
805
|
+
}, isPlainObject(opt) ? pick(opt, ['scalesByK', 'k', 'minK', 'maxK']) : {}));
|
806
|
+
return breaks;
|
807
|
+
};
|
808
|
+
|
809
|
+
var DEFAULT_OPTIONS = {
|
810
|
+
padding: {
|
811
|
+
top: 60,
|
812
|
+
bottom: 60,
|
813
|
+
left: 60,
|
814
|
+
right: 60
|
815
|
+
}
|
816
|
+
};
|
817
|
+
function fitGeometry(map, geo, options) {
|
818
|
+
if (options === void 0) {
|
819
|
+
options = DEFAULT_OPTIONS;
|
820
|
+
}
|
821
|
+
var bounds = bbox(geo);
|
822
|
+
return map.fitBounds([[bounds[0], bounds[1]], [bounds[2], bounds[3]]], __assign(__assign({}, DEFAULT_OPTIONS), options));
|
823
|
+
}
|
824
|
+
|
825
|
+
export { $naturalBreaks, HoverTooltip, LayeredMap, MapWindow, SyncedMaps, augmentFeature, fitGeometry, getSrcLayer, getSrcViewByLayerId, hoverParseEvent, makeSyncedMaps, naturalBreakBounds, parseMapViews, scaleNaturalBreaks, sortLayers, useHover, withHover };
|