@movk/maplibre 1.0.0 → 1.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.
Files changed (202) hide show
  1. package/README.en.md +2 -2
  2. package/README.md +2 -2
  3. package/dist/module.d.mts +12 -3
  4. package/dist/module.d.ts +12 -3
  5. package/dist/module.json +1 -1
  6. package/dist/module.mjs +26 -11
  7. package/dist/runtime/components/CustomLayer.d.vue.ts +1 -1
  8. package/dist/runtime/components/CustomLayer.vue +18 -4
  9. package/dist/runtime/components/CustomLayer.vue.d.ts +1 -1
  10. package/dist/runtime/components/Layer.d.vue.ts +4 -4
  11. package/dist/runtime/components/Layer.vue +43 -18
  12. package/dist/runtime/components/Layer.vue.d.ts +4 -4
  13. package/dist/runtime/components/LayerGroup.d.vue.ts +23 -10
  14. package/dist/runtime/components/LayerGroup.vue +44 -4
  15. package/dist/runtime/components/LayerGroup.vue.d.ts +23 -10
  16. package/dist/runtime/components/LottieMarker.d.vue.ts +3 -3
  17. package/dist/runtime/components/LottieMarker.vue +6 -2
  18. package/dist/runtime/components/LottieMarker.vue.d.ts +3 -3
  19. package/dist/runtime/components/Map.d.vue.ts +2 -1
  20. package/dist/runtime/components/Map.vue +2 -6
  21. package/dist/runtime/components/Map.vue.d.ts +2 -1
  22. package/dist/runtime/components/Marker.d.vue.ts +2 -1
  23. package/dist/runtime/components/Marker.vue +33 -9
  24. package/dist/runtime/components/Marker.vue.d.ts +2 -1
  25. package/dist/runtime/components/Popup.d.vue.ts +1 -1
  26. package/dist/runtime/components/Popup.vue +23 -4
  27. package/dist/runtime/components/Popup.vue.d.ts +1 -1
  28. package/dist/runtime/components/Source.d.vue.ts +2 -2
  29. package/dist/runtime/components/Source.vue +3 -15
  30. package/dist/runtime/components/Source.vue.d.ts +2 -2
  31. package/dist/runtime/components/Tooltip.d.vue.ts +2 -2
  32. package/dist/runtime/components/Tooltip.vue +47 -19
  33. package/dist/runtime/components/Tooltip.vue.d.ts +2 -2
  34. package/dist/runtime/components/buffers/BufferCircle.d.vue.ts +1 -1
  35. package/dist/runtime/components/buffers/BufferCircle.vue.d.ts +1 -1
  36. package/dist/runtime/components/buffers/BufferEllipse.d.vue.ts +1 -1
  37. package/dist/runtime/components/buffers/BufferEllipse.vue.d.ts +1 -1
  38. package/dist/runtime/components/buffers/BufferLine.d.vue.ts +1 -1
  39. package/dist/runtime/components/buffers/BufferLine.vue.d.ts +1 -1
  40. package/dist/runtime/components/buffers/BufferPolygon.d.vue.ts +1 -1
  41. package/dist/runtime/components/buffers/BufferPolygon.vue.d.ts +1 -1
  42. package/dist/runtime/components/buffers/BufferSector.d.vue.ts +1 -1
  43. package/dist/runtime/components/buffers/BufferSector.vue.d.ts +1 -1
  44. package/dist/runtime/components/controls/BasemapControl.d.vue.ts +35 -0
  45. package/dist/runtime/components/controls/BasemapControl.vue +60 -0
  46. package/dist/runtime/components/controls/BasemapControl.vue.d.ts +35 -0
  47. package/dist/runtime/components/controls/Control.d.vue.ts +51 -0
  48. package/dist/runtime/components/controls/Control.vue +95 -0
  49. package/dist/runtime/components/controls/Control.vue.d.ts +51 -0
  50. package/dist/runtime/components/controls/GlobeControl.d.vue.ts +18 -0
  51. package/dist/runtime/components/controls/GlobeControl.vue +15 -0
  52. package/dist/runtime/components/controls/GlobeControl.vue.d.ts +18 -0
  53. package/dist/runtime/components/controls/LayerControl.d.vue.ts +44 -0
  54. package/dist/runtime/components/controls/LayerControl.vue +63 -0
  55. package/dist/runtime/components/controls/LayerControl.vue.d.ts +44 -0
  56. package/dist/runtime/components/controls/Legend.d.vue.ts +47 -0
  57. package/dist/runtime/components/controls/Legend.vue +69 -0
  58. package/dist/runtime/components/controls/Legend.vue.d.ts +47 -0
  59. package/dist/runtime/components/controls/Minimap.d.vue.ts +45 -0
  60. package/dist/runtime/components/controls/Minimap.vue +31 -0
  61. package/dist/runtime/components/controls/Minimap.vue.d.ts +45 -0
  62. package/dist/runtime/components/effects/AnimatedImage.d.vue.ts +1 -1
  63. package/dist/runtime/components/effects/AnimatedImage.vue +9 -6
  64. package/dist/runtime/components/effects/AnimatedImage.vue.d.ts +1 -1
  65. package/dist/runtime/components/effects/DiffusionCircle.d.vue.ts +1 -1
  66. package/dist/runtime/components/effects/DiffusionCircle.vue.d.ts +1 -1
  67. package/dist/runtime/components/effects/FlowBuilding.d.vue.ts +1 -1
  68. package/dist/runtime/components/effects/FlowBuilding.vue.d.ts +1 -1
  69. package/dist/runtime/components/effects/GlowCircle.d.vue.ts +1 -1
  70. package/dist/runtime/components/effects/GlowCircle.vue.d.ts +1 -1
  71. package/dist/runtime/components/effects/GradientBuilding.d.vue.ts +1 -1
  72. package/dist/runtime/components/effects/GradientBuilding.vue.d.ts +1 -1
  73. package/dist/runtime/components/effects/Migration.d.vue.ts +1 -1
  74. package/dist/runtime/components/effects/Migration.vue.d.ts +1 -1
  75. package/dist/runtime/components/effects/Radar.d.vue.ts +1 -1
  76. package/dist/runtime/components/effects/Radar.vue.d.ts +1 -1
  77. package/dist/runtime/components/effects/SpriteImage.d.vue.ts +1 -1
  78. package/dist/runtime/components/effects/SpriteImage.vue +40 -24
  79. package/dist/runtime/components/effects/SpriteImage.vue.d.ts +1 -1
  80. package/dist/runtime/components/effects/TextureBuilding.d.vue.ts +1 -1
  81. package/dist/runtime/components/effects/TextureBuilding.vue +1 -1
  82. package/dist/runtime/components/effects/TextureBuilding.vue.d.ts +1 -1
  83. package/dist/runtime/components/effects/Trail.d.vue.ts +1 -1
  84. package/dist/runtime/components/effects/Trail.vue.d.ts +1 -1
  85. package/dist/runtime/components/effects/WaveCircle.d.vue.ts +1 -1
  86. package/dist/runtime/components/effects/WaveCircle.vue.d.ts +1 -1
  87. package/dist/runtime/components/effects/WindowBuilding.d.vue.ts +1 -1
  88. package/dist/runtime/components/effects/WindowBuilding.vue.d.ts +1 -1
  89. package/dist/runtime/components/environment/Projection.d.vue.ts +28 -0
  90. package/dist/runtime/components/environment/Projection.vue +27 -0
  91. package/dist/runtime/components/environment/Projection.vue.d.ts +28 -0
  92. package/dist/runtime/components/environment/Temperature.d.vue.ts +1 -1
  93. package/dist/runtime/components/environment/Temperature.vue.d.ts +1 -1
  94. package/dist/runtime/components/environment/Terrain.d.vue.ts +1 -1
  95. package/dist/runtime/components/environment/Terrain.vue +5 -0
  96. package/dist/runtime/components/environment/Terrain.vue.d.ts +1 -1
  97. package/dist/runtime/components/extensions/DrawControl.vue +23 -19
  98. package/dist/runtime/components/extensions/Swipe.d.vue.ts +48 -0
  99. package/dist/runtime/components/extensions/Swipe.vue +141 -0
  100. package/dist/runtime/components/extensions/Swipe.vue.d.ts +48 -0
  101. package/dist/runtime/components/layers/BuildingLayer.d.vue.ts +1 -1
  102. package/dist/runtime/components/layers/BuildingLayer.vue.d.ts +1 -1
  103. package/dist/runtime/components/layers/ClusterLayer.d.vue.ts +1 -1
  104. package/dist/runtime/components/layers/ClusterLayer.vue.d.ts +1 -1
  105. package/dist/runtime/components/layers/ContourLayer.d.vue.ts +59 -0
  106. package/dist/runtime/components/layers/ContourLayer.vue +84 -0
  107. package/dist/runtime/components/layers/ContourLayer.vue.d.ts +59 -0
  108. package/dist/runtime/components/layers/GraticuleLayer.d.vue.ts +31 -0
  109. package/dist/runtime/components/layers/GraticuleLayer.vue +88 -0
  110. package/dist/runtime/components/layers/GraticuleLayer.vue.d.ts +31 -0
  111. package/dist/runtime/components/layers/ImageLayer.d.vue.ts +1 -1
  112. package/dist/runtime/components/layers/ImageLayer.vue.d.ts +1 -1
  113. package/dist/runtime/components/layers/MaskLayer.d.vue.ts +44 -0
  114. package/dist/runtime/components/layers/MaskLayer.vue +32 -0
  115. package/dist/runtime/components/layers/MaskLayer.vue.d.ts +44 -0
  116. package/dist/runtime/components/layers/RasterLayer.d.vue.ts +5 -3
  117. package/dist/runtime/components/layers/RasterLayer.vue +9 -2
  118. package/dist/runtime/components/layers/RasterLayer.vue.d.ts +5 -3
  119. package/dist/runtime/components/layers/VideoLayer.d.vue.ts +1 -1
  120. package/dist/runtime/components/layers/VideoLayer.vue.d.ts +1 -1
  121. package/dist/runtime/composables/useFeatureState.js +27 -5
  122. package/dist/runtime/composables/useFrameIcon.d.ts +4 -3
  123. package/dist/runtime/composables/useFrameIcon.js +18 -8
  124. package/dist/runtime/composables/useLayerTree.d.ts +11 -0
  125. package/dist/runtime/composables/useLayerTree.js +12 -0
  126. package/dist/runtime/composables/useMapAnimation.d.ts +4 -2
  127. package/dist/runtime/composables/useMapAnimation.js +5 -4
  128. package/dist/runtime/composables/useMapExport.js +2 -5
  129. package/dist/runtime/composables/useMapSync.d.ts +16 -0
  130. package/dist/runtime/composables/useMapSync.js +42 -0
  131. package/dist/runtime/composables/useMaplibreCamera.d.ts +1 -1
  132. package/dist/runtime/composables/useMaplibreCamera.js +1 -1
  133. package/dist/runtime/composables/useMaplibreImage.d.ts +3 -3
  134. package/dist/runtime/composables/useMaplibreImage.js +26 -5
  135. package/dist/runtime/domains/map/config.js +2 -3
  136. package/dist/runtime/domains/map/context.js +15 -0
  137. package/dist/runtime/domains/map/control.d.ts +1 -1
  138. package/dist/runtime/domains/map/control.js +1 -1
  139. package/dist/runtime/domains/map/draw-modes.d.ts +9 -0
  140. package/dist/runtime/domains/map/draw-modes.js +53 -0
  141. package/dist/runtime/domains/map/draw-registry.d.ts +2 -3
  142. package/dist/runtime/domains/map/draw-registry.js +6 -9
  143. package/dist/runtime/domains/map/draw-theme.d.ts +12 -0
  144. package/dist/runtime/domains/map/draw-toolbar.js +11 -10
  145. package/dist/runtime/domains/map/layer-group.d.ts +15 -4
  146. package/dist/runtime/domains/map/layer-tree.d.ts +3 -0
  147. package/dist/runtime/domains/map/layer-tree.js +10 -0
  148. package/dist/runtime/domains/map/minimap.d.ts +18 -0
  149. package/dist/runtime/domains/map/minimap.js +86 -0
  150. package/dist/runtime/domains/map/registry.js +4 -3
  151. package/dist/runtime/domains/map/style-layers.d.ts +7 -0
  152. package/dist/runtime/domains/map/style-layers.js +54 -0
  153. package/dist/runtime/domains/map/style.d.ts +3 -0
  154. package/dist/runtime/domains/map/style.js +5 -0
  155. package/dist/runtime/domains/map/swipe.d.ts +9 -0
  156. package/dist/runtime/domains/map/swipe.js +62 -0
  157. package/dist/runtime/index.css +1 -1
  158. package/dist/runtime/types/draw.d.ts +34 -1
  159. package/dist/runtime/types/index.d.ts +1 -0
  160. package/dist/runtime/types/layer.d.ts +40 -0
  161. package/dist/runtime/types/layer.js +0 -0
  162. package/dist/runtime/types/map.d.ts +6 -0
  163. package/dist/runtime/utils/cog.d.ts +2 -0
  164. package/dist/runtime/utils/cog.js +9 -0
  165. package/dist/runtime/utils/effects.js +2 -1
  166. package/dist/runtime/utils/events.d.ts +6 -0
  167. package/dist/runtime/utils/events.js +25 -0
  168. package/dist/runtime/utils/frame-icon.d.ts +2 -5
  169. package/dist/runtime/utils/frame-icon.js +10 -4
  170. package/dist/runtime/utils/graticule.d.ts +19 -0
  171. package/dist/runtime/utils/graticule.js +62 -0
  172. package/dist/runtime/utils/layer-opacity.d.ts +7 -0
  173. package/dist/runtime/utils/layer-opacity.js +59 -0
  174. package/dist/runtime/utils/layer.js +2 -1
  175. package/dist/runtime/utils/legend.d.ts +9 -0
  176. package/dist/runtime/utils/legend.js +52 -0
  177. package/dist/runtime/utils/marker.d.ts +11 -0
  178. package/dist/runtime/utils/marker.js +28 -0
  179. package/dist/runtime/utils/mask.d.ts +8 -0
  180. package/dist/runtime/utils/mask.js +33 -0
  181. package/dist/runtime/utils/minimap.d.ts +6 -0
  182. package/dist/runtime/utils/minimap.js +15 -0
  183. package/dist/runtime/utils/pmtiles.d.ts +3 -0
  184. package/dist/runtime/utils/pmtiles.js +10 -0
  185. package/dist/runtime/utils/source.d.ts +7 -0
  186. package/dist/runtime/utils/source.js +35 -0
  187. package/dist/runtime/utils/swipe.d.ts +32 -0
  188. package/dist/runtime/utils/swipe.js +18 -0
  189. package/dist/runtime/utils/tianditu.d.ts +10 -1
  190. package/dist/runtime/utils/tianditu.js +11 -0
  191. package/dist/runtime/utils/zzts-tile.d.ts +54 -0
  192. package/dist/runtime/utils/zzts-tile.js +85 -0
  193. package/dist/runtime/utils/zzts.d.ts +14 -0
  194. package/dist/runtime/utils/zzts.js +72 -0
  195. package/dist/unplugin.d.mts +1 -1
  196. package/dist/unplugin.d.ts +1 -1
  197. package/dist/unplugin.mjs +1 -7
  198. package/package.json +29 -21
  199. package/dist/runtime/draw-modes/index.d.ts +0 -16
  200. package/dist/runtime/draw-modes/index.js +0 -32
  201. package/dist/runtime/utils/draw-theme.d.ts +0 -47
  202. /package/dist/runtime/{utils → domains/map}/draw-theme.js +0 -0
