@cn-map/gaode-react 0.0.0-stage → 0.0.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/LICENSE +21 -0
- package/README.md +306 -2
- package/dist/context-ChPGCKoP.js +100 -0
- package/dist/index.d.ts +610 -0
- package/dist/index.js +2264 -0
- package/dist/loca.d.ts +254 -0
- package/dist/loca.js +784 -0
- package/package.json +90 -3
package/dist/index.js
ADDED
|
@@ -0,0 +1,2264 @@
|
|
|
1
|
+
import { a as splitProps, c as useEventListeners, i as resolveTarget, n as useMap, o as syncProperty, r as useMapInstance, s as useLazyInit, t as MapContext } from "./context-ChPGCKoP.js";
|
|
2
|
+
import { LoadStatus, getAPIStatus, load, reset, subscribeAPIStatus } from "@cn-map/gaode-jsapi-loader";
|
|
3
|
+
import { createContext, use, useCallback, useEffect, useEffectEvent, useId, useImperativeHandle, useInsertionEffect, useLayoutEffect, useRef, useState, useSyncExternalStore } from "react";
|
|
4
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
import { clone, eventToProp, eventsToProps, logger, lostContextError, lowercase } from "@cn-map/gaode-shared/utils";
|
|
6
|
+
import { add, addNode, adjust, click, close, complete, dblClick, dragEnd, dragStart, dragging, draw, end, error, hide, hotspotClick, hotspotOut, hotspotOver, mapMove, mouseDown, mouseMove, mouseOut, mouseOver, mouseUp, mouseWheel, move, moveAlong, moveEnd, moveStart, moving, open, pitchChange, pitchEnd, pitchStart, removeNode, resize, rightClick, rotateChange, rotateEnd, rotateStart, show, touchEnd, touchMove, touchStart, viewChange, zoomChange, zoomEnd, zoomStart } from "@cn-map/gaode-shared/const";
|
|
7
|
+
import { patchContextMenu, patchMap, patchPolygonEditor } from "@cn-map/gaode-shared/patch";
|
|
8
|
+
import { createPortal } from "react-dom";
|
|
9
|
+
// src/api-loader/context.ts
|
|
10
|
+
function useAPIStatus(type) {
|
|
11
|
+
const statusRef = useRef({ ...getAPIStatus() });
|
|
12
|
+
const getSnapshot = () => {
|
|
13
|
+
const currentStatus = getAPIStatus();
|
|
14
|
+
if (JSON.stringify(statusRef.current) !== JSON.stringify(currentStatus)) statusRef.current = { ...currentStatus };
|
|
15
|
+
return type ? statusRef.current[type] : statusRef.current;
|
|
16
|
+
};
|
|
17
|
+
return useSyncExternalStore(subscribeAPIStatus, getSnapshot, getSnapshot);
|
|
18
|
+
}
|
|
19
|
+
// src/api-loader/use-api-loader.ts
|
|
20
|
+
/**
|
|
21
|
+
* 加载高德地图依赖的 Hook
|
|
22
|
+
* @param {APILoaderOptions} config - 加载高德地图API的配置项
|
|
23
|
+
* @param {boolean} [resetOnUnmount=false] - 组件卸载时是否重置全局 JSAPI 状态
|
|
24
|
+
*/
|
|
25
|
+
const useAPILoader = (config, resetOnUnmount = false) => {
|
|
26
|
+
const [error, setError] = useState(null);
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
const { apiKey, ...rest } = config;
|
|
29
|
+
load({
|
|
30
|
+
key: apiKey,
|
|
31
|
+
...rest
|
|
32
|
+
}).catch((err) => {
|
|
33
|
+
if (err instanceof Error || err instanceof Event) setError(err);
|
|
34
|
+
else throw new Error(`Unexpected error when loading API`, { cause: err });
|
|
35
|
+
});
|
|
36
|
+
}, [config, setError]);
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
return () => {
|
|
39
|
+
if (resetOnUnmount) reset();
|
|
40
|
+
};
|
|
41
|
+
}, []);
|
|
42
|
+
return [useAPIStatus(), error];
|
|
43
|
+
};
|
|
44
|
+
// src/api-loader/api-loader.tsx
|
|
45
|
+
/**
|
|
46
|
+
* APILoader 用于加载高德地图依赖
|
|
47
|
+
*/
|
|
48
|
+
const APILoader = ({ children, resetOnUnmount = false, ...config }) => {
|
|
49
|
+
const [status, error] = useAPILoader(config, resetOnUnmount);
|
|
50
|
+
return /* @__PURE__ */ jsx(Fragment, { children: typeof children === "function" ? children(status, error) : children });
|
|
51
|
+
};
|
|
52
|
+
// src/map/map.tsx
|
|
53
|
+
const mapEvents = [
|
|
54
|
+
click,
|
|
55
|
+
complete,
|
|
56
|
+
dblClick,
|
|
57
|
+
dragEnd,
|
|
58
|
+
dragging,
|
|
59
|
+
dragStart,
|
|
60
|
+
hotspotClick,
|
|
61
|
+
hotspotOut,
|
|
62
|
+
hotspotOver,
|
|
63
|
+
mapMove,
|
|
64
|
+
mouseDown,
|
|
65
|
+
mouseMove,
|
|
66
|
+
mouseOut,
|
|
67
|
+
mouseOver,
|
|
68
|
+
mouseUp,
|
|
69
|
+
mouseWheel,
|
|
70
|
+
moveEnd,
|
|
71
|
+
moveStart,
|
|
72
|
+
pitchChange,
|
|
73
|
+
pitchEnd,
|
|
74
|
+
pitchStart,
|
|
75
|
+
resize,
|
|
76
|
+
rightClick,
|
|
77
|
+
rotateChange,
|
|
78
|
+
rotateEnd,
|
|
79
|
+
rotateStart,
|
|
80
|
+
touchEnd,
|
|
81
|
+
touchMove,
|
|
82
|
+
touchStart,
|
|
83
|
+
viewChange,
|
|
84
|
+
zoomChange,
|
|
85
|
+
zoomEnd,
|
|
86
|
+
zoomStart
|
|
87
|
+
];
|
|
88
|
+
const mapStatusKeys = [
|
|
89
|
+
"allBubble",
|
|
90
|
+
"animateEnable",
|
|
91
|
+
"doubleClickZoom",
|
|
92
|
+
"dragEnable",
|
|
93
|
+
"features",
|
|
94
|
+
"isHotspot",
|
|
95
|
+
"jogEnable",
|
|
96
|
+
"keyboardEnable",
|
|
97
|
+
"pickWhenMoving",
|
|
98
|
+
"pitchEnable",
|
|
99
|
+
"rotateEnable",
|
|
100
|
+
"scrollWheel",
|
|
101
|
+
"showBuildingBlock",
|
|
102
|
+
"touchZoom",
|
|
103
|
+
"touchZoomCenter",
|
|
104
|
+
"zoomEnable",
|
|
105
|
+
"zoomSpeed"
|
|
106
|
+
];
|
|
107
|
+
function getContainer(container) {
|
|
108
|
+
return typeof container === "function" ? container() : typeof container === "string" ? document.getElementById(container) : container;
|
|
109
|
+
}
|
|
110
|
+
const Map$1 = ({ ref, className, style, children, immediately, duration, id, ...props }) => {
|
|
111
|
+
patchMap();
|
|
112
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(mapEvents));
|
|
113
|
+
const containerId = `map-gaode-${useId()}`;
|
|
114
|
+
const containerRef = useRef(getContainer(restProps.container));
|
|
115
|
+
const [map, setMap] = useState(null);
|
|
116
|
+
useLayoutEffect(() => {
|
|
117
|
+
if (restProps.container) containerRef.current = getContainer(restProps.container);
|
|
118
|
+
if (!containerRef.current) return;
|
|
119
|
+
try {
|
|
120
|
+
const instance = new AMap.Map(containerRef.current, restProps);
|
|
121
|
+
setMap(instance);
|
|
122
|
+
return () => {
|
|
123
|
+
instance.clearInfoWindow();
|
|
124
|
+
instance.clearMap();
|
|
125
|
+
instance.destroy();
|
|
126
|
+
};
|
|
127
|
+
} catch (e) {
|
|
128
|
+
logger.error("init map error", e);
|
|
129
|
+
}
|
|
130
|
+
}, [restProps.container]);
|
|
131
|
+
const setContainer = useCallback((node) => {
|
|
132
|
+
if (!node) return;
|
|
133
|
+
containerRef.current = node;
|
|
134
|
+
}, []);
|
|
135
|
+
useLayoutEffect(() => {
|
|
136
|
+
const prevCursor = containerRef.current?.style.getPropertyValue("cursor");
|
|
137
|
+
const prevBackgroundColor = containerRef.current?.style.getPropertyValue("background-color");
|
|
138
|
+
return () => {
|
|
139
|
+
containerRef.current?.classList.remove("amap-container");
|
|
140
|
+
if (prevCursor) containerRef.current?.style.setProperty("cursor", prevCursor);
|
|
141
|
+
else containerRef.current?.style.removeProperty("cursor");
|
|
142
|
+
if (prevBackgroundColor) containerRef.current?.style.setProperty("background-color", prevBackgroundColor);
|
|
143
|
+
else containerRef.current?.style.removeProperty("background-color");
|
|
144
|
+
};
|
|
145
|
+
}, [restProps.container]);
|
|
146
|
+
useImperativeHandle(ref, () => map, [map]);
|
|
147
|
+
const { center, labelRejectMask, mapStyle, mask, pitch, rotation, zoom, zooms, layers, showLabel, defaultCursor, overseaDataType, poiIcon, roofColor, showIndoorMap, showOversea, skyColor, terrain, vdataProxy, vectorMapForeign, viewMode, wallColor, WebGLParams } = restProps;
|
|
148
|
+
useLayoutEffect(() => {
|
|
149
|
+
if (center !== void 0 && !map?.getCenter().equals(center)) map?.setCenter(clone(center), typeof immediately === "boolean" ? immediately : immediately?.center, typeof duration === "number" ? duration : duration?.center);
|
|
150
|
+
}, [center]);
|
|
151
|
+
useLayoutEffect(() => {
|
|
152
|
+
if (pitch !== void 0 && pitch !== map?.getPitch()) map?.setPitch(pitch, typeof immediately === "boolean" ? immediately : immediately?.pitch, typeof duration === "number" ? duration : duration?.pitch);
|
|
153
|
+
}, [pitch]);
|
|
154
|
+
useLayoutEffect(() => {
|
|
155
|
+
if (rotation !== void 0 && rotation !== map?.getRotation()) map?.setRotation(rotation, typeof immediately === "boolean" ? immediately : immediately?.rotation, typeof duration === "number" ? duration : duration?.rotation);
|
|
156
|
+
}, [rotation]);
|
|
157
|
+
useLayoutEffect(() => {
|
|
158
|
+
if (zoom !== void 0 && zoom !== map?.getZoom()) map?.setZoom(zoom, typeof immediately === "boolean" ? immediately : immediately?.zoom, typeof duration === "number" ? duration : duration?.zoom);
|
|
159
|
+
}, [zoom]);
|
|
160
|
+
useLayoutEffect(() => {
|
|
161
|
+
if (zooms !== void 0) map?.setZooms(clone(zooms));
|
|
162
|
+
}, [zooms]);
|
|
163
|
+
useLayoutEffect(() => {
|
|
164
|
+
if (labelRejectMask !== void 0) map?.setLabelRejectMask(labelRejectMask);
|
|
165
|
+
}, [labelRejectMask]);
|
|
166
|
+
useLayoutEffect(() => {
|
|
167
|
+
if (mapStyle !== void 0 && mapStyle !== map?.getMapStyle()) map?.setMapStyle(mapStyle);
|
|
168
|
+
}, [mapStyle]);
|
|
169
|
+
useLayoutEffect(() => {
|
|
170
|
+
if (mask !== void 0) map?.setMask(clone(mask));
|
|
171
|
+
}, [mask]);
|
|
172
|
+
useLayoutEffect(() => {
|
|
173
|
+
if (layers !== void 0) map?.setLayers(layers);
|
|
174
|
+
}, [layers]);
|
|
175
|
+
useLayoutEffect(() => {
|
|
176
|
+
if (showLabel !== void 0) {
|
|
177
|
+
map?.set("showLabel", showLabel);
|
|
178
|
+
map?.setNeedUpdate(true);
|
|
179
|
+
}
|
|
180
|
+
}, [showLabel]);
|
|
181
|
+
mapStatusKeys.forEach((key) => {
|
|
182
|
+
useLayoutEffect(() => {
|
|
183
|
+
map?.setStatus({ [key]: restProps[key] });
|
|
184
|
+
}, [restProps[key]]);
|
|
185
|
+
});
|
|
186
|
+
useEventListeners(map, eventProps, mapEvents);
|
|
187
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [props.container ? null : /* @__PURE__ */ jsx("div", {
|
|
188
|
+
ref: setContainer,
|
|
189
|
+
className,
|
|
190
|
+
id: id || containerId,
|
|
191
|
+
style: {
|
|
192
|
+
width: "100%",
|
|
193
|
+
height: "100%",
|
|
194
|
+
...style
|
|
195
|
+
}
|
|
196
|
+
}), /* @__PURE__ */ jsx(MapContext, {
|
|
197
|
+
value: map,
|
|
198
|
+
children
|
|
199
|
+
})] });
|
|
200
|
+
};
|
|
201
|
+
// src/control/control/control.ts
|
|
202
|
+
const controlEvents = [hide, show];
|
|
203
|
+
function useControlAttributes(control, props) {
|
|
204
|
+
useLayoutEffect(() => {
|
|
205
|
+
if (props.visible !== void 0) {
|
|
206
|
+
if (props.visible) control.show();
|
|
207
|
+
else control.hide();
|
|
208
|
+
}
|
|
209
|
+
}, [props.visible]);
|
|
210
|
+
}
|
|
211
|
+
// src/control/control-bar/control-bar.ts
|
|
212
|
+
const controlBarEvents = controlEvents;
|
|
213
|
+
const ControlBar = ({ ref, map: _map, ...props }) => {
|
|
214
|
+
const map = useMapInstance(_map);
|
|
215
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(controlBarEvents));
|
|
216
|
+
const controlBar = useLazyInit(() => new AMap.ControlBar(restProps));
|
|
217
|
+
useLayoutEffect(() => {
|
|
218
|
+
if (!map) return;
|
|
219
|
+
map.addControl(controlBar);
|
|
220
|
+
return () => {
|
|
221
|
+
map.removeControl(controlBar);
|
|
222
|
+
};
|
|
223
|
+
}, [map]);
|
|
224
|
+
useImperativeHandle(ref, () => controlBar, []);
|
|
225
|
+
useControlAttributes(controlBar, restProps);
|
|
226
|
+
useEventListeners(controlBar, eventProps, controlBarEvents);
|
|
227
|
+
return null;
|
|
228
|
+
};
|
|
229
|
+
// src/control/geolocation/geolocation.ts
|
|
230
|
+
const geolocationEvents = [
|
|
231
|
+
...controlEvents,
|
|
232
|
+
complete,
|
|
233
|
+
error
|
|
234
|
+
];
|
|
235
|
+
const Geolocation = ({ ref, map: _map, ...props }) => {
|
|
236
|
+
const map = useMapInstance(_map);
|
|
237
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(geolocationEvents));
|
|
238
|
+
const geolocation = useLazyInit(() => new AMap.Geolocation(restProps));
|
|
239
|
+
useLayoutEffect(() => {
|
|
240
|
+
if (!map) return;
|
|
241
|
+
map.addControl(geolocation);
|
|
242
|
+
return () => {
|
|
243
|
+
map.removeControl(geolocation);
|
|
244
|
+
};
|
|
245
|
+
}, [map]);
|
|
246
|
+
useImperativeHandle(ref, () => geolocation, []);
|
|
247
|
+
useControlAttributes(geolocation, restProps);
|
|
248
|
+
useEventListeners(geolocation, eventProps, geolocationEvents);
|
|
249
|
+
return null;
|
|
250
|
+
};
|
|
251
|
+
// src/control/hawk-eye/hawk-eye.ts
|
|
252
|
+
const hawkEyeEvents = controlEvents;
|
|
253
|
+
const HawkEye = ({ ref, map: _map, ...props }) => {
|
|
254
|
+
const map = useMapInstance(_map);
|
|
255
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(hawkEyeEvents));
|
|
256
|
+
const hawkEye = useLazyInit(() => new AMap.HawkEye(restProps));
|
|
257
|
+
useLayoutEffect(() => {
|
|
258
|
+
if (!map) return;
|
|
259
|
+
map.addControl(hawkEye);
|
|
260
|
+
return () => {
|
|
261
|
+
map.removeControl(hawkEye);
|
|
262
|
+
};
|
|
263
|
+
}, [map]);
|
|
264
|
+
useImperativeHandle(ref, () => hawkEye, []);
|
|
265
|
+
useControlAttributes(hawkEye, restProps);
|
|
266
|
+
useEventListeners(hawkEye, eventProps, hawkEyeEvents);
|
|
267
|
+
return null;
|
|
268
|
+
};
|
|
269
|
+
// src/control/map-type/map-type.ts
|
|
270
|
+
const mapTypeEvents = controlEvents;
|
|
271
|
+
const MapType = ({ ref, map: _map, ...props }) => {
|
|
272
|
+
const map = useMapInstance(_map);
|
|
273
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(mapTypeEvents));
|
|
274
|
+
const mapType = useLazyInit(() => new AMap.MapType(restProps));
|
|
275
|
+
useLayoutEffect(() => {
|
|
276
|
+
if (!map) return;
|
|
277
|
+
map.addControl(mapType);
|
|
278
|
+
return () => {
|
|
279
|
+
mapType._config.layerInfos.forEach((layerInfo) => {
|
|
280
|
+
layerInfo.layer.setMap(null);
|
|
281
|
+
layerInfo.layer.destroy();
|
|
282
|
+
});
|
|
283
|
+
map.removeControl(mapType);
|
|
284
|
+
};
|
|
285
|
+
}, [map]);
|
|
286
|
+
useImperativeHandle(ref, () => mapType, []);
|
|
287
|
+
useControlAttributes(mapType, restProps);
|
|
288
|
+
useEventListeners(mapType, eventProps, mapTypeEvents);
|
|
289
|
+
return null;
|
|
290
|
+
};
|
|
291
|
+
// src/control/scale/scale.ts
|
|
292
|
+
const scaleEvents = controlEvents;
|
|
293
|
+
const Scale = ({ ref, map: _map, ...props }) => {
|
|
294
|
+
const map = useMapInstance(_map);
|
|
295
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(scaleEvents));
|
|
296
|
+
const scale = useLazyInit(() => new AMap.Scale(restProps));
|
|
297
|
+
useLayoutEffect(() => {
|
|
298
|
+
if (!map) return;
|
|
299
|
+
map.addControl(scale);
|
|
300
|
+
return () => {
|
|
301
|
+
map.removeControl(scale);
|
|
302
|
+
};
|
|
303
|
+
}, [map]);
|
|
304
|
+
useImperativeHandle(ref, () => scale, []);
|
|
305
|
+
useControlAttributes(scale, restProps);
|
|
306
|
+
useEventListeners(scale, eventProps, scaleEvents);
|
|
307
|
+
return null;
|
|
308
|
+
};
|
|
309
|
+
// src/control/tool-bar/tool-bar.ts
|
|
310
|
+
const toolBarEvents = controlEvents;
|
|
311
|
+
const ToolBar = ({ ref, map: _map, ...props }) => {
|
|
312
|
+
const map = useMapInstance(_map);
|
|
313
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(toolBarEvents));
|
|
314
|
+
const toolBar = useLazyInit(() => new AMap.ToolBar(restProps));
|
|
315
|
+
useLayoutEffect(() => {
|
|
316
|
+
if (!map) return;
|
|
317
|
+
map.addControl(toolBar);
|
|
318
|
+
return () => {
|
|
319
|
+
map.removeControl(toolBar);
|
|
320
|
+
};
|
|
321
|
+
}, [map]);
|
|
322
|
+
useImperativeHandle(ref, () => toolBar, []);
|
|
323
|
+
useControlAttributes(toolBar, restProps);
|
|
324
|
+
useEventListeners(toolBar, eventProps, toolBarEvents);
|
|
325
|
+
return null;
|
|
326
|
+
};
|
|
327
|
+
// src/layer/layer/layer.ts
|
|
328
|
+
const layerEvents = [complete];
|
|
329
|
+
function useLayerAttributes(layer, props) {
|
|
330
|
+
const { opacity, zooms, zIndex, visible } = props;
|
|
331
|
+
useLayoutEffect(() => {
|
|
332
|
+
if (opacity !== void 0) layer.setOpacity(opacity);
|
|
333
|
+
}, [opacity]);
|
|
334
|
+
useLayoutEffect(() => {
|
|
335
|
+
if (zooms !== void 0) layer.setZooms(zooms);
|
|
336
|
+
}, [zooms]);
|
|
337
|
+
useLayoutEffect(() => {
|
|
338
|
+
if (zIndex !== void 0) layer.setzIndex(zIndex);
|
|
339
|
+
}, [zIndex]);
|
|
340
|
+
useLayoutEffect(() => {
|
|
341
|
+
if (visible !== void 0) {
|
|
342
|
+
if (visible) layer.show();
|
|
343
|
+
else layer.hide();
|
|
344
|
+
}
|
|
345
|
+
}, [visible]);
|
|
346
|
+
}
|
|
347
|
+
// src/layer/buildings/buildings.ts
|
|
348
|
+
const Buildings = ({ ref, map: _map, ...props }) => {
|
|
349
|
+
const map = useMapInstance(_map);
|
|
350
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(layerEvents));
|
|
351
|
+
const buildings = useLazyInit(() => new AMap.Buildings(restProps));
|
|
352
|
+
useLayoutEffect(() => {
|
|
353
|
+
if (!map) return;
|
|
354
|
+
buildings.setMap(map);
|
|
355
|
+
return () => {
|
|
356
|
+
buildings.setMap(null);
|
|
357
|
+
};
|
|
358
|
+
}, [map]);
|
|
359
|
+
useEffect(() => {
|
|
360
|
+
return () => {
|
|
361
|
+
buildings.destroy();
|
|
362
|
+
};
|
|
363
|
+
}, []);
|
|
364
|
+
useImperativeHandle(ref, () => buildings, []);
|
|
365
|
+
useLayerAttributes(buildings, restProps);
|
|
366
|
+
useLayoutEffect(() => {
|
|
367
|
+
if (restProps.style !== void 0) buildings.setStyle(restProps.style);
|
|
368
|
+
}, [restProps.style]);
|
|
369
|
+
useEventListeners(buildings, eventProps, layerEvents);
|
|
370
|
+
return null;
|
|
371
|
+
};
|
|
372
|
+
// src/layer/canvas-layer/canvas-layer.ts
|
|
373
|
+
const CanvasLayer = ({ ref, map: _map, canvas, ...props }) => {
|
|
374
|
+
const map = useMapInstance(_map);
|
|
375
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(layerEvents));
|
|
376
|
+
const canvasLayer = useLazyInit(() => new AMap.CanvasLayer({
|
|
377
|
+
...restProps,
|
|
378
|
+
canvas: resolveTarget(canvas)
|
|
379
|
+
}));
|
|
380
|
+
useLayoutEffect(() => {
|
|
381
|
+
if (!map) return;
|
|
382
|
+
canvasLayer.setMap(map);
|
|
383
|
+
return () => {
|
|
384
|
+
canvasLayer.setMap(null);
|
|
385
|
+
};
|
|
386
|
+
}, [map]);
|
|
387
|
+
useEffect(() => {
|
|
388
|
+
return () => {
|
|
389
|
+
canvasLayer.destroy();
|
|
390
|
+
};
|
|
391
|
+
}, []);
|
|
392
|
+
useImperativeHandle(ref, () => canvasLayer, []);
|
|
393
|
+
useLayerAttributes(canvasLayer, restProps);
|
|
394
|
+
useLayoutEffect(() => {
|
|
395
|
+
if (!map) return;
|
|
396
|
+
canvasLayer.setBounds(restProps.bounds);
|
|
397
|
+
}, [map, restProps.bounds]);
|
|
398
|
+
useLayoutEffect(() => {
|
|
399
|
+
if (canvas !== void 0) canvasLayer.setCanvas(resolveTarget(canvas));
|
|
400
|
+
}, [canvas]);
|
|
401
|
+
useEventListeners(canvasLayer, eventProps, layerEvents);
|
|
402
|
+
return null;
|
|
403
|
+
};
|
|
404
|
+
// src/layer/custom-layer/custom-layer.ts
|
|
405
|
+
function toggleVisibility(customLayer, visible) {
|
|
406
|
+
if (visible !== void 0) {
|
|
407
|
+
if (visible) {
|
|
408
|
+
customLayer.canvas.style.visibility = "visible";
|
|
409
|
+
customLayer.canvas.style.display = "block";
|
|
410
|
+
} else {
|
|
411
|
+
customLayer.canvas.style.visibility = "hidden";
|
|
412
|
+
customLayer.canvas.style.display = "none";
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
const CustomLayer = ({ ref, map: _map, element, ...props }) => {
|
|
417
|
+
const map = useMapInstance(_map);
|
|
418
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(layerEvents));
|
|
419
|
+
const customLayer = useLazyInit(() => new AMap.CustomLayer(resolveTarget(element), restProps));
|
|
420
|
+
useLayoutEffect(() => {
|
|
421
|
+
if (!map) return;
|
|
422
|
+
customLayer.setMap(map);
|
|
423
|
+
return () => {
|
|
424
|
+
customLayer.setMap(null);
|
|
425
|
+
};
|
|
426
|
+
}, [map]);
|
|
427
|
+
useEffect(() => {
|
|
428
|
+
return () => {
|
|
429
|
+
customLayer.destroy();
|
|
430
|
+
};
|
|
431
|
+
}, []);
|
|
432
|
+
useImperativeHandle(ref, () => customLayer, []);
|
|
433
|
+
useLayerAttributes(customLayer, restProps);
|
|
434
|
+
useLayoutEffect(() => {
|
|
435
|
+
syncProperty(customLayer, "render", restProps.render || customLayer.render);
|
|
436
|
+
}, [restProps.render]);
|
|
437
|
+
useLayoutEffect(() => {
|
|
438
|
+
toggleVisibility(customLayer, restProps.visible);
|
|
439
|
+
}, [restProps.visible]);
|
|
440
|
+
useEventListeners(customLayer, eventProps, layerEvents);
|
|
441
|
+
return null;
|
|
442
|
+
};
|
|
443
|
+
// src/layer/district-layer/district-layer/district-layer.ts
|
|
444
|
+
function useDistrictLayerAttributes(districtLayer, props) {
|
|
445
|
+
useLayerAttributes(districtLayer, props);
|
|
446
|
+
useLayoutEffect(() => {
|
|
447
|
+
if (props.adcode !== void 0) districtLayer.setAdcode(props.adcode);
|
|
448
|
+
}, [props.adcode]);
|
|
449
|
+
useLayoutEffect(() => {
|
|
450
|
+
if (props.SOC !== void 0) districtLayer.setSOC(props.SOC);
|
|
451
|
+
}, [props.SOC]);
|
|
452
|
+
useLayoutEffect(() => {
|
|
453
|
+
if (props.styles !== void 0) districtLayer.setStyles(props.styles);
|
|
454
|
+
}, [props.styles]);
|
|
455
|
+
}
|
|
456
|
+
const DistrictLayer = ({ ref, map: _map, ...props }) => {
|
|
457
|
+
const map = useMapInstance(_map);
|
|
458
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(layerEvents));
|
|
459
|
+
const districtLayer = useLazyInit(() => new AMap.DistrictLayer(restProps));
|
|
460
|
+
useLayoutEffect(() => {
|
|
461
|
+
if (!map) return;
|
|
462
|
+
districtLayer.setMap(map);
|
|
463
|
+
return () => {
|
|
464
|
+
districtLayer.setMap(null);
|
|
465
|
+
};
|
|
466
|
+
}, [map]);
|
|
467
|
+
useEffect(() => {
|
|
468
|
+
return () => {
|
|
469
|
+
districtLayer.destroy();
|
|
470
|
+
};
|
|
471
|
+
}, []);
|
|
472
|
+
useImperativeHandle(ref, () => districtLayer, []);
|
|
473
|
+
useDistrictLayerAttributes(districtLayer, restProps);
|
|
474
|
+
useEventListeners(districtLayer, eventProps, layerEvents);
|
|
475
|
+
return null;
|
|
476
|
+
};
|
|
477
|
+
// src/layer/district-layer/country/country.ts
|
|
478
|
+
const Country = ({ ref, map: _map, ...props }) => {
|
|
479
|
+
const map = useMapInstance(_map);
|
|
480
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(layerEvents));
|
|
481
|
+
const country = useLazyInit(() => new AMap.DistrictLayer.Country(restProps));
|
|
482
|
+
useLayoutEffect(() => {
|
|
483
|
+
if (!map) return;
|
|
484
|
+
country.setMap(map);
|
|
485
|
+
return () => {
|
|
486
|
+
country.setMap(null);
|
|
487
|
+
};
|
|
488
|
+
}, [map]);
|
|
489
|
+
useEffect(() => {
|
|
490
|
+
return () => {
|
|
491
|
+
country.destroy();
|
|
492
|
+
};
|
|
493
|
+
}, []);
|
|
494
|
+
useImperativeHandle(ref, () => country, []);
|
|
495
|
+
useDistrictLayerAttributes(country, restProps);
|
|
496
|
+
useEventListeners(country, eventProps, layerEvents);
|
|
497
|
+
return null;
|
|
498
|
+
};
|
|
499
|
+
// src/layer/district-layer/province/province.ts
|
|
500
|
+
const Province = ({ ref, map: _map, ...props }) => {
|
|
501
|
+
const map = useMapInstance(_map);
|
|
502
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(layerEvents));
|
|
503
|
+
const province = useLazyInit(() => new AMap.DistrictLayer.Province(restProps));
|
|
504
|
+
useLayoutEffect(() => {
|
|
505
|
+
if (!map) return;
|
|
506
|
+
province.setMap(map);
|
|
507
|
+
return () => {
|
|
508
|
+
province.setMap(null);
|
|
509
|
+
};
|
|
510
|
+
}, [map]);
|
|
511
|
+
useEffect(() => {
|
|
512
|
+
return () => {
|
|
513
|
+
province.destroy();
|
|
514
|
+
};
|
|
515
|
+
}, []);
|
|
516
|
+
useImperativeHandle(ref, () => province, []);
|
|
517
|
+
useDistrictLayerAttributes(province, restProps);
|
|
518
|
+
useEventListeners(province, eventProps, layerEvents);
|
|
519
|
+
return null;
|
|
520
|
+
};
|
|
521
|
+
// src/layer/district-layer/world/world.ts
|
|
522
|
+
const World = ({ ref, map: _map, ...props }) => {
|
|
523
|
+
const map = useMapInstance(_map);
|
|
524
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(layerEvents));
|
|
525
|
+
const world = useLazyInit(() => new AMap.DistrictLayer.World(restProps));
|
|
526
|
+
useLayoutEffect(() => {
|
|
527
|
+
if (!map) return;
|
|
528
|
+
world.setMap(map);
|
|
529
|
+
return () => {
|
|
530
|
+
world.setMap(null);
|
|
531
|
+
};
|
|
532
|
+
}, [map]);
|
|
533
|
+
useEffect(() => {
|
|
534
|
+
return () => {
|
|
535
|
+
world.destroy();
|
|
536
|
+
};
|
|
537
|
+
}, []);
|
|
538
|
+
useImperativeHandle(ref, () => world, []);
|
|
539
|
+
useDistrictLayerAttributes(world, restProps);
|
|
540
|
+
useEventListeners(world, eventProps, layerEvents);
|
|
541
|
+
return null;
|
|
542
|
+
};
|
|
543
|
+
// src/layer/gl-custom-layer/gl-custom-layer.ts
|
|
544
|
+
const GLCustomLayer = ({ ref, map: _map, ...props }) => {
|
|
545
|
+
const map = useMapInstance(_map);
|
|
546
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(layerEvents));
|
|
547
|
+
const glCustomLayer = useLazyInit(() => new AMap.GLCustomLayer(restProps));
|
|
548
|
+
useLayoutEffect(() => {
|
|
549
|
+
if (!map) return;
|
|
550
|
+
glCustomLayer.setMap(map);
|
|
551
|
+
return () => {
|
|
552
|
+
glCustomLayer.setMap(null);
|
|
553
|
+
};
|
|
554
|
+
}, [map]);
|
|
555
|
+
useInsertionEffect(() => {
|
|
556
|
+
return () => {
|
|
557
|
+
glCustomLayer.destroy();
|
|
558
|
+
};
|
|
559
|
+
}, []);
|
|
560
|
+
useImperativeHandle(ref, () => glCustomLayer, []);
|
|
561
|
+
const { init, render, ...rest } = restProps;
|
|
562
|
+
useLayerAttributes(glCustomLayer, rest);
|
|
563
|
+
useLayoutEffect(() => {
|
|
564
|
+
syncProperty(glCustomLayer, "init", init || glCustomLayer.init);
|
|
565
|
+
}, [init]);
|
|
566
|
+
useLayoutEffect(() => {
|
|
567
|
+
syncProperty(glCustomLayer, "render", render || glCustomLayer.render);
|
|
568
|
+
}, [render]);
|
|
569
|
+
useEventListeners(glCustomLayer, eventProps, layerEvents);
|
|
570
|
+
return null;
|
|
571
|
+
};
|
|
572
|
+
// src/layer/heat-map/heat-map.ts
|
|
573
|
+
const HeatMap = ({ ref, map: _map, ...props }) => {
|
|
574
|
+
const map = useMapInstance(_map);
|
|
575
|
+
const heatMap = useLazyInit(() => new AMap.HeatMap(null, props));
|
|
576
|
+
useLayoutEffect(() => {
|
|
577
|
+
if (!map) return;
|
|
578
|
+
heatMap.setMap(map);
|
|
579
|
+
return () => {
|
|
580
|
+
heatMap.setMap(null);
|
|
581
|
+
};
|
|
582
|
+
}, [map]);
|
|
583
|
+
useEffect(() => {
|
|
584
|
+
return () => {
|
|
585
|
+
heatMap._renderLayer?._render.setMap(null);
|
|
586
|
+
heatMap._renderLayer?._render.render.destroy();
|
|
587
|
+
};
|
|
588
|
+
}, []);
|
|
589
|
+
useImperativeHandle(ref, () => heatMap, []);
|
|
590
|
+
const { visible, zIndex, dataset, ...rest } = props;
|
|
591
|
+
useLayoutEffect(() => {
|
|
592
|
+
if (visible !== void 0) {
|
|
593
|
+
if (visible) heatMap.show();
|
|
594
|
+
else heatMap.hide();
|
|
595
|
+
}
|
|
596
|
+
}, [visible]);
|
|
597
|
+
useLayoutEffect(() => {
|
|
598
|
+
if (zIndex !== void 0) heatMap.setzIndex(zIndex);
|
|
599
|
+
}, [zIndex]);
|
|
600
|
+
useLayoutEffect(() => {
|
|
601
|
+
if (dataset) heatMap.setDataSet(clone(dataset, true));
|
|
602
|
+
}, [dataset]);
|
|
603
|
+
useLayoutEffect(() => {
|
|
604
|
+
heatMap.setOptions(rest);
|
|
605
|
+
}, [rest]);
|
|
606
|
+
return null;
|
|
607
|
+
};
|
|
608
|
+
// src/layer/image-layer/image-layer.ts
|
|
609
|
+
const ImageLayer = ({ ref, map: _map, ...props }) => {
|
|
610
|
+
const map = useMapInstance(_map);
|
|
611
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(layerEvents));
|
|
612
|
+
const imageLayer = useLazyInit(() => new AMap.ImageLayer(restProps));
|
|
613
|
+
useLayoutEffect(() => {
|
|
614
|
+
if (!map) return;
|
|
615
|
+
imageLayer.setMap(map);
|
|
616
|
+
return () => {
|
|
617
|
+
imageLayer.setMap(null);
|
|
618
|
+
};
|
|
619
|
+
}, [map]);
|
|
620
|
+
useEffect(() => {
|
|
621
|
+
return () => imageLayer.destroy();
|
|
622
|
+
}, []);
|
|
623
|
+
useImperativeHandle(ref, () => imageLayer, []);
|
|
624
|
+
const { bounds, url, tileUrl } = restProps;
|
|
625
|
+
useLayerAttributes(imageLayer, restProps);
|
|
626
|
+
useLayoutEffect(() => {
|
|
627
|
+
if (!map) return;
|
|
628
|
+
imageLayer.setBounds(bounds);
|
|
629
|
+
}, [map, bounds]);
|
|
630
|
+
useLayoutEffect(() => {
|
|
631
|
+
if (!map) return;
|
|
632
|
+
imageLayer.setImageUrl(url || tileUrl);
|
|
633
|
+
}, [
|
|
634
|
+
map,
|
|
635
|
+
url,
|
|
636
|
+
tileUrl
|
|
637
|
+
]);
|
|
638
|
+
useEventListeners(imageLayer, eventProps, layerEvents);
|
|
639
|
+
return null;
|
|
640
|
+
};
|
|
641
|
+
// src/layer/indoor-map/indoor-map.ts
|
|
642
|
+
const indoorMapEvents = [...layerEvents, click];
|
|
643
|
+
const IndoorMap = ({ ref, map: _map, POIId, floor, ...props }) => {
|
|
644
|
+
const map = useMapInstance(_map);
|
|
645
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(indoorMapEvents));
|
|
646
|
+
const indoorMap = useLazyInit(() => map?.indoorMap ?? new AMap.IndoorMap(restProps));
|
|
647
|
+
useLayoutEffect(() => {
|
|
648
|
+
if (!map) return;
|
|
649
|
+
if (map?.indoorMap) return;
|
|
650
|
+
const { animateEnable } = map.getStatus();
|
|
651
|
+
const before = [...map.getEvents()?.moveend ?? []];
|
|
652
|
+
indoorMap.setMap(map);
|
|
653
|
+
const moveEndFns = [...map.getEvents()?.moveend ?? []].filter((a) => !before?.some((b) => b.fn === a.fn && b.context === a.context));
|
|
654
|
+
return () => {
|
|
655
|
+
moveEndFns?.forEach(({ fn, context }) => {
|
|
656
|
+
map.off("moveend", fn, context);
|
|
657
|
+
});
|
|
658
|
+
if (indoorMap.e$) map?.removeControl(indoorMap.e$);
|
|
659
|
+
indoorMap.VR.labelsLayer?.setMap(null);
|
|
660
|
+
map?.removeLayer(indoorMap);
|
|
661
|
+
map?.setStatus({ animateEnable });
|
|
662
|
+
delete map.im().Yh.indoor;
|
|
663
|
+
};
|
|
664
|
+
}, [map]);
|
|
665
|
+
useEffect(() => {
|
|
666
|
+
if (map && POIId) {
|
|
667
|
+
indoorMap.showIndoorMap(POIId, floor);
|
|
668
|
+
indoorMap.getSource()?.JR?.(POIId, floor);
|
|
669
|
+
}
|
|
670
|
+
}, [
|
|
671
|
+
POIId,
|
|
672
|
+
floor,
|
|
673
|
+
map
|
|
674
|
+
]);
|
|
675
|
+
useEffect(() => {
|
|
676
|
+
if (!map) return;
|
|
677
|
+
if (map?.indoorMap) return;
|
|
678
|
+
return () => {
|
|
679
|
+
indoorMap.VR.labelsLayer?.destroy();
|
|
680
|
+
indoorMap.destroy();
|
|
681
|
+
};
|
|
682
|
+
}, []);
|
|
683
|
+
useImperativeHandle(ref, () => indoorMap, []);
|
|
684
|
+
const { hideFloorBar } = restProps;
|
|
685
|
+
useLayerAttributes(indoorMap, restProps);
|
|
686
|
+
useLayoutEffect(() => {
|
|
687
|
+
if (hideFloorBar !== void 0) {
|
|
688
|
+
if (hideFloorBar) indoorMap.hideFloorBar();
|
|
689
|
+
else indoorMap.showFloorBar();
|
|
690
|
+
}
|
|
691
|
+
}, [hideFloorBar]);
|
|
692
|
+
useEventListeners(indoorMap, eventProps, indoorMapEvents);
|
|
693
|
+
return null;
|
|
694
|
+
};
|
|
695
|
+
// src/layer/labels-layer/context.ts
|
|
696
|
+
const EMPTY$1 = Symbol("No LabelsLayer");
|
|
697
|
+
const LabelsLayerContext = createContext(EMPTY$1);
|
|
698
|
+
/**
|
|
699
|
+
* 获取LabelsLayer实例 hook
|
|
700
|
+
*/
|
|
701
|
+
function useLabelsLayer() {
|
|
702
|
+
const context = use(LabelsLayerContext);
|
|
703
|
+
if (context === EMPTY$1) throw lostContextError("`AMap.LabelsLayer`");
|
|
704
|
+
return context;
|
|
705
|
+
}
|
|
706
|
+
/**
|
|
707
|
+
* 获取LabelsLayer实例
|
|
708
|
+
*/
|
|
709
|
+
function useLabelsLayerInstance() {
|
|
710
|
+
const context = use(LabelsLayerContext);
|
|
711
|
+
return context === EMPTY$1 ? null : context;
|
|
712
|
+
}
|
|
713
|
+
// src/layer/labels-layer/labels-layer.tsx
|
|
714
|
+
const LabelsLayer = ({ ref, map: _map, children, labelMarkers, ...props }) => {
|
|
715
|
+
const map = useMapInstance(_map);
|
|
716
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(layerEvents));
|
|
717
|
+
const labelsLayer = useLazyInit(() => new AMap.LabelsLayer(restProps));
|
|
718
|
+
useLayoutEffect(() => {
|
|
719
|
+
if (!map) return;
|
|
720
|
+
labelsLayer.setMap(map);
|
|
721
|
+
return () => {
|
|
722
|
+
labelsLayer.setMap(null);
|
|
723
|
+
};
|
|
724
|
+
}, [map]);
|
|
725
|
+
useLayoutEffect(() => {
|
|
726
|
+
if (!labelMarkers) return;
|
|
727
|
+
labelsLayer.add(labelMarkers);
|
|
728
|
+
return () => {
|
|
729
|
+
labelsLayer.remove(labelMarkers);
|
|
730
|
+
};
|
|
731
|
+
}, [labelMarkers]);
|
|
732
|
+
useEffect(() => {
|
|
733
|
+
return () => {
|
|
734
|
+
labelsLayer.destroy();
|
|
735
|
+
};
|
|
736
|
+
}, []);
|
|
737
|
+
useImperativeHandle(ref, () => labelsLayer, []);
|
|
738
|
+
useLayoutEffect(() => {
|
|
739
|
+
if (restProps.allowCollision !== void 0) labelsLayer.setAllowCollision(restProps.allowCollision);
|
|
740
|
+
}, [restProps.allowCollision]);
|
|
741
|
+
useLayoutEffect(() => {
|
|
742
|
+
if (restProps.collision !== void 0) labelsLayer.setCollision(restProps.collision);
|
|
743
|
+
}, [restProps.collision]);
|
|
744
|
+
useLayerAttributes(labelsLayer, restProps);
|
|
745
|
+
useEventListeners(labelsLayer, eventProps, layerEvents);
|
|
746
|
+
if (labelMarkers !== void 0) return null;
|
|
747
|
+
return /* @__PURE__ */ jsx(LabelsLayerContext, {
|
|
748
|
+
value: labelsLayer,
|
|
749
|
+
children
|
|
750
|
+
});
|
|
751
|
+
};
|
|
752
|
+
// src/layer/layer-group/layer-group.ts
|
|
753
|
+
const layerGroupEvents = layerEvents;
|
|
754
|
+
const LayerGroup = ({ ref, map: _map, layers, ...props }) => {
|
|
755
|
+
const map = useMapInstance(_map);
|
|
756
|
+
const [eventProps] = splitProps(props, eventsToProps(layerGroupEvents));
|
|
757
|
+
const layerGroup = useLazyInit(() => new AMap.LayerGroup());
|
|
758
|
+
useLayoutEffect(() => {
|
|
759
|
+
layerGroup.setMap(map);
|
|
760
|
+
return () => {
|
|
761
|
+
layerGroup.setMap(null);
|
|
762
|
+
};
|
|
763
|
+
}, [map]);
|
|
764
|
+
const mountedLayersRef = useRef(/* @__PURE__ */ new Set());
|
|
765
|
+
useEffect(() => {
|
|
766
|
+
const nextLayers = layers ? Array.from(new Set(layers)) : [];
|
|
767
|
+
const nextLayerSet = new Set(nextLayers);
|
|
768
|
+
const layersToRemove = Array.from(mountedLayersRef.current).filter((layer) => !nextLayerSet.has(layer));
|
|
769
|
+
const layersToAdd = nextLayers.filter((layer) => !mountedLayersRef.current.has(layer));
|
|
770
|
+
if (layersToRemove.length > 0) layerGroup.removeLayers(layersToRemove);
|
|
771
|
+
if (layersToAdd.length > 0) layerGroup.addLayers(layersToAdd);
|
|
772
|
+
mountedLayersRef.current = nextLayerSet;
|
|
773
|
+
}, [layerGroup, layers]);
|
|
774
|
+
useEffect(() => {
|
|
775
|
+
return () => {
|
|
776
|
+
const mountedLayers = Array.from(mountedLayersRef.current);
|
|
777
|
+
mountedLayersRef.current.clear();
|
|
778
|
+
if (mountedLayers.length > 0) layerGroup.removeLayers(mountedLayers);
|
|
779
|
+
for (const layer of mountedLayers) if ("destroy" in layer && typeof layer.destroy === "function") layer.destroy();
|
|
780
|
+
};
|
|
781
|
+
}, [layerGroup]);
|
|
782
|
+
const boundLayersRef = useRef(/* @__PURE__ */ new Map());
|
|
783
|
+
const getHandler = useEffectEvent((eventType) => {
|
|
784
|
+
return eventProps[eventToProp(eventType)];
|
|
785
|
+
});
|
|
786
|
+
useEffect(() => {
|
|
787
|
+
const nextLayers = layers ? Array.from(new Set(layers)) : [];
|
|
788
|
+
const nextLayerSet = new Set(nextLayers);
|
|
789
|
+
for (const [layer, handlerMap] of boundLayersRef.current) if (!nextLayerSet.has(layer)) {
|
|
790
|
+
for (const [eventType, handler] of handlerMap) layer.off(lowercase(eventType), handler);
|
|
791
|
+
boundLayersRef.current.delete(layer);
|
|
792
|
+
if ("destroy" in layer && typeof layer.destroy === "function") layer.destroy();
|
|
793
|
+
}
|
|
794
|
+
for (const layer of nextLayers) {
|
|
795
|
+
if (boundLayersRef.current.has(layer)) continue;
|
|
796
|
+
const handlerMap = /* @__PURE__ */ new Map();
|
|
797
|
+
for (const eventType of layerGroupEvents) {
|
|
798
|
+
const handler = (event) => {
|
|
799
|
+
getHandler(eventType)?.(event);
|
|
800
|
+
};
|
|
801
|
+
layer.on(lowercase(eventType), handler);
|
|
802
|
+
handlerMap.set(eventType, handler);
|
|
803
|
+
}
|
|
804
|
+
boundLayersRef.current.set(layer, handlerMap);
|
|
805
|
+
}
|
|
806
|
+
}, [layers]);
|
|
807
|
+
useEffect(() => {
|
|
808
|
+
const boundLayers = boundLayersRef.current;
|
|
809
|
+
return () => {
|
|
810
|
+
for (const [layer, handlerMap] of boundLayers) {
|
|
811
|
+
for (const [eventType, handler] of handlerMap) layer.off(lowercase(eventType), handler);
|
|
812
|
+
if ("destroy" in layer && typeof layer.destroy === "function") layer.destroy();
|
|
813
|
+
}
|
|
814
|
+
boundLayers.clear();
|
|
815
|
+
};
|
|
816
|
+
}, []);
|
|
817
|
+
useImperativeHandle(ref, () => layerGroup, [layerGroup]);
|
|
818
|
+
useLayoutEffect(() => {
|
|
819
|
+
if (props.visible !== void 0) {
|
|
820
|
+
if (props.visible) layerGroup.show();
|
|
821
|
+
else layerGroup.hide();
|
|
822
|
+
}
|
|
823
|
+
}, [layerGroup, props.visible]);
|
|
824
|
+
return null;
|
|
825
|
+
};
|
|
826
|
+
// src/layer/mapbox/mapbox.ts
|
|
827
|
+
const Mapbox = ({ ref, map: _map, children, ...props }) => {
|
|
828
|
+
const map = useMapInstance(_map);
|
|
829
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(layerEvents));
|
|
830
|
+
const mapbox = useLazyInit(() => new AMap.Mapbox(restProps));
|
|
831
|
+
useLayoutEffect(() => {
|
|
832
|
+
if (!map) return;
|
|
833
|
+
mapbox.setMap(map);
|
|
834
|
+
return () => {
|
|
835
|
+
mapbox.setMap(null);
|
|
836
|
+
};
|
|
837
|
+
}, [map]);
|
|
838
|
+
useEffect(() => {
|
|
839
|
+
return () => {
|
|
840
|
+
mapbox.destroy();
|
|
841
|
+
};
|
|
842
|
+
}, []);
|
|
843
|
+
useImperativeHandle(ref, () => mapbox, []);
|
|
844
|
+
useLayerAttributes(mapbox, restProps);
|
|
845
|
+
useEventListeners(mapbox, eventProps, layerEvents);
|
|
846
|
+
return children;
|
|
847
|
+
};
|
|
848
|
+
// src/layer/tile-layer/tile-layer/tile-layer.ts
|
|
849
|
+
function useTileLayerAttributes(tileLayer, props) {
|
|
850
|
+
useLayerAttributes(tileLayer, props);
|
|
851
|
+
useLayoutEffect(() => {
|
|
852
|
+
if (typeof props.getTileUrl === "string") tileLayer.setTileUrl(props.getTileUrl);
|
|
853
|
+
}, [props.getTileUrl]);
|
|
854
|
+
}
|
|
855
|
+
const TileLayer = ({ ref, map: _map, ...props }) => {
|
|
856
|
+
const map = useMapInstance(_map);
|
|
857
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(layerEvents));
|
|
858
|
+
const tileLayer = useLazyInit(() => new AMap.TileLayer(restProps));
|
|
859
|
+
useLayoutEffect(() => {
|
|
860
|
+
if (!map) return;
|
|
861
|
+
tileLayer.setMap(map);
|
|
862
|
+
return () => {
|
|
863
|
+
tileLayer.setMap(null);
|
|
864
|
+
};
|
|
865
|
+
}, [map]);
|
|
866
|
+
useEffect(() => {
|
|
867
|
+
return () => {
|
|
868
|
+
tileLayer.destroy();
|
|
869
|
+
};
|
|
870
|
+
}, []);
|
|
871
|
+
useImperativeHandle(ref, () => tileLayer, []);
|
|
872
|
+
useTileLayerAttributes(tileLayer, restProps);
|
|
873
|
+
useEventListeners(tileLayer, eventProps, layerEvents);
|
|
874
|
+
return null;
|
|
875
|
+
};
|
|
876
|
+
// src/layer/mapbox-vector-tile-layer/mapbox-vector-tile-layer.ts
|
|
877
|
+
const MapboxVectorTileLayer = ({ ref, map: _map, ...props }) => {
|
|
878
|
+
const map = useMapInstance(_map);
|
|
879
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(layerEvents));
|
|
880
|
+
const mvtLayer = useLazyInit(() => new AMap.MapboxVectorTileLayer(restProps));
|
|
881
|
+
useLayoutEffect(() => {
|
|
882
|
+
if (!map) return;
|
|
883
|
+
mvtLayer.setMap(map);
|
|
884
|
+
return () => {
|
|
885
|
+
mvtLayer.getLabelsLayer().setMap(null);
|
|
886
|
+
mvtLayer.setMap(null);
|
|
887
|
+
};
|
|
888
|
+
}, [map]);
|
|
889
|
+
useEffect(() => {
|
|
890
|
+
return () => {
|
|
891
|
+
mvtLayer.getLabelsLayer().destroy();
|
|
892
|
+
mvtLayer.destroy();
|
|
893
|
+
};
|
|
894
|
+
}, []);
|
|
895
|
+
useImperativeHandle(ref, () => mvtLayer, []);
|
|
896
|
+
useTileLayerAttributes(mvtLayer, restProps);
|
|
897
|
+
useLayoutEffect(() => {
|
|
898
|
+
if (restProps.styles !== void 0) mvtLayer.setStyle(restProps.styles);
|
|
899
|
+
}, [restProps.styles]);
|
|
900
|
+
useEventListeners(mvtLayer, eventProps, layerEvents);
|
|
901
|
+
return null;
|
|
902
|
+
};
|
|
903
|
+
// src/layer/tile-layer/flexible/flexible.ts
|
|
904
|
+
const Flexible = ({ ref, map: _map, ...props }) => {
|
|
905
|
+
const map = useMapInstance(_map);
|
|
906
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(layerEvents));
|
|
907
|
+
const flexible = useLazyInit(() => new AMap.TileLayer.Flexible(restProps));
|
|
908
|
+
useLayoutEffect(() => {
|
|
909
|
+
if (!map) return;
|
|
910
|
+
flexible.setMap(map);
|
|
911
|
+
return () => {
|
|
912
|
+
flexible.setMap(null);
|
|
913
|
+
};
|
|
914
|
+
}, [map]);
|
|
915
|
+
useEffect(() => {
|
|
916
|
+
return () => {
|
|
917
|
+
flexible.destroy();
|
|
918
|
+
};
|
|
919
|
+
}, []);
|
|
920
|
+
useImperativeHandle(ref, () => flexible, []);
|
|
921
|
+
useTileLayerAttributes(flexible, restProps);
|
|
922
|
+
useEventListeners(flexible, eventProps, layerEvents);
|
|
923
|
+
return null;
|
|
924
|
+
};
|
|
925
|
+
// src/layer/tile-layer/mark/mark.ts
|
|
926
|
+
const Mark = ({ ref, map: _map, ...props }) => {
|
|
927
|
+
const map = useMapInstance(_map);
|
|
928
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(layerEvents));
|
|
929
|
+
const mark = useLazyInit(() => new AMap.TileLayer.Mark(restProps));
|
|
930
|
+
useLayoutEffect(() => {
|
|
931
|
+
if (!map) return;
|
|
932
|
+
mark.setMap(map);
|
|
933
|
+
return () => {
|
|
934
|
+
mark.setMap(null);
|
|
935
|
+
};
|
|
936
|
+
}, [map]);
|
|
937
|
+
useEffect(() => {
|
|
938
|
+
return () => {
|
|
939
|
+
mark.destroy();
|
|
940
|
+
};
|
|
941
|
+
}, []);
|
|
942
|
+
useImperativeHandle(ref, () => mark, []);
|
|
943
|
+
useTileLayerAttributes(mark, restProps);
|
|
944
|
+
useEventListeners(mark, eventProps, layerEvents);
|
|
945
|
+
return null;
|
|
946
|
+
};
|
|
947
|
+
// src/layer/tile-layer/road-net/road-net.ts
|
|
948
|
+
const RoadNet = ({ ref, map: _map, ...props }) => {
|
|
949
|
+
const map = useMapInstance(_map);
|
|
950
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(layerEvents));
|
|
951
|
+
const roadNet = useLazyInit(() => new AMap.TileLayer.RoadNet(restProps));
|
|
952
|
+
useLayoutEffect(() => {
|
|
953
|
+
if (!map) return;
|
|
954
|
+
roadNet.setMap(map);
|
|
955
|
+
return () => {
|
|
956
|
+
roadNet.setMap(null);
|
|
957
|
+
};
|
|
958
|
+
}, [map]);
|
|
959
|
+
useEffect(() => {
|
|
960
|
+
return () => {
|
|
961
|
+
roadNet.destroy();
|
|
962
|
+
};
|
|
963
|
+
}, []);
|
|
964
|
+
useImperativeHandle(ref, () => roadNet, []);
|
|
965
|
+
useTileLayerAttributes(roadNet, restProps);
|
|
966
|
+
useEventListeners(roadNet, eventProps, layerEvents);
|
|
967
|
+
return null;
|
|
968
|
+
};
|
|
969
|
+
// src/layer/tile-layer/satellite/satellite.ts
|
|
970
|
+
const Satellite = ({ ref, map: _map, ...props }) => {
|
|
971
|
+
const map = useMapInstance(_map);
|
|
972
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(layerEvents));
|
|
973
|
+
const satellite = useLazyInit(() => new AMap.TileLayer.Satellite(restProps));
|
|
974
|
+
useLayoutEffect(() => {
|
|
975
|
+
if (!map) return;
|
|
976
|
+
satellite.setMap(map);
|
|
977
|
+
return () => {
|
|
978
|
+
satellite.setMap(null);
|
|
979
|
+
};
|
|
980
|
+
}, [map]);
|
|
981
|
+
useEffect(() => {
|
|
982
|
+
return () => {
|
|
983
|
+
satellite.destroy();
|
|
984
|
+
};
|
|
985
|
+
}, []);
|
|
986
|
+
useImperativeHandle(ref, () => satellite, []);
|
|
987
|
+
useTileLayerAttributes(satellite, restProps);
|
|
988
|
+
useEventListeners(satellite, eventProps, layerEvents);
|
|
989
|
+
return null;
|
|
990
|
+
};
|
|
991
|
+
// src/layer/tile-layer/traffic/traffic.ts
|
|
992
|
+
const Traffic = ({ ref, map: _map, ...props }) => {
|
|
993
|
+
const map = useMapInstance(_map);
|
|
994
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(layerEvents));
|
|
995
|
+
const traffic = useLazyInit(() => new AMap.TileLayer.Traffic(restProps));
|
|
996
|
+
useLayoutEffect(() => {
|
|
997
|
+
if (!map) return;
|
|
998
|
+
traffic.setMap(map);
|
|
999
|
+
return () => {
|
|
1000
|
+
traffic.setMap(null);
|
|
1001
|
+
};
|
|
1002
|
+
}, [map]);
|
|
1003
|
+
useEffect(() => {
|
|
1004
|
+
return () => {
|
|
1005
|
+
traffic.destroy();
|
|
1006
|
+
};
|
|
1007
|
+
}, []);
|
|
1008
|
+
useImperativeHandle(ref, () => traffic, []);
|
|
1009
|
+
useLayerAttributes(traffic, restProps);
|
|
1010
|
+
useEventListeners(traffic, eventProps, layerEvents);
|
|
1011
|
+
return null;
|
|
1012
|
+
};
|
|
1013
|
+
// src/layer/tile-layer/wms/wms.ts
|
|
1014
|
+
const Wms = ({ ref, map: _map, ...props }) => {
|
|
1015
|
+
const map = useMapInstance(_map);
|
|
1016
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(layerEvents));
|
|
1017
|
+
const wms = useLazyInit(() => new AMap.TileLayer.WMS(restProps));
|
|
1018
|
+
useLayoutEffect(() => {
|
|
1019
|
+
if (!map) return;
|
|
1020
|
+
wms.setMap(map);
|
|
1021
|
+
return () => {
|
|
1022
|
+
wms.setMap(null);
|
|
1023
|
+
};
|
|
1024
|
+
}, [map]);
|
|
1025
|
+
useEffect(() => {
|
|
1026
|
+
return () => {
|
|
1027
|
+
wms.destroy();
|
|
1028
|
+
};
|
|
1029
|
+
}, []);
|
|
1030
|
+
useImperativeHandle(ref, () => wms, []);
|
|
1031
|
+
useTileLayerAttributes(wms, restProps);
|
|
1032
|
+
useLayoutEffect(() => {
|
|
1033
|
+
if (restProps.params !== void 0) wms.setParams(restProps.params);
|
|
1034
|
+
}, [restProps.params]);
|
|
1035
|
+
useLayoutEffect(() => {
|
|
1036
|
+
if (restProps.url !== void 0) wms.setUrl(restProps.url);
|
|
1037
|
+
}, [restProps.url]);
|
|
1038
|
+
useEventListeners(wms, eventProps, layerEvents);
|
|
1039
|
+
return null;
|
|
1040
|
+
};
|
|
1041
|
+
// src/layer/tile-layer/wmts/wmts.ts
|
|
1042
|
+
const Wmts = ({ ref, map: _map, ...props }) => {
|
|
1043
|
+
const map = useMapInstance(_map);
|
|
1044
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(layerEvents));
|
|
1045
|
+
const wmts = useLazyInit(() => new AMap.TileLayer.WMTS(restProps));
|
|
1046
|
+
useLayoutEffect(() => {
|
|
1047
|
+
if (!map) return;
|
|
1048
|
+
wmts.setMap(map);
|
|
1049
|
+
return () => {
|
|
1050
|
+
wmts.setMap(null);
|
|
1051
|
+
};
|
|
1052
|
+
}, [map]);
|
|
1053
|
+
useEffect(() => {
|
|
1054
|
+
return () => {
|
|
1055
|
+
wmts.destroy();
|
|
1056
|
+
};
|
|
1057
|
+
}, []);
|
|
1058
|
+
useImperativeHandle(ref, () => wmts, []);
|
|
1059
|
+
useTileLayerAttributes(wmts, restProps);
|
|
1060
|
+
useLayoutEffect(() => {
|
|
1061
|
+
if (restProps.params !== void 0) wmts.setParams(restProps.params);
|
|
1062
|
+
}, [restProps.params]);
|
|
1063
|
+
useLayoutEffect(() => {
|
|
1064
|
+
if (restProps.url !== void 0) wmts.setUrl(restProps.url);
|
|
1065
|
+
}, [restProps.url]);
|
|
1066
|
+
useEventListeners(wmts, eventProps, layerEvents);
|
|
1067
|
+
return null;
|
|
1068
|
+
};
|
|
1069
|
+
// src/layer/vector-layer/context.ts
|
|
1070
|
+
const EMPTY = Symbol("No VectorLayer");
|
|
1071
|
+
const VectorLayerContext = createContext(EMPTY);
|
|
1072
|
+
/**
|
|
1073
|
+
* 获取VectorLayer实例 hook
|
|
1074
|
+
*/
|
|
1075
|
+
function useVectorLayer() {
|
|
1076
|
+
const context = use(VectorLayerContext);
|
|
1077
|
+
if (context === EMPTY) throw lostContextError("`AMap.VectorLayer`");
|
|
1078
|
+
return context;
|
|
1079
|
+
}
|
|
1080
|
+
/**
|
|
1081
|
+
* 获取VectorLayer实例
|
|
1082
|
+
*/
|
|
1083
|
+
function useVectorLayerInstance() {
|
|
1084
|
+
const context = use(VectorLayerContext);
|
|
1085
|
+
return context === EMPTY ? null : context;
|
|
1086
|
+
}
|
|
1087
|
+
// src/layer/vector-layer/vector-layer.tsx
|
|
1088
|
+
const VectorLayer = ({ ref, map: _map, children, ...props }) => {
|
|
1089
|
+
const map = useMapInstance(_map);
|
|
1090
|
+
const vectorLayer = useLazyInit(() => new AMap.VectorLayer(props));
|
|
1091
|
+
useLayoutEffect(() => {
|
|
1092
|
+
if (!map) return;
|
|
1093
|
+
vectorLayer.setMap(map);
|
|
1094
|
+
return () => {
|
|
1095
|
+
vectorLayer.setMap(null);
|
|
1096
|
+
};
|
|
1097
|
+
}, [map]);
|
|
1098
|
+
useEffect(() => {
|
|
1099
|
+
return () => {
|
|
1100
|
+
vectorLayer.destroy();
|
|
1101
|
+
};
|
|
1102
|
+
}, []);
|
|
1103
|
+
useImperativeHandle(ref, () => vectorLayer, []);
|
|
1104
|
+
useLayerAttributes(vectorLayer, props);
|
|
1105
|
+
const sourceReady = useSyncExternalStore(() => () => {}, () => !!vectorLayer?.getSource());
|
|
1106
|
+
return /* @__PURE__ */ jsx(VectorLayerContext, {
|
|
1107
|
+
value: vectorLayer,
|
|
1108
|
+
children: sourceReady ? children : null
|
|
1109
|
+
});
|
|
1110
|
+
};
|
|
1111
|
+
// src/overlay/vector-overlay/vector-overlay.ts
|
|
1112
|
+
const vectorOverlayEvents = [
|
|
1113
|
+
hide,
|
|
1114
|
+
show,
|
|
1115
|
+
click,
|
|
1116
|
+
dblClick,
|
|
1117
|
+
rightClick,
|
|
1118
|
+
mouseDown,
|
|
1119
|
+
mouseUp,
|
|
1120
|
+
mouseOver,
|
|
1121
|
+
mouseOut,
|
|
1122
|
+
dragStart,
|
|
1123
|
+
dragging,
|
|
1124
|
+
dragEnd,
|
|
1125
|
+
touchStart,
|
|
1126
|
+
touchMove,
|
|
1127
|
+
touchEnd
|
|
1128
|
+
];
|
|
1129
|
+
function useVectorOverlayAttributes(overlay, props) {
|
|
1130
|
+
const { draggable, extData, visible } = props;
|
|
1131
|
+
useLayoutEffect(() => {
|
|
1132
|
+
if (draggable !== void 0) overlay.setDraggable(draggable);
|
|
1133
|
+
}, [draggable]);
|
|
1134
|
+
useLayoutEffect(() => {
|
|
1135
|
+
overlay.setExtData(extData);
|
|
1136
|
+
}, [extData]);
|
|
1137
|
+
useLayoutEffect(() => {
|
|
1138
|
+
if (visible !== void 0) {
|
|
1139
|
+
if (visible) overlay.show();
|
|
1140
|
+
else overlay.hide();
|
|
1141
|
+
}
|
|
1142
|
+
}, [visible]);
|
|
1143
|
+
}
|
|
1144
|
+
// src/overlay/bezier-curve/bezier-curve.ts
|
|
1145
|
+
const bezierCurveEvents = vectorOverlayEvents;
|
|
1146
|
+
const BezierCurve = ({ ref, map: _map, ...props }) => {
|
|
1147
|
+
const map = useMapInstance(_map);
|
|
1148
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(bezierCurveEvents));
|
|
1149
|
+
const vectorLayer = useVectorLayerInstance();
|
|
1150
|
+
const bezierCurve = useLazyInit(() => new AMap.BezierCurve(restProps));
|
|
1151
|
+
useLayoutEffect(() => {
|
|
1152
|
+
if (vectorLayer) {
|
|
1153
|
+
vectorLayer.add(bezierCurve);
|
|
1154
|
+
return () => {
|
|
1155
|
+
vectorLayer.remove(bezierCurve);
|
|
1156
|
+
};
|
|
1157
|
+
} else {
|
|
1158
|
+
map?.add(bezierCurve);
|
|
1159
|
+
return () => {
|
|
1160
|
+
map?.remove(bezierCurve);
|
|
1161
|
+
};
|
|
1162
|
+
}
|
|
1163
|
+
}, [vectorLayer, map]);
|
|
1164
|
+
useEffect(() => {
|
|
1165
|
+
return () => bezierCurve.destroy();
|
|
1166
|
+
}, []);
|
|
1167
|
+
useImperativeHandle(ref, () => bezierCurve, []);
|
|
1168
|
+
const { draggable, extData, visible, path, ...rest } = restProps;
|
|
1169
|
+
useVectorOverlayAttributes(bezierCurve, restProps);
|
|
1170
|
+
useLayoutEffect(() => {
|
|
1171
|
+
bezierCurve.setOptions(rest);
|
|
1172
|
+
}, [rest]);
|
|
1173
|
+
useLayoutEffect(() => {
|
|
1174
|
+
bezierCurve.setPath(path);
|
|
1175
|
+
}, [path]);
|
|
1176
|
+
useEventListeners(bezierCurve, eventProps, bezierCurveEvents);
|
|
1177
|
+
return null;
|
|
1178
|
+
};
|
|
1179
|
+
// src/overlay/circle/circle.ts
|
|
1180
|
+
const circleEvents = vectorOverlayEvents;
|
|
1181
|
+
const Circle = ({ ref, map: _map, ...props }) => {
|
|
1182
|
+
const map = useMapInstance(_map);
|
|
1183
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(circleEvents));
|
|
1184
|
+
const vectorLayer = useVectorLayerInstance();
|
|
1185
|
+
const circle = useLazyInit(() => new AMap.Circle(restProps));
|
|
1186
|
+
useLayoutEffect(() => {
|
|
1187
|
+
if (vectorLayer) {
|
|
1188
|
+
vectorLayer.add(circle);
|
|
1189
|
+
return () => {
|
|
1190
|
+
vectorLayer.remove(circle);
|
|
1191
|
+
};
|
|
1192
|
+
} else {
|
|
1193
|
+
map?.add(circle);
|
|
1194
|
+
return () => {
|
|
1195
|
+
map?.remove(circle);
|
|
1196
|
+
};
|
|
1197
|
+
}
|
|
1198
|
+
}, [vectorLayer, map]);
|
|
1199
|
+
useEffect(() => {
|
|
1200
|
+
return () => circle.destroy();
|
|
1201
|
+
}, []);
|
|
1202
|
+
useImperativeHandle(ref, () => circle, []);
|
|
1203
|
+
const { draggable, extData, visible, center, radius, ...rest } = restProps;
|
|
1204
|
+
useVectorOverlayAttributes(circle, restProps);
|
|
1205
|
+
useLayoutEffect(() => {
|
|
1206
|
+
if (center !== void 0) circle.setCenter(center);
|
|
1207
|
+
}, [center]);
|
|
1208
|
+
useLayoutEffect(() => {
|
|
1209
|
+
if (radius !== void 0) circle.setRadius(radius);
|
|
1210
|
+
}, [radius]);
|
|
1211
|
+
useLayoutEffect(() => {
|
|
1212
|
+
circle.setOptions(rest);
|
|
1213
|
+
}, [rest]);
|
|
1214
|
+
useEventListeners(circle, eventProps, circleEvents);
|
|
1215
|
+
return null;
|
|
1216
|
+
};
|
|
1217
|
+
// src/overlay/circle-marker/circle-marker.ts
|
|
1218
|
+
const circleMarkerEvents = vectorOverlayEvents;
|
|
1219
|
+
const CircleMarker = ({ ref, map: _map, ...props }) => {
|
|
1220
|
+
const map = useMapInstance(_map);
|
|
1221
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(circleMarkerEvents));
|
|
1222
|
+
const vectorLayer = useVectorLayerInstance();
|
|
1223
|
+
const circleMarker = useLazyInit(() => new AMap.CircleMarker(restProps));
|
|
1224
|
+
useLayoutEffect(() => {
|
|
1225
|
+
if (vectorLayer) {
|
|
1226
|
+
vectorLayer.add(circleMarker);
|
|
1227
|
+
return () => {
|
|
1228
|
+
vectorLayer.remove(circleMarker);
|
|
1229
|
+
};
|
|
1230
|
+
} else {
|
|
1231
|
+
map?.add(circleMarker);
|
|
1232
|
+
return () => {
|
|
1233
|
+
map?.remove(circleMarker);
|
|
1234
|
+
};
|
|
1235
|
+
}
|
|
1236
|
+
}, [vectorLayer, map]);
|
|
1237
|
+
useEffect(() => {
|
|
1238
|
+
return () => circleMarker.destroy();
|
|
1239
|
+
}, []);
|
|
1240
|
+
useImperativeHandle(ref, () => circleMarker, []);
|
|
1241
|
+
const { draggable, extData, visible, center, radius, ...rest } = restProps;
|
|
1242
|
+
useVectorOverlayAttributes(circleMarker, restProps);
|
|
1243
|
+
useLayoutEffect(() => {
|
|
1244
|
+
if (center !== void 0) circleMarker.setCenter(center);
|
|
1245
|
+
}, [center]);
|
|
1246
|
+
useLayoutEffect(() => {
|
|
1247
|
+
if (radius !== void 0) circleMarker.setRadius(radius);
|
|
1248
|
+
}, [radius]);
|
|
1249
|
+
useLayoutEffect(() => {
|
|
1250
|
+
circleMarker.setOptions(rest);
|
|
1251
|
+
}, [rest]);
|
|
1252
|
+
useEventListeners(circleMarker, eventProps, circleMarkerEvents);
|
|
1253
|
+
return null;
|
|
1254
|
+
};
|
|
1255
|
+
// src/overlay/dom-overlay/custom-content.tsx
|
|
1256
|
+
function CustomContent({ instance, children }) {
|
|
1257
|
+
const dom = useLazyInit(() => document.createElement("div"));
|
|
1258
|
+
useLayoutEffect(() => {
|
|
1259
|
+
instance.setContent(dom);
|
|
1260
|
+
}, [children]);
|
|
1261
|
+
useEffect(() => {
|
|
1262
|
+
return () => {
|
|
1263
|
+
dom.remove();
|
|
1264
|
+
};
|
|
1265
|
+
}, []);
|
|
1266
|
+
return createPortal(children, dom);
|
|
1267
|
+
}
|
|
1268
|
+
// src/overlay/dom-overlay/dom-overlay.ts
|
|
1269
|
+
const domOverlayEvents = [
|
|
1270
|
+
click,
|
|
1271
|
+
dblClick,
|
|
1272
|
+
rightClick,
|
|
1273
|
+
dragStart,
|
|
1274
|
+
dragging,
|
|
1275
|
+
dragEnd,
|
|
1276
|
+
mouseDown,
|
|
1277
|
+
mouseUp,
|
|
1278
|
+
mouseOver,
|
|
1279
|
+
mouseOut,
|
|
1280
|
+
mouseMove,
|
|
1281
|
+
moveStart,
|
|
1282
|
+
moveAlong,
|
|
1283
|
+
moveEnd,
|
|
1284
|
+
moving,
|
|
1285
|
+
touchStart,
|
|
1286
|
+
touchMove,
|
|
1287
|
+
touchEnd
|
|
1288
|
+
];
|
|
1289
|
+
function useDOMOverlayAttributes(overlay, props, children) {
|
|
1290
|
+
const { anchor, content, offset, orientation, position, rotate, size, visible, zIndex } = props;
|
|
1291
|
+
useLayoutEffect(() => {
|
|
1292
|
+
overlay.setAnchor(anchor);
|
|
1293
|
+
}, [anchor]);
|
|
1294
|
+
useLayoutEffect(() => {
|
|
1295
|
+
if (children == null) overlay.setContent(content);
|
|
1296
|
+
}, [children, content]);
|
|
1297
|
+
useLayoutEffect(() => {
|
|
1298
|
+
overlay.setOffset(clone(offset));
|
|
1299
|
+
}, [offset]);
|
|
1300
|
+
useLayoutEffect(() => {
|
|
1301
|
+
overlay.setOrientation(orientation);
|
|
1302
|
+
}, [orientation]);
|
|
1303
|
+
useLayoutEffect(() => {
|
|
1304
|
+
if (position !== void 0) overlay.setPosition(clone(position));
|
|
1305
|
+
}, [position]);
|
|
1306
|
+
useLayoutEffect(() => {
|
|
1307
|
+
if (rotate !== void 0) overlay.setAngle(rotate);
|
|
1308
|
+
}, [rotate]);
|
|
1309
|
+
useLayoutEffect(() => {
|
|
1310
|
+
if (size !== void 0) overlay.setSize(clone(size));
|
|
1311
|
+
}, [size]);
|
|
1312
|
+
useLayoutEffect(() => {
|
|
1313
|
+
if (visible !== void 0) {
|
|
1314
|
+
if (visible) overlay.show();
|
|
1315
|
+
else overlay.hide();
|
|
1316
|
+
}
|
|
1317
|
+
}, [visible]);
|
|
1318
|
+
useLayoutEffect(() => {
|
|
1319
|
+
if (zIndex !== void 0) overlay.setzIndex(zIndex);
|
|
1320
|
+
}, [zIndex]);
|
|
1321
|
+
}
|
|
1322
|
+
// src/overlay/context-menu/context-menu.tsx
|
|
1323
|
+
const contextMenuEvents = [close, open];
|
|
1324
|
+
const ContextMenu = ({ ref, map, children, ...props }) => {
|
|
1325
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(contextMenuEvents));
|
|
1326
|
+
patchContextMenu();
|
|
1327
|
+
const contextMenu = useLazyInit(() => new AMap.ContextMenu(restProps));
|
|
1328
|
+
useEffect(() => {
|
|
1329
|
+
return () => {
|
|
1330
|
+
if (contextMenu?._parent?._container?.contains(contextMenu.getContentDom())) contextMenu.remove();
|
|
1331
|
+
contextMenu.destroy();
|
|
1332
|
+
};
|
|
1333
|
+
}, []);
|
|
1334
|
+
useImperativeHandle(ref, () => contextMenu, []);
|
|
1335
|
+
useDOMOverlayAttributes(contextMenu, restProps, children);
|
|
1336
|
+
useEventListeners(contextMenu, eventProps, contextMenuEvents);
|
|
1337
|
+
return children ? /* @__PURE__ */ jsx(CustomContent, {
|
|
1338
|
+
instance: contextMenu,
|
|
1339
|
+
children
|
|
1340
|
+
}) : null;
|
|
1341
|
+
};
|
|
1342
|
+
// src/overlay/marker/marker.tsx
|
|
1343
|
+
const markerEvents = domOverlayEvents;
|
|
1344
|
+
function useMarkerAttributes(marker, props, children) {
|
|
1345
|
+
const { anchor, content, offset, orientation, position, rotate, size, visible, zIndex, clickable, cursor, draggable, extData, icon, label, title, isTop, ...rest } = props;
|
|
1346
|
+
useLayoutEffect(() => {
|
|
1347
|
+
marker.setClickable(clickable);
|
|
1348
|
+
}, [clickable]);
|
|
1349
|
+
useLayoutEffect(() => {
|
|
1350
|
+
marker.setCursor(cursor);
|
|
1351
|
+
}, [cursor]);
|
|
1352
|
+
useLayoutEffect(() => {
|
|
1353
|
+
if (draggable !== void 0) marker.setDraggable(draggable);
|
|
1354
|
+
}, [draggable]);
|
|
1355
|
+
useLayoutEffect(() => {
|
|
1356
|
+
marker.setExtData(extData);
|
|
1357
|
+
}, [extData]);
|
|
1358
|
+
useLayoutEffect(() => {
|
|
1359
|
+
marker.setIcon(clone(icon));
|
|
1360
|
+
}, [icon]);
|
|
1361
|
+
useLayoutEffect(() => {
|
|
1362
|
+
if (label !== void 0) marker.setLabel(clone(label));
|
|
1363
|
+
}, [label]);
|
|
1364
|
+
useLayoutEffect(() => {
|
|
1365
|
+
if (title !== void 0) marker.setTitle(clone(title));
|
|
1366
|
+
}, [title]);
|
|
1367
|
+
useLayoutEffect(() => {
|
|
1368
|
+
marker.setTop(isTop);
|
|
1369
|
+
}, [isTop]);
|
|
1370
|
+
useLayoutEffect(() => {
|
|
1371
|
+
marker.setOptions(rest);
|
|
1372
|
+
}, [rest]);
|
|
1373
|
+
useDOMOverlayAttributes(marker, props, children);
|
|
1374
|
+
}
|
|
1375
|
+
const Marker = ({ ref, map: _map, children, ...props }) => {
|
|
1376
|
+
const map = useMapInstance(_map);
|
|
1377
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(markerEvents));
|
|
1378
|
+
const marker = useLazyInit(() => new AMap.Marker(restProps));
|
|
1379
|
+
useLayoutEffect(() => {
|
|
1380
|
+
map?.add(marker);
|
|
1381
|
+
return () => {
|
|
1382
|
+
map?.remove(marker);
|
|
1383
|
+
};
|
|
1384
|
+
}, [map]);
|
|
1385
|
+
useEffect(() => {
|
|
1386
|
+
return () => marker.destroy();
|
|
1387
|
+
}, []);
|
|
1388
|
+
useImperativeHandle(ref, () => marker, []);
|
|
1389
|
+
useMarkerAttributes(marker, restProps, children);
|
|
1390
|
+
useEventListeners(marker, eventProps, markerEvents);
|
|
1391
|
+
return children ? /* @__PURE__ */ jsx(CustomContent, {
|
|
1392
|
+
instance: marker,
|
|
1393
|
+
children
|
|
1394
|
+
}) : null;
|
|
1395
|
+
};
|
|
1396
|
+
// src/overlay/elastic-marker/elastic-marker.ts
|
|
1397
|
+
const elasticMarkerEvents = markerEvents;
|
|
1398
|
+
const ElasticMarker = ({ ref, map: _map, ...props }) => {
|
|
1399
|
+
const map = useMapInstance(_map);
|
|
1400
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(elasticMarkerEvents));
|
|
1401
|
+
const elasticMarker = useLazyInit(() => new AMap.ElasticMarker(restProps));
|
|
1402
|
+
useLayoutEffect(() => {
|
|
1403
|
+
map?.add(elasticMarker);
|
|
1404
|
+
return () => {
|
|
1405
|
+
map?.remove(elasticMarker);
|
|
1406
|
+
};
|
|
1407
|
+
}, [map]);
|
|
1408
|
+
useEffect(() => {
|
|
1409
|
+
return () => elasticMarker.destroy();
|
|
1410
|
+
}, []);
|
|
1411
|
+
useImperativeHandle(ref, () => elasticMarker, []);
|
|
1412
|
+
const { styles, zoomStyleMapping, ...rest } = restProps;
|
|
1413
|
+
useLayoutEffect(() => {
|
|
1414
|
+
if (zoomStyleMapping !== void 0) elasticMarker.setMapping(clone(zoomStyleMapping));
|
|
1415
|
+
}, [zoomStyleMapping]);
|
|
1416
|
+
useLayoutEffect(() => {
|
|
1417
|
+
if (styles !== void 0) elasticMarker.setStyle(clone(styles));
|
|
1418
|
+
}, [styles]);
|
|
1419
|
+
useMarkerAttributes(elasticMarker, rest);
|
|
1420
|
+
useEventListeners(elasticMarker, eventProps, elasticMarkerEvents);
|
|
1421
|
+
return null;
|
|
1422
|
+
};
|
|
1423
|
+
// src/overlay/ellipse/ellipse.ts
|
|
1424
|
+
const ellipseEvents = vectorOverlayEvents;
|
|
1425
|
+
const Ellipse = ({ ref, map: _map, ...props }) => {
|
|
1426
|
+
const map = useMapInstance(_map);
|
|
1427
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(ellipseEvents));
|
|
1428
|
+
const vectorLayer = useVectorLayerInstance();
|
|
1429
|
+
const ellipse = useLazyInit(() => new AMap.Ellipse(restProps));
|
|
1430
|
+
useLayoutEffect(() => {
|
|
1431
|
+
if (vectorLayer) {
|
|
1432
|
+
vectorLayer.add(ellipse);
|
|
1433
|
+
return () => {
|
|
1434
|
+
vectorLayer.remove(ellipse);
|
|
1435
|
+
};
|
|
1436
|
+
} else {
|
|
1437
|
+
map?.add(ellipse);
|
|
1438
|
+
return () => {
|
|
1439
|
+
map?.remove(ellipse);
|
|
1440
|
+
};
|
|
1441
|
+
}
|
|
1442
|
+
}, [vectorLayer, map]);
|
|
1443
|
+
useEffect(() => {
|
|
1444
|
+
return () => ellipse.destroy();
|
|
1445
|
+
}, []);
|
|
1446
|
+
useImperativeHandle(ref, () => ellipse, []);
|
|
1447
|
+
const { draggable, extData, visible, center, radius, ...rest } = restProps;
|
|
1448
|
+
useVectorOverlayAttributes(ellipse, restProps);
|
|
1449
|
+
useLayoutEffect(() => {
|
|
1450
|
+
if (center !== void 0) ellipse.setCenter(center);
|
|
1451
|
+
}, [center]);
|
|
1452
|
+
useLayoutEffect(() => {
|
|
1453
|
+
if (radius !== void 0) ellipse.setRadius(radius);
|
|
1454
|
+
}, [radius]);
|
|
1455
|
+
useLayoutEffect(() => {
|
|
1456
|
+
ellipse.setOptions(rest);
|
|
1457
|
+
}, [rest]);
|
|
1458
|
+
useEventListeners(ellipse, eventProps, ellipseEvents);
|
|
1459
|
+
return null;
|
|
1460
|
+
};
|
|
1461
|
+
// src/overlay/index-cluster/index-cluster.ts
|
|
1462
|
+
const indexClusterEvents = [click];
|
|
1463
|
+
const IndexCluster = ({ ref, map: _map, data, ...props }) => {
|
|
1464
|
+
const map = useMapInstance(_map);
|
|
1465
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(indexClusterEvents));
|
|
1466
|
+
const indexCluster = useLazyInit(() => new AMap.IndexCluster(null, clone(data, true), restProps));
|
|
1467
|
+
useLayoutEffect(() => {
|
|
1468
|
+
syncProperty(indexCluster, "i", null);
|
|
1469
|
+
indexCluster.setMap(map);
|
|
1470
|
+
return () => {
|
|
1471
|
+
indexCluster.setMap(null);
|
|
1472
|
+
};
|
|
1473
|
+
}, [map]);
|
|
1474
|
+
useEffect(() => {
|
|
1475
|
+
indexCluster?.setData(clone(data, true));
|
|
1476
|
+
return () => {
|
|
1477
|
+
indexCluster.setData([]);
|
|
1478
|
+
};
|
|
1479
|
+
}, [data]);
|
|
1480
|
+
useImperativeHandle(ref, () => indexCluster, []);
|
|
1481
|
+
const { averageCenter, clusterByZoomChange, customRender, gridSize, maxZoom, renderClusterMarker, renderMarker, styles } = restProps;
|
|
1482
|
+
useLayoutEffect(() => {
|
|
1483
|
+
if (averageCenter !== void 0) indexCluster.setAverageCenter(averageCenter);
|
|
1484
|
+
}, [averageCenter]);
|
|
1485
|
+
useLayoutEffect(() => {
|
|
1486
|
+
syncProperty(indexCluster, "clusterByZoomChange", clusterByZoomChange || false);
|
|
1487
|
+
}, [clusterByZoomChange]);
|
|
1488
|
+
useLayoutEffect(() => {
|
|
1489
|
+
syncProperty(indexCluster, "customRender", customRender || null);
|
|
1490
|
+
}, [customRender]);
|
|
1491
|
+
useLayoutEffect(() => {
|
|
1492
|
+
if (gridSize !== void 0) indexCluster.setGridSize(gridSize);
|
|
1493
|
+
}, [gridSize]);
|
|
1494
|
+
useLayoutEffect(() => {
|
|
1495
|
+
if (maxZoom !== void 0) indexCluster.setMaxZoom(maxZoom);
|
|
1496
|
+
}, [maxZoom]);
|
|
1497
|
+
useLayoutEffect(() => {
|
|
1498
|
+
syncProperty(indexCluster, "renderClusterMarker", renderClusterMarker || null);
|
|
1499
|
+
}, [renderClusterMarker]);
|
|
1500
|
+
useLayoutEffect(() => {
|
|
1501
|
+
indexCluster.setRenderMarkerStyle(renderMarker || null);
|
|
1502
|
+
}, [renderMarker]);
|
|
1503
|
+
useLayoutEffect(() => {
|
|
1504
|
+
if (styles !== void 0) {
|
|
1505
|
+
indexCluster.setStyles(styles);
|
|
1506
|
+
return;
|
|
1507
|
+
}
|
|
1508
|
+
const markerCluster = new AMap.IndexCluster();
|
|
1509
|
+
const defaultStyles = markerCluster.getStyles();
|
|
1510
|
+
markerCluster.setMap(null);
|
|
1511
|
+
indexCluster.setStyles(defaultStyles);
|
|
1512
|
+
}, [styles]);
|
|
1513
|
+
useEventListeners(indexCluster, eventProps, indexClusterEvents);
|
|
1514
|
+
return null;
|
|
1515
|
+
};
|
|
1516
|
+
// src/overlay/info-window/info-window.tsx
|
|
1517
|
+
const infoWindowEvents = [close, open];
|
|
1518
|
+
const InfoWindow = ({ ref, map: _map, children, ...props }) => {
|
|
1519
|
+
const map = useMapInstance(_map);
|
|
1520
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(infoWindowEvents));
|
|
1521
|
+
const infoWindow = useLazyInit(() => new AMap.InfoWindow(restProps));
|
|
1522
|
+
useLayoutEffect(() => {
|
|
1523
|
+
map?.add(infoWindow);
|
|
1524
|
+
return () => {
|
|
1525
|
+
map?.remove(infoWindow);
|
|
1526
|
+
};
|
|
1527
|
+
}, [map]);
|
|
1528
|
+
useEffect(() => {
|
|
1529
|
+
return () => infoWindow.destroy();
|
|
1530
|
+
}, []);
|
|
1531
|
+
useImperativeHandle(ref, () => infoWindow, []);
|
|
1532
|
+
const { anchor, content, offset, orientation, position, rotate, size, visible, zIndex, extData, ...rest } = restProps;
|
|
1533
|
+
useLayoutEffect(() => {
|
|
1534
|
+
infoWindow.setExtData(extData);
|
|
1535
|
+
}, [extData]);
|
|
1536
|
+
useLayoutEffect(() => {
|
|
1537
|
+
infoWindow.setOptions(rest);
|
|
1538
|
+
}, [rest]);
|
|
1539
|
+
useDOMOverlayAttributes(infoWindow, restProps, children);
|
|
1540
|
+
useEventListeners(infoWindow, eventProps, infoWindowEvents);
|
|
1541
|
+
return children ? /* @__PURE__ */ jsx(CustomContent, {
|
|
1542
|
+
instance: infoWindow,
|
|
1543
|
+
children
|
|
1544
|
+
}) : null;
|
|
1545
|
+
};
|
|
1546
|
+
// src/overlay/label-marker/label-marker.ts
|
|
1547
|
+
const labelMarkerEvents = [
|
|
1548
|
+
click,
|
|
1549
|
+
mouseMove,
|
|
1550
|
+
mouseOver,
|
|
1551
|
+
mouseOut,
|
|
1552
|
+
mouseDown,
|
|
1553
|
+
mouseUp,
|
|
1554
|
+
touchStart,
|
|
1555
|
+
touchMove,
|
|
1556
|
+
touchEnd
|
|
1557
|
+
];
|
|
1558
|
+
const LabelMarker = ({ ref, ...props }) => {
|
|
1559
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(labelMarkerEvents));
|
|
1560
|
+
const labelsLayer = useLabelsLayerInstance();
|
|
1561
|
+
const labelMarker = useLazyInit(() => new AMap.LabelMarker(restProps));
|
|
1562
|
+
useEffect(() => {
|
|
1563
|
+
labelsLayer?.add(labelMarker);
|
|
1564
|
+
return () => {
|
|
1565
|
+
labelsLayer?.remove(labelMarker);
|
|
1566
|
+
};
|
|
1567
|
+
}, [labelsLayer]);
|
|
1568
|
+
useImperativeHandle(ref, () => labelMarker, []);
|
|
1569
|
+
const { cursor, extData, icon, name, opacity, orientation, position, rank, richText, rotation, text, isTop, visible, zooms, zIndex } = restProps;
|
|
1570
|
+
useLayoutEffect(() => {
|
|
1571
|
+
labelMarker.setCursor(cursor);
|
|
1572
|
+
}, [cursor]);
|
|
1573
|
+
useLayoutEffect(() => {
|
|
1574
|
+
labelMarker.setExtData(extData);
|
|
1575
|
+
}, [extData]);
|
|
1576
|
+
useLayoutEffect(() => {
|
|
1577
|
+
labelMarker.setIcon(clone(icon));
|
|
1578
|
+
}, [icon]);
|
|
1579
|
+
useLayoutEffect(() => {
|
|
1580
|
+
if (name !== void 0) labelMarker.setName(name);
|
|
1581
|
+
}, [name]);
|
|
1582
|
+
useLayoutEffect(() => {
|
|
1583
|
+
labelMarker.setOpacity(opacity);
|
|
1584
|
+
}, [opacity]);
|
|
1585
|
+
useLayoutEffect(() => {
|
|
1586
|
+
labelMarker.setOrientation(orientation);
|
|
1587
|
+
}, [orientation]);
|
|
1588
|
+
useLayoutEffect(() => {
|
|
1589
|
+
if (position !== void 0) labelMarker.setPosition(clone(position));
|
|
1590
|
+
}, [position]);
|
|
1591
|
+
useLayoutEffect(() => {
|
|
1592
|
+
if (rank !== void 0) labelMarker.setRank(rank);
|
|
1593
|
+
}, [rank]);
|
|
1594
|
+
useLayoutEffect(() => {
|
|
1595
|
+
labelMarker.setRichText(clone(richText));
|
|
1596
|
+
}, [richText]);
|
|
1597
|
+
useLayoutEffect(() => {
|
|
1598
|
+
if (rotation !== void 0) labelMarker.setRotation(rotation);
|
|
1599
|
+
}, [rotation]);
|
|
1600
|
+
useLayoutEffect(() => {
|
|
1601
|
+
if (text !== void 0) labelMarker.setText(clone(text));
|
|
1602
|
+
}, [text]);
|
|
1603
|
+
useLayoutEffect(() => {
|
|
1604
|
+
labelMarker.setTop(isTop);
|
|
1605
|
+
}, [isTop]);
|
|
1606
|
+
useLayoutEffect(() => {
|
|
1607
|
+
labelMarker.setVisible(visible);
|
|
1608
|
+
}, [visible]);
|
|
1609
|
+
useLayoutEffect(() => {
|
|
1610
|
+
labelMarker.setZooms(clone(zooms));
|
|
1611
|
+
}, [zooms]);
|
|
1612
|
+
useLayoutEffect(() => {
|
|
1613
|
+
if (zIndex !== void 0) labelMarker.setzIndex(zIndex);
|
|
1614
|
+
}, [zIndex]);
|
|
1615
|
+
useEventListeners(labelMarker, eventProps, labelMarkerEvents);
|
|
1616
|
+
return null;
|
|
1617
|
+
};
|
|
1618
|
+
// src/overlay/marker-cluster/marker-cluster.ts
|
|
1619
|
+
const markerClusterEvents = [click];
|
|
1620
|
+
const MarkerCluster = ({ ref, map: _map, data, ...props }) => {
|
|
1621
|
+
const map = useMapInstance(_map);
|
|
1622
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(markerClusterEvents));
|
|
1623
|
+
const markerCluster = useLazyInit(() => new AMap.MarkerCluster(null, clone(data, true), restProps));
|
|
1624
|
+
useLayoutEffect(() => {
|
|
1625
|
+
syncProperty(markerCluster, "i", null);
|
|
1626
|
+
markerCluster.setMap(map);
|
|
1627
|
+
return () => {
|
|
1628
|
+
markerCluster.setMap(null);
|
|
1629
|
+
};
|
|
1630
|
+
}, [map]);
|
|
1631
|
+
useEffect(() => {
|
|
1632
|
+
markerCluster?.setData(clone(data, true));
|
|
1633
|
+
return () => {
|
|
1634
|
+
markerCluster.setData([]);
|
|
1635
|
+
};
|
|
1636
|
+
}, [data]);
|
|
1637
|
+
useImperativeHandle(ref, () => markerCluster, []);
|
|
1638
|
+
const { averageCenter, gridSize, maxZoom, minClusterSize, renderClusterMarker, renderMarker, styles } = restProps;
|
|
1639
|
+
useLayoutEffect(() => {
|
|
1640
|
+
if (averageCenter !== void 0) markerCluster.setAverageCenter(averageCenter);
|
|
1641
|
+
}, [averageCenter]);
|
|
1642
|
+
useLayoutEffect(() => {
|
|
1643
|
+
if (gridSize !== void 0) markerCluster.setGridSize(gridSize);
|
|
1644
|
+
}, [gridSize]);
|
|
1645
|
+
useLayoutEffect(() => {
|
|
1646
|
+
if (maxZoom !== void 0) markerCluster.setMaxZoom(maxZoom);
|
|
1647
|
+
}, [maxZoom]);
|
|
1648
|
+
useLayoutEffect(() => {
|
|
1649
|
+
if (minClusterSize !== void 0) markerCluster.setMinClusterSize(minClusterSize);
|
|
1650
|
+
}, [minClusterSize]);
|
|
1651
|
+
useLayoutEffect(() => {
|
|
1652
|
+
syncProperty(markerCluster, "renderClusterMarker", renderClusterMarker);
|
|
1653
|
+
}, [renderClusterMarker]);
|
|
1654
|
+
useLayoutEffect(() => {
|
|
1655
|
+
markerCluster.setRenderMarkerStyle(renderMarker);
|
|
1656
|
+
}, [renderMarker]);
|
|
1657
|
+
useLayoutEffect(() => {
|
|
1658
|
+
if (styles !== void 0) {
|
|
1659
|
+
markerCluster.setStyles(styles);
|
|
1660
|
+
return;
|
|
1661
|
+
}
|
|
1662
|
+
const markerClusterInstance = new AMap.MarkerCluster();
|
|
1663
|
+
const defaultStyles = markerClusterInstance.getStyles();
|
|
1664
|
+
markerClusterInstance.setMap(null);
|
|
1665
|
+
markerCluster.setStyles(defaultStyles);
|
|
1666
|
+
}, [styles]);
|
|
1667
|
+
useEventListeners(markerCluster, eventProps, markerClusterEvents);
|
|
1668
|
+
return null;
|
|
1669
|
+
};
|
|
1670
|
+
// src/overlay/mass-marks/mass-marks.ts
|
|
1671
|
+
const massMarksEvents = [
|
|
1672
|
+
click,
|
|
1673
|
+
complete,
|
|
1674
|
+
dblClick,
|
|
1675
|
+
mouseDown,
|
|
1676
|
+
mouseMove,
|
|
1677
|
+
mouseOut,
|
|
1678
|
+
mouseOver,
|
|
1679
|
+
mouseUp,
|
|
1680
|
+
touchEnd,
|
|
1681
|
+
touchStart
|
|
1682
|
+
];
|
|
1683
|
+
const MassMarks = ({ ref, map: _map, data, ...props }) => {
|
|
1684
|
+
const map = useMapInstance(_map);
|
|
1685
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(massMarksEvents));
|
|
1686
|
+
const massMarks = useLazyInit(() => new AMap.MassMarks(clone(data), restProps));
|
|
1687
|
+
useLayoutEffect(() => {
|
|
1688
|
+
massMarks.setMap(map);
|
|
1689
|
+
return () => {
|
|
1690
|
+
massMarks.setMap(null);
|
|
1691
|
+
};
|
|
1692
|
+
}, [map]);
|
|
1693
|
+
useEffect(() => {
|
|
1694
|
+
massMarks.setData(clone(data));
|
|
1695
|
+
}, [data]);
|
|
1696
|
+
useEffect(() => {
|
|
1697
|
+
return () => {
|
|
1698
|
+
massMarks.clear();
|
|
1699
|
+
};
|
|
1700
|
+
}, []);
|
|
1701
|
+
useImperativeHandle(ref, () => massMarks, []);
|
|
1702
|
+
const { opacity, style, zIndex, zooms } = restProps;
|
|
1703
|
+
useLayoutEffect(() => {
|
|
1704
|
+
if (opacity !== void 0) massMarks.setOpacity(opacity);
|
|
1705
|
+
}, [opacity]);
|
|
1706
|
+
useLayoutEffect(() => {
|
|
1707
|
+
if (style !== void 0) massMarks.setStyle(clone(style));
|
|
1708
|
+
}, [style]);
|
|
1709
|
+
useLayoutEffect(() => {
|
|
1710
|
+
if (zIndex !== void 0) massMarks.setzIndex(zIndex);
|
|
1711
|
+
}, [zIndex]);
|
|
1712
|
+
useLayoutEffect(() => {
|
|
1713
|
+
if (zooms !== void 0) massMarks.setZooms(clone(zooms));
|
|
1714
|
+
}, [zooms]);
|
|
1715
|
+
useEventListeners(massMarks, eventProps, massMarksEvents);
|
|
1716
|
+
return null;
|
|
1717
|
+
};
|
|
1718
|
+
// src/overlay/overlay-group/overlay-group.ts
|
|
1719
|
+
const overlayGroupEvents = [.../* @__PURE__ */ new Set([...vectorOverlayEvents, ...domOverlayEvents])];
|
|
1720
|
+
const OverlayGroup = ({ ref, visible, map: _map, overlays, ...props }) => {
|
|
1721
|
+
const map = useMapInstance(_map);
|
|
1722
|
+
const [eventProps] = splitProps(props, eventsToProps(overlayGroupEvents));
|
|
1723
|
+
const overlayGroup = useLazyInit(() => new AMap.OverlayGroup());
|
|
1724
|
+
useLayoutEffect(() => {
|
|
1725
|
+
if (!map) return;
|
|
1726
|
+
map.add(overlayGroup);
|
|
1727
|
+
return () => {
|
|
1728
|
+
map.remove(overlayGroup);
|
|
1729
|
+
};
|
|
1730
|
+
}, [map]);
|
|
1731
|
+
const mountedOverlaysRef = useRef(/* @__PURE__ */ new Set());
|
|
1732
|
+
useEffect(() => {
|
|
1733
|
+
const nextOverlays = overlays ? Array.from(new Set(overlays)) : [];
|
|
1734
|
+
const nextOverlaySet = new Set(nextOverlays);
|
|
1735
|
+
const overlaysToRemove = Array.from(mountedOverlaysRef.current).filter((overlay) => !nextOverlaySet.has(overlay));
|
|
1736
|
+
const overlaysToAdd = nextOverlays.filter((overlay) => !mountedOverlaysRef.current.has(overlay));
|
|
1737
|
+
if (overlaysToRemove.length > 0) overlayGroup.removeOverlays(overlaysToRemove);
|
|
1738
|
+
if (overlaysToAdd.length > 0) overlayGroup.addOverlays(overlaysToAdd);
|
|
1739
|
+
mountedOverlaysRef.current = nextOverlaySet;
|
|
1740
|
+
}, [overlayGroup, overlays]);
|
|
1741
|
+
useEffect(() => {
|
|
1742
|
+
return () => {
|
|
1743
|
+
mountedOverlaysRef.current.clear();
|
|
1744
|
+
overlayGroup.clearOverlays();
|
|
1745
|
+
};
|
|
1746
|
+
}, [overlayGroup]);
|
|
1747
|
+
const boundOverlaysRef = useRef(/* @__PURE__ */ new Map());
|
|
1748
|
+
const getHandler = useEffectEvent((eventType) => {
|
|
1749
|
+
return eventProps[eventToProp(eventType)];
|
|
1750
|
+
});
|
|
1751
|
+
useEffect(() => {
|
|
1752
|
+
const nextOverlays = overlays ? Array.from(new Set(overlays)) : [];
|
|
1753
|
+
const nextOverlaySet = new Set(nextOverlays);
|
|
1754
|
+
for (const [overlay, handlerMap] of boundOverlaysRef.current) if (!nextOverlaySet.has(overlay)) {
|
|
1755
|
+
for (const [eventType, handler] of handlerMap) overlay.off(lowercase(eventType), handler);
|
|
1756
|
+
boundOverlaysRef.current.delete(overlay);
|
|
1757
|
+
if ("destroy" in overlay && typeof overlay.destroy === "function") overlay.destroy();
|
|
1758
|
+
}
|
|
1759
|
+
for (const overlay of nextOverlays) {
|
|
1760
|
+
if (boundOverlaysRef.current.has(overlay)) continue;
|
|
1761
|
+
const handlerMap = /* @__PURE__ */ new Map();
|
|
1762
|
+
const eventTypes = overlay instanceof AMap.Marker ? domOverlayEvents : vectorOverlayEvents;
|
|
1763
|
+
for (const eventType of eventTypes) {
|
|
1764
|
+
const handler = (event) => {
|
|
1765
|
+
getHandler(eventType)?.(event);
|
|
1766
|
+
};
|
|
1767
|
+
overlay.on(lowercase(eventType), handler);
|
|
1768
|
+
handlerMap.set(eventType, handler);
|
|
1769
|
+
}
|
|
1770
|
+
boundOverlaysRef.current.set(overlay, handlerMap);
|
|
1771
|
+
}
|
|
1772
|
+
}, [overlays]);
|
|
1773
|
+
useEffect(() => {
|
|
1774
|
+
const boundOverlays = boundOverlaysRef.current;
|
|
1775
|
+
return () => {
|
|
1776
|
+
for (const [overlay, handlerMap] of boundOverlays) {
|
|
1777
|
+
for (const [eventType, handler] of handlerMap) overlay.off(lowercase(eventType), handler);
|
|
1778
|
+
if ("destroy" in overlay && typeof overlay.destroy === "function") overlay.destroy();
|
|
1779
|
+
}
|
|
1780
|
+
boundOverlays.clear();
|
|
1781
|
+
};
|
|
1782
|
+
}, []);
|
|
1783
|
+
useImperativeHandle(ref, () => overlayGroup, [overlayGroup]);
|
|
1784
|
+
useLayoutEffect(() => {
|
|
1785
|
+
if (visible !== void 0) {
|
|
1786
|
+
if (visible) overlayGroup.show();
|
|
1787
|
+
else overlayGroup.hide();
|
|
1788
|
+
}
|
|
1789
|
+
}, [overlayGroup, visible]);
|
|
1790
|
+
return null;
|
|
1791
|
+
};
|
|
1792
|
+
// src/overlay/polygon/polygon.ts
|
|
1793
|
+
const polygonEvents = vectorOverlayEvents;
|
|
1794
|
+
const Polygon = ({ ref, map: _map, ...props }) => {
|
|
1795
|
+
const map = useMapInstance(_map);
|
|
1796
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(polygonEvents));
|
|
1797
|
+
const vectorLayer = useVectorLayerInstance();
|
|
1798
|
+
const polygon = useLazyInit(() => new AMap.Polygon(restProps));
|
|
1799
|
+
useLayoutEffect(() => {
|
|
1800
|
+
if (vectorLayer) {
|
|
1801
|
+
vectorLayer.add(polygon);
|
|
1802
|
+
return () => {
|
|
1803
|
+
vectorLayer.remove(polygon);
|
|
1804
|
+
};
|
|
1805
|
+
} else {
|
|
1806
|
+
map?.add(polygon);
|
|
1807
|
+
return () => {
|
|
1808
|
+
map?.remove(polygon);
|
|
1809
|
+
};
|
|
1810
|
+
}
|
|
1811
|
+
}, [vectorLayer, map]);
|
|
1812
|
+
useEffect(() => {
|
|
1813
|
+
return () => polygon.destroy();
|
|
1814
|
+
}, []);
|
|
1815
|
+
useImperativeHandle(ref, () => polygon, []);
|
|
1816
|
+
const { draggable, extData, visible, extrusionHeight, path, ...rest } = restProps;
|
|
1817
|
+
useVectorOverlayAttributes(polygon, restProps);
|
|
1818
|
+
useLayoutEffect(() => {
|
|
1819
|
+
if (extrusionHeight !== void 0) polygon.setExtrusionHeight(extrusionHeight);
|
|
1820
|
+
}, [extrusionHeight]);
|
|
1821
|
+
useLayoutEffect(() => {
|
|
1822
|
+
polygon.setOptions(rest);
|
|
1823
|
+
}, [rest]);
|
|
1824
|
+
useLayoutEffect(() => {
|
|
1825
|
+
polygon.setPath(path);
|
|
1826
|
+
}, [path]);
|
|
1827
|
+
useEventListeners(polygon, eventProps, polygonEvents);
|
|
1828
|
+
return null;
|
|
1829
|
+
};
|
|
1830
|
+
// src/overlay/polyline/polyline.ts
|
|
1831
|
+
const polylineEvents = vectorOverlayEvents;
|
|
1832
|
+
const Polyline = ({ ref, map: _map, ...props }) => {
|
|
1833
|
+
const map = useMapInstance(_map);
|
|
1834
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(polylineEvents));
|
|
1835
|
+
const vectorLayer = useVectorLayerInstance();
|
|
1836
|
+
const polyline = useLazyInit(() => new AMap.Polyline(restProps));
|
|
1837
|
+
useLayoutEffect(() => {
|
|
1838
|
+
if (vectorLayer) {
|
|
1839
|
+
vectorLayer.add(polyline);
|
|
1840
|
+
return () => {
|
|
1841
|
+
vectorLayer.remove(polyline);
|
|
1842
|
+
};
|
|
1843
|
+
} else {
|
|
1844
|
+
map?.add(polyline);
|
|
1845
|
+
return () => {
|
|
1846
|
+
map?.remove(polyline);
|
|
1847
|
+
};
|
|
1848
|
+
}
|
|
1849
|
+
}, [vectorLayer, map]);
|
|
1850
|
+
useEffect(() => {
|
|
1851
|
+
return () => polyline.destroy();
|
|
1852
|
+
}, []);
|
|
1853
|
+
useImperativeHandle(ref, () => polyline, []);
|
|
1854
|
+
const { draggable, extData, visible, height, path, ...rest } = restProps;
|
|
1855
|
+
useVectorOverlayAttributes(polyline, restProps);
|
|
1856
|
+
useLayoutEffect(() => {
|
|
1857
|
+
polyline.setOptions(rest);
|
|
1858
|
+
}, [rest]);
|
|
1859
|
+
useLayoutEffect(() => {
|
|
1860
|
+
polyline.setPath(path);
|
|
1861
|
+
}, [path]);
|
|
1862
|
+
useEventListeners(polyline, eventProps, polylineEvents);
|
|
1863
|
+
return null;
|
|
1864
|
+
};
|
|
1865
|
+
// src/overlay/rectangle/rectangle.ts
|
|
1866
|
+
const rectangleEvents = vectorOverlayEvents;
|
|
1867
|
+
const Rectangle = ({ ref, map: _map, ...props }) => {
|
|
1868
|
+
const map = useMapInstance(_map);
|
|
1869
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(rectangleEvents));
|
|
1870
|
+
const vectorLayer = useVectorLayerInstance();
|
|
1871
|
+
const rectangle = useLazyInit(() => new AMap.Rectangle(restProps));
|
|
1872
|
+
useLayoutEffect(() => {
|
|
1873
|
+
if (vectorLayer) {
|
|
1874
|
+
vectorLayer.add(rectangle);
|
|
1875
|
+
return () => {
|
|
1876
|
+
vectorLayer.remove(rectangle);
|
|
1877
|
+
};
|
|
1878
|
+
} else {
|
|
1879
|
+
map?.add(rectangle);
|
|
1880
|
+
return () => {
|
|
1881
|
+
map?.remove(rectangle);
|
|
1882
|
+
};
|
|
1883
|
+
}
|
|
1884
|
+
}, [vectorLayer, map]);
|
|
1885
|
+
useEffect(() => {
|
|
1886
|
+
return () => rectangle.destroy();
|
|
1887
|
+
}, []);
|
|
1888
|
+
useImperativeHandle(ref, () => rectangle, []);
|
|
1889
|
+
const { draggable, extData, visible, bounds, ...rest } = restProps;
|
|
1890
|
+
useVectorOverlayAttributes(rectangle, restProps);
|
|
1891
|
+
useLayoutEffect(() => {
|
|
1892
|
+
rectangle.setOptions(rest);
|
|
1893
|
+
}, [rest]);
|
|
1894
|
+
useLayoutEffect(() => {
|
|
1895
|
+
rectangle.setBounds(bounds);
|
|
1896
|
+
}, [bounds]);
|
|
1897
|
+
useEventListeners(rectangle, eventProps, rectangleEvents);
|
|
1898
|
+
return null;
|
|
1899
|
+
};
|
|
1900
|
+
// src/overlay/text/text.tsx
|
|
1901
|
+
const textEvents = markerEvents;
|
|
1902
|
+
const Text = ({ ref, map: _map, children, ...props }) => {
|
|
1903
|
+
const map = useMapInstance(_map);
|
|
1904
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(textEvents));
|
|
1905
|
+
const text = useLazyInit(() => new AMap.Text(restProps));
|
|
1906
|
+
useLayoutEffect(() => {
|
|
1907
|
+
map?.add(text);
|
|
1908
|
+
return () => {
|
|
1909
|
+
map?.remove(text);
|
|
1910
|
+
};
|
|
1911
|
+
}, [map]);
|
|
1912
|
+
useEffect(() => {
|
|
1913
|
+
return () => text.destroy();
|
|
1914
|
+
}, []);
|
|
1915
|
+
useImperativeHandle(ref, () => text, []);
|
|
1916
|
+
const { style, text: _text, ...rest } = restProps;
|
|
1917
|
+
useLayoutEffect(() => {
|
|
1918
|
+
if (style !== void 0) text.setStyle(clone(style));
|
|
1919
|
+
}, [style]);
|
|
1920
|
+
useMarkerAttributes(text, rest, children);
|
|
1921
|
+
useLayoutEffect(() => {
|
|
1922
|
+
if (children ?? props.content) return;
|
|
1923
|
+
if (_text !== void 0) text.setText(clone(_text));
|
|
1924
|
+
}, [
|
|
1925
|
+
_text,
|
|
1926
|
+
children,
|
|
1927
|
+
rest.content
|
|
1928
|
+
]);
|
|
1929
|
+
useEventListeners(text, eventProps, textEvents);
|
|
1930
|
+
return children ? /* @__PURE__ */ jsx(CustomContent, {
|
|
1931
|
+
instance: text,
|
|
1932
|
+
children
|
|
1933
|
+
}) : null;
|
|
1934
|
+
};
|
|
1935
|
+
// src/tool/bezier-curve-editor/bezier-curve-editor.ts
|
|
1936
|
+
const bezierCurveEditorEvents = [
|
|
1937
|
+
add,
|
|
1938
|
+
end,
|
|
1939
|
+
adjust,
|
|
1940
|
+
addNode,
|
|
1941
|
+
removeNode
|
|
1942
|
+
];
|
|
1943
|
+
const BezierCurveEditor = ({ ref, map: _map, target, ...props }) => {
|
|
1944
|
+
const map = useMapInstance(_map);
|
|
1945
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(bezierCurveEditorEvents));
|
|
1946
|
+
const bezierCurveEditorRef = useRef(null);
|
|
1947
|
+
useLayoutEffect(() => {
|
|
1948
|
+
if (!map) return;
|
|
1949
|
+
bezierCurveEditorRef.current = new AMap.BezierCurveEditor(map, resolveTarget(target) ?? void 0, restProps);
|
|
1950
|
+
return () => {
|
|
1951
|
+
bezierCurveEditorRef.current?.destroy();
|
|
1952
|
+
bezierCurveEditorRef.current = null;
|
|
1953
|
+
};
|
|
1954
|
+
}, [map]);
|
|
1955
|
+
useEffect(() => {
|
|
1956
|
+
bezierCurveEditorRef.current?.setTarget(resolveTarget(target) ?? void 0);
|
|
1957
|
+
}, [target]);
|
|
1958
|
+
const getBezierCurveEditor = useCallback(() => bezierCurveEditorRef.current, []);
|
|
1959
|
+
useImperativeHandle(ref, getBezierCurveEditor);
|
|
1960
|
+
useLayoutEffect(() => {
|
|
1961
|
+
const editor = getBezierCurveEditor();
|
|
1962
|
+
if (restProps.createOptions && editor) editor._normalPolylineStyle = AMap.extend(editor._normalPolylineStyle, clone(restProps.createOptions));
|
|
1963
|
+
}, [restProps.createOptions]);
|
|
1964
|
+
useLayoutEffect(() => {
|
|
1965
|
+
const editor = getBezierCurveEditor();
|
|
1966
|
+
if (restProps.editOptions && editor) editor._editingPolylineStyle = AMap.extend(editor._editingPolylineStyle, clone(restProps.editOptions));
|
|
1967
|
+
}, [restProps.editOptions]);
|
|
1968
|
+
useLayoutEffect(() => {
|
|
1969
|
+
const editor = getBezierCurveEditor();
|
|
1970
|
+
if (restProps.controlPoint && editor) editor.opts.controlPoint = clone(restProps.controlPoint);
|
|
1971
|
+
}, [restProps.controlPoint]);
|
|
1972
|
+
useLayoutEffect(() => {
|
|
1973
|
+
const editor = getBezierCurveEditor();
|
|
1974
|
+
if (restProps.midControlPoint && editor) editor.opts.midControlPoint = clone(restProps.midControlPoint);
|
|
1975
|
+
}, [restProps.midControlPoint]);
|
|
1976
|
+
useLayoutEffect(() => {
|
|
1977
|
+
const editor = getBezierCurveEditor();
|
|
1978
|
+
if (restProps.bezierControlPoint && editor) editor.opts.bezierControlPoint = restProps.bezierControlPoint;
|
|
1979
|
+
}, [restProps.bezierControlPoint]);
|
|
1980
|
+
useLayoutEffect(() => {
|
|
1981
|
+
const editor = getBezierCurveEditor();
|
|
1982
|
+
if (restProps.bezierControlLine && editor) editor.opts.bezierControlLine = AMap.extend(editor.opts.bezierControlLine, restProps.bezierControlLine);
|
|
1983
|
+
}, [restProps.bezierControlLine]);
|
|
1984
|
+
useEventListeners(getBezierCurveEditor, eventProps, bezierCurveEditorEvents);
|
|
1985
|
+
return null;
|
|
1986
|
+
};
|
|
1987
|
+
// src/tool/circle-editor/circle-editor.ts
|
|
1988
|
+
const circleEditorEvents = [
|
|
1989
|
+
add,
|
|
1990
|
+
end,
|
|
1991
|
+
adjust,
|
|
1992
|
+
move
|
|
1993
|
+
];
|
|
1994
|
+
const CircleEditor = ({ ref, map: _map, target, ...props }) => {
|
|
1995
|
+
const map = useMapInstance(_map);
|
|
1996
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(circleEditorEvents));
|
|
1997
|
+
const circleEditorRef = useRef(null);
|
|
1998
|
+
useLayoutEffect(() => {
|
|
1999
|
+
if (!map) return;
|
|
2000
|
+
circleEditorRef.current = new AMap.CircleEditor(map, resolveTarget(target) ?? void 0, restProps);
|
|
2001
|
+
return () => {
|
|
2002
|
+
circleEditorRef.current?.destroy();
|
|
2003
|
+
circleEditorRef.current = null;
|
|
2004
|
+
};
|
|
2005
|
+
}, [map]);
|
|
2006
|
+
useEffect(() => {
|
|
2007
|
+
circleEditorRef.current?.setTarget(resolveTarget(target) ?? void 0);
|
|
2008
|
+
}, [target]);
|
|
2009
|
+
const getCircleEditor = useCallback(() => circleEditorRef.current, []);
|
|
2010
|
+
useImperativeHandle(ref, getCircleEditor);
|
|
2011
|
+
useLayoutEffect(() => {
|
|
2012
|
+
const editor = getCircleEditor();
|
|
2013
|
+
if (restProps.createOptions && editor) editor._normalCircleStyle = AMap.extend(editor._normalCircleStyle, clone(restProps.createOptions));
|
|
2014
|
+
}, [restProps.createOptions]);
|
|
2015
|
+
useLayoutEffect(() => {
|
|
2016
|
+
const editor = getCircleEditor();
|
|
2017
|
+
if (restProps.editOptions && editor) editor._editStyle = AMap.extend(editor._editStyle, clone(restProps.editOptions));
|
|
2018
|
+
}, [restProps.editOptions]);
|
|
2019
|
+
useLayoutEffect(() => {
|
|
2020
|
+
const editor = getCircleEditor();
|
|
2021
|
+
if (restProps.movePoint && editor) editor._opts.movePoint = restProps.movePoint;
|
|
2022
|
+
}, [restProps.movePoint]);
|
|
2023
|
+
useLayoutEffect(() => {
|
|
2024
|
+
const editor = getCircleEditor();
|
|
2025
|
+
if (restProps.resizePoint && editor) editor._opts.resizePoint = restProps.resizePoint;
|
|
2026
|
+
}, [restProps.resizePoint]);
|
|
2027
|
+
useEventListeners(getCircleEditor, eventProps, circleEditorEvents);
|
|
2028
|
+
return null;
|
|
2029
|
+
};
|
|
2030
|
+
// src/tool/ellipse-editor/ellipse-editor.ts
|
|
2031
|
+
const ellipseEditorEvents = [
|
|
2032
|
+
add,
|
|
2033
|
+
end,
|
|
2034
|
+
adjust,
|
|
2035
|
+
move
|
|
2036
|
+
];
|
|
2037
|
+
const EllipseEditor = ({ ref, map: _map, target, ...props }) => {
|
|
2038
|
+
const map = useMapInstance(_map);
|
|
2039
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(ellipseEditorEvents));
|
|
2040
|
+
const ellipseEditorRef = useRef(null);
|
|
2041
|
+
useLayoutEffect(() => {
|
|
2042
|
+
if (!map) return;
|
|
2043
|
+
ellipseEditorRef.current = new AMap.EllipseEditor(map, resolveTarget(target) ?? void 0, restProps);
|
|
2044
|
+
return () => {
|
|
2045
|
+
ellipseEditorRef.current?.destroy();
|
|
2046
|
+
ellipseEditorRef.current = null;
|
|
2047
|
+
};
|
|
2048
|
+
}, [map]);
|
|
2049
|
+
useEffect(() => {
|
|
2050
|
+
ellipseEditorRef.current?.setTarget(resolveTarget(target) ?? void 0);
|
|
2051
|
+
}, [target]);
|
|
2052
|
+
const getEllipseEditor = useCallback(() => ellipseEditorRef.current, []);
|
|
2053
|
+
useImperativeHandle(ref, getEllipseEditor);
|
|
2054
|
+
useLayoutEffect(() => {
|
|
2055
|
+
const editor = getEllipseEditor();
|
|
2056
|
+
if (restProps.createOptions && editor) editor._normalCircleStyle = AMap.extend(editor._normalCircleStyle, clone(restProps.createOptions));
|
|
2057
|
+
}, [restProps.createOptions]);
|
|
2058
|
+
useLayoutEffect(() => {
|
|
2059
|
+
const editor = getEllipseEditor();
|
|
2060
|
+
if (restProps.editOptions && editor) editor._editStyle = AMap.extend(editor._editStyle, clone(restProps.editOptions));
|
|
2061
|
+
}, [restProps.editOptions]);
|
|
2062
|
+
useLayoutEffect(() => {
|
|
2063
|
+
const editor = getEllipseEditor();
|
|
2064
|
+
if (restProps.movePoint && editor) editor._opts.movePoint = restProps.movePoint;
|
|
2065
|
+
}, [restProps.movePoint]);
|
|
2066
|
+
useLayoutEffect(() => {
|
|
2067
|
+
const editor = getEllipseEditor();
|
|
2068
|
+
if (restProps.resizeXPoint && editor) editor._opts.resizeXPoint = restProps.resizeXPoint;
|
|
2069
|
+
}, [restProps.resizeXPoint]);
|
|
2070
|
+
useLayoutEffect(() => {
|
|
2071
|
+
const editor = getEllipseEditor();
|
|
2072
|
+
if (restProps.resizeYPoint && editor) editor._opts.resizeYPoint = restProps.resizeYPoint;
|
|
2073
|
+
}, [restProps.resizeYPoint]);
|
|
2074
|
+
useEventListeners(getEllipseEditor, eventProps, ellipseEditorEvents);
|
|
2075
|
+
return null;
|
|
2076
|
+
};
|
|
2077
|
+
// src/tool/mouse-tool/mouse-tool.ts
|
|
2078
|
+
const mouseToolEvents = [draw];
|
|
2079
|
+
const MouseTool = ({ ref, map: _map, ...props }) => {
|
|
2080
|
+
const map = useMapInstance(_map);
|
|
2081
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(mouseToolEvents));
|
|
2082
|
+
const { toolBubble, clearOnClose } = restProps;
|
|
2083
|
+
const mouseToolRef = useRef(null);
|
|
2084
|
+
useLayoutEffect(() => {
|
|
2085
|
+
if (!map) return;
|
|
2086
|
+
const dragEnable = map.getStatus().dragEnable;
|
|
2087
|
+
mouseToolRef.current = new AMap.MouseTool(map, toolBubble);
|
|
2088
|
+
return () => {
|
|
2089
|
+
mouseToolRef.current?.close(clearOnClose);
|
|
2090
|
+
map.setStatus({ dragEnable });
|
|
2091
|
+
mouseToolRef.current = null;
|
|
2092
|
+
};
|
|
2093
|
+
}, [map]);
|
|
2094
|
+
const getMouseTool = useCallback(() => mouseToolRef.current, []);
|
|
2095
|
+
useImperativeHandle(ref, getMouseTool);
|
|
2096
|
+
useLayoutEffect(() => {
|
|
2097
|
+
const mouseToolInstance = getMouseTool();
|
|
2098
|
+
if (mouseToolInstance) mouseToolInstance.overlayBubble = restProps.toolBubble || false;
|
|
2099
|
+
}, [restProps.toolBubble]);
|
|
2100
|
+
useEventListeners(getMouseTool, eventProps, mouseToolEvents);
|
|
2101
|
+
return null;
|
|
2102
|
+
};
|
|
2103
|
+
// src/tool/polygon-editor/polygon-editor.ts
|
|
2104
|
+
const polygonEditorEvents = [
|
|
2105
|
+
add,
|
|
2106
|
+
end,
|
|
2107
|
+
adjust,
|
|
2108
|
+
addNode,
|
|
2109
|
+
removeNode
|
|
2110
|
+
];
|
|
2111
|
+
const PolygonEditor = ({ ref, map: _map, target, ...props }) => {
|
|
2112
|
+
const map = useMapInstance(_map);
|
|
2113
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(polygonEditorEvents));
|
|
2114
|
+
const polygonEditorRef = useRef(null);
|
|
2115
|
+
useLayoutEffect(() => {
|
|
2116
|
+
if (!map) return;
|
|
2117
|
+
polygonEditorRef.current = new AMap.PolygonEditor(map, resolveTarget(target) ?? void 0, restProps);
|
|
2118
|
+
patchPolygonEditor();
|
|
2119
|
+
return () => {
|
|
2120
|
+
polygonEditorRef.current?.destroy();
|
|
2121
|
+
polygonEditorRef.current = null;
|
|
2122
|
+
};
|
|
2123
|
+
}, [map]);
|
|
2124
|
+
useEffect(() => {
|
|
2125
|
+
polygonEditorRef.current?.setTarget(resolveTarget(target) ?? void 0);
|
|
2126
|
+
}, [target]);
|
|
2127
|
+
const getPolygonEditor = useCallback(() => polygonEditorRef.current, []);
|
|
2128
|
+
useImperativeHandle(ref, getPolygonEditor);
|
|
2129
|
+
useLayoutEffect(() => {
|
|
2130
|
+
const editor = getPolygonEditor();
|
|
2131
|
+
if (restProps.createOptions && editor) editor._opt.createOptions = clone(restProps.createOptions);
|
|
2132
|
+
}, [restProps.createOptions]);
|
|
2133
|
+
useLayoutEffect(() => {
|
|
2134
|
+
const editor = getPolygonEditor();
|
|
2135
|
+
if (restProps.editOptions && editor) editor._opt.editOptions = clone(restProps.editOptions);
|
|
2136
|
+
}, [restProps.editOptions]);
|
|
2137
|
+
useLayoutEffect(() => {
|
|
2138
|
+
const editor = getPolygonEditor();
|
|
2139
|
+
if (restProps.controlPoint && editor) {
|
|
2140
|
+
editor.controlPoint = AMap.extend(editor.controlPoint, clone(restProps.controlPoint));
|
|
2141
|
+
editor.movePoint = AMap.extend(editor.movePoint, clone(restProps.controlPoint));
|
|
2142
|
+
}
|
|
2143
|
+
}, [restProps.controlPoint]);
|
|
2144
|
+
useLayoutEffect(() => {
|
|
2145
|
+
const editor = getPolygonEditor();
|
|
2146
|
+
if (restProps.midControlPoint && editor) editor.midControlPoint = AMap.extend(editor.midControlPoint, clone(restProps.midControlPoint));
|
|
2147
|
+
}, [restProps.midControlPoint]);
|
|
2148
|
+
useEventListeners(getPolygonEditor, eventProps, polygonEditorEvents);
|
|
2149
|
+
return null;
|
|
2150
|
+
};
|
|
2151
|
+
// src/tool/polyline-editor/polyline-editor.ts
|
|
2152
|
+
const polylineEditorEvents = [
|
|
2153
|
+
add,
|
|
2154
|
+
end,
|
|
2155
|
+
adjust,
|
|
2156
|
+
addNode,
|
|
2157
|
+
removeNode
|
|
2158
|
+
];
|
|
2159
|
+
const PolylineEditor = ({ ref, map: _map, target, ...props }) => {
|
|
2160
|
+
const map = useMapInstance(_map);
|
|
2161
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(polylineEditorEvents));
|
|
2162
|
+
const polylineEditorRef = useRef(null);
|
|
2163
|
+
useLayoutEffect(() => {
|
|
2164
|
+
if (!map) return;
|
|
2165
|
+
polylineEditorRef.current = new AMap.PolylineEditor(map, resolveTarget(target) ?? void 0, restProps);
|
|
2166
|
+
return () => {
|
|
2167
|
+
polylineEditorRef.current?.destroy();
|
|
2168
|
+
polylineEditorRef.current = null;
|
|
2169
|
+
};
|
|
2170
|
+
}, [map]);
|
|
2171
|
+
useEffect(() => {
|
|
2172
|
+
polylineEditorRef.current?.setTarget(resolveTarget(target) ?? void 0);
|
|
2173
|
+
}, [target]);
|
|
2174
|
+
const getPolylineEditor = useCallback(() => polylineEditorRef.current, []);
|
|
2175
|
+
useImperativeHandle(ref, getPolylineEditor);
|
|
2176
|
+
useLayoutEffect(() => {
|
|
2177
|
+
const editor = getPolylineEditor();
|
|
2178
|
+
if (restProps.createOptions && editor) editor._defaultStyle = AMap.extend(editor._defaultStyle, clone(restProps.createOptions));
|
|
2179
|
+
}, [restProps.createOptions]);
|
|
2180
|
+
useLayoutEffect(() => {
|
|
2181
|
+
const editor = getPolylineEditor();
|
|
2182
|
+
if (restProps.editOptions && editor) editor._selectStyle = AMap.extend(editor._selectStyle, clone(restProps.editOptions));
|
|
2183
|
+
}, [restProps.editOptions]);
|
|
2184
|
+
useLayoutEffect(() => {
|
|
2185
|
+
const editor = getPolylineEditor();
|
|
2186
|
+
if (restProps.controlPoint && editor) editor._markerOptions = AMap.extend(editor._markerOptions, clone(restProps.controlPoint));
|
|
2187
|
+
}, [restProps.controlPoint]);
|
|
2188
|
+
useLayoutEffect(() => {
|
|
2189
|
+
const editor = getPolylineEditor();
|
|
2190
|
+
if (restProps.midControlPoint && editor) editor._middleMarkerOptions = AMap.extend(editor._middleMarkerOptions, clone(restProps.midControlPoint));
|
|
2191
|
+
}, [restProps.midControlPoint]);
|
|
2192
|
+
useEventListeners(getPolylineEditor, eventProps, polylineEditorEvents);
|
|
2193
|
+
return null;
|
|
2194
|
+
};
|
|
2195
|
+
// src/tool/ranging-tool/ranging-tool.ts
|
|
2196
|
+
const rangingToolEvents = [
|
|
2197
|
+
addNode,
|
|
2198
|
+
removeNode,
|
|
2199
|
+
end
|
|
2200
|
+
];
|
|
2201
|
+
const RangingTool = ({ ref, map: _map, ...props }) => {
|
|
2202
|
+
const map = useMapInstance(_map);
|
|
2203
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(rangingToolEvents));
|
|
2204
|
+
const rangingToolRef = useRef(null);
|
|
2205
|
+
useLayoutEffect(() => {
|
|
2206
|
+
if (!map) return;
|
|
2207
|
+
rangingToolRef.current = new AMap.RangingTool(map, restProps);
|
|
2208
|
+
return () => {
|
|
2209
|
+
rangingToolRef.current?.turnOff(true);
|
|
2210
|
+
rangingToolRef.current = null;
|
|
2211
|
+
};
|
|
2212
|
+
}, [map]);
|
|
2213
|
+
const getRangingTool = useCallback(() => rangingToolRef.current, []);
|
|
2214
|
+
useImperativeHandle(ref, getRangingTool);
|
|
2215
|
+
useLayoutEffect(() => {
|
|
2216
|
+
getRangingTool()?.setOptions(restProps);
|
|
2217
|
+
}, [restProps]);
|
|
2218
|
+
useEventListeners(getRangingTool, eventProps, rangingToolEvents);
|
|
2219
|
+
return null;
|
|
2220
|
+
};
|
|
2221
|
+
// src/tool/rectangle-editor/rectangle-editor.ts
|
|
2222
|
+
const rectangleEditorEvents = [
|
|
2223
|
+
add,
|
|
2224
|
+
end,
|
|
2225
|
+
adjust,
|
|
2226
|
+
move
|
|
2227
|
+
];
|
|
2228
|
+
const RectangleEditor = ({ ref, map: _map, target, ...props }) => {
|
|
2229
|
+
const map = useMapInstance(_map);
|
|
2230
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(rectangleEditorEvents));
|
|
2231
|
+
const rectangleEditorRef = useRef(null);
|
|
2232
|
+
useLayoutEffect(() => {
|
|
2233
|
+
if (!map) return;
|
|
2234
|
+
rectangleEditorRef.current = new AMap.RectangleEditor(map, resolveTarget(target) ?? void 0, restProps);
|
|
2235
|
+
return () => {
|
|
2236
|
+
rectangleEditorRef.current?.destroy();
|
|
2237
|
+
rectangleEditorRef.current = null;
|
|
2238
|
+
};
|
|
2239
|
+
}, [map]);
|
|
2240
|
+
useEffect(() => {
|
|
2241
|
+
rectangleEditorRef.current?.setTarget(resolveTarget(target) ?? void 0);
|
|
2242
|
+
}, [target]);
|
|
2243
|
+
const getRectangleEditor = useCallback(() => rectangleEditorRef.current, []);
|
|
2244
|
+
useImperativeHandle(ref, getRectangleEditor);
|
|
2245
|
+
useLayoutEffect(() => {
|
|
2246
|
+
const editor = getRectangleEditor();
|
|
2247
|
+
if (restProps.createOptions && editor) editor._normalRectangleStyle = AMap.extend(editor._normalRectangleStyle, clone(restProps.createOptions));
|
|
2248
|
+
}, [restProps.createOptions]);
|
|
2249
|
+
useLayoutEffect(() => {
|
|
2250
|
+
const editor = getRectangleEditor();
|
|
2251
|
+
if (restProps.editOptions && editor) editor._editStyle = AMap.extend(editor._editStyle, clone(restProps.editOptions));
|
|
2252
|
+
}, [restProps.editOptions]);
|
|
2253
|
+
useLayoutEffect(() => {
|
|
2254
|
+
const editor = getRectangleEditor();
|
|
2255
|
+
if (restProps.northEastPoint && editor) editor._opts.northEastPoint = restProps.northEastPoint;
|
|
2256
|
+
}, [restProps.northEastPoint]);
|
|
2257
|
+
useLayoutEffect(() => {
|
|
2258
|
+
const editor = getRectangleEditor();
|
|
2259
|
+
if (restProps.southWestPoint && editor) editor._opts.southWestPoint = restProps.southWestPoint;
|
|
2260
|
+
}, [restProps.southWestPoint]);
|
|
2261
|
+
useEventListeners(getRectangleEditor, eventProps, rectangleEditorEvents);
|
|
2262
|
+
return null;
|
|
2263
|
+
};
|
|
2264
|
+
export { APILoader, BezierCurve, BezierCurveEditor, Buildings as BuildingLayer, Buildings, CanvasLayer, Circle, CircleEditor, CircleMarker, ContextMenu, ControlBar, Country, CustomLayer, DistrictLayer, ElasticMarker, Ellipse, EllipseEditor, Flexible, GLCustomLayer, Geolocation, HawkEye, HeatMap, ImageLayer, IndexCluster, IndoorMap, InfoWindow, LabelMarker, LabelsLayer, LayerGroup, LoadStatus, Map$1 as Map, MapType, Mapbox, MapboxVectorTileLayer, Mark, Marker, MarkerCluster, MassMarks, MouseTool, OverlayGroup, Polygon, PolygonEditor, Polyline, PolylineEditor, Province, RangingTool, Rectangle, RectangleEditor, RoadNet, Satellite, Scale, Text, TileLayer, ToolBar, Traffic, VectorLayer, Wms as WMS, Wmts as WMTS, World, splitProps, useAPILoader, useAPIStatus, useLabelsLayer, useLazyInit, useMap, useMapInstance, useVectorLayer };
|