qm-map-maplibre-gl 0.0.8 → 0.1.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 +386 -162
- package/dist/index.d.ts +11 -3
- package/dist/maplibregl/MapWrapper.d.ts +1 -1
- package/dist/maplibregl/measure/BaseMeasure.d.ts +83 -0
- package/dist/maplibregl/measure/PolygonMeasure.d.ts +43 -0
- package/dist/maplibregl/measure/PolylineMeasure.d.ts +40 -0
- package/dist/maplibregl/measure/measureUtil.d.ts +33 -0
- package/dist/qm-map.css +1 -1
- package/dist/qm-map.es.js +743 -401
- package/dist/qm-map.umd.js +4 -4
- package/dist/widget/Clear/index.d.ts +2 -4
- package/dist/widget/Draw/index.d.ts +2 -15
- package/dist/widget/FullScreen/index.d.ts +3 -0
- package/dist/widget/LayerList/index.d.ts +2 -4
- package/dist/widget/Legend/index.d.ts +2 -4
- package/dist/widget/MeasureLine/index.d.ts +3 -0
- package/dist/widget/MeasurePolygon/index.d.ts +3 -0
- package/dist/widget/Print/index.d.ts +2 -4
- package/dist/widget/Swipe/index.d.ts +2 -4
- package/dist/widget/WidgetButton/index.d.ts +9 -0
- package/dist/widget/ZoomIn/index.d.ts +3 -0
- package/dist/widget/ZoomOut/index.d.ts +3 -0
- package/dist/widget/{Draw/constant.d.ts → constant.d.ts} +51 -0
- package/package.json +2 -2
- package/dist/widget/BaseWidget/index.d.ts +0 -26
package/README.md
CHANGED
|
@@ -1,162 +1,386 @@
|
|
|
1
|
-
# qm-map-maplibre-gl
|
|
2
|
-
|
|
3
|
-
基于 MapLibre GL 和 React 的地图组件库,提供丰富的地图交互组件。
|
|
4
|
-
|
|
5
|
-
## 安装
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
npm install qm-map-maplibre-gl
|
|
9
|
-
# 或
|
|
10
|
-
yarn add qm-map-maplibre-gl
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
## 依赖
|
|
14
|
-
|
|
15
|
-
- React >= 19.0.0
|
|
16
|
-
- React DOM >= 19.0.0
|
|
17
|
-
- MapLibre GL >= 5.0.0
|
|
18
|
-
|
|
19
|
-
## 快速开始
|
|
20
|
-
|
|
21
|
-
```tsx
|
|
22
|
-
import { MapWidget, LayerList, Legend } from 'qm-map-maplibre-gl';
|
|
23
|
-
import 'qm-map-maplibre-gl/dist/qm-map.css'
|
|
24
|
-
import type { LngLatLike } from 'maplibre-gl';
|
|
25
|
-
|
|
26
|
-
function App() {
|
|
27
|
-
const mapOptions = {
|
|
28
|
-
id: 'myMap',
|
|
29
|
-
center: [115.415, 33.254] as LngLatLike,
|
|
30
|
-
zoom: 9.5,
|
|
31
|
-
maxZoom: 18,
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
return (
|
|
35
|
-
<MapWidget mapOptions={mapOptions} mapLayerSettting={layerSetting}>
|
|
36
|
-
<LayerList
|
|
37
|
-
<Legend
|
|
38
|
-
</MapWidget>
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
##
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
1
|
+
# qm-map-maplibre-gl
|
|
2
|
+
|
|
3
|
+
基于 MapLibre GL 和 React 的地图组件库,提供丰富的地图交互组件。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install qm-map-maplibre-gl
|
|
9
|
+
# 或
|
|
10
|
+
yarn add qm-map-maplibre-gl
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## 依赖
|
|
14
|
+
|
|
15
|
+
- React >= 19.0.0
|
|
16
|
+
- React DOM >= 19.0.0
|
|
17
|
+
- MapLibre GL >= 5.0.0
|
|
18
|
+
|
|
19
|
+
## 快速开始
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
import { MapWidget, LayerList, Legend } from 'qm-map-maplibre-gl';
|
|
23
|
+
import 'qm-map-maplibre-gl/dist/qm-map.css'
|
|
24
|
+
import type { LngLatLike } from 'maplibre-gl';
|
|
25
|
+
|
|
26
|
+
function App() {
|
|
27
|
+
const mapOptions = {
|
|
28
|
+
id: 'myMap',
|
|
29
|
+
center: [115.415, 33.254] as LngLatLike,
|
|
30
|
+
zoom: 9.5,
|
|
31
|
+
maxZoom: 18,
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<MapWidget mapOptions={mapOptions} mapLayerSettting={layerSetting}>
|
|
36
|
+
<LayerList style={{ top: 10, left: 10 }} />
|
|
37
|
+
<Legend style={{ bottom: 10, left: 10 }} />
|
|
38
|
+
</MapWidget>
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## 通用控件属性 TWidgetProps
|
|
44
|
+
|
|
45
|
+
所有控件组件统一接收以下通用属性,通过 `style` 定位、`close` 控制显隐:
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
type TWidgetProps = {
|
|
49
|
+
/** 是否关闭(隐藏)控件,默认 false */
|
|
50
|
+
close?: boolean;
|
|
51
|
+
/** 自定义类名 */
|
|
52
|
+
classname?: string;
|
|
53
|
+
/** 样式,用于 absolute 定位 */
|
|
54
|
+
style?: CSSProperties;
|
|
55
|
+
/** 交互回调 */
|
|
56
|
+
onCallback?: (value?: any) => void;
|
|
57
|
+
};
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
面板类控件(LayerList、Legend、Swipe、Print)配合 [WidgetButton](#widgetbutton) 使用:按钮切换显隐状态,通过 `close` 传入控件。
|
|
61
|
+
|
|
62
|
+
## 组件列表
|
|
63
|
+
|
|
64
|
+
### MapWidget
|
|
65
|
+
地图容器组件,所有其他组件必须包裹在其中。
|
|
66
|
+
|
|
67
|
+
```tsx
|
|
68
|
+
interface TMapProps {
|
|
69
|
+
mapOptions: TMapOptions;
|
|
70
|
+
mapLayerSettting: TMapLayerSettting;
|
|
71
|
+
children?: React.ReactNode;
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### WidgetButton
|
|
76
|
+
轻量图标按钮组件,用于切换面板类控件的显隐:
|
|
77
|
+
|
|
78
|
+
```tsx
|
|
79
|
+
import { WidgetButton } from 'qm-map-maplibre-gl';
|
|
80
|
+
|
|
81
|
+
<WidgetButton
|
|
82
|
+
title="图层控制"
|
|
83
|
+
style={{ top: 10, left: 10 }}
|
|
84
|
+
icon={WIDGETICONS.LayerList}
|
|
85
|
+
onToggle={() => setLayerOpen((prev) => !prev)}
|
|
86
|
+
/>
|
|
87
|
+
<LayerList close={layerOpen} />
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
**Props:**
|
|
91
|
+
|
|
92
|
+
| 属性 | 类型 | 必填 | 说明 |
|
|
93
|
+
|------|------|------|------|
|
|
94
|
+
| icon | string | 是 | 按钮图标(图片地址,内置图标见 `lib/widget/constant.ts` 的 `WIDGETICONS`) |
|
|
95
|
+
| title | string | 否 | 悬停提示 |
|
|
96
|
+
| onToggle | (value: boolean) => void | 否 | 点击回调 |
|
|
97
|
+
| classname | string | 否 | 自定义类名 |
|
|
98
|
+
| style | CSSProperties | 否 | 样式定位 |
|
|
99
|
+
|
|
100
|
+
### LayerList
|
|
101
|
+
图层列表组件,显示和控制地图图层可见性(树形勾选)。
|
|
102
|
+
|
|
103
|
+
```tsx
|
|
104
|
+
<LayerList
|
|
105
|
+
style={{ top: 10, left: 10 }}
|
|
106
|
+
close={!layerOpen}
|
|
107
|
+
onCallback={(checkedKeys) => console.log('勾选的图层:', checkedKeys)}
|
|
108
|
+
/>
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
**Props:**
|
|
112
|
+
|
|
113
|
+
| 属性 | 类型 | 必填 | 说明 |
|
|
114
|
+
|------|------|------|------|
|
|
115
|
+
| close | boolean | 否 | 是否隐藏 |
|
|
116
|
+
| classname | string | 否 | 自定义类名 |
|
|
117
|
+
| style | CSSProperties | 否 | 样式定位 |
|
|
118
|
+
| onCallback | (checkedKeys: string[]) => void | 否 | 勾选变化回调,返回勾选的图层 id |
|
|
119
|
+
|
|
120
|
+
### Legend
|
|
121
|
+
图例组件,显示地图图例信息(依据图层配置的 `legend` 字段渲染)。
|
|
122
|
+
|
|
123
|
+
```tsx
|
|
124
|
+
<Legend style={{ bottom: 10, left: 10 }} close={false} />
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
**Props:**
|
|
128
|
+
|
|
129
|
+
| 属性 | 类型 | 必填 | 说明 |
|
|
130
|
+
|------|------|------|------|
|
|
131
|
+
| close | boolean | 否 | 是否隐藏 |
|
|
132
|
+
| classname | string | 否 | 自定义类名 |
|
|
133
|
+
| style | CSSProperties | 否 | 样式定位 |
|
|
134
|
+
|
|
135
|
+
### Draw
|
|
136
|
+
地图绘制组件,支持绘制点、线、面,绘制结果含初始要素。
|
|
137
|
+
|
|
138
|
+
```tsx
|
|
139
|
+
import DrawWidget from 'qm-map-maplibre-gl';
|
|
140
|
+
|
|
141
|
+
const onDraw = (res: TDrawResult) => {
|
|
142
|
+
console.log('绘制数据:', res.data);
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
// 基础用法
|
|
146
|
+
<Draw
|
|
147
|
+
style={{ bottom: 10, right: 10 }}
|
|
148
|
+
onDraw={onDraw}
|
|
149
|
+
/>
|
|
150
|
+
|
|
151
|
+
// 限制绘制模式
|
|
152
|
+
<Draw
|
|
153
|
+
modes={['draw_point', 'draw_polygon']}
|
|
154
|
+
style={{ bottom: 10, right: 10 }}
|
|
155
|
+
onDraw={onDraw}
|
|
156
|
+
/>
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
**Props:**
|
|
160
|
+
|
|
161
|
+
| 属性 | 类型 | 必填 | 说明 |
|
|
162
|
+
|------|------|------|------|
|
|
163
|
+
| close | boolean | 否 | 是否隐藏 |
|
|
164
|
+
| classname | string | 否 | 自定义类名 |
|
|
165
|
+
| style | CSSProperties | 否 | 样式定位 |
|
|
166
|
+
| onDraw | (result: TDrawResult) => void | 否 | 绘制/修改/删除完成回调 |
|
|
167
|
+
| modes | TDrawModeType[] | 否 | 允许的绘制模式,默认全部 |
|
|
168
|
+
| initFeature | FeatureCollection | 否 | 初始绘制数据 |
|
|
169
|
+
|
|
170
|
+
**绘制模式:**
|
|
171
|
+
- `'draw_point'` - 绘制点
|
|
172
|
+
- `'draw_line_string'` - 绘制线
|
|
173
|
+
- `'draw_polygon'` - 绘制多边形
|
|
174
|
+
- `'simple_select'` - 选择模式(清除工具始终保留)
|
|
175
|
+
|
|
176
|
+
### Clear
|
|
177
|
+
清除控件,点击清除地图上所有选中对象。
|
|
178
|
+
|
|
179
|
+
```tsx
|
|
180
|
+
<Clear style={{ top: 230, right: 10 }} onCallback={() => console.log('已清除')} />
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
**Props:**
|
|
184
|
+
|
|
185
|
+
| 属性 | 类型 | 必填 | 说明 |
|
|
186
|
+
|------|------|------|------|
|
|
187
|
+
| close | boolean | 否 | 是否隐藏 |
|
|
188
|
+
| classname | string | 否 | 自定义类名 |
|
|
189
|
+
| style | CSSProperties | 否 | 样式定位 |
|
|
190
|
+
| onCallback | () => void | 否 | 清除完成回调 |
|
|
191
|
+
|
|
192
|
+
### Swipe
|
|
193
|
+
地图分屏对比组件,点击按钮弹出模态框,内含左右两张联动地图进行卷帘对比。
|
|
194
|
+
|
|
195
|
+
```tsx
|
|
196
|
+
const [swipeOpen, setSwipeOpen] = useState(false);
|
|
197
|
+
|
|
198
|
+
<WidgetButton
|
|
199
|
+
title="卷帘对比"
|
|
200
|
+
style={{ top: 180, right: 10 }}
|
|
201
|
+
icon={WIDGETICONS.Swipe}
|
|
202
|
+
onToggle={() => setSwipeOpen((prev) => !prev)}
|
|
203
|
+
/>
|
|
204
|
+
<Swipe close={!swipeOpen} onCallback={(value) => setSwipeOpen(value)} />
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
**Props:**
|
|
208
|
+
|
|
209
|
+
| 属性 | 类型 | 必填 | 说明 |
|
|
210
|
+
|------|------|------|------|
|
|
211
|
+
| close | boolean | 否 | 是否关闭弹窗 |
|
|
212
|
+
| classname | string | 否 | 自定义类名 |
|
|
213
|
+
| style | CSSProperties | 否 | 弹窗样式定位 |
|
|
214
|
+
| onCallback | (open: boolean) => void | 否 | 关闭弹窗回调 |
|
|
215
|
+
|
|
216
|
+
### Print
|
|
217
|
+
地图打印组件,面板式导出:支持页面尺寸(A2~A6、B2~B6、Letter)、布局方向(横向/纵向)、导出格式(PDF/PNG/SVG/JPEG)、DPI(72~400),导出内容含指北针。
|
|
218
|
+
|
|
219
|
+
```tsx
|
|
220
|
+
const [printOpen, setPrintOpen] = useState(false);
|
|
221
|
+
|
|
222
|
+
<WidgetButton
|
|
223
|
+
title="地图打印"
|
|
224
|
+
style={{ top: 10, right: 10 }}
|
|
225
|
+
icon={WIDGETICONS.Print}
|
|
226
|
+
onToggle={() => setPrintOpen((prev) => !prev)}
|
|
227
|
+
/>
|
|
228
|
+
<Print close={printOpen} style={{ right: 50, top: 10 }} />
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
**Props:**
|
|
232
|
+
|
|
233
|
+
| 属性 | 类型 | 必填 | 说明 |
|
|
234
|
+
|------|------|------|------|
|
|
235
|
+
| close | boolean | 否 | 是否隐藏面板 |
|
|
236
|
+
| classname | string | 否 | 自定义类名 |
|
|
237
|
+
| style | CSSProperties | 否 | 样式定位 |
|
|
238
|
+
| onCallback | () => void | 否 | 导出完成回调 |
|
|
239
|
+
|
|
240
|
+
### FullScreen
|
|
241
|
+
全屏控件,点击进入/退出整页全屏。
|
|
242
|
+
|
|
243
|
+
```tsx
|
|
244
|
+
<FullScreen style={{ top: 350, right: 10 }} />
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
**Props:**
|
|
248
|
+
|
|
249
|
+
| 属性 | 类型 | 必填 | 说明 |
|
|
250
|
+
|------|------|------|------|
|
|
251
|
+
| close | boolean | 否 | 是否隐藏 |
|
|
252
|
+
| classname | string | 否 | 自定义类名 |
|
|
253
|
+
| style | CSSProperties | 否 | 样式定位 |
|
|
254
|
+
| onCallback | () => void | 否 | 全屏切换回调 |
|
|
255
|
+
|
|
256
|
+
### ZoomIn / ZoomOut
|
|
257
|
+
地图缩放控件,点击缩放级别 ±1。
|
|
258
|
+
|
|
259
|
+
```tsx
|
|
260
|
+
<ZoomIn style={{ top: 390, right: 10 }} />
|
|
261
|
+
<ZoomOut style={{ top: 430, right: 10 }} />
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
**Props:**
|
|
265
|
+
|
|
266
|
+
| 属性 | 类型 | 必填 | 说明 |
|
|
267
|
+
|------|------|------|------|
|
|
268
|
+
| close | boolean | 否 | 是否隐藏 |
|
|
269
|
+
| classname | string | 否 | 自定义类名 |
|
|
270
|
+
| style | CSSProperties | 否 | 样式定位 |
|
|
271
|
+
| onCallback | () => void | 否 | 缩放回调 |
|
|
272
|
+
|
|
273
|
+
### MeasureLine
|
|
274
|
+
测距控件,点击开始测量距离,双击结束。
|
|
275
|
+
|
|
276
|
+
```tsx
|
|
277
|
+
<MeasureLine
|
|
278
|
+
style={{ top: 270, right: 10 }}
|
|
279
|
+
onMeasure={(result: TMeasureResult) => console.log(result)}
|
|
280
|
+
/>
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
**Props:**
|
|
284
|
+
|
|
285
|
+
| 属性 | 类型 | 必填 | 说明 |
|
|
286
|
+
|------|------|------|------|
|
|
287
|
+
| close | boolean | 否 | 是否隐藏 |
|
|
288
|
+
| classname | string | 否 | 自定义类名 |
|
|
289
|
+
| style | CSSProperties | 否 | 样式定位 |
|
|
290
|
+
| onMeasure | (result: TMeasureResult) => void | 否 | 测量完成回调(双击结束时触发) |
|
|
291
|
+
|
|
292
|
+
### MeasurePolygon
|
|
293
|
+
测面控件,点击开始测量面积,双击结束。
|
|
294
|
+
|
|
295
|
+
```tsx
|
|
296
|
+
<MeasurePolygon
|
|
297
|
+
style={{ top: 310, right: 10 }}
|
|
298
|
+
unit="mu"
|
|
299
|
+
onMeasure={(result: TMeasureResult) => console.log(result)}
|
|
300
|
+
/>
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
**Props:**
|
|
304
|
+
|
|
305
|
+
| 属性 | 类型 | 必填 | 说明 |
|
|
306
|
+
|------|------|------|------|
|
|
307
|
+
| close | boolean | 否 | 是否隐藏 |
|
|
308
|
+
| classname | string | 否 | 自定义类名 |
|
|
309
|
+
| style | CSSProperties | 否 | 样式定位 |
|
|
310
|
+
| unit | 'mu' \| 'm2' | 否 | 面积单位,默认 'mu'(亩) |
|
|
311
|
+
| onMeasure | (result: TMeasureResult) => void | 否 | 测量完成回调(双击结束时触发) |
|
|
312
|
+
|
|
313
|
+
**测量结果 TMeasureResult:**
|
|
314
|
+
|
|
315
|
+
| 字段 | 类型 | 说明 |
|
|
316
|
+
|------|------|------|
|
|
317
|
+
| type | 'line' \| 'polygon' | 测量类型 |
|
|
318
|
+
| points | [number, number][] | 采集的坐标点([lng, lat],含双击结束点) |
|
|
319
|
+
| value | number | 原始数值:line 为 km;polygon 为 m² |
|
|
320
|
+
| formatted | string | 格式化文本(如 '1.23km'、'12.3456亩') |
|
|
321
|
+
|
|
322
|
+
## 测量类与工具函数
|
|
323
|
+
|
|
324
|
+
测量类也可脱离 React 组件直接使用:
|
|
325
|
+
|
|
326
|
+
```tsx
|
|
327
|
+
import { PolylineMeasure, PolygonMeasure } from 'qm-map-maplibre-gl';
|
|
328
|
+
|
|
329
|
+
// 测距
|
|
330
|
+
const measure = new PolylineMeasure(map, (result) => console.log(result));
|
|
331
|
+
measure.start();
|
|
332
|
+
// 双击结束测量,measure.clearMeasure() 清理
|
|
333
|
+
|
|
334
|
+
// 测面(unit: 'mu' 亩 | 'm2' 平方米)
|
|
335
|
+
const polygonMeasure = new PolygonMeasure(map, 'mu', (result) => console.log(result));
|
|
336
|
+
polygonMeasure.start();
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
工具函数:`haversineDistance`(两点距离 km)、`polylineLengthKm`(折线总长 km)、`polygonAreaM2`(多边形面积 m²)、`formatDistance`、`formatArea`。
|
|
340
|
+
|
|
341
|
+
## 类型导出
|
|
342
|
+
|
|
343
|
+
```tsx
|
|
344
|
+
import type {
|
|
345
|
+
TMapProps,
|
|
346
|
+
TWidgetProps,
|
|
347
|
+
TWidgetMeasureProps,
|
|
348
|
+
TWidgetDrawProps,
|
|
349
|
+
TDrawResult,
|
|
350
|
+
TDrawModeType,
|
|
351
|
+
TDrawMode,
|
|
352
|
+
TMapOptions,
|
|
353
|
+
TMapLayerSettting,
|
|
354
|
+
TMeasureResult,
|
|
355
|
+
TMeasurePoint,
|
|
356
|
+
TMeasureUnit
|
|
357
|
+
} from 'qm-map-maplibre-gl';
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
## 工具 Hooks
|
|
361
|
+
|
|
362
|
+
### useMap
|
|
363
|
+
获取地图实例上下文。
|
|
364
|
+
|
|
365
|
+
```tsx
|
|
366
|
+
import { useMap } from 'qm-map-maplibre-gl';
|
|
367
|
+
|
|
368
|
+
function MyComponent() {
|
|
369
|
+
const { map } = useMap();
|
|
370
|
+
|
|
371
|
+
// 使用 map 实例
|
|
372
|
+
const handleClick = () => {
|
|
373
|
+
map?.flyTo({ center: [116, 39], zoom: 10 });
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
return <button onClick={handleClick}>飞行到</button>;
|
|
377
|
+
}
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
## 样式
|
|
381
|
+
|
|
382
|
+
组件库已内置样式,无需额外引入 CSS 文件。
|
|
383
|
+
|
|
384
|
+
## License
|
|
385
|
+
|
|
386
|
+
MIT
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export { default as BaseWidget } from './widget/BaseWidget';
|
|
2
1
|
export { default as MapWidget } from './widget/MapWidget';
|
|
3
2
|
export { default as LayerList } from './widget/LayerList';
|
|
4
3
|
export { default as Legend } from './widget/Legend';
|
|
@@ -6,16 +5,25 @@ export { default as Print } from './widget/Print';
|
|
|
6
5
|
export { default as Swipe } from './widget/Swipe';
|
|
7
6
|
export { default as Draw } from './widget/Draw';
|
|
8
7
|
export { default as Clear } from './widget/Clear';
|
|
9
|
-
export
|
|
8
|
+
export { default as FullScreen } from './widget/FullScreen';
|
|
9
|
+
export { default as ZoomIn } from './widget/ZoomIn';
|
|
10
|
+
export { default as ZoomOut } from './widget/ZoomOut';
|
|
11
|
+
export { default as MeasureLine } from './widget/MeasureLine';
|
|
12
|
+
export { default as MeasurePolygon } from './widget/MeasurePolygon';
|
|
10
13
|
export type { TMapProps } from './widget/MapWidget';
|
|
11
|
-
export type { TDrawResult,
|
|
14
|
+
export type { TDrawResult, TDrawModeType, TWidgetProps, TWidgetMeasureProps, TWidgetDrawProps, TDrawMode } from './widget/constant';
|
|
12
15
|
export { default as BaseLayer } from './maplibregl/layer/BaseLayer';
|
|
13
16
|
export { default as LayerGroupWrapper } from './maplibregl/layer/LayerGroupWrapper';
|
|
14
17
|
export { default as LayerWrapper } from './maplibregl/layer/LayerWrapper';
|
|
15
18
|
export { default as MapWrapper } from './maplibregl/MapWrapper';
|
|
19
|
+
export { default as BaseMeasure } from './maplibregl/measure/BaseMeasure';
|
|
20
|
+
export { default as PolylineMeasure } from './maplibregl/measure/PolylineMeasure';
|
|
21
|
+
export { default as PolygonMeasure } from './maplibregl/measure/PolygonMeasure';
|
|
22
|
+
export { haversineDistance, polylineLengthKm, polygonAreaM2, formatDistance, formatArea, } from './maplibregl/measure/measureUtil';
|
|
16
23
|
export { useMap } from './context/mapContext';
|
|
17
24
|
export { MapContext } from './context/mapContext';
|
|
18
25
|
export type { MapEvent, MapEventData } from './maplibregl/typings/TEvent';
|
|
19
26
|
export type { TMapContext } from './context/mapContext';
|
|
27
|
+
export type { TMeasureResult, TMeasurePoint, TMeasureUnit, } from './maplibregl/measure/BaseMeasure';
|
|
20
28
|
export type { TMapLayerSettting, TLegendItemOptions, TLegendControlOptions, TLayerOptions, TLayerGroupOptions, TLayerSetingOptions, } from './maplibregl/typings/TLayerOptions';
|
|
21
29
|
export type { TMapOptions } from './maplibregl/typings/TMapOptions';
|
|
@@ -64,7 +64,7 @@ declare class MapWrapper extends Map {
|
|
|
64
64
|
* 在地图上显示选中的 GeoJSON 要素
|
|
65
65
|
* @param geo - GeoJSON 要素或要素集合
|
|
66
66
|
*/
|
|
67
|
-
selectFeature(geo: GeoJSON.Feature<GeoJSON.Geometry> | GeoJSON.FeatureCollection<GeoJSON.Geometry> | string
|
|
67
|
+
selectFeature(geo: GeoJSON.Feature<GeoJSON.Geometry> | GeoJSON.FeatureCollection<GeoJSON.Geometry> | string): void;
|
|
68
68
|
/**
|
|
69
69
|
* 清除选中要素的高亮显示
|
|
70
70
|
*/
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { Marker, MapMouseEvent } from 'maplibre-gl';
|
|
2
|
+
import { default as MapWrapper } from '../MapWrapper';
|
|
3
|
+
/** 经纬度坐标点 [lng, lat] */
|
|
4
|
+
export type TMeasurePoint = [number, number];
|
|
5
|
+
/** 面积单位:'mu' 亩 | 'm2' 平方米 */
|
|
6
|
+
export type TMeasureUnit = 'mu' | 'm2';
|
|
7
|
+
/**
|
|
8
|
+
* 测量完成回调结果
|
|
9
|
+
*/
|
|
10
|
+
export interface TMeasureResult {
|
|
11
|
+
/** 测量类型 */
|
|
12
|
+
type: 'line' | 'polygon';
|
|
13
|
+
/** 采集的坐标点(含双击结束点) */
|
|
14
|
+
points: TMeasurePoint[];
|
|
15
|
+
/** 原始数值:line 为 km;polygon 为 m² */
|
|
16
|
+
value: number;
|
|
17
|
+
/** 格式化文本(与地图 tooltip 一致) */
|
|
18
|
+
formatted: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* 测量基类
|
|
22
|
+
* 封装测量交互公共逻辑:事件注册、光标切换、tooltip 与关闭按钮、清理
|
|
23
|
+
*/
|
|
24
|
+
declare abstract class BaseMeasure {
|
|
25
|
+
protected map: MapWrapper;
|
|
26
|
+
protected uuid: string;
|
|
27
|
+
protected isMeasure: boolean;
|
|
28
|
+
protected points: TMeasurePoint[];
|
|
29
|
+
/** 所有 Marker(tooltip、每点标签、关闭按钮) */
|
|
30
|
+
protected markers: Marker[];
|
|
31
|
+
/** tooltip 的 DOM 元素 */
|
|
32
|
+
protected ele: HTMLDivElement;
|
|
33
|
+
protected tooltip: Marker;
|
|
34
|
+
protected onMeasure?: (result: TMeasureResult) => void;
|
|
35
|
+
/** 宿主页面缩放比例(适配 3D 沙箱场景) */
|
|
36
|
+
protected scale: number;
|
|
37
|
+
/** 测量前 doubleClickZoom 的启用状态,清理时恢复 */
|
|
38
|
+
private prevDoubleClickZoom;
|
|
39
|
+
constructor(map: MapWrapper, onMeasure?: (result: TMeasureResult) => void);
|
|
40
|
+
/**
|
|
41
|
+
* 生成唯一 ID
|
|
42
|
+
*/
|
|
43
|
+
generateId(): string;
|
|
44
|
+
/**
|
|
45
|
+
* 开始测量:禁用双击缩放、切换十字光标、注册地图事件
|
|
46
|
+
*/
|
|
47
|
+
start(): void;
|
|
48
|
+
/**
|
|
49
|
+
* 移除地图事件监听
|
|
50
|
+
*/
|
|
51
|
+
clearDrawEventListener(): void;
|
|
52
|
+
/**
|
|
53
|
+
* 清理所有测量痕迹并恢复地图状态(幂等,可重复调用)
|
|
54
|
+
*/
|
|
55
|
+
clearMeasure(): void;
|
|
56
|
+
/**
|
|
57
|
+
* 双击收尾:结束测量、移除 tooltip、添加关闭按钮、触发 onMeasure 回调
|
|
58
|
+
* @param coords - 结束点坐标
|
|
59
|
+
*/
|
|
60
|
+
protected finishMeasure(coords: TMeasurePoint): void;
|
|
61
|
+
/**
|
|
62
|
+
* 像素坐标转经纬度(除以宿主页面缩放比例)
|
|
63
|
+
* @param e - 地图鼠标事件
|
|
64
|
+
* @returns [lng, lat]
|
|
65
|
+
*/
|
|
66
|
+
protected getCoords(e: MapMouseEvent): TMeasurePoint;
|
|
67
|
+
/** 创建测量图层与数据源 */
|
|
68
|
+
protected abstract createLayers(): void;
|
|
69
|
+
/** 移除测量图层与数据源 */
|
|
70
|
+
protected abstract removeLayers(): void;
|
|
71
|
+
/** tooltip 实时文本 */
|
|
72
|
+
protected abstract getFormatText(coords: TMeasurePoint): string;
|
|
73
|
+
/** 测量结果原始数值(line: km;polygon: m²) */
|
|
74
|
+
protected abstract getResultValue(): number;
|
|
75
|
+
/** 测量结果格式化文本 */
|
|
76
|
+
protected abstract getResultText(): string;
|
|
77
|
+
/** 测量类型 */
|
|
78
|
+
protected abstract getMeasureType(): 'line' | 'polygon';
|
|
79
|
+
protected abstract mapClickHandle: (e: MapMouseEvent) => void;
|
|
80
|
+
protected abstract mapMouseMoveHandle: (e: MapMouseEvent) => void;
|
|
81
|
+
protected abstract mapDbclickHandle: (e: MapMouseEvent) => void;
|
|
82
|
+
}
|
|
83
|
+
export default BaseMeasure;
|