smap-leaflet 0.0.0-stage → 2.6.1
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/CHANGELOG.md +199 -0
- package/LICENSE +15 -0
- package/README.md +663 -2
- package/dist/index.d.ts +1240 -0
- package/dist/measure-BV-2_Fc1.cjs +2 -0
- package/dist/measure-BV-2_Fc1.cjs.map +1 -0
- package/dist/measure-DJVSnHDg.js +10 -0
- package/dist/measure-DJVSnHDg.js.map +1 -0
- package/dist/smap-leaflet.cjs +2 -0
- package/dist/smap-leaflet.cjs.map +1 -0
- package/dist/smap-leaflet.mjs +2381 -0
- package/dist/smap-leaflet.mjs.map +1 -0
- package/dist/style.css +1 -0
- package/llms.txt +557 -0
- package/package.json +74 -4
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,1240 @@
|
|
|
1
|
+
import * as L_2 from 'leaflet';
|
|
2
|
+
|
|
3
|
+
export declare interface AdministrativeParams extends ServiceKeyParam {
|
|
4
|
+
/** District name, or its 9-digit code such as "156340100" */
|
|
5
|
+
keyword?: string;
|
|
6
|
+
/** @deprecated Use `keyword` */
|
|
7
|
+
searchWord?: string;
|
|
8
|
+
/** How many levels of sub-districts to include (0–3). Default 0 */
|
|
9
|
+
childLevel?: 0 | 1 | 2 | 3;
|
|
10
|
+
/** Include boundary geometry (WKT). Default false */
|
|
11
|
+
extensions?: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export declare type AreaUnit = 'auto' | 'm2' | 'km2' | 'ha' | 'mu';
|
|
15
|
+
|
|
16
|
+
export declare interface AttributionOptions {
|
|
17
|
+
prefix?: string;
|
|
18
|
+
content?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Base class of the measure tools.
|
|
23
|
+
*
|
|
24
|
+
* It owns the whole lifecycle — drawing, labels, results, events, cleanup. A
|
|
25
|
+
* concrete tool only says how to read numbers off a shape and how to word them.
|
|
26
|
+
*/
|
|
27
|
+
export declare abstract class BaseMeasureTool implements MeasureTool {
|
|
28
|
+
protected map: L_2.Map;
|
|
29
|
+
protected options: MeasureOptions;
|
|
30
|
+
/** Holds the finished shapes */
|
|
31
|
+
protected layerGroup: L_2.FeatureGroup;
|
|
32
|
+
private entries;
|
|
33
|
+
/** Labels of the drawing in progress */
|
|
34
|
+
private draft;
|
|
35
|
+
private session;
|
|
36
|
+
private emitter;
|
|
37
|
+
private clickHandler;
|
|
38
|
+
private editor;
|
|
39
|
+
private snapper;
|
|
40
|
+
private destroyed;
|
|
41
|
+
/** @deprecated Nothing needs loading any more. Kept so existing calls keep working */
|
|
42
|
+
static preload(): Promise<void>;
|
|
43
|
+
constructor(map: L_2.Map, options?: MeasureOptions);
|
|
44
|
+
/** Which shape this tool draws */
|
|
45
|
+
protected abstract readonly drawType: MeasureType;
|
|
46
|
+
/** Read the measurement off a finished shape */
|
|
47
|
+
protected abstract measure(layer: any): MeasureGeometry;
|
|
48
|
+
/** Where the result label goes */
|
|
49
|
+
protected abstract anchor(result: MeasureResult): L_2.LatLng;
|
|
50
|
+
/** Default wording of a label */
|
|
51
|
+
protected abstract defaultText(label: MeasureLabel): string;
|
|
52
|
+
/** What the deprecated `valueFormatter` option receives for this tool */
|
|
53
|
+
protected abstract legacyValue(label: MeasureLabel): number | L_2.LatLng[];
|
|
54
|
+
/** Labels to show while drawing; only the distance tool has any */
|
|
55
|
+
protected draftLabels(_latlngs: L_2.LatLng[]): LabelSpec[];
|
|
56
|
+
/** Labels of a finished measurement. By default just the result label */
|
|
57
|
+
protected resultLabels(result: MeasureResult): LabelSpec[];
|
|
58
|
+
get type(): MeasureType;
|
|
59
|
+
get measuring(): boolean;
|
|
60
|
+
enable(): void;
|
|
61
|
+
disable(): void;
|
|
62
|
+
get editing(): boolean;
|
|
63
|
+
startEdit(): void;
|
|
64
|
+
undo(): boolean;
|
|
65
|
+
finishEdit(save?: boolean): void;
|
|
66
|
+
/** Read the numbers off the shape again and redraw its labels */
|
|
67
|
+
private refresh;
|
|
68
|
+
setOptions(options: Partial<MeasureOptions>): void;
|
|
69
|
+
getResults(): MeasureResult[];
|
|
70
|
+
remove(id: string): void;
|
|
71
|
+
clearAll(): void;
|
|
72
|
+
on<K extends keyof MeasureEvents>(type: K, handler: (event: MeasureEvents[K]) => void): void;
|
|
73
|
+
off<K extends keyof MeasureEvents>(type: K, handler: (event: MeasureEvents[K]) => void): void;
|
|
74
|
+
destroy(): void;
|
|
75
|
+
private handleVertex;
|
|
76
|
+
private handleCreated;
|
|
77
|
+
private setDraft;
|
|
78
|
+
/** Put labels on the map. A label is a permanent tooltip on an invisible marker */
|
|
79
|
+
private renderLabels;
|
|
80
|
+
protected getShapeOptions(): L_2.PathOptions;
|
|
81
|
+
/** Text of a label: `formatLabel`, else the deprecated `valueFormatter`, else the default */
|
|
82
|
+
protected text(label: MeasureLabel, legacyPrefix?: string): string;
|
|
83
|
+
/** Plain label, used for intermediate values */
|
|
84
|
+
protected labelHtml(content: string): string;
|
|
85
|
+
/** Emphasised label of a finished measurement, with the button that removes it */
|
|
86
|
+
protected resultHtml(result: MeasureResult, legacyPrefix?: string): string;
|
|
87
|
+
/** Labels take the colour of this tool's lines */
|
|
88
|
+
private accentStyle;
|
|
89
|
+
protected formatLength(meters: number): string;
|
|
90
|
+
protected formatArea(sqMeters: number): string;
|
|
91
|
+
/** Length of a path in metres */
|
|
92
|
+
protected pathLength(latlngs: L_2.LatLng[]): number;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** BD-09 → GCJ-02 */
|
|
96
|
+
export declare function bd09ToGcj02(lng: number, lat: number): Coord;
|
|
97
|
+
|
|
98
|
+
/** BD-09 → WGS-84 */
|
|
99
|
+
export declare function bd09ToWgs84(lng: number, lat: number): Coord;
|
|
100
|
+
|
|
101
|
+
/** Every tile type shipped with the library (kept in sync with `providers` by a test) */
|
|
102
|
+
export declare const BUILTIN_TILE_TYPES: readonly ["TianDiTu.Normal.Map", "TianDiTu.Normal.Annotion", "TianDiTu.Satellite.Map", "TianDiTu.Satellite.Annotion", "TianDiTu.Terrain.Map", "TianDiTu.Terrain.Annotion", "GaoDe.Normal.Map", "GaoDe.Satellite.Map", "GaoDe.Satellite.Annotion", "GaoDe.Brief.Map", "Google.Normal.Map", "Google.Satellite.Map", "Google.Satellite.Annotion", "Geoq.Normal.Map", "Geoq.Normal.PurplishBlue", "Geoq.Normal.Gray", "Geoq.Normal.Warm", "Geoq.Theme.Hydro", "OSM.Normal.Map", "Baidu.Normal.Map", "Baidu.Satellite.Map", "Baidu.Satellite.Annotion", "BaiduV3.Normal.Map", "Tencent.Normal.Map", "Tencent.Satellite.Map", "Tencent.Terrain.Map", "Mapbox.Satellite.Map"];
|
|
103
|
+
|
|
104
|
+
/** Tile types shipped with the library */
|
|
105
|
+
export declare type BuiltinTileType = (typeof BUILTIN_TILE_TYPES)[number];
|
|
106
|
+
|
|
107
|
+
export declare class CircleMeasure extends BaseMeasureTool {
|
|
108
|
+
protected readonly drawType = "circle";
|
|
109
|
+
protected measure(layer: L_2.Circle): MeasureGeometry;
|
|
110
|
+
protected anchor(result: MeasureResult): L_2.LatLng;
|
|
111
|
+
protected defaultText(label: MeasureLabel): string;
|
|
112
|
+
protected legacyValue(label: MeasureLabel): number;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Points that merge into counted bubbles when they would overlap.
|
|
117
|
+
*
|
|
118
|
+
* Clustering is a grid over the current zoom level: points falling into the same
|
|
119
|
+
* cell become one bubble at their average position. It is recomputed for the
|
|
120
|
+
* visible area on every move, which keeps it cheap for tens of thousands of points.
|
|
121
|
+
*/
|
|
122
|
+
export declare class ClusterLayer<T extends PointInput = PointInput> extends L_2.FeatureGroup {
|
|
123
|
+
private items;
|
|
124
|
+
private clusterOptions;
|
|
125
|
+
private canvas;
|
|
126
|
+
constructor(points: T[], options?: ClusterOptions<T>, canvas?: {
|
|
127
|
+
renderer?: L_2.Renderer;
|
|
128
|
+
});
|
|
129
|
+
/** Replace the data */
|
|
130
|
+
setPoints(points: T[]): this;
|
|
131
|
+
/** Bounds of all points, not just the ones currently drawn */
|
|
132
|
+
getBounds(): L_2.LatLngBounds;
|
|
133
|
+
onAdd(map: L_2.Map): this;
|
|
134
|
+
onRemove(map: L_2.Map): this;
|
|
135
|
+
private index;
|
|
136
|
+
private refresh;
|
|
137
|
+
private pointMarker;
|
|
138
|
+
private clusterMarker;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export declare interface ClusterOptions<T = PointInput> extends PointLayerOptions<T> {
|
|
142
|
+
/** Points closer than this (pixels) merge into one bubble. Default 60 */
|
|
143
|
+
clusterRadius?: number;
|
|
144
|
+
/** From this zoom level on, every point is shown on its own */
|
|
145
|
+
disableClusteringAtZoom?: number;
|
|
146
|
+
/** Called when a bubble is clicked. By default the map zooms in on it */
|
|
147
|
+
onClusterClick?: (points: T[], event: L_2.LeafletMouseEvent) => void;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Right-click menus for the map and for individual layers.
|
|
152
|
+
*/
|
|
153
|
+
export declare class ContextMenu {
|
|
154
|
+
private map;
|
|
155
|
+
private mapItems;
|
|
156
|
+
private bound;
|
|
157
|
+
private el;
|
|
158
|
+
constructor(map: L_2.Map);
|
|
159
|
+
/** Set the menu shown when right-clicking the map itself. Pass null to remove it */
|
|
160
|
+
setItems(items: ContextMenuItems | null): void;
|
|
161
|
+
/** Give a layer its own menu. Returns a function that removes it again */
|
|
162
|
+
bind(layer: L_2.Layer, items: ContextMenuItems): () => void;
|
|
163
|
+
unbind(layer: L_2.Layer): void;
|
|
164
|
+
/** Close the menu if it is open */
|
|
165
|
+
hide(): void;
|
|
166
|
+
destroy(): void;
|
|
167
|
+
private onMapContextMenu;
|
|
168
|
+
private onPointerDown;
|
|
169
|
+
private onKeyDown;
|
|
170
|
+
private open;
|
|
171
|
+
private renderItem;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export declare interface ContextMenuContext {
|
|
175
|
+
/** Where the right click happened */
|
|
176
|
+
latlng: L_2.LatLng;
|
|
177
|
+
containerPoint: L_2.Point;
|
|
178
|
+
/** The layer that was right-clicked, for menus bound to a layer */
|
|
179
|
+
layer?: L_2.Layer;
|
|
180
|
+
map: L_2.Map;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export declare type ContextMenuItem = {
|
|
184
|
+
text: string;
|
|
185
|
+
onClick?: (context: ContextMenuContext) => void;
|
|
186
|
+
disabled?: boolean;
|
|
187
|
+
/** Render as a destructive action */
|
|
188
|
+
danger?: boolean;
|
|
189
|
+
}
|
|
190
|
+
/** Separator */
|
|
191
|
+
| '-';
|
|
192
|
+
|
|
193
|
+
/** A fixed list, or a function building the list for each right click */
|
|
194
|
+
export declare type ContextMenuItems = ContextMenuItem[] | ((context: ContextMenuContext) => ContextMenuItem[]);
|
|
195
|
+
|
|
196
|
+
export declare class ControlManager {
|
|
197
|
+
private map;
|
|
198
|
+
private host?;
|
|
199
|
+
private controls;
|
|
200
|
+
private layers?;
|
|
201
|
+
private refreshLayers;
|
|
202
|
+
private refreshOverlays;
|
|
203
|
+
constructor(map: L_2.Map, host?: TileHost, layers?: LayerManager);
|
|
204
|
+
/**
|
|
205
|
+
* Add a control by type. Adding the same type again replaces the previous one.
|
|
206
|
+
*/
|
|
207
|
+
add(type: 'layers', options: LayersControlOptions): L_2.Control;
|
|
208
|
+
add(type: 'overlays', options?: OverlaysControlOptions): L_2.Control;
|
|
209
|
+
add(type: 'attribution' | 'zoom' | 'scale', options?: ControlOptions & AttributionOptions): L_2.Control;
|
|
210
|
+
/** Base-map switcher: one button per entry, the current one highlighted */
|
|
211
|
+
private createLayersControl;
|
|
212
|
+
/** Switches for the layers registered in `smap.layer` */
|
|
213
|
+
private createOverlaysControl;
|
|
214
|
+
/**
|
|
215
|
+
* Remove a control by type
|
|
216
|
+
*/
|
|
217
|
+
remove(type: string): void;
|
|
218
|
+
/**
|
|
219
|
+
* Remove all managed controls
|
|
220
|
+
*/
|
|
221
|
+
removeAll(): void;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export declare interface ControlOptions {
|
|
225
|
+
position?: L_2.ControlPosition;
|
|
226
|
+
[key: string]: unknown;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
export declare type ControlType = 'attribution' | 'zoom' | 'scale' | 'layers' | 'overlays';
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Coordinate system conversion utilities
|
|
233
|
+
* Supports: WGS-84, GCJ-02 (火星坐标), BD-09 (百度坐标)
|
|
234
|
+
*/
|
|
235
|
+
export declare interface Coord {
|
|
236
|
+
lng: number;
|
|
237
|
+
lat: number;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
declare type CoordSystem = 'wgs84' | 'gcj02' | 'bd09';
|
|
241
|
+
|
|
242
|
+
export declare type CoordType = 'wgs84' | 'gcj02' | 'bd09';
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Create a china tile layer from type string like "GaoDe.Normal.Map"
|
|
246
|
+
*/
|
|
247
|
+
export declare function createChinaTileLayer(type: string, options?: {
|
|
248
|
+
key?: string;
|
|
249
|
+
zIndex?: number;
|
|
250
|
+
[k: string]: any;
|
|
251
|
+
}): L_2.TileLayer;
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Snapping to the vertices and edges of other shapes.
|
|
255
|
+
* A vertex wins over an edge: corners are what people aim for.
|
|
256
|
+
*/
|
|
257
|
+
export declare function createSnapper(map: L_2.Map, sources: () => L_2.Layer[], distance?: number): Snapper;
|
|
258
|
+
|
|
259
|
+
export declare type DrawEvents = {
|
|
260
|
+
/** Drawing a shape has started */
|
|
261
|
+
drawstart: {
|
|
262
|
+
type: DrawType;
|
|
263
|
+
};
|
|
264
|
+
/** Drawing ended, whether a shape was finished or it was cancelled */
|
|
265
|
+
drawstop: {
|
|
266
|
+
type: DrawType;
|
|
267
|
+
};
|
|
268
|
+
/** A shape was finished */
|
|
269
|
+
created: {
|
|
270
|
+
layer: L_2.Layer;
|
|
271
|
+
type: DrawType;
|
|
272
|
+
};
|
|
273
|
+
/** A shape is being changed in edit mode: fired while dragging, and after an undo */
|
|
274
|
+
editing: {
|
|
275
|
+
layer: L_2.Layer;
|
|
276
|
+
};
|
|
277
|
+
/** Shapes were changed in edit mode and saved */
|
|
278
|
+
edited: {
|
|
279
|
+
layers: L_2.Layer[];
|
|
280
|
+
};
|
|
281
|
+
/** Shapes were removed */
|
|
282
|
+
removed: {
|
|
283
|
+
layers: L_2.Layer[];
|
|
284
|
+
};
|
|
285
|
+
/** Anything changed; carries the current content as GeoJSON */
|
|
286
|
+
change: GeoJSON.FeatureCollection;
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
export declare interface DrawOptions {
|
|
290
|
+
/** Style of drawn lines and areas */
|
|
291
|
+
shapeOptions?: L_2.PathOptions;
|
|
292
|
+
/** Icon of drawn markers. Defaults to a round dot */
|
|
293
|
+
markerIcon?: L_2.Icon | L_2.DivIcon;
|
|
294
|
+
/**
|
|
295
|
+
* Snap to the vertices and edges of the shapes already drawn, while drawing and
|
|
296
|
+
* editing. Pass an object to change the distance or to snap to other layers too.
|
|
297
|
+
*/
|
|
298
|
+
snap?: boolean | SnapOptions;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Draw, edit and export shapes. Create it with `smap.createDraw()`.
|
|
303
|
+
*/
|
|
304
|
+
export declare class DrawTool {
|
|
305
|
+
/** Everything drawn or loaded lives in this group */
|
|
306
|
+
readonly group: L_2.FeatureGroup;
|
|
307
|
+
private map;
|
|
308
|
+
private options;
|
|
309
|
+
private emitter;
|
|
310
|
+
private session;
|
|
311
|
+
private editor;
|
|
312
|
+
private snapper;
|
|
313
|
+
/** @deprecated Nothing needs loading any more. Kept so existing calls keep working */
|
|
314
|
+
static preload(): Promise<void>;
|
|
315
|
+
constructor(map: L_2.Map, options?: DrawOptions);
|
|
316
|
+
/** Shape currently being drawn, or null */
|
|
317
|
+
get drawing(): DrawType | null;
|
|
318
|
+
/** Start drawing one shape. Drawing ends by itself when the shape is finished */
|
|
319
|
+
draw(type: DrawType): void;
|
|
320
|
+
/** Abandon the shape being drawn */
|
|
321
|
+
cancel(): void;
|
|
322
|
+
/** True while shapes can be dragged and reshaped */
|
|
323
|
+
get editing(): boolean;
|
|
324
|
+
/** Make every shape editable: drag vertices, move markers, resize rectangles and circles */
|
|
325
|
+
startEdit(): void;
|
|
326
|
+
/** True when there is a change to take back in edit mode */
|
|
327
|
+
get canUndo(): boolean;
|
|
328
|
+
/** Take back the last change made in edit mode (also Ctrl/Cmd+Z). Returns false when there is none */
|
|
329
|
+
undo(): boolean;
|
|
330
|
+
/** Leave edit mode, keeping (`save = true`) or discarding the changes */
|
|
331
|
+
finishEdit(save?: boolean): void;
|
|
332
|
+
getLayers(): L_2.Layer[];
|
|
333
|
+
/** Remove one shape */
|
|
334
|
+
remove(layer: L_2.Layer): void;
|
|
335
|
+
/** Remove every shape */
|
|
336
|
+
clear(): void;
|
|
337
|
+
/**
|
|
338
|
+
* Export everything as GeoJSON (WGS-84).
|
|
339
|
+
* A circle becomes a Point with `properties.radius` in metres.
|
|
340
|
+
*/
|
|
341
|
+
toGeoJSON(): GeoJSON.FeatureCollection;
|
|
342
|
+
/**
|
|
343
|
+
* Load shapes from GeoJSON so they can be shown and edited.
|
|
344
|
+
* A Point with `properties.radius` becomes a circle.
|
|
345
|
+
*/
|
|
346
|
+
load(geojson: GeoJSON.GeoJsonObject, options?: {
|
|
347
|
+
replace?: boolean;
|
|
348
|
+
}): void;
|
|
349
|
+
on<K extends keyof DrawEvents>(type: K, handler: (event: DrawEvents[K]) => void): void;
|
|
350
|
+
off<K extends keyof DrawEvents>(type: K, handler: (event: DrawEvents[K]) => void): void;
|
|
351
|
+
destroy(): void;
|
|
352
|
+
private emitChange;
|
|
353
|
+
private shapeOptions;
|
|
354
|
+
private markerIcon;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
export declare type DrawType = 'marker' | 'polyline' | 'polygon' | 'rectangle' | 'circle';
|
|
358
|
+
|
|
359
|
+
export declare interface ExportImageOptions {
|
|
360
|
+
/** Image format. Default 'image/png' */
|
|
361
|
+
type?: 'image/png' | 'image/jpeg' | 'image/webp';
|
|
362
|
+
/** Quality from 0 to 1, for JPEG and WebP */
|
|
363
|
+
quality?: number;
|
|
364
|
+
/** Pixels per CSS pixel. Defaults to the screen's ratio, at most 2 */
|
|
365
|
+
scale?: number;
|
|
366
|
+
/** Colour behind the tiles. Default '#ffffff' */
|
|
367
|
+
background?: string;
|
|
368
|
+
/** Draw measurement labels, cluster bubbles and drawn markers into the image. Default true */
|
|
369
|
+
labels?: boolean;
|
|
370
|
+
/**
|
|
371
|
+
* CSS selectors of further simple HTML elements to draw: boxes with a background,
|
|
372
|
+
* border, rounded corners and a line of text. Not for images or complex layouts.
|
|
373
|
+
*/
|
|
374
|
+
include?: string[];
|
|
375
|
+
/** Longest wait (ms) for the base map to finish loading first. Default 8000 */
|
|
376
|
+
timeout?: number;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/** `auto` picks m² or km² by size; `ha` is hectares (公顷), `mu` is 亩 */
|
|
380
|
+
export declare function formatArea(sqMeters: number, unit?: AreaUnit): string;
|
|
381
|
+
|
|
382
|
+
/** `auto` picks metres or kilometres by size */
|
|
383
|
+
export declare function formatLength(meters: number, unit?: LengthUnit): string;
|
|
384
|
+
|
|
385
|
+
/** GCJ-02 → BD-09 */
|
|
386
|
+
export declare function gcj02ToBd09(lng: number, lat: number): Coord;
|
|
387
|
+
|
|
388
|
+
/** GCJ-02 → WGS-84 */
|
|
389
|
+
export declare function gcj02ToWgs84(lng: number, lat: number): Coord;
|
|
390
|
+
|
|
391
|
+
export declare interface GeocodeParams extends ServiceKeyParam {
|
|
392
|
+
/** Address to look up */
|
|
393
|
+
keyWord: string;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/** Area of a ring on the sphere, in square metres */
|
|
397
|
+
export declare function geodesicArea(latlngs: L_2.LatLng[]): number;
|
|
398
|
+
|
|
399
|
+
export declare function getCoordType(providerName: string): CoordType;
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* HTML5 Geolocation API wrapper
|
|
403
|
+
*/
|
|
404
|
+
export declare function getLocation(options?: LocationOptions): Promise<LocationResult>;
|
|
405
|
+
|
|
406
|
+
/** List every tile type currently available, including registered ones */
|
|
407
|
+
export declare function getTileTypes(): string[];
|
|
408
|
+
|
|
409
|
+
/** A label to put on the map */
|
|
410
|
+
declare interface LabelSpec {
|
|
411
|
+
latlng: L_2.LatLng;
|
|
412
|
+
html: string;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
export declare class LayerManager {
|
|
416
|
+
private map;
|
|
417
|
+
private registry;
|
|
418
|
+
private ownCanvas;
|
|
419
|
+
private listeners;
|
|
420
|
+
constructor(map: L_2.Map);
|
|
421
|
+
/** Be told when a layer is registered, removed, shown or hidden */
|
|
422
|
+
onChange(listener: () => void): void;
|
|
423
|
+
private changed;
|
|
424
|
+
/**
|
|
425
|
+
* Put a layer under management and add it to the map.
|
|
426
|
+
* An existing layer with the same id is removed first.
|
|
427
|
+
*/
|
|
428
|
+
add<T extends L_2.Layer>(id: string, layer: T, options?: {
|
|
429
|
+
visible?: boolean;
|
|
430
|
+
}): T;
|
|
431
|
+
get<T extends L_2.Layer = L_2.Layer>(id: string): T | undefined;
|
|
432
|
+
has(id: string): boolean;
|
|
433
|
+
/** Ids of all managed layers, in insertion order */
|
|
434
|
+
ids(): string[];
|
|
435
|
+
isVisible(id: string): boolean;
|
|
436
|
+
/** Show a managed layer. Returns false when the id is unknown */
|
|
437
|
+
show(id: string): boolean;
|
|
438
|
+
/** Hide a managed layer without forgetting it. Returns false when the id is unknown */
|
|
439
|
+
hide(id: string): boolean;
|
|
440
|
+
/** Flip (or set) visibility. Returns the resulting visibility */
|
|
441
|
+
toggle(id: string, visible?: boolean): boolean;
|
|
442
|
+
/** Remove a managed layer from the map and forget it. Returns false when the id is unknown */
|
|
443
|
+
remove(id: string): boolean;
|
|
444
|
+
/** Remove every managed layer */
|
|
445
|
+
clear(): void;
|
|
446
|
+
/** Release everything, including the shared canvas. Called by `smap.destroy()` */
|
|
447
|
+
destroy(): void;
|
|
448
|
+
/**
|
|
449
|
+
* Renderer option for vector layers created here.
|
|
450
|
+
*
|
|
451
|
+
* Everything must end up on ONE canvas: Leaflet stacks a full-size <canvas> per
|
|
452
|
+
* renderer and only the top one receives mouse events, and a renderer is never
|
|
453
|
+
* removed from the map when its layers are. So: reuse the map's own canvas when
|
|
454
|
+
* it has one (`preferCanvas`, the default), otherwise share a single canvas.
|
|
455
|
+
*/
|
|
456
|
+
private canvas;
|
|
457
|
+
private place;
|
|
458
|
+
/**
|
|
459
|
+
* Fetch GeoJSON from a GeoServer WFS endpoint
|
|
460
|
+
*/
|
|
461
|
+
loadWFS(options: WFSOptions): Promise<any>;
|
|
462
|
+
/**
|
|
463
|
+
* Create a GeoJSON layer from data with optional styling
|
|
464
|
+
*/
|
|
465
|
+
createGeoJsonLayer(data: GeoJSON.GeoJsonObject, style?: L_2.PathOptions): L_2.GeoJSON;
|
|
466
|
+
/**
|
|
467
|
+
* Load WFS data and add to map as a GeoJSON layer
|
|
468
|
+
*/
|
|
469
|
+
addWFS(options: WFSOptions): Promise<L_2.GeoJSON>;
|
|
470
|
+
/**
|
|
471
|
+
* Create a WMS tile layer
|
|
472
|
+
*/
|
|
473
|
+
createWMS(options: WMSOptions): L_2.TileLayer.WMS;
|
|
474
|
+
/**
|
|
475
|
+
* Create a WMS tile layer and add to map
|
|
476
|
+
*/
|
|
477
|
+
addWMS(options: WMSOptions): L_2.TileLayer.WMS;
|
|
478
|
+
/**
|
|
479
|
+
* Build a mask that dims everything outside the given polygon(s).
|
|
480
|
+
* `getBounds()` of the result is the bounds of the highlighted region.
|
|
481
|
+
*/
|
|
482
|
+
createMask(geojson: GeoJSON.GeoJsonObject, options?: MaskOptions): L_2.FeatureGroup;
|
|
483
|
+
/**
|
|
484
|
+
* Add a mask to the map. By default the view is fitted to the region.
|
|
485
|
+
*/
|
|
486
|
+
addMask(geojson: GeoJSON.GeoJsonObject, options?: MaskOptions): L_2.FeatureGroup;
|
|
487
|
+
/**
|
|
488
|
+
* Build a layer of many points, drawn on canvas.
|
|
489
|
+
* Suitable for tens of thousands of points, where one marker per point would be too slow.
|
|
490
|
+
*/
|
|
491
|
+
createPointLayer<T extends PointInput>(points: T[], options?: PointLayerOptions<T>): L_2.FeatureGroup;
|
|
492
|
+
/**
|
|
493
|
+
* Add a layer of many points to the map
|
|
494
|
+
*/
|
|
495
|
+
addPoints<T extends PointInput>(points: T[], options?: PointLayerOptions<T>): L_2.FeatureGroup;
|
|
496
|
+
/**
|
|
497
|
+
* Build a layer of points that merge into counted bubbles when zoomed out.
|
|
498
|
+
* Use it when there are too many points to tell apart at low zoom.
|
|
499
|
+
*/
|
|
500
|
+
createCluster<T extends PointInput>(points: T[], options?: ClusterOptions<T>): ClusterLayer<T>;
|
|
501
|
+
/**
|
|
502
|
+
* Add a clustered point layer to the map
|
|
503
|
+
*/
|
|
504
|
+
addCluster<T extends PointInput>(points: T[], options?: ClusterOptions<T>): ClusterLayer<T>;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
export declare interface LayersControlOptions {
|
|
508
|
+
position?: L_2.ControlPosition;
|
|
509
|
+
/** Base maps to choose from */
|
|
510
|
+
options: {
|
|
511
|
+
label: string;
|
|
512
|
+
/** One tile type, or several stacked (base + annotation) */
|
|
513
|
+
tileType: TileType | TileType[];
|
|
514
|
+
}[];
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
export declare type LengthUnit = 'auto' | 'm' | 'km';
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* @deprecated Drawing no longer depends on leaflet-draw; there is nothing to load.
|
|
521
|
+
* Kept so existing `await loadLeafletDraw()` / `Tool.preload()` calls keep working.
|
|
522
|
+
*/
|
|
523
|
+
export declare function loadLeafletDraw(): Promise<void>;
|
|
524
|
+
|
|
525
|
+
/**
|
|
526
|
+
* Dynamically load an external script. Deduplicates by URL.
|
|
527
|
+
*/
|
|
528
|
+
export declare function loadScript(src: string): Promise<void>;
|
|
529
|
+
|
|
530
|
+
/**
|
|
531
|
+
* Dynamically load an external stylesheet. Deduplicates by URL.
|
|
532
|
+
*/
|
|
533
|
+
export declare function loadStyle(href: string): void;
|
|
534
|
+
|
|
535
|
+
export declare interface LocateOptions extends LocationOptions {
|
|
536
|
+
/** Move the map to the position. Default true */
|
|
537
|
+
setView?: boolean;
|
|
538
|
+
/** Zoom to use when moving. Defaults to at least 16 */
|
|
539
|
+
zoom?: number;
|
|
540
|
+
/** Show the position and its accuracy on the map. Default true */
|
|
541
|
+
marker?: boolean;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
export declare interface LocateResult extends LocationResult {
|
|
545
|
+
latlng: L_2.LatLng;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
export declare interface LocationOptions {
|
|
549
|
+
timeout?: number;
|
|
550
|
+
enableHighAccuracy?: boolean;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
export declare interface LocationResult {
|
|
554
|
+
latitude: number;
|
|
555
|
+
longitude: number;
|
|
556
|
+
/** Accuracy radius in metres */
|
|
557
|
+
accuracy: number;
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
export declare interface MaskOptions {
|
|
561
|
+
/** Register the mask under this id in `smap.layer` */
|
|
562
|
+
id?: string;
|
|
563
|
+
/** Colour of the dimmed area. Default '#000' */
|
|
564
|
+
fillColor?: string;
|
|
565
|
+
/** Opacity of the dimmed area. Default 0.5 */
|
|
566
|
+
fillOpacity?: number;
|
|
567
|
+
/** Draw the region's border. Default true */
|
|
568
|
+
outline?: boolean;
|
|
569
|
+
/** Border colour. Default '#3388ff' */
|
|
570
|
+
color?: string;
|
|
571
|
+
/** Border width. Default 2 */
|
|
572
|
+
weight?: number;
|
|
573
|
+
/** Fit the view to the region when added. Default true */
|
|
574
|
+
fit?: boolean;
|
|
575
|
+
/** Keep the map from being panned away from the region while the mask is shown. Default false */
|
|
576
|
+
restrict?: boolean;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
export declare type MeasureEvents = {
|
|
580
|
+
/** Measuring started */
|
|
581
|
+
start: {
|
|
582
|
+
type: MeasureType;
|
|
583
|
+
};
|
|
584
|
+
/** Measuring ended. `completed` is false when it was cancelled */
|
|
585
|
+
stop: {
|
|
586
|
+
type: MeasureType;
|
|
587
|
+
completed: boolean;
|
|
588
|
+
};
|
|
589
|
+
/** A shape was finished */
|
|
590
|
+
created: MeasureResult;
|
|
591
|
+
/** A measurement was removed (delete button, `remove()` or `clearAll()`) */
|
|
592
|
+
removed: {
|
|
593
|
+
id: string;
|
|
594
|
+
type: MeasureType;
|
|
595
|
+
};
|
|
596
|
+
/** A measurement is being reshaped: fired while dragging, and after an undo */
|
|
597
|
+
updating: MeasureResult;
|
|
598
|
+
/** A measurement was reshaped in edit mode and saved */
|
|
599
|
+
updated: MeasureResult;
|
|
600
|
+
/** The tool was destroyed */
|
|
601
|
+
destroyed: {
|
|
602
|
+
type: MeasureType;
|
|
603
|
+
};
|
|
604
|
+
};
|
|
605
|
+
|
|
606
|
+
/** What a tool works out from a finished shape */
|
|
607
|
+
declare type MeasureGeometry = Omit<MeasureResult, 'id' | 'type' | 'layer'>;
|
|
608
|
+
|
|
609
|
+
/** What a label formatter is given */
|
|
610
|
+
export declare type MeasureLabel = Omit<MeasureResult, 'id' | 'layer'> & {
|
|
611
|
+
/** True for an intermediate value, false for the final result */
|
|
612
|
+
partial: boolean;
|
|
613
|
+
};
|
|
614
|
+
|
|
615
|
+
export declare interface MeasureOptions {
|
|
616
|
+
/** Whether to show distance/area markers */
|
|
617
|
+
showMarker?: boolean;
|
|
618
|
+
/** Snap to earlier measurements (and to `layers`, if given) while drawing and editing */
|
|
619
|
+
snap?: boolean | SnapOptions;
|
|
620
|
+
/** Unit of distances in the default labels. Default 'auto' (m or km by size) */
|
|
621
|
+
lengthUnit?: LengthUnit;
|
|
622
|
+
/** Unit of areas in the default labels: 'auto', 'm2', 'km2', 'ha' (公顷) or 'mu' (亩). Default 'auto' */
|
|
623
|
+
areaUnit?: AreaUnit;
|
|
624
|
+
/**
|
|
625
|
+
* Custom text for the labels. Receives the measurement; `partial` is true for
|
|
626
|
+
* the running totals shown while a line is being drawn.
|
|
627
|
+
*/
|
|
628
|
+
formatLabel?: (label: MeasureLabel) => string;
|
|
629
|
+
/**
|
|
630
|
+
* @deprecated Use `formatLabel`. What this receives depends on the tool: the
|
|
631
|
+
* distance for a line, the radius for a circle, the vertices for an area.
|
|
632
|
+
*/
|
|
633
|
+
valueFormatter?: (value: number | L_2.LatLng[]) => string;
|
|
634
|
+
/** Style of the measured lines and areas */
|
|
635
|
+
shapeOptions?: L_2.PathOptions;
|
|
636
|
+
/** Icon for draw vertices */
|
|
637
|
+
icon?: L_2.DivIcon;
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
/** Outcome of one finished measurement */
|
|
641
|
+
export declare interface MeasureResult {
|
|
642
|
+
/** Id of this measurement, usable with `tool.remove(id)` */
|
|
643
|
+
id: string;
|
|
644
|
+
type: MeasureType;
|
|
645
|
+
/** Total length in metres (polyline) */
|
|
646
|
+
distance?: number;
|
|
647
|
+
/** Area in square metres (polygon, rectangle, circle) */
|
|
648
|
+
area?: number;
|
|
649
|
+
/** Length of the outline in metres (polygon, rectangle, circle) */
|
|
650
|
+
perimeter?: number;
|
|
651
|
+
/** Radius in metres (circle) */
|
|
652
|
+
radius?: number;
|
|
653
|
+
/** Centre (circle) */
|
|
654
|
+
center?: L_2.LatLng;
|
|
655
|
+
/** Vertices of the shape; for a circle, its centre */
|
|
656
|
+
latlngs: L_2.LatLng[];
|
|
657
|
+
/** The drawn Leaflet layer */
|
|
658
|
+
layer: L_2.Layer;
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
export declare interface MeasureTool {
|
|
662
|
+
readonly type: MeasureType;
|
|
663
|
+
/** True while a measurement is being drawn */
|
|
664
|
+
readonly measuring: boolean;
|
|
665
|
+
/** True while the results can be reshaped */
|
|
666
|
+
readonly editing: boolean;
|
|
667
|
+
/** Let the user reshape the finished measurements; values and labels follow live */
|
|
668
|
+
startEdit(): void;
|
|
669
|
+
/** Leave edit mode, keeping (default) or discarding the changes */
|
|
670
|
+
finishEdit(save?: boolean): void;
|
|
671
|
+
/** Take back the last change made in edit mode. Returns false when there is none */
|
|
672
|
+
undo(): boolean;
|
|
673
|
+
/** Change options afterwards, e.g. the units; labels on the map are redrawn */
|
|
674
|
+
setOptions(options: Partial<MeasureOptions>): void;
|
|
675
|
+
enable(): void;
|
|
676
|
+
disable(): void;
|
|
677
|
+
remove(id: string): void;
|
|
678
|
+
clearAll(): void;
|
|
679
|
+
destroy(): void;
|
|
680
|
+
/** Finished measurements still on the map, oldest first */
|
|
681
|
+
getResults(): MeasureResult[];
|
|
682
|
+
on<K extends keyof MeasureEvents>(type: K, handler: (event: MeasureEvents[K]) => void): void;
|
|
683
|
+
off<K extends keyof MeasureEvents>(type: K, handler: (event: MeasureEvents[K]) => void): void;
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
export declare type MeasureType = 'polyline' | 'polygon' | 'circle' | 'rectangle';
|
|
687
|
+
|
|
688
|
+
export declare interface OverlaysControlOptions {
|
|
689
|
+
position?: L_2.ControlPosition;
|
|
690
|
+
/** Heading shown above the list */
|
|
691
|
+
title?: string;
|
|
692
|
+
/**
|
|
693
|
+
* Layers to list, by the id they are registered under in `smap.layer`.
|
|
694
|
+
* Omit to list every registered layer, labelled by its id.
|
|
695
|
+
*/
|
|
696
|
+
items?: {
|
|
697
|
+
id: string;
|
|
698
|
+
label: string;
|
|
699
|
+
}[];
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
/** Length of a path in metres */
|
|
703
|
+
export declare function pathLength(latlngs: L_2.LatLng[]): number;
|
|
704
|
+
|
|
705
|
+
/** A point for `addPoints()`: `[lat, lng]`, or any object with `lat` and `lng` */
|
|
706
|
+
export declare type PointInput = L_2.LatLngExpression | {
|
|
707
|
+
lat: number;
|
|
708
|
+
lng: number;
|
|
709
|
+
};
|
|
710
|
+
|
|
711
|
+
export declare interface PointLayerOptions<T = PointInput> {
|
|
712
|
+
/** Register the layer under this id in `smap.layer` */
|
|
713
|
+
id?: string;
|
|
714
|
+
/** Radius in pixels. Default 4 */
|
|
715
|
+
radius?: number;
|
|
716
|
+
/** Style for all points, or a function returning the style of each one */
|
|
717
|
+
style?: L_2.CircleMarkerOptions | ((point: T, index: number) => L_2.CircleMarkerOptions);
|
|
718
|
+
/** Tooltip text for a point */
|
|
719
|
+
tooltip?: (point: T) => string;
|
|
720
|
+
/** Called when a point is clicked */
|
|
721
|
+
onClick?: (point: T, event: L_2.LeafletMouseEvent) => void;
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
export declare class PolygonMeasure extends RingAreaMeasure {
|
|
725
|
+
protected readonly drawType = "polygon";
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
/** Distance along a line, with the running total shown at each vertex */
|
|
729
|
+
export declare class PolylineMeasure extends BaseMeasureTool {
|
|
730
|
+
protected readonly drawType = "polyline";
|
|
731
|
+
protected measure(layer: L_2.Polyline): MeasureGeometry;
|
|
732
|
+
protected anchor(result: MeasureResult): L_2.LatLng;
|
|
733
|
+
protected defaultText(label: MeasureLabel): string;
|
|
734
|
+
protected legacyValue(label: MeasureLabel): number;
|
|
735
|
+
protected draftLabels(latlngs: L_2.LatLng[]): LabelSpec[];
|
|
736
|
+
protected resultLabels(result: MeasureResult): LabelSpec[];
|
|
737
|
+
/** "起点" on the first vertex, the distance so far on the others */
|
|
738
|
+
private nodeLabels;
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
/** Provider definitions: Provider.MapName.MapType -> URL template */
|
|
742
|
+
export declare const providers: Record<string, any>;
|
|
743
|
+
|
|
744
|
+
export declare class RectangleMeasure extends RingAreaMeasure {
|
|
745
|
+
protected readonly drawType = "rectangle";
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
/**
|
|
749
|
+
* Register a custom tile provider (or override a built-in one).
|
|
750
|
+
* Its layers are then addressable as `"<name>.<group>.<type>"`.
|
|
751
|
+
*
|
|
752
|
+
* @example
|
|
753
|
+
* ```ts
|
|
754
|
+
* registerProvider('Intranet', {
|
|
755
|
+
* layers: { Satellite: { Map: 'https://tiles.example.com/{z}/{x}/{y}.png' } },
|
|
756
|
+
* coordType: 'gcj02',
|
|
757
|
+
* })
|
|
758
|
+
* smap.setTileLayer('Intranet.Satellite.Map')
|
|
759
|
+
* ```
|
|
760
|
+
*/
|
|
761
|
+
export declare function registerProvider(name: string, definition: TileProviderDefinition): void;
|
|
762
|
+
|
|
763
|
+
export declare interface ReverseGeocodeParams extends ServiceKeyParam {
|
|
764
|
+
/** Longitude */
|
|
765
|
+
lon: number;
|
|
766
|
+
/** Latitude */
|
|
767
|
+
lat: number;
|
|
768
|
+
ver?: number;
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
/** Shared by the tools that measure the area of a ring: polygon and rectangle */
|
|
772
|
+
declare abstract class RingAreaMeasure extends BaseMeasureTool {
|
|
773
|
+
protected measure(layer: L_2.Polygon): MeasureGeometry;
|
|
774
|
+
protected anchor(result: MeasureResult): L_2.LatLng;
|
|
775
|
+
protected defaultText(label: MeasureLabel): string;
|
|
776
|
+
protected legacyValue(label: MeasureLabel): L_2.LatLng[];
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
export declare interface SearchParams extends ServiceKeyParam {
|
|
780
|
+
/** Search keyword */
|
|
781
|
+
keyword: string;
|
|
782
|
+
/** Number of results to return. Default 10 */
|
|
783
|
+
count?: number;
|
|
784
|
+
/** Start index. Default 0 */
|
|
785
|
+
start?: number;
|
|
786
|
+
/** TianDiTu query type. Default 1 (keyword search) */
|
|
787
|
+
queryType?: number;
|
|
788
|
+
/** Zoom level used for ranking. Defaults to the map's current zoom */
|
|
789
|
+
level?: number;
|
|
790
|
+
/** Search extent "minLng,minLat,maxLng,maxLat". Defaults to the map's current view */
|
|
791
|
+
mapBound?: string;
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
/**
|
|
795
|
+
* TianDiTu web services.
|
|
796
|
+
*
|
|
797
|
+
* `smap.service` is bound to its map and to `tdtKey`, so calls need neither.
|
|
798
|
+
* A standalone `new ServiceClient()` must be given `tk` (and, for `search`,
|
|
799
|
+
* a map or `mapBound` + `level`) on every call.
|
|
800
|
+
*/
|
|
801
|
+
export declare class ServiceClient {
|
|
802
|
+
private context;
|
|
803
|
+
constructor(context?: ServiceContext);
|
|
804
|
+
/**
|
|
805
|
+
* POI keyword search within the map's current view
|
|
806
|
+
*/
|
|
807
|
+
search(params: SearchParams): Promise<TdtSearchResult>;
|
|
808
|
+
/** @deprecated Pass only `params`; `smap.service` already knows its map */
|
|
809
|
+
search(map: L_2.Map, params: SearchParams): Promise<TdtSearchResult>;
|
|
810
|
+
/**
|
|
811
|
+
* Geocoding: address → coordinates
|
|
812
|
+
*/
|
|
813
|
+
geocode(params: GeocodeParams): Promise<TdtGeocodeResult>;
|
|
814
|
+
/**
|
|
815
|
+
* Reverse geocoding: coordinates → address
|
|
816
|
+
*/
|
|
817
|
+
reverseGeocode(params: ReverseGeocodeParams): Promise<TdtReverseGeocodeResult>;
|
|
818
|
+
/**
|
|
819
|
+
* Administrative district query (TianDiTu v2 API)
|
|
820
|
+
*/
|
|
821
|
+
getAdministrative(params: AdministrativeParams): Promise<TdtAdministrativeResult>;
|
|
822
|
+
/**
|
|
823
|
+
* Get location by IP (no key required)
|
|
824
|
+
*/
|
|
825
|
+
getLocationByIp(): Promise<TdtIpLocationResult>;
|
|
826
|
+
private resolveKey;
|
|
827
|
+
private request;
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
export declare interface ServiceContext {
|
|
831
|
+
/** Map whose current view scopes `search()` */
|
|
832
|
+
map?: L_2.Map;
|
|
833
|
+
/** Default TianDiTu key, used when a call does not pass `tk` */
|
|
834
|
+
key?: string | (() => string | undefined);
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
/** Fields shared by every TianDiTu service call */
|
|
838
|
+
declare interface ServiceKeyParam {
|
|
839
|
+
/** TianDiTu API key. Defaults to the map's `tdtKey` */
|
|
840
|
+
tk?: string;
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
/**
|
|
844
|
+
* Texts shown next to the cursor while drawing and editing.
|
|
845
|
+
* Assign to the fields to translate or reword them.
|
|
846
|
+
*/
|
|
847
|
+
export declare const sketchText: {
|
|
848
|
+
marker: {
|
|
849
|
+
start: string;
|
|
850
|
+
};
|
|
851
|
+
polyline: {
|
|
852
|
+
start: string;
|
|
853
|
+
next: string;
|
|
854
|
+
finish: string;
|
|
855
|
+
};
|
|
856
|
+
polygon: {
|
|
857
|
+
start: string;
|
|
858
|
+
next: string;
|
|
859
|
+
finish: string;
|
|
860
|
+
};
|
|
861
|
+
rectangle: {
|
|
862
|
+
start: string;
|
|
863
|
+
finish: string;
|
|
864
|
+
};
|
|
865
|
+
circle: {
|
|
866
|
+
start: string;
|
|
867
|
+
finish: string;
|
|
868
|
+
radius: string;
|
|
869
|
+
};
|
|
870
|
+
/** {n} is replaced by the number of points required */
|
|
871
|
+
tooFewPoints: string;
|
|
872
|
+
cancel: string;
|
|
873
|
+
edit: string;
|
|
874
|
+
};
|
|
875
|
+
|
|
876
|
+
/**
|
|
877
|
+
* Main map class — supports multi-instance, fully typed API
|
|
878
|
+
*
|
|
879
|
+
* @example
|
|
880
|
+
* ```ts
|
|
881
|
+
* const map = new SMap('#map', {
|
|
882
|
+
* tileType: ['TianDiTu.Normal.Map', 'TianDiTu.Normal.Annotion'],
|
|
883
|
+
* center: [31.82, 117.23],
|
|
884
|
+
* zoom: 12,
|
|
885
|
+
* tdtKey: 'your-key',
|
|
886
|
+
* })
|
|
887
|
+
* ```
|
|
888
|
+
*/
|
|
889
|
+
export declare class SMap {
|
|
890
|
+
/** The underlying Leaflet map instance */
|
|
891
|
+
readonly instance: L_2.Map;
|
|
892
|
+
/** Layer management (registry, WFS/WMS, mask, points) */
|
|
893
|
+
readonly layer: LayerManager;
|
|
894
|
+
/** Control management (zoom, scale, attribution, base-map switcher) */
|
|
895
|
+
readonly control: ControlManager;
|
|
896
|
+
/** TianDiTu web services (search, geocode, etc.) */
|
|
897
|
+
readonly service: ServiceClient;
|
|
898
|
+
/** Right-click menus for the map and for layers */
|
|
899
|
+
readonly contextMenu: ContextMenu;
|
|
900
|
+
private tileLayers;
|
|
901
|
+
private tileTypes;
|
|
902
|
+
private tileChangeHandlers;
|
|
903
|
+
private drawTools;
|
|
904
|
+
private locationLayer;
|
|
905
|
+
private measureTools;
|
|
906
|
+
private sharedMeasures;
|
|
907
|
+
private emitter;
|
|
908
|
+
private options;
|
|
909
|
+
private tileObserver;
|
|
910
|
+
private destroyed;
|
|
911
|
+
constructor(container: string | HTMLElement, options?: SMapOptions);
|
|
912
|
+
/**
|
|
913
|
+
* Replace current tile layers with new type(s)
|
|
914
|
+
*/
|
|
915
|
+
setTileLayer(type: TileType | TileType[]): L_2.TileLayer[];
|
|
916
|
+
/**
|
|
917
|
+
* Add additional tile layer(s) without removing existing ones
|
|
918
|
+
*/
|
|
919
|
+
addTileLayer(type: TileType | TileType[]): L_2.TileLayer[];
|
|
920
|
+
private notifyTileChange;
|
|
921
|
+
/**
|
|
922
|
+
* Pick the credential that belongs to the tile provider
|
|
923
|
+
* (TianDiTu → tdtKey, Mapbox → mapboxToken, others → provider default)
|
|
924
|
+
*/
|
|
925
|
+
private resolveKey;
|
|
926
|
+
/**
|
|
927
|
+
* Remove all tile layers
|
|
928
|
+
*/
|
|
929
|
+
clearTileLayers(): void;
|
|
930
|
+
/**
|
|
931
|
+
* Types of the current tile layers, bottom first
|
|
932
|
+
*/
|
|
933
|
+
getTileType(): TileType[];
|
|
934
|
+
/**
|
|
935
|
+
* Get current tile layers
|
|
936
|
+
*/
|
|
937
|
+
getTileLayers(): L_2.TileLayer[];
|
|
938
|
+
/**
|
|
939
|
+
* Create a new measure tool.
|
|
940
|
+
*
|
|
941
|
+
* Every call creates another tool; keep the one you get and reuse it, or call
|
|
942
|
+
* its `destroy()` when done. For one shared tool per type use `getMeasure()`.
|
|
943
|
+
*/
|
|
944
|
+
createMeasure(type: MeasureType, options?: MeasureOptions): Promise<MeasureTool>;
|
|
945
|
+
/**
|
|
946
|
+
* The map's shared measure tool of a type, created on first use.
|
|
947
|
+
* `options` only apply when it is created.
|
|
948
|
+
*/
|
|
949
|
+
getMeasure(type: MeasureType, options?: MeasureOptions): Promise<MeasureTool>;
|
|
950
|
+
/**
|
|
951
|
+
* Destroy all measure tools
|
|
952
|
+
*/
|
|
953
|
+
clearMeasures(): void;
|
|
954
|
+
/**
|
|
955
|
+
* Create a tool for drawing and editing shapes (loads leaflet-draw on first call)
|
|
956
|
+
*/
|
|
957
|
+
createDraw(options?: DrawOptions): Promise<DrawTool>;
|
|
958
|
+
/**
|
|
959
|
+
* Locate the user with the browser's geolocation, show the position and move there.
|
|
960
|
+
* Rejects when permission is denied or the position is unavailable.
|
|
961
|
+
*/
|
|
962
|
+
locate(options?: LocateOptions): Promise<LocateResult>;
|
|
963
|
+
/** Remove the position shown by `locate()` */
|
|
964
|
+
clearLocation(): void;
|
|
965
|
+
/**
|
|
966
|
+
* The map as currently shown, as an image.
|
|
967
|
+
*
|
|
968
|
+
* Contains the base map, vector shapes (lines, areas, circles, point layers) and
|
|
969
|
+
* the library's own labels: measurement labels, cluster bubbles, drawn markers.
|
|
970
|
+
* Other HTML — custom marker icons, popups, controls — is not part of it unless
|
|
971
|
+
* named in `include`. Rejects if a tile server forbids cross-origin reading.
|
|
972
|
+
*/
|
|
973
|
+
exportImage(options?: ExportImageOptions): Promise<Blob>;
|
|
974
|
+
/** Export the map and save it as a file */
|
|
975
|
+
downloadImage(filename?: string, options?: ExportImageOptions): Promise<void>;
|
|
976
|
+
/**
|
|
977
|
+
* Fit map to bounds of a layer
|
|
978
|
+
*/
|
|
979
|
+
fitToLayer(layer: L_2.Layer): void;
|
|
980
|
+
/**
|
|
981
|
+
* Set map view
|
|
982
|
+
*/
|
|
983
|
+
setView(center: [number, number], zoom?: number): void;
|
|
984
|
+
on<K extends keyof SMapEvents>(type: K, handler: (event: SMapEvents[K]) => void): void;
|
|
985
|
+
off<K extends keyof SMapEvents>(type: K, handler: (event: SMapEvents[K]) => void): void;
|
|
986
|
+
/**
|
|
987
|
+
* Destroy the map instance and clean up all resources
|
|
988
|
+
*/
|
|
989
|
+
destroy(): void;
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
export declare type SMapEvents = {
|
|
993
|
+
loaded: L_2.Map;
|
|
994
|
+
tileLoaded: L_2.TileLayer[];
|
|
995
|
+
/** A measurement was finished by any tool created through `createMeasure()` */
|
|
996
|
+
'measure:created': MeasureResult;
|
|
997
|
+
/** A measurement was removed */
|
|
998
|
+
'measure:removed': {
|
|
999
|
+
id: string;
|
|
1000
|
+
type: MeasureType;
|
|
1001
|
+
};
|
|
1002
|
+
/** A measurement is being reshaped in edit mode */
|
|
1003
|
+
'measure:updating': MeasureResult;
|
|
1004
|
+
/** A measurement was reshaped in edit mode and saved */
|
|
1005
|
+
'measure:updated': MeasureResult;
|
|
1006
|
+
/** A measure tool started drawing */
|
|
1007
|
+
'measure:start': {
|
|
1008
|
+
type: MeasureType;
|
|
1009
|
+
};
|
|
1010
|
+
/** A measure tool stopped drawing. `completed` is false when it was cancelled */
|
|
1011
|
+
'measure:stop': {
|
|
1012
|
+
type: MeasureType;
|
|
1013
|
+
completed: boolean;
|
|
1014
|
+
};
|
|
1015
|
+
};
|
|
1016
|
+
|
|
1017
|
+
export declare interface SMapOptions {
|
|
1018
|
+
/** Map container element ID or HTMLElement */
|
|
1019
|
+
container?: string | HTMLElement;
|
|
1020
|
+
/** Tile layer type(s), e.g. "GaoDe.Normal.Map" or ["TianDiTu.Normal.Map", "TianDiTu.Normal.Annotion"] */
|
|
1021
|
+
tileType?: TileType | TileType[];
|
|
1022
|
+
/** Map center [lat, lng] */
|
|
1023
|
+
center?: [number, number];
|
|
1024
|
+
/** Initial zoom level */
|
|
1025
|
+
zoom?: number;
|
|
1026
|
+
/** Minimum zoom level */
|
|
1027
|
+
minZoom?: number;
|
|
1028
|
+
/** Maximum zoom level */
|
|
1029
|
+
maxZoom?: number;
|
|
1030
|
+
/** Maximum native zoom */
|
|
1031
|
+
maxNativeZoom?: number;
|
|
1032
|
+
/** Whether to use Canvas renderer */
|
|
1033
|
+
preferCanvas?: boolean;
|
|
1034
|
+
/** TianDiTu API key */
|
|
1035
|
+
tdtKey?: string;
|
|
1036
|
+
/** Mapbox access token */
|
|
1037
|
+
mapboxToken?: string;
|
|
1038
|
+
/** Any additional Leaflet map options */
|
|
1039
|
+
[key: string]: unknown;
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
export declare interface SnapOptions {
|
|
1043
|
+
/** How close (pixels) the cursor has to be. Default 12 */
|
|
1044
|
+
distance?: number;
|
|
1045
|
+
/** Other layers to snap to, besides the tool's own shapes */
|
|
1046
|
+
layers?: L_2.Layer[] | (() => L_2.Layer[]);
|
|
1047
|
+
}
|
|
1048
|
+
|
|
1049
|
+
/** Returns the position to use: the nearest vertex or edge if one is close, else the input */
|
|
1050
|
+
export declare type Snapper = (latlng: L_2.LatLng, exclude?: L_2.Layer) => L_2.LatLng;
|
|
1051
|
+
|
|
1052
|
+
export declare interface TdtAdministrativeResult {
|
|
1053
|
+
/** 200 on success */
|
|
1054
|
+
status: number;
|
|
1055
|
+
message: string;
|
|
1056
|
+
data?: {
|
|
1057
|
+
district: TdtDistrict[];
|
|
1058
|
+
suggestion: unknown[];
|
|
1059
|
+
};
|
|
1060
|
+
[key: string]: unknown;
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1063
|
+
export declare interface TdtDistrict {
|
|
1064
|
+
/** 9-digit district code, e.g. "156340100" */
|
|
1065
|
+
gb: string;
|
|
1066
|
+
/** Parent district code */
|
|
1067
|
+
pgb: string;
|
|
1068
|
+
name: string;
|
|
1069
|
+
center: {
|
|
1070
|
+
lng: number;
|
|
1071
|
+
lat: number;
|
|
1072
|
+
};
|
|
1073
|
+
level: number;
|
|
1074
|
+
/** WKT geometry, present when `extensions` is true */
|
|
1075
|
+
boundary?: string;
|
|
1076
|
+
/** Present when `childLevel` > 0 */
|
|
1077
|
+
children?: TdtDistrict[];
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
export declare interface TdtGeocodeResult {
|
|
1081
|
+
/** "0" on success */
|
|
1082
|
+
status: string;
|
|
1083
|
+
msg: string;
|
|
1084
|
+
location?: {
|
|
1085
|
+
/** Longitude, as a string */
|
|
1086
|
+
lon: string;
|
|
1087
|
+
/** Latitude, as a string */
|
|
1088
|
+
lat: string;
|
|
1089
|
+
level?: string;
|
|
1090
|
+
score?: number;
|
|
1091
|
+
keyWord?: string;
|
|
1092
|
+
};
|
|
1093
|
+
[key: string]: unknown;
|
|
1094
|
+
}
|
|
1095
|
+
|
|
1096
|
+
export declare interface TdtIpLocationResult {
|
|
1097
|
+
code: number;
|
|
1098
|
+
msg: string;
|
|
1099
|
+
data?: {
|
|
1100
|
+
country?: string;
|
|
1101
|
+
province?: string;
|
|
1102
|
+
city?: string;
|
|
1103
|
+
/** Administrative code */
|
|
1104
|
+
gb?: string;
|
|
1105
|
+
/** Latitude, as a string */
|
|
1106
|
+
lat?: string;
|
|
1107
|
+
/** Longitude, as a string */
|
|
1108
|
+
lng?: string;
|
|
1109
|
+
[key: string]: unknown;
|
|
1110
|
+
};
|
|
1111
|
+
[key: string]: unknown;
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1114
|
+
export declare interface TdtPoi {
|
|
1115
|
+
name: string;
|
|
1116
|
+
address?: string;
|
|
1117
|
+
phone?: string;
|
|
1118
|
+
poiType?: string;
|
|
1119
|
+
source?: string;
|
|
1120
|
+
hotPointID?: string;
|
|
1121
|
+
/** "lng,lat" */
|
|
1122
|
+
lonlat: string;
|
|
1123
|
+
[key: string]: unknown;
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1126
|
+
export declare interface TdtReverseGeocodeResult {
|
|
1127
|
+
/** "0" on success */
|
|
1128
|
+
status: string;
|
|
1129
|
+
msg: string;
|
|
1130
|
+
result?: {
|
|
1131
|
+
formatted_address: string;
|
|
1132
|
+
location: {
|
|
1133
|
+
lon: number;
|
|
1134
|
+
lat: number;
|
|
1135
|
+
};
|
|
1136
|
+
addressComponent: {
|
|
1137
|
+
nation?: string;
|
|
1138
|
+
province?: string;
|
|
1139
|
+
province_code?: string;
|
|
1140
|
+
city?: string;
|
|
1141
|
+
city_code?: string;
|
|
1142
|
+
county?: string;
|
|
1143
|
+
county_code?: string;
|
|
1144
|
+
town?: string;
|
|
1145
|
+
town_code?: string;
|
|
1146
|
+
road?: string;
|
|
1147
|
+
road_distance?: number;
|
|
1148
|
+
address?: string;
|
|
1149
|
+
address_distance?: number;
|
|
1150
|
+
address_position?: string;
|
|
1151
|
+
poi?: string;
|
|
1152
|
+
poi_distance?: number;
|
|
1153
|
+
poi_position?: string;
|
|
1154
|
+
};
|
|
1155
|
+
};
|
|
1156
|
+
[key: string]: unknown;
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1159
|
+
export declare interface TdtSearchResult {
|
|
1160
|
+
/** Total number of matches */
|
|
1161
|
+
count?: number;
|
|
1162
|
+
resultType?: number;
|
|
1163
|
+
keyWord?: string;
|
|
1164
|
+
/** Present when the search matched POIs */
|
|
1165
|
+
pois?: TdtPoi[];
|
|
1166
|
+
status: {
|
|
1167
|
+
infocode: number;
|
|
1168
|
+
cndesc: string;
|
|
1169
|
+
};
|
|
1170
|
+
[key: string]: unknown;
|
|
1171
|
+
}
|
|
1172
|
+
|
|
1173
|
+
/** What the base-map switcher needs from the map it belongs to */
|
|
1174
|
+
declare interface TileHost {
|
|
1175
|
+
setTileLayer(type: TileType | TileType[]): unknown;
|
|
1176
|
+
getTileType(): TileType[];
|
|
1177
|
+
onTileChange(handler: () => void): void;
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1180
|
+
/** Definition passed to `registerProvider()` */
|
|
1181
|
+
export declare interface TileProviderDefinition {
|
|
1182
|
+
/**
|
|
1183
|
+
* group → type → URL template, addressed as `"<provider>.<group>.<type>"`.
|
|
1184
|
+
* Placeholders: `{s}` subdomain, `{x}` `{y}` `{z}`, `{-y}` inverted y, `{key}`.
|
|
1185
|
+
*/
|
|
1186
|
+
layers: Record<string, Record<string, string>>;
|
|
1187
|
+
/** Values substituted for `{s}` */
|
|
1188
|
+
subdomains?: string[];
|
|
1189
|
+
/** Coordinate system of the tiles. Non-WGS-84 tiles are shifted to line up with WGS-84 data. Default 'wgs84' */
|
|
1190
|
+
coordType?: CoordType;
|
|
1191
|
+
/** Tiles use TMS (inverted y) numbering */
|
|
1192
|
+
tms?: boolean;
|
|
1193
|
+
/** Value substituted for `{key}` */
|
|
1194
|
+
key?: string;
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1197
|
+
/**
|
|
1198
|
+
* Tile type string, e.g. "GaoDe.Normal.Map".
|
|
1199
|
+
* Built-in types autocomplete; any other string is accepted for providers
|
|
1200
|
+
* added through `registerProvider()`.
|
|
1201
|
+
*/
|
|
1202
|
+
export declare type TileType = BuiltinTileType | (string & {});
|
|
1203
|
+
|
|
1204
|
+
/** Convert one coordinate between any two of WGS-84, GCJ-02 and BD-09 */
|
|
1205
|
+
export declare function transformCoord(lng: number, lat: number, from: CoordSystem, to: CoordSystem): Coord;
|
|
1206
|
+
|
|
1207
|
+
/**
|
|
1208
|
+
* Convert every coordinate in a GeoJSON object. Returns a deep copy; the input is not modified.
|
|
1209
|
+
* Typical use: data received in GCJ-02 or BD-09 → WGS-84 before putting it on the map.
|
|
1210
|
+
*/
|
|
1211
|
+
export declare function transformGeoJSON<T>(geojson: T, from: CoordSystem, to: CoordSystem): T;
|
|
1212
|
+
|
|
1213
|
+
export declare interface WFSOptions {
|
|
1214
|
+
url: string;
|
|
1215
|
+
layer: string;
|
|
1216
|
+
/** Register the layer under this id in `smap.layer` */
|
|
1217
|
+
id?: string;
|
|
1218
|
+
style?: L_2.PathOptions;
|
|
1219
|
+
outputFormat?: string;
|
|
1220
|
+
[key: string]: unknown;
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1223
|
+
/** WGS-84 → BD-09 */
|
|
1224
|
+
export declare function wgs84ToBd09(lng: number, lat: number): Coord;
|
|
1225
|
+
|
|
1226
|
+
/** WGS-84 → GCJ-02 */
|
|
1227
|
+
export declare function wgs84ToGcj02(lng: number, lat: number): Coord;
|
|
1228
|
+
|
|
1229
|
+
export declare interface WMSOptions {
|
|
1230
|
+
url: string;
|
|
1231
|
+
layer: string;
|
|
1232
|
+
/** Register the layer under this id in `smap.layer` */
|
|
1233
|
+
id?: string;
|
|
1234
|
+
format?: string;
|
|
1235
|
+
transparent?: boolean;
|
|
1236
|
+
crs?: L_2.CRS;
|
|
1237
|
+
[key: string]: unknown;
|
|
1238
|
+
}
|
|
1239
|
+
|
|
1240
|
+
export { }
|