uni-leaflet 1.1.0 → 1.2.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/README.md +304 -5
- package/UniLeafletMap.vue +433 -65
- package/app-render.js +897 -95
- package/engine/canvas-tile-engine.ts +694 -79
- package/engine/factory.ts +15 -0
- package/engine/h5-map-adapter.ts +894 -133
- package/index.ts +4 -0
- package/package.json +1 -1
- package/types.ts +95 -2
- package/utils/bounds.ts +264 -0
- package/utils/cluster.ts +158 -0
- package/utils/curve.ts +86 -0
- package/utils/geojson.ts +175 -0
- package/uni-leaflet-1.0.0.tgz +0 -0
package/utils/geojson.ts
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import type { LatLngTuple, GeoJsonStyleOptions, GeoJsonStyle } from '../types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Extracts an array of [lat, lng] coordinates from any GeoJSON structure
|
|
5
|
+
* (FeatureCollection, Feature, or raw Geometry).
|
|
6
|
+
* Note: GeoJSON stores coordinates as [longitude, latitude], which is converted here
|
|
7
|
+
* to [latitude, longitude] tuples for Leaflet / Map consistency.
|
|
8
|
+
*/
|
|
9
|
+
export function extractGeoJsonLatLngs(geojson: any): LatLngTuple[] {
|
|
10
|
+
if (!geojson) return [];
|
|
11
|
+
|
|
12
|
+
const result: LatLngTuple[] = [];
|
|
13
|
+
|
|
14
|
+
function parseCoordinates(coords: any) {
|
|
15
|
+
if (!coords || !Array.isArray(coords)) return;
|
|
16
|
+
|
|
17
|
+
// Single coordinate pair: [lng, lat]
|
|
18
|
+
if (
|
|
19
|
+
coords.length >= 2 &&
|
|
20
|
+
typeof coords[0] === 'number' &&
|
|
21
|
+
typeof coords[1] === 'number'
|
|
22
|
+
) {
|
|
23
|
+
result.push([coords[1], coords[0]]);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Nested coordinate arrays
|
|
28
|
+
for (const sub of coords) {
|
|
29
|
+
parseCoordinates(sub);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function parseGeometry(geom: any) {
|
|
34
|
+
if (!geom || !geom.type) return;
|
|
35
|
+
|
|
36
|
+
if (geom.type === 'GeometryCollection' && Array.isArray(geom.geometries)) {
|
|
37
|
+
for (const g of geom.geometries) {
|
|
38
|
+
parseGeometry(g);
|
|
39
|
+
}
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (geom.coordinates) {
|
|
44
|
+
parseCoordinates(geom.coordinates);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function parseFeature(feature: any) {
|
|
49
|
+
if (!feature) return;
|
|
50
|
+
if (feature.geometry) {
|
|
51
|
+
parseGeometry(feature.geometry);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (geojson.type === 'FeatureCollection' && Array.isArray(geojson.features)) {
|
|
56
|
+
for (const f of geojson.features) {
|
|
57
|
+
parseFeature(f);
|
|
58
|
+
}
|
|
59
|
+
} else if (geojson.type === 'Feature') {
|
|
60
|
+
parseFeature(geojson);
|
|
61
|
+
} else if (geojson.type) {
|
|
62
|
+
// Direct Geometry object
|
|
63
|
+
parseGeometry(geojson);
|
|
64
|
+
} else if (Array.isArray(geojson)) {
|
|
65
|
+
for (const item of geojson) {
|
|
66
|
+
result.push(...extractGeoJsonLatLngs(item));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface NormalizedGeoJsonFeature {
|
|
74
|
+
type: 'Feature';
|
|
75
|
+
geometry: {
|
|
76
|
+
type:
|
|
77
|
+
| 'Point'
|
|
78
|
+
| 'MultiPoint'
|
|
79
|
+
| 'LineString'
|
|
80
|
+
| 'MultiLineString'
|
|
81
|
+
| 'Polygon'
|
|
82
|
+
| 'MultiPolygon'
|
|
83
|
+
| 'GeometryCollection';
|
|
84
|
+
coordinates: any;
|
|
85
|
+
};
|
|
86
|
+
properties: Record<string, any>;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Normalizes any GeoJSON input into an array of Standard Features
|
|
91
|
+
*/
|
|
92
|
+
export function normalizeGeoJsonFeatures(
|
|
93
|
+
geojson: any
|
|
94
|
+
): NormalizedGeoJsonFeature[] {
|
|
95
|
+
if (!geojson) return [];
|
|
96
|
+
|
|
97
|
+
if (geojson.type === 'FeatureCollection' && Array.isArray(geojson.features)) {
|
|
98
|
+
return geojson.features.filter((f: any) => f && f.geometry);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (geojson.type === 'Feature' && geojson.geometry) {
|
|
102
|
+
return [geojson];
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (geojson.type) {
|
|
106
|
+
// Direct geometry
|
|
107
|
+
return [
|
|
108
|
+
{
|
|
109
|
+
type: 'Feature',
|
|
110
|
+
geometry: geojson,
|
|
111
|
+
properties: {},
|
|
112
|
+
},
|
|
113
|
+
];
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (Array.isArray(geojson)) {
|
|
117
|
+
const list: NormalizedGeoJsonFeature[] = [];
|
|
118
|
+
for (const item of geojson) {
|
|
119
|
+
list.push(...normalizeGeoJsonFeatures(item));
|
|
120
|
+
}
|
|
121
|
+
return list;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return [];
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Resolve style for a given feature from static or functional GeoJsonStyle
|
|
129
|
+
*/
|
|
130
|
+
export function resolveGeoJsonStyle(
|
|
131
|
+
style: GeoJsonStyle | undefined,
|
|
132
|
+
feature: any,
|
|
133
|
+
defaultColor = '#3b82f6'
|
|
134
|
+
): GeoJsonStyleOptions {
|
|
135
|
+
let computed: GeoJsonStyleOptions = {};
|
|
136
|
+
if (typeof style === 'function') {
|
|
137
|
+
computed = style(feature) || {};
|
|
138
|
+
} else if (style && typeof style === 'object') {
|
|
139
|
+
computed = { ...style };
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return {
|
|
143
|
+
color: computed.color || defaultColor,
|
|
144
|
+
weight: computed.weight ?? 2,
|
|
145
|
+
opacity: computed.opacity ?? 1,
|
|
146
|
+
fillColor: computed.fillColor || computed.color || defaultColor,
|
|
147
|
+
fillOpacity: computed.fillOpacity ?? 0.25,
|
|
148
|
+
dashArray: computed.dashArray,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Ray-casting algorithm to test if a 2D point [x, y] is inside a polygon ring
|
|
154
|
+
*/
|
|
155
|
+
export function isPointInPolygon2D(
|
|
156
|
+
pt: [number, number],
|
|
157
|
+
ring: [number, number][]
|
|
158
|
+
): boolean {
|
|
159
|
+
let inside = false;
|
|
160
|
+
const x = pt[0];
|
|
161
|
+
const y = pt[1];
|
|
162
|
+
|
|
163
|
+
for (let i = 0, j = ring.length - 1; i < ring.length; j = i++) {
|
|
164
|
+
const xi = ring[i][0];
|
|
165
|
+
const yi = ring[i][1];
|
|
166
|
+
const xj = ring[j][0];
|
|
167
|
+
const yj = ring[j][1];
|
|
168
|
+
|
|
169
|
+
const intersect =
|
|
170
|
+
yi > y !== yj > y && x < ((xj - xi) * (y - yi)) / (yj - yi) + xi;
|
|
171
|
+
if (intersect) inside = !inside;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return inside;
|
|
175
|
+
}
|
package/uni-leaflet-1.0.0.tgz
DELETED
|
Binary file
|