map-ol-utils 0.1.30 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +223 -45
- package/dist/index.cjs +1907 -1120
- package/dist/index.d.cts +475 -134
- package/dist/index.d.mts +661 -0
- package/dist/index.mjs +1830 -0
- package/dist/tdt-vts/decoder.worker.cjs +46 -0
- package/dist/tdt-vts/decoder.worker.d.cts +1 -0
- package/dist/tdt-vts/decoder.worker.d.mts +1 -0
- package/dist/tdt-vts/decoder.worker.mjs +47 -0
- package/dist/tile-loader-CtZwCurI.mjs +630 -0
- package/dist/tile-loader-D4cn6nMU.cjs +683 -0
- package/package.json +20 -12
- package/dist/index.d.ts +0 -320
- package/dist/index.js +0 -1096
package/dist/index.js
DELETED
|
@@ -1,1096 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defProps = Object.defineProperties;
|
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
var __async = (__this, __arguments, generator) => {
|
|
21
|
-
return new Promise((resolve, reject) => {
|
|
22
|
-
var fulfilled = (value) => {
|
|
23
|
-
try {
|
|
24
|
-
step(generator.next(value));
|
|
25
|
-
} catch (e) {
|
|
26
|
-
reject(e);
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
var rejected = (value) => {
|
|
30
|
-
try {
|
|
31
|
-
step(generator.throw(value));
|
|
32
|
-
} catch (e) {
|
|
33
|
-
reject(e);
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
37
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
38
|
-
});
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
// src/types.ts
|
|
42
|
-
var GeometryType = /* @__PURE__ */ ((GeometryType2) => {
|
|
43
|
-
GeometryType2["LineString"] = "LineString";
|
|
44
|
-
GeometryType2["MultiLineString"] = "MultiLineString";
|
|
45
|
-
GeometryType2["Polygon"] = "Polygon";
|
|
46
|
-
GeometryType2["MultiPolygon"] = "MultiPolygon";
|
|
47
|
-
GeometryType2["Invalid"] = "Invalid";
|
|
48
|
-
return GeometryType2;
|
|
49
|
-
})(GeometryType || {});
|
|
50
|
-
|
|
51
|
-
// src/emitter.ts
|
|
52
|
-
import mitt from "mitt";
|
|
53
|
-
var emitter = mitt();
|
|
54
|
-
var emitter_default = emitter;
|
|
55
|
-
|
|
56
|
-
// src/create-map.ts
|
|
57
|
-
import Map2 from "ol/Map";
|
|
58
|
-
import View from "ol/View";
|
|
59
|
-
import { defaults } from "ol/control";
|
|
60
|
-
|
|
61
|
-
// src/overlay.ts
|
|
62
|
-
import gcoord from "gcoord";
|
|
63
|
-
import { Overlay } from "ol";
|
|
64
|
-
var removeOverlays = (key = "") => {
|
|
65
|
-
if (instance) {
|
|
66
|
-
const overlays = instance.getOverlays().getArray().filter((overlay) => overlay.get(key || "position"));
|
|
67
|
-
overlays.forEach((overlay) => instance.removeOverlay(overlay));
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
var removeAnimationMarker = () => removeOverlays("_isAnimationMarker");
|
|
71
|
-
var createAnimationMarker = (imgUrl, data) => {
|
|
72
|
-
removeAnimationMarker();
|
|
73
|
-
const { width, height, lnglat, crsForm } = data;
|
|
74
|
-
const element = document.createElement("div");
|
|
75
|
-
element.innerHTML = `<img src=${imgUrl} height=${height} width=${width} alt="" />`;
|
|
76
|
-
const overlay = new Overlay({
|
|
77
|
-
element,
|
|
78
|
-
stopEvent: false,
|
|
79
|
-
positioning: "bottom-center",
|
|
80
|
-
position: gcoord.transform(
|
|
81
|
-
[+lnglat[0], +lnglat[1]],
|
|
82
|
-
crsForm || gcoord.WGS84,
|
|
83
|
-
gcoord.WGS84
|
|
84
|
-
)
|
|
85
|
-
});
|
|
86
|
-
overlay.set("_isAnimationMarker", true);
|
|
87
|
-
instance.addOverlay(overlay);
|
|
88
|
-
};
|
|
89
|
-
var createOverlay = (config = { id: "popup-container", positioning: "top-center" }) => {
|
|
90
|
-
return new Overlay(
|
|
91
|
-
Object.assign(
|
|
92
|
-
{
|
|
93
|
-
element: document.getElementById(config.id) || void 0
|
|
94
|
-
},
|
|
95
|
-
config
|
|
96
|
-
)
|
|
97
|
-
);
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
// src/layer-manager.ts
|
|
101
|
-
var resetActiveVector = () => {
|
|
102
|
-
removeOverlays();
|
|
103
|
-
const layers = instance.getAllLayers();
|
|
104
|
-
layers.forEach((layer) => {
|
|
105
|
-
const interaction = layer.get("_selectInteraction");
|
|
106
|
-
interaction == null ? void 0 : interaction.getFeatures().clear();
|
|
107
|
-
});
|
|
108
|
-
};
|
|
109
|
-
var removeAllLayers = () => {
|
|
110
|
-
removeOverlays();
|
|
111
|
-
if (instance) {
|
|
112
|
-
instance.getAllLayers().forEach((layer) => {
|
|
113
|
-
if (!layer.get("_isBaseLayer")) {
|
|
114
|
-
const source = layer.getSource();
|
|
115
|
-
if (source && source.dispose) {
|
|
116
|
-
source.dispose();
|
|
117
|
-
}
|
|
118
|
-
instance.removeLayer(layer);
|
|
119
|
-
layer.dispose();
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
var resetActiveFeature = () => {
|
|
125
|
-
removeOverlays();
|
|
126
|
-
const targetLayers = instance.getAllLayers().filter((layer) => layer.get("_isVectorLayer"));
|
|
127
|
-
targetLayers.forEach((layer) => {
|
|
128
|
-
const selectInteraction = layer.get("_selectInteraction");
|
|
129
|
-
if (selectInteraction) {
|
|
130
|
-
selectInteraction.dispatchEvent({
|
|
131
|
-
type: "select",
|
|
132
|
-
selected: [],
|
|
133
|
-
mapBrowserEvent: void 0,
|
|
134
|
-
deselected: selectInteraction.getFeatures().getArray()
|
|
135
|
-
});
|
|
136
|
-
selectInteraction.getFeatures().clear();
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
};
|
|
140
|
-
var activeFeatureByUid = (uid) => {
|
|
141
|
-
var _a;
|
|
142
|
-
const targetLayers = instance.getAllLayers().filter((layer) => layer.get("_isVectorLayer"));
|
|
143
|
-
if (targetLayers.length) {
|
|
144
|
-
const targetLayer = targetLayers.find(
|
|
145
|
-
(layer) => layer.get("_uuidSet").has(uid) && layer.get("_selectInteraction")
|
|
146
|
-
);
|
|
147
|
-
if (targetLayer) {
|
|
148
|
-
const tempList = ((_a = targetLayer.getSource()) == null ? void 0 : _a.getFeatures()) || [];
|
|
149
|
-
const targetFeature = tempList.find(
|
|
150
|
-
(feature) => feature.get("_uuid") === uid
|
|
151
|
-
);
|
|
152
|
-
const selectInteraction = targetLayer.get("_selectInteraction");
|
|
153
|
-
if (selectInteraction) {
|
|
154
|
-
const collection = selectInteraction.getFeatures().getArray();
|
|
155
|
-
const hasFeature = collection.find(
|
|
156
|
-
(feature) => feature.get("_uuid") === uid
|
|
157
|
-
);
|
|
158
|
-
if (!hasFeature) {
|
|
159
|
-
selectInteraction.dispatchEvent({
|
|
160
|
-
type: "select",
|
|
161
|
-
deselected: collection,
|
|
162
|
-
selected: [targetFeature],
|
|
163
|
-
mapBrowserEvent: void 0
|
|
164
|
-
});
|
|
165
|
-
selectInteraction.getFeatures().push(targetFeature);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
// src/create-map.ts
|
|
173
|
-
import { defaults as interactionDefaults } from "ol/interaction";
|
|
174
|
-
|
|
175
|
-
// src/base-layer.ts
|
|
176
|
-
import { XYZ, WMTS } from "ol/source";
|
|
177
|
-
import { TileGrid } from "ol/tilegrid";
|
|
178
|
-
import { Tile } from "ol/layer";
|
|
179
|
-
import WMTSTileGrid from "ol/tilegrid/WMTS";
|
|
180
|
-
|
|
181
|
-
// src/constants.ts
|
|
182
|
-
var DEFAULT_TIANDITU_TK = "c77eddc667c5bed016fded560baf93e7";
|
|
183
|
-
var DEFAULT_ZHEJIANG_TOKEN = "3b0cdd02-c366-4363-b6de-081a9f12b364";
|
|
184
|
-
|
|
185
|
-
// src/base-layer.ts
|
|
186
|
-
var createBaseLayer = (layerName = "hzsyvector_dark") => {
|
|
187
|
-
const config = {
|
|
188
|
-
zIndex: -5,
|
|
189
|
-
preload: 1,
|
|
190
|
-
minZoom: 8,
|
|
191
|
-
maxZoom: 21,
|
|
192
|
-
source: new XYZ({
|
|
193
|
-
tileGrid: new TileGrid({
|
|
194
|
-
tileSize: 256,
|
|
195
|
-
resolutions: [
|
|
196
|
-
0.00549933137253187,
|
|
197
|
-
0.00274966568626595,
|
|
198
|
-
0.00137483284313297,
|
|
199
|
-
687416421566485e-18,
|
|
200
|
-
343708210783242e-18,
|
|
201
|
-
171854105391621e-18,
|
|
202
|
-
859270526958104e-19,
|
|
203
|
-
429635263479052e-19,
|
|
204
|
-
214817631739526e-19,
|
|
205
|
-
107408815869763e-19,
|
|
206
|
-
537044079348816e-20,
|
|
207
|
-
268522039674407e-20,
|
|
208
|
-
134261019837204e-20
|
|
209
|
-
],
|
|
210
|
-
origin: [118.122911693886, 31.2869311022836],
|
|
211
|
-
extent: [
|
|
212
|
-
116.43263049006,
|
|
213
|
-
28.6201742126026,
|
|
214
|
-
123.705594256347,
|
|
215
|
-
31.9765041681924
|
|
216
|
-
]
|
|
217
|
-
}),
|
|
218
|
-
projection: "EPSG:4326",
|
|
219
|
-
urls: [
|
|
220
|
-
`https://cb.hangzhoumap.gov.cn/E36CCEA93443D1495DB9B9F2B2FFE348CB1A367D75176F815040AB19E54CDCA5DAAA25813AF965E2ABD0CC2463DD1223/PBS/rest/services/${layerName}/Mapserver/tile/{z}/{y}/{x}`
|
|
221
|
-
]
|
|
222
|
-
}),
|
|
223
|
-
properties: {
|
|
224
|
-
_isBaseLayer: true,
|
|
225
|
-
_layerName: layerName
|
|
226
|
-
}
|
|
227
|
-
};
|
|
228
|
-
return new Tile(config);
|
|
229
|
-
};
|
|
230
|
-
var createMapWorldLayer = (layerName, tk = DEFAULT_TIANDITU_TK) => {
|
|
231
|
-
const [name, matrixSet] = layerName.split("_");
|
|
232
|
-
const config = {
|
|
233
|
-
preload: 1,
|
|
234
|
-
zIndex: -10,
|
|
235
|
-
cacheSize: 20240,
|
|
236
|
-
properties: {
|
|
237
|
-
_isBaseLayer: true,
|
|
238
|
-
_layerName: layerName
|
|
239
|
-
},
|
|
240
|
-
source: new WMTS({
|
|
241
|
-
crossOrigin: "anonymous",
|
|
242
|
-
projection: "EPSG:4326",
|
|
243
|
-
wrapX: true,
|
|
244
|
-
layer: name,
|
|
245
|
-
style: "default",
|
|
246
|
-
version: "1.0.0",
|
|
247
|
-
format: "image/png",
|
|
248
|
-
matrixSet,
|
|
249
|
-
tileGrid: new WMTSTileGrid({
|
|
250
|
-
tileSize: 256,
|
|
251
|
-
origin: [-180, 90],
|
|
252
|
-
matrixIds: [
|
|
253
|
-
"1",
|
|
254
|
-
"2",
|
|
255
|
-
"3",
|
|
256
|
-
"4",
|
|
257
|
-
"5",
|
|
258
|
-
"6",
|
|
259
|
-
"7",
|
|
260
|
-
"8",
|
|
261
|
-
"9",
|
|
262
|
-
"10",
|
|
263
|
-
"11",
|
|
264
|
-
"12",
|
|
265
|
-
"13",
|
|
266
|
-
"14",
|
|
267
|
-
"15",
|
|
268
|
-
"16",
|
|
269
|
-
"17",
|
|
270
|
-
"18",
|
|
271
|
-
"19"
|
|
272
|
-
],
|
|
273
|
-
resolutions: [
|
|
274
|
-
0.703125,
|
|
275
|
-
0.3515625,
|
|
276
|
-
0.17578125,
|
|
277
|
-
0.087890625,
|
|
278
|
-
0.0439453125,
|
|
279
|
-
0.02197265625,
|
|
280
|
-
0.010986328125,
|
|
281
|
-
0.0054931640625,
|
|
282
|
-
0.00274658203125,
|
|
283
|
-
0.001373291015625,
|
|
284
|
-
6866455078125e-16,
|
|
285
|
-
34332275390625e-17,
|
|
286
|
-
171661376953125e-18,
|
|
287
|
-
858306884765625e-19,
|
|
288
|
-
4291534423828125e-20,
|
|
289
|
-
21457672119140625e-21,
|
|
290
|
-
10728836059570312e-21,
|
|
291
|
-
5364418029785156e-21,
|
|
292
|
-
2682209014892578e-21
|
|
293
|
-
]
|
|
294
|
-
}),
|
|
295
|
-
url: `https://t{0-7}.tianditu.gov.cn/${layerName}/wmts?tk=${tk}`
|
|
296
|
-
})
|
|
297
|
-
};
|
|
298
|
-
return new Tile(config);
|
|
299
|
-
};
|
|
300
|
-
var createZheJiangLayer = (layerName = "emap", tk = DEFAULT_ZHEJIANG_TOKEN) => {
|
|
301
|
-
return new Tile({
|
|
302
|
-
preload: 1,
|
|
303
|
-
minZoom: 4,
|
|
304
|
-
maxZoom: 20,
|
|
305
|
-
zIndex: -10,
|
|
306
|
-
cacheSize: 20240,
|
|
307
|
-
source: new XYZ({
|
|
308
|
-
wrapX: true,
|
|
309
|
-
projection: "EPSG:4326",
|
|
310
|
-
crossOrigin: "anonymous",
|
|
311
|
-
url: `https://ditu{0-6}.zjzwfw.gov.cn/services/wmts/${layerName}/default/oss/getTile/{z}/{y}/{x}?token=${tk}`
|
|
312
|
-
})
|
|
313
|
-
});
|
|
314
|
-
};
|
|
315
|
-
var getLayerByName = (name) => instance.getAllLayers().find((item) => (item.get("_layerName") || item.getClassName()) === name);
|
|
316
|
-
var removeLayerByName = (name) => {
|
|
317
|
-
const layer = getLayerByName(name);
|
|
318
|
-
if (layer) {
|
|
319
|
-
const source = layer.getSource();
|
|
320
|
-
if (source && source.dispose) {
|
|
321
|
-
source.dispose();
|
|
322
|
-
}
|
|
323
|
-
instance.removeLayer(layer);
|
|
324
|
-
layer.dispose();
|
|
325
|
-
}
|
|
326
|
-
};
|
|
327
|
-
var changeLayersByNames = (activeNames, allLayerNames) => {
|
|
328
|
-
const changeLayers = instance.getAllLayers().filter((item) => allLayerNames.includes(item.getClassName()));
|
|
329
|
-
changeLayers.forEach((layer) => {
|
|
330
|
-
layer.setVisible(activeNames == null ? void 0 : activeNames.includes(layer.getClassName()));
|
|
331
|
-
});
|
|
332
|
-
};
|
|
333
|
-
|
|
334
|
-
// src/create-map.ts
|
|
335
|
-
var instance;
|
|
336
|
-
var mapCenter = [119.71512016971076, 30.122490541963536];
|
|
337
|
-
var createMapInstance = (config = {}) => {
|
|
338
|
-
if (instance) {
|
|
339
|
-
return instance;
|
|
340
|
-
}
|
|
341
|
-
instance = createMap(config);
|
|
342
|
-
return instance;
|
|
343
|
-
};
|
|
344
|
-
var createMap = (config = {}) => {
|
|
345
|
-
const innerConfig = Object.assign(
|
|
346
|
-
{
|
|
347
|
-
zoom: 9.4,
|
|
348
|
-
maxZoom: 18,
|
|
349
|
-
minZoom: 9.4,
|
|
350
|
-
center: mapCenter,
|
|
351
|
-
baseLayer: "vec-layer",
|
|
352
|
-
projection: "EPSG:4326",
|
|
353
|
-
layers: [createBaseLayer()],
|
|
354
|
-
constrainResolution: false,
|
|
355
|
-
smoothExtentConstraint: false,
|
|
356
|
-
tk: DEFAULT_TIANDITU_TK
|
|
357
|
-
},
|
|
358
|
-
config || {}
|
|
359
|
-
);
|
|
360
|
-
const map = new Map2({
|
|
361
|
-
view: new View(innerConfig),
|
|
362
|
-
controls: defaults({
|
|
363
|
-
zoom: false,
|
|
364
|
-
rotate: false,
|
|
365
|
-
attribution: false
|
|
366
|
-
}),
|
|
367
|
-
interactions: interactionDefaults({
|
|
368
|
-
pinchRotate: false,
|
|
369
|
-
doubleClickZoom: false,
|
|
370
|
-
altShiftDragRotate: false
|
|
371
|
-
}),
|
|
372
|
-
layers: innerConfig.layers || [createBaseLayer()]
|
|
373
|
-
});
|
|
374
|
-
mapCenter = innerConfig.center || mapCenter;
|
|
375
|
-
map.activeBaseLayer = innerConfig.baseLayer;
|
|
376
|
-
map.getLayerByName = getLayerByName;
|
|
377
|
-
map.removeLayerByName = removeLayerByName;
|
|
378
|
-
map.changeLayersByNames = changeLayersByNames;
|
|
379
|
-
map.on("pointermove", (evt) => {
|
|
380
|
-
map.getTargetElement().style.cursor = map.hasFeatureAtPixel(evt.pixel) ? "pointer" : "";
|
|
381
|
-
});
|
|
382
|
-
return map;
|
|
383
|
-
};
|
|
384
|
-
var disposeMap = () => {
|
|
385
|
-
instance.getOverlays().forEach((overlay) => {
|
|
386
|
-
instance.removeOverlay(overlay);
|
|
387
|
-
});
|
|
388
|
-
instance.getInteractions().clear();
|
|
389
|
-
const layers = instance.getAllLayers();
|
|
390
|
-
layers.forEach((layer) => {
|
|
391
|
-
const source = layer.getSource();
|
|
392
|
-
if (source && source.dispose) {
|
|
393
|
-
source.dispose();
|
|
394
|
-
}
|
|
395
|
-
instance.removeLayer(layer);
|
|
396
|
-
layer.dispose();
|
|
397
|
-
});
|
|
398
|
-
instance.setTarget("");
|
|
399
|
-
instance.dispose();
|
|
400
|
-
instance = void 0;
|
|
401
|
-
};
|
|
402
|
-
var getMapInstance = () => instance;
|
|
403
|
-
var resetZoomAndCenter = (center = mapCenter) => {
|
|
404
|
-
if (instance) {
|
|
405
|
-
const view = instance.getView();
|
|
406
|
-
view.animate({
|
|
407
|
-
zoom: 9.4,
|
|
408
|
-
center,
|
|
409
|
-
duration: 1e3
|
|
410
|
-
});
|
|
411
|
-
}
|
|
412
|
-
};
|
|
413
|
-
var resetMap = (config = { center: mapCenter, isClearAll: true }) => {
|
|
414
|
-
removeAllLayers();
|
|
415
|
-
resetZoomAndCenter(config.center || mapCenter);
|
|
416
|
-
};
|
|
417
|
-
|
|
418
|
-
// src/helper.ts
|
|
419
|
-
var hexToRgba = (hex, alpha) => {
|
|
420
|
-
if (hex.startsWith("#")) {
|
|
421
|
-
let tempHex = hex.replace("#", "");
|
|
422
|
-
if (tempHex.length === 3) {
|
|
423
|
-
tempHex = tempHex[0] + tempHex[0] + tempHex[1] + tempHex[1] + tempHex[2] + tempHex[2];
|
|
424
|
-
}
|
|
425
|
-
const r = parseInt(tempHex.substring(0, 2), 16);
|
|
426
|
-
const g = parseInt(tempHex.substring(2, 4), 16);
|
|
427
|
-
const b = parseInt(tempHex.substring(4, 6), 16);
|
|
428
|
-
return `rgba(${r}, ${g}, ${b}, ${alpha})`;
|
|
429
|
-
} else {
|
|
430
|
-
return hex;
|
|
431
|
-
}
|
|
432
|
-
};
|
|
433
|
-
var getLayersDataList = () => {
|
|
434
|
-
var _a;
|
|
435
|
-
return ((_a = instance) == null ? void 0 : _a.getAllLayers().map((layer) => layer.get("_dataList") || []).flat(2)) || [];
|
|
436
|
-
};
|
|
437
|
-
var determineGeometryType = (coordinates) => {
|
|
438
|
-
const getArrayDepth = (arr) => {
|
|
439
|
-
if (!Array.isArray(arr) || arr.length === 0) return 0;
|
|
440
|
-
return 1 + getArrayDepth(arr[0]);
|
|
441
|
-
};
|
|
442
|
-
const isClosedRing = (coords) => {
|
|
443
|
-
if (!Array.isArray(coords) || coords.length < 3) return false;
|
|
444
|
-
const first = coords[0];
|
|
445
|
-
const last = coords[coords.length - 1];
|
|
446
|
-
return first[0] === last[0] && first[1] === last[1];
|
|
447
|
-
};
|
|
448
|
-
const isValidCoordinate = (coord) => {
|
|
449
|
-
return Array.isArray(coord) && coord.length >= 2 && typeof coord[0] === "number" && typeof coord[1] === "number";
|
|
450
|
-
};
|
|
451
|
-
const isValidLineString = (coords) => {
|
|
452
|
-
return Array.isArray(coords) && coords.length >= 2 && coords.every(isValidCoordinate);
|
|
453
|
-
};
|
|
454
|
-
const isValidPolygon = (coords) => {
|
|
455
|
-
if (!Array.isArray(coords)) return false;
|
|
456
|
-
const rings = getArrayDepth(coords) === 2 ? [coords] : coords;
|
|
457
|
-
return rings.every(
|
|
458
|
-
(ring) => Array.isArray(ring) && ring.length >= 4 && isClosedRing(ring) && ring.every(isValidCoordinate)
|
|
459
|
-
);
|
|
460
|
-
};
|
|
461
|
-
const depth = getArrayDepth(coordinates);
|
|
462
|
-
try {
|
|
463
|
-
if (depth < 2 || !coordinates || coordinates.length === 0) {
|
|
464
|
-
return "Invalid" /* Invalid */;
|
|
465
|
-
} else if (depth === 2 && isValidLineString(coordinates)) {
|
|
466
|
-
return isClosedRing(coordinates) && coordinates.length >= 4 ? "Polygon" /* Polygon */ : "LineString" /* LineString */;
|
|
467
|
-
} else if (depth === 3 && Array.isArray(coordinates) && coordinates.every(isValidLineString)) {
|
|
468
|
-
if (isValidPolygon(coordinates)) {
|
|
469
|
-
return "Polygon" /* Polygon */;
|
|
470
|
-
} else if (coordinates.every((arr) => !isClosedRing(arr))) {
|
|
471
|
-
return "MultiLineString" /* MultiLineString */;
|
|
472
|
-
} else {
|
|
473
|
-
return "Invalid" /* Invalid */;
|
|
474
|
-
}
|
|
475
|
-
} else if (depth === 4 && Array.isArray(coordinates) && coordinates.every((rings) => isValidPolygon(rings))) {
|
|
476
|
-
return "MultiPolygon" /* MultiPolygon */;
|
|
477
|
-
} else {
|
|
478
|
-
return "Invalid" /* Invalid */;
|
|
479
|
-
}
|
|
480
|
-
} catch (error) {
|
|
481
|
-
console.error("Error analyzing coordinates:", error);
|
|
482
|
-
return "Invalid" /* Invalid */;
|
|
483
|
-
}
|
|
484
|
-
};
|
|
485
|
-
|
|
486
|
-
// src/ogc-utils.ts
|
|
487
|
-
import { WMTS as WMTS2 } from "ol/source";
|
|
488
|
-
import TileLayer from "ol/layer/Tile";
|
|
489
|
-
import { WMTSCapabilities } from "ol/format";
|
|
490
|
-
import { optionsFromCapabilities } from "ol/source/WMTS";
|
|
491
|
-
var parser = new WMTSCapabilities();
|
|
492
|
-
var capabilitiesMap = /* @__PURE__ */ new Map();
|
|
493
|
-
var getCapabilities = (url) => {
|
|
494
|
-
return new Promise((resolve) => {
|
|
495
|
-
const capabilities = capabilitiesMap.get(url);
|
|
496
|
-
if (capabilities) {
|
|
497
|
-
resolve(capabilities);
|
|
498
|
-
} else {
|
|
499
|
-
fetch(url).then((data) => data.text()).then((text) => {
|
|
500
|
-
const capabilities2 = parser.read(text);
|
|
501
|
-
capabilitiesMap.set(url, capabilities2);
|
|
502
|
-
resolve(capabilities2);
|
|
503
|
-
});
|
|
504
|
-
}
|
|
505
|
-
});
|
|
506
|
-
};
|
|
507
|
-
var createWmtsLayer = (serverUrl) => (config) => __async(null, null, function* () {
|
|
508
|
-
const { style, format, version, layerName, matrixSet } = config;
|
|
509
|
-
const [workspace, datastore] = layerName.split(":");
|
|
510
|
-
const capabilitiesUrl = `${serverUrl}/${workspace}/${datastore}/gwc/service/wmts?request=GetCapabilities`;
|
|
511
|
-
return new Promise((resolve, reject) => {
|
|
512
|
-
getCapabilities(capabilitiesUrl).then((data) => {
|
|
513
|
-
const options = optionsFromCapabilities(data, {
|
|
514
|
-
Style: style || "",
|
|
515
|
-
layer: datastore,
|
|
516
|
-
version: version || "1.1.0",
|
|
517
|
-
format: format || "image/png",
|
|
518
|
-
matrixSet: matrixSet || "EPSG:4326"
|
|
519
|
-
});
|
|
520
|
-
if (options) {
|
|
521
|
-
resolve(
|
|
522
|
-
new TileLayer({
|
|
523
|
-
zIndex: 3,
|
|
524
|
-
className: layerName,
|
|
525
|
-
source: new WMTS2(options)
|
|
526
|
-
})
|
|
527
|
-
);
|
|
528
|
-
} else {
|
|
529
|
-
reject(new Error("Unable to create TileLayer"));
|
|
530
|
-
}
|
|
531
|
-
});
|
|
532
|
-
});
|
|
533
|
-
});
|
|
534
|
-
|
|
535
|
-
// src/view-fit.ts
|
|
536
|
-
import { boundingExtent } from "ol/extent";
|
|
537
|
-
var DEFAULT_FIT_OPTIONS = {
|
|
538
|
-
padding: [50, 50, 50, 50],
|
|
539
|
-
duration: 1e3
|
|
540
|
-
};
|
|
541
|
-
var setFitViewByCoords = (coords, mapInstance = instance, fitOptions) => {
|
|
542
|
-
const view = mapInstance.getView();
|
|
543
|
-
if (coords.length === 1) {
|
|
544
|
-
view.animate(__spreadValues({
|
|
545
|
-
zoom: 14,
|
|
546
|
-
duration: 1e3,
|
|
547
|
-
center: coords[0]
|
|
548
|
-
}, fitOptions || {}));
|
|
549
|
-
} else {
|
|
550
|
-
const extent = boundingExtent(coords);
|
|
551
|
-
view.fit(extent, __spreadValues(__spreadValues({}, DEFAULT_FIT_OPTIONS), fitOptions || {}));
|
|
552
|
-
}
|
|
553
|
-
};
|
|
554
|
-
var setFitViewByGeom = (geom, mapInstance = instance, fitOptions) => {
|
|
555
|
-
mapInstance.getView().fit(geom, __spreadValues(__spreadValues({}, DEFAULT_FIT_OPTIONS), fitOptions || {}));
|
|
556
|
-
};
|
|
557
|
-
var setFitViewByLayer = (layer, mapInstance = instance, fitOptions) => {
|
|
558
|
-
var _a;
|
|
559
|
-
const extent = ((_a = layer.getSource()) == null ? void 0 : _a.getExtent()) || [];
|
|
560
|
-
mapInstance.getView().fit(extent, __spreadValues(__spreadValues({}, DEFAULT_FIT_OPTIONS), fitOptions || {}));
|
|
561
|
-
};
|
|
562
|
-
|
|
563
|
-
// src/select.ts
|
|
564
|
-
import { getCenter } from "ol/extent";
|
|
565
|
-
import { Select } from "ol/interaction";
|
|
566
|
-
import { singleClick } from "ol/events/condition";
|
|
567
|
-
var selectEventHandle = (vectorLayer, feature) => {
|
|
568
|
-
const data = feature.getProperties();
|
|
569
|
-
const { activeStyle } = data;
|
|
570
|
-
feature.setStyle(activeStyle);
|
|
571
|
-
emitter_default.emit("selected-feature", data);
|
|
572
|
-
vectorLayer.set("_hasActive", true);
|
|
573
|
-
if (vectorLayer.get("_isDynamic")) {
|
|
574
|
-
const activeImage = activeStyle.getImage();
|
|
575
|
-
setTimeout(() => {
|
|
576
|
-
emitter_default.emit(
|
|
577
|
-
"dynamic-marker",
|
|
578
|
-
Object.assign({}, data.rawData || {}, {
|
|
579
|
-
lnglat: data.lnglat,
|
|
580
|
-
style: data.style,
|
|
581
|
-
crsForm: data.crsForm,
|
|
582
|
-
width: activeImage.getWidth(),
|
|
583
|
-
height: activeImage.getHeight()
|
|
584
|
-
})
|
|
585
|
-
);
|
|
586
|
-
}, 1e3);
|
|
587
|
-
}
|
|
588
|
-
const isAutoFit = vectorLayer.get("_isAutoFit");
|
|
589
|
-
if (isAutoFit) {
|
|
590
|
-
const view = instance.getView();
|
|
591
|
-
view.animate({
|
|
592
|
-
duration: 1e3,
|
|
593
|
-
zoom: view.getZoom(),
|
|
594
|
-
center: getCenter(feature.getGeometry().getExtent())
|
|
595
|
-
});
|
|
596
|
-
}
|
|
597
|
-
};
|
|
598
|
-
var createSelectByLayer = (vectorLayer) => {
|
|
599
|
-
const interaction = new Select({
|
|
600
|
-
style: null,
|
|
601
|
-
multi: false,
|
|
602
|
-
hitTolerance: 10,
|
|
603
|
-
layers: [vectorLayer],
|
|
604
|
-
condition: (evt) => {
|
|
605
|
-
let hasFeature = false;
|
|
606
|
-
instance.forEachFeatureAtPixel(
|
|
607
|
-
evt.pixel,
|
|
608
|
-
() => {
|
|
609
|
-
hasFeature = true;
|
|
610
|
-
},
|
|
611
|
-
{
|
|
612
|
-
layerFilter: (layer) => layer === vectorLayer
|
|
613
|
-
}
|
|
614
|
-
);
|
|
615
|
-
return singleClick(evt) && hasFeature;
|
|
616
|
-
}
|
|
617
|
-
});
|
|
618
|
-
interaction.on("select", (evt) => {
|
|
619
|
-
const { selected, deselected } = evt;
|
|
620
|
-
if (selected.length) {
|
|
621
|
-
const feature = selected[0];
|
|
622
|
-
const isClusterLayer = vectorLayer.get("_isClusterLayer");
|
|
623
|
-
if (isClusterLayer) {
|
|
624
|
-
const features = feature.get("features");
|
|
625
|
-
if (features.length === 1) {
|
|
626
|
-
selectEventHandle(vectorLayer, features[0]);
|
|
627
|
-
}
|
|
628
|
-
} else {
|
|
629
|
-
selectEventHandle(vectorLayer, feature);
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
if (deselected.length) {
|
|
633
|
-
const feature = deselected[0];
|
|
634
|
-
const data = feature.getProperties();
|
|
635
|
-
feature.setStyle(data.unActiveStyle);
|
|
636
|
-
vectorLayer.set("_hasActive", false);
|
|
637
|
-
}
|
|
638
|
-
});
|
|
639
|
-
instance.addInteraction(interaction);
|
|
640
|
-
vectorLayer.set("_selectInteraction", interaction);
|
|
641
|
-
return interaction;
|
|
642
|
-
};
|
|
643
|
-
|
|
644
|
-
// src/vector-layer.ts
|
|
645
|
-
import { GeoJSON } from "ol/format";
|
|
646
|
-
import gcoord2 from "gcoord";
|
|
647
|
-
import VectorLayer from "ol/layer/Vector";
|
|
648
|
-
import VectorSource from "ol/source/Vector";
|
|
649
|
-
import { Fill, Style, Stroke } from "ol/style";
|
|
650
|
-
var resolveColor = (data, colorKey, colorMap, fallback) => colorKey ? (colorMap == null ? void 0 : colorMap.get(data[colorKey])) || fallback : fallback;
|
|
651
|
-
var assembleGeoJson = (dataList, config) => {
|
|
652
|
-
const { key, crsForm } = config;
|
|
653
|
-
const tempList = [];
|
|
654
|
-
dataList.forEach((item) => {
|
|
655
|
-
try {
|
|
656
|
-
const raw = item[key];
|
|
657
|
-
const pathArray = Array.isArray(raw) ? raw : JSON.parse(raw || "[]");
|
|
658
|
-
if (pathArray.length) {
|
|
659
|
-
const type = item["geoType"] || determineGeometryType(pathArray);
|
|
660
|
-
if (type !== "Invalid" /* Invalid */) {
|
|
661
|
-
tempList.push({
|
|
662
|
-
type: "Feature",
|
|
663
|
-
properties: __spreadValues({}, item),
|
|
664
|
-
geometry: {
|
|
665
|
-
type,
|
|
666
|
-
coordinates: pathArray
|
|
667
|
-
}
|
|
668
|
-
});
|
|
669
|
-
}
|
|
670
|
-
}
|
|
671
|
-
} catch (e) {
|
|
672
|
-
console.error(`\u521B\u5EFA\u7EBF\u72B6\u6570\u636E\u5931\u8D25\uFF1A${e}`);
|
|
673
|
-
}
|
|
674
|
-
});
|
|
675
|
-
return gcoord2.transform(
|
|
676
|
-
{ type: "FeatureCollection", features: tempList },
|
|
677
|
-
crsForm || gcoord2.WGS84,
|
|
678
|
-
gcoord2.WGS84
|
|
679
|
-
);
|
|
680
|
-
};
|
|
681
|
-
var createVectorStyle = (feature, config) => {
|
|
682
|
-
const {
|
|
683
|
-
isLine,
|
|
684
|
-
colorMap,
|
|
685
|
-
fillColor,
|
|
686
|
-
colorKey,
|
|
687
|
-
strokeColor,
|
|
688
|
-
fillOpacity,
|
|
689
|
-
strokeWeight,
|
|
690
|
-
activeFillColor,
|
|
691
|
-
activeFillOpacity,
|
|
692
|
-
activeStrokeColor,
|
|
693
|
-
activeStrokeWeight
|
|
694
|
-
} = config || {};
|
|
695
|
-
const data = feature.getProperties();
|
|
696
|
-
const activeStyle = new Style({
|
|
697
|
-
stroke: new Stroke({
|
|
698
|
-
width: activeStrokeWeight || strokeWeight || 4,
|
|
699
|
-
color: activeStrokeColor || resolveColor(data, colorKey, colorMap, strokeColor)
|
|
700
|
-
})
|
|
701
|
-
});
|
|
702
|
-
const unActiveStyle = new Style({
|
|
703
|
-
stroke: new Stroke({
|
|
704
|
-
width: strokeWeight || 2,
|
|
705
|
-
color: resolveColor(data, colorKey, colorMap, strokeColor)
|
|
706
|
-
})
|
|
707
|
-
});
|
|
708
|
-
if (!isLine) {
|
|
709
|
-
activeStyle.setFill(
|
|
710
|
-
new Fill({
|
|
711
|
-
color: hexToRgba(
|
|
712
|
-
activeFillColor || fillColor || "",
|
|
713
|
-
activeFillOpacity || 1
|
|
714
|
-
) || hexToRgba(
|
|
715
|
-
resolveColor(data, colorKey, colorMap, fillColor) || "",
|
|
716
|
-
fillOpacity || 1
|
|
717
|
-
)
|
|
718
|
-
})
|
|
719
|
-
);
|
|
720
|
-
unActiveStyle.setFill(
|
|
721
|
-
new Fill({
|
|
722
|
-
color: hexToRgba(
|
|
723
|
-
resolveColor(data, colorKey, colorMap, fillColor) || "",
|
|
724
|
-
fillOpacity || 1
|
|
725
|
-
)
|
|
726
|
-
})
|
|
727
|
-
);
|
|
728
|
-
}
|
|
729
|
-
feature.setProperties({
|
|
730
|
-
activeStyle,
|
|
731
|
-
unActiveStyle
|
|
732
|
-
});
|
|
733
|
-
return unActiveStyle;
|
|
734
|
-
};
|
|
735
|
-
var createBusinessLayer = (dataList, config) => {
|
|
736
|
-
const { isAutoFit, layerName, openClick } = config;
|
|
737
|
-
const geoJson = assembleGeoJson(dataList, config);
|
|
738
|
-
const vectorLayer = new VectorLayer({
|
|
739
|
-
zIndex: 5,
|
|
740
|
-
className: layerName ? layerName : "ol-layer",
|
|
741
|
-
source: new VectorSource({
|
|
742
|
-
features: new GeoJSON().readFeatures(geoJson).map((feature) => {
|
|
743
|
-
feature.setStyle(createVectorStyle(feature, config));
|
|
744
|
-
return feature;
|
|
745
|
-
})
|
|
746
|
-
})
|
|
747
|
-
});
|
|
748
|
-
if (openClick) {
|
|
749
|
-
createSelectByLayer(vectorLayer);
|
|
750
|
-
}
|
|
751
|
-
vectorLayer.setProperties({
|
|
752
|
-
_isCustom: true,
|
|
753
|
-
_isAutoFit: isAutoFit,
|
|
754
|
-
_isVectorLayer: true,
|
|
755
|
-
_vectorConfig: config,
|
|
756
|
-
_layerName: layerName,
|
|
757
|
-
_dataList: [...dataList],
|
|
758
|
-
_uuidSet: new Set(dataList.map((item) => item._uuid) || [])
|
|
759
|
-
});
|
|
760
|
-
return vectorLayer;
|
|
761
|
-
};
|
|
762
|
-
var appendFeaturesByLayer = (targetLayer, dataList, crsForm) => {
|
|
763
|
-
const vectorSource = targetLayer.getSource();
|
|
764
|
-
const tempSet = targetLayer.get("_uuidSet") || /* @__PURE__ */ new Set();
|
|
765
|
-
dataList.forEach((item) => tempSet.add(item._uuid));
|
|
766
|
-
targetLayer.set("_uuidSet", tempSet);
|
|
767
|
-
const { _vectorConfig: config } = targetLayer.getProperties() || {};
|
|
768
|
-
const geoJson = assembleGeoJson(
|
|
769
|
-
dataList,
|
|
770
|
-
Object.assign({}, config, { crsForm })
|
|
771
|
-
);
|
|
772
|
-
vectorSource.addFeatures(
|
|
773
|
-
new GeoJSON().readFeatures(geoJson).map((feature) => {
|
|
774
|
-
feature.setStyle(createVectorStyle(feature, config));
|
|
775
|
-
return feature;
|
|
776
|
-
})
|
|
777
|
-
);
|
|
778
|
-
};
|
|
779
|
-
var createVectorFaceLayer = (dataList = [], config) => createBusinessLayer(dataList, Object.assign({}, config, { isLine: false }));
|
|
780
|
-
var createVectorLineLayer = (dataList = [], config) => createBusinessLayer(dataList, Object.assign({}, config, { isLine: true }));
|
|
781
|
-
|
|
782
|
-
// src/mass-marks.ts
|
|
783
|
-
import { Feature } from "ol";
|
|
784
|
-
import { Point } from "ol/geom";
|
|
785
|
-
import gcoord3 from "gcoord";
|
|
786
|
-
import { Icon, Style as Style2 } from "ol/style";
|
|
787
|
-
import VectorLayer2 from "ol/layer/Vector";
|
|
788
|
-
import VectorSource2 from "ol/source/Vector";
|
|
789
|
-
var buildMassMarksStyles = (getImgUrlFn) => {
|
|
790
|
-
return (iconConfig) => {
|
|
791
|
-
const {
|
|
792
|
-
baseUrl,
|
|
793
|
-
markerIcon,
|
|
794
|
-
statusNum = 5,
|
|
795
|
-
activeScale = 1.3,
|
|
796
|
-
markerSize = [32, 32]
|
|
797
|
-
} = iconConfig;
|
|
798
|
-
const getMarkerUrl = getImgUrlFn(baseUrl);
|
|
799
|
-
const [x, y] = markerSize;
|
|
800
|
-
const massMarksStyles = new Array(statusNum * 2);
|
|
801
|
-
for (let i = 0; i < statusNum; i++) {
|
|
802
|
-
const imageUrl = getMarkerUrl(`${markerIcon}-${i}`, ".webp");
|
|
803
|
-
massMarksStyles[i] = new Style2({
|
|
804
|
-
zIndex: 88 + i,
|
|
805
|
-
image: new Icon({
|
|
806
|
-
width: x,
|
|
807
|
-
height: y,
|
|
808
|
-
src: imageUrl,
|
|
809
|
-
anchor: [0.5, 1]
|
|
810
|
-
})
|
|
811
|
-
});
|
|
812
|
-
const activeImage = getMarkerUrl(`${markerIcon}-${i}-active`, ".webp");
|
|
813
|
-
massMarksStyles[i + statusNum] = new Style2({
|
|
814
|
-
zIndex: 120,
|
|
815
|
-
image: new Icon({
|
|
816
|
-
width: x * activeScale,
|
|
817
|
-
height: y * activeScale,
|
|
818
|
-
anchor: [0.5, 1],
|
|
819
|
-
src: activeImage ? activeImage : imageUrl
|
|
820
|
-
})
|
|
821
|
-
});
|
|
822
|
-
}
|
|
823
|
-
return massMarksStyles;
|
|
824
|
-
};
|
|
825
|
-
};
|
|
826
|
-
var createFeatures = (dataList, styleList = []) => {
|
|
827
|
-
return dataList.map((item) => {
|
|
828
|
-
const { crsForm } = item;
|
|
829
|
-
const coord = gcoord3.transform(
|
|
830
|
-
[+item.lnglat[0], +item.lnglat[1]],
|
|
831
|
-
crsForm || gcoord3.WGS84,
|
|
832
|
-
gcoord3.WGS84
|
|
833
|
-
);
|
|
834
|
-
const feature = new Feature({
|
|
835
|
-
geometry: new Point(coord)
|
|
836
|
-
});
|
|
837
|
-
feature.setProperties(__spreadProps(__spreadValues({}, item), {
|
|
838
|
-
unActiveStyle: styleList[item.style],
|
|
839
|
-
activeStyle: styleList[item.style + styleList.length / 2]
|
|
840
|
-
}));
|
|
841
|
-
feature.setStyle(styleList[item.style]);
|
|
842
|
-
return feature;
|
|
843
|
-
});
|
|
844
|
-
};
|
|
845
|
-
var addFeaturesByLayer = (targetLayer, dataList, config) => {
|
|
846
|
-
const massMarksStyles = targetLayer.get("_massMarksStyles");
|
|
847
|
-
const targetSource = targetLayer == null ? void 0 : targetLayer.getSource();
|
|
848
|
-
const { clear } = config;
|
|
849
|
-
if (clear) {
|
|
850
|
-
targetSource == null ? void 0 : targetSource.clear();
|
|
851
|
-
}
|
|
852
|
-
targetSource == null ? void 0 : targetSource.addFeatures(createFeatures(dataList, massMarksStyles));
|
|
853
|
-
};
|
|
854
|
-
var createMassMarksLayer = (dataList, styleList = []) => {
|
|
855
|
-
const vectorLayer = new VectorLayer2({
|
|
856
|
-
zIndex: 2e3,
|
|
857
|
-
source: new VectorSource2({
|
|
858
|
-
features: createFeatures(dataList, styleList)
|
|
859
|
-
})
|
|
860
|
-
});
|
|
861
|
-
vectorLayer.setProperties({
|
|
862
|
-
_isCustom: true,
|
|
863
|
-
_isVectorLayer: true,
|
|
864
|
-
_isMassMarksLayer: true,
|
|
865
|
-
_statusNum: styleList.length / 2,
|
|
866
|
-
_dataList: [...dataList],
|
|
867
|
-
_uuidSet: new Set(dataList.map((item) => item._uuid) || [])
|
|
868
|
-
});
|
|
869
|
-
return vectorLayer;
|
|
870
|
-
};
|
|
871
|
-
var addMassMarksLayer = (getImgUrlFn) => {
|
|
872
|
-
return (dataList = [], iconConfig, openClick = true) => {
|
|
873
|
-
const {
|
|
874
|
-
offset = [0, 0],
|
|
875
|
-
baseUrl,
|
|
876
|
-
hasLine,
|
|
877
|
-
hasFace,
|
|
878
|
-
layerName,
|
|
879
|
-
isDynamic,
|
|
880
|
-
isAutoFit,
|
|
881
|
-
statusNum,
|
|
882
|
-
markerIcon,
|
|
883
|
-
marksStyles,
|
|
884
|
-
markerSize,
|
|
885
|
-
activeScale,
|
|
886
|
-
vectorConfig
|
|
887
|
-
} = iconConfig;
|
|
888
|
-
const massMarksStyles = marksStyles ? marksStyles : buildMassMarksStyles(getImgUrlFn)({
|
|
889
|
-
baseUrl,
|
|
890
|
-
markerIcon,
|
|
891
|
-
markerSize,
|
|
892
|
-
statusNum: statusNum || 5,
|
|
893
|
-
activeScale: activeScale || 1.3
|
|
894
|
-
});
|
|
895
|
-
const massMarksLayer = createMassMarksLayer(dataList, massMarksStyles);
|
|
896
|
-
if (openClick) {
|
|
897
|
-
massMarksLayer.setProperties({
|
|
898
|
-
_offset: offset,
|
|
899
|
-
_isAutoFit: isAutoFit
|
|
900
|
-
});
|
|
901
|
-
createSelectByLayer(massMarksLayer);
|
|
902
|
-
}
|
|
903
|
-
if (hasLine) {
|
|
904
|
-
const vectorLayer = createBusinessLayer(
|
|
905
|
-
dataList,
|
|
906
|
-
Object.assign(
|
|
907
|
-
{},
|
|
908
|
-
{
|
|
909
|
-
key: "line",
|
|
910
|
-
isLine: true,
|
|
911
|
-
openClick: false,
|
|
912
|
-
strokeWeight: 4,
|
|
913
|
-
strokeColor: "rgba(29, 235, 255, 0.8)"
|
|
914
|
-
},
|
|
915
|
-
vectorConfig || {}
|
|
916
|
-
)
|
|
917
|
-
);
|
|
918
|
-
instance.addLayer(vectorLayer);
|
|
919
|
-
}
|
|
920
|
-
if (hasFace) {
|
|
921
|
-
const vectorLayer = createBusinessLayer(
|
|
922
|
-
dataList,
|
|
923
|
-
Object.assign(
|
|
924
|
-
{},
|
|
925
|
-
{
|
|
926
|
-
isLine: false,
|
|
927
|
-
key: "faceList",
|
|
928
|
-
strokeWeight: 1,
|
|
929
|
-
openClick: false,
|
|
930
|
-
fillColor: "#4247DF",
|
|
931
|
-
strokeStyle: "dashed",
|
|
932
|
-
strokeColor: "#4247DF"
|
|
933
|
-
},
|
|
934
|
-
vectorConfig || {}
|
|
935
|
-
)
|
|
936
|
-
);
|
|
937
|
-
instance.addLayer(vectorLayer);
|
|
938
|
-
}
|
|
939
|
-
massMarksLayer.setProperties({
|
|
940
|
-
_isCustom: true,
|
|
941
|
-
_offset: offset,
|
|
942
|
-
_hasLine: hasLine,
|
|
943
|
-
_hasFace: hasFace,
|
|
944
|
-
className: layerName,
|
|
945
|
-
_layerName: layerName,
|
|
946
|
-
_isVectorLayer: true,
|
|
947
|
-
_isDynamic: isDynamic,
|
|
948
|
-
_massMarksStyles: massMarksStyles
|
|
949
|
-
});
|
|
950
|
-
instance.addLayer(massMarksLayer);
|
|
951
|
-
return massMarksLayer;
|
|
952
|
-
};
|
|
953
|
-
};
|
|
954
|
-
var updateMarksLayersByStatus = (checkedStatusList = []) => {
|
|
955
|
-
const hideStyle = new Style2({});
|
|
956
|
-
const tempList = [];
|
|
957
|
-
const targetLayers = instance.getAllLayers().filter((layer) => layer.get("_isMassMarksLayer"));
|
|
958
|
-
targetLayers.forEach((layer) => {
|
|
959
|
-
const features = layer.getSource().getFeatures();
|
|
960
|
-
features.forEach((feature) => {
|
|
961
|
-
const data = feature.getProperties();
|
|
962
|
-
if (!checkedStatusList.includes(data.status)) {
|
|
963
|
-
feature.setStyle(hideStyle);
|
|
964
|
-
} else {
|
|
965
|
-
tempList.push(data);
|
|
966
|
-
feature.setStyle(data.unActiveStyle);
|
|
967
|
-
}
|
|
968
|
-
});
|
|
969
|
-
});
|
|
970
|
-
return tempList;
|
|
971
|
-
};
|
|
972
|
-
|
|
973
|
-
// src/cluster.ts
|
|
974
|
-
import { Feature as Feature2 } from "ol";
|
|
975
|
-
import { Point as Point2 } from "ol/geom";
|
|
976
|
-
import Cluster from "ol/source/Cluster";
|
|
977
|
-
import CircleStyle from "ol/style/Circle";
|
|
978
|
-
import VectorLayer3 from "ol/layer/Vector";
|
|
979
|
-
import VectorSource3 from "ol/source/Vector";
|
|
980
|
-
import { Fill as Fill2, Style as Style3, Stroke as Stroke2, Text } from "ol/style";
|
|
981
|
-
var createClusterLayer = (dataList, config) => {
|
|
982
|
-
const count = dataList.length;
|
|
983
|
-
const styleCache = {};
|
|
984
|
-
const {
|
|
985
|
-
distance,
|
|
986
|
-
minDistance,
|
|
987
|
-
openClick,
|
|
988
|
-
buildStyle,
|
|
989
|
-
singleStyles,
|
|
990
|
-
computedRadius,
|
|
991
|
-
layerName = "cluster-layer"
|
|
992
|
-
} = config;
|
|
993
|
-
const innerComputedRadius = (size) => Math.pow(size / count, 1 / 18);
|
|
994
|
-
styleCache[1] = singleStyles;
|
|
995
|
-
const innerBuildStyle = (feature) => {
|
|
996
|
-
const size = feature.get("features").length;
|
|
997
|
-
let style = styleCache[size];
|
|
998
|
-
const tempRadius = computedRadius ? computedRadius(size) : innerComputedRadius(size);
|
|
999
|
-
if (!style) {
|
|
1000
|
-
style = new Style3({
|
|
1001
|
-
image: new CircleStyle({
|
|
1002
|
-
radius: tempRadius * 20,
|
|
1003
|
-
stroke: new Stroke2({
|
|
1004
|
-
width: 2,
|
|
1005
|
-
color: `hsla(${180 - tempRadius * 180}, 100%, 40%, 1)`
|
|
1006
|
-
}),
|
|
1007
|
-
fill: new Fill2({
|
|
1008
|
-
color: `hsla(${180 - tempRadius * 180}, 100%, 50%, 1)`
|
|
1009
|
-
})
|
|
1010
|
-
}),
|
|
1011
|
-
text: new Text({
|
|
1012
|
-
text: size.toString(),
|
|
1013
|
-
fill: new Fill2({
|
|
1014
|
-
color: `hsla(${180 - tempRadius * 180}, 100%, 10%, 1)`
|
|
1015
|
-
}),
|
|
1016
|
-
textBaseline: "middle"
|
|
1017
|
-
})
|
|
1018
|
-
});
|
|
1019
|
-
styleCache[size] = style;
|
|
1020
|
-
}
|
|
1021
|
-
if (Array.isArray(style)) {
|
|
1022
|
-
const tempFeature = feature.get("features")[0];
|
|
1023
|
-
const index = tempFeature.get("styleIndex") || 0;
|
|
1024
|
-
tempFeature.setProperties({
|
|
1025
|
-
unActiveStyle: style[index],
|
|
1026
|
-
activeStyle: style[index + style.length / 2]
|
|
1027
|
-
});
|
|
1028
|
-
return style[index];
|
|
1029
|
-
}
|
|
1030
|
-
return style;
|
|
1031
|
-
};
|
|
1032
|
-
const vectorLayer = new VectorLayer3({
|
|
1033
|
-
zIndex: 200,
|
|
1034
|
-
className: layerName,
|
|
1035
|
-
source: new Cluster({
|
|
1036
|
-
distance: distance || 80,
|
|
1037
|
-
minDistance: minDistance || 0,
|
|
1038
|
-
source: new VectorSource3({
|
|
1039
|
-
features: dataList.map((item) => {
|
|
1040
|
-
const feature = new Feature2(new Point2(item.lnglat));
|
|
1041
|
-
feature.setProperties(item);
|
|
1042
|
-
return feature;
|
|
1043
|
-
})
|
|
1044
|
-
})
|
|
1045
|
-
}),
|
|
1046
|
-
style: (feature) => buildStyle ? buildStyle(feature) : innerBuildStyle(feature)
|
|
1047
|
-
});
|
|
1048
|
-
vectorLayer.setProperties({
|
|
1049
|
-
_isCustom: true,
|
|
1050
|
-
_isVectorLayer: true,
|
|
1051
|
-
_isClusterLayer: true
|
|
1052
|
-
});
|
|
1053
|
-
if (openClick) {
|
|
1054
|
-
createSelectByLayer(vectorLayer);
|
|
1055
|
-
}
|
|
1056
|
-
return vectorLayer;
|
|
1057
|
-
};
|
|
1058
|
-
export {
|
|
1059
|
-
GeometryType,
|
|
1060
|
-
activeFeatureByUid,
|
|
1061
|
-
addFeaturesByLayer,
|
|
1062
|
-
addMassMarksLayer,
|
|
1063
|
-
appendFeaturesByLayer,
|
|
1064
|
-
buildMassMarksStyles,
|
|
1065
|
-
createAnimationMarker,
|
|
1066
|
-
createBaseLayer,
|
|
1067
|
-
createBusinessLayer,
|
|
1068
|
-
createClusterLayer,
|
|
1069
|
-
createMap,
|
|
1070
|
-
createMapInstance,
|
|
1071
|
-
createMapWorldLayer,
|
|
1072
|
-
createMassMarksLayer,
|
|
1073
|
-
createOverlay,
|
|
1074
|
-
createSelectByLayer,
|
|
1075
|
-
createVectorFaceLayer,
|
|
1076
|
-
createVectorLineLayer,
|
|
1077
|
-
createWmtsLayer,
|
|
1078
|
-
createZheJiangLayer,
|
|
1079
|
-
disposeMap,
|
|
1080
|
-
emitter_default as emitter,
|
|
1081
|
-
getLayerByName,
|
|
1082
|
-
getLayersDataList,
|
|
1083
|
-
getMapInstance,
|
|
1084
|
-
instance,
|
|
1085
|
-
removeAllLayers,
|
|
1086
|
-
removeLayerByName,
|
|
1087
|
-
removeOverlays,
|
|
1088
|
-
resetActiveFeature,
|
|
1089
|
-
resetActiveVector,
|
|
1090
|
-
resetMap,
|
|
1091
|
-
resetZoomAndCenter,
|
|
1092
|
-
setFitViewByCoords,
|
|
1093
|
-
setFitViewByGeom,
|
|
1094
|
-
setFitViewByLayer,
|
|
1095
|
-
updateMarksLayersByStatus
|
|
1096
|
-
};
|