shaoxing-geo-tools 0.0.5 → 0.0.7

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.
Files changed (3) hide show
  1. package/README.md +11 -11
  2. package/dist/index.d.ts +172 -0
  3. package/package.json +4 -2
package/README.md CHANGED
@@ -204,32 +204,32 @@
204
204
 
205
205
  ## 使用示例
206
206
  ```javascript
207
- import { setDefault, getDistricts, batchSimplify, batchGetSpaceExtra, getCityBoundary, getDistrictBoundary } from 'shaoxing-geo-tools'
207
+ import geoTools from 'shaoxing-geo-tools'
208
208
 
209
209
  // 设置默认地图视口和边距比例, 也可以不设置,在 batchGetSpaceExtra 和 batchGetLineExtra 传入[1920, 1080]以及0.5
210
210
  // setDefault设置后,batchGetSpaceExtra 和 batchGetLineExtra 中缺省就按设置的走
211
211
 
212
- setDefault(1920, 1080, 0.3)
212
+ geoTools.setDefault(1920, 1080, 0.3)
213
213
 
214
214
  // 获取行政区划
215
- const districts = await getDistricts(someGeoJson)
216
- getDistricts(someGeoJson).then(result => {})
215
+ const districts = await geoTools.getDistricts(someGeoJson)
216
+ geoTools.getDistricts(someGeoJson).then(result => {})
217
217
 
218
218
  // 批量简化
219
- const simplified = await batchSimplify([complexGeoJson], 11)
220
- batchSimplify([complexGeoJson], 11).then(result => {})
219
+ const simplified = await geoTools.batchSimplify([complexGeoJson], 11)
220
+ geoTools.batchSimplify([complexGeoJson], 11).then(result => {})
221
221
 
222
222
  // 获取空间信息
223
- const extras = await batchGetSpaceExtra([polygonGeoJson])
224
- batchGetSpaceExtra([polygonGeoJson]).then(result => {})
223
+ const extras = await geoTools.batchGetSpaceExtra([polygonGeoJson])
224
+ geoTools.batchGetSpaceExtra([polygonGeoJson]).then(result => {})
225
225
 
226
226
  // 获取绍兴市边界
227
- const cityBoundary = await getCityBoundary()
227
+ const cityBoundary = await geoTools.getCityBoundary()
228
228
  // 或传入简化容差
229
- const simplifiedCityBoundary = await getCityBoundary(50)
229
+ const simplifiedCityBoundary = await geoTools.getCityBoundary(50)
230
230
 
231
231
  // 获取各区县边界
232
- const districtBoundary = await getDistrictBoundary()
232
+ const districtBoundary = await geoTools.getDistrictBoundary()
233
233
  ```
234
234
 
235
235
  ## 架构说明
