@gis_victory/gismap 1.0.57 → 2.0.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/README.md +453 -260
- package/dist/assets/icons//347/251/272/347/275/256/345/216/202/346/210/277.png +0 -0
- package/dist/assets/icons//351/227/262/347/275/256/345/234/260/345/235/227.png +0 -0
- package/dist/gismap.css +1 -1
- package/dist/index.d.ts +5720 -14164
- package/dist/index.es.js +1 -99817
- package/dist/index.umd.js +1 -36
- package/package.json +57 -52
- package/dist/assets/icons/arrow.png +0 -1
- package/dist/assets/icons/fh_bz.png +0 -0
- package/dist/assets/icons/fh_df.png +0 -0
- package/dist/assets/icons/fh_ht.png +0 -0
- package/dist/assets/icons/fh_sk.png +0 -0
- package/dist/assets/icons/fh_st.png +0 -0
- package/dist/assets/icons/fh_sz.png +0 -0
- package/dist/assets/icons/fh_yq.png +0 -0
- package/dist/assets/icons/fy_bfg.png +0 -0
- package/dist/assets/icons/fy_dwyld.png +0 -0
- package/dist/assets/icons/fy_dxkj.png +0 -0
- package/dist/assets/icons/fy_dzzhyhd_czd.png +0 -0
- package/dist/assets/icons/fy_dzzhyhd_yb.png +0 -0
- package/dist/assets/icons/fy_dzzhyhd_zd.png +0 -0
- package/dist/assets/icons/fy_jzgd.png +0 -0
- package/dist/assets/icons/fy_lyjq.png +0 -0
- package/dist/assets/icons/fy_shzhyfq_dw.png +0 -0
- package/dist/assets/icons/fy_shzhyfq_gw.png +0 -0
- package/dist/assets/icons/fy_shzhyfq_jd.png +0 -0
- package/dist/assets/icons/fy_whqy.png +0 -0
- package/dist/assets/icons/fy_wjf_c.png +0 -0
- package/dist/assets/icons/fy_wjf_d.png +0 -0
- package/dist/assets/icons/fy_xcsljq.png +0 -0
- package/dist/assets/icons/fy_xx.png +0 -0
- package/dist/assets/icons/fy_yly.png +0 -0
- package/dist/assets/icons/fy_yy.png +0 -0
- package/dist/assets/icons/fy_zrc.png +0 -0
- package/dist/assets/icons/jc_dzzhjcsb.png +0 -0
- package/dist/assets/icons/jc_jsjcsb.png +0 -0
- package/dist/assets/icons/jc_qxz.png +0 -0
- package/dist/assets/icons/jc_spjk.png +0 -0
- package/dist/assets/icons/jc_swcz.png +0 -0
- package/dist/assets/icons/jc_xdyjsb.png +0 -0
- package/dist/assets/icons/point.png +0 -0
- package/dist/assets/icons/xzq.png +0 -0
- package/dist/assets/icons/xzq_cwh_bzd.png +0 -0
- package/dist/assets/icons/xzq_cwh_bzd_wzck.png +0 -0
- package/dist/assets/icons/xzq_cwh_wzck.png +0 -0
- package/dist/assets/icons/xzq_cwh_yfxc.png +0 -0
- package/dist/assets/icons/xzq_sf.png +0 -0
- package/dist/assets/icons/xzq_shengzf.png +0 -0
- package/dist/assets/icons/xzq_szf.png +0 -0
- package/dist/assets/icons/xzq_xzf.png +0 -0
- package/dist/assets/icons/xzq_xzqh.png +0 -0
- package/dist/assets/icons/xzq_zrc.png +0 -0
- package/dist/assets/icons/xzqh.png +0 -0
- package/dist/assets/icons/yj_bzazcs.png +0 -0
- package/dist/assets/icons/yj_hkjyd.png +0 -0
- package/dist/assets/icons/yj_shjydw.png +0 -0
- package/dist/assets/icons/yj_yjjydw.png +0 -0
- package/dist/assets/icons/yj_yjwzck.png +0 -0
- package/dist/assets/legend/xzq_zrc.png +0 -0
package/README.md
CHANGED
|
@@ -1,350 +1,543 @@
|
|
|
1
|
-
#
|
|
1
|
+
# GISMap - 通用地图组件库
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
GISMap 是一个基于适配器模式设计的通用地图组件库,支持多种地图引擎(如 Mapbox GL、MapLibre 等),提供统一的 API 接口和丰富的功能模块。
|
|
4
4
|
|
|
5
5
|
## 特性
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
- 📍 标记和弹窗
|
|
13
|
-
- 📊 图例和数据可视化
|
|
14
|
-
- 🔄 地图切换和扩展
|
|
7
|
+
- **多引擎支持**:通过适配器模式,支持不同的地图引擎
|
|
8
|
+
- **丰富的管理器**:提供图层、标记、雷达、地形、绘制、测量等多种管理器
|
|
9
|
+
- **响应式设计**:基于 Vue 3 的 Composition API,提供响应式的地图状态管理
|
|
10
|
+
- **模块化架构**:清晰的代码结构,易于扩展和维护
|
|
11
|
+
- **TypeScript 支持**:完整的类型定义,提供良好的开发体验
|
|
15
12
|
|
|
16
13
|
## 安装
|
|
17
14
|
|
|
18
15
|
```bash
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
# 使用 npm
|
|
17
|
+
npm install gismap
|
|
18
|
+
|
|
19
|
+
# 使用 yarn
|
|
20
|
+
yarn add gismap
|
|
21
|
+
|
|
22
|
+
# 使用 pnpm
|
|
23
|
+
pnpm add gismap
|
|
22
24
|
```
|
|
23
25
|
|
|
24
|
-
##
|
|
26
|
+
## 基本使用
|
|
25
27
|
|
|
26
|
-
###
|
|
28
|
+
### 1. 基础地图组件
|
|
27
29
|
|
|
28
30
|
```vue
|
|
29
31
|
<template>
|
|
30
|
-
<
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
<GisMapCompass />
|
|
41
|
-
</template>
|
|
42
|
-
</MapContainer>
|
|
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>
|
|
43
42
|
</template>
|
|
44
43
|
|
|
45
44
|
<script setup lang="ts">
|
|
46
|
-
import {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
glyphs: "http://www.gisx.work/map-assets/fonts/{fontstack}/{range}.pbf",
|
|
45
|
+
import { GisMapContainer } from 'gismap';
|
|
46
|
+
|
|
47
|
+
// 初始化图标配置
|
|
48
|
+
const initIcons = [
|
|
49
|
+
{
|
|
50
|
+
name: 'marker-icon',
|
|
51
|
+
url: 'https://example.com/marker.png'
|
|
54
52
|
},
|
|
55
|
-
|
|
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
|
+
### 3. 使用 MapSwitch 组件
|
|
98
|
+
|
|
99
|
+
```vue
|
|
100
|
+
<template>
|
|
101
|
+
<div style="width: 100vw; height: 100vh; position: relative;">
|
|
102
|
+
<!-- 地图容器 -->
|
|
103
|
+
<GisMapContainer
|
|
104
|
+
:center="[120, 30]"
|
|
105
|
+
:zoom="10"
|
|
106
|
+
:access-token="'your-mapbox-access-token'"
|
|
107
|
+
>
|
|
108
|
+
<!-- 地图切换组件 -->
|
|
109
|
+
<template #top-right>
|
|
110
|
+
<GisMapSwitch :data="mapSwitchData" />
|
|
111
|
+
</template>
|
|
112
|
+
</GisMapContainer>
|
|
113
|
+
</div>
|
|
114
|
+
</template>
|
|
115
|
+
|
|
116
|
+
<script setup lang="ts">
|
|
117
|
+
import { ref } from 'vue';
|
|
118
|
+
import { GisMapContainer, GisMapSwitch } from 'gismap';
|
|
119
|
+
|
|
120
|
+
// 地图切换数据
|
|
121
|
+
const mapSwitchData = ref({
|
|
122
|
+
// 底图图层
|
|
123
|
+
layers: [
|
|
56
124
|
{
|
|
57
|
-
name: '
|
|
58
|
-
label:
|
|
59
|
-
|
|
125
|
+
name: 'tdt-vec',
|
|
126
|
+
label: '矢量底图',
|
|
127
|
+
checked: true,
|
|
128
|
+
iconName: 'Picture'
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
name: 'tdt-img',
|
|
132
|
+
label: '影像底图',
|
|
133
|
+
checked: false,
|
|
134
|
+
iconName: 'Camera'
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
name: 'custom-layer',
|
|
138
|
+
label: '自定义底图',
|
|
139
|
+
checked: false,
|
|
140
|
+
iconName: 'Map'
|
|
141
|
+
}
|
|
142
|
+
],
|
|
143
|
+
// 叠加图层
|
|
144
|
+
extensions: [
|
|
145
|
+
{
|
|
146
|
+
name: 'tdt-cia',
|
|
147
|
+
label: '天地图注记',
|
|
148
|
+
checked: true
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
name: 'terrain',
|
|
152
|
+
label: '地形',
|
|
153
|
+
checked: false
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
name: 'custom-extension',
|
|
157
|
+
label: '自定义叠加层',
|
|
158
|
+
checked: false
|
|
60
159
|
}
|
|
61
|
-
// 更多图标配置...
|
|
62
160
|
]
|
|
63
161
|
});
|
|
162
|
+
</script>
|
|
163
|
+
```
|
|
64
164
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
165
|
+
## 核心功能
|
|
166
|
+
|
|
167
|
+
### 1. 图层管理
|
|
168
|
+
|
|
169
|
+
```typescript
|
|
170
|
+
import { useLayers } from 'gismap';
|
|
171
|
+
|
|
172
|
+
const { addLayer, removeLayer, layers } = useLayers();
|
|
173
|
+
|
|
174
|
+
// 添加 GeoJSON 图层
|
|
175
|
+
const layer = addLayer({
|
|
176
|
+
id: 'points',
|
|
177
|
+
type: 'circle',
|
|
178
|
+
source: {
|
|
179
|
+
type: 'geojson',
|
|
180
|
+
data: {
|
|
181
|
+
type: 'FeatureCollection',
|
|
182
|
+
features: [
|
|
183
|
+
{
|
|
184
|
+
type: 'Feature',
|
|
185
|
+
geometry: {
|
|
186
|
+
type: 'Point',
|
|
187
|
+
coordinates: [120, 30]
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
]
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
paint: {
|
|
194
|
+
'circle-radius': 10,
|
|
195
|
+
'circle-color': '#ff0000'
|
|
196
|
+
}
|
|
82
197
|
});
|
|
83
198
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
199
|
+
// 移除图层
|
|
200
|
+
removeLayer(layer.id);
|
|
201
|
+
```
|
|
87
202
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
};
|
|
92
|
-
|
|
203
|
+
### 2. 标记管理
|
|
204
|
+
|
|
205
|
+
```typescript
|
|
206
|
+
import { useMarkers } from 'gismap';
|
|
207
|
+
|
|
208
|
+
const { add, remove, getAll } = useMarkers();
|
|
209
|
+
|
|
210
|
+
// 添加标记
|
|
211
|
+
const marker = add({
|
|
212
|
+
id: 'marker-1',
|
|
213
|
+
position: [120, 30],
|
|
214
|
+
options: {
|
|
215
|
+
draggable: true,
|
|
216
|
+
anchor: 'bottom'
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
// 移除标记
|
|
221
|
+
remove('marker-1');
|
|
222
|
+
|
|
223
|
+
// 获取所有标记
|
|
224
|
+
const allMarkers = getAll();
|
|
93
225
|
```
|
|
94
226
|
|
|
95
|
-
|
|
227
|
+
### 3. 绘制功能
|
|
96
228
|
|
|
97
|
-
|
|
229
|
+
```typescript
|
|
230
|
+
import { useDraw } from 'gismap';
|
|
98
231
|
|
|
99
|
-
|
|
100
|
-
|-------|------|------|
|
|
101
|
-
| `MapContainer` | 地图容器,包含所有地图组件 | `<MapContainer :mapViewData="mapViewData" @load="onMapLoad" />` |
|
|
102
|
-
| `GisMapView` | 地图视图组件 | `<GisMapView :mapViewData="mapViewData" />` |
|
|
103
|
-
| `GisMapLayer` | 地图图层管理组件 | `<GisMapLayer :layerData="layerData" />` |
|
|
104
|
-
| `GisMapLegend` | 地图图例组件 | `<GisMapLegend />` |
|
|
105
|
-
| `GisMapTools` | 地图工具组件 | `<GisMapTools :toolsData="toolsData" />` |
|
|
106
|
-
| `GisMapSwitch` | 地图切换组件 | `<GisMapSwitch :switchData="switchData" />` |
|
|
107
|
-
| `GisMapSearch` | 地图搜索组件 | `<GisMapSearch :searchData="searchData" />` |
|
|
232
|
+
const { startDraw, stopDraw, isDrawing, selected } = useDraw();
|
|
108
233
|
|
|
109
|
-
|
|
234
|
+
// 开始绘制多边形
|
|
235
|
+
startDraw('polygon', (type, geoJson, wkt, feature) => {
|
|
236
|
+
console.log('绘制完成:', type, geoJson, wkt);
|
|
237
|
+
});
|
|
110
238
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
| `GisMapPopupBar` | 弹窗工具栏组件 | `<GisMapPopupBar>` |
|
|
115
|
-
| `GisMapPopupBarItem` | 弹窗工具栏项组件 | `<GisMapPopupBarItem label="示例" />` |
|
|
239
|
+
// 停止绘制
|
|
240
|
+
stopDraw();
|
|
241
|
+
```
|
|
116
242
|
|
|
117
|
-
###
|
|
243
|
+
### 4. 测量功能
|
|
118
244
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
| `MobileMapLayer` | 移动端地图图层组件 | `<MobileMapLayer>` |
|
|
122
|
-
| `MobileBaseLayerSwitch` | 移动端底图切换组件 | `<MobileBaseLayerSwitch :data="layersData" />` |
|
|
245
|
+
```typescript
|
|
246
|
+
import { useMeasure } from 'gismap';
|
|
123
247
|
|
|
124
|
-
|
|
248
|
+
const { startMeasure, stopMeasure, isMeasuring, results } = useMeasure();
|
|
125
249
|
|
|
126
|
-
|
|
250
|
+
// 开始测量距离
|
|
251
|
+
startMeasure('line', (result) => {
|
|
252
|
+
console.log('测量结果:', result.value, result.unit);
|
|
253
|
+
});
|
|
127
254
|
|
|
128
|
-
|
|
255
|
+
// 停止测量
|
|
256
|
+
stopMeasure();
|
|
257
|
+
```
|
|
129
258
|
|
|
130
|
-
|
|
131
|
-
|-------|------|------|--------|
|
|
132
|
-
| `mapViewData` | `Object` | 地图视图配置 | `{}` |
|
|
133
|
-
| `switchData` | `Object` | 地图切换配置 | `{}` |
|
|
134
|
-
| `layerData` | `Array` | 图层数据 | `[]` |
|
|
135
|
-
| `toolsData` | `Array` | 工具数据 | `[]` |
|
|
136
|
-
| `searchData` | `Array` | 搜索数据 | `[]` |
|
|
259
|
+
### 5. 雷达图层
|
|
137
260
|
|
|
138
|
-
|
|
261
|
+
```typescript
|
|
262
|
+
import { useMap } from 'gismap';
|
|
139
263
|
|
|
140
|
-
|
|
141
|
-
|-------|------|------|
|
|
142
|
-
| `load` | `map: GSMap` | 地图加载完成事件 |
|
|
264
|
+
const { radarManager } = useMap();
|
|
143
265
|
|
|
144
|
-
|
|
266
|
+
// 添加雷达
|
|
267
|
+
radarManager.value?.add({
|
|
268
|
+
center: [120, 30],
|
|
269
|
+
radius: 500,
|
|
270
|
+
sectorVisible: true,
|
|
271
|
+
sectorAngle: 45
|
|
272
|
+
});
|
|
145
273
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
| `bottom-left` | 地图左下角插槽 |
|
|
149
|
-
| `bottom-right` | 地图右下角插槽 |
|
|
150
|
-
| `top-left` | 地图左上角插槽 |
|
|
151
|
-
| `top-right` | 地图右上角插槽 |
|
|
274
|
+
// 开始扫描
|
|
275
|
+
radarManager.value?.startScan();
|
|
152
276
|
|
|
153
|
-
|
|
277
|
+
// 停止扫描
|
|
278
|
+
radarManager.value?.stopScan();
|
|
154
279
|
|
|
155
|
-
|
|
280
|
+
// 移除雷达
|
|
281
|
+
radarManager.value?.remove();
|
|
282
|
+
```
|
|
156
283
|
|
|
157
|
-
|
|
158
|
-
|-------|------|------|
|
|
159
|
-
| `pubsub.on` | `event: string, callback: Function` | 订阅地图事件 |
|
|
160
|
-
| `pubsub.emit` | `event: string, data: any` | 发布地图事件 |
|
|
161
|
-
| `manager.templateManager.add` | `id: string, template: string` | 添加模板 |
|
|
162
|
-
| `manager.maskManager.add` | `data: string` | 添加遮罩 |
|
|
284
|
+
### 6. 地形管理
|
|
163
285
|
|
|
164
|
-
|
|
286
|
+
```typescript
|
|
287
|
+
import { useMap } from 'gismap';
|
|
165
288
|
|
|
166
|
-
|
|
289
|
+
const { terrainManager } = useMap();
|
|
167
290
|
|
|
168
|
-
|
|
169
|
-
{
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
291
|
+
// 添加地形
|
|
292
|
+
terrainManager.value?.add({
|
|
293
|
+
source: {
|
|
294
|
+
tiles: ['https://example.com/terrain/{z}/{x}/{y}.png'],
|
|
295
|
+
minzoom: 0,
|
|
296
|
+
maxzoom: 14
|
|
174
297
|
},
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
298
|
+
layer: {
|
|
299
|
+
exaggeration: 1.5
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
// 添加山体阴影
|
|
304
|
+
terrainManager.value?.addHillshade();
|
|
305
|
+
|
|
306
|
+
// 移除地形
|
|
307
|
+
terrainManager.value?.remove();
|
|
183
308
|
```
|
|
184
309
|
|
|
185
|
-
###
|
|
310
|
+
### 7. 图标管理
|
|
186
311
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
312
|
+
#### 最佳实践:在地图初始化完成后立即加载图标
|
|
313
|
+
|
|
314
|
+
为了确保地图能够正确读取图标,应该在地图初始化完成后立即加载图标。推荐使用 `useMapReady` 组合式函数来监听地图就绪事件:
|
|
315
|
+
|
|
316
|
+
```typescript
|
|
317
|
+
import { useMapReady } from 'gismap';
|
|
318
|
+
|
|
319
|
+
// 在地图就绪后立即加载图标
|
|
320
|
+
useMapReady(async (context) => {
|
|
321
|
+
try {
|
|
322
|
+
// 批量加载图标
|
|
323
|
+
await context.iconManager?.load([
|
|
324
|
+
{
|
|
325
|
+
name: 'marker-icon',
|
|
326
|
+
url: 'https://example.com/marker.png'
|
|
327
|
+
},
|
|
328
|
+
{
|
|
329
|
+
name: 'icon-2',
|
|
330
|
+
url: 'https://example.com/icon2.png'
|
|
331
|
+
}
|
|
332
|
+
], {
|
|
333
|
+
batchSize: 5, // 每批加载5个图标
|
|
334
|
+
batchInterval: 100, // 每批间隔100毫秒
|
|
335
|
+
onProgress: (loaded, total) => {
|
|
336
|
+
console.log(`加载进度: ${loaded}/${total}`);
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
console.log('图标加载完成');
|
|
341
|
+
|
|
342
|
+
// 图标加载完成后,再添加使用图标的图层
|
|
343
|
+
addIconLayer(context);
|
|
344
|
+
} catch (error) {
|
|
345
|
+
console.error('图标加载失败:', error);
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
// 添加使用图标的图层
|
|
350
|
+
function addIconLayer(context) {
|
|
351
|
+
if (context?.layerManager) {
|
|
352
|
+
context.layerManager.addLayer({
|
|
353
|
+
id: 'icon-layer',
|
|
354
|
+
type: 'symbol',
|
|
355
|
+
source: {
|
|
356
|
+
type: 'geojson',
|
|
357
|
+
data: {
|
|
358
|
+
type: 'FeatureCollection',
|
|
359
|
+
features: [
|
|
360
|
+
{
|
|
361
|
+
type: 'Feature',
|
|
362
|
+
geometry: {
|
|
363
|
+
type: 'Point',
|
|
364
|
+
coordinates: [120, 30]
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
]
|
|
205
368
|
}
|
|
369
|
+
},
|
|
370
|
+
layout: {
|
|
371
|
+
'icon-image': 'marker-icon', // 使用已加载的图标
|
|
372
|
+
'icon-size': 1.5
|
|
206
373
|
}
|
|
207
|
-
}
|
|
208
|
-
|
|
374
|
+
});
|
|
375
|
+
}
|
|
209
376
|
}
|
|
210
377
|
```
|
|
211
378
|
|
|
212
|
-
|
|
379
|
+
#### 其他用法
|
|
213
380
|
|
|
214
|
-
|
|
381
|
+
```typescript
|
|
382
|
+
import { useMap } from 'gismap';
|
|
215
383
|
|
|
216
|
-
|
|
217
|
-
<template>
|
|
218
|
-
<MapContainer
|
|
219
|
-
:mapViewData="mapViewData"
|
|
220
|
-
:switchData="switchData"
|
|
221
|
-
:layerData="layerData"
|
|
222
|
-
:toolsData="toolsData"
|
|
223
|
-
:searchData="searchData"
|
|
224
|
-
@load="onMapLoad"
|
|
225
|
-
>
|
|
226
|
-
<template #bottom-left>
|
|
227
|
-
<GisMapCompass />
|
|
228
|
-
</template>
|
|
229
|
-
<template #top-right>
|
|
230
|
-
<MobileMapLayer>
|
|
231
|
-
<MobileBaseLayerSwitch :data="switchData.layers" />
|
|
232
|
-
</MobileMapLayer>
|
|
233
|
-
</template>
|
|
234
|
-
</MapContainer>
|
|
235
|
-
</template>
|
|
384
|
+
const { iconManager } = useMap();
|
|
236
385
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
zoom: 9,
|
|
243
|
-
center: [120.65677441301864, 29.745141743380103],
|
|
244
|
-
style: {
|
|
245
|
-
glyphs: "http://www.gisx.work/map-assets/fonts/{fontstack}/{range}.pbf",
|
|
386
|
+
// 批量加载图标(基本用法)
|
|
387
|
+
iconManager.value?.load([
|
|
388
|
+
{
|
|
389
|
+
name: 'marker-icon',
|
|
390
|
+
url: 'https://example.com/marker.png'
|
|
246
391
|
},
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
]
|
|
392
|
+
{
|
|
393
|
+
name: 'icon-2',
|
|
394
|
+
url: 'https://example.com/icon2.png'
|
|
395
|
+
}
|
|
396
|
+
]).then(() => {
|
|
397
|
+
console.log('图标加载完成');
|
|
254
398
|
});
|
|
255
399
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
}, {
|
|
263
|
-
name: "tdt-img",
|
|
264
|
-
label: "卫星影像",
|
|
265
|
-
iconName: "satellite",
|
|
266
|
-
checked: false
|
|
267
|
-
}],
|
|
268
|
-
extensions: [{
|
|
269
|
-
name: "tdt-cia",
|
|
270
|
-
label: "注记",
|
|
271
|
-
checked: true,
|
|
272
|
-
}]
|
|
400
|
+
// 加载单个图标
|
|
401
|
+
iconManager.value?.loadOne({
|
|
402
|
+
name: 'single-icon',
|
|
403
|
+
url: 'https://example.com/single.png'
|
|
404
|
+
}).then(() => {
|
|
405
|
+
console.log('单个图标加载完成');
|
|
273
406
|
});
|
|
274
407
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
let map: GSMap;
|
|
280
|
-
const onMapLoad = (_map: GSMap) => {
|
|
281
|
-
map = _map;
|
|
282
|
-
// 地图加载完成后的操作
|
|
283
|
-
map.pubsub.on('layer:click', ({ templateId, feature }: { templateId: string, feature: any }) => {
|
|
284
|
-
const template = map.manager?.templateManager?.renderHtml(templateId, feature.properties);
|
|
285
|
-
if (template) {
|
|
286
|
-
map.manager?.popupManager.show({
|
|
287
|
-
position: feature.geometry.coordinates,
|
|
288
|
-
html: template,
|
|
289
|
-
});
|
|
290
|
-
}
|
|
291
|
-
});
|
|
292
|
-
};
|
|
408
|
+
// 检查图标是否已加载
|
|
409
|
+
if (iconManager.value?.hasIcon('marker-icon')) {
|
|
410
|
+
console.log('图标已加载');
|
|
411
|
+
}
|
|
293
412
|
|
|
294
|
-
//
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
413
|
+
// 移除图标
|
|
414
|
+
iconManager.value?.removeIcon('marker-icon');
|
|
415
|
+
|
|
416
|
+
// 清除所有图标记录
|
|
417
|
+
iconManager.value?.clear();
|
|
299
418
|
```
|
|
300
419
|
|
|
301
|
-
##
|
|
420
|
+
## 高级功能
|
|
302
421
|
|
|
303
|
-
###
|
|
422
|
+
### 1. 自定义适配器
|
|
304
423
|
|
|
305
|
-
|
|
424
|
+
您可以通过实现 `MapAdapter` 或 `VectorTileAdapter` 接口来创建自定义适配器,支持其他地图引擎。
|
|
306
425
|
|
|
307
|
-
```
|
|
308
|
-
|
|
309
|
-
cd gismap
|
|
310
|
-
```
|
|
426
|
+
```typescript
|
|
427
|
+
import type { MapAdapter, MapInitOptions, MapViewState } from 'gismap';
|
|
311
428
|
|
|
312
|
-
|
|
429
|
+
export class MyCustomAdapter implements MapAdapter {
|
|
430
|
+
private map: any = null;
|
|
313
431
|
|
|
314
|
-
|
|
315
|
-
|
|
432
|
+
async initialize(container: HTMLElement, options: MapInitOptions): Promise<void> {
|
|
433
|
+
// 初始化您的地图引擎
|
|
434
|
+
// this.map = new MyMapEngine(container, options);
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
dispose(): void {
|
|
438
|
+
// 清理资源
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
getMap(): any {
|
|
442
|
+
return this.map;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
// 实现其他必要的方法...
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
// 使用自定义适配器
|
|
449
|
+
<GisMapContainer :adapter="new MyCustomAdapter()" />
|
|
316
450
|
```
|
|
317
451
|
|
|
318
|
-
|
|
452
|
+
### 2. 扩展管理器
|
|
319
453
|
|
|
320
|
-
|
|
321
|
-
|
|
454
|
+
您可以通过继承现有管理器或创建新的管理器来扩展功能。
|
|
455
|
+
|
|
456
|
+
```typescript
|
|
457
|
+
import { VectorTileAdapter } from 'gismap';
|
|
458
|
+
|
|
459
|
+
export class CustomManager {
|
|
460
|
+
private adapter: VectorTileAdapter;
|
|
461
|
+
|
|
462
|
+
constructor(adapter: VectorTileAdapter) {
|
|
463
|
+
this.adapter = adapter;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
// 实现您的自定义功能
|
|
467
|
+
doSomething() {
|
|
468
|
+
// 使用 this.adapter 操作地图
|
|
469
|
+
}
|
|
470
|
+
}
|
|
322
471
|
```
|
|
323
472
|
|
|
324
|
-
|
|
473
|
+
### 3. 事件系统
|
|
325
474
|
|
|
326
|
-
|
|
327
|
-
|
|
475
|
+
GISMap 提供了完善的事件系统,您可以监听各种地图事件。
|
|
476
|
+
|
|
477
|
+
```typescript
|
|
478
|
+
import { useMapEvent } from 'gismap';
|
|
479
|
+
|
|
480
|
+
// 监听地图点击事件
|
|
481
|
+
useMapEvent('click', (event) => {
|
|
482
|
+
console.log('地图点击:', event.coordinates);
|
|
483
|
+
});
|
|
484
|
+
|
|
485
|
+
// 监听视图变化事件
|
|
486
|
+
useMapEvent('viewChange', (view) => {
|
|
487
|
+
console.log('视图变化:', view);
|
|
488
|
+
});
|
|
328
489
|
```
|
|
329
490
|
|
|
330
|
-
|
|
491
|
+
## 项目结构
|
|
331
492
|
|
|
332
|
-
```
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
#
|
|
336
|
-
|
|
337
|
-
#
|
|
338
|
-
|
|
493
|
+
```
|
|
494
|
+
src/
|
|
495
|
+
├── adapters/ # 地图适配器
|
|
496
|
+
│ ├── mapbox/ # Mapbox GL 适配器
|
|
497
|
+
│ ├── types.ts # 适配器类型定义
|
|
498
|
+
│ └── index.ts # 适配器统一导出
|
|
499
|
+
├── components/ # Vue 组件
|
|
500
|
+
│ ├── MapContainer/ # 地图容器组件
|
|
501
|
+
│ └── ...
|
|
502
|
+
├── composables/ # 组合式函数
|
|
503
|
+
│ ├── useMap.ts # 地图核心组合式函数
|
|
504
|
+
│ ├── useLayer.ts # 图层组合式函数
|
|
505
|
+
│ └── ...
|
|
506
|
+
├── core/ # 核心功能
|
|
507
|
+
│ ├── event.ts # 事件系统
|
|
508
|
+
│ ├── StateStore.ts # 状态管理
|
|
509
|
+
│ └── ...
|
|
510
|
+
├── domain/ # 领域服务
|
|
511
|
+
│ ├── LayerService.ts # 图层服务
|
|
512
|
+
│ ├── MarkerService.ts # 标记服务
|
|
513
|
+
│ └── ...
|
|
514
|
+
├── manager/ # 管理器
|
|
515
|
+
│ ├── mapbox/ # Mapbox 专用管理器
|
|
516
|
+
│ ├── layer/ # 图层相关
|
|
517
|
+
│ ├── LayerManager.ts # 图层管理器
|
|
518
|
+
│ ├── RadarManager.ts # 雷达管理器
|
|
519
|
+
│ └── ...
|
|
520
|
+
├── services/ # 服务
|
|
521
|
+
│ ├── MapContext.ts # 地图上下文
|
|
522
|
+
│ └── ...
|
|
523
|
+
└── index.ts # 主入口
|
|
339
524
|
```
|
|
340
525
|
|
|
341
526
|
## 浏览器兼容性
|
|
342
527
|
|
|
343
|
-
- Chrome
|
|
344
|
-
- Firefox
|
|
345
|
-
- Safari
|
|
346
|
-
- Edge (最新版本)
|
|
528
|
+
- Chrome/Edge >= 88
|
|
529
|
+
- Firefox >= 85
|
|
530
|
+
- Safari >= 14
|
|
347
531
|
|
|
348
532
|
## 许可证
|
|
349
533
|
|
|
350
534
|
MIT
|
|
535
|
+
|
|
536
|
+
## 贡献
|
|
537
|
+
|
|
538
|
+
欢迎提交 Issue 和 Pull Request!
|
|
539
|
+
|
|
540
|
+
## 联系方式
|
|
541
|
+
|
|
542
|
+
- 项目地址:https://github.com/your-username/gismap
|
|
543
|
+
- 问题反馈:https://github.com/your-username/gismap/issues
|