qwc2 2026.8.13 → 2026.8.21
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 -1
- package/components/AttributeTableWidget.js +121 -285
- package/components/BookmarkPanel.js +3 -2
- package/components/IdentifyViewer.js +39 -20
- package/components/ImportLayer.js +6 -392
- package/components/QtDesignerForm.js +1 -1
- package/components/ResizeableWindow.js +10 -0
- package/components/map3d/style/Map3D.css +1 -0
- package/components/style/AttributeTableWidget.css +1 -140
- package/components/widgets/FeaturesTable.js +30 -31
- package/components/widgets/MenuButton.js +10 -10
- package/components/widgets/TextInput.js +0 -10
- package/components/widgets/style/FeaturesTable.css +46 -19
- package/icons/public.svg +63 -0
- package/package.json +1 -1
- package/plugins/BottomBar.js +123 -111
- package/plugins/MapDropImport.js +135 -0
- package/plugins/map3d/Viewshed3D.js +171 -52
- package/plugins/map3d/style/Viewshed3D.css +4 -0
- package/plugins/style/BottomBar.css +10 -3
- package/plugins/style/MapDropImport.css +19 -0
- package/static/translations/bg-BG.json +8 -0
- package/static/translations/ca-ES.json +8 -0
- package/static/translations/cs-CZ.json +8 -0
- package/static/translations/de-CH.json +8 -0
- package/static/translations/de-DE.json +8 -0
- package/static/translations/en-US.json +8 -0
- package/static/translations/es-ES.json +8 -0
- package/static/translations/fi-FI.json +8 -0
- package/static/translations/fr-FR.json +8 -0
- package/static/translations/hu-HU.json +8 -0
- package/static/translations/it-IT.json +8 -0
- package/static/translations/ja-JP.json +8 -0
- package/static/translations/nl-NL.json +8 -0
- package/static/translations/no-NO.json +8 -0
- package/static/translations/pl-PL.json +8 -0
- package/static/translations/pt-BR.json +8 -0
- package/static/translations/pt-PT.json +8 -0
- package/static/translations/ro-RO.json +8 -0
- package/static/translations/ru-RU.json +8 -0
- package/static/translations/sv-SE.json +8 -0
- package/static/translations/tr-TR.json +8 -0
- package/static/translations/tsconfig.json +4 -0
- package/static/translations/uk-UA.json +8 -0
- package/utils/FileImportUtils.js +390 -0
- package/utils/LayerUtils.js +2 -2
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
|
|
3
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
5
|
+
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
|
6
|
+
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
|
|
7
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
8
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
9
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
10
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
11
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
12
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
13
|
+
function _regeneratorKeys(e) { var n = Object(e), r = []; for (var t in n) r.unshift(t); return function e() { for (; r.length;) if ((t = r.pop()) in n) return e.value = t, e.done = !1, e; return e.done = !0, e; }; }
|
|
14
|
+
function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
|
|
15
|
+
function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
|
|
16
|
+
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
|
17
|
+
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
|
|
18
|
+
/**
|
|
19
|
+
* Copyright 2017-2026 Sourcepole AG
|
|
20
|
+
* All rights reserved.
|
|
21
|
+
*
|
|
22
|
+
* This source code is licensed under the BSD-style license found in the
|
|
23
|
+
* LICENSE file in the root directory of this source tree.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import isEmpty from 'lodash.isempty';
|
|
27
|
+
import Proj4js from 'proj4';
|
|
28
|
+
import ConfigUtils from './ConfigUtils';
|
|
29
|
+
import CoordinatesUtils from './CoordinatesUtils';
|
|
30
|
+
import LocaleUtils from './LocaleUtils';
|
|
31
|
+
import VectorLayerUtils from './VectorLayerUtils';
|
|
32
|
+
var FileImportUtils = {
|
|
33
|
+
/**
|
|
34
|
+
* Imports a local file (KML, KMZ, GeoJSON, zipped Shapefile, GeoPDF) as a map layer.
|
|
35
|
+
* Returns a promise which resolves when the import completed.
|
|
36
|
+
*/
|
|
37
|
+
importFile: function importFile(file, mapCrs, addLayer, addLayerFeatures) {
|
|
38
|
+
var filename = file.name.toLowerCase();
|
|
39
|
+
if (filename.endsWith(".pdf")) {
|
|
40
|
+
return FileImportUtils.addGeoPDFLayer(file, mapCrs, addLayer);
|
|
41
|
+
} else if (filename.endsWith(".zip")) {
|
|
42
|
+
return FileImportUtils.addSHPLayer(file, mapCrs, addLayerFeatures);
|
|
43
|
+
} else if (filename.endsWith(".kmz")) {
|
|
44
|
+
return FileImportUtils.addKMZLayer(file, addLayerFeatures);
|
|
45
|
+
} else if (filename.endsWith(".kml")) {
|
|
46
|
+
return file.text().then(function (data) {
|
|
47
|
+
FileImportUtils.addKMLLayer(file.name, data, addLayerFeatures);
|
|
48
|
+
});
|
|
49
|
+
} else if (filename.endsWith(".geojson") || filename.endsWith(".json")) {
|
|
50
|
+
return file.text().then(function (data) {
|
|
51
|
+
try {
|
|
52
|
+
FileImportUtils.addGeoJSONLayer(file.name, JSON.parse(data), addLayerFeatures);
|
|
53
|
+
} catch (_unused) {
|
|
54
|
+
/* Pass */
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
/* eslint-disable-next-line */
|
|
59
|
+
alert(LocaleUtils.tr("importlayer.unsupportedfile"));
|
|
60
|
+
return Promise.resolve();
|
|
61
|
+
},
|
|
62
|
+
addKMLLayer: function addKMLLayer(filename, data, addLayerFeatures) {
|
|
63
|
+
FileImportUtils.addGeoJSONLayer(filename, {
|
|
64
|
+
features: VectorLayerUtils.kmlToGeoJSON(data)
|
|
65
|
+
}, addLayerFeatures);
|
|
66
|
+
},
|
|
67
|
+
addKMZLayer: function () {
|
|
68
|
+
var _addKMZLayer = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(file, addLayerFeatures) {
|
|
69
|
+
var _yield$import, load, _yield$import2, ZipLoader, fileMap, fileName, decoder, _t, _t2;
|
|
70
|
+
return _regenerator().w(function (_context) {
|
|
71
|
+
while (1) switch (_context.n) {
|
|
72
|
+
case 0:
|
|
73
|
+
_context.n = 1;
|
|
74
|
+
return import('@loaders.gl/core');
|
|
75
|
+
case 1:
|
|
76
|
+
_yield$import = _context.v;
|
|
77
|
+
load = _yield$import.load;
|
|
78
|
+
_context.n = 2;
|
|
79
|
+
return import('@loaders.gl/zip');
|
|
80
|
+
case 2:
|
|
81
|
+
_yield$import2 = _context.v;
|
|
82
|
+
ZipLoader = _yield$import2.ZipLoader;
|
|
83
|
+
_context.n = 3;
|
|
84
|
+
return load(file, ZipLoader);
|
|
85
|
+
case 3:
|
|
86
|
+
fileMap = _context.v;
|
|
87
|
+
_t = _regeneratorKeys(fileMap);
|
|
88
|
+
case 4:
|
|
89
|
+
if ((_t2 = _t()).done) {
|
|
90
|
+
_context.n = 6;
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
fileName = _t2.value;
|
|
94
|
+
if (!(fileName === "doc.kml")) {
|
|
95
|
+
_context.n = 5;
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
decoder = new TextDecoder();
|
|
99
|
+
FileImportUtils.addKMLLayer(file.name, decoder.decode(fileMap[fileName]), addLayerFeatures);
|
|
100
|
+
return _context.a(3, 6);
|
|
101
|
+
case 5:
|
|
102
|
+
_context.n = 4;
|
|
103
|
+
break;
|
|
104
|
+
case 6:
|
|
105
|
+
return _context.a(2);
|
|
106
|
+
}
|
|
107
|
+
}, _callee);
|
|
108
|
+
}));
|
|
109
|
+
function addKMZLayer(_x, _x2) {
|
|
110
|
+
return _addKMZLayer.apply(this, arguments);
|
|
111
|
+
}
|
|
112
|
+
return addKMZLayer;
|
|
113
|
+
}(),
|
|
114
|
+
addGeoJSONLayer: function addGeoJSONLayer(filename, data, addLayerFeatures) {
|
|
115
|
+
if (!data.features && data.type === "Feature") {
|
|
116
|
+
data = {
|
|
117
|
+
type: "FeatureCollection",
|
|
118
|
+
features: [data],
|
|
119
|
+
crs: data.crs
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
if (!isEmpty(data.features)) {
|
|
123
|
+
var defaultCrs = "EPSG:4326";
|
|
124
|
+
if (data.crs && data.crs.properties && data.crs.properties.name) {
|
|
125
|
+
// Extract CRS from FeatureCollection crs
|
|
126
|
+
defaultCrs = CoordinatesUtils.fromOgcUrnCrs(data.crs.properties.name);
|
|
127
|
+
}
|
|
128
|
+
var features = data.features.map(function (feature) {
|
|
129
|
+
var crs = defaultCrs;
|
|
130
|
+
if (feature.crs && feature.crs.properties && feature.crs.properties.name) {
|
|
131
|
+
crs = CoordinatesUtils.fromOgcUrnCrs(feature.crs.properties.name);
|
|
132
|
+
} else if (typeof feature.crs === "string") {
|
|
133
|
+
crs = feature.crs;
|
|
134
|
+
}
|
|
135
|
+
if (feature.geometry && feature.geometry.coordinates) {
|
|
136
|
+
feature.geometry.coordinates = feature.geometry.coordinates.map(VectorLayerUtils.convert3dto2d);
|
|
137
|
+
}
|
|
138
|
+
return _objectSpread(_objectSpread({}, feature), {}, {
|
|
139
|
+
crs: crs
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
addLayerFeatures({
|
|
143
|
+
name: filename,
|
|
144
|
+
title: filename.replace(/\.[^/.]+$/, ""),
|
|
145
|
+
zoomToExtent: true
|
|
146
|
+
}, features, true);
|
|
147
|
+
} else {
|
|
148
|
+
// eslint-disable-next-line
|
|
149
|
+
alert(LocaleUtils.tr("importlayer.nofeatures"));
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
addGeoPDFLayer: function addGeoPDFLayer(file, mapCrs, addLayer) {
|
|
153
|
+
return new Promise(function (resolve) {
|
|
154
|
+
var reader = new FileReader();
|
|
155
|
+
reader.onload = function (ev) {
|
|
156
|
+
var pdfText = atob(ev.target.result.slice(28));
|
|
157
|
+
/* FIXME: This is a very ugly way to extract PDF objects */
|
|
158
|
+
var GPTS = pdfText.match(/\/GPTS\s+\[([^\]]+)\]/);
|
|
159
|
+
var LPTS = pdfText.match(/\/LPTS\s+\[([^\]]+)\]/);
|
|
160
|
+
var Viewport = pdfText.match(/<<([^>]+\/Type\s+\/Viewport[^>]+)>>/);
|
|
161
|
+
var EPSG = pdfText.match(/\/EPSG\s*(\d+)/);
|
|
162
|
+
if (!GPTS || !LPTS || !Viewport || !EPSG) {
|
|
163
|
+
/* eslint-disable-next-line */
|
|
164
|
+
alert(LocaleUtils.tr("importlayer.notgeopdf"));
|
|
165
|
+
resolve();
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
var pairs = function pairs(res, value, idx, array) {
|
|
169
|
+
return idx % 2 === 0 ? [].concat(_toConsumableArray(res), [array.slice(idx, idx + 2)]) : res;
|
|
170
|
+
};
|
|
171
|
+
var gpts = GPTS[1].split(/\s+/).filter(Boolean).map(Number).reduce(pairs, []).map(function (e) {
|
|
172
|
+
return e.reverse();
|
|
173
|
+
}); // lat-lon => lon-lat
|
|
174
|
+
var lpts = LPTS[1].split(/\s+/).filter(Boolean).map(Number).reduce(pairs, []);
|
|
175
|
+
var viewport = Viewport[1].match(/\/BBox\s+\[([^\]]+)\]/)[1].split(/\s+/).filter(Boolean).map(Number);
|
|
176
|
+
var epsg = EPSG[1];
|
|
177
|
+
var projDef = Proj4js.defs('EPSG:' + epsg);
|
|
178
|
+
if (!projDef) {
|
|
179
|
+
/* eslint-disable-next-line */
|
|
180
|
+
alert(LocaleUtils.tr("importlayer.unknownproj", 'EPSG:' + epsg));
|
|
181
|
+
resolve();
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
// Construct geog CS
|
|
185
|
+
var geogCs = {
|
|
186
|
+
projName: 'longlat',
|
|
187
|
+
ellps: projDef.ellps,
|
|
188
|
+
datum_params: projDef.datum_params,
|
|
189
|
+
no_defs: projDef.no_defs
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
// Compute the georeferenced area
|
|
193
|
+
// Note: this is a simplistic implementation, assuming that the frame is rectangular and not skewed
|
|
194
|
+
var getCornerIdx = function getCornerIdx(x, y) {
|
|
195
|
+
return lpts.findIndex(function (entry) {
|
|
196
|
+
return Math.round(entry[0]) === x && Math.round(entry[1]) === y;
|
|
197
|
+
});
|
|
198
|
+
};
|
|
199
|
+
var idxBL = getCornerIdx(0, 0);
|
|
200
|
+
var idxTR = getCornerIdx(1, 1);
|
|
201
|
+
var computeCorner = function computeCorner(idx) {
|
|
202
|
+
return {
|
|
203
|
+
pixel: [viewport[0] * (1 - lpts[idx][0]) + viewport[2] * lpts[idx][0], viewport[1] * (1 - lpts[idx][1]) + viewport[3] * lpts[idx][1]],
|
|
204
|
+
// eslint-disable-next-line
|
|
205
|
+
coo: Proj4js(geogCs, mapCrs, gpts[idx])
|
|
206
|
+
};
|
|
207
|
+
};
|
|
208
|
+
var bl = computeCorner(idxBL);
|
|
209
|
+
var tr = computeCorner(idxTR);
|
|
210
|
+
var geoextent = [bl.coo[0], bl.coo[1], tr.coo[0], tr.coo[1]];
|
|
211
|
+
var imgextent = [bl.pixel[0], bl.pixel[1], tr.pixel[0], tr.pixel[1]];
|
|
212
|
+
import('pdfjs-dist').then(function (pdfjsLib) {
|
|
213
|
+
pdfjsLib.GlobalWorkerOptions.workerSrc = new URL('pdfjs-dist/build/pdf.worker.min.mjs', import.meta.url).toString();
|
|
214
|
+
pdfjsLib.getDocument(ev.target.result).promise.then(function (pdf) {
|
|
215
|
+
pdf.getPage(1).then(function (page) {
|
|
216
|
+
var pageViewport = page.getViewport({
|
|
217
|
+
scale: 1
|
|
218
|
+
});
|
|
219
|
+
var canvas = document.createElement('canvas');
|
|
220
|
+
canvas.width = imgextent[2] - imgextent[0];
|
|
221
|
+
canvas.height = imgextent[3] - imgextent[1];
|
|
222
|
+
var context = canvas.getContext('2d');
|
|
223
|
+
context.translate(-imgextent[0], -(pageViewport.height - imgextent[3]));
|
|
224
|
+
page.render({
|
|
225
|
+
canvasContext: context,
|
|
226
|
+
viewport: pageViewport
|
|
227
|
+
}).promise.then(function () {
|
|
228
|
+
addLayer({
|
|
229
|
+
type: "image",
|
|
230
|
+
name: file.name,
|
|
231
|
+
title: file.name,
|
|
232
|
+
url: canvas.toDataURL(),
|
|
233
|
+
projection: mapCrs,
|
|
234
|
+
imageExtent: geoextent
|
|
235
|
+
});
|
|
236
|
+
resolve();
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
});
|
|
240
|
+
})["catch"](function () {
|
|
241
|
+
/* eslint-disable-next-line */
|
|
242
|
+
console.warn("pdfjs import failed");
|
|
243
|
+
resolve();
|
|
244
|
+
});
|
|
245
|
+
};
|
|
246
|
+
reader.readAsDataURL(file);
|
|
247
|
+
});
|
|
248
|
+
},
|
|
249
|
+
addSHPLayer: function () {
|
|
250
|
+
var _addSHPLayer = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(file, mapCrs, addLayerFeatures) {
|
|
251
|
+
var _yield$import3, _BrowserFileSystem, load, _yield$import4, Proj4Projection, _yield$import5, ShapefileLoader, _yield$import6, ZipLoader, mimeTypes, projections, fileMap, EXTENSIONS, files, fileName, name, ext, fileList, blob, f, list, fileSystem, fetch, filename, data, _t3, _t4, _t5, _t6;
|
|
252
|
+
return _regenerator().w(function (_context2) {
|
|
253
|
+
while (1) switch (_context2.p = _context2.n) {
|
|
254
|
+
case 0:
|
|
255
|
+
_context2.n = 1;
|
|
256
|
+
return import('@loaders.gl/core');
|
|
257
|
+
case 1:
|
|
258
|
+
_yield$import3 = _context2.v;
|
|
259
|
+
_BrowserFileSystem = _yield$import3._BrowserFileSystem;
|
|
260
|
+
load = _yield$import3.load;
|
|
261
|
+
_context2.n = 2;
|
|
262
|
+
return import('@math.gl/proj4');
|
|
263
|
+
case 2:
|
|
264
|
+
_yield$import4 = _context2.v;
|
|
265
|
+
Proj4Projection = _yield$import4.Proj4Projection;
|
|
266
|
+
_context2.n = 3;
|
|
267
|
+
return import('@loaders.gl/shapefile');
|
|
268
|
+
case 3:
|
|
269
|
+
_yield$import5 = _context2.v;
|
|
270
|
+
ShapefileLoader = _yield$import5.ShapefileLoader;
|
|
271
|
+
_context2.n = 4;
|
|
272
|
+
return import('@loaders.gl/zip');
|
|
273
|
+
case 4:
|
|
274
|
+
_yield$import6 = _context2.v;
|
|
275
|
+
ZipLoader = _yield$import6.ZipLoader;
|
|
276
|
+
// Import SHP layer from ZIP. Zip must contain all the required files : shp, dbf, shx, prj, cpg
|
|
277
|
+
mimeTypes = ['application/zip', 'application/zip-compressed', 'application/x-zip-compressed'];
|
|
278
|
+
if (!mimeTypes.includes(file.type)) {
|
|
279
|
+
_context2.n = 15;
|
|
280
|
+
break;
|
|
281
|
+
}
|
|
282
|
+
projections = ConfigUtils.getConfigProp("projections") || [];
|
|
283
|
+
if (projections) {
|
|
284
|
+
Proj4Projection.defineProjectionAliases(projections);
|
|
285
|
+
}
|
|
286
|
+
_context2.n = 5;
|
|
287
|
+
return load(file, ZipLoader);
|
|
288
|
+
case 5:
|
|
289
|
+
fileMap = _context2.v;
|
|
290
|
+
EXTENSIONS = ['shp', 'shx', 'dbf', 'cpg', 'prj'];
|
|
291
|
+
files = {}; // Iterate through all the files in ZIP to get a list of (SHP + sidecar files) by filename
|
|
292
|
+
for (fileName in fileMap) {
|
|
293
|
+
if (Object.hasOwn(fileMap, fileName)) {
|
|
294
|
+
name = fileName.split('.')[0];
|
|
295
|
+
ext = fileName.split('.').pop();
|
|
296
|
+
fileList = files[name] || [];
|
|
297
|
+
if (EXTENSIONS.includes(ext)) {
|
|
298
|
+
// Create Blob and File from arrayBuffer loaded by ZipLoader
|
|
299
|
+
blob = new Blob([fileMap[fileName]]);
|
|
300
|
+
fileList.push(new File([blob], fileName));
|
|
301
|
+
}
|
|
302
|
+
files[name] = fileList;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
// Load each SHP with sidecar files as GeoJSON features
|
|
306
|
+
_t3 = _regeneratorKeys(files);
|
|
307
|
+
case 6:
|
|
308
|
+
if ((_t4 = _t3()).done) {
|
|
309
|
+
_context2.n = 15;
|
|
310
|
+
break;
|
|
311
|
+
}
|
|
312
|
+
f = _t4.value;
|
|
313
|
+
if (!Object.hasOwn(files, f)) {
|
|
314
|
+
_context2.n = 14;
|
|
315
|
+
break;
|
|
316
|
+
}
|
|
317
|
+
list = files[f];
|
|
318
|
+
fileSystem = new _BrowserFileSystem(list);
|
|
319
|
+
fetch = fileSystem.fetch.bind(fileSystem.fetch);
|
|
320
|
+
filename = "".concat(f, ".shp"); // Load SHP and reproject to mapCrs
|
|
321
|
+
data = null;
|
|
322
|
+
_context2.p = 7;
|
|
323
|
+
_context2.n = 8;
|
|
324
|
+
return load(filename, ShapefileLoader, {
|
|
325
|
+
fetch: fetch,
|
|
326
|
+
shapefile: {
|
|
327
|
+
shape: 'geojson-table'
|
|
328
|
+
},
|
|
329
|
+
gis: {
|
|
330
|
+
format: 'geojson',
|
|
331
|
+
reproject: true,
|
|
332
|
+
_targetCrs: mapCrs
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
case 8:
|
|
336
|
+
data = _context2.v;
|
|
337
|
+
_context2.n = 13;
|
|
338
|
+
break;
|
|
339
|
+
case 9:
|
|
340
|
+
_context2.p = 9;
|
|
341
|
+
_t5 = _context2.v;
|
|
342
|
+
_context2.p = 10;
|
|
343
|
+
_context2.n = 11;
|
|
344
|
+
return load(filename, ShapefileLoader, {
|
|
345
|
+
fetch: fetch,
|
|
346
|
+
shapefile: {
|
|
347
|
+
shape: 'geojson-table'
|
|
348
|
+
},
|
|
349
|
+
gis: {
|
|
350
|
+
format: 'geojson',
|
|
351
|
+
reproject: false,
|
|
352
|
+
_targetCrs: mapCrs
|
|
353
|
+
}
|
|
354
|
+
});
|
|
355
|
+
case 11:
|
|
356
|
+
data = _context2.v;
|
|
357
|
+
/* eslint-disable-next-line */
|
|
358
|
+
alert(LocaleUtils.tr("importlayer.shpreprojectionerror"));
|
|
359
|
+
_context2.n = 13;
|
|
360
|
+
break;
|
|
361
|
+
case 12:
|
|
362
|
+
_context2.p = 12;
|
|
363
|
+
_t6 = _context2.v;
|
|
364
|
+
data = null;
|
|
365
|
+
case 13:
|
|
366
|
+
if (data) {
|
|
367
|
+
data.crs = {
|
|
368
|
+
type: "name",
|
|
369
|
+
properties: {
|
|
370
|
+
name: CoordinatesUtils.toOgcUrnCrs(mapCrs)
|
|
371
|
+
}
|
|
372
|
+
};
|
|
373
|
+
// Add data as GeoJSON layer
|
|
374
|
+
FileImportUtils.addGeoJSONLayer(f, data, addLayerFeatures);
|
|
375
|
+
}
|
|
376
|
+
case 14:
|
|
377
|
+
_context2.n = 6;
|
|
378
|
+
break;
|
|
379
|
+
case 15:
|
|
380
|
+
return _context2.a(2);
|
|
381
|
+
}
|
|
382
|
+
}, _callee2, null, [[10, 12], [7, 9]]);
|
|
383
|
+
}));
|
|
384
|
+
function addSHPLayer(_x3, _x4, _x5) {
|
|
385
|
+
return _addSHPLayer.apply(this, arguments);
|
|
386
|
+
}
|
|
387
|
+
return addSHPLayer;
|
|
388
|
+
}()
|
|
389
|
+
};
|
|
390
|
+
export default FileImportUtils;
|
package/utils/LayerUtils.js
CHANGED
|
@@ -703,8 +703,8 @@ var LayerUtils = {
|
|
|
703
703
|
var entry = _step1.value;
|
|
704
704
|
var _layer2 = entry.layer;
|
|
705
705
|
|
|
706
|
-
// Attempt to merge with previous if possible
|
|
707
|
-
if (((_prevlayer = prevlayer) === null || _prevlayer === void 0 ? void 0 : _prevlayer.srcid) === _layer2.srcid) {
|
|
706
|
+
// Attempt to merge with previous if possible (same srcid when defined)
|
|
707
|
+
if (_layer2 !== null && _layer2 !== void 0 && _layer2.srcid && ((_prevlayer = prevlayer) === null || _prevlayer === void 0 ? void 0 : _prevlayer.srcid) === _layer2.srcid) {
|
|
708
708
|
if (isEmpty(prevlayer.sublayers)) {
|
|
709
709
|
prevlayer.sublayers = _layer2.sublayers;
|
|
710
710
|
} else if (!isEmpty(_layer2.sublayers)) {
|