@loongbao-web-gis-utils/draw-utils-core 0.1.0 → 0.3.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/dist/index.cjs +28 -0
- package/dist/index.d.ts +288 -9
- package/dist/index.js +5369 -5
- package/package.json +25 -7
- package/dist/DrawTool.d.ts +0 -50
- package/dist/DrawTool.js +0 -358
- package/dist/adapter/index.d.ts +0 -48
- package/dist/adapter/index.js +0 -1
- package/dist/state-machine/index.d.ts +0 -12
- package/dist/state-machine/index.js +0 -42
- package/dist/types/config.d.ts +0 -69
- package/dist/types/config.js +0 -7
- package/dist/types/feature.d.ts +0 -60
- package/dist/types/feature.js +0 -1
- package/dist/types/index.d.ts +0 -4
- package/dist/types/index.js +0 -2
- package/dist/types/state.d.ts +0 -6
- package/dist/types/state.js +0 -7
- package/dist/utils/index.d.ts +0 -11
- package/dist/utils/index.js +0 -101
package/dist/types/config.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export const DEFAULT_DRAW_CONFIG = { limit: 1, enableLimitMsg: false, enableEdit: false, enableDel: false, showLenOnInsert: false, showAreaOnInsert: false, showLenForAll: false, showAreaForAll: false, debug: false };
|
|
2
|
-
export const DEFAULT_RECT_DETAILS = { name: '', lineWidth: 2, lineType: 'solid', strokeLineDash: '15 15 15 15', lineRgba: 'rgba(255,0,0,1)', fillRgba: 'rgba(255,0,0,0.5)', textRgba: 'rgba(255,255,255,1)' };
|
|
3
|
-
export const DEFAULT_TRIANGLE_DETAILS = { name: '', lineWidth: 2, lineType: 'solid', strokeLineDash: '15 15 15 15', lineRgba: 'rgba(0,0,255,1)', fillRgba: 'rgba(0,0,255,0.5)', textRgba: 'rgba(255,255,255,1)' };
|
|
4
|
-
export const DEFAULT_CIRCLE_DETAILS = { name: '', radius: 0, lineWidth: 2, lineType: 'solid', strokeLineDash: '15 15 15 15', lineRgba: 'rgba(34,197,94,1)', fillRgba: 'rgba(34,197,94,0.5)', textRgba: 'rgba(255,255,255,1)' };
|
|
5
|
-
export const DEFAULT_LINE_DETAILS = { name: '', lineWidth: 2, lineType: 'solid', strokeLineDash: '15 15 15 15', lineRgba: 'rgba(234,179,8,1)', textRgba: 'rgba(255,255,255,1)' };
|
|
6
|
-
export const DEFAULT_POLYLINE_DETAILS = { name: '', lineWidth: 2, lineType: 'solid', strokeLineDash: '15 15 15 15', lineRgba: 'rgba(234,179,8,1)', textRgba: 'rgba(255,255,255,1)' };
|
|
7
|
-
export const DEFAULT_SHAPE_DETAILS = { name: '', lineWidth: 2, lineType: 'solid', strokeLineDash: '15 15 15 15', lineRgba: 'rgba(139,92,246,1)', fillRgba: 'rgba(139,92,246,0.5)', textRgba: 'rgba(255,255,255,1)' };
|
package/dist/types/feature.d.ts
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
export interface FeatureInfo {
|
|
2
|
-
id: number;
|
|
3
|
-
type: FeatureType;
|
|
4
|
-
wkt: string;
|
|
5
|
-
details: RectInfo | TriangleInfo | CircleInfo | LineInfo | PolylineInfo | ShapeInfo;
|
|
6
|
-
}
|
|
7
|
-
export type FeatureType = 'rect' | 'triangle' | 'circle' | 'line' | 'polyline' | 'customShape';
|
|
8
|
-
export interface RectInfo {
|
|
9
|
-
name: string;
|
|
10
|
-
lineWidth: number;
|
|
11
|
-
lineType: 'dashed' | 'solid';
|
|
12
|
-
strokeLineDash: string;
|
|
13
|
-
lineRgba: string;
|
|
14
|
-
fillRgba: string;
|
|
15
|
-
textRgba: string;
|
|
16
|
-
}
|
|
17
|
-
export interface TriangleInfo {
|
|
18
|
-
name: string;
|
|
19
|
-
lineWidth: number;
|
|
20
|
-
lineType: 'dashed' | 'solid';
|
|
21
|
-
strokeLineDash: string;
|
|
22
|
-
lineRgba: string;
|
|
23
|
-
fillRgba: string;
|
|
24
|
-
textRgba: string;
|
|
25
|
-
}
|
|
26
|
-
export interface CircleInfo {
|
|
27
|
-
name: string;
|
|
28
|
-
radius: number;
|
|
29
|
-
lineWidth: number;
|
|
30
|
-
lineType: 'dashed' | 'solid';
|
|
31
|
-
strokeLineDash: string;
|
|
32
|
-
lineRgba: string;
|
|
33
|
-
fillRgba: string;
|
|
34
|
-
textRgba: string;
|
|
35
|
-
}
|
|
36
|
-
export interface LineInfo {
|
|
37
|
-
name: string;
|
|
38
|
-
lineWidth: number;
|
|
39
|
-
lineType: 'dashed' | 'solid';
|
|
40
|
-
strokeLineDash: string;
|
|
41
|
-
lineRgba: string;
|
|
42
|
-
textRgba: string;
|
|
43
|
-
}
|
|
44
|
-
export interface PolylineInfo {
|
|
45
|
-
name: string;
|
|
46
|
-
lineWidth: number;
|
|
47
|
-
lineType: 'dashed' | 'solid';
|
|
48
|
-
strokeLineDash: string;
|
|
49
|
-
lineRgba: string;
|
|
50
|
-
textRgba: string;
|
|
51
|
-
}
|
|
52
|
-
export interface ShapeInfo {
|
|
53
|
-
name: string;
|
|
54
|
-
lineWidth: number;
|
|
55
|
-
lineType: 'dashed' | 'solid';
|
|
56
|
-
strokeLineDash: string;
|
|
57
|
-
lineRgba: string;
|
|
58
|
-
fillRgba: string;
|
|
59
|
-
textRgba: string;
|
|
60
|
-
}
|
package/dist/types/feature.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/types/index.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export type { FeatureInfo, FeatureType, RectInfo, TriangleInfo, CircleInfo, LineInfo, PolylineInfo, ShapeInfo } from './feature';
|
|
2
|
-
export type { DrawConfig } from './config';
|
|
3
|
-
export { DEFAULT_DRAW_CONFIG, DEFAULT_RECT_DETAILS, DEFAULT_TRIANGLE_DETAILS, DEFAULT_CIRCLE_DETAILS, DEFAULT_LINE_DETAILS, DEFAULT_POLYLINE_DETAILS, DEFAULT_SHAPE_DETAILS, } from './config';
|
|
4
|
-
export { DrawState } from './state';
|
package/dist/types/index.js
DELETED
package/dist/types/state.d.ts
DELETED
package/dist/types/state.js
DELETED
package/dist/utils/index.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export declare function generateUniqueId(): number;
|
|
2
|
-
export declare function generateFeatureName(length?: number): string;
|
|
3
|
-
export declare function isPointInPolygon(point: [number, number], polygon: [number, number][]): boolean;
|
|
4
|
-
export declare function parseWkt(wkt: string): [number, number][];
|
|
5
|
-
export declare function toWktPolygon(coordinates: [number, number][]): string;
|
|
6
|
-
export declare function toWktLineString(coordinates: [number, number][]): string;
|
|
7
|
-
export declare function geoDistance(a: [number, number], b: [number, number]): number;
|
|
8
|
-
export declare function geoArea(coords: [number, number][]): number;
|
|
9
|
-
export declare function geoPolygonCenter(coords: [number, number][]): [number, number];
|
|
10
|
-
export declare function formatMeters(m: number): string;
|
|
11
|
-
export declare function formatArea(area: number): string;
|
package/dist/utils/index.js
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
let counter = 0;
|
|
2
|
-
export function generateUniqueId() {
|
|
3
|
-
counter += 1;
|
|
4
|
-
return Date.now() * 100 + counter;
|
|
5
|
-
}
|
|
6
|
-
export function generateFeatureName(length = 8) {
|
|
7
|
-
const chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
|
8
|
-
let result = '';
|
|
9
|
-
for (let i = 0; i < length; i++) {
|
|
10
|
-
result += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
11
|
-
}
|
|
12
|
-
return result;
|
|
13
|
-
}
|
|
14
|
-
export function isPointInPolygon(point, polygon) {
|
|
15
|
-
let inside = false;
|
|
16
|
-
const [px, py] = point;
|
|
17
|
-
let j = polygon.length - 1;
|
|
18
|
-
for (let i = 0; i < polygon.length; i++) {
|
|
19
|
-
const [xi, yi] = polygon[i];
|
|
20
|
-
const [xj, yj] = polygon[j];
|
|
21
|
-
if (yi > py !== yj > py && px < ((xj - xi) * (py - yi)) / (yj - yi) + xi) {
|
|
22
|
-
inside = !inside;
|
|
23
|
-
}
|
|
24
|
-
j = i;
|
|
25
|
-
}
|
|
26
|
-
return inside;
|
|
27
|
-
}
|
|
28
|
-
export function parseWkt(wkt) {
|
|
29
|
-
const m = wkt.match(/\((.*)\)/);
|
|
30
|
-
if (!m)
|
|
31
|
-
throw new Error(`Invalid WKT: ${wkt}`);
|
|
32
|
-
let inner = m[1];
|
|
33
|
-
inner = inner.replace(/^\(/, '').replace(/\)$/, '');
|
|
34
|
-
return inner.split(',').map((pair) => {
|
|
35
|
-
const [x, y] = pair.trim().split(/\s+/).map(Number);
|
|
36
|
-
return [x, y];
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
export function toWktPolygon(coordinates) {
|
|
40
|
-
const coords = coordinates.map(([x, y]) => `${x} ${y}`).join(', ');
|
|
41
|
-
return `POLYGON((${coords}))`;
|
|
42
|
-
}
|
|
43
|
-
export function toWktLineString(coordinates) {
|
|
44
|
-
const coords = coordinates.map(([x, y]) => `${x} ${y}`).join(', ');
|
|
45
|
-
return `LINESTRING(${coords})`;
|
|
46
|
-
}
|
|
47
|
-
export function geoDistance(a, b) {
|
|
48
|
-
const R = 6371000;
|
|
49
|
-
const dLat = (b[1] - a[1]) * Math.PI / 180;
|
|
50
|
-
const dLon = (b[0] - a[0]) * Math.PI / 180;
|
|
51
|
-
const lat1 = a[1] * Math.PI / 180;
|
|
52
|
-
const lat2 = b[1] * Math.PI / 180;
|
|
53
|
-
const sinDLat = Math.sin(dLat / 2);
|
|
54
|
-
const sinDLon = Math.sin(dLon / 2);
|
|
55
|
-
const h = sinDLat * sinDLat + Math.cos(lat1) * Math.cos(lat2) * sinDLon * sinDLon;
|
|
56
|
-
return 2 * R * Math.atan2(Math.sqrt(h), Math.sqrt(1 - h));
|
|
57
|
-
}
|
|
58
|
-
export function geoArea(coords) {
|
|
59
|
-
const n = coords.length;
|
|
60
|
-
if (n < 3)
|
|
61
|
-
return 0;
|
|
62
|
-
let area = 0;
|
|
63
|
-
for (let i = 0; i < n; i++) {
|
|
64
|
-
const j = (i + 1) % n;
|
|
65
|
-
area += coords[i][0] * coords[j][1];
|
|
66
|
-
area -= coords[j][0] * coords[i][1];
|
|
67
|
-
}
|
|
68
|
-
area = Math.abs(area) / 2;
|
|
69
|
-
const centerLat = coords.reduce((s, c) => s + c[1], 0) / n;
|
|
70
|
-
const latRad = centerLat * Math.PI / 180;
|
|
71
|
-
const mPerDegLon = 111320 * Math.cos(latRad);
|
|
72
|
-
const mPerDegLat = 111320;
|
|
73
|
-
return area * mPerDegLon * mPerDegLat;
|
|
74
|
-
}
|
|
75
|
-
export function geoPolygonCenter(coords) {
|
|
76
|
-
const n = coords.length;
|
|
77
|
-
let cx = 0, cy = 0;
|
|
78
|
-
for (const c of coords) {
|
|
79
|
-
cx += c[0];
|
|
80
|
-
cy += c[1];
|
|
81
|
-
}
|
|
82
|
-
return [cx / n, cy / n];
|
|
83
|
-
}
|
|
84
|
-
export function formatMeters(m) {
|
|
85
|
-
if (m < 0.01)
|
|
86
|
-
return '0.00米';
|
|
87
|
-
if (m < 1)
|
|
88
|
-
return m.toFixed(2) + '米';
|
|
89
|
-
if (m < 1000)
|
|
90
|
-
return m.toFixed(1) + '米';
|
|
91
|
-
return (m / 1000).toFixed(2) + '千米';
|
|
92
|
-
}
|
|
93
|
-
export function formatArea(area) {
|
|
94
|
-
if (area < 0.01)
|
|
95
|
-
return '0.00㎡';
|
|
96
|
-
if (area < 1)
|
|
97
|
-
return area.toFixed(2) + '㎡';
|
|
98
|
-
if (area < 10000)
|
|
99
|
-
return area.toFixed(1) + '㎡';
|
|
100
|
-
return (area / 1000000).toFixed(2) + 'k㎡';
|
|
101
|
-
}
|