geo-types-cz 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/LICENSE +21 -0
- package/README.md +297 -0
- package/dist/bbox.d.ts +25 -0
- package/dist/bbox.d.ts.map +1 -0
- package/dist/bbox.js +98 -0
- package/dist/bbox.js.map +1 -0
- package/dist/crs.d.ts +37 -0
- package/dist/crs.d.ts.map +1 -0
- package/dist/crs.js +81 -0
- package/dist/crs.js.map +1 -0
- package/dist/extensions.d.ts +150 -0
- package/dist/extensions.d.ts.map +1 -0
- package/dist/extensions.js +63 -0
- package/dist/extensions.js.map +1 -0
- package/dist/feature.d.ts +29 -0
- package/dist/feature.d.ts.map +1 -0
- package/dist/feature.js +42 -0
- package/dist/feature.js.map +1 -0
- package/dist/geometry.d.ts +58 -0
- package/dist/geometry.d.ts.map +1 -0
- package/dist/geometry.js +78 -0
- package/dist/geometry.js.map +1 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +108 -0
- package/dist/index.js.map +1 -0
- package/dist/utils.d.ts +19 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +238 -0
- package/dist/utils.js.map +1 -0
- package/package.json +40 -0
- package/src/bbox.ts +142 -0
- package/src/crs.ts +107 -0
- package/src/extensions.ts +231 -0
- package/src/feature.ts +70 -0
- package/src/geometry.ts +138 -0
- package/src/index.ts +156 -0
- package/src/utils.ts +289 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 geo-types-cz
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
# geo-types-cz
|
|
2
|
+
|
|
3
|
+
🌍 完整的 TypeScript GeoJSON 类型定义包,专为前端 GIS 开发设计
|
|
4
|
+
|
|
5
|
+
## 特性
|
|
6
|
+
|
|
7
|
+
- ✅ **完整的 GeoJSON 支持** - 基于 RFC 7946 标准
|
|
8
|
+
- 🎯 **TypeScript 优先** - 提供完整的类型安全
|
|
9
|
+
- 🚀 **扩展功能** - 包含样式、图层、查询等 GIS 扩展类型
|
|
10
|
+
- 🛠️ **实用工具** - 内置常用的地理计算函数
|
|
11
|
+
- 📦 **零依赖** - 轻量级,无外部依赖
|
|
12
|
+
- 📦 NPM: https://www.npmjs.com/package/geo-types-cz
|
|
13
|
+
- 🌏 **中文友好** - 支持中国常用坐标系
|
|
14
|
+
|
|
15
|
+
## 安装
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install geo-types-cz
|
|
19
|
+
# 或
|
|
20
|
+
yarn add geo-types-cz
|
|
21
|
+
# 或
|
|
22
|
+
pnpm add geo-types-cz
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## 快速开始
|
|
26
|
+
|
|
27
|
+
### 基础 GeoJSON 类型
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
import { Point, Feature, FeatureCollection, createFeature } from 'geo-types-cz';
|
|
31
|
+
|
|
32
|
+
// 创建点几何
|
|
33
|
+
const point: Point = {
|
|
34
|
+
type: 'Point',
|
|
35
|
+
coordinates: [116.3974, 39.9093] // 北京天安门
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// 创建要素
|
|
39
|
+
const feature = createFeature(point, {
|
|
40
|
+
name: '天安门',
|
|
41
|
+
city: '北京',
|
|
42
|
+
type: '景点'
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// 创建要素集合
|
|
46
|
+
const featureCollection: FeatureCollection = {
|
|
47
|
+
type: 'FeatureCollection',
|
|
48
|
+
features: [feature]
|
|
49
|
+
};
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### 几何计算
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
import {
|
|
56
|
+
calculateDistance,
|
|
57
|
+
calculateBearing,
|
|
58
|
+
calculateDestination,
|
|
59
|
+
calculatePolygonArea
|
|
60
|
+
} from 'geo-types-cz';
|
|
61
|
+
|
|
62
|
+
// 计算两点间距离(米)
|
|
63
|
+
const distance = calculateDistance(
|
|
64
|
+
[116.3974, 39.9093], // 北京天安门
|
|
65
|
+
[121.4737, 31.2304] // 上海外滩
|
|
66
|
+
);
|
|
67
|
+
console.log(`距离: ${Math.round(distance / 1000)}公里`);
|
|
68
|
+
|
|
69
|
+
// 计算方位角
|
|
70
|
+
const bearing = calculateBearing(
|
|
71
|
+
[116.3974, 39.9093],
|
|
72
|
+
[121.4737, 31.2304]
|
|
73
|
+
);
|
|
74
|
+
console.log(`方位角: ${bearing.toFixed(1)}度`);
|
|
75
|
+
|
|
76
|
+
// 根据起点、距离和方位角计算终点
|
|
77
|
+
const destination = calculateDestination(
|
|
78
|
+
[116.3974, 39.9093], // 起点
|
|
79
|
+
1000, // 距离(米)
|
|
80
|
+
90 // 方位角(度)
|
|
81
|
+
);
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### 样式和图层
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
import {
|
|
88
|
+
Style,
|
|
89
|
+
StyledFeature,
|
|
90
|
+
VectorLayer,
|
|
91
|
+
createVectorLayer
|
|
92
|
+
} from 'geo-types-cz';
|
|
93
|
+
|
|
94
|
+
// 定义样式
|
|
95
|
+
const style: Style = {
|
|
96
|
+
fill: {
|
|
97
|
+
color: '#ff0000',
|
|
98
|
+
opacity: 0.6
|
|
99
|
+
},
|
|
100
|
+
stroke: {
|
|
101
|
+
color: '#000000',
|
|
102
|
+
width: 2
|
|
103
|
+
},
|
|
104
|
+
marker: {
|
|
105
|
+
size: 10,
|
|
106
|
+
color: '#0066cc',
|
|
107
|
+
symbol: 'circle'
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
// 创建带样式的要素
|
|
112
|
+
const styledFeature: StyledFeature = {
|
|
113
|
+
...feature,
|
|
114
|
+
style
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
// 创建矢量图层
|
|
118
|
+
const layer = createVectorLayer(
|
|
119
|
+
'poi-layer',
|
|
120
|
+
'POI图层',
|
|
121
|
+
featureCollection,
|
|
122
|
+
style
|
|
123
|
+
);
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### 坐标参考系统
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
import { CommonCRS, createNamedCRS } from 'geo-types-cz';
|
|
130
|
+
|
|
131
|
+
// 使用预定义的CRS
|
|
132
|
+
const wgs84 = CommonCRS.WGS84;
|
|
133
|
+
const webMercator = CommonCRS.WebMercator;
|
|
134
|
+
const cgcs2000 = CommonCRS.CGCS2000;
|
|
135
|
+
|
|
136
|
+
// 创建自定义CRS
|
|
137
|
+
const customCRS = createNamedCRS('EPSG:4547'); // 北京54 / 3-degree Gauss-Kruger CM 120E
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### 边界框操作
|
|
141
|
+
|
|
142
|
+
```typescript
|
|
143
|
+
import {
|
|
144
|
+
BBox,
|
|
145
|
+
createBBox2D,
|
|
146
|
+
unionBBox,
|
|
147
|
+
isPositionInBBox,
|
|
148
|
+
calculateGeometryBBox
|
|
149
|
+
} from 'geo-types-cz';
|
|
150
|
+
|
|
151
|
+
// 创建边界框
|
|
152
|
+
const bbox = createBBox2D(116.0, 39.0, 117.0, 40.0); // [west, south, east, north]
|
|
153
|
+
|
|
154
|
+
// 检查点是否在边界框内
|
|
155
|
+
const isInside = isPositionInBBox([116.5, 39.5], bbox);
|
|
156
|
+
|
|
157
|
+
// 计算几何对象的边界框
|
|
158
|
+
const geomBBox = calculateGeometryBBox(point);
|
|
159
|
+
|
|
160
|
+
// 合并两个边界框
|
|
161
|
+
const mergedBBox = unionBBox(bbox, geomBBox);
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## API 文档
|
|
165
|
+
|
|
166
|
+
### 核心类型
|
|
167
|
+
|
|
168
|
+
#### 几何类型 (Geometry)
|
|
169
|
+
- `Point` - 点
|
|
170
|
+
- `LineString` - 线
|
|
171
|
+
- `Polygon` - 多边形
|
|
172
|
+
- `MultiPoint` - 多点
|
|
173
|
+
- `MultiLineString` - 多线
|
|
174
|
+
- `MultiPolygon` - 多多边形
|
|
175
|
+
- `GeometryCollection` - 几何集合
|
|
176
|
+
|
|
177
|
+
#### 要素类型 (Feature)
|
|
178
|
+
- `Feature<G, P>` - 要素,支持泛型
|
|
179
|
+
- `FeatureCollection<G, P>` - 要素集合
|
|
180
|
+
- `Properties` - 属性类型
|
|
181
|
+
|
|
182
|
+
#### 扩展类型
|
|
183
|
+
- `Style` - 样式定义
|
|
184
|
+
- `Layer` - 图层类型(矢量、栅格、瓦片)
|
|
185
|
+
- `MapConfig` - 地图配置
|
|
186
|
+
- `Query` - 空间和属性查询
|
|
187
|
+
|
|
188
|
+
### 工具函数
|
|
189
|
+
|
|
190
|
+
#### 距离和方位计算
|
|
191
|
+
- `calculateDistance(pos1, pos2)` - 计算两点间距离
|
|
192
|
+
- `calculateBearing(pos1, pos2)` - 计算方位角
|
|
193
|
+
- `calculateDestination(start, distance, bearing)` - 计算目标点
|
|
194
|
+
|
|
195
|
+
#### 几何计算
|
|
196
|
+
- `calculateLineLength(lineString)` - 计算线段长度
|
|
197
|
+
- `calculatePolygonArea(polygon)` - 计算多边形面积
|
|
198
|
+
- `calculateGeometryBBox(geometry)` - 计算几何边界框
|
|
199
|
+
|
|
200
|
+
#### 数据处理
|
|
201
|
+
- `simplifyLineString(lineString, tolerance)` - 线段简化
|
|
202
|
+
- `createBuffer(point, distance)` - 创建缓冲区
|
|
203
|
+
|
|
204
|
+
### 类型守卫
|
|
205
|
+
|
|
206
|
+
```typescript
|
|
207
|
+
import { isPoint, isFeature, isVectorLayer } from 'geo-types-cz';
|
|
208
|
+
|
|
209
|
+
if (isPoint(geometry)) {
|
|
210
|
+
// geometry 现在被推断为 Point 类型
|
|
211
|
+
console.log(geometry.coordinates);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if (isFeature(geoJsonObject)) {
|
|
215
|
+
// geoJsonObject 现在被推断为 Feature 类型
|
|
216
|
+
console.log(geoJsonObject.properties);
|
|
217
|
+
}
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
## 使用场景
|
|
221
|
+
|
|
222
|
+
### Web 地图开发
|
|
223
|
+
```typescript
|
|
224
|
+
import { MapConfig, TileLayer, VectorLayer } from 'geo-types-cz';
|
|
225
|
+
|
|
226
|
+
const mapConfig: MapConfig = {
|
|
227
|
+
container: 'map',
|
|
228
|
+
view: {
|
|
229
|
+
center: [116.3974, 39.9093],
|
|
230
|
+
zoom: 10
|
|
231
|
+
},
|
|
232
|
+
layers: [
|
|
233
|
+
{
|
|
234
|
+
id: 'osm',
|
|
235
|
+
name: 'OpenStreetMap',
|
|
236
|
+
type: 'tile',
|
|
237
|
+
url: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
|
|
238
|
+
visible: true
|
|
239
|
+
}
|
|
240
|
+
]
|
|
241
|
+
};
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
### 数据可视化
|
|
245
|
+
```typescript
|
|
246
|
+
import { StyledFeatureCollection, Style } from 'geo-types-cz';
|
|
247
|
+
|
|
248
|
+
const heatmapStyle: Style = {
|
|
249
|
+
fill: {
|
|
250
|
+
color: 'rgba(255, 0, 0, 0.6)'
|
|
251
|
+
},
|
|
252
|
+
marker: {
|
|
253
|
+
size: 8,
|
|
254
|
+
color: '#ff0000'
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
### 空间分析
|
|
260
|
+
```typescript
|
|
261
|
+
import { SpatialQuery, AttributeQuery } from 'geo-types-cz';
|
|
262
|
+
|
|
263
|
+
const spatialQuery: SpatialQuery = {
|
|
264
|
+
type: 'intersects',
|
|
265
|
+
geometry: polygon,
|
|
266
|
+
buffer: 1000
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
const attributeQuery: AttributeQuery = {
|
|
270
|
+
field: 'population',
|
|
271
|
+
operator: '>',
|
|
272
|
+
value: 100000
|
|
273
|
+
};
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
## 兼容性
|
|
277
|
+
|
|
278
|
+
- TypeScript 4.0+
|
|
279
|
+
- Node.js 14+
|
|
280
|
+
- 现代浏览器 (ES2020+)
|
|
281
|
+
|
|
282
|
+
## 贡献
|
|
283
|
+
|
|
284
|
+
欢迎提交 Issue 和 Pull Request!
|
|
285
|
+
|
|
286
|
+
## 许可证
|
|
287
|
+
|
|
288
|
+
MIT License
|
|
289
|
+
|
|
290
|
+
## 更新日志
|
|
291
|
+
|
|
292
|
+
### 1.0.0
|
|
293
|
+
- 初始版本发布
|
|
294
|
+
- 完整的 GeoJSON 类型支持
|
|
295
|
+
- 扩展的 GIS 类型定义
|
|
296
|
+
- 常用工具函数
|
|
297
|
+
- 中国坐标系支持
|
package/dist/bbox.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 边界框(BBox)类型定义和工具函数
|
|
3
|
+
*/
|
|
4
|
+
import { Position } from './geometry';
|
|
5
|
+
export type BBox2D = [number, number, number, number];
|
|
6
|
+
export type BBox3D = [number, number, number, number, number, number];
|
|
7
|
+
export type BBox = BBox2D | BBox3D;
|
|
8
|
+
export interface BoundingBox {
|
|
9
|
+
west: number;
|
|
10
|
+
south: number;
|
|
11
|
+
east: number;
|
|
12
|
+
north: number;
|
|
13
|
+
minElevation?: number;
|
|
14
|
+
maxElevation?: number;
|
|
15
|
+
}
|
|
16
|
+
export declare function is2DBBox(bbox: BBox): bbox is BBox2D;
|
|
17
|
+
export declare function is3DBBox(bbox: BBox): bbox is BBox3D;
|
|
18
|
+
export declare function createBBox2D(west: number, south: number, east: number, north: number): BBox2D;
|
|
19
|
+
export declare function createBBox3D(west: number, south: number, minElevation: number, east: number, north: number, maxElevation: number): BBox3D;
|
|
20
|
+
export declare function bboxToObject(bbox: BBox): BoundingBox;
|
|
21
|
+
export declare function objectToBBox(boundingBox: BoundingBox): BBox;
|
|
22
|
+
export declare function unionBBox(bbox1: BBox, bbox2: BBox): BBox;
|
|
23
|
+
export declare function isPositionInBBox(position: Position, bbox: BBox): boolean;
|
|
24
|
+
export declare function getBBoxCenter(bbox: BBox): Position;
|
|
25
|
+
//# sourceMappingURL=bbox.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bbox.d.ts","sourceRoot":"","sources":["../src/bbox.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAGtC,MAAM,MAAM,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,EA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AAI,EAAE,IAAI,GAAG,QAAQ,CAWlD"}
|
package/dist/bbox.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* 边界框(BBox)类型定义和工具函数
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.is2DBBox = is2DBBox;
|
|
7
|
+
exports.is3DBBox = is3DBBox;
|
|
8
|
+
exports.createBBox2D = createBBox2D;
|
|
9
|
+
exports.createBBox3D = createBBox3D;
|
|
10
|
+
exports.bboxToObject = bboxToObject;
|
|
11
|
+
exports.objectToBBox = objectToBBox;
|
|
12
|
+
exports.unionBBox = unionBBox;
|
|
13
|
+
exports.isPositionInBBox = isPositionInBBox;
|
|
14
|
+
exports.getBBoxCenter = getBBoxCenter;
|
|
15
|
+
// 类型守卫函数
|
|
16
|
+
function is2DBBox(bbox) {
|
|
17
|
+
return bbox.length === 4;
|
|
18
|
+
}
|
|
19
|
+
function is3DBBox(bbox) {
|
|
20
|
+
return bbox.length === 6;
|
|
21
|
+
}
|
|
22
|
+
// 工具函数
|
|
23
|
+
function createBBox2D(west, south, east, north) {
|
|
24
|
+
return [west, south, east, north];
|
|
25
|
+
}
|
|
26
|
+
function createBBox3D(west, south, minElevation, east, north, maxElevation) {
|
|
27
|
+
return [west, south, minElevation, east, north, maxElevation];
|
|
28
|
+
}
|
|
29
|
+
// 从边界框数组转换为对象
|
|
30
|
+
function bboxToObject(bbox) {
|
|
31
|
+
if (is2DBBox(bbox)) {
|
|
32
|
+
return {
|
|
33
|
+
west: bbox[0],
|
|
34
|
+
south: bbox[1],
|
|
35
|
+
east: bbox[2],
|
|
36
|
+
north: bbox[3]
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
return {
|
|
41
|
+
west: bbox[0],
|
|
42
|
+
south: bbox[1],
|
|
43
|
+
east: bbox[3],
|
|
44
|
+
north: bbox[4],
|
|
45
|
+
minElevation: bbox[2],
|
|
46
|
+
maxElevation: bbox[5]
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
// 从对象转换为边界框数组
|
|
51
|
+
function objectToBBox(boundingBox) {
|
|
52
|
+
if (boundingBox.minElevation !== undefined && boundingBox.maxElevation !== undefined) {
|
|
53
|
+
return createBBox3D(boundingBox.west, boundingBox.south, boundingBox.minElevation, boundingBox.east, boundingBox.north, boundingBox.maxElevation);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
return createBBox2D(boundingBox.west, boundingBox.south, boundingBox.east, boundingBox.north);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// 计算两个边界框的并集
|
|
60
|
+
function unionBBox(bbox1, bbox2) {
|
|
61
|
+
const obj1 = bboxToObject(bbox1);
|
|
62
|
+
const obj2 = bboxToObject(bbox2);
|
|
63
|
+
const result = {
|
|
64
|
+
west: Math.min(obj1.west, obj2.west),
|
|
65
|
+
south: Math.min(obj1.south, obj2.south),
|
|
66
|
+
east: Math.max(obj1.east, obj2.east),
|
|
67
|
+
north: Math.max(obj1.north, obj2.north)
|
|
68
|
+
};
|
|
69
|
+
if (obj1.minElevation !== undefined && obj2.minElevation !== undefined) {
|
|
70
|
+
result.minElevation = Math.min(obj1.minElevation, obj2.minElevation);
|
|
71
|
+
}
|
|
72
|
+
if (obj1.maxElevation !== undefined && obj2.maxElevation !== undefined) {
|
|
73
|
+
result.maxElevation = Math.max(obj1.maxElevation, obj2.maxElevation);
|
|
74
|
+
}
|
|
75
|
+
return objectToBBox(result);
|
|
76
|
+
}
|
|
77
|
+
// 检查点是否在边界框内
|
|
78
|
+
function isPositionInBBox(position, bbox) {
|
|
79
|
+
const [lon, lat, elevation] = position;
|
|
80
|
+
const obj = bboxToObject(bbox);
|
|
81
|
+
const inBounds = lon >= obj.west && lon <= obj.east && lat >= obj.south && lat <= obj.north;
|
|
82
|
+
if (elevation !== undefined && obj.minElevation !== undefined && obj.maxElevation !== undefined) {
|
|
83
|
+
return inBounds && elevation >= obj.minElevation && elevation <= obj.maxElevation;
|
|
84
|
+
}
|
|
85
|
+
return inBounds;
|
|
86
|
+
}
|
|
87
|
+
// 计算边界框的中心点
|
|
88
|
+
function getBBoxCenter(bbox) {
|
|
89
|
+
const obj = bboxToObject(bbox);
|
|
90
|
+
const centerLon = (obj.west + obj.east) / 2;
|
|
91
|
+
const centerLat = (obj.south + obj.north) / 2;
|
|
92
|
+
if (obj.minElevation !== undefined && obj.maxElevation !== undefined) {
|
|
93
|
+
const centerElevation = (obj.minElevation + obj.maxElevation) / 2;
|
|
94
|
+
return [centerLon, centerLat, centerElevation];
|
|
95
|
+
}
|
|
96
|
+
return [centerLon, centerLat];
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=bbox.js.map
|
package/dist/bbox.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bbox.js","sourceRoot":"","sources":["../src/bbox.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAwBH,4BAEC;AAED,4BAEC;AAGD,oCAEC;AAED,oCASC;AAGD,oCAkBC;AAGD,oCAkBC;AAGD,8BAoBC;AAGD,4CAWC;AAGD,sCAWC;AApHD,SAAS;AACT,SAAgB,QAAQ,CAAC,IAAU;IACjC,OAAO,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC;AAC3B,CAAC;AAED,SAAgB,QAAQ,CAAC,IAAU;IACjC,OAAO,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC;AAC3B,CAAC;AAED,OAAO;AACP,SAAgB,YAAY,CAAC,IAAY,EAAE,KAAa,EAAE,IAAY,EAAE,KAAa;IACnF,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;AACpC,CAAC;AAED,SAAgB,YAAY,CAC1B,IAAY,EACZ,KAAa,EACb,YAAoB,EACpB,IAAY,EACZ,KAAa,EACb,YAAoB;IAEpB,OAAO,CAAC,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CAAC,IAAI,IAAI,GAAG,IAAI,GAAG,CAAC,KAAK,IAAI,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC;IAE5F,IAAI,SAAS,KAAK,SAAS,IAAI,GAAG,CAAC,YAAY,KAAK,SAAS,IAAI,GAAG,CAAC,YAAY,KAAK,SAAS,EAAE,CAAC;QAChG,OAAO,QAAQ,IAAI,SAAS,IAAI,GAAG,CAAC,YAAY,IAAI,SAAS,IAAI,GAAG,CAAC,YAAY,CAAC;IACpF,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,YAAY;AACZ,SAAgB,aAAa,CAAC,IAAU;IACtC,MAAM,GAAG,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;IAC/B,MAAM,SAAS,GAAG,CAAC,GAAG,CAAC,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC5C,MAAM,SAAS,GAAG,CAAC,GAAG,CAAC,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAE9C,IAAI,GAAG,CAAC,YAAY,KAAK,SAAS,IAAI,GAAG,CAAC,YAAY,KAAK,SAAS,EAAE,CAAC;QACrE,MAAM,eAAe,GAAG,CAAC,GAAG,CAAC,YAAY,GAAG,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;QAClE,OAAO,CAAC,SAAS,EAAE,SAAS,EAAE,eAAe,CAAC,CAAC;IACjD,CAAC;IAED,OAAO,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;AAChC,CAAC"}
|
package/dist/crs.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 坐标参考系统(CRS)类型定义
|
|
3
|
+
* 虽然GeoJSON RFC 7946不推荐使用CRS,但在实际GIS应用中仍然重要
|
|
4
|
+
*/
|
|
5
|
+
export declare enum CRSType {
|
|
6
|
+
Name = "name",
|
|
7
|
+
Link = "link"
|
|
8
|
+
}
|
|
9
|
+
export interface BaseCRS {
|
|
10
|
+
type: CRSType;
|
|
11
|
+
}
|
|
12
|
+
export interface NamedCRS extends BaseCRS {
|
|
13
|
+
type: CRSType.Name;
|
|
14
|
+
properties: {
|
|
15
|
+
name: string;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export interface LinkedCRS extends BaseCRS {
|
|
19
|
+
type: CRSType.Link;
|
|
20
|
+
properties: {
|
|
21
|
+
href: string;
|
|
22
|
+
type?: string;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export type CRS = NamedCRS | LinkedCRS;
|
|
26
|
+
export declare const CommonCRS: {
|
|
27
|
+
readonly WGS84: NamedCRS;
|
|
28
|
+
readonly WebMercator: NamedCRS;
|
|
29
|
+
readonly CGCS2000: NamedCRS;
|
|
30
|
+
readonly Beijing54: NamedCRS;
|
|
31
|
+
readonly Xian80: NamedCRS;
|
|
32
|
+
};
|
|
33
|
+
export declare function isNamedCRS(crs: CRS): crs is NamedCRS;
|
|
34
|
+
export declare function isLinkedCRS(crs: CRS): crs is LinkedCRS;
|
|
35
|
+
export declare function createNamedCRS(name: string): NamedCRS;
|
|
36
|
+
export declare function createLinkedCRS(href: string, type?: string): LinkedCRS;
|
|
37
|
+
//# sourceMappingURL=crs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crs.d.ts","sourceRoot":"","sources":["../src/crs.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,oBAAY,OAAO;IACjB,IAAI,SAAS;IACb,IAAI,SAAS;CACd;AAGD,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,OAAO,CAAC;CACf;AAGD,MAAM,WAAW,QAAS,SAAQ,OAAO;IACvC,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC;IACnB,UAAU,EAAE;QACV,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;CACH;AAGD,MAAM,WAAW,SAAU,SAAQ,OAAO;IACxC,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC;IACnB,UAAU,EAAE;QACV,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,CAAC,EAAE,MAAM,CAAC;KACf,CAAC;CACH;AAGD,MAAM,MAAM,GAAG,GAAG,QAAQ,GAAG,SAAS,CAAC;AAGvC,eAAO,MAAM,SAAS;oBAOf,QAAQ;0BAQR,QAAQ;uBAQR,QAAQ;wBAQR,QAAQ;qBAQR,QAAQ;CACL,CAAC;AAGX,wBAAgB,UAAU,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,QAAQ,CAEpD;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,SAAS,CAEtD;AAGD,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,CAOrD;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAQtE"}
|
package/dist/crs.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* 坐标参考系统(CRS)类型定义
|
|
4
|
+
* 虽然GeoJSON RFC 7946不推荐使用CRS,但在实际GIS应用中仍然重要
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.CommonCRS = exports.CRSType = void 0;
|
|
8
|
+
exports.isNamedCRS = isNamedCRS;
|
|
9
|
+
exports.isLinkedCRS = isLinkedCRS;
|
|
10
|
+
exports.createNamedCRS = createNamedCRS;
|
|
11
|
+
exports.createLinkedCRS = createLinkedCRS;
|
|
12
|
+
// CRS类型枚举
|
|
13
|
+
var CRSType;
|
|
14
|
+
(function (CRSType) {
|
|
15
|
+
CRSType["Name"] = "name";
|
|
16
|
+
CRSType["Link"] = "link";
|
|
17
|
+
})(CRSType || (exports.CRSType = CRSType = {}));
|
|
18
|
+
// 常用的CRS定义
|
|
19
|
+
exports.CommonCRS = {
|
|
20
|
+
// WGS84 地理坐标系
|
|
21
|
+
WGS84: {
|
|
22
|
+
type: CRSType.Name,
|
|
23
|
+
properties: {
|
|
24
|
+
name: 'EPSG:4326'
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
// Web墨卡托投影
|
|
28
|
+
WebMercator: {
|
|
29
|
+
type: CRSType.Name,
|
|
30
|
+
properties: {
|
|
31
|
+
name: 'EPSG:3857'
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
// 中国大地坐标系2000
|
|
35
|
+
CGCS2000: {
|
|
36
|
+
type: CRSType.Name,
|
|
37
|
+
properties: {
|
|
38
|
+
name: 'EPSG:4490'
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
// 北京54坐标系
|
|
42
|
+
Beijing54: {
|
|
43
|
+
type: CRSType.Name,
|
|
44
|
+
properties: {
|
|
45
|
+
name: 'EPSG:4214'
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
// 西安80坐标系
|
|
49
|
+
Xian80: {
|
|
50
|
+
type: CRSType.Name,
|
|
51
|
+
properties: {
|
|
52
|
+
name: 'EPSG:4610'
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
// 类型守卫函数
|
|
57
|
+
function isNamedCRS(crs) {
|
|
58
|
+
return crs.type === CRSType.Name;
|
|
59
|
+
}
|
|
60
|
+
function isLinkedCRS(crs) {
|
|
61
|
+
return crs.type === CRSType.Link;
|
|
62
|
+
}
|
|
63
|
+
// 工具函数
|
|
64
|
+
function createNamedCRS(name) {
|
|
65
|
+
return {
|
|
66
|
+
type: CRSType.Name,
|
|
67
|
+
properties: {
|
|
68
|
+
name
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function createLinkedCRS(href, type) {
|
|
73
|
+
return {
|
|
74
|
+
type: CRSType.Link,
|
|
75
|
+
properties: {
|
|
76
|
+
href,
|
|
77
|
+
...(type && { type })
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=crs.js.map
|
package/dist/crs.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crs.js","sourceRoot":"","sources":["../src/crs.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AA6EH,gCAEC;AAED,kCAEC;AAGD,wCAOC;AAED,0CAQC;AArGD,UAAU;AACV,IAAY,OAGX;AAHD,WAAY,OAAO;IACjB,wBAAa,CAAA;IACb,wBAAa,CAAA;AACf,CAAC,EAHW,OAAO,uBAAP,OAAO,QAGlB;AA2BD,WAAW;AACE,QAAA,SAAS,GAAG;IACvB,cAAc;IACd,KAAK,EAAE;QACL,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,UAAU,EAAE;YACV,IAAI,EAAE,WAAW;SAClB;KACU;IAEb,WAAW;IACX,WAAW,EAAE;QACX,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,UAAU,EAAE;YACV,IAAI,EAAE,WAAW;SAClB;KACU;IAEb,cAAc;IACd,QAAQ,EAAE;QACR,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,UAAU,EAAE;YACV,IAAI,EAAE,WAAW;SAClB;KACU;IAEb,UAAU;IACV,SAAS,EAAE;QACT,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,UAAU,EAAE;YACV,IAAI,EAAE,WAAW;SAClB;KACU;IAEb,UAAU;IACV,MAAM,EAAE;QACN,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,UAAU,EAAE;YACV,IAAI,EAAE,WAAW;SAClB;KACU;CACL,CAAC;AAEX,SAAS;AACT,SAAgB,UAAU,CAAC,GAAQ;IACjC,OAAO,GAAG,CAAC,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC;AACnC,CAAC;AAED,SAAgB,WAAW,CAAC,GAAQ;IAClC,OAAO,GAAG,CAAC,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC;AACnC,CAAC;AAED,OAAO;AACP,SAAgB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