@mapcomponents/react-maplibre 0.1.94 → 0.1.95
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 +9 -1
- package/dist/components/MlGeoJsonLayer/MlGeoJsonLayer.stories.d.ts +1 -0
- package/dist/index.d.ts +62 -57
- package/dist/index.esm.js +488 -453
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -57,6 +57,10 @@ var reactColor = require('react-color');
|
|
|
57
57
|
var TuneIcon = require('@mui/icons-material/Tune');
|
|
58
58
|
var ScatterPlotIcon = require('@mui/icons-material/ScatterPlot');
|
|
59
59
|
var PolylineIcon = require('@mui/icons-material/Polyline');
|
|
60
|
+
var csv2geojson = require('csv2geojson');
|
|
61
|
+
var osm2geojson = require('osm2geojson-lite');
|
|
62
|
+
var topojsonClient = require('topojson-client');
|
|
63
|
+
var externParser = require('@tmcw/togeojson');
|
|
60
64
|
var d3 = require('d3');
|
|
61
65
|
var core = require('@dnd-kit/core');
|
|
62
66
|
var modifiers = require('@dnd-kit/modifiers');
|
|
@@ -64,10 +68,6 @@ var PlaylistAddIcon = require('@mui/icons-material/PlaylistAdd');
|
|
|
64
68
|
var DynamicFeedIcon = require('@mui/icons-material/DynamicFeed');
|
|
65
69
|
var AddBoxIcon = require('@mui/icons-material/AddBox');
|
|
66
70
|
var IndeterminateCheckBoxIcon = require('@mui/icons-material/IndeterminateCheckBox');
|
|
67
|
-
var csv2geojson = require('csv2geojson');
|
|
68
|
-
var topojsonClient = require('topojson-client');
|
|
69
|
-
var osm2geojson = require('osm2geojson-lite');
|
|
70
|
-
var externParser = require('@tmcw/togeojson');
|
|
71
71
|
var KeyboardArrowDownIcon = require('@mui/icons-material/KeyboardArrowDown');
|
|
72
72
|
var KeyboardArrowUpIcon = require('@mui/icons-material/KeyboardArrowUp');
|
|
73
73
|
var AppBar = require('@mui/material/AppBar');
|
|
@@ -151,14 +151,14 @@ var Tooltip__default = /*#__PURE__*/_interopDefaultLegacy(Tooltip);
|
|
|
151
151
|
var TuneIcon__default = /*#__PURE__*/_interopDefaultLegacy(TuneIcon);
|
|
152
152
|
var ScatterPlotIcon__default = /*#__PURE__*/_interopDefaultLegacy(ScatterPlotIcon);
|
|
153
153
|
var PolylineIcon__default = /*#__PURE__*/_interopDefaultLegacy(PolylineIcon);
|
|
154
|
+
var csv2geojson__namespace = /*#__PURE__*/_interopNamespace(csv2geojson);
|
|
155
|
+
var osm2geojson__default = /*#__PURE__*/_interopDefaultLegacy(osm2geojson);
|
|
156
|
+
var externParser__namespace = /*#__PURE__*/_interopNamespace(externParser);
|
|
154
157
|
var d3__namespace = /*#__PURE__*/_interopNamespace(d3);
|
|
155
158
|
var PlaylistAddIcon__default = /*#__PURE__*/_interopDefaultLegacy(PlaylistAddIcon);
|
|
156
159
|
var DynamicFeedIcon__default = /*#__PURE__*/_interopDefaultLegacy(DynamicFeedIcon);
|
|
157
160
|
var AddBoxIcon__default = /*#__PURE__*/_interopDefaultLegacy(AddBoxIcon);
|
|
158
161
|
var IndeterminateCheckBoxIcon__default = /*#__PURE__*/_interopDefaultLegacy(IndeterminateCheckBoxIcon);
|
|
159
|
-
var csv2geojson__namespace = /*#__PURE__*/_interopNamespace(csv2geojson);
|
|
160
|
-
var osm2geojson__default = /*#__PURE__*/_interopDefaultLegacy(osm2geojson);
|
|
161
|
-
var externParser__namespace = /*#__PURE__*/_interopNamespace(externParser);
|
|
162
162
|
var KeyboardArrowDownIcon__default = /*#__PURE__*/_interopDefaultLegacy(KeyboardArrowDownIcon);
|
|
163
163
|
var KeyboardArrowUpIcon__default = /*#__PURE__*/_interopDefaultLegacy(KeyboardArrowUpIcon);
|
|
164
164
|
var AppBar__default = /*#__PURE__*/_interopDefaultLegacy(AppBar);
|
|
@@ -2437,7 +2437,7 @@ function useLayer(props) {
|
|
|
2437
2437
|
var initializedRef = React.useRef(false);
|
|
2438
2438
|
var layerId = React.useRef(props.layerId || (props.idPrefix ? props.idPrefix : 'Layer-') + mapHook.componentId);
|
|
2439
2439
|
var createLayer = React.useCallback(function () {
|
|
2440
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
2440
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
|
|
2441
2441
|
if (!mapHook.map || (mapHook === null || mapHook === void 0 ? void 0 : mapHook.map.cancelled))
|
|
2442
2442
|
return;
|
|
2443
2443
|
if (mapHook.map.map.getLayer(layerId.current)) {
|
|
@@ -2453,7 +2453,8 @@ function useLayer(props) {
|
|
|
2453
2453
|
}
|
|
2454
2454
|
if (typeof ((_b = props === null || props === void 0 ? void 0 : props.options) === null || _b === void 0 ? void 0 : _b.source) !== 'string' &&
|
|
2455
2455
|
!props.geojson &&
|
|
2456
|
-
!((_d = (_c = props === null || props === void 0 ? void 0 : props.options) === null || _c === void 0 ? void 0 : _c.source) === null || _d === void 0 ? void 0 : _d.data)
|
|
2456
|
+
!((_d = (_c = props === null || props === void 0 ? void 0 : props.options) === null || _c === void 0 ? void 0 : _c.source) === null || _d === void 0 ? void 0 : _d.data) &&
|
|
2457
|
+
((_e = props === null || props === void 0 ? void 0 : props.options) === null || _e === void 0 ? void 0 : _e.type) !== 'background') {
|
|
2457
2458
|
return;
|
|
2458
2459
|
}
|
|
2459
2460
|
if (typeof props.options.type === 'undefined') {
|
|
@@ -2462,21 +2463,21 @@ function useLayer(props) {
|
|
|
2462
2463
|
initializedRef.current = true;
|
|
2463
2464
|
try {
|
|
2464
2465
|
mapHook.map.addLayer(__assign(__assign(__assign(__assign({}, props.options), (props.geojson &&
|
|
2465
|
-
(!((
|
|
2466
|
-
(typeof ((
|
|
2467
|
-
((
|
|
2468
|
-
!((
|
|
2466
|
+
(!((_f = props.options) === null || _f === void 0 ? void 0 : _f.source) ||
|
|
2467
|
+
(typeof ((_g = props === null || props === void 0 ? void 0 : props.options) === null || _g === void 0 ? void 0 : _g.source) !== 'string' &&
|
|
2468
|
+
((_j = (_h = props.options) === null || _h === void 0 ? void 0 : _h.source) === null || _j === void 0 ? void 0 : _j.attribution) &&
|
|
2469
|
+
!((_l = (_k = props.options) === null || _k === void 0 ? void 0 : _k.source) === null || _l === void 0 ? void 0 : _l.type))) // if either options.source isn't defined or only options.source.attribution is defined
|
|
2469
2470
|
? {
|
|
2470
2471
|
source: {
|
|
2471
2472
|
type: 'geojson',
|
|
2472
2473
|
data: props.geojson,
|
|
2473
|
-
attribution: typeof ((
|
|
2474
|
-
? (
|
|
2474
|
+
attribution: typeof ((_m = props === null || props === void 0 ? void 0 : props.options) === null || _m === void 0 ? void 0 : _m.source) !== 'string' && ((_o = props.options.source) === null || _o === void 0 ? void 0 : _o.attribution)
|
|
2475
|
+
? (_p = props.options.source) === null || _p === void 0 ? void 0 : _p.attribution
|
|
2475
2476
|
: '',
|
|
2476
2477
|
},
|
|
2477
2478
|
// eslint-disable-next-line no-mixed-spaces-and-tabs
|
|
2478
2479
|
}
|
|
2479
|
-
: {})), (typeof ((
|
|
2480
|
+
: {})), (typeof ((_q = props.options) === null || _q === void 0 ? void 0 : _q.source) === 'string'
|
|
2480
2481
|
? {
|
|
2481
2482
|
source: props.options.source,
|
|
2482
2483
|
// eslint-disable-next-line no-mixed-spaces-and-tabs
|
|
@@ -2507,19 +2508,19 @@ function useLayer(props) {
|
|
|
2507
2508
|
createLayer();
|
|
2508
2509
|
}
|
|
2509
2510
|
}, mapHook.componentId);
|
|
2510
|
-
layerPaintConfRef.current = JSON.stringify((
|
|
2511
|
-
layerLayoutConfRef.current = JSON.stringify((
|
|
2511
|
+
layerPaintConfRef.current = JSON.stringify((_r = props.options) === null || _r === void 0 ? void 0 : _r.paint);
|
|
2512
|
+
layerLayoutConfRef.current = JSON.stringify((_s = props.options) === null || _s === void 0 ? void 0 : _s.layout);
|
|
2512
2513
|
layerTypeRef.current = props.options.type;
|
|
2513
2514
|
}, [props, mapHook]);
|
|
2514
2515
|
React.useEffect(function () {
|
|
2515
|
-
var _a, _b, _c, _d;
|
|
2516
|
+
var _a, _b, _c, _d, _e;
|
|
2516
2517
|
if (!mapHook.map)
|
|
2517
2518
|
return;
|
|
2518
|
-
if (!props.geojson && !props.options.source)
|
|
2519
|
+
if (!props.geojson && !props.options.source && ((_a = props === null || props === void 0 ? void 0 : props.options) === null || _a === void 0 ? void 0 : _a.type) !== 'background')
|
|
2519
2520
|
return;
|
|
2520
|
-
if (((
|
|
2521
|
+
if (((_b = mapHook.map) === null || _b === void 0 ? void 0 : _b.cancelled) === false &&
|
|
2521
2522
|
initializedRef.current &&
|
|
2522
|
-
((
|
|
2523
|
+
((_e = (_d = (_c = mapHook === null || mapHook === void 0 ? void 0 : mapHook.map) === null || _c === void 0 ? void 0 : _c.map) === null || _d === void 0 ? void 0 : _d.getLayer) === null || _e === void 0 ? void 0 : _e.call(_d, layerId.current)) &&
|
|
2523
2524
|
(legalLayerTypes.indexOf(props.options.type) === -1 ||
|
|
2524
2525
|
(legalLayerTypes.indexOf(props.options.type) !== -1 &&
|
|
2525
2526
|
props.options.type === layerTypeRef.current))) {
|
|
@@ -2780,7 +2781,7 @@ function useSource(props) {
|
|
|
2780
2781
|
* @component
|
|
2781
2782
|
*/
|
|
2782
2783
|
var MlGeoJsonLayer = function (props) {
|
|
2783
|
-
var _a, _b, _c, _d, _e;
|
|
2784
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
2784
2785
|
var layerType = props.type || getDefaulLayerTypeByGeometry(props.geojson);
|
|
2785
2786
|
var layerId = React.useRef(props.layerId || 'MlGeoJsonLayer-' + uuid.v4());
|
|
2786
2787
|
var labelLayerId = "label-".concat(layerId.current);
|
|
@@ -2794,16 +2795,16 @@ var MlGeoJsonLayer = function (props) {
|
|
|
2794
2795
|
}, [props.layerId]);
|
|
2795
2796
|
useSource({
|
|
2796
2797
|
mapId: props.mapId,
|
|
2797
|
-
sourceId:
|
|
2798
|
-
source: {
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2798
|
+
sourceId: 'source-' + layerId.current,
|
|
2799
|
+
source: __assign({ type: 'geojson', data: props.geojson }, (typeof ((_a = props === null || props === void 0 ? void 0 : props.options) === null || _a === void 0 ? void 0 : _a.source) !== 'undefined' &&
|
|
2800
|
+
typeof ((_b = props === null || props === void 0 ? void 0 : props.options) === null || _b === void 0 ? void 0 : _b.source) !== 'string'
|
|
2801
|
+
? props.options.source
|
|
2802
|
+
: {})),
|
|
2802
2803
|
});
|
|
2803
2804
|
useLayer({
|
|
2804
2805
|
mapId: props.mapId,
|
|
2805
2806
|
layerId: layerId.current,
|
|
2806
|
-
options: __assign(__assign({ source:
|
|
2807
|
+
options: __assign(__assign({}, props.options), { source: 'source-' + layerId.current, paint: __assign(__assign({}, (props.paint || getDefaultPaintPropsByType(layerType, props.defaultPaintOverrides))), (_c = props === null || props === void 0 ? void 0 : props.options) === null || _c === void 0 ? void 0 : _c.paint), layout: __assign(__assign({}, ((props === null || props === void 0 ? void 0 : props.layout) || {})), (_d = props === null || props === void 0 ? void 0 : props.options) === null || _d === void 0 ? void 0 : _d.layout), type: layerType }),
|
|
2807
2808
|
insertBeforeLayer: props.insertBeforeLayer,
|
|
2808
2809
|
onHover: props.onHover,
|
|
2809
2810
|
onClick: props.onClick,
|
|
@@ -2813,11 +2814,7 @@ var MlGeoJsonLayer = function (props) {
|
|
|
2813
2814
|
// Using it with geojson and options.source undefined will cause it to return without creating a layer.
|
|
2814
2815
|
useLayer({
|
|
2815
2816
|
mapId: props.mapId,
|
|
2816
|
-
options: __assign(__assign(__assign({ source: props.labelProp ?
|
|
2817
|
-
'text-halo-width': 1,
|
|
2818
|
-
'text-halo-color': '#fefefe',
|
|
2819
|
-
'text-color': '#121212',
|
|
2820
|
-
} }),
|
|
2817
|
+
options: __assign(__assign(__assign({ source: props.labelProp ? 'source-' + layerId.current : undefined, id: labelLayerId, type: 'symbol', maxzoom: 24, minzoom: 1 }, ((props === null || props === void 0 ? void 0 : props.labelOptions) ? props.labelOptions : {})), (((_e = props === null || props === void 0 ? void 0 : props.options) === null || _e === void 0 ? void 0 : _e.filter) ? { filter: props.options.filter } : {})), { layout: __assign(__assign({ 'text-font': ['Open Sans Regular'], 'text-field': "{".concat(props.labelProp, "}"), 'text-size': 12, 'text-anchor': 'top' }, (((_f = props === null || props === void 0 ? void 0 : props.labelOptions) === null || _f === void 0 ? void 0 : _f.layout) ? props.labelOptions.layout : {})), (((_g = props === null || props === void 0 ? void 0 : props.layout) === null || _g === void 0 ? void 0 : _g.visibility) ? { visibility: props.layout.visibility } : {})), paint: __assign({ 'text-halo-width': 1, 'text-halo-color': '#fefefe', 'text-color': '#121212' }, (((_h = props === null || props === void 0 ? void 0 : props.labelOptions) === null || _h === void 0 ? void 0 : _h.paint) ? props.labelOptions.paint : {})) }),
|
|
2821
2818
|
});
|
|
2822
2819
|
return React__default["default"].createElement(React__default["default"].Fragment, null);
|
|
2823
2820
|
};
|
|
@@ -3030,10 +3027,10 @@ var MlMeasureTool = function (props) {
|
|
|
3030
3027
|
value = result * 1000000;
|
|
3031
3028
|
}
|
|
3032
3029
|
if (getUnitLabel(props.unit) === 'mi') {
|
|
3033
|
-
label = '
|
|
3034
|
-
value = result *
|
|
3030
|
+
label = 'Yard';
|
|
3031
|
+
value = result * 1760;
|
|
3035
3032
|
if (props.measureType === 'polygon') {
|
|
3036
|
-
value = result *
|
|
3033
|
+
value = result * 3097600;
|
|
3037
3034
|
}
|
|
3038
3035
|
}
|
|
3039
3036
|
setDisplayValue({ value: value, label: label });
|
|
@@ -7201,173 +7198,457 @@ useAddProtocol.defaultProps = {
|
|
|
7201
7198
|
mapId: undefined,
|
|
7202
7199
|
};
|
|
7203
7200
|
|
|
7204
|
-
|
|
7205
|
-
var
|
|
7206
|
-
|
|
7207
|
-
var
|
|
7208
|
-
|
|
7209
|
-
|
|
7210
|
-
|
|
7211
|
-
|
|
7212
|
-
|
|
7213
|
-
|
|
7214
|
-
|
|
7215
|
-
|
|
7216
|
-
|
|
7217
|
-
}
|
|
7218
|
-
|
|
7219
|
-
} else if (props.format === "xml") {
|
|
7220
|
-
data_promise = d3__namespace.xml(props.url);
|
|
7221
|
-
}
|
|
7222
|
-
if (data_promise) {
|
|
7223
|
-
data_promise.then(function (received_data) {
|
|
7224
|
-
if (props.format === "xml") {
|
|
7225
|
-
if (props.nodeType) {
|
|
7226
|
-
var dataTmp = [];
|
|
7227
|
-
received_data.querySelectorAll(props.nodeType).forEach(function (el) {
|
|
7228
|
-
dataTmp.push(props.formatData(el));
|
|
7229
|
-
});
|
|
7230
|
-
setData(dataTmp);
|
|
7231
|
-
}
|
|
7232
|
-
} else {
|
|
7233
|
-
if (props.data_property) {
|
|
7234
|
-
received_data = received_data[props.data_property];
|
|
7235
|
-
}
|
|
7236
|
-
if (typeof props.formatData === "function") {
|
|
7237
|
-
setData(received_data.map(props.formatData));
|
|
7238
|
-
} else {
|
|
7239
|
-
setData(received_data);
|
|
7240
|
-
}
|
|
7241
|
-
}
|
|
7242
|
-
if (typeof props.onData === "function") {
|
|
7243
|
-
props.onData();
|
|
7244
|
-
}
|
|
7245
|
-
});
|
|
7246
|
-
}
|
|
7247
|
-
}, [props.url, props]);
|
|
7248
|
-
var value = {
|
|
7249
|
-
data: data,
|
|
7250
|
-
setData: setData
|
|
7251
|
-
};
|
|
7252
|
-
return /*#__PURE__*/React__default["default"].createElement(SimpleDataContextProvider, {
|
|
7253
|
-
value: value
|
|
7254
|
-
}, props.children);
|
|
7255
|
-
};
|
|
7256
|
-
SimpleDataProvider.propTypes = {
|
|
7257
|
-
children: PropTypes__default["default"].node.isRequired
|
|
7258
|
-
};
|
|
7201
|
+
function protocolPathParser(url) {
|
|
7202
|
+
var test = url.split('?');
|
|
7203
|
+
var urlParts = test[0].split('://');
|
|
7204
|
+
var protocolId = urlParts[0];
|
|
7205
|
+
var csvUrl = urlParts.length > 2 ? urlParts[1] + '://' + urlParts[2] : urlParts[1];
|
|
7206
|
+
var csvParts = csvUrl.split('/');
|
|
7207
|
+
var filename = csvParts.join('/');
|
|
7208
|
+
var optionsString = decodeURI(test[1]);
|
|
7209
|
+
var options = Object.fromEntries(new URLSearchParams(optionsString));
|
|
7210
|
+
return {
|
|
7211
|
+
protocolId: protocolId,
|
|
7212
|
+
filename: filename,
|
|
7213
|
+
options: options,
|
|
7214
|
+
};
|
|
7215
|
+
}
|
|
7259
7216
|
|
|
7260
|
-
|
|
7261
|
-
|
|
7262
|
-
|
|
7263
|
-
function
|
|
7264
|
-
|
|
7217
|
+
function getProtocolData(path) {
|
|
7218
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
7219
|
+
var response, rawData, error_1;
|
|
7220
|
+
return __generator(this, function (_a) {
|
|
7221
|
+
switch (_a.label) {
|
|
7222
|
+
case 0:
|
|
7223
|
+
_a.trys.push([0, 3, , 4]);
|
|
7224
|
+
return [4 /*yield*/, fetch(path)];
|
|
7225
|
+
case 1:
|
|
7226
|
+
response = _a.sent();
|
|
7227
|
+
return [4 /*yield*/, response.text()];
|
|
7228
|
+
case 2:
|
|
7229
|
+
rawData = _a.sent();
|
|
7230
|
+
return [2 /*return*/, rawData];
|
|
7231
|
+
case 3:
|
|
7232
|
+
error_1 = _a.sent();
|
|
7233
|
+
console.error('File could not be loaded: ', error_1);
|
|
7234
|
+
return [2 /*return*/, error_1];
|
|
7235
|
+
case 4: return [2 /*return*/];
|
|
7236
|
+
}
|
|
7237
|
+
});
|
|
7238
|
+
});
|
|
7265
7239
|
}
|
|
7266
7240
|
|
|
7267
|
-
|
|
7268
|
-
|
|
7269
|
-
|
|
7270
|
-
|
|
7271
|
-
|
|
7272
|
-
|
|
7273
|
-
|
|
7274
|
-
|
|
7275
|
-
|
|
7276
|
-
|
|
7277
|
-
|
|
7278
|
-
|
|
7279
|
-
|
|
7280
|
-
|
|
7281
|
-
|
|
7282
|
-
|
|
7283
|
-
|
|
7284
|
-
|
|
7285
|
-
|
|
7286
|
-
|
|
7287
|
-
|
|
7288
|
-
|
|
7289
|
-
|
|
7290
|
-
|
|
7291
|
-
|
|
7292
|
-
|
|
7293
|
-
|
|
7294
|
-
|
|
7295
|
-
|
|
7296
|
-
|
|
7297
|
-
|
|
7298
|
-
|
|
7299
|
-
|
|
7300
|
-
|
|
7301
|
-
|
|
7302
|
-
|
|
7303
|
-
_bbox = turf.bbox(_geojson);
|
|
7304
|
-
}
|
|
7305
|
-
break;
|
|
7306
|
-
case 'vt':
|
|
7307
|
-
console.log('vt');
|
|
7308
|
-
break;
|
|
7309
|
-
case 'wms':
|
|
7310
|
-
_bbox = (_o = (_m = (_l = (_k = layer === null || layer === void 0 ? void 0 : layer.config) === null || _k === void 0 ? void 0 : _k.config) === null || _l === void 0 ? void 0 : _l.layers) === null || _m === void 0 ? void 0 : _m[0]) === null || _o === void 0 ? void 0 : _o.EX_GeographicBoundingBox;
|
|
7311
|
-
break;
|
|
7312
|
-
default:
|
|
7313
|
-
return;
|
|
7241
|
+
function convertCsv(filename, options) {
|
|
7242
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
7243
|
+
var geojson;
|
|
7244
|
+
return __generator(this, function (_a) {
|
|
7245
|
+
switch (_a.label) {
|
|
7246
|
+
case 0: return [4 /*yield*/, new Promise(function (resolve, reject) {
|
|
7247
|
+
var useOptions = options || {};
|
|
7248
|
+
var extension = filename.substring(filename.length - 3);
|
|
7249
|
+
if (extension === 'tsv') {
|
|
7250
|
+
options.delimiter = '\t';
|
|
7251
|
+
}
|
|
7252
|
+
getProtocolData(filename).then(function (rawData) {
|
|
7253
|
+
// Use the csv2geojson library to convert the CSV to GeoJSON
|
|
7254
|
+
csv2geojson__namespace.csv2geojson(rawData, useOptions, function (err, data) {
|
|
7255
|
+
if (err) {
|
|
7256
|
+
reject(err);
|
|
7257
|
+
}
|
|
7258
|
+
else {
|
|
7259
|
+
resolve(data);
|
|
7260
|
+
}
|
|
7261
|
+
});
|
|
7262
|
+
});
|
|
7263
|
+
})];
|
|
7264
|
+
case 1:
|
|
7265
|
+
geojson = _a.sent();
|
|
7266
|
+
return [2 /*return*/, geojson];
|
|
7267
|
+
}
|
|
7268
|
+
});
|
|
7269
|
+
});
|
|
7270
|
+
}
|
|
7271
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7272
|
+
var CSVProtocolHandler = function (params, callback) {
|
|
7273
|
+
var parsedParams = protocolPathParser(params.url);
|
|
7274
|
+
convertCsv(parsedParams.filename, parsedParams.options).then(function (data) {
|
|
7275
|
+
if (data !== undefined) {
|
|
7276
|
+
callback(null, data, null, null);
|
|
7314
7277
|
}
|
|
7315
|
-
|
|
7316
|
-
(
|
|
7278
|
+
else {
|
|
7279
|
+
callback(new Error('CSV not found'));
|
|
7317
7280
|
}
|
|
7318
|
-
}
|
|
7319
|
-
var orderLayers = React.useMemo(function () {
|
|
7320
|
-
var layerIds = __spreadArray(__spreadArray([
|
|
7321
|
-
'order-background'
|
|
7322
|
-
], __spreadArray([], layerContext.layers, true).map(function (_el, idx) { return 'content_order_' + idx; }), true), [
|
|
7323
|
-
'order-labels',
|
|
7324
|
-
], false);
|
|
7325
|
-
return layerIds.reverse();
|
|
7326
|
-
}, [layerContext.layers]);
|
|
7327
|
-
var layers = React.useMemo(function () {
|
|
7328
|
-
if (props.layers)
|
|
7329
|
-
return props.layers;
|
|
7330
|
-
if (layerContext === null || layerContext === void 0 ? void 0 : layerContext.layers)
|
|
7331
|
-
return layerContext.layers;
|
|
7332
|
-
return [];
|
|
7333
|
-
}, [props.layers, layerContext.layers]);
|
|
7334
|
-
var setLayers = React.useMemo(function () {
|
|
7335
|
-
if (props.setLayers)
|
|
7336
|
-
return props.setLayers;
|
|
7337
|
-
return layerContext.setLayers;
|
|
7338
|
-
}, [props.setLayers, layerContext.setLayers]);
|
|
7339
|
-
var pointerSensor = core.useSensor(core.PointerSensor, {
|
|
7340
|
-
activationConstraint: {
|
|
7341
|
-
distance: 5,
|
|
7342
|
-
},
|
|
7343
|
-
});
|
|
7344
|
-
var mouseSensor = core.useSensor(core.MouseSensor, {
|
|
7345
|
-
activationConstraint: {
|
|
7346
|
-
distance: 5,
|
|
7347
|
-
},
|
|
7348
7281
|
});
|
|
7349
|
-
|
|
7350
|
-
|
|
7351
|
-
|
|
7352
|
-
|
|
7353
|
-
|
|
7354
|
-
|
|
7355
|
-
|
|
7356
|
-
|
|
7357
|
-
|
|
7358
|
-
|
|
7359
|
-
|
|
7360
|
-
|
|
7361
|
-
|
|
7362
|
-
|
|
7363
|
-
|
|
7364
|
-
|
|
7365
|
-
|
|
7366
|
-
|
|
7367
|
-
|
|
7368
|
-
|
|
7369
|
-
|
|
7370
|
-
|
|
7282
|
+
return { cancel: function () { } };
|
|
7283
|
+
};
|
|
7284
|
+
|
|
7285
|
+
function convertOSM(params) {
|
|
7286
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
7287
|
+
var options, geojson;
|
|
7288
|
+
return __generator(this, function (_a) {
|
|
7289
|
+
switch (_a.label) {
|
|
7290
|
+
case 0:
|
|
7291
|
+
options = params.options || {};
|
|
7292
|
+
return [4 /*yield*/, new Promise(function (resolve, reject) {
|
|
7293
|
+
getProtocolData(params.filename).then(function (rawData) {
|
|
7294
|
+
var newData = osm2geojson__default["default"](rawData, options);
|
|
7295
|
+
if (!newData) {
|
|
7296
|
+
reject('Conversion failed');
|
|
7297
|
+
}
|
|
7298
|
+
else {
|
|
7299
|
+
resolve(newData);
|
|
7300
|
+
}
|
|
7301
|
+
});
|
|
7302
|
+
})];
|
|
7303
|
+
case 1:
|
|
7304
|
+
geojson = _a.sent();
|
|
7305
|
+
return [2 /*return*/, geojson];
|
|
7306
|
+
}
|
|
7307
|
+
});
|
|
7308
|
+
});
|
|
7309
|
+
}
|
|
7310
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7311
|
+
var OSMProtocolHandler = function (params, callback) {
|
|
7312
|
+
var parsedParams = protocolPathParser(params.url);
|
|
7313
|
+
convertOSM(parsedParams).then(function (data) {
|
|
7314
|
+
if (data !== undefined) {
|
|
7315
|
+
callback(null, data, null, null);
|
|
7316
|
+
}
|
|
7317
|
+
else {
|
|
7318
|
+
callback(new Error('OSM File not found'));
|
|
7319
|
+
}
|
|
7320
|
+
});
|
|
7321
|
+
return { cancel: function () { } };
|
|
7322
|
+
};
|
|
7323
|
+
|
|
7324
|
+
function reduceFeatures(geojson) {
|
|
7325
|
+
var newFeatures = [];
|
|
7326
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7327
|
+
geojson.features.forEach(function (e) {
|
|
7328
|
+
if (!e.features) {
|
|
7329
|
+
newFeatures.push({
|
|
7330
|
+
type: e.type,
|
|
7331
|
+
geometry: e.geometry,
|
|
7332
|
+
properties: e.properties,
|
|
7333
|
+
});
|
|
7334
|
+
}
|
|
7335
|
+
else {
|
|
7336
|
+
e.features.forEach(function (el) {
|
|
7337
|
+
newFeatures.push({ type: el.type, geometry: el.geometry, properties: el.properties });
|
|
7338
|
+
});
|
|
7339
|
+
}
|
|
7340
|
+
});
|
|
7341
|
+
return newFeatures;
|
|
7342
|
+
}
|
|
7343
|
+
function convertTopojson(params) {
|
|
7344
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
7345
|
+
var geojson;
|
|
7346
|
+
return __generator(this, function (_a) {
|
|
7347
|
+
switch (_a.label) {
|
|
7348
|
+
case 0: return [4 /*yield*/, new Promise(function (resolve) {
|
|
7349
|
+
var topoJsonData = {
|
|
7350
|
+
type: 'Topology',
|
|
7351
|
+
objects: { key: '' },
|
|
7352
|
+
arcs: []
|
|
7353
|
+
};
|
|
7354
|
+
getProtocolData(params.filename).then(function (rawData) {
|
|
7355
|
+
try {
|
|
7356
|
+
topoJsonData = JSON.parse(rawData);
|
|
7357
|
+
}
|
|
7358
|
+
catch (e) {
|
|
7359
|
+
throw 'Invalid TopoJson';
|
|
7360
|
+
}
|
|
7361
|
+
// Convert the data
|
|
7362
|
+
var result = {
|
|
7363
|
+
type: 'FeatureCollection',
|
|
7364
|
+
features: [],
|
|
7365
|
+
};
|
|
7366
|
+
if (topoJsonData.type === 'Topology' && topoJsonData.objects !== undefined) {
|
|
7367
|
+
// add the "fromObject" property in each topojson feature
|
|
7368
|
+
Object.keys(topoJsonData.objects).map(function (key) {
|
|
7369
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
7370
|
+
if (((_a = topoJsonData.objects) === null || _a === void 0 ? void 0 : _a[key].type) === 'GeometryCollection') {
|
|
7371
|
+
(_c = (_b = topoJsonData.objects) === null || _b === void 0 ? void 0 : _b[key].geometries) === null || _c === void 0 ? void 0 : _c.forEach(function (e) { return (e.properties = __assign({ fromObject: key }, e.properties)); });
|
|
7372
|
+
}
|
|
7373
|
+
else if (((_d = topoJsonData === null || topoJsonData === void 0 ? void 0 : topoJsonData.objects) === null || _d === void 0 ? void 0 : _d[key]) &&
|
|
7374
|
+
((_f = (_e = topoJsonData === null || topoJsonData === void 0 ? void 0 : topoJsonData.objects) === null || _e === void 0 ? void 0 : _e[key]) === null || _f === void 0 ? void 0 : _f.type) !== 'GeometryCollection') {
|
|
7375
|
+
topoJsonData.objects[key].properties = __assign({ fromObject: key }, (_g = topoJsonData.objects) === null || _g === void 0 ? void 0 : _g[key].properties);
|
|
7376
|
+
}
|
|
7377
|
+
});
|
|
7378
|
+
//convert the data into a geoJson object
|
|
7379
|
+
result = {
|
|
7380
|
+
type: 'FeatureCollection',
|
|
7381
|
+
features: Object.keys(topoJsonData.objects).map(function (key) {
|
|
7382
|
+
return topojsonClient.feature(topoJsonData, key);
|
|
7383
|
+
}),
|
|
7384
|
+
};
|
|
7385
|
+
result.features = reduceFeatures(result);
|
|
7386
|
+
}
|
|
7387
|
+
resolve(result);
|
|
7388
|
+
});
|
|
7389
|
+
})];
|
|
7390
|
+
case 1:
|
|
7391
|
+
geojson = _a.sent();
|
|
7392
|
+
return [2 /*return*/, geojson];
|
|
7393
|
+
}
|
|
7394
|
+
});
|
|
7395
|
+
});
|
|
7396
|
+
}
|
|
7397
|
+
var TopojsonProtocolHandler = function (params, callback) {
|
|
7398
|
+
var parsedParams = protocolPathParser(params.url);
|
|
7399
|
+
convertTopojson(parsedParams).then(function (data) {
|
|
7400
|
+
if (data !== undefined) {
|
|
7401
|
+
callback(null, data, null, null);
|
|
7402
|
+
}
|
|
7403
|
+
else {
|
|
7404
|
+
callback(new Error('Topojson not found'));
|
|
7405
|
+
}
|
|
7406
|
+
});
|
|
7407
|
+
return { cancel: function () { } };
|
|
7408
|
+
};
|
|
7409
|
+
|
|
7410
|
+
function convertXML(params) {
|
|
7411
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
7412
|
+
var geojson;
|
|
7413
|
+
return __generator(this, function (_a) {
|
|
7414
|
+
switch (_a.label) {
|
|
7415
|
+
case 0: return [4 /*yield*/, new Promise(function (resolve, reject) {
|
|
7416
|
+
getProtocolData(params.filename).then(function (rawData) {
|
|
7417
|
+
var newData = function () {
|
|
7418
|
+
// use an extern converter for tcx files
|
|
7419
|
+
if (params.protocolId === 'tcx') {
|
|
7420
|
+
return externParser__namespace[params.protocolId](new DOMParser().parseFromString(rawData, 'text/xml'));
|
|
7421
|
+
// use the projects gpxConverter function for gpx and kml files
|
|
7422
|
+
}
|
|
7423
|
+
else {
|
|
7424
|
+
return toGeoJSON[params.protocolId](new DOMParser().parseFromString(rawData, 'text/xml'));
|
|
7425
|
+
}
|
|
7426
|
+
};
|
|
7427
|
+
if (!newData()) {
|
|
7428
|
+
reject('Conversion failed');
|
|
7429
|
+
}
|
|
7430
|
+
else {
|
|
7431
|
+
resolve(newData());
|
|
7432
|
+
}
|
|
7433
|
+
});
|
|
7434
|
+
})];
|
|
7435
|
+
case 1:
|
|
7436
|
+
geojson = _a.sent();
|
|
7437
|
+
return [2 /*return*/, geojson];
|
|
7438
|
+
}
|
|
7439
|
+
});
|
|
7440
|
+
});
|
|
7441
|
+
}
|
|
7442
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7443
|
+
var XMLProtocolHandler = function (params, callback) {
|
|
7444
|
+
var parsedParams = protocolPathParser(params.url);
|
|
7445
|
+
convertXML(parsedParams).then(function (data) {
|
|
7446
|
+
if (data !== undefined) {
|
|
7447
|
+
callback(null, data, null, null);
|
|
7448
|
+
}
|
|
7449
|
+
else {
|
|
7450
|
+
callback(new Error('XML not found'));
|
|
7451
|
+
}
|
|
7452
|
+
});
|
|
7453
|
+
return { cancel: function () { } };
|
|
7454
|
+
};
|
|
7455
|
+
|
|
7456
|
+
/**
|
|
7457
|
+
*
|
|
7458
|
+
*/
|
|
7459
|
+
var useAddImage = function (props) {
|
|
7460
|
+
var mapHook = useMap({
|
|
7461
|
+
mapId: undefined,
|
|
7462
|
+
});
|
|
7463
|
+
var initializedRef = React.useRef(false);
|
|
7464
|
+
React.useEffect(function () {
|
|
7465
|
+
var _a;
|
|
7466
|
+
if (!mapHook.map || initializedRef.current)
|
|
7467
|
+
return;
|
|
7468
|
+
(_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.loadImage(props.imagePath, function (error, image) {
|
|
7469
|
+
var _a;
|
|
7470
|
+
if (error)
|
|
7471
|
+
throw error;
|
|
7472
|
+
(_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.addImage(props.imageId, image);
|
|
7473
|
+
return function () {
|
|
7474
|
+
var _a;
|
|
7475
|
+
(_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.removeImage(props.imageId);
|
|
7476
|
+
};
|
|
7477
|
+
});
|
|
7478
|
+
}, [mapHook.map, props]);
|
|
7479
|
+
return;
|
|
7480
|
+
};
|
|
7481
|
+
useAddImage.defaultProps = {
|
|
7482
|
+
mapId: undefined,
|
|
7483
|
+
};
|
|
7484
|
+
|
|
7485
|
+
var SimpleDataContext = /*#__PURE__*/React__default["default"].createContext({});
|
|
7486
|
+
var SimpleDataContextProvider = SimpleDataContext.Provider;
|
|
7487
|
+
|
|
7488
|
+
var SimpleDataProvider = function SimpleDataProvider(props) {
|
|
7489
|
+
var _useState = React.useState(null),
|
|
7490
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
7491
|
+
data = _useState2[0],
|
|
7492
|
+
setData = _useState2[1];
|
|
7493
|
+
React.useEffect(function () {
|
|
7494
|
+
if (!props.url) return;
|
|
7495
|
+
var data_promise = null;
|
|
7496
|
+
if (props.format === "json") {
|
|
7497
|
+
data_promise = d3__namespace.json(props.url);
|
|
7498
|
+
} else if (props.format === "csv") {
|
|
7499
|
+
data_promise = d3__namespace.csv(props.url);
|
|
7500
|
+
} else if (props.format === "xml") {
|
|
7501
|
+
data_promise = d3__namespace.xml(props.url);
|
|
7502
|
+
}
|
|
7503
|
+
if (data_promise) {
|
|
7504
|
+
data_promise.then(function (received_data) {
|
|
7505
|
+
if (props.format === "xml") {
|
|
7506
|
+
if (props.nodeType) {
|
|
7507
|
+
var dataTmp = [];
|
|
7508
|
+
received_data.querySelectorAll(props.nodeType).forEach(function (el) {
|
|
7509
|
+
dataTmp.push(props.formatData(el));
|
|
7510
|
+
});
|
|
7511
|
+
setData(dataTmp);
|
|
7512
|
+
}
|
|
7513
|
+
} else {
|
|
7514
|
+
if (props.data_property) {
|
|
7515
|
+
received_data = received_data[props.data_property];
|
|
7516
|
+
}
|
|
7517
|
+
if (typeof props.formatData === "function") {
|
|
7518
|
+
setData(received_data.map(props.formatData));
|
|
7519
|
+
} else {
|
|
7520
|
+
setData(received_data);
|
|
7521
|
+
}
|
|
7522
|
+
}
|
|
7523
|
+
if (typeof props.onData === "function") {
|
|
7524
|
+
props.onData();
|
|
7525
|
+
}
|
|
7526
|
+
});
|
|
7527
|
+
}
|
|
7528
|
+
}, [props.url, props]);
|
|
7529
|
+
var value = {
|
|
7530
|
+
data: data,
|
|
7531
|
+
setData: setData
|
|
7532
|
+
};
|
|
7533
|
+
return /*#__PURE__*/React__default["default"].createElement(SimpleDataContextProvider, {
|
|
7534
|
+
value: value
|
|
7535
|
+
}, props.children);
|
|
7536
|
+
};
|
|
7537
|
+
SimpleDataProvider.propTypes = {
|
|
7538
|
+
children: PropTypes__default["default"].node.isRequired
|
|
7539
|
+
};
|
|
7540
|
+
|
|
7541
|
+
var ListStyled = material.styled(material.List)({
|
|
7542
|
+
marginTop: '15px',
|
|
7543
|
+
});
|
|
7544
|
+
function LayerList(props) {
|
|
7545
|
+
return React__default["default"].createElement(ListStyled, null, props === null || props === void 0 ? void 0 : props.children);
|
|
7546
|
+
}
|
|
7547
|
+
|
|
7548
|
+
var IconButtonStyled = material.styled(material.IconButton)({
|
|
7549
|
+
padding: '4px',
|
|
7550
|
+
marginTop: '-3px',
|
|
7551
|
+
background: 'none',
|
|
7552
|
+
'&:hover': {
|
|
7553
|
+
background: 'none',
|
|
7554
|
+
},
|
|
7555
|
+
});
|
|
7556
|
+
function LayerListItemFactory(props) {
|
|
7557
|
+
var _a, _b;
|
|
7558
|
+
var layerContext = useLayerContext();
|
|
7559
|
+
var mapHook = useMap({ mapId: undefined });
|
|
7560
|
+
//useCallback Hook
|
|
7561
|
+
function fitLayer(layer) {
|
|
7562
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
7563
|
+
var layerSource = layer.id && ((_b = (_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.getLayer(layer.id)) === null || _b === void 0 ? void 0 : _b.source)
|
|
7564
|
+
? (_c = mapHook.map) === null || _c === void 0 ? void 0 : _c.getLayer(layer.id).source
|
|
7565
|
+
: undefined;
|
|
7566
|
+
var _bbox = null;
|
|
7567
|
+
switch (layer.type) {
|
|
7568
|
+
case 'geojson':
|
|
7569
|
+
if ((_d = layer.config) === null || _d === void 0 ? void 0 : _d.geojson) {
|
|
7570
|
+
(_e = mapHook.map) === null || _e === void 0 ? void 0 : _e.fitBounds(turf.bbox((_f = layer.config) === null || _f === void 0 ? void 0 : _f.geojson), props.fitBoundsOptions);
|
|
7571
|
+
}
|
|
7572
|
+
else {
|
|
7573
|
+
if (!layerSource) {
|
|
7574
|
+
return;
|
|
7575
|
+
}
|
|
7576
|
+
var _geojson = {
|
|
7577
|
+
type: 'FeatureCollection',
|
|
7578
|
+
features: (_g = mapHook.map) === null || _g === void 0 ? void 0 : _g.querySourceFeatures(layerSource),
|
|
7579
|
+
};
|
|
7580
|
+
if (_geojson.features.length === 0) {
|
|
7581
|
+
(_h = mapHook.map) === null || _h === void 0 ? void 0 : _h.zoomTo(1);
|
|
7582
|
+
_geojson.features = (_j = mapHook.map) === null || _j === void 0 ? void 0 : _j.querySourceFeatures(layerSource);
|
|
7583
|
+
}
|
|
7584
|
+
_bbox = turf.bbox(_geojson);
|
|
7585
|
+
}
|
|
7586
|
+
break;
|
|
7587
|
+
case 'vt':
|
|
7588
|
+
console.log('vt');
|
|
7589
|
+
break;
|
|
7590
|
+
case 'wms':
|
|
7591
|
+
_bbox = (_o = (_m = (_l = (_k = layer === null || layer === void 0 ? void 0 : layer.config) === null || _k === void 0 ? void 0 : _k.config) === null || _l === void 0 ? void 0 : _l.layers) === null || _m === void 0 ? void 0 : _m[0]) === null || _o === void 0 ? void 0 : _o.EX_GeographicBoundingBox;
|
|
7592
|
+
break;
|
|
7593
|
+
default:
|
|
7594
|
+
return;
|
|
7595
|
+
}
|
|
7596
|
+
if (_bbox) {
|
|
7597
|
+
(_p = mapHook.map) === null || _p === void 0 ? void 0 : _p.fitBounds(_bbox, props.fitBoundsOptions);
|
|
7598
|
+
}
|
|
7599
|
+
}
|
|
7600
|
+
var orderLayers = React.useMemo(function () {
|
|
7601
|
+
var layerIds = __spreadArray(__spreadArray([
|
|
7602
|
+
'order-background'
|
|
7603
|
+
], __spreadArray([], layerContext.layers, true).map(function (_el, idx) { return 'content_order_' + idx; }), true), [
|
|
7604
|
+
'order-labels',
|
|
7605
|
+
], false);
|
|
7606
|
+
return layerIds.reverse();
|
|
7607
|
+
}, [layerContext.layers]);
|
|
7608
|
+
var layers = React.useMemo(function () {
|
|
7609
|
+
if (props.layers)
|
|
7610
|
+
return props.layers;
|
|
7611
|
+
if (layerContext === null || layerContext === void 0 ? void 0 : layerContext.layers)
|
|
7612
|
+
return layerContext.layers;
|
|
7613
|
+
return [];
|
|
7614
|
+
}, [props.layers, layerContext.layers]);
|
|
7615
|
+
var setLayers = React.useMemo(function () {
|
|
7616
|
+
if (props.setLayers)
|
|
7617
|
+
return props.setLayers;
|
|
7618
|
+
return layerContext.setLayers;
|
|
7619
|
+
}, [props.setLayers, layerContext.setLayers]);
|
|
7620
|
+
var pointerSensor = core.useSensor(core.PointerSensor, {
|
|
7621
|
+
activationConstraint: {
|
|
7622
|
+
distance: 5,
|
|
7623
|
+
},
|
|
7624
|
+
});
|
|
7625
|
+
var mouseSensor = core.useSensor(core.MouseSensor, {
|
|
7626
|
+
activationConstraint: {
|
|
7627
|
+
distance: 5,
|
|
7628
|
+
},
|
|
7629
|
+
});
|
|
7630
|
+
var sensors = core.useSensors(mouseSensor, pointerSensor);
|
|
7631
|
+
function dragEnd(event) {
|
|
7632
|
+
var _a, _b, _c;
|
|
7633
|
+
var dragLayerId = event.active.id;
|
|
7634
|
+
var dragLayerNewPosition = (_c = (_b = (_a = event.over) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.current) === null || _c === void 0 ? void 0 : _c.sortable.index;
|
|
7635
|
+
layerContext.moveLayer(String(dragLayerId), function () { return dragLayerNewPosition; });
|
|
7636
|
+
}
|
|
7637
|
+
return (React__default["default"].createElement(React__default["default"].Fragment, null,
|
|
7638
|
+
React__default["default"].createElement(MlOrderLayers, { layerIds: orderLayers, insertBeforeLayer: "_background" }),
|
|
7639
|
+
((_a = layerContext === null || layerContext === void 0 ? void 0 : layerContext.symbolLayers) === null || _a === void 0 ? void 0 : _a.length) > 0 && (React__default["default"].createElement(LayerListItem, { key: 'background_labels', layerComponent: React__default["default"].createElement(MlVectorTileLayer, __assign({}, layerContext.vtLayerConfig, { layers: layerContext.symbolLayers, mapId: props === null || props === void 0 ? void 0 : props.mapId, insertBeforeLayer: 'order-labels' })), setLayerState: function (state) {
|
|
7640
|
+
return layerContext.setSymbolLayers(state === null || state === void 0 ? void 0 : state.layers);
|
|
7641
|
+
}, visible: true, configurable: true, type: "layer", name: "Labels" })),
|
|
7642
|
+
React__default["default"].createElement(core.DndContext, { collisionDetection: core.closestCenter, sensors: sensors, onDragEnd: function (event) { return dragEnd(event); }, modifiers: [modifiers.restrictToVerticalAxis] },
|
|
7643
|
+
React__default["default"].createElement(sortable.SortableContext, { items: layers, strategy: sortable.verticalListSortingStrategy },
|
|
7644
|
+
__spreadArray([], layers, true).map(function (layer, idx) {
|
|
7645
|
+
var _a, _b, _c, _d, _e;
|
|
7646
|
+
if (!(layer === null || layer === void 0 ? void 0 : layer.id))
|
|
7647
|
+
return null;
|
|
7648
|
+
switch (layer.type) {
|
|
7649
|
+
case 'geojson':
|
|
7650
|
+
return (React__default["default"].createElement(LayerListItem, { key: layer.id, layerId: layer.id, sortable: props.sortable, name: (layer === null || layer === void 0 ? void 0 : layer.name) || ((_a = layer === null || layer === void 0 ? void 0 : layer.config) === null || _a === void 0 ? void 0 : _a.type) + ' layer' || 'unnamed layer', layerComponent: React__default["default"].createElement(MlGeoJsonLayer, __assign({}, layer.config, { mapId: props === null || props === void 0 ? void 0 : props.mapId, layerId: layer.id, insertBeforeLayer: 'content_order_' + (layers.length - 1 - idx) })), buttons: React__default["default"].createElement(React__default["default"].Fragment, null,
|
|
7651
|
+
React__default["default"].createElement(IconButtonStyled, { disabled: idx === layers.length - 1, onClick: function () {
|
|
7371
7652
|
layerContext.moveDown(layer.id || '');
|
|
7372
7653
|
} },
|
|
7373
7654
|
React__default["default"].createElement(iconsMaterial.ArrowCircleDown, null)),
|
|
@@ -7575,261 +7856,6 @@ function OsmOptionsFomular(props) {
|
|
|
7575
7856
|
})))));
|
|
7576
7857
|
}
|
|
7577
7858
|
|
|
7578
|
-
function protocolPathParser(url) {
|
|
7579
|
-
var test = url.split('?');
|
|
7580
|
-
var urlParts = test[0].split('://');
|
|
7581
|
-
var protocolId = urlParts[0];
|
|
7582
|
-
var csvUrl = urlParts.length > 2 ? urlParts[1] + '://' + urlParts[2] : urlParts[1];
|
|
7583
|
-
var csvParts = csvUrl.split('/');
|
|
7584
|
-
var filename = csvParts.join('/');
|
|
7585
|
-
var optionsString = decodeURI(test[1]);
|
|
7586
|
-
var options = Object.fromEntries(new URLSearchParams(optionsString));
|
|
7587
|
-
return {
|
|
7588
|
-
protocolId: protocolId,
|
|
7589
|
-
filename: filename,
|
|
7590
|
-
options: options,
|
|
7591
|
-
};
|
|
7592
|
-
}
|
|
7593
|
-
|
|
7594
|
-
function getProtocolData(path) {
|
|
7595
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
7596
|
-
var response, rawData, error_1;
|
|
7597
|
-
return __generator(this, function (_a) {
|
|
7598
|
-
switch (_a.label) {
|
|
7599
|
-
case 0:
|
|
7600
|
-
_a.trys.push([0, 3, , 4]);
|
|
7601
|
-
return [4 /*yield*/, fetch(path)];
|
|
7602
|
-
case 1:
|
|
7603
|
-
response = _a.sent();
|
|
7604
|
-
return [4 /*yield*/, response.text()];
|
|
7605
|
-
case 2:
|
|
7606
|
-
rawData = _a.sent();
|
|
7607
|
-
return [2 /*return*/, rawData];
|
|
7608
|
-
case 3:
|
|
7609
|
-
error_1 = _a.sent();
|
|
7610
|
-
console.error('File could not be loaded: ', error_1);
|
|
7611
|
-
return [2 /*return*/, error_1];
|
|
7612
|
-
case 4: return [2 /*return*/];
|
|
7613
|
-
}
|
|
7614
|
-
});
|
|
7615
|
-
});
|
|
7616
|
-
}
|
|
7617
|
-
|
|
7618
|
-
function convertCsv(filename, options) {
|
|
7619
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
7620
|
-
var geojson;
|
|
7621
|
-
return __generator(this, function (_a) {
|
|
7622
|
-
switch (_a.label) {
|
|
7623
|
-
case 0: return [4 /*yield*/, new Promise(function (resolve, reject) {
|
|
7624
|
-
var useOptions = options || {};
|
|
7625
|
-
var extension = filename.substring(filename.length - 3);
|
|
7626
|
-
if (extension === 'tsv') {
|
|
7627
|
-
options.delimiter = '\t';
|
|
7628
|
-
}
|
|
7629
|
-
getProtocolData(filename).then(function (rawData) {
|
|
7630
|
-
// Use the csv2geojson library to convert the CSV to GeoJSON
|
|
7631
|
-
csv2geojson__namespace.csv2geojson(rawData, useOptions, function (err, data) {
|
|
7632
|
-
if (err) {
|
|
7633
|
-
reject(err);
|
|
7634
|
-
}
|
|
7635
|
-
else {
|
|
7636
|
-
resolve(data);
|
|
7637
|
-
}
|
|
7638
|
-
});
|
|
7639
|
-
});
|
|
7640
|
-
})];
|
|
7641
|
-
case 1:
|
|
7642
|
-
geojson = _a.sent();
|
|
7643
|
-
return [2 /*return*/, geojson];
|
|
7644
|
-
}
|
|
7645
|
-
});
|
|
7646
|
-
});
|
|
7647
|
-
}
|
|
7648
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7649
|
-
var CSVProtocolHandler = function (params, callback) {
|
|
7650
|
-
var parsedParams = protocolPathParser(params.url);
|
|
7651
|
-
convertCsv(parsedParams.filename, parsedParams.options).then(function (data) {
|
|
7652
|
-
if (data !== undefined) {
|
|
7653
|
-
callback(null, data, null, null);
|
|
7654
|
-
}
|
|
7655
|
-
else {
|
|
7656
|
-
callback(new Error('CSV not found'));
|
|
7657
|
-
}
|
|
7658
|
-
});
|
|
7659
|
-
return { cancel: function () { } };
|
|
7660
|
-
};
|
|
7661
|
-
|
|
7662
|
-
function reduceFeatures(geojson) {
|
|
7663
|
-
var newFeatures = [];
|
|
7664
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7665
|
-
geojson.features.forEach(function (e) {
|
|
7666
|
-
if (!e.features) {
|
|
7667
|
-
newFeatures.push({
|
|
7668
|
-
type: e.type,
|
|
7669
|
-
geometry: e.geometry,
|
|
7670
|
-
properties: e.properties,
|
|
7671
|
-
});
|
|
7672
|
-
}
|
|
7673
|
-
else {
|
|
7674
|
-
e.features.forEach(function (el) {
|
|
7675
|
-
newFeatures.push({ type: el.type, geometry: el.geometry, properties: el.properties });
|
|
7676
|
-
});
|
|
7677
|
-
}
|
|
7678
|
-
});
|
|
7679
|
-
return newFeatures;
|
|
7680
|
-
}
|
|
7681
|
-
function convertTopojson(params) {
|
|
7682
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
7683
|
-
var geojson;
|
|
7684
|
-
return __generator(this, function (_a) {
|
|
7685
|
-
switch (_a.label) {
|
|
7686
|
-
case 0: return [4 /*yield*/, new Promise(function (resolve) {
|
|
7687
|
-
var topoJsonData = {
|
|
7688
|
-
type: 'Topology',
|
|
7689
|
-
objects: { key: '' },
|
|
7690
|
-
arcs: []
|
|
7691
|
-
};
|
|
7692
|
-
getProtocolData(params.filename).then(function (rawData) {
|
|
7693
|
-
try {
|
|
7694
|
-
topoJsonData = JSON.parse(rawData);
|
|
7695
|
-
}
|
|
7696
|
-
catch (e) {
|
|
7697
|
-
throw 'Invalid TopoJson';
|
|
7698
|
-
}
|
|
7699
|
-
// Convert the data
|
|
7700
|
-
var result = {
|
|
7701
|
-
type: 'FeatureCollection',
|
|
7702
|
-
features: [],
|
|
7703
|
-
};
|
|
7704
|
-
if (topoJsonData.type === 'Topology' && topoJsonData.objects !== undefined) {
|
|
7705
|
-
// add the "fromObject" property in each topojson feature
|
|
7706
|
-
Object.keys(topoJsonData.objects).map(function (key) {
|
|
7707
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
7708
|
-
if (((_a = topoJsonData.objects) === null || _a === void 0 ? void 0 : _a[key].type) === 'GeometryCollection') {
|
|
7709
|
-
(_c = (_b = topoJsonData.objects) === null || _b === void 0 ? void 0 : _b[key].geometries) === null || _c === void 0 ? void 0 : _c.forEach(function (e) { return (e.properties = __assign({ fromObject: key }, e.properties)); });
|
|
7710
|
-
}
|
|
7711
|
-
else if (((_d = topoJsonData === null || topoJsonData === void 0 ? void 0 : topoJsonData.objects) === null || _d === void 0 ? void 0 : _d[key]) &&
|
|
7712
|
-
((_f = (_e = topoJsonData === null || topoJsonData === void 0 ? void 0 : topoJsonData.objects) === null || _e === void 0 ? void 0 : _e[key]) === null || _f === void 0 ? void 0 : _f.type) !== 'GeometryCollection') {
|
|
7713
|
-
topoJsonData.objects[key].properties = __assign({ fromObject: key }, (_g = topoJsonData.objects) === null || _g === void 0 ? void 0 : _g[key].properties);
|
|
7714
|
-
}
|
|
7715
|
-
});
|
|
7716
|
-
//convert the data into a geoJson object
|
|
7717
|
-
result = {
|
|
7718
|
-
type: 'FeatureCollection',
|
|
7719
|
-
features: Object.keys(topoJsonData.objects).map(function (key) {
|
|
7720
|
-
return topojsonClient.feature(topoJsonData, key);
|
|
7721
|
-
}),
|
|
7722
|
-
};
|
|
7723
|
-
result.features = reduceFeatures(result);
|
|
7724
|
-
}
|
|
7725
|
-
resolve(result);
|
|
7726
|
-
});
|
|
7727
|
-
})];
|
|
7728
|
-
case 1:
|
|
7729
|
-
geojson = _a.sent();
|
|
7730
|
-
return [2 /*return*/, geojson];
|
|
7731
|
-
}
|
|
7732
|
-
});
|
|
7733
|
-
});
|
|
7734
|
-
}
|
|
7735
|
-
var TopojsonProtocolHandler = function (params, callback) {
|
|
7736
|
-
var parsedParams = protocolPathParser(params.url);
|
|
7737
|
-
convertTopojson(parsedParams).then(function (data) {
|
|
7738
|
-
if (data !== undefined) {
|
|
7739
|
-
callback(null, data, null, null);
|
|
7740
|
-
}
|
|
7741
|
-
else {
|
|
7742
|
-
callback(new Error('Topojson not found'));
|
|
7743
|
-
}
|
|
7744
|
-
});
|
|
7745
|
-
return { cancel: function () { } };
|
|
7746
|
-
};
|
|
7747
|
-
|
|
7748
|
-
function convertOSM(params) {
|
|
7749
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
7750
|
-
var options, geojson;
|
|
7751
|
-
return __generator(this, function (_a) {
|
|
7752
|
-
switch (_a.label) {
|
|
7753
|
-
case 0:
|
|
7754
|
-
options = params.options || {};
|
|
7755
|
-
return [4 /*yield*/, new Promise(function (resolve, reject) {
|
|
7756
|
-
getProtocolData(params.filename).then(function (rawData) {
|
|
7757
|
-
var newData = osm2geojson__default["default"](rawData, options);
|
|
7758
|
-
if (!newData) {
|
|
7759
|
-
reject('Conversion failed');
|
|
7760
|
-
}
|
|
7761
|
-
else {
|
|
7762
|
-
resolve(newData);
|
|
7763
|
-
}
|
|
7764
|
-
});
|
|
7765
|
-
})];
|
|
7766
|
-
case 1:
|
|
7767
|
-
geojson = _a.sent();
|
|
7768
|
-
return [2 /*return*/, geojson];
|
|
7769
|
-
}
|
|
7770
|
-
});
|
|
7771
|
-
});
|
|
7772
|
-
}
|
|
7773
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7774
|
-
var OSMProtocolHandler = function (params, callback) {
|
|
7775
|
-
var parsedParams = protocolPathParser(params.url);
|
|
7776
|
-
convertOSM(parsedParams).then(function (data) {
|
|
7777
|
-
if (data !== undefined) {
|
|
7778
|
-
callback(null, data, null, null);
|
|
7779
|
-
}
|
|
7780
|
-
else {
|
|
7781
|
-
callback(new Error('OSM File not found'));
|
|
7782
|
-
}
|
|
7783
|
-
});
|
|
7784
|
-
return { cancel: function () { } };
|
|
7785
|
-
};
|
|
7786
|
-
|
|
7787
|
-
function convertXML(params) {
|
|
7788
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
7789
|
-
var geojson;
|
|
7790
|
-
return __generator(this, function (_a) {
|
|
7791
|
-
switch (_a.label) {
|
|
7792
|
-
case 0: return [4 /*yield*/, new Promise(function (resolve, reject) {
|
|
7793
|
-
getProtocolData(params.filename).then(function (rawData) {
|
|
7794
|
-
var newData = function () {
|
|
7795
|
-
// use an extern converter for tcx files
|
|
7796
|
-
if (params.protocolId === 'tcx') {
|
|
7797
|
-
return externParser__namespace[params.protocolId](new DOMParser().parseFromString(rawData, 'text/xml'));
|
|
7798
|
-
// use the projects gpxConverter function for gpx and kml files
|
|
7799
|
-
}
|
|
7800
|
-
else {
|
|
7801
|
-
return toGeoJSON[params.protocolId](new DOMParser().parseFromString(rawData, 'text/xml'));
|
|
7802
|
-
}
|
|
7803
|
-
};
|
|
7804
|
-
if (!newData()) {
|
|
7805
|
-
reject('Conversion failed');
|
|
7806
|
-
}
|
|
7807
|
-
else {
|
|
7808
|
-
resolve(newData());
|
|
7809
|
-
}
|
|
7810
|
-
});
|
|
7811
|
-
})];
|
|
7812
|
-
case 1:
|
|
7813
|
-
geojson = _a.sent();
|
|
7814
|
-
return [2 /*return*/, geojson];
|
|
7815
|
-
}
|
|
7816
|
-
});
|
|
7817
|
-
});
|
|
7818
|
-
}
|
|
7819
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7820
|
-
var XMLProtocolHandler = function (params, callback) {
|
|
7821
|
-
var parsedParams = protocolPathParser(params.url);
|
|
7822
|
-
convertXML(parsedParams).then(function (data) {
|
|
7823
|
-
if (data !== undefined) {
|
|
7824
|
-
callback(null, data, null, null);
|
|
7825
|
-
}
|
|
7826
|
-
else {
|
|
7827
|
-
callback(new Error('XML not found'));
|
|
7828
|
-
}
|
|
7829
|
-
});
|
|
7830
|
-
return { cancel: function () { } };
|
|
7831
|
-
};
|
|
7832
|
-
|
|
7833
7859
|
var handlers = {
|
|
7834
7860
|
csv: CSVProtocolHandler,
|
|
7835
7861
|
topojson: TopojsonProtocolHandler,
|
|
@@ -21130,6 +21156,7 @@ SpeedDial.defaultProps = {
|
|
|
21130
21156
|
|
|
21131
21157
|
exports.AddLayerButton = AddLayerButton;
|
|
21132
21158
|
exports.AddLayerPopup = AddLayerPopup;
|
|
21159
|
+
exports.CSVProtocolHandler = CSVProtocolHandler;
|
|
21133
21160
|
exports.ColorPicker = PaintPropsColorPicker;
|
|
21134
21161
|
exports.ConfirmDialog = ConfirmDialog;
|
|
21135
21162
|
exports.GeoJsonContext = GeoJsonContext;
|
|
@@ -21183,6 +21210,7 @@ exports.MlWmsFeatureInfoPopup = MlWmsFeatureInfoPopup;
|
|
|
21183
21210
|
exports.MlWmsLayer = MlWmsLayer;
|
|
21184
21211
|
exports.MlWmsLoader = MlWmsLoader;
|
|
21185
21212
|
exports.MonokaiStyle = MonokaiStyle;
|
|
21213
|
+
exports.OSMProtocolHandler = OSMProtocolHandler;
|
|
21186
21214
|
exports.OceanicNextStyle = OceanicNextStyle;
|
|
21187
21215
|
exports.PdfContext = PdfContext;
|
|
21188
21216
|
exports.PdfForm = PdfForm;
|
|
@@ -21194,9 +21222,16 @@ exports.SimpleDataProvider = SimpleDataProvider;
|
|
|
21194
21222
|
exports.SolarizedStyle = SolarizedStyle;
|
|
21195
21223
|
exports.SpeedDial = SpeedDial;
|
|
21196
21224
|
exports.TopToolbar = TopToolbar;
|
|
21225
|
+
exports.TopojsonProtocolHandler = TopojsonProtocolHandler;
|
|
21197
21226
|
exports.UploadButton = UploadButton;
|
|
21198
21227
|
exports.WmsLayerForm = WmsLayerForm;
|
|
21228
|
+
exports.XMLProtocolHandler = XMLProtocolHandler;
|
|
21229
|
+
exports.convertCsv = convertCsv;
|
|
21230
|
+
exports.convertOSM = convertOSM;
|
|
21231
|
+
exports.convertTopojson = convertTopojson;
|
|
21232
|
+
exports.convertXML = convertXML;
|
|
21199
21233
|
exports.getTheme = getTheme;
|
|
21234
|
+
exports.useAddImage = useAddImage;
|
|
21200
21235
|
exports.useAddProtocol = useAddProtocol;
|
|
21201
21236
|
exports.useCameraFollowPath = useCameraFollowPath;
|
|
21202
21237
|
exports.useExportMap = useExportMap;
|