uni-leaflet 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/README.md +383 -0
- package/UniLeafletMap.vue +706 -0
- package/app-render.d.ts +2 -0
- package/app-render.js +550 -0
- package/engine/canvas-tile-engine.ts +1252 -0
- package/engine/factory.ts +101 -0
- package/engine/h5-map-adapter.ts +470 -0
- package/engine/tile-manager.ts +192 -0
- package/index.ts +19 -0
- package/package.json +46 -0
- package/types.ts +159 -0
- package/utils/crs.ts +60 -0
- package/utils/tile.ts +118 -0
package/README.md
ADDED
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
# uni-leaflet
|
|
2
|
+
|
|
3
|
+
🚀 跨端、高性能的 Uni-App (Vue 3 + TypeScript) 地图组件。
|
|
4
|
+
|
|
5
|
+
在 **H5 端** 与 **App 端 (APP-PLUS)** 自动加载成熟强大的 **Leaflet.js** 生态(App 端基于 `renderjs` 独立视图层驱动与手势防抖锁);在 **微信小程序端** 自动无缝切换为纯原生 **Canvas 2D** 瓦片与矢量渲染引擎。一套代码,三端极致体验!
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## ✨ 核心特性
|
|
10
|
+
|
|
11
|
+
- 🌐 **一套代码,跨端自适应**:
|
|
12
|
+
- **H5 端**:采用标准 Leaflet.js DOM 渲染,支持完整 GIS 坐标变换与图层生态。
|
|
13
|
+
- **App 端 (iOS / Android)**:采用 Leaflet.js + Uni-App `renderjs` 架构,配合**手势互斥锁(Anti-Feedback Loop)**与**图层增量 Diff 缓存**,彻底杜绝手势抖动与白屏闪烁,体验媲美原生。
|
|
14
|
+
- **微信小程序端**:采用底层 Canvas 2D 高性能离屏/视口瓦片调度,支持 DPR 高分屏自适应,内置 Canvas 原生矢量缩放控件(零 DOM 遮挡)。
|
|
15
|
+
- 🎨 **丰富多样的图标样式支持 (Marker Icons)**:
|
|
16
|
+
- **Emoji 字符图标**:免网络请求,轻量生动(如 `🏛️`, `🚩`, `☕`)。
|
|
17
|
+
- **PNG / JPG / 本地图片 / 网络 URL**:支持本地 `/static/icons/xxx.png` 相对路径、网络图片或 Base64 Data URI。
|
|
18
|
+
- **SVG 矢量文件**:支持引用 `.svg` 静态文件,无损缩放,高分屏超清晰。
|
|
19
|
+
- **SVG 内联代码**:支持直接传入 `<svg>...</svg>` XML 字符串,支持动态渐变(Gradient)、自定义矢量图案与阴影。
|
|
20
|
+
- **默认矢量 Pin**:内置优雅水滴 Pin,支持自定义主题填充色 (`color`)。
|
|
21
|
+
- 🗺️ **多源底图即开即用**:
|
|
22
|
+
- **高德地图 (AutoNavi)**:道路矢量、卫星影像、路网注记(免 Token 极速加载)。
|
|
23
|
+
- **天地图 (Tianditu)**:矢量/影像/地形底图 + 透明地名道路注记图层叠加(WMTS 标准)。
|
|
24
|
+
- **OpenStreetMap / CartoDB**:浅色/深色极简底图。
|
|
25
|
+
- 📑 **多图层叠加与混合渲染**:支持卫星影像底图 + 透明地名道路注记图层叠加(如天地图 `img_w + cia_w`、高德 `style=6 + style=8`)。
|
|
26
|
+
- 📍 **完整矢量要素与 Label 气泡标注**:
|
|
27
|
+
- **点与图标 (Markers)**:支持自定义尺寸 `size`、精准锚点 `anchor` 与永久/动态悬浮 Label。
|
|
28
|
+
- **折线路线 (Polylines)**:支持实线、虚线 (`dashArray`)、颜色、线宽及中点 Label 标注。
|
|
29
|
+
- **多边形区域 (Polygons)**:支持半透明填充、边框色及几何质心居中 Label 标注。
|
|
30
|
+
- **辐射圆形 (Circles)**:基于米制半径换算像素,支持居中 Label 标注。
|
|
31
|
+
- 👆 **全手势与交互体验**:
|
|
32
|
+
- 单指拖拽平移、双指多点缩放(Pinch Zoom)、双击居中放大、平滑动画平移 (`panTo`)。
|
|
33
|
+
- **PC 端 / 开发者工具鼠标滚轮精准缩放**:以鼠标光标为锚点(Pivot Point),并自动阻止外层页面联动滚动。
|
|
34
|
+
- ⚡ **动态响应式驱动**:深度响应 Vue 3 响应式数据变化,支持接口异步请求后直接更新、追加或清空标注要素。
|
|
35
|
+
- 🛡️ **TypeScript 严格类型支持**:内置完整的类型声明定义。
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## 📱 平台支持
|
|
40
|
+
|
|
41
|
+
| 平台 | 渲染引擎 | 底层机制 | 状态 |
|
|
42
|
+
| :--- | :--- | :--- | :---: |
|
|
43
|
+
| **H5 (Web / Mobile Browser)** | Leaflet.js | 标准 DOM / SVG / Canvas | ✅ 完美支持 |
|
|
44
|
+
| **App (iOS / Android)** | Leaflet.js | `renderjs` 独立 Webview 视图层 + 手势防抖锁 | ✅ 完美支持 |
|
|
45
|
+
| **微信小程序 (MP-WEIXIN)** | Canvas 2D Engine | 原生 Canvas 2D + 视口瓦片调度 | ✅ 完美支持 |
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## 📦 安装
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
# npm
|
|
53
|
+
npm install uni-leaflet leaflet
|
|
54
|
+
|
|
55
|
+
# pnpm
|
|
56
|
+
pnpm add uni-leaflet leaflet
|
|
57
|
+
|
|
58
|
+
# yarn
|
|
59
|
+
yarn add uni-leaflet leaflet
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## 🚀 快速上手
|
|
65
|
+
|
|
66
|
+
### 1. 基础用法 (单文件组件内局部引入)
|
|
67
|
+
|
|
68
|
+
```vue
|
|
69
|
+
<template>
|
|
70
|
+
<view class="map-container">
|
|
71
|
+
<UniLeafletMap
|
|
72
|
+
v-model:center="center"
|
|
73
|
+
v-model:zoom="zoom"
|
|
74
|
+
:tile-url="tileUrl"
|
|
75
|
+
:subdomains="subdomains"
|
|
76
|
+
height="600rpx"
|
|
77
|
+
@click="onMapClick"
|
|
78
|
+
/>
|
|
79
|
+
</view>
|
|
80
|
+
</template>
|
|
81
|
+
|
|
82
|
+
<script setup lang="ts">
|
|
83
|
+
import { ref } from 'vue';
|
|
84
|
+
import { UniLeafletMap } from 'uni-leaflet';
|
|
85
|
+
import type { LatLngTuple } from 'uni-leaflet';
|
|
86
|
+
|
|
87
|
+
const center = ref<LatLngTuple>([39.9042, 116.4074]); // 北京
|
|
88
|
+
const zoom = ref(13);
|
|
89
|
+
|
|
90
|
+
// 高德地图道路矢量切片(免 Token,极速加载)
|
|
91
|
+
const tileUrl = ref('https://wprd0{s}.is.autonavi.com/appmaptile?x={x}&y={y}&z={z}&lang=zh_cn&size=1&scl=1&style=7');
|
|
92
|
+
const subdomains = ref(['1', '2', '3', '4']);
|
|
93
|
+
|
|
94
|
+
function onMapClick(e: any) {
|
|
95
|
+
console.log('点击坐标:', e.latLng);
|
|
96
|
+
}
|
|
97
|
+
</script>
|
|
98
|
+
|
|
99
|
+
<style scoped>
|
|
100
|
+
.map-container {
|
|
101
|
+
width: 100%;
|
|
102
|
+
height: 600rpx;
|
|
103
|
+
}
|
|
104
|
+
</style>
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
### 2. 全局注册 (`main.ts`)
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
import { createSSRApp } from 'vue';
|
|
113
|
+
import App from './App.vue';
|
|
114
|
+
import UniLeaflet from 'uni-leaflet';
|
|
115
|
+
|
|
116
|
+
export function createApp() {
|
|
117
|
+
const app = createSSRApp(App);
|
|
118
|
+
app.use(UniLeaflet); // 全局注册 <UniLeafletMap> 组件
|
|
119
|
+
return { app };
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
### 3. 多图层叠加 (例如:天地图卫星影像 + 文字地名注记)
|
|
126
|
+
|
|
127
|
+
```vue
|
|
128
|
+
<template>
|
|
129
|
+
<UniLeafletMap
|
|
130
|
+
:center="[39.9163, 116.3972]"
|
|
131
|
+
:zoom="13"
|
|
132
|
+
:layers="layers"
|
|
133
|
+
height="100vh"
|
|
134
|
+
/>
|
|
135
|
+
</template>
|
|
136
|
+
|
|
137
|
+
<script setup lang="ts">
|
|
138
|
+
import { ref } from 'vue';
|
|
139
|
+
import { UniLeafletMap } from 'uni-leaflet';
|
|
140
|
+
import type { TileLayerConfig } from 'uni-leaflet';
|
|
141
|
+
|
|
142
|
+
const myTiandituToken = 'YOUR_TIANDITU_TOKEN';
|
|
143
|
+
|
|
144
|
+
const layers = ref<TileLayerConfig[]>([
|
|
145
|
+
// 1. 底层:天地图卫星影像底图 (img_w)
|
|
146
|
+
{
|
|
147
|
+
id: 'img',
|
|
148
|
+
url: `https://t{s}.tianditu.gov.cn/img_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=img&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&tk=${myTiandituToken}`,
|
|
149
|
+
subdomains: ['0', '1', '2', '3', '4', '5', '6', '7'],
|
|
150
|
+
},
|
|
151
|
+
// 2. 顶层:天地图文字地名注记 (cia_w - 透明 PNG)
|
|
152
|
+
{
|
|
153
|
+
id: 'cia',
|
|
154
|
+
url: `https://t{s}.tianditu.gov.cn/cia_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=cia&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&tk=${myTiandituToken}`,
|
|
155
|
+
subdomains: ['0', '1', '2', '3', '4', '5', '6', '7'],
|
|
156
|
+
zIndex: 10,
|
|
157
|
+
},
|
|
158
|
+
]);
|
|
159
|
+
</script>
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
---
|
|
163
|
+
|
|
164
|
+
### 4. 点图标 (Emoji / PNG / SVG 文件 / SVG 内联代码) 及矢量要素
|
|
165
|
+
|
|
166
|
+
```vue
|
|
167
|
+
<template>
|
|
168
|
+
<UniLeafletMap
|
|
169
|
+
ref="mapRef"
|
|
170
|
+
:center="[39.9163, 116.3972]"
|
|
171
|
+
:zoom="14"
|
|
172
|
+
:markers="markers"
|
|
173
|
+
:polylines="polylines"
|
|
174
|
+
:polygons="polygons"
|
|
175
|
+
:circles="circles"
|
|
176
|
+
@overlay-click="onOverlayClick"
|
|
177
|
+
/>
|
|
178
|
+
</template>
|
|
179
|
+
|
|
180
|
+
<script setup lang="ts">
|
|
181
|
+
import { ref } from 'vue';
|
|
182
|
+
import { UniLeafletMap } from 'uni-leaflet';
|
|
183
|
+
import type {
|
|
184
|
+
MarkerOptions,
|
|
185
|
+
PolylineOptions,
|
|
186
|
+
PolygonOptions,
|
|
187
|
+
CircleOptions,
|
|
188
|
+
OverlayClickEvent,
|
|
189
|
+
} from 'uni-leaflet';
|
|
190
|
+
|
|
191
|
+
// 1. 点标注 (支持 Emoji / PNG 图片 / SVG 矢量文件 / SVG 内联代码)
|
|
192
|
+
const markers = ref<MarkerOptions[]>([
|
|
193
|
+
// A. Emoji 字符图标
|
|
194
|
+
{
|
|
195
|
+
id: 'm1',
|
|
196
|
+
latLng: [39.9163, 116.3972],
|
|
197
|
+
title: '故宫博物院',
|
|
198
|
+
icon: { text: '🏛️', size: [34, 34] },
|
|
199
|
+
label: { text: '故宫博物院 (Emoji)', offset: [0, -28] },
|
|
200
|
+
},
|
|
201
|
+
|
|
202
|
+
// B. PNG 图片图标 (支持 static 相对路径、网络 URL 或 Base64)
|
|
203
|
+
{
|
|
204
|
+
id: 'm2',
|
|
205
|
+
latLng: [39.9242, 116.3995],
|
|
206
|
+
title: '景山公园万春亭',
|
|
207
|
+
icon: {
|
|
208
|
+
url: '/static/icons/pin-purple.png',
|
|
209
|
+
size: [32, 40],
|
|
210
|
+
anchor: [16, 40], // 底部尖端对齐
|
|
211
|
+
},
|
|
212
|
+
label: { text: '景山公园万春亭 (PNG)', offset: [0, -32] },
|
|
213
|
+
},
|
|
214
|
+
|
|
215
|
+
// C. SVG 矢量文件图标 (无损缩放,高分屏超清晰)
|
|
216
|
+
{
|
|
217
|
+
id: 'm3',
|
|
218
|
+
latLng: [39.9100, 116.3910],
|
|
219
|
+
title: '中山公园摄影打卡点',
|
|
220
|
+
icon: {
|
|
221
|
+
url: '/static/icons/camera.svg',
|
|
222
|
+
size: [36, 36],
|
|
223
|
+
anchor: [18, 36],
|
|
224
|
+
},
|
|
225
|
+
label: { text: '摄影打卡点 (SVG)', offset: [0, -30] },
|
|
226
|
+
},
|
|
227
|
+
|
|
228
|
+
// D. SVG 内联代码 (直接传入 SVG 标签字符串,支持动态渐变与任意矢量图形)
|
|
229
|
+
{
|
|
230
|
+
id: 'm4',
|
|
231
|
+
latLng: [39.9045, 116.3895],
|
|
232
|
+
title: '国家大剧院',
|
|
233
|
+
icon: {
|
|
234
|
+
svg: `<svg viewBox="0 0 36 36" width="36" height="36">
|
|
235
|
+
<defs>
|
|
236
|
+
<linearGradient id="gTheater" x1="0%" y1="0%" x2="100%" y2="100%">
|
|
237
|
+
<stop offset="0%" stop-color="#ec4899"/>
|
|
238
|
+
<stop offset="100%" stop-color="#8b5cf6"/>
|
|
239
|
+
</linearGradient>
|
|
240
|
+
</defs>
|
|
241
|
+
<circle cx="18" cy="18" r="16" fill="url(#gTheater)" stroke="#ffffff" stroke-width="2"/>
|
|
242
|
+
<text x="18" y="24" font-size="16" text-anchor="middle" fill="#ffffff">🎭</text>
|
|
243
|
+
</svg>`,
|
|
244
|
+
size: [36, 36],
|
|
245
|
+
anchor: [18, 18], // 中心对齐
|
|
246
|
+
},
|
|
247
|
+
label: { text: '国家大剧院 (内联SVG)', offset: [0, -26] },
|
|
248
|
+
},
|
|
249
|
+
]);
|
|
250
|
+
|
|
251
|
+
// 2. 路线折线 (带虚线与中点 Label)
|
|
252
|
+
const polylines = ref<PolylineOptions[]>([
|
|
253
|
+
{
|
|
254
|
+
id: 'l1',
|
|
255
|
+
latLngs: [
|
|
256
|
+
[39.9295, 116.3972],
|
|
257
|
+
[39.9163, 116.3972],
|
|
258
|
+
[39.8985, 116.3972],
|
|
259
|
+
],
|
|
260
|
+
color: '#3b82f6',
|
|
261
|
+
width: 5,
|
|
262
|
+
label: '中轴线景观路线',
|
|
263
|
+
},
|
|
264
|
+
]);
|
|
265
|
+
|
|
266
|
+
// 3. 多边形区域 (带质心 Label)
|
|
267
|
+
const polygons = ref<PolygonOptions[]>([
|
|
268
|
+
{
|
|
269
|
+
id: 'p1',
|
|
270
|
+
latLngs: [
|
|
271
|
+
[39.9240, 116.3915],
|
|
272
|
+
[39.9240, 116.4025],
|
|
273
|
+
[39.9115, 116.4025],
|
|
274
|
+
[39.9115, 116.3915],
|
|
275
|
+
],
|
|
276
|
+
color: '#ef4444',
|
|
277
|
+
fillColor: 'rgba(239, 68, 68, 0.22)',
|
|
278
|
+
label: '故宫紫禁城核心区',
|
|
279
|
+
},
|
|
280
|
+
]);
|
|
281
|
+
|
|
282
|
+
// 4. 圆形辐射范围 (米制半径)
|
|
283
|
+
const circles = ref<CircleOptions[]>([
|
|
284
|
+
{
|
|
285
|
+
id: 'c1',
|
|
286
|
+
latLng: [39.9055, 116.3976],
|
|
287
|
+
radius: 1000, // 1000 米
|
|
288
|
+
color: '#10b981',
|
|
289
|
+
fillColor: 'rgba(16, 185, 129, 0.18)',
|
|
290
|
+
label: '1km 核心辐射圈',
|
|
291
|
+
},
|
|
292
|
+
]);
|
|
293
|
+
|
|
294
|
+
function onOverlayClick(e: OverlayClickEvent) {
|
|
295
|
+
console.log('点击了要素:', e.type, e.data);
|
|
296
|
+
}
|
|
297
|
+
</script>
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
---
|
|
301
|
+
|
|
302
|
+
## 📖 API 参考
|
|
303
|
+
|
|
304
|
+
### Props
|
|
305
|
+
|
|
306
|
+
| 参数 | 类型 | 默认值 | 说明 |
|
|
307
|
+
| :--- | :--- | :--- | :--- |
|
|
308
|
+
| `v-model:center` | `[number, number]` | `[39.9042, 116.4074]` | 地图中心点经纬度 `[纬度, 经度]` |
|
|
309
|
+
| `v-model:zoom` | `number` | `13` | 地图缩放级别 |
|
|
310
|
+
| `min-zoom` | `number` | `3` | 最小缩放层级 |
|
|
311
|
+
| `max-zoom` | `number` | `18` | 最大缩放层级 |
|
|
312
|
+
| `tile-url` | `string` | OSM URL | 单图层瓦片模板地址 |
|
|
313
|
+
| `subdomains` | `string[]` | `['a', 'b', 'c']` | 瓦片子域名轮换配置 |
|
|
314
|
+
| `layers` | `TileLayerConfig[]` | `undefined` | 多图层叠加配置数组(按顺序自底向上叠加) |
|
|
315
|
+
| `markers` | `MarkerOptions[]` | `[]` | 点标注数组 |
|
|
316
|
+
| `polylines` | `PolylineOptions[]` | `[]` | 折线路线数组 |
|
|
317
|
+
| `polygons` | `PolygonOptions[]` | `[]` | 多边形面数组 |
|
|
318
|
+
| `circles` | `CircleOptions[]` | `[]` | 圆形范围数组 |
|
|
319
|
+
| `overlays` | `MapOverlays` | `undefined` | 综合覆盖物对象 |
|
|
320
|
+
| `width` | `string` | `'100%'` | 地图宽度 |
|
|
321
|
+
| `height` | `string` | `'100%'` | 地图高度 |
|
|
322
|
+
| `show-controls` | `boolean` | `true` | 是否显示右上方缩放控件按钮(H5/App 为悬浮组件,小程序为 Canvas 2D 顶层渲染) |
|
|
323
|
+
|
|
324
|
+
---
|
|
325
|
+
|
|
326
|
+
### MarkerIconOptions (图标详细配置)
|
|
327
|
+
|
|
328
|
+
| 字段 | 类型 | 默认值 | 说明 |
|
|
329
|
+
| :--- | :--- | :--- | :--- |
|
|
330
|
+
| `text` | `string` | `undefined` | Emoji 字符或文字图标,如 `'🏛️'`, `'🚩'`, `'☕'` |
|
|
331
|
+
| `url` | `string` | `undefined` | PNG / JPG / SVG 文件路径、网络 URL 或 Base64 Data URI,如 `'/static/icons/pin-blue.png'`、`'/static/icons/camera.svg'` |
|
|
332
|
+
| `svg` | `string` | `undefined` | 原始 SVG XML 字符串,支持动态渐变与任意矢量图形,如 `'<svg viewBox="0 0 36 36">...</svg>'` |
|
|
333
|
+
| `html` | `string` | `undefined` | 自定义 HTML 结构 (仅 H5 与 App renderjs 生效) |
|
|
334
|
+
| `color` | `string` | `'#ef4444'` | 默认矢量 Pin 图钉的主题填充色 |
|
|
335
|
+
| `size` | `[number, number]` | `[32, 32]` | 图标渲染尺寸 `[宽, 高]` (px) |
|
|
336
|
+
| `anchor` | `[number, number]` | 居中或底部 | 图标锚点 `[x, y]`。图钉尖部对齐常用 `[width/2, height]`,圆形徽章居中对齐常用 `[width/2, height/2]` |
|
|
337
|
+
|
|
338
|
+
---
|
|
339
|
+
|
|
340
|
+
### Events
|
|
341
|
+
|
|
342
|
+
| 事件名 | 参数 | 说明 |
|
|
343
|
+
| :--- | :--- | :--- |
|
|
344
|
+
| `@ready` | `(engine: IMapEngine) => void` | 地图引擎初始化完成时触发 |
|
|
345
|
+
| `@click` | `({ latLng, point }) => void` | 点击地图空白区域时触发 |
|
|
346
|
+
| `@move` | `({ center, zoom }) => void` | 地图平移漫游中持续触发 |
|
|
347
|
+
| `@moveend` | `({ center, zoom }) => void` | 地图平移结束时触发 |
|
|
348
|
+
| `@zoom` | `(zoom: number) => void` | 地图缩放中持续触发 |
|
|
349
|
+
| `@zoomend` | `(zoom: number) => void` | 地图缩放结束时触发 |
|
|
350
|
+
| `@overlay-click` | `(event: OverlayClickEvent) => void` | 点击任意点、线、面、圆要素时触发 |
|
|
351
|
+
| `@marker-click` | `(marker: MarkerOptions) => void` | 点击点图标时触发 |
|
|
352
|
+
| `@polyline-click`| `(polyline: PolylineOptions) => void`| 点击折线时触发 |
|
|
353
|
+
| `@polygon-click` | `(polygon: PolygonOptions) => void` | 点击多边形时触发 |
|
|
354
|
+
| `@circle-click` | `(circle: CircleOptions) => void` | 点击圆形时触发 |
|
|
355
|
+
|
|
356
|
+
---
|
|
357
|
+
|
|
358
|
+
### Methods (通过 `ref` 获取实例)
|
|
359
|
+
|
|
360
|
+
| 方法名 | 参数 | 说明 |
|
|
361
|
+
| :--- | :--- | :--- |
|
|
362
|
+
| `setCenter` | `(center: LatLngTuple, animate?: boolean)` | 设置地图中心点 |
|
|
363
|
+
| `setZoom` | `(zoom: number)` | 设置缩放层级 |
|
|
364
|
+
| `zoomIn` | `()` | 放大一级 |
|
|
365
|
+
| `zoomOut` | `()` | 缩小一级 |
|
|
366
|
+
| `panTo` | `(center: LatLngTuple, duration?: number)` | 平滑缓动平移至指定坐标 |
|
|
367
|
+
| `setTileUrl` | `(url: string, subdomains?: string[])` | 切换单底图源 |
|
|
368
|
+
| `setLayers` | `(layers: TileLayerConfig[])` | 动态切换多图层源 |
|
|
369
|
+
| `setMarkers` | `(markers: MarkerOptions[])` | 动态更新点标注 |
|
|
370
|
+
| `setPolylines`| `(polylines: PolylineOptions[])` | 动态更新折线 |
|
|
371
|
+
| `setPolygons` | `(polygons: PolygonOptions[])` | 动态更新多边形 |
|
|
372
|
+
| `setCircles` | `(circles: CircleOptions[])` | 动态更新圆形 |
|
|
373
|
+
| `clearOverlays`| `()` | 清空所有覆盖物 |
|
|
374
|
+
| `resize` | `(width?: number, height?: number)` | 重新计算视口尺寸与 DPR 适配 |
|
|
375
|
+
| `getCenter` | `()` | 获取当前中心点 `[lat, lng]` |
|
|
376
|
+
| `getZoom` | `()` | 获取当前缩放层级 |
|
|
377
|
+
| `getNativeInstance` | `()` | 获取底层原生实例(H5/App 为 Leaflet `L.map`,小程序为 `canvas` 节点) |
|
|
378
|
+
|
|
379
|
+
---
|
|
380
|
+
|
|
381
|
+
## 📄 开源协议
|
|
382
|
+
|
|
383
|
+
[MIT License](LICENSE)
|