@@ -0,0 +1,172 @@
1
+ /** 操作结果,由 WASM 返回 */
2
+ export interface GeoResult<T = any> {
3
+ /** 是否成功 */
4
+ valid: boolean
5
+ /** 错误信息(valid 为 true 时为空字符串) */
6
+ message: string
7
+ /** 返回数据 */
8
+ data: T | null
9
+ }
10
+
11
+ /** 空间额外信息 */
12
+ export interface SpaceExtra {
13
+ /** 空间面积(平方米) */
14
+ area: number
15
+ /** 空间中心点坐标 */
16
+ center: [lng: number, lat: number]
17
+ /** 空间在当前视口下的最佳缩放级别 */
18
+ zoom: number
19
+ /** 空间覆盖的区县编码列表 */
20
+ cityCodes: string[]
21
+ }
22
+
23
+ /** 航线额外信息 */
24
+ export interface LineExtra {
25
+ /** 航线长度(米) */
26
+ length: number
27
+ /** 航线中心点坐标 */
28
+ center: [lng: number, lat: number]
29
+ /** 航线在当前视口下的最佳缩放级别 */
30
+ zoom: number
31
+ /** 航线经过的区县编码列表 */
32
+ cityCodes: string[]
33
+ }
34
+
35
+ export interface GeoTools {
36
+ /**
37
+ * 设置默认地图视口和边距比例
38
+ *
39
+ * 用于 batchGetSpaceExtra 和 batchGetLineExtra 中的 zoom 计算。
40
+ * 大部分情况下无需调用,使用默认值即可。
41
+ *
42
+ * @param width - 地图视口宽度(像素),默认 4910
43
+ * @param height - 地图视口高度(像素),默认 1311
44
+ * @param ratio - 边距比例,值越大 zoom 越小,默认 0.5
45
+ */
46
+ setDefault(width: number, height: number, ratio: number): void
47
+
48
+ /**
49
+ * 获取行政区划信息
50
+ *
51
+ * 根据传入的地理范围(GeoJSON),返回该区域覆盖的行政区划数据(仅对绍兴市有效)。
52
+ *
53
+ * @param geo - 输入的地理范围(GeoJSON)
54
+ * @returns 行政区划信息
55
+ */
56
+ getDistricts(geo: GeoJSON.GeoJSON): Promise<GeoResult>
57
+
58
+ /**
59
+ * 检查点
60
+ *
61
+ * 对传入的点(Point)进行空间校验或查询。
62
+ *
63
+ * @param geo - 待检查的点几何对象(GeoJSON)
64
+ * @returns 校验结果
65
+ */
66
+ checkPoint(geo: GeoJSON.GeoJSON): Promise<GeoResult>
67
+
68
+ /**
69
+ * 检查线
70
+ *
71
+ * 对传入的线(LineString)进行空间校验或查询。
72
+ *
73
+ * @param geo - 待检查的线几何对象(GeoJSON)
74
+ * @returns 校验结果
75
+ */
76
+ checkLine(geo: GeoJSON.GeoJSON): Promise<GeoResult>
77
+
78
+ /**
79
+ * 检查多边形
80
+ *
81
+ * 对传入的多边形(Polygon)进行空间校验或查询。
82
+ *
83
+ * @param geo - 待检查的多边形几何对象(GeoJSON)
84
+ * @returns 校验结果
85
+ */
86
+ checkPolygon(geo: GeoJSON.GeoJSON): Promise<GeoResult>
87
+
88
+ /**
89
+ * 批量获取覆盖信息
90
+ *
91
+ * 计算一组 GeoJSON 在指定距离下的覆盖范围,并支持设置不同透明度。
92
+ *
93
+ * @param geo_jsons - 需要计算覆盖的 GeoJSON 数组
94
+ * @param distances - 覆盖距离(米),每个层级一个值
95
+ * @param opacities - 每层覆盖的透明度,默认 [0.2, 0.2, 0.2]
96
+ * @returns 覆盖信息数组
97
+ */
98
+ batchGetCovers(
99
+ geo_jsons: GeoJSON.GeoJSON[],
100
+ distances: number[],
101
+ opacities?: number[],
102
+ ): Promise<GeoResult>
103
+
104
+ /**
105
+ * 批量简化 GeoJSON 数据
106
+ *
107
+ * 简化一组 GeoJSON 的几何精度,去除冗余顶点,减少数据量。
108
+ * 简化过程中会自动剔除不合法的 GeoJSON,返回的数组元素数量 ≤ 传入的数组元素数量。
109
+ *
110
+ * @param geo_jsons - 需要简化的 GeoJSON 数组
111
+ * @param toleranceMeters - 简化容差(米),该距离内的相邻点将被合并,默认 11
112
+ * @returns 简化后的 GeoJSON 数组
113
+ */
114
+ batchSimplify(geo_jsons: GeoJSON.GeoJSON[], toleranceMeters?: number): Promise<GeoResult>
115
+
116
+ /**
117
+ * 批量获取空间额外信息
118
+ *
119
+ * 计算一组空间(多边形/面)的额外元信息,包括面积、中心点、最佳缩放级别、覆盖的区县编码。
120
+ *
121
+ * @param geo_jsons - 空间 GeoJSON 数组(面要素)
122
+ * @param mapSizes - 地图视口尺寸(像素),默认 [4910, 1311]
123
+ * @param paddingRatio - 边距比例,用于计算最佳缩放级别,默认 0.5
124
+ * @returns 空间额外信息数组
125
+ */
126
+ batchGetSpaceExtra(
127
+ geo_jsons: GeoJSON.GeoJSON[],
128
+ mapSizes?: [width: number, height: number],
129
+ paddingRatio?: number,
130
+ ): Promise<GeoResult<SpaceExtra[]>>
131
+
132
+ /**
133
+ * 批量获取航线额外信息
134
+ *
135
+ * 计算一组航线(线)的额外元信息,包括长度、中心点、最佳缩放级别、经过的区县编码。
136
+ *
137
+ * @param geo_jsons - 航线 GeoJSON 数组(线要素)
138
+ * @param mapSizes - 地图视口尺寸(像素),默认 [4910, 1311]
139
+ * @param paddingRatio - 边距比例,用于计算最佳缩放级别,默认 0.5
140
+ * @returns 航线额外信息数组
141
+ */
142
+ batchGetLineExtra(
143
+ geo_jsons: GeoJSON.GeoJSON[],
144
+ mapSizes?: [width: number, height: number],
145
+ paddingRatio?: number,
146
+ ): Promise<GeoResult<LineExtra[]>>
147
+
148
+ /**
149
+ * 获取绍兴市边界
150
+ *
151
+ * 从 WASM 中读取绍兴市行政边界 GeoJSON(FeatureCollection),
152
+ * 可按米为单位设置简化容差来减少数据量。
153
+ *
154
+ * @param toleranceMeters - 简化容差(米),不传返回完整边界
155
+ * @returns 绍兴市边界 GeoJSON
156
+ */
157
+ getCityBoundary(toleranceMeters?: number | null): Promise<GeoResult>
158
+
159
+ /**
160
+ * 获取绍兴市各区县边界
161
+ *
162
+ * 从 WASM 中读取绍兴市各区县行政边界 GeoJSON(FeatureCollection),
163
+ * 每个区县为一个 Feature,可按米为单位设置简化容差。
164
+ *
165
+ * @param toleranceMeters - 简化容差(米),不传返回完整边界
166
+ * @returns 各区县边界 GeoJSON
167
+ */
168
+ getDistrictBoundary(toleranceMeters?: number | null): Promise<GeoResult>
169
+ }
170
+
171
+ declare const geoTools: GeoTools
172
+ export default geoTools
package/package.json CHANGED
@@ -1,10 +1,12 @@
1
1
  {
2
2
  "name": "shaoxing-geo-tools",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "description": "GIS tools for shaoxing city GeoJSON data",
5
5
  "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
6
7
  "exports": {
7
8
  ".": {
9
+ "types": "./dist/index.d.ts",
8
10
  "import": "./dist/index.js"
9
11
  }
10
12
  },
@@ -20,7 +22,7 @@
20
22
  "type": "module",
21
23
  "scripts": {
22
24
  "dev": "vite",
23
- "build": "vite build",
25
+ "build": "vite build && cp index.d.ts dist/index.d.ts",
24
26
  "preview": "vite preview",
25
27
  "clean": "npm cache clean --force"
26
28
  },