geo-types-cz 1.0.3 → 1.0.4
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/dist/bbox.d.ts +17 -1
- package/dist/bbox.d.ts.map +1 -1
- package/dist/bbox.js +61 -0
- package/dist/bbox.js.map +1 -1
- package/dist/index.d.ts +2 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -7
- package/dist/index.js.map +1 -1
- package/dist/service.d.ts +9 -0
- package/dist/service.d.ts.map +1 -0
- package/dist/service.js +33 -0
- package/dist/service.js.map +1 -0
- package/package.json +1 -1
- package/src/bbox.ts +65 -1
- package/src/index.ts +6 -7
- package/src/service.ts +29 -0
package/dist/bbox.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 边界框(BBox)类型定义和工具函数
|
|
3
3
|
*/
|
|
4
|
-
import { Position } from './geometry';
|
|
4
|
+
import { Polygon, Position } from './geometry';
|
|
5
5
|
export type BBox2D = [number, number, number, number];
|
|
6
6
|
export type BBox3D = [number, number, number, number, number, number];
|
|
7
7
|
export type BBox = BBox2D | BBox3D;
|
|
@@ -18,8 +18,24 @@ export declare function is3DBBox(bbox: BBox): bbox is BBox3D;
|
|
|
18
18
|
export declare function createBBox2D(west: number, south: number, east: number, north: number): BBox2D;
|
|
19
19
|
export declare function createBBox3D(west: number, south: number, minElevation: number, east: number, north: number, maxElevation: number): BBox3D;
|
|
20
20
|
export declare function bboxToObject(bbox: BBox): BoundingBox;
|
|
21
|
+
export declare function bboxToPolygon(bbox: BBox): Polygon;
|
|
21
22
|
export declare function objectToBBox(boundingBox: BoundingBox): BBox;
|
|
22
23
|
export declare function unionBBox(bbox1: BBox, bbox2: BBox): BBox;
|
|
23
24
|
export declare function isPositionInBBox(position: Position, bbox: BBox): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* @description: 验证bbox(2D)是否符合规范
|
|
27
|
+
* @param {any} bbox
|
|
28
|
+
* @return {*} boolean
|
|
29
|
+
*/
|
|
30
|
+
export declare function validateBBox(bbox: any): bbox is BBox;
|
|
24
31
|
export declare function getBBoxCenter(bbox: BBox): Position;
|
|
32
|
+
/**
|
|
33
|
+
* @description: 根据paths计算bbox
|
|
34
|
+
* @param {any} Position[]
|
|
35
|
+
* @return {*}
|
|
36
|
+
*/
|
|
37
|
+
export declare function calcGeometryBBox(geometry: Position[]): {
|
|
38
|
+
southWest: number[];
|
|
39
|
+
northEast: number[];
|
|
40
|
+
};
|
|
25
41
|
//# sourceMappingURL=bbox.d.ts.map
|
package/dist/bbox.d.ts.map
CHANGED
|
@@ -1 +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;
|
|
1
|
+
{"version":3,"file":"bbox.d.ts","sourceRoot":"","sources":["../src/bbox.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAgB,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAG7D,MAAM,MAAM,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAGtD,MAAM,MAAM,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAGtE,MAAM,MAAM,IAAI,GAAG,MAAM,GAAG,MAAM,CAAC;AAGnC,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAGD,wBAAgB,QAAQ,CAAC,IAAI,EAAE,IAAI,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
|
6
7
|
return bbox.length === 4;
|
|
@@ -36,6 +37,20 @@ export function bboxToObject(bbox) {
|
|
|
36
37
|
};
|
|
37
38
|
}
|
|
38
39
|
}
|
|
40
|
+
//bbox转换为多边形
|
|
41
|
+
export function bboxToPolygon(bbox) {
|
|
42
|
+
const [minX, minY, maxX, maxY] = bbox;
|
|
43
|
+
return {
|
|
44
|
+
type: GeometryType.Polygon,
|
|
45
|
+
coordinates: [[
|
|
46
|
+
[minX, minY],
|
|
47
|
+
[maxX, minY],
|
|
48
|
+
[maxX, maxY],
|
|
49
|
+
[minX, maxY],
|
|
50
|
+
[minX, minY]
|
|
51
|
+
]]
|
|
52
|
+
};
|
|
53
|
+
}
|
|
39
54
|
// 从对象转换为边界框数组
|
|
40
55
|
export function objectToBBox(boundingBox) {
|
|
41
56
|
if (boundingBox.minElevation !== undefined && boundingBox.maxElevation !== undefined) {
|
|
@@ -73,6 +88,23 @@ export function isPositionInBBox(position, bbox) {
|
|
|
73
88
|
}
|
|
74
89
|
return inBounds;
|
|
75
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* @description: 验证bbox(2D)是否符合规范
|
|
93
|
+
* @param {any} bbox
|
|
94
|
+
* @return {*} boolean
|
|
95
|
+
*/
|
|
96
|
+
export function validateBBox(bbox) {
|
|
97
|
+
if (!Array.isArray(bbox) || bbox.length < 4) {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
const [minX, minY, maxX, maxY] = bbox;
|
|
101
|
+
return typeof minX === 'number' &&
|
|
102
|
+
typeof minY === 'number' &&
|
|
103
|
+
typeof maxX === 'number' &&
|
|
104
|
+
typeof maxY === 'number' &&
|
|
105
|
+
minX <= maxX &&
|
|
106
|
+
minY <= maxY;
|
|
107
|
+
}
|
|
76
108
|
// 计算边界框的中心点
|
|
77
109
|
export function getBBoxCenter(bbox) {
|
|
78
110
|
const obj = bboxToObject(bbox);
|
|
@@ -84,4 +116,33 @@ export function getBBoxCenter(bbox) {
|
|
|
84
116
|
}
|
|
85
117
|
return [centerLon, centerLat];
|
|
86
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* @description: 根据paths计算bbox
|
|
121
|
+
* @param {any} Position[]
|
|
122
|
+
* @return {*}
|
|
123
|
+
*/
|
|
124
|
+
export function calcGeometryBBox(geometry) {
|
|
125
|
+
let minLng = Infinity, minLat = Infinity, maxLng = -Infinity, maxLat = -Infinity;
|
|
126
|
+
for (const [lng, lat] of geometry) {
|
|
127
|
+
if (lng < minLng)
|
|
128
|
+
minLng = lng;
|
|
129
|
+
if (lat < minLat)
|
|
130
|
+
minLat = lat;
|
|
131
|
+
if (lng > maxLng)
|
|
132
|
+
maxLng = lng;
|
|
133
|
+
if (lat > maxLat)
|
|
134
|
+
maxLat = lat;
|
|
135
|
+
}
|
|
136
|
+
// 适度留白,避免多边形贴边
|
|
137
|
+
const padLng = 0.001;
|
|
138
|
+
const padLat = 0.001;
|
|
139
|
+
minLng = minLng - padLng;
|
|
140
|
+
minLat = minLat - padLat;
|
|
141
|
+
maxLng = maxLng + padLng;
|
|
142
|
+
maxLat = maxLat + padLat;
|
|
143
|
+
return {
|
|
144
|
+
southWest: [minLng, minLat],
|
|
145
|
+
northEast: [maxLng, maxLat],
|
|
146
|
+
};
|
|
147
|
+
}
|
|
87
148
|
//# sourceMappingURL=bbox.js.map
|
package/dist/bbox.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bbox.js","sourceRoot":"","sources":["../src/bbox.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"bbox.js","sourceRoot":"","sources":["../src/bbox.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,YAAY,EAAqB,MAAM,YAAY,CAAC;AAqB7D,SAAS;AACT,MAAM,UAAU,QAAQ,CAAC,IAAU;IACjC,OAAO,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC;AAC3B,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,IA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AE,CAAC;QAClC,IAAI,GAAG,GAAG,MAAM;YAAE,MAAM,GAAG,GAAG,CAAC;QAC/B,IAAI,GAAG,GAAG,MAAM;YAAE,MAAM,GAAG,GAAG,CAAC;QAC/B,IAAI,GAAG,GAAG,MAAM;YAAE,MAAM,GAAG,GAAG,CAAC;QAC/B,IAAI,GAAG,GAAG,MAAM;YAAE,MAAM,GAAG,GAAG,CAAC;IACjC,CAAC;IAED,eAAe;IACf,MAAM,MAAM,GAAG,KAAK,CAAC;IACrB,MAAM,MAAM,GAAG,KAAK,CAAC;IAErB,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;IACzB,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;IACzB,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;IACzB,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;IACzB,OAAO;QACL,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC;QAC3B,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC;KAC5B,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -8,14 +8,10 @@
|
|
|
8
8
|
export { Position, GeometryType, BaseGeometry, Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon, GeometryCollection, Geometry, isPoint, isLineString, isPolygon, isMultiPoint, isMultiLineString, isMultiPolygon, isGeometryCollection, validateCoordinates, validateFeatureGeometry } from './geometry';
|
|
9
9
|
export { FeatureType, Properties, Feature, FeatureCollection, GeoJSONObject, isFeature, isFeatureCollection, createFeature, createFeatureCollection, createCircle } from './feature';
|
|
10
10
|
export { CRSType, BaseCRS, NamedCRS, LinkedCRS, CRS, CommonCRS, isNamedCRS, isLinkedCRS, createNamedCRS, createLinkedCRS } from './crs';
|
|
11
|
-
export { BBox2D, BBox3D, BBox, BoundingBox, is2DBBox, is3DBBox, createBBox2D, createBBox3D, bboxToObject, objectToBBox, unionBBox, isPositionInBBox, getBBoxCenter } from './bbox';
|
|
11
|
+
export { BBox2D, BBox3D, BBox, validateBBox, BoundingBox, is2DBBox, is3DBBox, createBBox2D, createBBox3D, bboxToObject, objectToBBox, unionBBox, isPositionInBBox, getBBoxCenter, calcGeometryBBox } from './bbox';
|
|
12
12
|
export { Color, Style, StyledFeature, StyledFeatureCollection, LayerType, BaseLayer, VectorLayer, RasterLayer, TileLayer, Layer, MapView, MapConfig, SpatialQueryType, SpatialQuery, AttributeQuery, Query, isVectorLayer, isRasterLayer, isTileLayer, ClusterConfig } from './extensions';
|
|
13
13
|
export { degreesToRadians, radiansToDegrees, calculateDistance, calculateBearing, calculateDestination, calculateLineLength, calculatePolygonArea, calculateGeometryBBox, calculateFeatureCollectionBBox, simplifyLineString, createBuffer } from './utils';
|
|
14
|
-
export
|
|
15
|
-
declare const _default: {
|
|
16
|
-
VERSION: string;
|
|
17
|
-
};
|
|
18
|
-
export default _default;
|
|
14
|
+
export { getAddressByGeocoder } from "./service";
|
|
19
15
|
/**
|
|
20
16
|
* 使用示例:
|
|
21
17
|
*
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EACL,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,KAAK,EACL,UAAU,EACV,OAAO,EACP,UAAU,EACV,eAAe,EACf,YAAY,EACZ,kBAAkB,EAClB,QAAQ,EACR,OAAO,EACP,YAAY,EACZ,SAAS,EACT,YAAY,EACZ,iBAAiB,EACjB,cAAc,EACd,oBAAoB,EACpB,mBAAmB,EACnB,uBAAuB,EACxB,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,WAAW,EACX,UAAU,EACV,OAAO,EACP,iBAAiB,EACjB,aAAa,EACb,SAAS,EACT,mBAAmB,EACnB,aAAa,EACb,uBAAuB,EACvB,YAAY,EACb,MAAM,WAAW,CAAC;AAGnB,OAAO,EACL,OAAO,EACP,OAAO,EACP,QAAQ,EACR,SAAS,EACT,GAAG,EACH,SAAS,EACT,UAAU,EACV,WAAW,EACX,cAAc,EACd,eAAe,EAChB,MAAM,OAAO,CAAC;AAGf,OAAO,EACL,MAAM,EACN,MAAM,EACN,IAAI,EACJ,WAAW,EACX,QAAQ,EACR,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,SAAS,EACT,gBAAgB,EAChB,aAAa,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EACL,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,KAAK,EACL,UAAU,EACV,OAAO,EACP,UAAU,EACV,eAAe,EACf,YAAY,EACZ,kBAAkB,EAClB,QAAQ,EACR,OAAO,EACP,YAAY,EACZ,SAAS,EACT,YAAY,EACZ,iBAAiB,EACjB,cAAc,EACd,oBAAoB,EACpB,mBAAmB,EACnB,uBAAuB,EACxB,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,WAAW,EACX,UAAU,EACV,OAAO,EACP,iBAAiB,EACjB,aAAa,EACb,SAAS,EACT,mBAAmB,EACnB,aAAa,EACb,uBAAuB,EACvB,YAAY,EACb,MAAM,WAAW,CAAC;AAGnB,OAAO,EACL,OAAO,EACP,OAAO,EACP,QAAQ,EACR,SAAS,EACT,GAAG,EACH,SAAS,EACT,UAAU,EACV,WAAW,EACX,cAAc,EACd,eAAe,EAChB,MAAM,OAAO,CAAC;AAGf,OAAO,EACL,MAAM,EACN,MAAM,EACN,IAAI,EACJ,YAAY,EACZ,WAAW,EACX,QAAQ,EACR,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,SAAS,EACT,gBAAgB,EAChB,aAAa,EACb,gBAAgB,EACjB,MAAM,QAAQ,CAAC;AAGhB,OAAO,EACL,KAAK,EACL,KAAK,EACL,aAAa,EACb,uBAAuB,EACvB,SAAS,EACT,SAAS,EACT,WAAW,EACX,WAAW,EACX,SAAS,EACT,KAAK,EACL,OAAO,EACP,SAAS,EACT,gBAAgB,EAChB,YAAY,EACZ,cAAc,EACd,KAAK,EACL,aAAa,EACb,aAAa,EACb,WAAW,EACX,aAAa,EACd,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,EACrB,8BAA8B,EAC9B,kBAAkB,EAClB,YAAY,EACb,MAAM,SAAS,CAAC;AAIjB,OAAO,EAAC,oBAAoB,EAAC,MAAM,WAAW,CAAA;AAG9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG"}
|
package/dist/index.js
CHANGED
|
@@ -12,17 +12,13 @@ export { FeatureType, isFeature, isFeatureCollection, createFeature, createFeatu
|
|
|
12
12
|
// 导出坐标参考系统类型
|
|
13
13
|
export { CRSType, CommonCRS, isNamedCRS, isLinkedCRS, createNamedCRS, createLinkedCRS } from './crs';
|
|
14
14
|
// 导出边界框类型
|
|
15
|
-
export { is2DBBox, is3DBBox, createBBox2D, createBBox3D, bboxToObject, objectToBBox, unionBBox, isPositionInBBox, getBBoxCenter } from './bbox';
|
|
15
|
+
export { validateBBox, is2DBBox, is3DBBox, createBBox2D, createBBox3D, bboxToObject, objectToBBox, unionBBox, isPositionInBBox, getBBoxCenter, calcGeometryBBox } from './bbox';
|
|
16
16
|
// 导出扩展类型
|
|
17
17
|
export { LayerType, SpatialQueryType, isVectorLayer, isRasterLayer, isTileLayer } from './extensions';
|
|
18
18
|
// 导出工具函数
|
|
19
19
|
export { degreesToRadians, radiansToDegrees, calculateDistance, calculateBearing, calculateDestination, calculateLineLength, calculatePolygonArea, calculateGeometryBBox, calculateFeatureCollectionBBox, simplifyLineString, createBuffer } from './utils';
|
|
20
|
-
|
|
21
|
-
export
|
|
22
|
-
// 默认导出
|
|
23
|
-
export default {
|
|
24
|
-
VERSION
|
|
25
|
-
};
|
|
20
|
+
//导出服务函数
|
|
21
|
+
export { getAddressByGeocoder } from "./service";
|
|
26
22
|
/**
|
|
27
23
|
* 使用示例:
|
|
28
24
|
*
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,SAAS;AACT,OAAO,EAEL,YAAY,EAUZ,OAAO,EACP,YAAY,EACZ,SAAS,EACT,YAAY,EACZ,iBAAiB,EACjB,cAAc,EACd,oBAAoB,EACpB,mBAAmB,EACnB,uBAAuB,EACxB,MAAM,YAAY,CAAC;AAEpB,SAAS;AACT,OAAO,EACL,WAAW,EAKX,SAAS,EACT,mBAAmB,EACnB,aAAa,EACb,uBAAuB,EACvB,YAAY,EACb,MAAM,WAAW,CAAC;AAEnB,aAAa;AACb,OAAO,EACL,OAAO,EAKP,SAAS,EACT,UAAU,EACV,WAAW,EACX,cAAc,EACd,eAAe,EAChB,MAAM,OAAO,CAAC;AAEf,UAAU;AACV,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,SAAS;AACT,OAAO,EAEL,YAAY,EAUZ,OAAO,EACP,YAAY,EACZ,SAAS,EACT,YAAY,EACZ,iBAAiB,EACjB,cAAc,EACd,oBAAoB,EACpB,mBAAmB,EACnB,uBAAuB,EACxB,MAAM,YAAY,CAAC;AAEpB,SAAS;AACT,OAAO,EACL,WAAW,EAKX,SAAS,EACT,mBAAmB,EACnB,aAAa,EACb,uBAAuB,EACvB,YAAY,EACb,MAAM,WAAW,CAAC;AAEnB,aAAa;AACb,OAAO,EACL,OAAO,EAKP,SAAS,EACT,UAAU,EACV,WAAW,EACX,cAAc,EACd,eAAe,EAChB,MAAM,OAAO,CAAC;AAEf,UAAU;AACV,OAAO,EAIL,YAAY,EAEZ,QAAQ,EACR,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,SAAS,EACT,gBAAgB,EAChB,aAAa,EACb,gBAAgB,EACjB,MAAM,QAAQ,CAAC;AAEhB,SAAS;AACT,OAAO,EAKL,SAAS,EAQT,gBAAgB,EAIhB,aAAa,EACb,aAAa,EACb,WAAW,EAEZ,MAAM,cAAc,CAAC;AAEtB,SAAS;AACT,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,EACrB,8BAA8B,EAC9B,kBAAkB,EAClB,YAAY,EACb,MAAM,SAAS,CAAC;AAGjB,QAAQ;AACR,OAAO,EAAC,oBAAoB,EAAC,MAAM,WAAW,CAAA;AAG9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Position } from "./geometry";
|
|
2
|
+
/**
|
|
3
|
+
* @description: 高德地图,逆地理编码(坐标 -> 地址),获取地址
|
|
4
|
+
* @param {any} geocoder AMap.Geocoder
|
|
5
|
+
* @param {Position} lnglat 经纬度
|
|
6
|
+
* @return {Promise<string>} 地址
|
|
7
|
+
*/
|
|
8
|
+
export declare function getAddressByGeocoder(geocoder: any, lnglat: Position): Promise<unknown>;
|
|
9
|
+
//# sourceMappingURL=service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,oBAqBnE"}
|
package/dist/service.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description: 高德地图,逆地理编码(坐标 -> 地址),获取地址
|
|
3
|
+
* @param {any} geocoder AMap.Geocoder
|
|
4
|
+
* @param {Position} lnglat 经纬度
|
|
5
|
+
* @return {Promise<string>} 地址
|
|
6
|
+
*/
|
|
7
|
+
export function getAddressByGeocoder(geocoder, lnglat) {
|
|
8
|
+
return new Promise((resolve, reject) => {
|
|
9
|
+
// 坐标与地址插件-逆地理编码(坐标 -> 地址)
|
|
10
|
+
geocoder.getAddress(lnglat, function (status, result) {
|
|
11
|
+
if (status === 'complete' && result.regeocode) {
|
|
12
|
+
let address = '';
|
|
13
|
+
if (result.regeocode.aois.length > 0) {
|
|
14
|
+
address += result.regeocode.aois[0].name;
|
|
15
|
+
}
|
|
16
|
+
else if (result.regeocode.pois.length > 0) {
|
|
17
|
+
address += result.regeocode.pois[0].name;
|
|
18
|
+
}
|
|
19
|
+
else if (result.regeocode.roads.length > 0) {
|
|
20
|
+
address += result.regeocode.roads[0].name;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
address = result.regeocode.formattedAddress;
|
|
24
|
+
}
|
|
25
|
+
resolve(address);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
reject(result);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AACA;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAAC,QAAa,EAAE,MAAgB;IAClE,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,0BAA0B;QAC1B,QAAQ,CAAC,UAAU,CAAC,MAAM,EAAE,UAAU,MAAa,EAAE,MAAU;YAC7D,IAAI,MAAM,KAAK,UAAU,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;gBAC9C,IAAI,OAAO,GAAG,EAAE,CAAC;gBACjB,IAAI,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;oBACrC,OAAO,IAAI,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;gBAC3C,CAAC;qBAAM,IAAI,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;oBAC5C,OAAO,IAAI,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;gBAC3C,CAAC;qBAAM,IAAI,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;oBAC7C,OAAO,IAAI,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;gBAC5C,CAAC;qBAAM,CAAC;oBACN,OAAO,GAAG,MAAM,CAAC,SAAS,CAAC,gBAAgB,CAAC;gBAC9C,CAAC;gBACD,OAAO,CAAC,OAAO,CAAC,CAAC;YACnB,CAAC;iBAAM,CAAC;gBACN,MAAM,CAAC,MAAM,CAAC,CAAC;YACjB,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/package.json
CHANGED
package/src/bbox.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* 边界框(BBox)类型定义和工具函数
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import { Position } from './geometry';
|
|
5
|
+
import { GeometryType, Polygon, Position } from './geometry';
|
|
6
6
|
|
|
7
7
|
// 2D边界框 [west, south, east, north]
|
|
8
8
|
export type BBox2D = [number, number, number, number];
|
|
@@ -68,6 +68,20 @@ export function bboxToObject(bbox: BBox): BoundingBox {
|
|
|
68
68
|
};
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
|
+
//bbox转换为多边形
|
|
72
|
+
export function bboxToPolygon(bbox: BBox): Polygon {
|
|
73
|
+
const [minX, minY, maxX, maxY] = bbox
|
|
74
|
+
return {
|
|
75
|
+
type: GeometryType.Polygon,
|
|
76
|
+
coordinates: [[
|
|
77
|
+
[minX, minY],
|
|
78
|
+
[maxX, minY],
|
|
79
|
+
[maxX, maxY],
|
|
80
|
+
[minX, maxY],
|
|
81
|
+
[minX, minY]
|
|
82
|
+
]]
|
|
83
|
+
}
|
|
84
|
+
}
|
|
71
85
|
|
|
72
86
|
// 从对象转换为边界框数组
|
|
73
87
|
export function objectToBBox(boundingBox: BoundingBox): BBox {
|
|
@@ -127,6 +141,25 @@ export function isPositionInBBox(position: Position, bbox: BBox): boolean {
|
|
|
127
141
|
return inBounds;
|
|
128
142
|
}
|
|
129
143
|
|
|
144
|
+
/**
|
|
145
|
+
* @description: 验证bbox(2D)是否符合规范
|
|
146
|
+
* @param {any} bbox
|
|
147
|
+
* @return {*} boolean
|
|
148
|
+
*/
|
|
149
|
+
export function validateBBox(bbox: any): bbox is BBox {
|
|
150
|
+
if (!Array.isArray(bbox) || bbox.length < 4) {
|
|
151
|
+
return false
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const [minX, minY, maxX, maxY] = bbox
|
|
155
|
+
return typeof minX === 'number' &&
|
|
156
|
+
typeof minY === 'number' &&
|
|
157
|
+
typeof maxX === 'number' &&
|
|
158
|
+
typeof maxY === 'number' &&
|
|
159
|
+
minX <= maxX &&
|
|
160
|
+
minY <= maxY
|
|
161
|
+
}
|
|
162
|
+
|
|
130
163
|
// 计算边界框的中心点
|
|
131
164
|
export function getBBoxCenter(bbox: BBox): Position {
|
|
132
165
|
const obj = bboxToObject(bbox);
|
|
@@ -139,4 +172,35 @@ export function getBBoxCenter(bbox: BBox): Position {
|
|
|
139
172
|
}
|
|
140
173
|
|
|
141
174
|
return [centerLon, centerLat];
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* @description: 根据paths计算bbox
|
|
179
|
+
* @param {any} Position[]
|
|
180
|
+
* @return {*}
|
|
181
|
+
*/
|
|
182
|
+
export function calcGeometryBBox(geometry: Position[]) {
|
|
183
|
+
let minLng = Infinity,
|
|
184
|
+
minLat = Infinity,
|
|
185
|
+
maxLng = -Infinity,
|
|
186
|
+
maxLat = -Infinity;
|
|
187
|
+
for (const [lng, lat] of geometry) {
|
|
188
|
+
if (lng < minLng) minLng = lng;
|
|
189
|
+
if (lat < minLat) minLat = lat;
|
|
190
|
+
if (lng > maxLng) maxLng = lng;
|
|
191
|
+
if (lat > maxLat) maxLat = lat;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// 适度留白,避免多边形贴边
|
|
195
|
+
const padLng = 0.001;
|
|
196
|
+
const padLat = 0.001;
|
|
197
|
+
|
|
198
|
+
minLng = minLng - padLng;
|
|
199
|
+
minLat = minLat - padLat;
|
|
200
|
+
maxLng = maxLng + padLng;
|
|
201
|
+
maxLat = maxLat + padLat;
|
|
202
|
+
return {
|
|
203
|
+
southWest: [minLng, minLat],
|
|
204
|
+
northEast: [maxLng, maxLat],
|
|
205
|
+
};
|
|
142
206
|
}
|
package/src/index.ts
CHANGED
|
@@ -63,6 +63,7 @@ export {
|
|
|
63
63
|
BBox2D,
|
|
64
64
|
BBox3D,
|
|
65
65
|
BBox,
|
|
66
|
+
validateBBox,
|
|
66
67
|
BoundingBox,
|
|
67
68
|
is2DBBox,
|
|
68
69
|
is3DBBox,
|
|
@@ -72,7 +73,8 @@ export {
|
|
|
72
73
|
objectToBBox,
|
|
73
74
|
unionBBox,
|
|
74
75
|
isPositionInBBox,
|
|
75
|
-
getBBoxCenter
|
|
76
|
+
getBBoxCenter,
|
|
77
|
+
calcGeometryBBox
|
|
76
78
|
} from './bbox';
|
|
77
79
|
|
|
78
80
|
// 导出扩展类型
|
|
@@ -114,13 +116,10 @@ export {
|
|
|
114
116
|
createBuffer
|
|
115
117
|
} from './utils';
|
|
116
118
|
|
|
117
|
-
// 版本信息
|
|
118
|
-
export const VERSION = '1.0.0';
|
|
119
119
|
|
|
120
|
-
|
|
121
|
-
export
|
|
122
|
-
|
|
123
|
-
};
|
|
120
|
+
//导出服务函数
|
|
121
|
+
export {getAddressByGeocoder} from "./service"
|
|
122
|
+
|
|
124
123
|
|
|
125
124
|
/**
|
|
126
125
|
* 使用示例:
|
package/src/service.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Position } from "./geometry";
|
|
2
|
+
/**
|
|
3
|
+
* @description: 高德地图,逆地理编码(坐标 -> 地址),获取地址
|
|
4
|
+
* @param {any} geocoder AMap.Geocoder
|
|
5
|
+
* @param {Position} lnglat 经纬度
|
|
6
|
+
* @return {Promise<string>} 地址
|
|
7
|
+
*/
|
|
8
|
+
export function getAddressByGeocoder(geocoder: any, lnglat: Position) {
|
|
9
|
+
return new Promise((resolve, reject) => {
|
|
10
|
+
// 坐标与地址插件-逆地理编码(坐标 -> 地址)
|
|
11
|
+
geocoder.getAddress(lnglat, function (status:string, result:any) {
|
|
12
|
+
if (status === 'complete' && result.regeocode) {
|
|
13
|
+
let address = '';
|
|
14
|
+
if (result.regeocode.aois.length > 0) {
|
|
15
|
+
address += result.regeocode.aois[0].name;
|
|
16
|
+
} else if (result.regeocode.pois.length > 0) {
|
|
17
|
+
address += result.regeocode.pois[0].name;
|
|
18
|
+
} else if (result.regeocode.roads.length > 0) {
|
|
19
|
+
address += result.regeocode.roads[0].name;
|
|
20
|
+
} else {
|
|
21
|
+
address = result.regeocode.formattedAddress;
|
|
22
|
+
}
|
|
23
|
+
resolve(address);
|
|
24
|
+
} else {
|
|
25
|
+
reject(result);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
}
|