@movk/maplibre 1.0.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/LICENSE +21 -0
- package/README.en.md +192 -0
- package/README.md +191 -0
- package/dist/module.d.mts +20 -0
- package/dist/module.d.ts +20 -0
- package/dist/module.json +12 -0
- package/dist/module.mjs +63 -0
- package/dist/runtime/components/CustomLayer.d.vue.ts +24 -0
- package/dist/runtime/components/CustomLayer.vue +23 -0
- package/dist/runtime/components/CustomLayer.vue.d.ts +24 -0
- package/dist/runtime/components/Layer.d.vue.ts +75 -0
- package/dist/runtime/components/Layer.vue +112 -0
- package/dist/runtime/components/Layer.vue.d.ts +75 -0
- package/dist/runtime/components/LayerGroup.d.vue.ts +25 -0
- package/dist/runtime/components/LayerGroup.vue +16 -0
- package/dist/runtime/components/LayerGroup.vue.d.ts +25 -0
- package/dist/runtime/components/LottieMarker.d.vue.ts +50 -0
- package/dist/runtime/components/LottieMarker.vue +31 -0
- package/dist/runtime/components/LottieMarker.vue.d.ts +50 -0
- package/dist/runtime/components/Map.d.vue.ts +84 -0
- package/dist/runtime/components/Map.vue +134 -0
- package/dist/runtime/components/Map.vue.d.ts +84 -0
- package/dist/runtime/components/Marker.d.vue.ts +54 -0
- package/dist/runtime/components/Marker.vue +86 -0
- package/dist/runtime/components/Marker.vue.d.ts +54 -0
- package/dist/runtime/components/Popup.d.vue.ts +30 -0
- package/dist/runtime/components/Popup.vue +33 -0
- package/dist/runtime/components/Popup.vue.d.ts +30 -0
- package/dist/runtime/components/Source.d.vue.ts +23 -0
- package/dist/runtime/components/Source.vue +44 -0
- package/dist/runtime/components/Source.vue.d.ts +23 -0
- package/dist/runtime/components/Tooltip.d.vue.ts +45 -0
- package/dist/runtime/components/Tooltip.vue +106 -0
- package/dist/runtime/components/Tooltip.vue.d.ts +45 -0
- package/dist/runtime/components/buffers/BufferCircle.d.vue.ts +27 -0
- package/dist/runtime/components/buffers/BufferCircle.vue +30 -0
- package/dist/runtime/components/buffers/BufferCircle.vue.d.ts +27 -0
- package/dist/runtime/components/buffers/BufferEllipse.d.vue.ts +35 -0
- package/dist/runtime/components/buffers/BufferEllipse.vue +36 -0
- package/dist/runtime/components/buffers/BufferEllipse.vue.d.ts +35 -0
- package/dist/runtime/components/buffers/BufferLine.d.vue.ts +21 -0
- package/dist/runtime/components/buffers/BufferLine.vue +40 -0
- package/dist/runtime/components/buffers/BufferLine.vue.d.ts +21 -0
- package/dist/runtime/components/buffers/BufferPolygon.d.vue.ts +21 -0
- package/dist/runtime/components/buffers/BufferPolygon.vue +40 -0
- package/dist/runtime/components/buffers/BufferPolygon.vue.d.ts +21 -0
- package/dist/runtime/components/buffers/BufferSector.d.vue.ts +31 -0
- package/dist/runtime/components/buffers/BufferSector.vue +35 -0
- package/dist/runtime/components/buffers/BufferSector.vue.d.ts +31 -0
- package/dist/runtime/components/controls/AttributionControl.d.vue.ts +24 -0
- package/dist/runtime/components/controls/AttributionControl.vue +18 -0
- package/dist/runtime/components/controls/AttributionControl.vue.d.ts +24 -0
- package/dist/runtime/components/controls/FullscreenControl.d.vue.ts +24 -0
- package/dist/runtime/components/controls/FullscreenControl.vue +18 -0
- package/dist/runtime/components/controls/FullscreenControl.vue.d.ts +24 -0
- package/dist/runtime/components/controls/GeolocateControl.d.vue.ts +24 -0
- package/dist/runtime/components/controls/GeolocateControl.vue +18 -0
- package/dist/runtime/components/controls/GeolocateControl.vue.d.ts +24 -0
- package/dist/runtime/components/controls/NavigationControl.d.vue.ts +24 -0
- package/dist/runtime/components/controls/NavigationControl.vue +18 -0
- package/dist/runtime/components/controls/NavigationControl.vue.d.ts +24 -0
- package/dist/runtime/components/controls/ScaleControl.d.vue.ts +24 -0
- package/dist/runtime/components/controls/ScaleControl.vue +18 -0
- package/dist/runtime/components/controls/ScaleControl.vue.d.ts +24 -0
- package/dist/runtime/components/effects/AnimatedImage.d.vue.ts +28 -0
- package/dist/runtime/components/effects/AnimatedImage.vue +50 -0
- package/dist/runtime/components/effects/AnimatedImage.vue.d.ts +28 -0
- package/dist/runtime/components/effects/DiffusionCircle.d.vue.ts +44 -0
- package/dist/runtime/components/effects/DiffusionCircle.vue +47 -0
- package/dist/runtime/components/effects/DiffusionCircle.vue.d.ts +44 -0
- package/dist/runtime/components/effects/FlowBuilding.d.vue.ts +53 -0
- package/dist/runtime/components/effects/FlowBuilding.vue +64 -0
- package/dist/runtime/components/effects/FlowBuilding.vue.d.ts +53 -0
- package/dist/runtime/components/effects/GlowCircle.d.vue.ts +44 -0
- package/dist/runtime/components/effects/GlowCircle.vue +42 -0
- package/dist/runtime/components/effects/GlowCircle.vue.d.ts +44 -0
- package/dist/runtime/components/effects/GradientBuilding.d.vue.ts +25 -0
- package/dist/runtime/components/effects/GradientBuilding.vue +37 -0
- package/dist/runtime/components/effects/GradientBuilding.vue.d.ts +25 -0
- package/dist/runtime/components/effects/Migration.d.vue.ts +50 -0
- package/dist/runtime/components/effects/Migration.vue +90 -0
- package/dist/runtime/components/effects/Migration.vue.d.ts +50 -0
- package/dist/runtime/components/effects/Radar.d.vue.ts +32 -0
- package/dist/runtime/components/effects/Radar.vue +49 -0
- package/dist/runtime/components/effects/Radar.vue.d.ts +32 -0
- package/dist/runtime/components/effects/SpriteImage.d.vue.ts +41 -0
- package/dist/runtime/components/effects/SpriteImage.vue +67 -0
- package/dist/runtime/components/effects/SpriteImage.vue.d.ts +41 -0
- package/dist/runtime/components/effects/TextureBuilding.d.vue.ts +25 -0
- package/dist/runtime/components/effects/TextureBuilding.vue +39 -0
- package/dist/runtime/components/effects/TextureBuilding.vue.d.ts +25 -0
- package/dist/runtime/components/effects/Trail.d.vue.ts +44 -0
- package/dist/runtime/components/effects/Trail.vue +61 -0
- package/dist/runtime/components/effects/Trail.vue.d.ts +44 -0
- package/dist/runtime/components/effects/WaveCircle.d.vue.ts +44 -0
- package/dist/runtime/components/effects/WaveCircle.vue +55 -0
- package/dist/runtime/components/effects/WaveCircle.vue.d.ts +44 -0
- package/dist/runtime/components/effects/WindowBuilding.d.vue.ts +53 -0
- package/dist/runtime/components/effects/WindowBuilding.vue +61 -0
- package/dist/runtime/components/effects/WindowBuilding.vue.d.ts +53 -0
- package/dist/runtime/components/environment/Sky.d.vue.ts +21 -0
- package/dist/runtime/components/environment/Sky.vue +15 -0
- package/dist/runtime/components/environment/Sky.vue.d.ts +21 -0
- package/dist/runtime/components/environment/Temperature.d.vue.ts +47 -0
- package/dist/runtime/components/environment/Temperature.vue +41 -0
- package/dist/runtime/components/environment/Temperature.vue.d.ts +47 -0
- package/dist/runtime/components/environment/Terrain.d.vue.ts +34 -0
- package/dist/runtime/components/environment/Terrain.vue +47 -0
- package/dist/runtime/components/environment/Terrain.vue.d.ts +34 -0
- package/dist/runtime/components/extensions/DrawControl.d.vue.ts +0 -0
- package/dist/runtime/components/extensions/DrawControl.vue +168 -0
- package/dist/runtime/components/extensions/DrawControl.vue.d.ts +0 -0
- package/dist/runtime/components/extensions/TiandituLayer.d.vue.ts +20 -0
- package/dist/runtime/components/extensions/TiandituLayer.vue +26 -0
- package/dist/runtime/components/extensions/TiandituLayer.vue.d.ts +20 -0
- package/dist/runtime/components/extensions/WmsLayer.d.vue.ts +50 -0
- package/dist/runtime/components/extensions/WmsLayer.vue +39 -0
- package/dist/runtime/components/extensions/WmsLayer.vue.d.ts +50 -0
- package/dist/runtime/components/extensions/WmtsLayer.d.vue.ts +42 -0
- package/dist/runtime/components/extensions/WmtsLayer.vue +37 -0
- package/dist/runtime/components/extensions/WmtsLayer.vue.d.ts +42 -0
- package/dist/runtime/components/layers/BuildingLayer.d.vue.ts +28 -0
- package/dist/runtime/components/layers/BuildingLayer.vue +41 -0
- package/dist/runtime/components/layers/BuildingLayer.vue.d.ts +28 -0
- package/dist/runtime/components/layers/ClusterLayer.d.vue.ts +55 -0
- package/dist/runtime/components/layers/ClusterLayer.vue +86 -0
- package/dist/runtime/components/layers/ClusterLayer.vue.d.ts +55 -0
- package/dist/runtime/components/layers/ImageLayer.d.vue.ts +21 -0
- package/dist/runtime/components/layers/ImageLayer.vue +25 -0
- package/dist/runtime/components/layers/ImageLayer.vue.d.ts +21 -0
- package/dist/runtime/components/layers/RasterLayer.d.vue.ts +35 -0
- package/dist/runtime/components/layers/RasterLayer.vue +34 -0
- package/dist/runtime/components/layers/RasterLayer.vue.d.ts +35 -0
- package/dist/runtime/components/layers/VideoLayer.d.vue.ts +28 -0
- package/dist/runtime/components/layers/VideoLayer.vue +38 -0
- package/dist/runtime/components/layers/VideoLayer.vue.d.ts +28 -0
- package/dist/runtime/composables/defineMaplibreControl.d.ts +3 -0
- package/dist/runtime/composables/defineMaplibreControl.js +6 -0
- package/dist/runtime/composables/useFeatureState.d.ts +35 -0
- package/dist/runtime/composables/useFeatureState.js +76 -0
- package/dist/runtime/composables/useFrameIcon.d.ts +17 -0
- package/dist/runtime/composables/useFrameIcon.js +36 -0
- package/dist/runtime/composables/useMap.d.ts +3 -0
- package/dist/runtime/composables/useMap.js +9 -0
- package/dist/runtime/composables/useMapAnimation.d.ts +21 -0
- package/dist/runtime/composables/useMapAnimation.js +13 -0
- package/dist/runtime/composables/useMapExport.d.ts +34 -0
- package/dist/runtime/composables/useMapExport.js +35 -0
- package/dist/runtime/composables/useMaplibre.d.ts +6 -0
- package/dist/runtime/composables/useMaplibre.js +4 -0
- package/dist/runtime/composables/useMaplibreCamera.d.ts +15 -0
- package/dist/runtime/composables/useMaplibreCamera.js +32 -0
- package/dist/runtime/composables/useMaplibreDraw.d.ts +10 -0
- package/dist/runtime/composables/useMaplibreDraw.js +34 -0
- package/dist/runtime/composables/useMaplibreImage.d.ts +19 -0
- package/dist/runtime/composables/useMaplibreImage.js +33 -0
- package/dist/runtime/composables/useMeasure.d.ts +25 -0
- package/dist/runtime/composables/useMeasure.js +173 -0
- package/dist/runtime/domains/map/config.d.ts +7 -0
- package/dist/runtime/domains/map/config.js +13 -0
- package/dist/runtime/domains/map/context.d.ts +13 -0
- package/dist/runtime/domains/map/context.js +51 -0
- package/dist/runtime/domains/map/control.d.ts +4 -0
- package/dist/runtime/domains/map/control.js +28 -0
- package/dist/runtime/domains/map/create-map.d.ts +3 -0
- package/dist/runtime/domains/map/create-map.js +21 -0
- package/dist/runtime/domains/map/draw-context.d.ts +26 -0
- package/dist/runtime/domains/map/draw-context.js +73 -0
- package/dist/runtime/domains/map/draw-registry.d.ts +5 -0
- package/dist/runtime/domains/map/draw-registry.js +15 -0
- package/dist/runtime/domains/map/draw-toolbar.d.ts +15 -0
- package/dist/runtime/domains/map/draw-toolbar.js +52 -0
- package/dist/runtime/domains/map/draw.d.ts +4 -0
- package/dist/runtime/domains/map/draw.js +1 -0
- package/dist/runtime/domains/map/layer-group.d.ts +9 -0
- package/dist/runtime/domains/map/layer-group.js +1 -0
- package/dist/runtime/domains/map/registry.d.ts +4 -0
- package/dist/runtime/domains/map/registry.js +10 -0
- package/dist/runtime/domains/map/resolve.d.ts +7 -0
- package/dist/runtime/domains/map/resolve.js +7 -0
- package/dist/runtime/domains/map/style-effect.d.ts +6 -0
- package/dist/runtime/domains/map/style-effect.js +21 -0
- package/dist/runtime/draw-modes/index.d.ts +16 -0
- package/dist/runtime/draw-modes/index.js +32 -0
- package/dist/runtime/index.css +1 -0
- package/dist/runtime/plugins/config.d.ts +2 -0
- package/dist/runtime/plugins/config.js +6 -0
- package/dist/runtime/types/draw.d.ts +30 -0
- package/dist/runtime/types/draw.js +0 -0
- package/dist/runtime/types/index.d.ts +3 -0
- package/dist/runtime/types/index.js +0 -0
- package/dist/runtime/types/map.d.ts +45 -0
- package/dist/runtime/types/map.js +0 -0
- package/dist/runtime/types/tianditu.d.ts +247 -0
- package/dist/runtime/types/tianditu.js +0 -0
- package/dist/runtime/utils/animated-image.d.ts +13 -0
- package/dist/runtime/utils/animated-image.js +47 -0
- package/dist/runtime/utils/buffer.d.ts +24 -0
- package/dist/runtime/utils/buffer.js +13 -0
- package/dist/runtime/utils/building-effects.d.ts +73 -0
- package/dist/runtime/utils/building-effects.js +50 -0
- package/dist/runtime/utils/building.d.ts +53 -0
- package/dist/runtime/utils/building.js +26 -0
- package/dist/runtime/utils/cluster.d.ts +24 -0
- package/dist/runtime/utils/cluster.js +42 -0
- package/dist/runtime/utils/coordinate.d.ts +12 -0
- package/dist/runtime/utils/coordinate.js +44 -0
- package/dist/runtime/utils/draw-theme.d.ts +47 -0
- package/dist/runtime/utils/draw-theme.js +39 -0
- package/dist/runtime/utils/effects.d.ts +34 -0
- package/dist/runtime/utils/effects.js +78 -0
- package/dist/runtime/utils/events.d.ts +6 -0
- package/dist/runtime/utils/events.js +20 -0
- package/dist/runtime/utils/frame-icon.d.ts +27 -0
- package/dist/runtime/utils/frame-icon.js +45 -0
- package/dist/runtime/utils/geometry.d.ts +5 -0
- package/dist/runtime/utils/geometry.js +41 -0
- package/dist/runtime/utils/heatmap.d.ts +36 -0
- package/dist/runtime/utils/heatmap.js +30 -0
- package/dist/runtime/utils/layer.d.ts +13 -0
- package/dist/runtime/utils/layer.js +17 -0
- package/dist/runtime/utils/logger.d.ts +2 -0
- package/dist/runtime/utils/logger.js +2 -0
- package/dist/runtime/utils/measure.d.ts +4 -0
- package/dist/runtime/utils/measure.js +8 -0
- package/dist/runtime/utils/sprite.d.ts +31 -0
- package/dist/runtime/utils/sprite.js +23 -0
- package/dist/runtime/utils/tianditu-administrative.d.ts +3 -0
- package/dist/runtime/utils/tianditu-administrative.js +48 -0
- package/dist/runtime/utils/tianditu-client.d.ts +30 -0
- package/dist/runtime/utils/tianditu-client.js +17 -0
- package/dist/runtime/utils/tianditu-geocoder.d.ts +5 -0
- package/dist/runtime/utils/tianditu-geocoder.js +37 -0
- package/dist/runtime/utils/tianditu-request.d.ts +20 -0
- package/dist/runtime/utils/tianditu-request.js +42 -0
- package/dist/runtime/utils/tianditu-route.d.ts +3 -0
- package/dist/runtime/utils/tianditu-route.js +40 -0
- package/dist/runtime/utils/tianditu-search.d.ts +15 -0
- package/dist/runtime/utils/tianditu-search.js +183 -0
- package/dist/runtime/utils/tianditu.d.ts +21 -0
- package/dist/runtime/utils/tianditu.js +26 -0
- package/dist/runtime/utils/wms.d.ts +43 -0
- package/dist/runtime/utils/wms.js +30 -0
- package/dist/runtime/utils/wmts.d.ts +35 -0
- package/dist/runtime/utils/wmts.js +29 -0
- package/dist/types.d.mts +5 -0
- package/dist/unplugin.d.mts +30 -0
- package/dist/unplugin.d.ts +30 -0
- package/dist/unplugin.mjs +53 -0
- package/dist/vite.d.mts +7 -0
- package/dist/vite.d.ts +7 -0
- package/dist/vite.mjs +11 -0
- package/dist/vue-plugin.d.mts +9 -0
- package/dist/vue-plugin.d.ts +9 -0
- package/dist/vue-plugin.mjs +9 -0
- package/package.json +174 -0
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { onMounted, onUnmounted, provide, useId, useTemplateRef, watch } from "vue";
|
|
3
|
+
import { useResizeObserver } from "@vueuse/core";
|
|
4
|
+
import { omitUndefined } from "@movk/core";
|
|
5
|
+
import { LngLat } from "maplibre-gl";
|
|
6
|
+
import { createMaplibreContext, MaplibreContextKey } from "../domains/map/context";
|
|
7
|
+
import { createMaplibreGl } from "../domains/map/create-map";
|
|
8
|
+
import { getMaplibreConfig } from "../domains/map/config";
|
|
9
|
+
import { getMapContext, registerMap, unregisterMap } from "../domains/map/registry";
|
|
10
|
+
import { bindMapEvents } from "../utils/events";
|
|
11
|
+
defineOptions({ inheritAttrs: false });
|
|
12
|
+
function blankStyle() {
|
|
13
|
+
const { glyphs } = getMaplibreConfig();
|
|
14
|
+
return { version: 8, ...glyphs ? { glyphs } : {}, sources: {}, layers: [] };
|
|
15
|
+
}
|
|
16
|
+
const props = defineProps({
|
|
17
|
+
mapId: { type: String, required: false },
|
|
18
|
+
options: { type: Object, required: false },
|
|
19
|
+
persistent: { type: Boolean, required: false, default: false }
|
|
20
|
+
});
|
|
21
|
+
const emit = defineEmits(["load", "idle", "error", "click", "dblclick", "contextmenu", "mousemove", "mousedown", "mouseup", "movestart", "moveend", "zoomstart", "zoomend", "rotateend", "pitchend", "dragend", "styledata", "sourcedata"]);
|
|
22
|
+
const FORWARDED_EVENTS = [
|
|
23
|
+
"error",
|
|
24
|
+
"click",
|
|
25
|
+
"dblclick",
|
|
26
|
+
"contextmenu",
|
|
27
|
+
"mousemove",
|
|
28
|
+
"mousedown",
|
|
29
|
+
"mouseup",
|
|
30
|
+
"movestart",
|
|
31
|
+
"moveend",
|
|
32
|
+
"zoomstart",
|
|
33
|
+
"zoomend",
|
|
34
|
+
"rotateend",
|
|
35
|
+
"pitchend",
|
|
36
|
+
"dragend",
|
|
37
|
+
"styledata",
|
|
38
|
+
"sourcedata"
|
|
39
|
+
];
|
|
40
|
+
const center = defineModel("center", { type: [Object, Array] });
|
|
41
|
+
const zoom = defineModel("zoom", { type: Number });
|
|
42
|
+
const bearing = defineModel("bearing", { type: Number });
|
|
43
|
+
const pitch = defineModel("pitch", { type: Number });
|
|
44
|
+
const container = useTemplateRef("container");
|
|
45
|
+
const mapId = props.mapId ?? `movk-maplibre-${useId()}`;
|
|
46
|
+
const existing = props.mapId ? getMapContext(mapId) : void 0;
|
|
47
|
+
const created = existing ? void 0 : createMaplibreContext(mapId);
|
|
48
|
+
const context = existing ?? created.context;
|
|
49
|
+
provide(MaplibreContextKey, context);
|
|
50
|
+
if (created && props.mapId) registerMap(context);
|
|
51
|
+
function syncModelsFromMap(map) {
|
|
52
|
+
const c = map.getCenter();
|
|
53
|
+
center.value = [c.lng, c.lat];
|
|
54
|
+
zoom.value = map.getZoom();
|
|
55
|
+
bearing.value = map.getBearing();
|
|
56
|
+
pitch.value = map.getPitch();
|
|
57
|
+
}
|
|
58
|
+
let runtimeBound = false;
|
|
59
|
+
function bindRuntime(map) {
|
|
60
|
+
if (runtimeBound) return;
|
|
61
|
+
runtimeBound = true;
|
|
62
|
+
bindMapEvents(map, FORWARDED_EVENTS, (type, event) => emit(type, event));
|
|
63
|
+
map.on("load", () => emit("load", map));
|
|
64
|
+
map.on("idle", () => emit("idle", map));
|
|
65
|
+
map.on("moveend", () => syncModelsFromMap(map));
|
|
66
|
+
useResizeObserver(container, () => map.resize());
|
|
67
|
+
}
|
|
68
|
+
onMounted(() => {
|
|
69
|
+
if (existing?.map.value) {
|
|
70
|
+
bindRuntime(existing.map.value);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (!created || !container.value) return;
|
|
74
|
+
const map = createMaplibreGl(omitUndefined({
|
|
75
|
+
...props.options,
|
|
76
|
+
style: props.options?.style ?? blankStyle(),
|
|
77
|
+
center: center.value ?? props.options?.center,
|
|
78
|
+
zoom: zoom.value ?? props.options?.zoom,
|
|
79
|
+
bearing: bearing.value ?? props.options?.bearing,
|
|
80
|
+
pitch: pitch.value ?? props.options?.pitch,
|
|
81
|
+
container: container.value
|
|
82
|
+
}));
|
|
83
|
+
created.attach(map);
|
|
84
|
+
bindRuntime(map);
|
|
85
|
+
});
|
|
86
|
+
watch(center, (value) => {
|
|
87
|
+
const map = context.map.value;
|
|
88
|
+
if (!map || !value) return;
|
|
89
|
+
const next = LngLat.convert(value);
|
|
90
|
+
const cur = map.getCenter();
|
|
91
|
+
if (Math.abs(cur.lng - next.lng) < 1e-9 && Math.abs(cur.lat - next.lat) < 1e-9) return;
|
|
92
|
+
map.setCenter(value);
|
|
93
|
+
});
|
|
94
|
+
watch(zoom, (value) => {
|
|
95
|
+
const map = context.map.value;
|
|
96
|
+
if (!map || value === void 0 || map.getZoom() === value) return;
|
|
97
|
+
map.setZoom(value);
|
|
98
|
+
});
|
|
99
|
+
watch(bearing, (value) => {
|
|
100
|
+
const map = context.map.value;
|
|
101
|
+
if (!map || value === void 0 || map.getBearing() === value) return;
|
|
102
|
+
map.setBearing(value);
|
|
103
|
+
});
|
|
104
|
+
watch(pitch, (value) => {
|
|
105
|
+
const map = context.map.value;
|
|
106
|
+
if (!map || value === void 0 || map.getPitch() === value) return;
|
|
107
|
+
map.setPitch(value);
|
|
108
|
+
});
|
|
109
|
+
watch(() => props.options?.style, (style) => {
|
|
110
|
+
const map = context.map.value;
|
|
111
|
+
if (!map || !style) return;
|
|
112
|
+
map.setStyle(style, { diff: false });
|
|
113
|
+
});
|
|
114
|
+
onUnmounted(() => {
|
|
115
|
+
if (props.persistent) return;
|
|
116
|
+
context.map.value?.remove();
|
|
117
|
+
unregisterMap(context.id);
|
|
118
|
+
});
|
|
119
|
+
defineExpose({
|
|
120
|
+
/** 当前地图上下文 */
|
|
121
|
+
context: () => context
|
|
122
|
+
});
|
|
123
|
+
</script>
|
|
124
|
+
|
|
125
|
+
<template>
|
|
126
|
+
<div class="movk-maplibre" v-bind="$attrs">
|
|
127
|
+
<div ref="container" class="movk-maplibre__container" />
|
|
128
|
+
<slot />
|
|
129
|
+
</div>
|
|
130
|
+
</template>
|
|
131
|
+
|
|
132
|
+
<style>
|
|
133
|
+
@layer components{:where(.movk-maplibre){height:100%;position:relative;width:100%}}.movk-maplibre>.movk-maplibre__container{inset:0;position:absolute}
|
|
134
|
+
</style>
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { LngLatLike, Map as MaplibreMap } from 'maplibre-gl';
|
|
2
|
+
import type { MaplibreMapOptions } from '../types';
|
|
3
|
+
type __VLS_Props = {
|
|
4
|
+
/** 地图 id;省略时自动生成。提供后可经 useMaplibre(id) 外部访问 */
|
|
5
|
+
mapId?: string;
|
|
6
|
+
/**
|
|
7
|
+
* maplibre-gl Map 初始化选项(container 由组件接管);缺省 style 时使用空白样式
|
|
8
|
+
* @see https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/MapOptions/
|
|
9
|
+
*/
|
|
10
|
+
options?: MaplibreMapOptions;
|
|
11
|
+
/** 卸载时不销毁实例,配合 keepalive / `<keep-alive>` 跨路由复用 */
|
|
12
|
+
persistent?: boolean;
|
|
13
|
+
};
|
|
14
|
+
type __VLS_ModelProps = {
|
|
15
|
+
'center'?: LngLatLike;
|
|
16
|
+
'zoom'?: number;
|
|
17
|
+
'bearing'?: number;
|
|
18
|
+
'pitch'?: number;
|
|
19
|
+
};
|
|
20
|
+
type __VLS_PublicProps = __VLS_Props & __VLS_ModelProps;
|
|
21
|
+
declare var __VLS_1: {};
|
|
22
|
+
type __VLS_Slots = {} & {
|
|
23
|
+
default?: (props: typeof __VLS_1) => any;
|
|
24
|
+
};
|
|
25
|
+
declare const __VLS_base: import("vue").DefineComponent<__VLS_PublicProps, {
|
|
26
|
+
/** 当前地图上下文 */
|
|
27
|
+
context: () => import("../types").MaplibreContext;
|
|
28
|
+
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
29
|
+
click: (event: import("maplibre-gl").MapMouseEvent) => any;
|
|
30
|
+
load: (map: MaplibreMap) => any;
|
|
31
|
+
error: (event: import("maplibre-gl").ErrorEvent) => any;
|
|
32
|
+
idle: (map: MaplibreMap) => any;
|
|
33
|
+
sourcedata: (event: import("maplibre-gl").MapSourceDataEvent) => any;
|
|
34
|
+
styledata: (event: import("maplibre-gl").MapStyleDataEvent) => any;
|
|
35
|
+
contextmenu: (event: import("maplibre-gl").MapMouseEvent) => any;
|
|
36
|
+
dblclick: (event: import("maplibre-gl").MapMouseEvent) => any;
|
|
37
|
+
mousemove: (event: import("maplibre-gl").MapMouseEvent) => any;
|
|
38
|
+
mouseup: (event: import("maplibre-gl").MapMouseEvent) => any;
|
|
39
|
+
mousedown: (event: import("maplibre-gl").MapMouseEvent) => any;
|
|
40
|
+
movestart: (event: import("maplibre-gl").MapMovementEvent) => any;
|
|
41
|
+
moveend: (event: import("maplibre-gl").MapMovementEvent) => any;
|
|
42
|
+
zoomstart: (event: import("maplibre-gl").MapMovementEvent) => any;
|
|
43
|
+
zoomend: (event: import("maplibre-gl").MapMovementEvent) => any;
|
|
44
|
+
rotateend: (event: import("maplibre-gl").MapMovementEvent) => any;
|
|
45
|
+
dragend: (event: import("maplibre-gl").MapMovementEvent) => any;
|
|
46
|
+
pitchend: (event: import("maplibre-gl").MapMovementEvent) => any;
|
|
47
|
+
"update:center": (value: LngLatLike | undefined) => any;
|
|
48
|
+
"update:zoom": (value: number | undefined) => any;
|
|
49
|
+
"update:bearing": (value: number | undefined) => any;
|
|
50
|
+
"update:pitch": (value: number | undefined) => any;
|
|
51
|
+
}, string, import("vue").PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
|
|
52
|
+
onClick?: ((event: import("maplibre-gl").MapMouseEvent) => any) | undefined;
|
|
53
|
+
onLoad?: ((map: MaplibreMap) => any) | undefined;
|
|
54
|
+
onError?: ((event: import("maplibre-gl").ErrorEvent) => any) | undefined;
|
|
55
|
+
onIdle?: ((map: MaplibreMap) => any) | undefined;
|
|
56
|
+
onSourcedata?: ((event: import("maplibre-gl").MapSourceDataEvent) => any) | undefined;
|
|
57
|
+
onStyledata?: ((event: import("maplibre-gl").MapStyleDataEvent) => any) | undefined;
|
|
58
|
+
onContextmenu?: ((event: import("maplibre-gl").MapMouseEvent) => any) | undefined;
|
|
59
|
+
onDblclick?: ((event: import("maplibre-gl").MapMouseEvent) => any) | undefined;
|
|
60
|
+
onMousemove?: ((event: import("maplibre-gl").MapMouseEvent) => any) | undefined;
|
|
61
|
+
onMouseup?: ((event: import("maplibre-gl").MapMouseEvent) => any) | undefined;
|
|
62
|
+
onMousedown?: ((event: import("maplibre-gl").MapMouseEvent) => any) | undefined;
|
|
63
|
+
onMovestart?: ((event: import("maplibre-gl").MapMovementEvent) => any) | undefined;
|
|
64
|
+
onMoveend?: ((event: import("maplibre-gl").MapMovementEvent) => any) | undefined;
|
|
65
|
+
onZoomstart?: ((event: import("maplibre-gl").MapMovementEvent) => any) | undefined;
|
|
66
|
+
onZoomend?: ((event: import("maplibre-gl").MapMovementEvent) => any) | undefined;
|
|
67
|
+
onRotateend?: ((event: import("maplibre-gl").MapMovementEvent) => any) | undefined;
|
|
68
|
+
onDragend?: ((event: import("maplibre-gl").MapMovementEvent) => any) | undefined;
|
|
69
|
+
onPitchend?: ((event: import("maplibre-gl").MapMovementEvent) => any) | undefined;
|
|
70
|
+
"onUpdate:center"?: ((value: LngLatLike | undefined) => any) | undefined;
|
|
71
|
+
"onUpdate:zoom"?: ((value: number | undefined) => any) | undefined;
|
|
72
|
+
"onUpdate:bearing"?: ((value: number | undefined) => any) | undefined;
|
|
73
|
+
"onUpdate:pitch"?: ((value: number | undefined) => any) | undefined;
|
|
74
|
+
}>, {
|
|
75
|
+
persistent: boolean;
|
|
76
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
77
|
+
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
78
|
+
declare const _default: typeof __VLS_export;
|
|
79
|
+
export default _default;
|
|
80
|
+
type __VLS_WithSlots<T, S> = T & {
|
|
81
|
+
new (): {
|
|
82
|
+
$slots: S;
|
|
83
|
+
};
|
|
84
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Marker } from 'maplibre-gl';
|
|
2
|
+
import type { LngLatLike, MarkerOptions, PopupOptions } from 'maplibre-gl';
|
|
3
|
+
import type { PopupTrigger } from '../types';
|
|
4
|
+
type __VLS_Props = {
|
|
5
|
+
/**
|
|
6
|
+
* 标记选项;element 由默认插槽提供,无需在此传入
|
|
7
|
+
* @see https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/MarkerOptions/
|
|
8
|
+
*/
|
|
9
|
+
options?: Omit<MarkerOptions, 'element'>;
|
|
10
|
+
/**
|
|
11
|
+
* 弹窗选项,仅在提供 #popup 插槽时生效
|
|
12
|
+
* @see https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/PopupOptions/
|
|
13
|
+
*/
|
|
14
|
+
popupOptions?: PopupOptions;
|
|
15
|
+
/**
|
|
16
|
+
* #popup 插槽的触发时机;'none' 表示不绑定监听,完全由 v-model:open 受控
|
|
17
|
+
* @defaultValue 'click'
|
|
18
|
+
*/
|
|
19
|
+
trigger?: PopupTrigger;
|
|
20
|
+
};
|
|
21
|
+
declare function closePopup(): void;
|
|
22
|
+
type __VLS_ModelProps = {
|
|
23
|
+
'lnglat': LngLatLike;
|
|
24
|
+
/** 弹窗开合状态;初始传 true 即默认展开 */
|
|
25
|
+
'open'?: boolean;
|
|
26
|
+
};
|
|
27
|
+
type __VLS_PublicProps = __VLS_Props & __VLS_ModelProps;
|
|
28
|
+
declare var __VLS_1: {}, __VLS_11: {
|
|
29
|
+
close: typeof closePopup;
|
|
30
|
+
};
|
|
31
|
+
type __VLS_Slots = {} & {
|
|
32
|
+
default?: (props: typeof __VLS_1) => any;
|
|
33
|
+
} & {
|
|
34
|
+
popup?: (props: typeof __VLS_11) => any;
|
|
35
|
+
};
|
|
36
|
+
declare const __VLS_base: import("vue").DefineComponent<__VLS_PublicProps, {
|
|
37
|
+
marker: () => Marker | undefined;
|
|
38
|
+
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
39
|
+
"update:lnglat": (value: LngLatLike) => any;
|
|
40
|
+
"update:open": (value: boolean) => any;
|
|
41
|
+
}, string, import("vue").PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
|
|
42
|
+
"onUpdate:lnglat"?: ((value: LngLatLike) => any) | undefined;
|
|
43
|
+
"onUpdate:open"?: ((value: boolean) => any) | undefined;
|
|
44
|
+
}>, {
|
|
45
|
+
trigger: PopupTrigger;
|
|
46
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
47
|
+
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
48
|
+
declare const _default: typeof __VLS_export;
|
|
49
|
+
export default _default;
|
|
50
|
+
type __VLS_WithSlots<T, S> = T & {
|
|
51
|
+
new (): {
|
|
52
|
+
$slots: S;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { onMounted, onUnmounted, ref, useSlots, useTemplateRef, watch } from "vue";
|
|
3
|
+
import { Marker } from "maplibre-gl";
|
|
4
|
+
import { useMap } from "../composables/useMap";
|
|
5
|
+
import MaplibrePopup from "./Popup.vue";
|
|
6
|
+
const props = defineProps({
|
|
7
|
+
options: { type: Object, required: false },
|
|
8
|
+
popupOptions: { type: Object, required: false },
|
|
9
|
+
trigger: { type: String, required: false, default: "click" }
|
|
10
|
+
});
|
|
11
|
+
const lnglat = defineModel("lnglat", { type: [Object, Array], ...{ required: true } });
|
|
12
|
+
const open = defineModel("open", { type: Boolean, ...{ default: false } });
|
|
13
|
+
const ctx = useMap();
|
|
14
|
+
const slots = useSlots();
|
|
15
|
+
const el = useTemplateRef("el");
|
|
16
|
+
const ready = ref(false);
|
|
17
|
+
let marker;
|
|
18
|
+
let unbindTrigger;
|
|
19
|
+
function openPopup() {
|
|
20
|
+
open.value = true;
|
|
21
|
+
}
|
|
22
|
+
function closePopup() {
|
|
23
|
+
open.value = false;
|
|
24
|
+
}
|
|
25
|
+
function togglePopup() {
|
|
26
|
+
open.value = !open.value;
|
|
27
|
+
}
|
|
28
|
+
function onElementClick(event) {
|
|
29
|
+
event.stopPropagation();
|
|
30
|
+
togglePopup();
|
|
31
|
+
}
|
|
32
|
+
function bindTrigger() {
|
|
33
|
+
unbindTrigger?.();
|
|
34
|
+
unbindTrigger = void 0;
|
|
35
|
+
if (!marker || !slots.popup || props.trigger === "none") return;
|
|
36
|
+
const element = marker.getElement();
|
|
37
|
+
if (props.trigger === "click") {
|
|
38
|
+
element.addEventListener("click", onElementClick);
|
|
39
|
+
unbindTrigger = () => element.removeEventListener("click", onElementClick);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
element.addEventListener("mouseenter", openPopup);
|
|
43
|
+
element.addEventListener("mouseleave", closePopup);
|
|
44
|
+
unbindTrigger = () => {
|
|
45
|
+
element.removeEventListener("mouseenter", openPopup);
|
|
46
|
+
element.removeEventListener("mouseleave", closePopup);
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
onMounted(async () => {
|
|
50
|
+
const map = await ctx.whenLoaded();
|
|
51
|
+
const useSlot = Boolean(slots.default && el.value);
|
|
52
|
+
marker = new Marker({ ...props.options, ...useSlot ? { element: el.value } : {} });
|
|
53
|
+
marker.setLngLat(lnglat.value).addTo(map);
|
|
54
|
+
ready.value = true;
|
|
55
|
+
bindTrigger();
|
|
56
|
+
if (props.options?.draggable) {
|
|
57
|
+
marker.on("dragend", () => {
|
|
58
|
+
const { lng, lat } = marker.getLngLat();
|
|
59
|
+
lnglat.value = [lng, lat];
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
watch(lnglat, (value) => {
|
|
64
|
+
if (value) marker?.setLngLat(value);
|
|
65
|
+
});
|
|
66
|
+
watch(() => props.trigger, bindTrigger);
|
|
67
|
+
onUnmounted(() => {
|
|
68
|
+
unbindTrigger?.();
|
|
69
|
+
marker?.remove();
|
|
70
|
+
});
|
|
71
|
+
defineExpose({ marker: () => marker });
|
|
72
|
+
</script>
|
|
73
|
+
|
|
74
|
+
<template>
|
|
75
|
+
<div v-if="$slots.default" ref="el" :style="{ visibility: ready ? void 0 : 'hidden' }">
|
|
76
|
+
<slot />
|
|
77
|
+
</div>
|
|
78
|
+
<MaplibrePopup
|
|
79
|
+
v-if="$slots.popup && open"
|
|
80
|
+
:lnglat="lnglat"
|
|
81
|
+
:options="popupOptions"
|
|
82
|
+
@close="closePopup"
|
|
83
|
+
>
|
|
84
|
+
<slot name="popup" :close="closePopup" />
|
|
85
|
+
</MaplibrePopup>
|
|
86
|
+
</template>
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Marker } from 'maplibre-gl';
|
|
2
|
+
import type { LngLatLike, MarkerOptions, PopupOptions } from 'maplibre-gl';
|
|
3
|
+
import type { PopupTrigger } from '../types';
|
|
4
|
+
type __VLS_Props = {
|
|
5
|
+
/**
|
|
6
|
+
* 标记选项;element 由默认插槽提供,无需在此传入
|
|
7
|
+
* @see https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/MarkerOptions/
|
|
8
|
+
*/
|
|
9
|
+
options?: Omit<MarkerOptions, 'element'>;
|
|
10
|
+
/**
|
|
11
|
+
* 弹窗选项,仅在提供 #popup 插槽时生效
|
|
12
|
+
* @see https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/PopupOptions/
|
|
13
|
+
*/
|
|
14
|
+
popupOptions?: PopupOptions;
|
|
15
|
+
/**
|
|
16
|
+
* #popup 插槽的触发时机;'none' 表示不绑定监听,完全由 v-model:open 受控
|
|
17
|
+
* @defaultValue 'click'
|
|
18
|
+
*/
|
|
19
|
+
trigger?: PopupTrigger;
|
|
20
|
+
};
|
|
21
|
+
declare function closePopup(): void;
|
|
22
|
+
type __VLS_ModelProps = {
|
|
23
|
+
'lnglat': LngLatLike;
|
|
24
|
+
/** 弹窗开合状态;初始传 true 即默认展开 */
|
|
25
|
+
'open'?: boolean;
|
|
26
|
+
};
|
|
27
|
+
type __VLS_PublicProps = __VLS_Props & __VLS_ModelProps;
|
|
28
|
+
declare var __VLS_1: {}, __VLS_11: {
|
|
29
|
+
close: typeof closePopup;
|
|
30
|
+
};
|
|
31
|
+
type __VLS_Slots = {} & {
|
|
32
|
+
default?: (props: typeof __VLS_1) => any;
|
|
33
|
+
} & {
|
|
34
|
+
popup?: (props: typeof __VLS_11) => any;
|
|
35
|
+
};
|
|
36
|
+
declare const __VLS_base: import("vue").DefineComponent<__VLS_PublicProps, {
|
|
37
|
+
marker: () => Marker | undefined;
|
|
38
|
+
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
39
|
+
"update:lnglat": (value: LngLatLike) => any;
|
|
40
|
+
"update:open": (value: boolean) => any;
|
|
41
|
+
}, string, import("vue").PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
|
|
42
|
+
"onUpdate:lnglat"?: ((value: LngLatLike) => any) | undefined;
|
|
43
|
+
"onUpdate:open"?: ((value: boolean) => any) | undefined;
|
|
44
|
+
}>, {
|
|
45
|
+
trigger: PopupTrigger;
|
|
46
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
47
|
+
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
48
|
+
declare const _default: typeof __VLS_export;
|
|
49
|
+
export default _default;
|
|
50
|
+
type __VLS_WithSlots<T, S> = T & {
|
|
51
|
+
new (): {
|
|
52
|
+
$slots: S;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Popup } from 'maplibre-gl';
|
|
2
|
+
import type { LngLatLike, PopupOptions } from 'maplibre-gl';
|
|
3
|
+
type __VLS_Props = {
|
|
4
|
+
/** 弹窗锚定的经纬度 */
|
|
5
|
+
lnglat: LngLatLike;
|
|
6
|
+
/**
|
|
7
|
+
* Popup 选项
|
|
8
|
+
* @see https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/PopupOptions/
|
|
9
|
+
*/
|
|
10
|
+
options?: PopupOptions;
|
|
11
|
+
};
|
|
12
|
+
declare var __VLS_1: {};
|
|
13
|
+
type __VLS_Slots = {} & {
|
|
14
|
+
default?: (props: typeof __VLS_1) => any;
|
|
15
|
+
};
|
|
16
|
+
declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {
|
|
17
|
+
popup: () => Popup | undefined;
|
|
18
|
+
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
19
|
+
close: () => any;
|
|
20
|
+
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
21
|
+
onClose?: (() => any) | undefined;
|
|
22
|
+
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
23
|
+
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
24
|
+
declare const _default: typeof __VLS_export;
|
|
25
|
+
export default _default;
|
|
26
|
+
type __VLS_WithSlots<T, S> = T & {
|
|
27
|
+
new (): {
|
|
28
|
+
$slots: S;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { onMounted, onUnmounted, useTemplateRef, watch } from "vue";
|
|
3
|
+
import { Popup } from "maplibre-gl";
|
|
4
|
+
import { useMap } from "../composables/useMap";
|
|
5
|
+
const props = defineProps({
|
|
6
|
+
lnglat: { type: [Object, Array], required: true },
|
|
7
|
+
options: { type: Object, required: false }
|
|
8
|
+
});
|
|
9
|
+
const emit = defineEmits(["close"]);
|
|
10
|
+
defineOptions({ inheritAttrs: false });
|
|
11
|
+
const ctx = useMap();
|
|
12
|
+
const el = useTemplateRef("el");
|
|
13
|
+
let popup;
|
|
14
|
+
onMounted(async () => {
|
|
15
|
+
const map = await ctx.whenLoaded();
|
|
16
|
+
popup = new Popup(props.options);
|
|
17
|
+
popup.setLngLat(props.lnglat);
|
|
18
|
+
if (el.value) popup.setDOMContent(el.value);
|
|
19
|
+
popup.on("close", () => emit("close"));
|
|
20
|
+
popup.addTo(map);
|
|
21
|
+
});
|
|
22
|
+
watch(() => props.lnglat, (value) => popup?.setLngLat(value));
|
|
23
|
+
onUnmounted(() => popup?.remove());
|
|
24
|
+
defineExpose({ popup: () => popup });
|
|
25
|
+
</script>
|
|
26
|
+
|
|
27
|
+
<template>
|
|
28
|
+
<div style="display: none">
|
|
29
|
+
<div ref="el" v-bind="$attrs">
|
|
30
|
+
<slot />
|
|
31
|
+
</div>
|
|
32
|
+
</div>
|
|
33
|
+
</template>
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Popup } from 'maplibre-gl';
|
|
2
|
+
import type { LngLatLike, PopupOptions } from 'maplibre-gl';
|
|
3
|
+
type __VLS_Props = {
|
|
4
|
+
/** 弹窗锚定的经纬度 */
|
|
5
|
+
lnglat: LngLatLike;
|
|
6
|
+
/**
|
|
7
|
+
* Popup 选项
|
|
8
|
+
* @see https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/PopupOptions/
|
|
9
|
+
*/
|
|
10
|
+
options?: PopupOptions;
|
|
11
|
+
};
|
|
12
|
+
declare var __VLS_1: {};
|
|
13
|
+
type __VLS_Slots = {} & {
|
|
14
|
+
default?: (props: typeof __VLS_1) => any;
|
|
15
|
+
};
|
|
16
|
+
declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {
|
|
17
|
+
popup: () => Popup | undefined;
|
|
18
|
+
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
19
|
+
close: () => any;
|
|
20
|
+
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
21
|
+
onClose?: (() => any) | undefined;
|
|
22
|
+
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
23
|
+
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
24
|
+
declare const _default: typeof __VLS_export;
|
|
25
|
+
export default _default;
|
|
26
|
+
type __VLS_WithSlots<T, S> = T & {
|
|
27
|
+
new (): {
|
|
28
|
+
$slots: S;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { SourceSpecification } from '@maplibre/maplibre-gl-style-spec';
|
|
2
|
+
type __VLS_Props = {
|
|
3
|
+
/** 数据源 id,供图层经 source 字段按字符串引用 */
|
|
4
|
+
sourceId: string;
|
|
5
|
+
/**
|
|
6
|
+
* 数据源定义
|
|
7
|
+
* @see https://maplibre.org/maplibre-style-spec/sources/
|
|
8
|
+
*/
|
|
9
|
+
source: SourceSpecification;
|
|
10
|
+
};
|
|
11
|
+
declare var __VLS_1: {};
|
|
12
|
+
type __VLS_Slots = {} & {
|
|
13
|
+
default?: (props: typeof __VLS_1) => any;
|
|
14
|
+
};
|
|
15
|
+
declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
16
|
+
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
17
|
+
declare const _default: typeof __VLS_export;
|
|
18
|
+
export default _default;
|
|
19
|
+
type __VLS_WithSlots<T, S> = T & {
|
|
20
|
+
new (): {
|
|
21
|
+
$slots: S;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { onUnmounted, watch } from "vue";
|
|
3
|
+
import { useMap } from "../composables/useMap";
|
|
4
|
+
const props = defineProps({
|
|
5
|
+
sourceId: { type: String, required: true },
|
|
6
|
+
source: { type: Object, required: true }
|
|
7
|
+
});
|
|
8
|
+
const ctx = useMap();
|
|
9
|
+
const stopReady = ctx.onReady((map) => {
|
|
10
|
+
if (!map.getSource(props.sourceId)) {
|
|
11
|
+
map.addSource(props.sourceId, props.source);
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
watch(() => props.source, (next) => {
|
|
15
|
+
const source = ctx.map.value?.getSource(props.sourceId);
|
|
16
|
+
if (!source) return;
|
|
17
|
+
if (next.type === "geojson" && next.data) {
|
|
18
|
+
source.setData(next.data);
|
|
19
|
+
} else if (next.type === "vector") {
|
|
20
|
+
if (next.url) source.setUrl(next.url);
|
|
21
|
+
if (next.tiles) source.setTiles(next.tiles);
|
|
22
|
+
} else if (next.type === "raster" || next.type === "raster-dem") {
|
|
23
|
+
if (next.url) source.setUrl(next.url);
|
|
24
|
+
if (next.tiles) source.setTiles(next.tiles);
|
|
25
|
+
} else if (next.type === "image" && next.url) {
|
|
26
|
+
source.updateImage(next);
|
|
27
|
+
} else if (next.type === "video" && next.coordinates) {
|
|
28
|
+
source.setCoordinates(next.coordinates);
|
|
29
|
+
}
|
|
30
|
+
}, { deep: true });
|
|
31
|
+
onUnmounted(() => {
|
|
32
|
+
stopReady();
|
|
33
|
+
const map = ctx.map.value;
|
|
34
|
+
if (!map?.getSource(props.sourceId)) return;
|
|
35
|
+
try {
|
|
36
|
+
map.removeSource(props.sourceId);
|
|
37
|
+
} catch {
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
</script>
|
|
41
|
+
|
|
42
|
+
<template>
|
|
43
|
+
<slot />
|
|
44
|
+
</template>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { SourceSpecification } from '@maplibre/maplibre-gl-style-spec';
|
|
2
|
+
type __VLS_Props = {
|
|
3
|
+
/** 数据源 id,供图层经 source 字段按字符串引用 */
|
|
4
|
+
sourceId: string;
|
|
5
|
+
/**
|
|
6
|
+
* 数据源定义
|
|
7
|
+
* @see https://maplibre.org/maplibre-style-spec/sources/
|
|
8
|
+
*/
|
|
9
|
+
source: SourceSpecification;
|
|
10
|
+
};
|
|
11
|
+
declare var __VLS_1: {};
|
|
12
|
+
type __VLS_Slots = {} & {
|
|
13
|
+
default?: (props: typeof __VLS_1) => any;
|
|
14
|
+
};
|
|
15
|
+
declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
16
|
+
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
17
|
+
declare const _default: typeof __VLS_export;
|
|
18
|
+
export default _default;
|
|
19
|
+
type __VLS_WithSlots<T, S> = T & {
|
|
20
|
+
new (): {
|
|
21
|
+
$slots: S;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { GeoJSONFeature, PopupOptions } from 'maplibre-gl';
|
|
2
|
+
import type { PopupTrigger } from '../types';
|
|
3
|
+
/** 目标图层要素的弹窗:按 trigger 以悬浮或点击触发,作用域插槽拿到当前要素。 */
|
|
4
|
+
type __VLS_Props = {
|
|
5
|
+
/** 目标图层 id */
|
|
6
|
+
layerId: string;
|
|
7
|
+
/**
|
|
8
|
+
* Popup 选项(hover 模式下 closeButton/closeOnClick 由组件接管)
|
|
9
|
+
* @see https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/PopupOptions/
|
|
10
|
+
*/
|
|
11
|
+
options?: PopupOptions;
|
|
12
|
+
/**
|
|
13
|
+
* 悬浮时鼠标指针样式
|
|
14
|
+
* @defaultValue 'pointer'
|
|
15
|
+
*/
|
|
16
|
+
cursor?: string;
|
|
17
|
+
/**
|
|
18
|
+
* 触发时机;'none' 表示不绑定任何监听,可用于临时停用
|
|
19
|
+
* @defaultValue 'hover'
|
|
20
|
+
*/
|
|
21
|
+
trigger?: PopupTrigger;
|
|
22
|
+
};
|
|
23
|
+
declare function close(): void;
|
|
24
|
+
declare var __VLS_1: {
|
|
25
|
+
feature: GeoJSONFeature | undefined;
|
|
26
|
+
close: typeof close;
|
|
27
|
+
};
|
|
28
|
+
type __VLS_Slots = {} & {
|
|
29
|
+
default?: (props: typeof __VLS_1) => any;
|
|
30
|
+
};
|
|
31
|
+
declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {
|
|
32
|
+
/** 当前激活要素 */
|
|
33
|
+
hovered: () => GeoJSONFeature | undefined;
|
|
34
|
+
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
|
|
35
|
+
trigger: PopupTrigger;
|
|
36
|
+
cursor: string;
|
|
37
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
38
|
+
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
39
|
+
declare const _default: typeof __VLS_export;
|
|
40
|
+
export default _default;
|
|
41
|
+
type __VLS_WithSlots<T, S> = T & {
|
|
42
|
+
new (): {
|
|
43
|
+
$slots: S;
|
|
44
|
+
};
|
|
45
|
+
};
|