@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/loca.js
ADDED
|
@@ -0,0 +1,784 @@
|
|
|
1
|
+
import { a as splitProps, c as useEventListeners, o as syncProperty, r as useMapInstance, s as useLazyInit } from "./context-ChPGCKoP.js";
|
|
2
|
+
import { createContext, use, useCallback, useEffect, useImperativeHandle, useLayoutEffect, useRef, useState } from "react";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
import { clone, eventsToProps, lostContextError } from "@cn-map/gaode-shared/utils";
|
|
5
|
+
import { complete, loaded } from "@cn-map/gaode-shared/const";
|
|
6
|
+
import { patchGeoBufferSource, patchGeoJSONSource, patchLocaLayer } from "@cn-map/gaode-shared/patch";
|
|
7
|
+
// src/loca/loca/context.ts
|
|
8
|
+
const EMPTY$1 = Symbol("No Loca");
|
|
9
|
+
const LocaContext = createContext(EMPTY$1);
|
|
10
|
+
/**
|
|
11
|
+
* 获取 Loca 容器实例 hook
|
|
12
|
+
*/
|
|
13
|
+
function useLoca() {
|
|
14
|
+
const loca = use(LocaContext);
|
|
15
|
+
if (loca === EMPTY$1) throw lostContextError("`Loca.Container`");
|
|
16
|
+
return loca;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* 获取合并props的 Loca 容器实例
|
|
20
|
+
*/
|
|
21
|
+
function useLocaInstance(locaInProps) {
|
|
22
|
+
const locaInCtx = use(LocaContext);
|
|
23
|
+
return locaInProps ?? (locaInCtx === EMPTY$1 ? null : locaInCtx);
|
|
24
|
+
}
|
|
25
|
+
// src/loca/loca/loca.tsx
|
|
26
|
+
const Container = ({ ref, map: _map, ...props }) => {
|
|
27
|
+
const map = useMapInstance(_map);
|
|
28
|
+
const [loca, setLoca] = useState(null);
|
|
29
|
+
useLayoutEffect(() => {
|
|
30
|
+
if (!map) return;
|
|
31
|
+
const container = new Loca.Container({ map });
|
|
32
|
+
setLoca(container);
|
|
33
|
+
return () => {
|
|
34
|
+
if (container.map) {
|
|
35
|
+
AMap.Event.clearListeners(container.map, "firstPaint");
|
|
36
|
+
container.destroy();
|
|
37
|
+
}
|
|
38
|
+
setLoca(null);
|
|
39
|
+
};
|
|
40
|
+
}, [map]);
|
|
41
|
+
useImperativeHandle(ref, () => loca, [loca]);
|
|
42
|
+
return /* @__PURE__ */ jsx(LocaContext, {
|
|
43
|
+
value: loca,
|
|
44
|
+
children: props.children
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
// src/loca/source/data-source/context.ts
|
|
48
|
+
const EMPTY = Symbol("No DataSource");
|
|
49
|
+
const DataSourceContext = createContext(EMPTY);
|
|
50
|
+
/**
|
|
51
|
+
* 获取 Loca 数据源实例 hook
|
|
52
|
+
*/
|
|
53
|
+
function useDataSource() {
|
|
54
|
+
const context = use(DataSourceContext);
|
|
55
|
+
if (context === EMPTY) throw lostContextError("`Loca.GeoBufferSource`/`Loca.GeoJSONSource`");
|
|
56
|
+
return context;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* 获取合并props的 Loca 数据源实例
|
|
60
|
+
*/
|
|
61
|
+
function useDataSourceInstance(dataSourceInProps) {
|
|
62
|
+
const dataSourceInCtx = use(DataSourceContext);
|
|
63
|
+
return dataSourceInProps ?? (dataSourceInCtx === EMPTY ? null : dataSourceInCtx);
|
|
64
|
+
}
|
|
65
|
+
// src/loca/source/data-source/data-source.ts
|
|
66
|
+
function hasData(data) {
|
|
67
|
+
return data !== void 0;
|
|
68
|
+
}
|
|
69
|
+
function hasUrl(url) {
|
|
70
|
+
return typeof url === "string" && url.length > 0;
|
|
71
|
+
}
|
|
72
|
+
function reloadSource(source) {
|
|
73
|
+
for (const layer of source.layers) layer.ll?.destroy();
|
|
74
|
+
source.abort?.();
|
|
75
|
+
source.load();
|
|
76
|
+
}
|
|
77
|
+
function syncDataSourceAttributes(source, props, prevRef) {
|
|
78
|
+
const mode = hasData(props.data) ? "data" : hasUrl(props.url) ? "url" : "idle";
|
|
79
|
+
const activeValue = mode === "data" ? props.data : props.url;
|
|
80
|
+
if (hasData(props.data)) source.options.data = clone(props.data, true);
|
|
81
|
+
else delete source.options.data;
|
|
82
|
+
if (hasUrl(props.url)) {
|
|
83
|
+
source.options.url = props.url;
|
|
84
|
+
source.url = props.url;
|
|
85
|
+
} else {
|
|
86
|
+
delete source.options.url;
|
|
87
|
+
source.url = void 0;
|
|
88
|
+
}
|
|
89
|
+
if (mode === "idle") {
|
|
90
|
+
if (prevRef.current && prevRef.current.mode !== "idle") {
|
|
91
|
+
source.abort?.();
|
|
92
|
+
source.dataset = [];
|
|
93
|
+
for (const layer of source.layers) layer.receiveDataset?.(source.dataset);
|
|
94
|
+
}
|
|
95
|
+
} else if (!prevRef.current) {
|
|
96
|
+
if (source.status !== "loading" && source.dataset.length === 0) source.load();
|
|
97
|
+
} else if (prevRef.current.mode !== mode || prevRef.current.value !== activeValue) reloadSource(source);
|
|
98
|
+
else if (source.dataset.length === 0) {
|
|
99
|
+
if (source.status !== "loading") source.load();
|
|
100
|
+
}
|
|
101
|
+
prevRef.current = {
|
|
102
|
+
mode,
|
|
103
|
+
value: activeValue
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
function useDataSourceAttributes(source, props) {
|
|
107
|
+
const prevRef = useRef(void 0);
|
|
108
|
+
useLayoutEffect(() => {
|
|
109
|
+
syncDataSourceAttributes(source, props, prevRef);
|
|
110
|
+
}, [
|
|
111
|
+
props.data,
|
|
112
|
+
props.url,
|
|
113
|
+
source
|
|
114
|
+
]);
|
|
115
|
+
}
|
|
116
|
+
// src/loca/layer/layer/layer.ts
|
|
117
|
+
const layerEvents = [complete, loaded];
|
|
118
|
+
function useLayerAttributes(getLayer, props) {
|
|
119
|
+
patchLocaLayer();
|
|
120
|
+
const { opacity, zooms, zIndex, source, style, visible, duration, onShow, onHide } = props;
|
|
121
|
+
useLayoutEffect(() => {
|
|
122
|
+
getLayer()?.setOpacity(opacity);
|
|
123
|
+
}, [opacity]);
|
|
124
|
+
useLayoutEffect(() => {
|
|
125
|
+
getLayer()?.setZooms(clone(zooms));
|
|
126
|
+
}, [zooms]);
|
|
127
|
+
useLayoutEffect(() => {
|
|
128
|
+
getLayer()?.setzIndex(zIndex);
|
|
129
|
+
}, [zIndex]);
|
|
130
|
+
useLayoutEffect(() => {
|
|
131
|
+
const layer = getLayer();
|
|
132
|
+
if (source) layer?.setSource(source);
|
|
133
|
+
return () => {
|
|
134
|
+
layer?.source?.Mr(layer);
|
|
135
|
+
};
|
|
136
|
+
}, [source]);
|
|
137
|
+
useLayoutEffect(() => {
|
|
138
|
+
if (style !== void 0) getLayer()?.setStyle(clone(style));
|
|
139
|
+
}, [style]);
|
|
140
|
+
useLayoutEffect(() => {
|
|
141
|
+
const layer = getLayer();
|
|
142
|
+
if (visible !== void 0 && layer?.visible !== visible) {
|
|
143
|
+
if (visible) layer?.show(duration?.show, onShow);
|
|
144
|
+
else layer?.hide(duration?.hide, onHide);
|
|
145
|
+
}
|
|
146
|
+
}, [
|
|
147
|
+
visible,
|
|
148
|
+
duration,
|
|
149
|
+
onShow,
|
|
150
|
+
onHide
|
|
151
|
+
]);
|
|
152
|
+
}
|
|
153
|
+
// src/loca/layer/grid-layer/grid-layer.ts
|
|
154
|
+
const GridLayer = ({ ref, map, loca: _loca, source: _source, ...props }) => {
|
|
155
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(layerEvents));
|
|
156
|
+
const loca = useLocaInstance(_loca);
|
|
157
|
+
const source = useDataSourceInstance(_source);
|
|
158
|
+
const gridLayerRef = useRef(null);
|
|
159
|
+
const getGridLayer = useCallback(() => gridLayerRef.current, []);
|
|
160
|
+
useLayoutEffect(() => {
|
|
161
|
+
gridLayerRef.current = new Loca.GridLayer(restProps);
|
|
162
|
+
}, []);
|
|
163
|
+
useEffect(() => {
|
|
164
|
+
if (!loca) return;
|
|
165
|
+
const layer = gridLayerRef.current;
|
|
166
|
+
loca.add(layer);
|
|
167
|
+
return () => {
|
|
168
|
+
loca.remove(layer);
|
|
169
|
+
};
|
|
170
|
+
}, [loca]);
|
|
171
|
+
useEffect(() => {
|
|
172
|
+
return () => {
|
|
173
|
+
gridLayerRef.current?.destroy();
|
|
174
|
+
gridLayerRef.current = null;
|
|
175
|
+
};
|
|
176
|
+
}, []);
|
|
177
|
+
useImperativeHandle(ref, getGridLayer, []);
|
|
178
|
+
useLayerAttributes(getGridLayer, {
|
|
179
|
+
...restProps,
|
|
180
|
+
source
|
|
181
|
+
});
|
|
182
|
+
useEventListeners(getGridLayer, eventProps, layerEvents);
|
|
183
|
+
return null;
|
|
184
|
+
};
|
|
185
|
+
// src/loca/layer/heat-map-layer/heat-map-layer.ts
|
|
186
|
+
const HeatMapLayer = ({ ref, map, loca: _loca, source: _source, ...props }) => {
|
|
187
|
+
const loca = useLocaInstance(_loca);
|
|
188
|
+
const source = useDataSourceInstance(_source);
|
|
189
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(layerEvents));
|
|
190
|
+
const heatMapLayerRef = useRef(null);
|
|
191
|
+
const getHeatMapLayer = useCallback(() => heatMapLayerRef.current, []);
|
|
192
|
+
useLayoutEffect(() => {
|
|
193
|
+
heatMapLayerRef.current = new Loca.HeatMapLayer(restProps);
|
|
194
|
+
}, []);
|
|
195
|
+
useEffect(() => {
|
|
196
|
+
if (!loca) return;
|
|
197
|
+
const layer = heatMapLayerRef.current;
|
|
198
|
+
loca.add(layer);
|
|
199
|
+
return () => {
|
|
200
|
+
loca.remove(layer);
|
|
201
|
+
};
|
|
202
|
+
}, [loca]);
|
|
203
|
+
useEffect(() => {
|
|
204
|
+
return () => {
|
|
205
|
+
heatMapLayerRef.current?.destroy();
|
|
206
|
+
heatMapLayerRef.current = null;
|
|
207
|
+
};
|
|
208
|
+
}, []);
|
|
209
|
+
useImperativeHandle(ref, getHeatMapLayer, []);
|
|
210
|
+
useLayerAttributes(getHeatMapLayer, {
|
|
211
|
+
...restProps,
|
|
212
|
+
source
|
|
213
|
+
});
|
|
214
|
+
useEventListeners(getHeatMapLayer, eventProps, layerEvents);
|
|
215
|
+
return null;
|
|
216
|
+
};
|
|
217
|
+
// src/loca/layer/hexagon-layer/hexagon-layer.ts
|
|
218
|
+
const HexagonLayer = ({ ref, map, loca: _loca, source: _source, ...props }) => {
|
|
219
|
+
const loca = useLocaInstance(_loca);
|
|
220
|
+
const source = useDataSourceInstance(_source);
|
|
221
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(layerEvents));
|
|
222
|
+
const hexagonLayerRef = useRef(null);
|
|
223
|
+
const getHexagonLayer = useCallback(() => hexagonLayerRef.current, []);
|
|
224
|
+
useLayoutEffect(() => {
|
|
225
|
+
hexagonLayerRef.current = new Loca.HexagonLayer(restProps);
|
|
226
|
+
}, []);
|
|
227
|
+
useEffect(() => {
|
|
228
|
+
if (!loca) return;
|
|
229
|
+
const layer = hexagonLayerRef.current;
|
|
230
|
+
loca.add(layer);
|
|
231
|
+
return () => {
|
|
232
|
+
loca.remove(layer);
|
|
233
|
+
};
|
|
234
|
+
}, [loca]);
|
|
235
|
+
useEffect(() => {
|
|
236
|
+
return () => {
|
|
237
|
+
hexagonLayerRef.current?.destroy();
|
|
238
|
+
hexagonLayerRef.current = null;
|
|
239
|
+
};
|
|
240
|
+
}, []);
|
|
241
|
+
useImperativeHandle(ref, getHexagonLayer, []);
|
|
242
|
+
useLayerAttributes(getHexagonLayer, {
|
|
243
|
+
...restProps,
|
|
244
|
+
source
|
|
245
|
+
});
|
|
246
|
+
useEventListeners(getHexagonLayer, eventProps, layerEvents);
|
|
247
|
+
return null;
|
|
248
|
+
};
|
|
249
|
+
// src/loca/layer/icon-layer/icon-layer.ts
|
|
250
|
+
const IconLayer = ({ ref, map, loca: _loca, source: _source, ...props }) => {
|
|
251
|
+
const loca = useLocaInstance(_loca);
|
|
252
|
+
const source = useDataSourceInstance(_source);
|
|
253
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(layerEvents));
|
|
254
|
+
const iconLayerRef = useRef(null);
|
|
255
|
+
const getIconLayer = useCallback(() => iconLayerRef.current, []);
|
|
256
|
+
useLayoutEffect(() => {
|
|
257
|
+
iconLayerRef.current = new Loca.IconLayer(restProps);
|
|
258
|
+
}, []);
|
|
259
|
+
useEffect(() => {
|
|
260
|
+
if (!loca) return;
|
|
261
|
+
const layer = iconLayerRef.current;
|
|
262
|
+
loca.add(layer);
|
|
263
|
+
return () => {
|
|
264
|
+
loca.remove(layer);
|
|
265
|
+
};
|
|
266
|
+
}, [loca]);
|
|
267
|
+
useEffect(() => {
|
|
268
|
+
return () => {
|
|
269
|
+
iconLayerRef.current?.destroy();
|
|
270
|
+
iconLayerRef.current = null;
|
|
271
|
+
};
|
|
272
|
+
}, []);
|
|
273
|
+
useImperativeHandle(ref, getIconLayer, []);
|
|
274
|
+
useLayerAttributes(getIconLayer, {
|
|
275
|
+
...restProps,
|
|
276
|
+
source
|
|
277
|
+
});
|
|
278
|
+
useEventListeners(getIconLayer, eventProps, layerEvents);
|
|
279
|
+
return null;
|
|
280
|
+
};
|
|
281
|
+
// src/loca/layer/labels-layer/labels-layer.ts
|
|
282
|
+
const LabelsLayer = ({ ref, map, loca: _loca, source: _source, ...props }) => {
|
|
283
|
+
const loca = useLocaInstance(_loca);
|
|
284
|
+
const source = useDataSourceInstance(_source);
|
|
285
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(layerEvents));
|
|
286
|
+
const labelsLayerRef = useRef(null);
|
|
287
|
+
const getLabelsLayer = useCallback(() => labelsLayerRef.current, []);
|
|
288
|
+
useLayoutEffect(() => {
|
|
289
|
+
labelsLayerRef.current = new Loca.LabelsLayer(restProps);
|
|
290
|
+
}, []);
|
|
291
|
+
useEffect(() => {
|
|
292
|
+
if (!loca) return;
|
|
293
|
+
const layer = labelsLayerRef.current;
|
|
294
|
+
loca.add(layer);
|
|
295
|
+
return () => {
|
|
296
|
+
loca.remove(layer);
|
|
297
|
+
};
|
|
298
|
+
}, [loca]);
|
|
299
|
+
useEffect(() => {
|
|
300
|
+
return () => {
|
|
301
|
+
labelsLayerRef.current?.destroy();
|
|
302
|
+
labelsLayerRef.current = null;
|
|
303
|
+
};
|
|
304
|
+
}, []);
|
|
305
|
+
useImperativeHandle(ref, getLabelsLayer, []);
|
|
306
|
+
const { allowCollision, collision, ...layerRestProps } = restProps;
|
|
307
|
+
useLayoutEffect(() => {
|
|
308
|
+
if (allowCollision !== void 0) getLabelsLayer()?.setAllowCollision(allowCollision);
|
|
309
|
+
}, [allowCollision]);
|
|
310
|
+
useLayoutEffect(() => {
|
|
311
|
+
if (collision !== void 0) getLabelsLayer()?.setCollision(collision);
|
|
312
|
+
}, [collision]);
|
|
313
|
+
useLayerAttributes(getLabelsLayer, {
|
|
314
|
+
...layerRestProps,
|
|
315
|
+
source
|
|
316
|
+
});
|
|
317
|
+
useEventListeners(getLabelsLayer, eventProps, layerEvents);
|
|
318
|
+
return null;
|
|
319
|
+
};
|
|
320
|
+
// src/loca/layer/laser-layer/laser-layer.ts
|
|
321
|
+
const LaserLayer = ({ ref, map, loca: _loca, source: _source, ...props }) => {
|
|
322
|
+
const loca = useLocaInstance(_loca);
|
|
323
|
+
const source = useDataSourceInstance(_source);
|
|
324
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(layerEvents));
|
|
325
|
+
const laserLayerRef = useRef(null);
|
|
326
|
+
const getLaserLayer = useCallback(() => laserLayerRef.current, []);
|
|
327
|
+
useLayoutEffect(() => {
|
|
328
|
+
laserLayerRef.current = new Loca.LaserLayer(restProps);
|
|
329
|
+
}, []);
|
|
330
|
+
useEffect(() => {
|
|
331
|
+
if (!loca) return;
|
|
332
|
+
const layer = laserLayerRef.current;
|
|
333
|
+
loca.add(layer);
|
|
334
|
+
return () => {
|
|
335
|
+
loca.remove(layer);
|
|
336
|
+
};
|
|
337
|
+
}, [loca]);
|
|
338
|
+
useEffect(() => {
|
|
339
|
+
return () => {
|
|
340
|
+
laserLayerRef.current?.destroy();
|
|
341
|
+
laserLayerRef.current = null;
|
|
342
|
+
};
|
|
343
|
+
}, []);
|
|
344
|
+
useImperativeHandle(ref, getLaserLayer, []);
|
|
345
|
+
useLayerAttributes(getLaserLayer, {
|
|
346
|
+
...restProps,
|
|
347
|
+
source
|
|
348
|
+
});
|
|
349
|
+
useEventListeners(getLaserLayer, eventProps, layerEvents);
|
|
350
|
+
return null;
|
|
351
|
+
};
|
|
352
|
+
// src/loca/layer/line-layer/line-layer.ts
|
|
353
|
+
const LineLayer = ({ ref, map, loca: _loca, source: _source, ...props }) => {
|
|
354
|
+
const loca = useLocaInstance(_loca);
|
|
355
|
+
const source = useDataSourceInstance(_source);
|
|
356
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(layerEvents));
|
|
357
|
+
const lineLayerRef = useRef(null);
|
|
358
|
+
const getLineLayer = useCallback(() => lineLayerRef.current, []);
|
|
359
|
+
useLayoutEffect(() => {
|
|
360
|
+
lineLayerRef.current = new Loca.LineLayer(restProps);
|
|
361
|
+
}, []);
|
|
362
|
+
useEffect(() => {
|
|
363
|
+
if (!loca) return;
|
|
364
|
+
const layer = lineLayerRef.current;
|
|
365
|
+
loca.add(layer);
|
|
366
|
+
return () => {
|
|
367
|
+
loca.remove(layer);
|
|
368
|
+
};
|
|
369
|
+
}, [loca]);
|
|
370
|
+
useEffect(() => {
|
|
371
|
+
return () => {
|
|
372
|
+
lineLayerRef.current?.destroy();
|
|
373
|
+
lineLayerRef.current = null;
|
|
374
|
+
};
|
|
375
|
+
}, []);
|
|
376
|
+
useImperativeHandle(ref, getLineLayer, []);
|
|
377
|
+
useLayerAttributes(getLineLayer, {
|
|
378
|
+
...restProps,
|
|
379
|
+
source
|
|
380
|
+
});
|
|
381
|
+
useEventListeners(getLineLayer, eventProps, layerEvents);
|
|
382
|
+
return null;
|
|
383
|
+
};
|
|
384
|
+
// src/loca/layer/link-layer/link-layer.ts
|
|
385
|
+
const LinkLayer = ({ ref, map, loca: _loca, source: _source, ...props }) => {
|
|
386
|
+
const loca = useLocaInstance(_loca);
|
|
387
|
+
const source = useDataSourceInstance(_source);
|
|
388
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(layerEvents));
|
|
389
|
+
const linkLayerRef = useRef(null);
|
|
390
|
+
const getLinkLayer = useCallback(() => linkLayerRef.current, []);
|
|
391
|
+
useLayoutEffect(() => {
|
|
392
|
+
linkLayerRef.current = new Loca.LinkLayer(restProps);
|
|
393
|
+
}, []);
|
|
394
|
+
useEffect(() => {
|
|
395
|
+
if (!loca) return;
|
|
396
|
+
const layer = linkLayerRef.current;
|
|
397
|
+
loca.add(layer);
|
|
398
|
+
return () => {
|
|
399
|
+
loca.remove(layer);
|
|
400
|
+
};
|
|
401
|
+
}, [loca]);
|
|
402
|
+
useEffect(() => {
|
|
403
|
+
return () => {
|
|
404
|
+
linkLayerRef.current?.destroy();
|
|
405
|
+
linkLayerRef.current = null;
|
|
406
|
+
};
|
|
407
|
+
}, []);
|
|
408
|
+
useImperativeHandle(ref, getLinkLayer, []);
|
|
409
|
+
useLayerAttributes(getLinkLayer, {
|
|
410
|
+
...restProps,
|
|
411
|
+
source
|
|
412
|
+
});
|
|
413
|
+
useEventListeners(getLinkLayer, eventProps, layerEvents);
|
|
414
|
+
return null;
|
|
415
|
+
};
|
|
416
|
+
// src/loca/layer/point-layer/point-layer.ts
|
|
417
|
+
const PointLayer = ({ ref, map, loca: _loca, source: _source, ...props }) => {
|
|
418
|
+
const loca = useLocaInstance(_loca);
|
|
419
|
+
const source = useDataSourceInstance(_source);
|
|
420
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(layerEvents));
|
|
421
|
+
const pointLayerRef = useRef(null);
|
|
422
|
+
const getPointLayer = useCallback(() => pointLayerRef.current, []);
|
|
423
|
+
useLayoutEffect(() => {
|
|
424
|
+
pointLayerRef.current = new Loca.PointLayer(restProps);
|
|
425
|
+
}, []);
|
|
426
|
+
useEffect(() => {
|
|
427
|
+
if (!loca) return;
|
|
428
|
+
const layer = pointLayerRef.current;
|
|
429
|
+
loca.add(layer);
|
|
430
|
+
return () => {
|
|
431
|
+
loca.remove(layer);
|
|
432
|
+
};
|
|
433
|
+
}, [loca]);
|
|
434
|
+
useEffect(() => {
|
|
435
|
+
return () => {
|
|
436
|
+
pointLayerRef.current?.destroy();
|
|
437
|
+
pointLayerRef.current = null;
|
|
438
|
+
};
|
|
439
|
+
}, []);
|
|
440
|
+
useImperativeHandle(ref, getPointLayer, []);
|
|
441
|
+
useLayerAttributes(getPointLayer, {
|
|
442
|
+
...restProps,
|
|
443
|
+
source
|
|
444
|
+
});
|
|
445
|
+
useEventListeners(getPointLayer, eventProps, layerEvents);
|
|
446
|
+
return null;
|
|
447
|
+
};
|
|
448
|
+
// src/loca/layer/polygon-layer/polygon-layer.ts
|
|
449
|
+
const PolygonLayer = ({ ref, map, loca: _loca, source: _source, ...props }) => {
|
|
450
|
+
const loca = useLocaInstance(_loca);
|
|
451
|
+
const source = useDataSourceInstance(_source);
|
|
452
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(layerEvents));
|
|
453
|
+
const polygonLayerRef = useRef(null);
|
|
454
|
+
const getPolygonLayer = useCallback(() => polygonLayerRef.current, []);
|
|
455
|
+
useLayoutEffect(() => {
|
|
456
|
+
polygonLayerRef.current = new Loca.PolygonLayer(restProps);
|
|
457
|
+
}, []);
|
|
458
|
+
useEffect(() => {
|
|
459
|
+
if (!loca) return;
|
|
460
|
+
const layer = polygonLayerRef.current;
|
|
461
|
+
loca.add(layer);
|
|
462
|
+
return () => {
|
|
463
|
+
loca.remove(layer);
|
|
464
|
+
};
|
|
465
|
+
}, [loca]);
|
|
466
|
+
useEffect(() => {
|
|
467
|
+
return () => {
|
|
468
|
+
polygonLayerRef.current?.destroy();
|
|
469
|
+
polygonLayerRef.current = null;
|
|
470
|
+
};
|
|
471
|
+
}, []);
|
|
472
|
+
useImperativeHandle(ref, getPolygonLayer, []);
|
|
473
|
+
useLayerAttributes(getPolygonLayer, {
|
|
474
|
+
...restProps,
|
|
475
|
+
source
|
|
476
|
+
});
|
|
477
|
+
useEventListeners(getPolygonLayer, eventProps, layerEvents);
|
|
478
|
+
return null;
|
|
479
|
+
};
|
|
480
|
+
// src/loca/layer/prism-layer/prism-layer.ts
|
|
481
|
+
const PrismLayer = ({ ref, map, loca: _loca, source: _source, ...props }) => {
|
|
482
|
+
const loca = useLocaInstance(_loca);
|
|
483
|
+
const source = useDataSourceInstance(_source);
|
|
484
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(layerEvents));
|
|
485
|
+
const prismLayerRef = useRef(null);
|
|
486
|
+
const getPrismLayer = useCallback(() => prismLayerRef.current, []);
|
|
487
|
+
useLayoutEffect(() => {
|
|
488
|
+
prismLayerRef.current = new Loca.PrismLayer(restProps);
|
|
489
|
+
}, []);
|
|
490
|
+
useEffect(() => {
|
|
491
|
+
if (!loca) return;
|
|
492
|
+
const layer = prismLayerRef.current;
|
|
493
|
+
loca.add(layer);
|
|
494
|
+
return () => {
|
|
495
|
+
loca.remove(layer);
|
|
496
|
+
};
|
|
497
|
+
}, [loca]);
|
|
498
|
+
useEffect(() => {
|
|
499
|
+
return () => {
|
|
500
|
+
prismLayerRef.current?.destroy();
|
|
501
|
+
prismLayerRef.current = null;
|
|
502
|
+
};
|
|
503
|
+
}, []);
|
|
504
|
+
useImperativeHandle(ref, getPrismLayer, []);
|
|
505
|
+
useLayerAttributes(getPrismLayer, {
|
|
506
|
+
...restProps,
|
|
507
|
+
source
|
|
508
|
+
});
|
|
509
|
+
useEventListeners(getPrismLayer, eventProps, layerEvents);
|
|
510
|
+
return null;
|
|
511
|
+
};
|
|
512
|
+
// src/loca/layer/pulse-line-layer/pulse-line-layer.ts
|
|
513
|
+
const PulseLineLayer = ({ ref, map, loca: _loca, source: _source, ...props }) => {
|
|
514
|
+
const loca = useLocaInstance(_loca);
|
|
515
|
+
const source = useDataSourceInstance(_source);
|
|
516
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(layerEvents));
|
|
517
|
+
const pulseLineLayerRef = useRef(null);
|
|
518
|
+
const getPulseLineLayer = useCallback(() => pulseLineLayerRef.current, []);
|
|
519
|
+
useLayoutEffect(() => {
|
|
520
|
+
pulseLineLayerRef.current = new Loca.PulseLineLayer(restProps);
|
|
521
|
+
}, []);
|
|
522
|
+
useEffect(() => {
|
|
523
|
+
if (!loca) return;
|
|
524
|
+
const layer = pulseLineLayerRef.current;
|
|
525
|
+
loca.add(layer);
|
|
526
|
+
return () => {
|
|
527
|
+
loca.remove(layer);
|
|
528
|
+
};
|
|
529
|
+
}, [loca]);
|
|
530
|
+
useEffect(() => {
|
|
531
|
+
return () => {
|
|
532
|
+
pulseLineLayerRef.current?.destroy();
|
|
533
|
+
pulseLineLayerRef.current = null;
|
|
534
|
+
};
|
|
535
|
+
}, []);
|
|
536
|
+
useImperativeHandle(ref, getPulseLineLayer, []);
|
|
537
|
+
useLayerAttributes(getPulseLineLayer, {
|
|
538
|
+
...restProps,
|
|
539
|
+
source
|
|
540
|
+
});
|
|
541
|
+
useEventListeners(getPulseLineLayer, eventProps, layerEvents);
|
|
542
|
+
return null;
|
|
543
|
+
};
|
|
544
|
+
// src/loca/layer/pulse-link-layer/pulse-link-layer.ts
|
|
545
|
+
const PulseLinkLayer = ({ ref, map, loca: _loca, source: _source, ...props }) => {
|
|
546
|
+
const loca = useLocaInstance(_loca);
|
|
547
|
+
const source = useDataSourceInstance(_source);
|
|
548
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(layerEvents));
|
|
549
|
+
const pulseLinkLayerRef = useRef(null);
|
|
550
|
+
const getPulseLinkLayer = useCallback(() => pulseLinkLayerRef.current, []);
|
|
551
|
+
useLayoutEffect(() => {
|
|
552
|
+
pulseLinkLayerRef.current = new Loca.PulseLinkLayer(restProps);
|
|
553
|
+
}, []);
|
|
554
|
+
useEffect(() => {
|
|
555
|
+
if (!loca) return;
|
|
556
|
+
const layer = pulseLinkLayerRef.current;
|
|
557
|
+
loca.add(layer);
|
|
558
|
+
return () => {
|
|
559
|
+
loca.remove(layer);
|
|
560
|
+
};
|
|
561
|
+
}, [loca]);
|
|
562
|
+
useEffect(() => {
|
|
563
|
+
return () => {
|
|
564
|
+
pulseLinkLayerRef.current?.destroy();
|
|
565
|
+
pulseLinkLayerRef.current = null;
|
|
566
|
+
};
|
|
567
|
+
}, []);
|
|
568
|
+
useImperativeHandle(ref, getPulseLinkLayer, []);
|
|
569
|
+
useLayerAttributes(getPulseLinkLayer, {
|
|
570
|
+
...restProps,
|
|
571
|
+
source
|
|
572
|
+
});
|
|
573
|
+
useEventListeners(getPulseLinkLayer, eventProps, layerEvents);
|
|
574
|
+
return null;
|
|
575
|
+
};
|
|
576
|
+
// src/loca/layer/scatter-layer/scatter-layer.ts
|
|
577
|
+
const ScatterLayer = ({ ref, map, loca: _loca, source: _source, ...props }) => {
|
|
578
|
+
const loca = useLocaInstance(_loca);
|
|
579
|
+
const source = useDataSourceInstance(_source);
|
|
580
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(layerEvents));
|
|
581
|
+
const scatterLayerRef = useRef(null);
|
|
582
|
+
const getScatterLayer = useCallback(() => scatterLayerRef.current, []);
|
|
583
|
+
useLayoutEffect(() => {
|
|
584
|
+
scatterLayerRef.current = new Loca.ScatterLayer(restProps);
|
|
585
|
+
}, []);
|
|
586
|
+
useEffect(() => {
|
|
587
|
+
if (!loca) return;
|
|
588
|
+
const layer = scatterLayerRef.current;
|
|
589
|
+
loca.add(layer);
|
|
590
|
+
return () => {
|
|
591
|
+
loca.remove(layer);
|
|
592
|
+
};
|
|
593
|
+
}, [loca]);
|
|
594
|
+
useEffect(() => {
|
|
595
|
+
return () => {
|
|
596
|
+
scatterLayerRef.current?.destroy();
|
|
597
|
+
scatterLayerRef.current = null;
|
|
598
|
+
};
|
|
599
|
+
}, []);
|
|
600
|
+
useImperativeHandle(ref, getScatterLayer, []);
|
|
601
|
+
useLayerAttributes(getScatterLayer, {
|
|
602
|
+
...restProps,
|
|
603
|
+
source
|
|
604
|
+
});
|
|
605
|
+
useEventListeners(getScatterLayer, eventProps, layerEvents);
|
|
606
|
+
return null;
|
|
607
|
+
};
|
|
608
|
+
// src/loca/layer/z-marker-layer/z-marker-layer.ts
|
|
609
|
+
const ZMarkerLayer = ({ ref, map, loca: _loca, source: _source, ...props }) => {
|
|
610
|
+
const loca = useLocaInstance(_loca);
|
|
611
|
+
const source = useDataSourceInstance(_source);
|
|
612
|
+
const [eventProps, restProps] = splitProps(props, eventsToProps(layerEvents));
|
|
613
|
+
const zMarkerLayerRef = useRef(null);
|
|
614
|
+
const getZMarkerLayer = useCallback(() => zMarkerLayerRef.current, []);
|
|
615
|
+
useLayoutEffect(() => {
|
|
616
|
+
zMarkerLayerRef.current = new Loca.ZMarkerLayer(restProps);
|
|
617
|
+
}, []);
|
|
618
|
+
useEffect(() => {
|
|
619
|
+
if (!loca) return;
|
|
620
|
+
const layer = zMarkerLayerRef.current;
|
|
621
|
+
loca.add(layer);
|
|
622
|
+
return () => {
|
|
623
|
+
loca.remove(layer);
|
|
624
|
+
};
|
|
625
|
+
}, [loca]);
|
|
626
|
+
useEffect(() => {
|
|
627
|
+
return () => {
|
|
628
|
+
zMarkerLayerRef.current?.destroy();
|
|
629
|
+
zMarkerLayerRef.current = null;
|
|
630
|
+
};
|
|
631
|
+
}, []);
|
|
632
|
+
useImperativeHandle(ref, getZMarkerLayer, []);
|
|
633
|
+
useLayerAttributes(getZMarkerLayer, {
|
|
634
|
+
...restProps,
|
|
635
|
+
source
|
|
636
|
+
});
|
|
637
|
+
useEventListeners(getZMarkerLayer, eventProps, layerEvents);
|
|
638
|
+
return null;
|
|
639
|
+
};
|
|
640
|
+
// src/loca/legend/legend.ts
|
|
641
|
+
const Legend = ({ ref, loca: _loca, ...props }) => {
|
|
642
|
+
const loca = useLocaInstance(_loca);
|
|
643
|
+
const legend = useLazyInit(() => new Loca.Legend(props));
|
|
644
|
+
useLayoutEffect(() => {
|
|
645
|
+
if (!loca) return;
|
|
646
|
+
legend.addTo(loca);
|
|
647
|
+
return () => {
|
|
648
|
+
legend.remove();
|
|
649
|
+
};
|
|
650
|
+
}, [loca]);
|
|
651
|
+
useImperativeHandle(ref, () => legend, []);
|
|
652
|
+
const { style, title } = props;
|
|
653
|
+
useLayoutEffect(() => {
|
|
654
|
+
legend.setStyle({
|
|
655
|
+
style,
|
|
656
|
+
title
|
|
657
|
+
});
|
|
658
|
+
}, [style, title]);
|
|
659
|
+
return null;
|
|
660
|
+
};
|
|
661
|
+
// src/loca/light/ambient-light/ambient-light.ts
|
|
662
|
+
const AmbientLight = ({ ref, loca: _loca, ...props }) => {
|
|
663
|
+
const loca = useLocaInstance(_loca);
|
|
664
|
+
const ambientLight = useLazyInit(() => new Loca.AmbientLight(props));
|
|
665
|
+
useLayoutEffect(() => {
|
|
666
|
+
if (!loca) return;
|
|
667
|
+
loca.addLight(ambientLight);
|
|
668
|
+
return () => {
|
|
669
|
+
loca.removeLight(ambientLight);
|
|
670
|
+
};
|
|
671
|
+
}, [loca]);
|
|
672
|
+
useImperativeHandle(ref, () => ambientLight, []);
|
|
673
|
+
const { color, intensity } = props;
|
|
674
|
+
useLayoutEffect(() => {
|
|
675
|
+
syncProperty(ambientLight, "color", color);
|
|
676
|
+
}, [color]);
|
|
677
|
+
useLayoutEffect(() => {
|
|
678
|
+
syncProperty(ambientLight, "intensity", intensity);
|
|
679
|
+
}, [intensity]);
|
|
680
|
+
return null;
|
|
681
|
+
};
|
|
682
|
+
// src/loca/light/directional-light/directional-light.ts
|
|
683
|
+
const DirectionalLight = ({ ref, loca: _loca, ...props }) => {
|
|
684
|
+
const loca = useLocaInstance(_loca);
|
|
685
|
+
const directionalLight = useLazyInit(() => new Loca.DirectionalLight(props));
|
|
686
|
+
useLayoutEffect(() => {
|
|
687
|
+
if (!loca) return;
|
|
688
|
+
loca.addLight(directionalLight);
|
|
689
|
+
return () => {
|
|
690
|
+
loca.removeLight(directionalLight);
|
|
691
|
+
};
|
|
692
|
+
}, [loca]);
|
|
693
|
+
useImperativeHandle(ref, () => directionalLight, []);
|
|
694
|
+
const { color, intensity, target, position } = props;
|
|
695
|
+
useLayoutEffect(() => {
|
|
696
|
+
syncProperty(directionalLight, "color", color);
|
|
697
|
+
}, [color]);
|
|
698
|
+
useLayoutEffect(() => {
|
|
699
|
+
syncProperty(directionalLight, "intensity", intensity);
|
|
700
|
+
}, [intensity]);
|
|
701
|
+
useLayoutEffect(() => {
|
|
702
|
+
syncProperty(directionalLight, "target", target);
|
|
703
|
+
}, [target]);
|
|
704
|
+
useLayoutEffect(() => {
|
|
705
|
+
syncProperty(directionalLight, "position", position);
|
|
706
|
+
}, [position]);
|
|
707
|
+
return null;
|
|
708
|
+
};
|
|
709
|
+
// src/loca/light/point-light/point-light.ts
|
|
710
|
+
const PointLight = ({ ref, loca: _loca, ...props }) => {
|
|
711
|
+
const loca = useLocaInstance(_loca);
|
|
712
|
+
const pointLight = useLazyInit(() => new Loca.PointLight(props));
|
|
713
|
+
useLayoutEffect(() => {
|
|
714
|
+
if (!loca) return;
|
|
715
|
+
loca.addLight(pointLight);
|
|
716
|
+
return () => {
|
|
717
|
+
loca.removeLight(pointLight);
|
|
718
|
+
};
|
|
719
|
+
}, [loca]);
|
|
720
|
+
useImperativeHandle(ref, () => pointLight, []);
|
|
721
|
+
const { color, intensity, distance, position } = props;
|
|
722
|
+
useLayoutEffect(() => {
|
|
723
|
+
syncProperty(pointLight, "color", color);
|
|
724
|
+
}, [color]);
|
|
725
|
+
useLayoutEffect(() => {
|
|
726
|
+
syncProperty(pointLight, "intensity", intensity);
|
|
727
|
+
}, [intensity]);
|
|
728
|
+
useLayoutEffect(() => {
|
|
729
|
+
syncProperty(pointLight, "distance", distance);
|
|
730
|
+
}, [distance]);
|
|
731
|
+
useLayoutEffect(() => {
|
|
732
|
+
syncProperty(pointLight, "position", position);
|
|
733
|
+
}, [position]);
|
|
734
|
+
return null;
|
|
735
|
+
};
|
|
736
|
+
// src/loca/source/geo-buffer-source/geo-buffer-source.tsx
|
|
737
|
+
const GeoBufferSource = ({ ref, children, ...props }) => {
|
|
738
|
+
patchGeoBufferSource();
|
|
739
|
+
const { layer, ...restProps } = props;
|
|
740
|
+
const geoBufferSource = useLazyInit(() => new Loca.GeoBufferSource(restProps));
|
|
741
|
+
useLayoutEffect(() => {
|
|
742
|
+
if (!layer) return;
|
|
743
|
+
layer.setSource(geoBufferSource);
|
|
744
|
+
return () => {
|
|
745
|
+
geoBufferSource.Mr(layer);
|
|
746
|
+
};
|
|
747
|
+
}, [layer]);
|
|
748
|
+
useEffect(() => {
|
|
749
|
+
return () => {
|
|
750
|
+
geoBufferSource.abort();
|
|
751
|
+
};
|
|
752
|
+
}, []);
|
|
753
|
+
useImperativeHandle(ref, () => geoBufferSource, []);
|
|
754
|
+
useDataSourceAttributes(geoBufferSource, props);
|
|
755
|
+
return /* @__PURE__ */ jsx(DataSourceContext, {
|
|
756
|
+
value: geoBufferSource,
|
|
757
|
+
children
|
|
758
|
+
});
|
|
759
|
+
};
|
|
760
|
+
// src/loca/source/geo-json-source/geo-json-source.tsx
|
|
761
|
+
const GeoJSONSource = ({ ref, children, ...props }) => {
|
|
762
|
+
patchGeoJSONSource();
|
|
763
|
+
const { layer, ...restProps } = props;
|
|
764
|
+
const geoJSONSource = useLazyInit(() => new Loca.GeoJSONSource(restProps));
|
|
765
|
+
useLayoutEffect(() => {
|
|
766
|
+
if (!layer) return;
|
|
767
|
+
layer.setSource(geoJSONSource);
|
|
768
|
+
return () => {
|
|
769
|
+
geoJSONSource.Mr(layer);
|
|
770
|
+
};
|
|
771
|
+
}, [layer]);
|
|
772
|
+
useEffect(() => {
|
|
773
|
+
return () => {
|
|
774
|
+
geoJSONSource.abort();
|
|
775
|
+
};
|
|
776
|
+
}, []);
|
|
777
|
+
useImperativeHandle(ref, () => geoJSONSource, []);
|
|
778
|
+
useDataSourceAttributes(geoJSONSource, props);
|
|
779
|
+
return /* @__PURE__ */ jsx(DataSourceContext, {
|
|
780
|
+
value: geoJSONSource,
|
|
781
|
+
children
|
|
782
|
+
});
|
|
783
|
+
};
|
|
784
|
+
export { AmbientLight, DirectionalLight, GeoBufferSource, GeoJSONSource, GridLayer, HeatMapLayer, HexagonLayer, IconLayer, LabelsLayer, LaserLayer, Legend, LineLayer, LinkLayer, Container as Loca, PointLayer, PointLight, PolygonLayer, PrismLayer, PulseLineLayer, PulseLinkLayer, ScatterLayer, ZMarkerLayer, useDataSource, useLoca };
|