@summeruse/ol 0.4.2 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -2,347 +2,31 @@ import { computed, createElementBlock, defineComponent, inject, onBeforeUnmount,
2
2
  import { Feature, Map as Map$1, Overlay, View } from "ol";
3
3
  import { Attribution, FullScreen, OverviewMap, Rotate, ScaleLine, Zoom } from "ol/control";
4
4
  import { DoubleClickZoom, DragPan, DragRotate, Draw, KeyboardPan, KeyboardZoom, Modify, MouseWheelZoom, PinchRotate, PinchZoom } from "ol/interaction";
5
- import { getCenter } from "ol/extent";
6
5
  import { Circle, LineString, MultiLineString, MultiPoint, MultiPolygon, Point, Polygon } from "ol/geom";
7
- import VectorLayer from "ol/layer/Vector";
8
- import VectorSource from "ol/source/Vector";
9
6
  import { Circle as Circle$1, Fill, Icon, Stroke, Style, Text } from "ol/style";
10
7
  import { Graticule, Layer, Tile } from "ol/layer";
8
+ import HeatmapLayer from "ol/layer/Heatmap";
9
+ import VectorLayer from "ol/layer/Vector";
11
10
  import WebGLVectorLayer from "ol/layer/WebGLVector";
12
11
  import { BingMaps, OSM, Source, XYZ } from "ol/source";
13
12
  import ImageTileSource from "ol/source/ImageTile";
13
+ import VectorSource from "ol/source/Vector";
14
14
  import { get, transform, transformExtent } from "ol/proj";
15
15
  import { register } from "ol/proj/proj4";
16
16
  import { createXYZ } from "ol/tilegrid";
17
+ import { getCenter } from "ol/extent";
17
18
 
18
- //#region components/ol-map/props.ts
19
- const olMapInjectionKey = Symbol("olMapInjectionKey");
20
- function useOlMap() {
21
- return inject(olMapInjectionKey);
22
- }
19
+ //#region constants/distance.ts
20
+ const ONE_NM = 1852;
23
21
 
24
22
  //#endregion
25
- //#region components/ol-map/index.vue
26
- const _sfc_main = /* @__PURE__ */ defineComponent({
27
- name: "OlMap",
28
- __name: "index",
29
- props: {
30
- olMap: { default: () => new Map$1() },
31
- center: { default: () => [0, 0] },
32
- zoom: { default: 2 },
33
- minZoom: { default: 2 },
34
- maxZoom: { default: 18 },
35
- constrainResolution: {
36
- type: Boolean,
37
- default: true
38
- },
39
- projection: {},
40
- extent: {},
41
- showZoom: {
42
- type: Boolean,
43
- default: false
44
- },
45
- showAttribution: {
46
- type: Boolean,
47
- default: false
48
- },
49
- showRotate: {
50
- type: Boolean,
51
- default: false
52
- },
53
- showFullScreen: {
54
- type: Boolean,
55
- default: false
56
- },
57
- showOverview: {
58
- type: Boolean,
59
- default: false
60
- },
61
- showScale: {
62
- type: Boolean,
63
- default: false
64
- },
65
- dragPan: {
66
- type: Boolean,
67
- default: true
68
- },
69
- mouseWheelZoom: {
70
- type: Boolean,
71
- default: true
72
- },
73
- doubleClickZoom: {
74
- type: Boolean,
75
- default: false
76
- },
77
- pinchRotate: { type: Boolean },
78
- pinchZoom: { type: Boolean },
79
- altShiftDragRotate: { type: Boolean }
80
- },
81
- emits: [
82
- "update:zoom",
83
- "update:center",
84
- "changeResolution",
85
- "changeCenter",
86
- "moveend",
87
- "movestart"
88
- ],
89
- setup(__props, { expose: __expose, emit: __emit }) {
90
- const props = __props;
91
- const emits = __emit;
92
- const mapRef = ref();
93
- const olMap = props.olMap;
94
- const view = new View({
95
- projection: props.projection,
96
- extent: props.extent
97
- });
98
- olMap.setView(view);
99
- view.setZoom(props.zoom);
100
- view.setCenter(props.center);
101
- watch(() => props.constrainResolution, (val) => {
102
- view.setConstrainResolution(val);
103
- }, { immediate: true });
104
- watch(() => props.minZoom, (val) => {
105
- if (val) view.setMinZoom(val);
106
- }, { immediate: true });
107
- watch(() => props.maxZoom, (val) => {
108
- if (val) view.setMaxZoom(val);
109
- }, { immediate: true });
110
- watch(mapRef, (val) => {
111
- if (val) olMap.setTarget(val);
112
- });
113
- __expose({ olMap });
114
- provide(olMapInjectionKey, olMap);
115
- const controls = olMap.getControls().getArray();
116
- const zoomControl = controls.find((control) => control instanceof Zoom) || new Zoom();
117
- const attributionControl = controls.find((control) => control instanceof Attribution) || new Attribution();
118
- const rotateControl = controls.find((control) => control instanceof Rotate) || new Rotate();
119
- const fullScreenControl = controls.find((control) => control instanceof FullScreen) || new FullScreen();
120
- const overviewMapControl = controls.find((control) => control instanceof OverviewMap) || new OverviewMap();
121
- const scaleControl = controls.find((control) => control instanceof ScaleLine) || new ScaleLine();
122
- watch(() => props.showZoom, (val) => {
123
- zoomControl.setMap(val ? olMap : null);
124
- }, { immediate: true });
125
- watch(() => props.showAttribution, (val) => {
126
- attributionControl.setMap(val ? olMap : null);
127
- }, { immediate: true });
128
- watch(() => props.showRotate, (val) => {
129
- rotateControl.setMap(val ? olMap : null);
130
- }, { immediate: true });
131
- watch(() => props.showFullScreen, (val) => {
132
- fullScreenControl.setMap(val ? olMap : null);
133
- }, { immediate: true });
134
- watch(() => props.showOverview, (val) => {
135
- overviewMapControl.setMap(val ? olMap : null);
136
- }, { immediate: true });
137
- watch(() => props.showScale, (val) => {
138
- scaleControl.setMap(val ? olMap : null);
139
- }, { immediate: true });
140
- const interactions = olMap.getInteractions().getArray();
141
- const dragPan = interactions.find((i$1) => i$1 instanceof DragPan) || new DragPan();
142
- const mouseWheelZoom = interactions.find((i$1) => i$1 instanceof MouseWheelZoom) || new MouseWheelZoom();
143
- const doubleClickZoom = interactions.find((i$1) => i$1 instanceof DoubleClickZoom) || new DoubleClickZoom();
144
- const pinchRotate = interactions.find((i$1) => i$1 instanceof PinchRotate) || new PinchRotate();
145
- const pinchZoom = interactions.find((i$1) => i$1 instanceof PinchZoom) || new PinchZoom();
146
- const altShiftDragRotate = interactions.find((i$1) => i$1 instanceof DragRotate) || new DragRotate();
147
- const keyboardPan = interactions.find((i$1) => i$1 instanceof KeyboardPan) || new KeyboardPan();
148
- const keyboardZoom = interactions.find((i$1) => i$1 instanceof KeyboardZoom) || new KeyboardZoom();
149
- olMap.removeInteraction(dragPan);
150
- olMap.addInteraction(dragPan);
151
- olMap.removeInteraction(mouseWheelZoom);
152
- olMap.addInteraction(mouseWheelZoom);
153
- olMap.removeInteraction(doubleClickZoom);
154
- olMap.addInteraction(doubleClickZoom);
155
- olMap.removeInteraction(pinchRotate);
156
- olMap.addInteraction(pinchRotate);
157
- olMap.removeInteraction(pinchZoom);
158
- olMap.addInteraction(pinchZoom);
159
- olMap.removeInteraction(altShiftDragRotate);
160
- olMap.addInteraction(altShiftDragRotate);
161
- olMap.removeInteraction(keyboardPan);
162
- olMap.removeInteraction(keyboardZoom);
163
- watch(() => props.dragPan, (val) => {
164
- dragPan.setActive(val);
165
- }, { immediate: true });
166
- watch(() => props.mouseWheelZoom, (val) => {
167
- mouseWheelZoom.setActive(val);
168
- }, { immediate: true });
169
- watch(() => props.doubleClickZoom, (val) => {
170
- doubleClickZoom.setActive(val);
171
- }, { immediate: true });
172
- watch(() => props.pinchRotate, (val) => {
173
- pinchRotate.setActive(val);
174
- }, { immediate: true });
175
- watch(() => props.pinchZoom, (val) => {
176
- pinchZoom.setActive(val);
177
- }, { immediate: true });
178
- watch(() => props.altShiftDragRotate, (val) => {
179
- altShiftDragRotate.setActive(val);
180
- }, { immediate: true });
181
- function changeResolution(e) {
182
- emits("update:zoom", Math.floor(view.getZoom() || 0));
183
- emits("changeResolution", e);
184
- }
185
- onMounted(() => {
186
- view.on("change:resolution", changeResolution);
187
- });
188
- onUnmounted(() => {
189
- view.un("change:resolution", changeResolution);
190
- });
191
- function changeCenter(e) {
192
- emits("update:center", view.getCenter() || [0, 0]);
193
- emits("changeCenter", e);
194
- }
195
- onMounted(() => {
196
- view.on("change:center", changeCenter);
197
- });
198
- onUnmounted(() => {
199
- view.un("change:center", changeCenter);
200
- });
201
- function movestart(e) {
202
- emits("movestart", e);
203
- }
204
- onMounted(() => {
205
- olMap.on("movestart", movestart);
206
- });
207
- onUnmounted(() => {
208
- olMap.un("movestart", movestart);
209
- });
210
- function moveend(e) {
211
- emits("moveend", e);
212
- }
213
- onMounted(() => {
214
- olMap.on("moveend", moveend);
215
- });
216
- onUnmounted(() => {
217
- olMap.un("moveend", moveend);
218
- });
219
- return (_ctx, _cache) => {
220
- return openBlock(), createElementBlock("div", {
221
- ref_key: "mapRef",
222
- ref: mapRef
223
- }, [renderSlot(_ctx.$slots, "default", {
224
- olMap: unref(olMap),
225
- mapRef: mapRef.value
226
- })], 512);
227
- };
228
- }
229
- });
230
- var ol_map_default = _sfc_main;
231
-
232
- //#endregion
233
- //#region composables/useContextmenu/index.ts
234
- function useContextmenu(mapRef, items) {
235
- const visible = ref(false);
236
- const position = ref({
237
- x: 0,
238
- y: 0
239
- });
240
- const feature = ref();
241
- const options = ref([]);
242
- const coordinate = ref();
243
- let currentMap;
244
- /** 递归过滤可见菜单并排序 */
245
- function filterAndSortMenu(menus, params$1) {
246
- const options$1 = [];
247
- menus.filter((item) => {
248
- const visible$1 = item.visible;
249
- if (typeof visible$1 === "function") return visible$1(params$1);
250
- return visible$1 ?? true;
251
- }).filter((item) => !item.children || item.children.length > 0).sort((a, b$1) => (a.order ?? 0) - (b$1.order ?? 0)).forEach((item) => {
252
- const icon = item.icon;
253
- const label = item.label;
254
- options$1.push({
255
- ...item,
256
- children: item.children ? filterAndSortMenu(item.children, params$1) : void 0,
257
- visible: true,
258
- action: () => {
259
- item.action?.(params$1);
260
- hide();
261
- },
262
- icon: typeof icon === "function" ? () => icon(params$1) : icon,
263
- label: typeof label === "function" ? () => label(params$1) : label,
264
- disabled: typeof item.disabled === "function" ? item.disabled(params$1) : item.disabled ?? false
265
- });
266
- });
267
- return options$1;
268
- }
269
- function show(evt) {
270
- evt.preventDefault();
271
- if (!currentMap) return;
272
- const _coordinate = currentMap.getEventCoordinate(evt);
273
- coordinate.value = _coordinate;
274
- const pixel = currentMap.getEventPixel(evt);
275
- let foundFeature;
276
- let foundLayer;
277
- currentMap.forEachFeatureAtPixel(pixel, (feature$1, layer) => {
278
- foundFeature = feature$1;
279
- foundLayer = layer;
280
- return true;
281
- });
282
- feature.value = foundFeature;
283
- const [x$2, y] = [evt.clientX, evt.clientY];
284
- position.value = {
285
- x: x$2,
286
- y
287
- };
288
- options.value = filterAndSortMenu(toValue(items), {
289
- map: currentMap,
290
- position: { ...position.value },
291
- coordinate: _coordinate,
292
- feature: foundFeature,
293
- layer: foundLayer
294
- });
295
- visible.value = true;
296
- }
297
- function hide() {
298
- visible.value = false;
299
- }
300
- /** 绑定 / 解绑事件 */
301
- function bindMapEvents(map) {
302
- if (!map) return;
303
- const el = map.getViewport();
304
- el.addEventListener("contextmenu", show);
305
- el.addEventListener("click", hide);
306
- }
307
- function unbindMapEvents(map) {
308
- if (!map) return;
309
- const el = map.getViewport();
310
- el.removeEventListener("contextmenu", show);
311
- el.removeEventListener("click", hide);
312
- }
313
- /** 监听 mapRef 变化 */
314
- watch(() => toValue(mapRef), (newMap, oldMap) => {
315
- if (oldMap !== newMap) {
316
- unbindMapEvents(oldMap);
317
- bindMapEvents(newMap);
318
- currentMap = newMap;
319
- }
320
- }, { immediate: true });
321
- onBeforeUnmount(() => {
322
- unbindMapEvents(currentMap);
323
- });
324
- return {
325
- visible: computed(() => visible.value),
326
- position: computed(() => position.value),
327
- feature: computed(() => feature.value),
328
- options: computed(() => options.value),
329
- coordinate: computed(() => coordinate.value),
330
- hide
331
- };
332
- }
333
-
334
- //#endregion
335
- //#region constants/distance.ts
336
- const ONE_NM = 1852;
337
-
338
- //#endregion
339
- //#region constants/projection.ts
340
- /** 3857坐标系 球面墨卡托投影坐标系 */
341
- const EPSG_3857 = "EPSG:3857";
342
- /** 4326坐标系 经纬度坐标系 等距圆柱投影 */
343
- const EPSG_4326 = "EPSG:4326";
344
- /** 3395坐标系 椭球墨卡托投影坐标系 */
345
- const EPSG_3395 = "EPSG:3395";
23
+ //#region constants/projection.ts
24
+ /** 3857坐标系 球面墨卡托投影坐标系 */
25
+ const EPSG_3857 = "EPSG:3857";
26
+ /** 4326坐标系 经纬度坐标系 等距圆柱投影 */
27
+ const EPSG_4326 = "EPSG:4326";
28
+ /** 3395坐标系 椭球墨卡托投影坐标系 */
29
+ const EPSG_3395 = "EPSG:3395";
346
30
 
347
31
  //#endregion
348
32
  //#region utils/distance/index.ts
@@ -354,6 +38,14 @@ function kmToNauticalMiles(km) {
354
38
  function nauticalMilesToKm(nauticalMiles) {
355
39
  return nauticalMiles * ONE_NM / 1e3;
356
40
  }
41
+ /** 弧度转角度 */
42
+ function rotationToAngle(rotation) {
43
+ return formatRotation(rotation) * 180 / Math.PI;
44
+ }
45
+ /** 角度转弧度 */
46
+ function angleToRotation(angle) {
47
+ return formatAngle(angle) * Math.PI / 180;
48
+ }
357
49
  /** 格式化Rotation */
358
50
  function formatRotation(rotation) {
359
51
  if (rotation < 0) return formatRotation(rotation + 2 * Math.PI);
@@ -9620,6 +9312,347 @@ function createCanvasLayer(olMap, refresh, options) {
9620
9312
  source
9621
9313
  };
9622
9314
  }
9315
+ function createHeatmapLayer(options) {
9316
+ const { sourceOptions, ...restOptions } = options || {};
9317
+ const source = createVectorSource(sourceOptions);
9318
+ return {
9319
+ layer: new HeatmapLayer({
9320
+ ...restOptions,
9321
+ source
9322
+ }),
9323
+ source
9324
+ };
9325
+ }
9326
+
9327
+ //#endregion
9328
+ //#region components/ol-map/props.ts
9329
+ const olMapInjectionKey = Symbol("olMapInjectionKey");
9330
+ function useOlMap() {
9331
+ return inject(olMapInjectionKey);
9332
+ }
9333
+
9334
+ //#endregion
9335
+ //#region components/ol-map/index.vue
9336
+ const _sfc_main = /* @__PURE__ */ defineComponent({
9337
+ name: "OlMap",
9338
+ __name: "index",
9339
+ props: {
9340
+ olMap: { default: () => new Map$1() },
9341
+ center: { default: () => [0, 0] },
9342
+ rotation: { default: 0 },
9343
+ zoom: { default: 2 },
9344
+ minZoom: { default: 2 },
9345
+ maxZoom: { default: 18 },
9346
+ constrainResolution: {
9347
+ type: Boolean,
9348
+ default: true
9349
+ },
9350
+ projection: {},
9351
+ extent: {},
9352
+ showZoom: {
9353
+ type: Boolean,
9354
+ default: false
9355
+ },
9356
+ showAttribution: {
9357
+ type: Boolean,
9358
+ default: false
9359
+ },
9360
+ showRotate: {
9361
+ type: Boolean,
9362
+ default: false
9363
+ },
9364
+ showFullScreen: {
9365
+ type: Boolean,
9366
+ default: false
9367
+ },
9368
+ showOverview: {
9369
+ type: Boolean,
9370
+ default: false
9371
+ },
9372
+ showScale: {
9373
+ type: Boolean,
9374
+ default: false
9375
+ },
9376
+ dragPan: {
9377
+ type: Boolean,
9378
+ default: true
9379
+ },
9380
+ mouseWheelZoom: {
9381
+ type: Boolean,
9382
+ default: true
9383
+ },
9384
+ doubleClickZoom: {
9385
+ type: Boolean,
9386
+ default: false
9387
+ },
9388
+ pinchRotate: { type: Boolean },
9389
+ pinchZoom: { type: Boolean },
9390
+ altShiftDragRotate: { type: Boolean }
9391
+ },
9392
+ emits: [
9393
+ "update:zoom",
9394
+ "update:center",
9395
+ "update:rotation",
9396
+ "changeResolution",
9397
+ "changeRotation",
9398
+ "changeCenter",
9399
+ "moveend",
9400
+ "movestart"
9401
+ ],
9402
+ setup(__props, { expose: __expose, emit: __emit }) {
9403
+ const props = __props;
9404
+ const emits = __emit;
9405
+ const mapRef = ref();
9406
+ const olMap = props.olMap;
9407
+ const view = new View({
9408
+ projection: props.projection,
9409
+ extent: props.extent
9410
+ });
9411
+ olMap.setView(view);
9412
+ view.setZoom(props.zoom);
9413
+ view.setCenter(props.center);
9414
+ watch(() => props.constrainResolution, (val) => {
9415
+ view.setConstrainResolution(val);
9416
+ }, { immediate: true });
9417
+ watch(() => props.minZoom, (val) => {
9418
+ if (val) view.setMinZoom(val);
9419
+ }, { immediate: true });
9420
+ watch(() => props.maxZoom, (val) => {
9421
+ if (val) view.setMaxZoom(val);
9422
+ }, { immediate: true });
9423
+ watch(mapRef, (val) => {
9424
+ if (val) olMap.setTarget(val);
9425
+ });
9426
+ __expose({ olMap });
9427
+ provide(olMapInjectionKey, olMap);
9428
+ const controls = olMap.getControls().getArray();
9429
+ const zoomControl = controls.find((control) => control instanceof Zoom) || new Zoom();
9430
+ const attributionControl = controls.find((control) => control instanceof Attribution) || new Attribution();
9431
+ const rotateControl = controls.find((control) => control instanceof Rotate) || new Rotate();
9432
+ const fullScreenControl = controls.find((control) => control instanceof FullScreen) || new FullScreen();
9433
+ const overviewMapControl = controls.find((control) => control instanceof OverviewMap) || new OverviewMap();
9434
+ const scaleControl = controls.find((control) => control instanceof ScaleLine) || new ScaleLine();
9435
+ watch(() => props.showZoom, (val) => {
9436
+ zoomControl.setMap(val ? olMap : null);
9437
+ }, { immediate: true });
9438
+ watch(() => props.showAttribution, (val) => {
9439
+ attributionControl.setMap(val ? olMap : null);
9440
+ }, { immediate: true });
9441
+ watch(() => props.showRotate, (val) => {
9442
+ rotateControl.setMap(val ? olMap : null);
9443
+ }, { immediate: true });
9444
+ watch(() => props.showFullScreen, (val) => {
9445
+ fullScreenControl.setMap(val ? olMap : null);
9446
+ }, { immediate: true });
9447
+ watch(() => props.showOverview, (val) => {
9448
+ overviewMapControl.setMap(val ? olMap : null);
9449
+ }, { immediate: true });
9450
+ watch(() => props.showScale, (val) => {
9451
+ scaleControl.setMap(val ? olMap : null);
9452
+ }, { immediate: true });
9453
+ const interactions = olMap.getInteractions().getArray();
9454
+ const dragPan = interactions.find((i$1) => i$1 instanceof DragPan) || new DragPan();
9455
+ const mouseWheelZoom = interactions.find((i$1) => i$1 instanceof MouseWheelZoom) || new MouseWheelZoom();
9456
+ const doubleClickZoom = interactions.find((i$1) => i$1 instanceof DoubleClickZoom) || new DoubleClickZoom();
9457
+ const pinchRotate = interactions.find((i$1) => i$1 instanceof PinchRotate) || new PinchRotate();
9458
+ const pinchZoom = interactions.find((i$1) => i$1 instanceof PinchZoom) || new PinchZoom();
9459
+ const altShiftDragRotate = interactions.find((i$1) => i$1 instanceof DragRotate) || new DragRotate();
9460
+ const keyboardPan = interactions.find((i$1) => i$1 instanceof KeyboardPan) || new KeyboardPan();
9461
+ const keyboardZoom = interactions.find((i$1) => i$1 instanceof KeyboardZoom) || new KeyboardZoom();
9462
+ olMap.removeInteraction(dragPan);
9463
+ olMap.addInteraction(dragPan);
9464
+ olMap.removeInteraction(mouseWheelZoom);
9465
+ olMap.addInteraction(mouseWheelZoom);
9466
+ olMap.removeInteraction(doubleClickZoom);
9467
+ olMap.addInteraction(doubleClickZoom);
9468
+ olMap.removeInteraction(pinchRotate);
9469
+ olMap.addInteraction(pinchRotate);
9470
+ olMap.removeInteraction(pinchZoom);
9471
+ olMap.addInteraction(pinchZoom);
9472
+ olMap.removeInteraction(altShiftDragRotate);
9473
+ olMap.addInteraction(altShiftDragRotate);
9474
+ olMap.removeInteraction(keyboardPan);
9475
+ olMap.removeInteraction(keyboardZoom);
9476
+ watch(() => props.dragPan, (val) => {
9477
+ dragPan.setActive(val);
9478
+ }, { immediate: true });
9479
+ watch(() => props.mouseWheelZoom, (val) => {
9480
+ mouseWheelZoom.setActive(val);
9481
+ }, { immediate: true });
9482
+ watch(() => props.doubleClickZoom, (val) => {
9483
+ doubleClickZoom.setActive(val);
9484
+ }, { immediate: true });
9485
+ watch(() => props.pinchRotate, (val) => {
9486
+ pinchRotate.setActive(val);
9487
+ }, { immediate: true });
9488
+ watch(() => props.pinchZoom, (val) => {
9489
+ pinchZoom.setActive(val);
9490
+ }, { immediate: true });
9491
+ watch(() => props.altShiftDragRotate, (val) => {
9492
+ altShiftDragRotate.setActive(val);
9493
+ }, { immediate: true });
9494
+ function changeResolution(e) {
9495
+ emits("update:zoom", Math.floor(view.getZoom() || 0));
9496
+ emits("changeResolution", e);
9497
+ }
9498
+ onMounted(() => {
9499
+ view.on("change:resolution", changeResolution);
9500
+ });
9501
+ onUnmounted(() => {
9502
+ view.un("change:resolution", changeResolution);
9503
+ });
9504
+ function changeCenter(e) {
9505
+ emits("update:center", view.getCenter() || [0, 0]);
9506
+ emits("changeCenter", e);
9507
+ }
9508
+ onMounted(() => {
9509
+ view.on("change:center", changeCenter);
9510
+ });
9511
+ onUnmounted(() => {
9512
+ view.un("change:center", changeCenter);
9513
+ });
9514
+ function movestart(e) {
9515
+ emits("movestart", e);
9516
+ }
9517
+ onMounted(() => {
9518
+ olMap.on("movestart", movestart);
9519
+ });
9520
+ onUnmounted(() => {
9521
+ olMap.un("movestart", movestart);
9522
+ });
9523
+ function moveend(e) {
9524
+ emits("moveend", e);
9525
+ }
9526
+ onMounted(() => {
9527
+ olMap.on("moveend", moveend);
9528
+ });
9529
+ onUnmounted(() => {
9530
+ olMap.un("moveend", moveend);
9531
+ });
9532
+ function changeRotation(e) {
9533
+ emits("update:rotation", formatRotation(e.target.getRotation() || 0));
9534
+ emits("changeRotation", e);
9535
+ }
9536
+ onMounted(() => {
9537
+ view.on("change:rotation", changeRotation);
9538
+ });
9539
+ onUnmounted(() => {
9540
+ view.un("change:rotation", changeRotation);
9541
+ });
9542
+ return (_ctx, _cache) => {
9543
+ return openBlock(), createElementBlock("div", {
9544
+ ref_key: "mapRef",
9545
+ ref: mapRef
9546
+ }, [renderSlot(_ctx.$slots, "default", {
9547
+ olMap: unref(olMap),
9548
+ mapRef: mapRef.value
9549
+ })], 512);
9550
+ };
9551
+ }
9552
+ });
9553
+ var ol_map_default = _sfc_main;
9554
+
9555
+ //#endregion
9556
+ //#region composables/useContextmenu/index.ts
9557
+ function useContextmenu(mapRef, items) {
9558
+ const visible = ref(false);
9559
+ const position = ref({
9560
+ x: 0,
9561
+ y: 0
9562
+ });
9563
+ const feature = ref();
9564
+ const options = ref([]);
9565
+ const coordinate = ref();
9566
+ let currentMap;
9567
+ /** 递归过滤可见菜单并排序 */
9568
+ function filterAndSortMenu(menus, params$1) {
9569
+ const options$1 = [];
9570
+ menus.filter((item) => {
9571
+ const visible$1 = item.visible;
9572
+ if (typeof visible$1 === "function") return visible$1(params$1);
9573
+ return visible$1 ?? true;
9574
+ }).filter((item) => !item.children || item.children.length > 0).sort((a, b$1) => (a.order ?? 0) - (b$1.order ?? 0)).forEach((item) => {
9575
+ const icon = item.icon;
9576
+ const label = item.label;
9577
+ options$1.push({
9578
+ ...item,
9579
+ children: item.children ? filterAndSortMenu(item.children, params$1) : void 0,
9580
+ visible: true,
9581
+ action: () => {
9582
+ item.action?.(params$1);
9583
+ hide();
9584
+ },
9585
+ icon: typeof icon === "function" ? () => icon(params$1) : icon,
9586
+ label: typeof label === "function" ? () => label(params$1) : label,
9587
+ disabled: typeof item.disabled === "function" ? item.disabled(params$1) : item.disabled ?? false
9588
+ });
9589
+ });
9590
+ return options$1;
9591
+ }
9592
+ function show(evt) {
9593
+ evt.preventDefault();
9594
+ if (!currentMap) return;
9595
+ const _coordinate = currentMap.getEventCoordinate(evt);
9596
+ coordinate.value = _coordinate;
9597
+ const pixel = currentMap.getEventPixel(evt);
9598
+ let foundFeature;
9599
+ let foundLayer;
9600
+ currentMap.forEachFeatureAtPixel(pixel, (feature$1, layer) => {
9601
+ foundFeature = feature$1;
9602
+ foundLayer = layer;
9603
+ return true;
9604
+ });
9605
+ feature.value = foundFeature;
9606
+ const [x$2, y] = [evt.clientX, evt.clientY];
9607
+ position.value = {
9608
+ x: x$2,
9609
+ y
9610
+ };
9611
+ options.value = filterAndSortMenu(toValue(items), {
9612
+ map: currentMap,
9613
+ position: { ...position.value },
9614
+ coordinate: _coordinate,
9615
+ feature: foundFeature,
9616
+ layer: foundLayer
9617
+ });
9618
+ visible.value = true;
9619
+ }
9620
+ function hide() {
9621
+ visible.value = false;
9622
+ }
9623
+ /** 绑定 / 解绑事件 */
9624
+ function bindMapEvents(map) {
9625
+ if (!map) return;
9626
+ const el = map.getViewport();
9627
+ el.addEventListener("contextmenu", show);
9628
+ el.addEventListener("click", hide);
9629
+ }
9630
+ function unbindMapEvents(map) {
9631
+ if (!map) return;
9632
+ const el = map.getViewport();
9633
+ el.removeEventListener("contextmenu", show);
9634
+ el.removeEventListener("click", hide);
9635
+ }
9636
+ /** 监听 mapRef 变化 */
9637
+ watch(() => toValue(mapRef), (newMap, oldMap) => {
9638
+ if (oldMap !== newMap) {
9639
+ unbindMapEvents(oldMap);
9640
+ bindMapEvents(newMap);
9641
+ currentMap = newMap;
9642
+ }
9643
+ }, { immediate: true });
9644
+ onBeforeUnmount(() => {
9645
+ unbindMapEvents(currentMap);
9646
+ });
9647
+ return {
9648
+ visible: computed(() => visible.value),
9649
+ position: computed(() => position.value),
9650
+ feature: computed(() => feature.value),
9651
+ options: computed(() => options.value),
9652
+ coordinate: computed(() => coordinate.value),
9653
+ hide
9654
+ };
9655
+ }
9623
9656
 
9624
9657
  //#endregion
9625
9658
  //#region composables/common/index.ts
@@ -10112,4 +10145,4 @@ function useSwitchBaseLayer(data) {
10112
10145
  }
10113
10146
 
10114
10147
  //#endregion
10115
- export { EPSG_3395, EPSG_3857, EPSG_3857ExtentToEPSG_4326, EPSG_3857ToEPSG_4326, EPSG_4326, EPSG_4326ExtentToEPSG_3857, EPSG_4326ToEPSG_3857, ONE_NM, ol_map_default as OlMap, createBingLayer, createCanvasLayer, createCircle, createCircleFeature, createCircleStyle, createFeature, createLineString, createLineStringFeature, createMultiLineString, createMultiLineStringFeature, createMultiPoint, createMultiPointFeature, createMultiPolygon, createMultiPolygonFeature, createOpenStreetMapLayer, createPMTilesLayer, createPoint, createPointFeature, createPolygon, createPolygonFeature, createStyle, createTextStyle, createTianDiTuLayer, createTianDiTuUrl, createTileGrid, createVectorLayer, createVectorSource, createWebGLVectorLayer, createXYZLayer, formatAngle, formatRotation, kmToNauticalMiles, nauticalMilesToKm, olMapInjectionKey, lib_default as proj4, registerEPSG_3395, useContextmenu, useDrawLineString, useDrawPolygon, useGraticule, useOlMap, usePointermove, useSwitchBaseLayer };
10148
+ export { EPSG_3395, EPSG_3857, EPSG_3857ExtentToEPSG_4326, EPSG_3857ToEPSG_4326, EPSG_4326, EPSG_4326ExtentToEPSG_3857, EPSG_4326ToEPSG_3857, ONE_NM, ol_map_default as OlMap, angleToRotation, createBingLayer, createCanvasLayer, createCircle, createCircleFeature, createCircleStyle, createFeature, createHeatmapLayer, createLineString, createLineStringFeature, createMultiLineString, createMultiLineStringFeature, createMultiPoint, createMultiPointFeature, createMultiPolygon, createMultiPolygonFeature, createOpenStreetMapLayer, createPMTilesLayer, createPoint, createPointFeature, createPolygon, createPolygonFeature, createStyle, createTextStyle, createTianDiTuLayer, createTianDiTuUrl, createTileGrid, createVectorLayer, createVectorSource, createWebGLVectorLayer, createXYZLayer, formatAngle, formatRotation, kmToNauticalMiles, nauticalMilesToKm, olMapInjectionKey, lib_default as proj4, registerEPSG_3395, rotationToAngle, useContextmenu, useDrawLineString, useDrawPolygon, useGraticule, useOlMap, usePointermove, useSwitchBaseLayer };