@gis_victory/gismap 1.0.56 → 2.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/README.md CHANGED
@@ -1,5 +1,475 @@
1
- # Vue 3 + TypeScript + Vite
1
+ # GISMap - 通用地图组件库
2
2
 
3
- This template should help get you started developing with Vue 3 and TypeScript in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.
3
+ GISMap 是一个基于适配器模式设计的通用地图组件库,支持多种地图引擎(如 Mapbox GL、MapLibre 等),提供统一的 API 接口和丰富的功能模块。
4
4
 
5
- Learn more about the recommended Project Setup and IDE Support in the [Vue Docs TypeScript Guide](https://vuejs.org/guide/typescript/overview.html#project-setup).
5
+ ## 特性
6
+
7
+ - **多引擎支持**:通过适配器模式,支持不同的地图引擎
8
+ - **丰富的管理器**:提供图层、标记、雷达、地形、绘制、测量等多种管理器
9
+ - **响应式设计**:基于 Vue 3 的 Composition API,提供响应式的地图状态管理
10
+ - **模块化架构**:清晰的代码结构,易于扩展和维护
11
+ - **TypeScript 支持**:完整的类型定义,提供良好的开发体验
12
+
13
+ ## 安装
14
+
15
+ ```bash
16
+ # 使用 npm
17
+ npm install gismap
18
+
19
+ # 使用 yarn
20
+ yarn add gismap
21
+
22
+ # 使用 pnpm
23
+ pnpm add gismap
24
+ ```
25
+
26
+ ## 基本使用
27
+
28
+ ### 1. 基础地图组件
29
+
30
+ ```vue
31
+ <template>
32
+ <div style="width: 100vw; height: 100vh;">
33
+ <GisMapContainer
34
+ :center="[120, 30]"
35
+ :zoom="10"
36
+ :access-token="'your-mapbox-access-token'"
37
+ :init-icons="initIcons"
38
+ >
39
+ <!-- 可以在这里添加地图控件 -->
40
+ </GisMapContainer>
41
+ </div>
42
+ </template>
43
+
44
+ <script setup lang="ts">
45
+ import { GisMapContainer } from 'gismap';
46
+
47
+ // 初始化图标配置
48
+ const initIcons = [
49
+ {
50
+ name: 'marker-icon',
51
+ url: 'https://example.com/marker.png'
52
+ },
53
+ {
54
+ name: 'icon-2',
55
+ url: 'https://example.com/icon2.png'
56
+ }
57
+ ];
58
+ </script>
59
+ ```
60
+
61
+ ### 2. 使用组合式函数
62
+
63
+ ```vue
64
+ <template>
65
+ <div style="width: 100vw; height: 100vh;">
66
+ <GisMapContainer @ready="handleMapReady">
67
+ <button @click="addMarker" style="position: absolute; top: 10px; left: 10px; z-index: 1000;">
68
+ 添加标记
69
+ </button>
70
+ </GisMapContainer>
71
+ </div>
72
+ </template>
73
+
74
+ <script setup lang="ts">
75
+ import { GisMapContainer } from 'gismap';
76
+ import { useMap, useMarker, useLayer } from 'gismap';
77
+
78
+ const { map, layers, markers } = useMap();
79
+
80
+ const handleMapReady = () => {
81
+ console.log('地图就绪');
82
+ };
83
+
84
+ const addMarker = () => {
85
+ // 添加标记
86
+ markers.value.add({
87
+ id: `marker-${Date.now()}`,
88
+ position: [120, 30],
89
+ options: {
90
+ draggable: true
91
+ }
92
+ });
93
+ };
94
+ </script>
95
+ ```
96
+
97
+ ## 核心功能
98
+
99
+ ### 1. 图层管理
100
+
101
+ ```typescript
102
+ import { useLayers } from 'gismap';
103
+
104
+ const { addLayer, removeLayer, layers } = useLayers();
105
+
106
+ // 添加 GeoJSON 图层
107
+ const layer = addLayer({
108
+ id: 'points',
109
+ type: 'circle',
110
+ source: {
111
+ type: 'geojson',
112
+ data: {
113
+ type: 'FeatureCollection',
114
+ features: [
115
+ {
116
+ type: 'Feature',
117
+ geometry: {
118
+ type: 'Point',
119
+ coordinates: [120, 30]
120
+ }
121
+ }
122
+ ]
123
+ }
124
+ },
125
+ paint: {
126
+ 'circle-radius': 10,
127
+ 'circle-color': '#ff0000'
128
+ }
129
+ });
130
+
131
+ // 移除图层
132
+ removeLayer(layer.id);
133
+ ```
134
+
135
+ ### 2. 标记管理
136
+
137
+ ```typescript
138
+ import { useMarkers } from 'gismap';
139
+
140
+ const { add, remove, getAll } = useMarkers();
141
+
142
+ // 添加标记
143
+ const marker = add({
144
+ id: 'marker-1',
145
+ position: [120, 30],
146
+ options: {
147
+ draggable: true,
148
+ anchor: 'bottom'
149
+ }
150
+ });
151
+
152
+ // 移除标记
153
+ remove('marker-1');
154
+
155
+ // 获取所有标记
156
+ const allMarkers = getAll();
157
+ ```
158
+
159
+ ### 3. 绘制功能
160
+
161
+ ```typescript
162
+ import { useDraw } from 'gismap';
163
+
164
+ const { startDraw, stopDraw, isDrawing, selected } = useDraw();
165
+
166
+ // 开始绘制多边形
167
+ startDraw('polygon', (type, geoJson, wkt, feature) => {
168
+ console.log('绘制完成:', type, geoJson, wkt);
169
+ });
170
+
171
+ // 停止绘制
172
+ stopDraw();
173
+ ```
174
+
175
+ ### 4. 测量功能
176
+
177
+ ```typescript
178
+ import { useMeasure } from 'gismap';
179
+
180
+ const { startMeasure, stopMeasure, isMeasuring, results } = useMeasure();
181
+
182
+ // 开始测量距离
183
+ startMeasure('line', (result) => {
184
+ console.log('测量结果:', result.value, result.unit);
185
+ });
186
+
187
+ // 停止测量
188
+ stopMeasure();
189
+ ```
190
+
191
+ ### 5. 雷达图层
192
+
193
+ ```typescript
194
+ import { useMap } from 'gismap';
195
+
196
+ const { radarManager } = useMap();
197
+
198
+ // 添加雷达
199
+ radarManager.value?.add({
200
+ center: [120, 30],
201
+ radius: 500,
202
+ sectorVisible: true,
203
+ sectorAngle: 45
204
+ });
205
+
206
+ // 开始扫描
207
+ radarManager.value?.startScan();
208
+
209
+ // 停止扫描
210
+ radarManager.value?.stopScan();
211
+
212
+ // 移除雷达
213
+ radarManager.value?.remove();
214
+ ```
215
+
216
+ ### 6. 地形管理
217
+
218
+ ```typescript
219
+ import { useMap } from 'gismap';
220
+
221
+ const { terrainManager } = useMap();
222
+
223
+ // 添加地形
224
+ terrainManager.value?.add({
225
+ source: {
226
+ tiles: ['https://example.com/terrain/{z}/{x}/{y}.png'],
227
+ minzoom: 0,
228
+ maxzoom: 14
229
+ },
230
+ layer: {
231
+ exaggeration: 1.5
232
+ }
233
+ });
234
+
235
+ // 添加山体阴影
236
+ terrainManager.value?.addHillshade();
237
+
238
+ // 移除地形
239
+ terrainManager.value?.remove();
240
+ ```
241
+
242
+ ### 7. 图标管理
243
+
244
+ #### 最佳实践:在地图初始化完成后立即加载图标
245
+
246
+ 为了确保地图能够正确读取图标,应该在地图初始化完成后立即加载图标。推荐使用 `useMapReady` 组合式函数来监听地图就绪事件:
247
+
248
+ ```typescript
249
+ import { useMapReady } from 'gismap';
250
+
251
+ // 在地图就绪后立即加载图标
252
+ useMapReady(async (context) => {
253
+ try {
254
+ // 批量加载图标
255
+ await context.iconManager?.load([
256
+ {
257
+ name: 'marker-icon',
258
+ url: 'https://example.com/marker.png'
259
+ },
260
+ {
261
+ name: 'icon-2',
262
+ url: 'https://example.com/icon2.png'
263
+ }
264
+ ], {
265
+ batchSize: 5, // 每批加载5个图标
266
+ batchInterval: 100, // 每批间隔100毫秒
267
+ onProgress: (loaded, total) => {
268
+ console.log(`加载进度: ${loaded}/${total}`);
269
+ }
270
+ });
271
+
272
+ console.log('图标加载完成');
273
+
274
+ // 图标加载完成后,再添加使用图标的图层
275
+ addIconLayer(context);
276
+ } catch (error) {
277
+ console.error('图标加载失败:', error);
278
+ }
279
+ });
280
+
281
+ // 添加使用图标的图层
282
+ function addIconLayer(context) {
283
+ if (context?.layerManager) {
284
+ context.layerManager.addLayer({
285
+ id: 'icon-layer',
286
+ type: 'symbol',
287
+ source: {
288
+ type: 'geojson',
289
+ data: {
290
+ type: 'FeatureCollection',
291
+ features: [
292
+ {
293
+ type: 'Feature',
294
+ geometry: {
295
+ type: 'Point',
296
+ coordinates: [120, 30]
297
+ }
298
+ }
299
+ ]
300
+ }
301
+ },
302
+ layout: {
303
+ 'icon-image': 'marker-icon', // 使用已加载的图标
304
+ 'icon-size': 1.5
305
+ }
306
+ });
307
+ }
308
+ }
309
+ ```
310
+
311
+ #### 其他用法
312
+
313
+ ```typescript
314
+ import { useMap } from 'gismap';
315
+
316
+ const { iconManager } = useMap();
317
+
318
+ // 批量加载图标(基本用法)
319
+ iconManager.value?.load([
320
+ {
321
+ name: 'marker-icon',
322
+ url: 'https://example.com/marker.png'
323
+ },
324
+ {
325
+ name: 'icon-2',
326
+ url: 'https://example.com/icon2.png'
327
+ }
328
+ ]).then(() => {
329
+ console.log('图标加载完成');
330
+ });
331
+
332
+ // 加载单个图标
333
+ iconManager.value?.loadOne({
334
+ name: 'single-icon',
335
+ url: 'https://example.com/single.png'
336
+ }).then(() => {
337
+ console.log('单个图标加载完成');
338
+ });
339
+
340
+ // 检查图标是否已加载
341
+ if (iconManager.value?.hasIcon('marker-icon')) {
342
+ console.log('图标已加载');
343
+ }
344
+
345
+ // 移除图标
346
+ iconManager.value?.removeIcon('marker-icon');
347
+
348
+ // 清除所有图标记录
349
+ iconManager.value?.clear();
350
+ ```
351
+
352
+ ## 高级功能
353
+
354
+ ### 1. 自定义适配器
355
+
356
+ 您可以通过实现 `MapAdapter` 或 `VectorTileAdapter` 接口来创建自定义适配器,支持其他地图引擎。
357
+
358
+ ```typescript
359
+ import type { MapAdapter, MapInitOptions, MapViewState } from 'gismap';
360
+
361
+ export class MyCustomAdapter implements MapAdapter {
362
+ private map: any = null;
363
+
364
+ async initialize(container: HTMLElement, options: MapInitOptions): Promise<void> {
365
+ // 初始化您的地图引擎
366
+ // this.map = new MyMapEngine(container, options);
367
+ }
368
+
369
+ dispose(): void {
370
+ // 清理资源
371
+ }
372
+
373
+ getMap(): any {
374
+ return this.map;
375
+ }
376
+
377
+ // 实现其他必要的方法...
378
+ }
379
+
380
+ // 使用自定义适配器
381
+ <GisMapContainer :adapter="new MyCustomAdapter()" />
382
+ ```
383
+
384
+ ### 2. 扩展管理器
385
+
386
+ 您可以通过继承现有管理器或创建新的管理器来扩展功能。
387
+
388
+ ```typescript
389
+ import { VectorTileAdapter } from 'gismap';
390
+
391
+ export class CustomManager {
392
+ private adapter: VectorTileAdapter;
393
+
394
+ constructor(adapter: VectorTileAdapter) {
395
+ this.adapter = adapter;
396
+ }
397
+
398
+ // 实现您的自定义功能
399
+ doSomething() {
400
+ // 使用 this.adapter 操作地图
401
+ }
402
+ }
403
+ ```
404
+
405
+ ### 3. 事件系统
406
+
407
+ GISMap 提供了完善的事件系统,您可以监听各种地图事件。
408
+
409
+ ```typescript
410
+ import { useMapEvent } from 'gismap';
411
+
412
+ // 监听地图点击事件
413
+ useMapEvent('click', (event) => {
414
+ console.log('地图点击:', event.coordinates);
415
+ });
416
+
417
+ // 监听视图变化事件
418
+ useMapEvent('viewChange', (view) => {
419
+ console.log('视图变化:', view);
420
+ });
421
+ ```
422
+
423
+ ## 项目结构
424
+
425
+ ```
426
+ src/
427
+ ├── adapters/ # 地图适配器
428
+ │ ├── mapbox/ # Mapbox GL 适配器
429
+ │ ├── types.ts # 适配器类型定义
430
+ │ └── index.ts # 适配器统一导出
431
+ ├── components/ # Vue 组件
432
+ │ ├── MapContainer/ # 地图容器组件
433
+ │ └── ...
434
+ ├── composables/ # 组合式函数
435
+ │ ├── useMap.ts # 地图核心组合式函数
436
+ │ ├── useLayer.ts # 图层组合式函数
437
+ │ └── ...
438
+ ├── core/ # 核心功能
439
+ │ ├── event.ts # 事件系统
440
+ │ ├── StateStore.ts # 状态管理
441
+ │ └── ...
442
+ ├── domain/ # 领域服务
443
+ │ ├── LayerService.ts # 图层服务
444
+ │ ├── MarkerService.ts # 标记服务
445
+ │ └── ...
446
+ ├── manager/ # 管理器
447
+ │ ├── mapbox/ # Mapbox 专用管理器
448
+ │ ├── layer/ # 图层相关
449
+ │ ├── LayerManager.ts # 图层管理器
450
+ │ ├── RadarManager.ts # 雷达管理器
451
+ │ └── ...
452
+ ├── services/ # 服务
453
+ │ ├── MapContext.ts # 地图上下文
454
+ │ └── ...
455
+ └── index.ts # 主入口
456
+ ```
457
+
458
+ ## 浏览器兼容性
459
+
460
+ - Chrome/Edge >= 88
461
+ - Firefox >= 85
462
+ - Safari >= 14
463
+
464
+ ## 许可证
465
+
466
+ MIT
467
+
468
+ ## 贡献
469
+
470
+ 欢迎提交 Issue 和 Pull Request!
471
+
472
+ ## 联系方式
473
+
474
+ - 项目地址:https://github.com/your-username/gismap
475
+ - 问题反馈:https://github.com/your-username/gismap/issues