@@ -0,0 +1,85 @@
1
+ export const ZZTS_TILE_SIZE = 512;
2
+ const PROTOCOL_PREFIX = "zzts://";
3
+ const TILE_HASH = /#(\d+)\/(\d+)\/(\d+)$/;
4
+ const EARTH_CIRCUMFERENCE = 2 * Math.PI * 6378137;
5
+ const METERS_PER_PIXEL_TO_SCALE = 96 / 0.0254;
6
+ const MAX_BBOX_SPAN = 20;
7
+ const LINEAR_ZOOM = 8;
8
+ const STRIP_HEIGHT = 32;
9
+ export function parseZztsUrl(url) {
10
+ const raw = url.startsWith(PROTOCOL_PREFIX) ? url.slice(PROTOCOL_PREFIX.length) : url;
11
+ const match = raw.match(TILE_HASH);
12
+ if (!match) return { mediaUrl: raw };
13
+ return {
14
+ mediaUrl: raw.slice(0, match.index),
15
+ tile: { z: Number(match[1]), x: Number(match[2]), y: Number(match[3]) }
16
+ };
17
+ }
18
+ const lngAt = (x, z) => x / 2 ** z * 360 - 180;
19
+ function snapOut(x, y, w, h) {
20
+ const left = Math.floor(x);
21
+ const top = Math.floor(y);
22
+ return [left, top, Math.ceil(x + w) - left, Math.ceil(y + h) - top];
23
+ }
24
+ const latAt = (y, z) => Math.atan(Math.sinh(Math.PI * (1 - 2 * y / 2 ** z))) * 180 / Math.PI;
25
+ const rowAt = (lat, z) => (1 - Math.asinh(Math.tan(lat * Math.PI / 180)) / Math.PI) / 2 * 2 ** z;
26
+ export function tileBBox({ z, x, y }) {
27
+ return [lngAt(x, z), latAt(y + 1, z), lngAt(x + 1, z), latAt(y, z)];
28
+ }
29
+ export function tileScale(z, lat) {
30
+ const metersPerPixel = EARTH_CIRCUMFERENCE * Math.cos(lat * Math.PI / 180) / (ZZTS_TILE_SIZE * 2 ** z);
31
+ return metersPerPixel * METERS_PER_PIXEL_TO_SCALE;
32
+ }
33
+ export function zztsTileJson(url, media) {
34
+ const { xmin, ymin, xmax, ymax } = media.extent;
35
+ const centerLat = (ymin + ymax) / 2;
36
+ const minzoom = Math.ceil(Math.log2(360 / MAX_BBOX_SPAN));
37
+ const nativeZoom = Math.ceil(Math.log2(EARTH_CIRCUMFERENCE * Math.cos(centerLat * Math.PI / 180) / (ZZTS_TILE_SIZE * media.resolution)));
38
+ return {
39
+ tiles: [`${url}#{z}/{x}/{y}`],
40
+ bounds: [xmin, ymin, xmax, ymax],
41
+ minzoom,
42
+ maxzoom: Math.max(minzoom, nativeZoom),
43
+ tileSize: ZZTS_TILE_SIZE,
44
+ name: media.name
45
+ };
46
+ }
47
+ export function elementsUrl(mediaUrl, tile, coarser = 0) {
48
+ const [west, south, east, north] = tileBBox(tile);
49
+ const url = new URL(mediaUrl);
50
+ url.pathname = `${url.pathname.replace(/\/$/, "")}/elements`;
51
+ url.searchParams.set("width", String(ZZTS_TILE_SIZE));
52
+ url.searchParams.set("height", String(ZZTS_TILE_SIZE));
53
+ url.searchParams.set("scale", String(tileScale(tile.z, (south + north) / 2) * 2 ** coarser));
54
+ url.searchParams.set("bbox", [west, south, east, north].join(","));
55
+ return url.toString();
56
+ }
57
+ export function planDraws(extent, tile) {
58
+ const [west, south, east, north] = tileBBox(tile);
59
+ const left = Math.max(extent.xmin, west);
60
+ const right = Math.min(extent.xmax, east);
61
+ const bottom = Math.max(extent.ymin, south);
62
+ const top = Math.min(extent.ymax, north);
63
+ if (left >= right || bottom >= top) return [];
64
+ const { z, x, y } = tile;
65
+ const width = extent.xmax - extent.xmin;
66
+ const height = extent.ymax - extent.ymin;
67
+ const sx = (left - extent.xmin) / width;
68
+ const sw = (right - left) / width;
69
+ const dx = ((left + 180) / 360 * 2 ** z - x) * ZZTS_TILE_SIZE;
70
+ const dw = (right - left) / 360 * 2 ** z * ZZTS_TILE_SIZE;
71
+ const dyTop = (rowAt(top, z) - y) * ZZTS_TILE_SIZE;
72
+ const dyBottom = (rowAt(bottom, z) - y) * ZZTS_TILE_SIZE;
73
+ const strips = z >= LINEAR_ZOOM ? 1 : Math.max(1, Math.ceil((dyBottom - dyTop) / STRIP_HEIGHT));
74
+ const stripHeight = (dyBottom - dyTop) / strips;
75
+ const latAtPixel = (py) => latAt(y + py / ZZTS_TILE_SIZE, z);
76
+ return Array.from({ length: strips }, (_, i) => {
77
+ const dy = dyTop + i * stripHeight;
78
+ const latTop = i === 0 ? top : latAtPixel(dy);
79
+ const latBottom = i === strips - 1 ? bottom : latAtPixel(dy + stripHeight);
80
+ return {
81
+ source: [sx, (extent.ymax - latTop) / height, sw, (latTop - latBottom) / height],
82
+ target: snapOut(dx, dy, dw, stripHeight)
83
+ };
84
+ });
85
+ }
@@ -0,0 +1,14 @@
1
+ export interface ZztsProtocolOptions {
2
+ /** 自定义请求,元数据、元素列表与元素图片共用;用于附加鉴权头或改走代理 */
3
+ fetch?: typeof globalThis.fetch;
4
+ /**
5
+ * 元素图片缓存数量;相邻瓦片常共用同一网格图片,命中时不再重复下载
6
+ * @defaultValue 256
7
+ */
8
+ cacheSize?: number;
9
+ }
10
+ /**
11
+ * 注册 `zzts://` 协议(全局单例、幂等):把 ZZTS 二维动态切片服务适配为 512 墨卡托栅格瓦片。
12
+ * `MaplibreRasterLayer` 的 `url` 写成 `zzts://` + media 接口地址即可。
13
+ */
14
+ export declare function registerZztsProtocol(options?: ZztsProtocolOptions): void;
@@ -0,0 +1,72 @@
1
+ import { addProtocol } from "maplibre-gl";
2
+ import { defineGlobalSingleton } from "@movk/core";
3
+ import { ZZTS_TILE_SIZE, elementsUrl, parseZztsUrl, planDraws, zztsTileJson } from "./zzts-tile.js";
4
+ const EMPTY_TILE = new ArrayBuffer(0);
5
+ const MAX_FALLBACK_LEVELS = 3;
6
+ async function getJson(request, url, signal) {
7
+ const res = await request(url, { signal });
8
+ if (!res.ok) throw new Error(`ZZTS \u8BF7\u6C42\u5931\u8D25\uFF1AHTTP ${res.status}`);
9
+ return await res.json();
10
+ }
11
+ function imageElements(payload) {
12
+ if (!Array.isArray(payload.elements)) throw new Error(payload.msg || "ZZTS \u5143\u7D20\u8BF7\u6C42\u5931\u8D25");
13
+ return payload.elements.filter(
14
+ (element, i, list) => element.type === "image" && list.findIndex((item) => item.id === element.id) === i
15
+ );
16
+ }
17
+ function createImageCache(request, size) {
18
+ const cache = /* @__PURE__ */ new Map();
19
+ return (url) => {
20
+ const hit = cache.get(url);
21
+ if (hit) {
22
+ cache.delete(url);
23
+ cache.set(url, hit);
24
+ return hit;
25
+ }
26
+ const pending = request(url).then(async (res) => {
27
+ if (res.status === 404) return void 0;
28
+ if (!res.ok) throw new Error(`ZZTS \u56FE\u7247\u52A0\u8F7D\u5931\u8D25\uFF1AHTTP ${res.status}`);
29
+ return createImageBitmap(await res.blob());
30
+ });
31
+ pending.catch(() => cache.delete(url));
32
+ cache.set(url, pending);
33
+ if (cache.size > size) cache.delete(cache.keys().next().value);
34
+ return pending;
35
+ };
36
+ }
37
+ function compose(tile, items) {
38
+ const canvas = new OffscreenCanvas(ZZTS_TILE_SIZE, ZZTS_TILE_SIZE);
39
+ const context = canvas.getContext("2d");
40
+ for (const { element, image } of items) {
41
+ for (const { source: [sx, sy, sw, sh], target: [dx, dy, dw, dh] } of planDraws(element.extent, tile)) {
42
+ context.drawImage(image, sx * image.width, sy * image.height, sw * image.width, sh * image.height, dx, dy, dw, dh);
43
+ }
44
+ }
45
+ return canvas.transferToImageBitmap();
46
+ }
47
+ function createZztsProtocol({ fetch: request = globalThis.fetch.bind(globalThis), cacheSize = 256 } = {}) {
48
+ const loadImage = createImageCache(request, cacheSize);
49
+ async function loadLevel(mediaUrl, tile, coarser, signal) {
50
+ const elements = imageElements(await getJson(request, elementsUrl(mediaUrl, tile, coarser), signal));
51
+ const images = await Promise.all(elements.map((element) => loadImage(element.url).catch(() => void 0)));
52
+ const layers = elements.flatMap((element, i) => images[i] ? [{ element, image: images[i] }] : []);
53
+ if (layers.length === elements.length || coarser >= MAX_FALLBACK_LEVELS) return layers;
54
+ return [...await loadLevel(mediaUrl, tile, coarser + 1, signal), ...layers];
55
+ }
56
+ return async ({ url }, { signal }) => {
57
+ const { mediaUrl, tile } = parseZztsUrl(url);
58
+ if (!tile) {
59
+ const media = await getJson(request, mediaUrl, signal);
60
+ return { data: zztsTileJson(url, media) };
61
+ }
62
+ const layers = await loadLevel(mediaUrl, tile, 0, signal);
63
+ signal.throwIfAborted();
64
+ return { data: layers.length ? compose(tile, layers) : EMPTY_TILE };
65
+ };
66
+ }
67
+ export function registerZztsProtocol(options) {
68
+ defineGlobalSingleton("movk-maplibre:protocol:zzts", () => {
69
+ addProtocol("zzts", createZztsProtocol(options));
70
+ return true;
71
+ });
72
+ }
@@ -19,7 +19,7 @@ declare function maplibreComponentResolver(options?: MaplibreResolverOptions): {
19
19
  from: string;
20
20
  } | undefined;
