shaoxing-geo-tools 0.0.3 → 0.0.5
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 +65 -36
- package/dist/Constant-BZ3rU2jA.js +8 -0
- package/dist/geoToolsWorker-CTS0SJgH.js +16 -0
- package/dist/index.js +173 -126
- package/dist/wasmApi-1NHF35d0.js +566 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,36 +13,25 @@
|
|
|
13
13
|
|
|
14
14
|
## 功能列表
|
|
15
15
|
|
|
16
|
-
### 1. `
|
|
16
|
+
### 1. `setDefault(width, height, ratio)`
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
**设置默认地图视口和边距比例**
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
*大部分情况下无须设置*
|
|
21
|
+
|
|
22
|
+
设置地图视口的默认大小(像素)和边距默认比例,用于 `batchGetSpaceExtra` 和 `batchGetLineExtra` 中的 `zoom` 计算。大部分情况下无需调用,使用默认值即可。
|
|
21
23
|
|
|
22
24
|
| 参数 | 类型 | 默认值 | 说明 |
|
|
23
25
|
|------|------|--------|------|
|
|
24
26
|
| width | number | `4910` | 地图视口宽度(像素) |
|
|
25
27
|
| height | number | `1311` | 地图视口高度(像素) |
|
|
28
|
+
| ratio | number | `0.5` | 边距比例,值越大 `zoom` 越小 |
|
|
26
29
|
|
|
27
|
-
**用途:**
|
|
30
|
+
**用途:** 当地图容器大小或边距需求变化时,通过此函数同步更新默认参数,以确保后续 `zoom` 计算结果准确。
|
|
28
31
|
|
|
29
32
|
---
|
|
30
33
|
|
|
31
|
-
### 2. `
|
|
32
|
-
|
|
33
|
-
**设置边距默认比例**
|
|
34
|
-
|
|
35
|
-
设置用于计算最佳缩放级别的边距默认比例,值越大则缩放级别越小(视野更宽)。
|
|
36
|
-
|
|
37
|
-
| 参数 | 类型 | 默认值 | 说明 |
|
|
38
|
-
|------|------|--------|------|
|
|
39
|
-
| ratio | number | `0.5` | 边距比例,值越大 `bestZoom` 越小 |
|
|
40
|
-
|
|
41
|
-
**用途:** 调整空间/航线在视口中的边距,控制最佳缩放级别的计算结果。
|
|
42
|
-
|
|
43
|
-
---
|
|
44
|
-
|
|
45
|
-
### 3. `getDistricts(geo)`
|
|
34
|
+
### 2. `getDistricts(geo)`
|
|
46
35
|
|
|
47
36
|
**获取行政区划信息**
|
|
48
37
|
|
|
@@ -56,7 +45,7 @@
|
|
|
56
45
|
|
|
57
46
|
---
|
|
58
47
|
|
|
59
|
-
###
|
|
48
|
+
### 3. `checkPoint(geo)`
|
|
60
49
|
|
|
61
50
|
**检查点**
|
|
62
51
|
|
|
@@ -70,7 +59,7 @@
|
|
|
70
59
|
|
|
71
60
|
---
|
|
72
61
|
|
|
73
|
-
###
|
|
62
|
+
### 4. `checkLine(geo)`
|
|
74
63
|
|
|
75
64
|
**检查线**
|
|
76
65
|
|
|
@@ -80,11 +69,11 @@
|
|
|
80
69
|
|------|------|------|
|
|
81
70
|
| geo | GeoJSON | 待检查的线几何对象 |
|
|
82
71
|
|
|
83
|
-
**用途:**
|
|
72
|
+
**用途:** 检查航线、路径等线状要素是否符合空间约束和geoJson标准。
|
|
84
73
|
|
|
85
74
|
---
|
|
86
75
|
|
|
87
|
-
###
|
|
76
|
+
### 5. `checkPolygon(geo)`
|
|
88
77
|
|
|
89
78
|
**检查多边形**
|
|
90
79
|
|
|
@@ -98,7 +87,7 @@
|
|
|
98
87
|
|
|
99
88
|
---
|
|
100
89
|
|
|
101
|
-
###
|
|
90
|
+
### 6. `batchGetCovers(geo_jsons, distances, opacities)`
|
|
102
91
|
|
|
103
92
|
**批量获取覆盖信息**
|
|
104
93
|
|
|
@@ -114,7 +103,7 @@
|
|
|
114
103
|
|
|
115
104
|
---
|
|
116
105
|
|
|
117
|
-
###
|
|
106
|
+
### 7. `batchSimplify(geo_jsons, toleranceMeters)`
|
|
118
107
|
|
|
119
108
|
**批量简化 GeoJSON 数据**
|
|
120
109
|
|
|
@@ -131,7 +120,7 @@
|
|
|
131
120
|
|
|
132
121
|
---
|
|
133
122
|
|
|
134
|
-
###
|
|
123
|
+
### 8. `batchGetSpaceExtra(geo_jsons, mapSizes, paddingRatio)`
|
|
135
124
|
|
|
136
125
|
**批量获取空间额外信息**
|
|
137
126
|
|
|
@@ -149,14 +138,14 @@
|
|
|
149
138
|
|------|------|------|
|
|
150
139
|
| area | number | 空间面积(平方米) |
|
|
151
140
|
| center | [lng, lat] | 空间中心点坐标 |
|
|
152
|
-
|
|
|
141
|
+
| zoom | number | 空间在当前视口下的最佳缩放级别 |
|
|
153
142
|
| cityCodes | string[] | 空间覆盖的区县编码列表 |
|
|
154
143
|
|
|
155
144
|
**用途:** 展示空域信息时,需要面积、中心点、最佳缩放级别等元数据。
|
|
156
145
|
|
|
157
146
|
---
|
|
158
147
|
|
|
159
|
-
###
|
|
148
|
+
### 9. `batchGetLineExtra(geo_jsons, mapSizes, paddingRatio)`
|
|
160
149
|
|
|
161
150
|
**批量获取航线额外信息**
|
|
162
151
|
|
|
@@ -174,33 +163,73 @@
|
|
|
174
163
|
|------|------|------|
|
|
175
164
|
| length | number | 航线长度(米) |
|
|
176
165
|
| center | [lng, lat] | 航线中心点坐标 |
|
|
177
|
-
|
|
|
166
|
+
| zoom | number | 航线在当前视口下的最佳缩放级别 |
|
|
178
167
|
| cityCodes | string[] | 航线经过的区县编码列表 |
|
|
179
168
|
|
|
180
169
|
**用途:** 展示航线时,需要长度、中心点、最佳缩放级别等信息。
|
|
181
170
|
|
|
182
171
|
---
|
|
183
172
|
|
|
173
|
+
### 10. `getCityBoundary(toleranceMeters)`
|
|
174
|
+
|
|
175
|
+
**获取绍兴市边界**
|
|
176
|
+
|
|
177
|
+
从 WASM 中读取绍兴市行政边界 GeoJSON(`FeatureCollection`),可按米为单位设置简化容差来减少数据量。
|
|
178
|
+
|
|
179
|
+
| 参数 | 类型 | 默认值 | 说明 |
|
|
180
|
+
|------|------|--------|------|
|
|
181
|
+
| toleranceMeters | number \| null | `null` | 简化容差(米),不传或传 `null` 返回完整边界 |
|
|
182
|
+
|
|
183
|
+
**返回值:** 解析结果为 `{ valid, message, data }`,`data` 为 `FeatureCollection<Polygon>`。
|
|
184
|
+
|
|
185
|
+
**用途:** 在地图上绘制绍兴市行政边界轮廓,或用于空间分析中的边界参考。
|
|
186
|
+
|
|
187
|
+
---
|
|
188
|
+
|
|
189
|
+
### 11. `getDistrictBoundary(toleranceMeters)`
|
|
190
|
+
|
|
191
|
+
**获取绍兴市各区县边界**
|
|
192
|
+
|
|
193
|
+
从 WASM 中读取绍兴市各区县行政边界 GeoJSON(`FeatureCollection`),每个区县为一个 Feature,可按米为单位设置简化容差。
|
|
194
|
+
|
|
195
|
+
| 参数 | 类型 | 默认值 | 说明 |
|
|
196
|
+
|------|------|--------|------|
|
|
197
|
+
| toleranceMeters | number \| null | `null` | 简化容差(米),不传或传 `null` 返回完整边界 |
|
|
198
|
+
|
|
199
|
+
**返回值:** 解析结果为 `{ valid, message, data }`,`data` 为 `FeatureCollection<Polygon>`。
|
|
200
|
+
|
|
201
|
+
**用途:** 在地图上绘制各区县边界,或按区县维度进行空间统计与分析。
|
|
202
|
+
|
|
203
|
+
---
|
|
204
|
+
|
|
184
205
|
## 使用示例
|
|
185
206
|
```javascript
|
|
186
|
-
import
|
|
187
|
-
|
|
188
|
-
const { setMapSize, setPaddingRatio, getDistricts, batchSimplify, batchGetSpaceExtra } = useGeoTools()
|
|
207
|
+
import { setDefault, getDistricts, batchSimplify, batchGetSpaceExtra, getCityBoundary, getDistrictBoundary } from 'shaoxing-geo-tools'
|
|
189
208
|
|
|
190
|
-
//
|
|
191
|
-
|
|
209
|
+
// 设置默认地图视口和边距比例, 也可以不设置,在 batchGetSpaceExtra 和 batchGetLineExtra 传入[1920, 1080]以及0.5
|
|
210
|
+
// setDefault设置后,batchGetSpaceExtra 和 batchGetLineExtra 中缺省就按设置的走
|
|
192
211
|
|
|
193
|
-
|
|
194
|
-
setPaddingRatio(0.3)
|
|
212
|
+
setDefault(1920, 1080, 0.3)
|
|
195
213
|
|
|
196
214
|
// 获取行政区划
|
|
197
215
|
const districts = await getDistricts(someGeoJson)
|
|
216
|
+
getDistricts(someGeoJson).then(result => {})
|
|
198
217
|
|
|
199
218
|
// 批量简化
|
|
200
219
|
const simplified = await batchSimplify([complexGeoJson], 11)
|
|
220
|
+
batchSimplify([complexGeoJson], 11).then(result => {})
|
|
201
221
|
|
|
202
222
|
// 获取空间信息
|
|
203
223
|
const extras = await batchGetSpaceExtra([polygonGeoJson])
|
|
224
|
+
batchGetSpaceExtra([polygonGeoJson]).then(result => {})
|
|
225
|
+
|
|
226
|
+
// 获取绍兴市边界
|
|
227
|
+
const cityBoundary = await getCityBoundary()
|
|
228
|
+
// 或传入简化容差
|
|
229
|
+
const simplifiedCityBoundary = await getCityBoundary(50)
|
|
230
|
+
|
|
231
|
+
// 获取各区县边界
|
|
232
|
+
const districtBoundary = await getDistrictBoundary()
|
|
204
233
|
```
|
|
205
234
|
|
|
206
235
|
## 架构说明
|