21
21
  };
22
- /** 本库 composables + 工具的自动导入项,注入既有 unplugin-auto-import 实例复用 */
22
+ /** 本库 composables 的自动导入项,注入既有 unplugin-auto-import 实例复用 */
23
23
  declare function maplibreAutoImports(): {
24
24
  from: string;
25
25
  imports: string[];
@@ -19,7 +19,7 @@ declare function maplibreComponentResolver(options?: MaplibreResolverOptions): {
19
19
  from: string;
20
20
  } | undefined;
21
21
  };
22
- /** 本库 composables + 工具的自动导入项,注入既有 unplugin-auto-import 实例复用 */
22
+ /** 本库 composables 的自动导入项,注入既有 unplugin-auto-import 实例复用 */
23
23
  declare function maplibreAutoImports(): {
24
24
  from: string;
25
25
  imports: string[];
package/dist/unplugin.mjs CHANGED
@@ -6,10 +6,6 @@ import Components from 'unplugin-vue-components';
6
6
  import AutoImport from 'unplugin-auto-import';
7
7
 
8
8
  const runtimeDir = fileURLToPath(new URL("./runtime", import.meta.url));
9
- const UTIL_MANIFEST = {
10
- movkDrawModes: "draw-modes",
11
- drawThemeStyles: "utils/draw-theme"
12
- };
13
9
  function componentMap() {
14
10
  const dir = join(runtimeDir, "components");
15
11
  const map = /* @__PURE__ */ new Map();
@@ -33,9 +29,7 @@ function maplibreComponentResolver(options = {}) {
33
29
  }
34
30
  function maplibreAutoImports() {
35
31
  const cdir = join(runtimeDir, "composables");
36
- const composables = readdirSync(cdir).filter((f) => f.endsWith(".ts")).map((f) => f.slice(0, -".ts".length)).map((name) => ({ from: join(cdir, name), imports: [name] }));
37
- const utils = Object.entries(UTIL_MANIFEST).map(([name, file]) => ({ from: join(runtimeDir, file), imports: [name] }));
38
- return [...composables, ...utils];
32
+ return readdirSync(cdir).filter((f) => f.endsWith(".ts")).map((f) => f.slice(0, -".ts".length)).map((name) => ({ from: join(cdir, name), imports: [name] }));
39
33
  }
40
34
  const MaplibreUnplugin = createUnplugin((options = {}, meta) => {
41
35
  const dts = options.dts ?? true;
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@movk/maplibre",
3
3
  "type": "module",
4
- "version": "1.0.0",
5
- "packageManager": "pnpm@12.5.1",
4
+ "version": "1.2.0",
5
+ "packageManager": "pnpm@12.10.1",
6
6
  "description": "声明式 MapLibre GL 封装库:MaplibreMap/Source/Layer 等组件与 composables,原生支持 Nuxt 4 模块,并通过 Vite 插件在纯 Vue + Vite 项目中可用。无需 access token,内置 3D 建筑、雷达/扩散/辉光等动态效果,sky/terrain 环境,绘制(terra-draw)、天地图、WMS/WMTS 与多坐标系本土化支持。",
7
7
  "author": "YiXuan <mhaibaraai@gmail.com>",
8
8
  "license": "MIT",
@@ -49,10 +49,6 @@
49
49
  "types": "./dist/vue-plugin.d.mts",
50
50
  "import": "./dist/vue-plugin.mjs"
51
51
  },
52
- "./draw-modes": {
53
- "types": "./dist/runtime/draw-modes/index.d.ts",
54
- "import": "./dist/runtime/draw-modes/index.js"
55
- },
56
52
  "./index.css": "./dist/runtime/index.css",
57
53
  "./runtime/*": "./dist/runtime/*",
58
54
  "./components/*": "./dist/runtime/components/*",
@@ -75,9 +71,6 @@
75
71
  "vue-plugin": [
76
72
  "./dist/vue-plugin.d.mts"
77
73
  ],
78
- "draw-modes": [
79
- "./dist/runtime/draw-modes/index.d.ts"
80
- ],
81
74
  "runtime/*": [
82
75
  "./dist/runtime/*"
83
76
  ],
@@ -95,16 +88,28 @@
95
88
  "dist"
96
89
  ],
97
90
  "peerDependencies": {
91
+ "@geomatico/maplibre-cog-protocol": ">=0.10.0",
98
92
  "lottie-web": ">=5.0.0",
93
+ "maplibre-contour": ">=0.1.0",
99
94
  "maplibre-gl": ">=6.0.0",
95
+ "pmtiles": ">=4.0.0",
100
96
  "terra-draw": ">=1.0.0",
101
97
  "terra-draw-maplibre-gl-adapter": ">=1.0.0",
102
98
  "vue": ">=3.5.0"
103
99
  },
104
100
  "peerDependenciesMeta": {
101
+ "@geomatico/maplibre-cog-protocol": {
102
+ "optional": true
103
+ },
105
104
  "lottie-web": {
106
105
  "optional": true
107
106
  },
107
+ "maplibre-contour": {
108
+ "optional": true
109
+ },
110
+ "pmtiles": {
111
+ "optional": true
112
+ },
108
113
  "terra-draw": {
109
114
  "optional": true
110
115
  },
@@ -131,7 +136,7 @@
131
136
  },
132
137
  "dependencies": {
133
138
  "@maplibre/maplibre-gl-style-spec": "^26.4.4",
134
- "@movk/core": "^1.4.1",
139
+ "@movk/core": "^1.5.0",
135
140
  "@turf/area": "^7.4.0",
136
141
  "@turf/bearing": "^7.4.0",
137
142
  "@turf/buffer": "^7.4.0",
@@ -148,27 +153,30 @@
148
153
  "unplugin-vue-components": "^32.1.0"
149
154
  },
150
155
  "devDependencies": {
156
+ "@geomatico/maplibre-cog-protocol": "^0.10.0",
151
157
  "@nuxt/eslint-config": "^1.17.0",
152
- "@nuxt/kit": "^4.5.2",
158
+ "@nuxt/kit": "^4.6.0",
153
159
  "@nuxt/module-builder": "^1.0.3",
154
- "@nuxt/schema": "^4.5.2",
160
+ "@nuxt/schema": "^4.6.0",
155
161
  "@release-it/conventional-changelog": "^12.0.2",
156
162
  "@types/geojson": "^7946.0.16",
157
163
  "@vitejs/plugin-vue": "^6.0.9",
158
164
  "@vue/test-utils": "^2.5.1",
159
- "eslint": "^10.11.0",
160
- "happy-dom": "^20.14.5",
165
+ "eslint": "^10.12.0",
166
+ "happy-dom": "^20.14.6",
161
167
  "lottie-web": "^5.13.0",
162
- "maplibre-gl": "^6.10.0",
163
- "nuxt": "^4.5.2",
164
- "release-it": "^21.1.0",
165
- "terra-draw": "^1.35.0",
166
- "terra-draw-maplibre-gl-adapter": "^1.4.1",
168
+ "maplibre-contour": "^0.1.1",
169
+ "maplibre-gl": "^6.13.0",
170
+ "nuxt": "^4.6.0",
171
+ "pmtiles": "^4.5.0",
172
+ "release-it": "^21.1.1",
173
+ "terra-draw": "^1.37.0",
174
+ "terra-draw-maplibre-gl-adapter": "^1.5.0",
167
175
  "typescript": "^6.0.3",
168
176
  "unbuild": "^3.6.1",
169
177
  "unplugin": "^3.4.0",
170
- "vitest": "^5.0.1",
178
+ "vitest": "^5.0.3",
171
179
  "vue": "^3.5.43",
172
- "vue-tsc": "^3.3.11"
180
+ "vue-tsc": "^3.3.12"
173
181
  }
174
182
  }
@@ -1,16 +0,0 @@
1
- import type { TerraDrawExtend } from 'terra-draw';
2
- import type { DrawThemeOptions } from '../utils/draw-theme';
3
- /** 内置绘制模式名(不含选择模式 'select') */
4
- export declare const DRAW_MODE_NAMES: readonly ["point", "linestring", "polygon", "rectangle", "circle", "ellipse", "sector"];
5
- export type DrawModeName = (typeof DRAW_MODE_NAMES)[number];
6
- /** terra-draw 模式实例(绘制或选择模式) */
7
- export type DrawMode = TerraDrawExtend.TerraDrawBaseDrawMode<TerraDrawExtend.CustomStyling>;
8
- export interface MovkDrawModesOptions {
9
- /** 绘制主题,参见 drawThemeStyles */
10
- theme?: DrawThemeOptions;
11
- }
12
- /**
13
- * 预设 terra-draw 模式集合:选择模式 + 全部内置绘制模式,统一应用主题。
14
- * 每次调用返回新实例,模式实例不可在多个 TerraDraw 间共享。
15
- */
16
- export declare function movkDrawModes(options?: MovkDrawModesOptions): DrawMode[];
@@ -1,32 +0,0 @@
1
- import {
2
- TerraDrawCircleMode,
3
- TerraDrawEllipseMode,
4
- TerraDrawLineStringMode,
5
- TerraDrawPointMode,
6
- TerraDrawPolygonMode,
7
- TerraDrawRectangleMode,
8
- TerraDrawSectorMode,
9
- TerraDrawSelectMode
10
- } from "terra-draw";
11
- import { drawThemeStyles } from "../utils/draw-theme.js";
12
- export const DRAW_MODE_NAMES = ["point", "linestring", "polygon", "rectangle", "circle", "ellipse", "sector"];
13
- const EDITABLE_COORDINATES = { draggable: true, deletable: true, midpoints: true };
14
- export function movkDrawModes(options = {}) {
15
- const styles = drawThemeStyles(options.theme);
16
- const flags = Object.fromEntries(DRAW_MODE_NAMES.map((name) => [name, {
17
- feature: {
18
- draggable: true,
19
- ...name === "linestring" || name === "polygon" ? { coordinates: EDITABLE_COORDINATES } : {}
20
- }
21
- }]));
22
- return [
23
- new TerraDrawSelectMode({ flags, styles: styles.select }),
24
- new TerraDrawPointMode({ styles: styles.point }),
25
- new TerraDrawLineStringMode({ styles: styles.linestring }),
26
- new TerraDrawPolygonMode({ styles: styles.polygon }),
27
- new TerraDrawRectangleMode({ styles: styles.rectangle }),
28
- new TerraDrawCircleMode({ styles: styles.circle }),
29
- new TerraDrawEllipseMode({ styles: styles.ellipse }),
30
- new TerraDrawSectorMode({ styles: styles.sector })
31
- ];
32
- }
@@ -1,47 +0,0 @@
1
- import type { GeoJSONStoreFeatures, HexColor } from 'terra-draw';
2
- export interface DrawThemeOptions {
3
- /**
4
- * 非激活态主色
5
- * @defaultValue '#3b82f6'
6
- */
7
- color?: HexColor;
8
- /**
9
- * 激活态(绘制辅助点/选中)主色
10
- * @defaultValue '#f59e0b'
11
- */
12
- activeColor?: HexColor;
13
- /**
14
- * 多边形填充不透明度
15
- * @defaultValue 0.1
16
- */
17
- fillOpacity?: number;
18
- /**
19
- * 线宽
20
- * @defaultValue 2
21
- */
22
- lineWidth?: number;
23
- /**
24
- * 顶点圆半径
25
- * @defaultValue 5
26
- */
27
- vertexRadius?: number;
28
- }
29
- type ColorStyle = (feature: GeoJSONStoreFeatures) => HexColor;
30
- type ModeStyles = Record<string, number | HexColor | ColorStyle>;
31
- /** 各模式的 terra-draw styles,键为模式名 */
32
- export interface DrawThemeStyles {
33
- select: Record<string, number | HexColor>;
34
- point: ModeStyles;
35
- linestring: ModeStyles;
36
- polygon: ModeStyles;
37
- rectangle: ModeStyles;
38
- circle: ModeStyles;
39
- ellipse: ModeStyles;
40
- sector: ModeStyles;
41
- }
42
- /**
43
- * 生成 terra-draw 各模式的主题样式。
44
- * 要素 `properties.color` 优先于主题色,便于按要素单独着色(配合 setFeatureProperty)。
45
- */
46
- export declare function drawThemeStyles(options?: DrawThemeOptions): DrawThemeStyles;
47
- export {};