@superrouteca/smap-react 1.1.2 → 1.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/README.md +51 -0
- package/dist/index.cjs +240 -32
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +82 -4
- package/dist/index.d.ts +82 -4
- package/dist/index.js +230 -26
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.1.6 — 2026-10-28
|
|
4
|
+
|
|
5
|
+
- Plan editor: `<PlanEditor>` edits a plan of routes on the map with the ready-made panel in 14 languages — drag stops
|
|
6
|
+
within and between routes, remove, insert, refine, undo and redo — and reports every new plan to `onChange`.
|
|
7
|
+
`usePlanEditor` gives the editor and its state for an interface of your own.
|
|
8
|
+
- Map tools: `<Tool layer="stops">` (or `layer={['stops', 'stop-labels']}`) makes a data layer a tool, shown and
|
|
9
|
+
hidden by the tools control like every other tool.
|
|
10
|
+
- Map tools: the tools control is the last button of the map's toolbar by default (the corner of the zoom buttons,
|
|
11
|
+
top left without one); `tools={{ control: 'top-right' }}` keeps a corner as before. Its corner is drawn above the
|
|
12
|
+
others while the panel is open.
|
|
13
|
+
|
|
14
|
+
## 1.1.5 — 2026-10-28
|
|
15
|
+
|
|
16
|
+
- Map tools: `<Tool>` puts a control or panel on the map that the map's tools control shows and hides, one by one or
|
|
17
|
+
all at once — your own content in a corner (`position`) or where you place it (`position="none"`), or a zoom,
|
|
18
|
+
locate, full screen or scale control (`kind`). A hidden tool keeps its state. `<SMap tools={{ hidden }}>` gives the
|
|
19
|
+
starting state and `onToolsChange` reports every change, so the app decides whether and where to keep it.
|
|
20
|
+
Needs `react-dom` beside `react` (any app rendering to a page already has it).
|
|
21
|
+
|
|
3
22
|
## 1.1.2 — 2026-10-27
|
|
4
23
|
|
|
5
24
|
- The version follows the shared 1.1.2 release; no change of its own.
|
package/README.md
CHANGED
|
@@ -80,6 +80,57 @@ feature)`, `visible` and `slot` (`bottom`, `roads`, `labels` or `top`: where the
|
|
|
80
80
|
layers; without one it draws on top, in the order added, as in 1.0). A layer is added when the map is ready and removed when the component unmounts; new `data`
|
|
81
81
|
replaces the data and keeps the look, new `options` draw the layer again. Higher `zIndex` draws on top.
|
|
82
82
|
|
|
83
|
+
## Map tools
|
|
84
|
+
|
|
85
|
+
Put controls, panels and data layers on the map as `<Tool>`s; the map gets a tools control (one button, the last of
|
|
86
|
+
the map's toolbar) that shows or hides each of them, with *Show all* and *Hide all*:
|
|
87
|
+
|
|
88
|
+
```jsx
|
|
89
|
+
<SMap apiKey="smk_…" tools={{ hidden: saved }} onToolsChange={(e) => save(e.hidden)}>
|
|
90
|
+
<Tool id="zoom" kind="navigation" options={{ showCompass: false }} />
|
|
91
|
+
<Tool id="fullscreen" kind="fullscreen" />
|
|
92
|
+
<Tool id="legend" label="Legend" position="bottom-left"><Legend /></Tool>
|
|
93
|
+
<Tool id="orders" label="Orders list" position="none"><OrdersList /></Tool>
|
|
94
|
+
<Tool id="stops" label="Stops" layer={['stops', 'stop-labels']} />
|
|
95
|
+
</SMap>
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
- `kind` makes a control: `navigation`, `geolocate`, `fullscreen` or `scale`. Otherwise the children are the tool,
|
|
99
|
+
drawn in a corner (`position`, default `top-left`) or where `<Tool>` is (`position="none"`).
|
|
100
|
+
- `layer` makes a data-layer tool: one or more layer ids (`<Points>`, `<Lines>`, `<Polygons>`, the map's layer calls,
|
|
101
|
+
or the basemap's). Hiding the tool hides them, showing it shows them; it renders nothing.
|
|
102
|
+
- A hidden tool stays mounted: its state is kept and it comes back as it was.
|
|
103
|
+
- `tools` is read when the map is created: `hidden` (ids hidden from the start), `control` (`'toolbar'` by default: the last
|
|
104
|
+
button of the corner holding the zoom buttons, top left without one; a corner; or `false` for none) and `labels` (`button`, `showAll`, `hideAll`). The map keeps no state: keep `onToolsChange`'s `hidden`
|
|
105
|
+
yourself. The ref's `setToolVisible`, `setToolsVisible` and `tools()` switch and read them in code.
|
|
106
|
+
- The map data credit and the sMap badge are never tools and always stay.
|
|
107
|
+
|
|
108
|
+
## Plan editor
|
|
109
|
+
|
|
110
|
+
`<PlanEditor>` edits a plan of routes on the map with the ready-made panel (see the Web SDK's *Plan editor*): drag
|
|
111
|
+
stops within and between routes, remove, insert, refine, undo and redo, each a call of the Open Platform's plan
|
|
112
|
+
editing. The ref is the editor once the map is ready.
|
|
113
|
+
|
|
114
|
+
```tsx
|
|
115
|
+
const [plan, setPlan] = useState<Plan>(initialPlan);
|
|
116
|
+
const editor = useRef<MapPlanEditor>(null);
|
|
117
|
+
|
|
118
|
+
<SMap apiKey="smk_…">
|
|
119
|
+
<PlanEditor ref={editor} credentials={{ token: getPlanToken }} plan={plan} language="de"
|
|
120
|
+
onChange={(e) => { if (!e.pending) { setPlan(e.plan!); } }} onError={(err) => report(err.code)} />
|
|
121
|
+
</SMap>
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
- `credentials`: `{ token: () => Promise<string | PlanTokenAnswer> }` (the latest function is called; your own
|
|
125
|
+
server mints the token with `POST /v1/plan/token` and may hand its answer on as it is) or `{ key: 'smk_…' }` (a map
|
|
126
|
+
key with plan editing switched on). Both are sent as `Authorization: Bearer …`.
|
|
127
|
+
- `plan`: a plan that differs from the one the editor holds replaces it; handing back the plan of `onChange` is not a
|
|
128
|
+
change.
|
|
129
|
+
- `usePlanEditor(props)` gives the editor and its state (`plan`, `result`, `busy`, `error`, `canUndo`, `canRedo`,
|
|
130
|
+
`choices`, `preview`) for an interface of your own; with `panel={false}` the map shows only the routes.
|
|
131
|
+
- Every option of `map.planEditor` is a prop (`region`, `profile`, `insertLimit`, `objective`, `colors`, `panel`,
|
|
132
|
+
`labels`, …); `onBusy`, `onSnapshot` and `onReady` report the rest.
|
|
133
|
+
|
|
83
134
|
## Basemap and custom styles
|
|
84
135
|
|
|
85
136
|
`basemap` shows, hides and recolours the basemap by class — `water`, `land`, `parks`, `roads` (and `roads.highway`,
|
package/dist/index.cjs
CHANGED
|
@@ -12,9 +12,9 @@ var __export = (target, all) => {
|
|
|
12
12
|
};
|
|
13
13
|
var __copyProps = (to, from, except, desc) => {
|
|
14
14
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
-
for (let
|
|
16
|
-
if (!__hasOwnProp.call(to,
|
|
17
|
-
__defProp(to,
|
|
15
|
+
for (let key3 of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key3) && key3 !== except)
|
|
17
|
+
__defProp(to, key3, { get: () => from[key3], enumerable: !(desc = __getOwnPropDesc(from, key3)) || desc.enumerable });
|
|
18
18
|
}
|
|
19
19
|
return to;
|
|
20
20
|
};
|
|
@@ -36,17 +36,21 @@ __export(index_exports, {
|
|
|
36
36
|
DeckLayer: () => DeckLayer,
|
|
37
37
|
Layers: () => Layers,
|
|
38
38
|
Lines: () => Lines,
|
|
39
|
+
PlanEditor: () => PlanEditor,
|
|
39
40
|
Points: () => Points,
|
|
40
41
|
Polygons: () => Polygons,
|
|
41
42
|
RasterLayer: () => RasterLayer,
|
|
42
43
|
SMap: () => SMap,
|
|
43
44
|
Source: () => Source,
|
|
44
45
|
StyleLayer: () => StyleLayer,
|
|
46
|
+
Tool: () => Tool,
|
|
45
47
|
VectorTiles: () => VectorTiles,
|
|
46
48
|
WmsLayer: () => WmsLayer,
|
|
47
49
|
WmtsLayer: () => WmtsLayer,
|
|
48
50
|
formats: () => formats2,
|
|
51
|
+
planTexts: () => import_smap2.planTexts,
|
|
49
52
|
popupTemplate: () => import_smap2.popupTemplate,
|
|
53
|
+
usePlanEditor: () => usePlanEditor,
|
|
50
54
|
useRasterUrl: () => useRasterUrl,
|
|
51
55
|
useSMap: () => useSMap
|
|
52
56
|
});
|
|
@@ -112,7 +116,8 @@ var SMap = (0, import_react.forwardRef)(function SMap2(props, ref) {
|
|
|
112
116
|
nearest: p.nearest,
|
|
113
117
|
projection: p.projection,
|
|
114
118
|
popup: p.popup,
|
|
115
|
-
popupLoading: p.popupLoading
|
|
119
|
+
popupLoading: p.popupLoading,
|
|
120
|
+
tools: p.tools
|
|
116
121
|
};
|
|
117
122
|
for (const k of Object.keys(options)) {
|
|
118
123
|
if (options[k] === void 0) {
|
|
@@ -136,6 +141,7 @@ var SMap = (0, import_react.forwardRef)(function SMap2(props, ref) {
|
|
|
136
141
|
buildings: false,
|
|
137
142
|
basemap: key(void 0)
|
|
138
143
|
};
|
|
144
|
+
created.onToolsChange((e) => latest.current.onToolsChange?.(e));
|
|
139
145
|
created.ready.then(() => {
|
|
140
146
|
ready = true;
|
|
141
147
|
if (!alive) {
|
|
@@ -323,26 +329,224 @@ function Polygons(props) {
|
|
|
323
329
|
return useLayer("addPolygons", props);
|
|
324
330
|
}
|
|
325
331
|
|
|
326
|
-
// src/
|
|
332
|
+
// src/tools.tsx
|
|
327
333
|
var import_react3 = require("react");
|
|
328
|
-
var
|
|
334
|
+
var import_react_dom = require("react-dom");
|
|
329
335
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
336
|
+
var optionsKey2 = (v) => JSON.stringify(v ?? null);
|
|
337
|
+
function Tool(props) {
|
|
338
|
+
const map = useSMap();
|
|
339
|
+
const { id, label, kind } = props;
|
|
340
|
+
const layer = props.layer;
|
|
341
|
+
const layerKey = layer === void 0 ? null : JSON.stringify(layer);
|
|
342
|
+
const isLayer = layerKey !== null;
|
|
343
|
+
const position = isLayer ? void 0 : props.position ?? (kind ? void 0 : "top-left");
|
|
344
|
+
const inPlace = !kind && !isLayer && position === "none";
|
|
345
|
+
const [box, setBox] = (0, import_react3.useState)(null);
|
|
346
|
+
(0, import_react3.useEffect)(() => {
|
|
347
|
+
if (!kind && !isLayer && !inPlace && !box) {
|
|
348
|
+
setBox(document.createElement("div"));
|
|
349
|
+
}
|
|
350
|
+
}, [kind, isLayer, inPlace, box]);
|
|
351
|
+
const inPlaceRef = (0, import_react3.useRef)(null);
|
|
352
|
+
const kindOptions = optionsKey2(props.options);
|
|
353
|
+
const latestOptions = (0, import_react3.useRef)(props.options);
|
|
354
|
+
latestOptions.current = props.options;
|
|
355
|
+
if (box) {
|
|
356
|
+
box.className = props.className ?? "";
|
|
357
|
+
box.removeAttribute("style");
|
|
358
|
+
Object.assign(box.style, props.style || {});
|
|
359
|
+
}
|
|
360
|
+
(0, import_react3.useEffect)(() => {
|
|
361
|
+
if (!map) {
|
|
362
|
+
return void 0;
|
|
363
|
+
}
|
|
364
|
+
if (layerKey !== null) {
|
|
365
|
+
map.addTool(id, { layer: JSON.parse(layerKey) }, { label });
|
|
366
|
+
return () => {
|
|
367
|
+
if (!removedMaps.has(map)) {
|
|
368
|
+
map.removeTool(id);
|
|
369
|
+
}
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
const target = kind ?? (inPlace ? inPlaceRef.current : box);
|
|
373
|
+
if (!target) {
|
|
374
|
+
return void 0;
|
|
375
|
+
}
|
|
376
|
+
map.addTool(id, target, { label, position, options: latestOptions.current });
|
|
377
|
+
return () => {
|
|
378
|
+
if (!removedMaps.has(map)) {
|
|
379
|
+
map.removeTool(id);
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
}, [map, id, label, position, kind, inPlace, kindOptions, box, layerKey]);
|
|
383
|
+
if (kind || isLayer) {
|
|
384
|
+
return null;
|
|
385
|
+
}
|
|
386
|
+
if (inPlace) {
|
|
387
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { ref: inPlaceRef, className: props.className, style: props.style, children: props.children });
|
|
388
|
+
}
|
|
389
|
+
return box ? (0, import_react_dom.createPortal)(props.children, box) : null;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
// src/plan.tsx
|
|
393
|
+
var import_react4 = require("react");
|
|
394
|
+
function destroyOffMap(made) {
|
|
395
|
+
made.layer.remove = () => {
|
|
396
|
+
};
|
|
397
|
+
try {
|
|
398
|
+
made.destroy();
|
|
399
|
+
} catch {
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
var key2 = (v) => JSON.stringify(v ?? null);
|
|
403
|
+
function planKey(plan) {
|
|
404
|
+
if (!plan) {
|
|
405
|
+
return key2(null);
|
|
406
|
+
}
|
|
407
|
+
const routes = (plan.routes || []).map((r) => ({ v: String(r.vehicle_id), s: (r.reverse ? r.stops.slice().reverse() : r.stops).map(String) })).filter((r) => r.s.length).sort((a, b) => a.v < b.v ? -1 : a.v > b.v ? 1 : 0);
|
|
408
|
+
const jobs = (plan.jobs || []).map((j) => j.id).sort();
|
|
409
|
+
return key2({ vehicles: plan.vehicles, jobs, routes, region: plan.region ?? null, profile: plan.profile ?? null, departed_at: plan.departed_at ?? null });
|
|
410
|
+
}
|
|
411
|
+
var EMPTY = {
|
|
412
|
+
plan: null,
|
|
413
|
+
result: null,
|
|
414
|
+
busy: false,
|
|
415
|
+
error: null,
|
|
416
|
+
canUndo: false,
|
|
417
|
+
canRedo: false,
|
|
418
|
+
choices: null,
|
|
419
|
+
locked: [],
|
|
420
|
+
last: null,
|
|
421
|
+
preview: null
|
|
422
|
+
};
|
|
423
|
+
function usePlanEditor(props) {
|
|
424
|
+
const map = useSMap();
|
|
425
|
+
const [editor, setEditor] = (0, import_react4.useState)(null);
|
|
426
|
+
const [state, setState] = (0, import_react4.useState)(EMPTY);
|
|
427
|
+
const latest = (0, import_react4.useRef)(props);
|
|
428
|
+
latest.current = props;
|
|
429
|
+
const applied = (0, import_react4.useRef)(null);
|
|
430
|
+
const credentialKey = "key" in props.credentials ? "key:" + props.credentials.key : "token";
|
|
431
|
+
const madeKey = key2({
|
|
432
|
+
baseUrl: props.baseUrl,
|
|
433
|
+
app: props.app,
|
|
434
|
+
region: props.region,
|
|
435
|
+
profile: props.profile,
|
|
436
|
+
snapshot: props.snapshot,
|
|
437
|
+
geometry: props.geometry,
|
|
438
|
+
insertLimit: props.insertLimit,
|
|
439
|
+
objective: props.objective,
|
|
440
|
+
id: props.id,
|
|
441
|
+
colors: props.colors,
|
|
442
|
+
preview: props.preview,
|
|
443
|
+
panel: props.panel,
|
|
444
|
+
labels: props.labels
|
|
445
|
+
});
|
|
446
|
+
(0, import_react4.useEffect)(() => {
|
|
447
|
+
if (!map) {
|
|
448
|
+
return void 0;
|
|
449
|
+
}
|
|
450
|
+
const p = latest.current;
|
|
451
|
+
const credentials = "key" in p.credentials ? { key: p.credentials.key } : { token: () => latest.current.credentials.token() };
|
|
452
|
+
const options = {
|
|
453
|
+
credentials,
|
|
454
|
+
app: p.app,
|
|
455
|
+
baseUrl: p.baseUrl,
|
|
456
|
+
fetch: p.fetch,
|
|
457
|
+
region: p.region,
|
|
458
|
+
profile: p.profile,
|
|
459
|
+
snapshot: p.snapshot,
|
|
460
|
+
geometry: p.geometry,
|
|
461
|
+
insertLimit: p.insertLimit,
|
|
462
|
+
objective: p.objective,
|
|
463
|
+
id: p.id,
|
|
464
|
+
colors: p.colors,
|
|
465
|
+
preview: p.preview,
|
|
466
|
+
language: p.language,
|
|
467
|
+
labels: p.labels,
|
|
468
|
+
panel: p.panel
|
|
469
|
+
};
|
|
470
|
+
for (const k of Object.keys(options)) {
|
|
471
|
+
if (options[k] === void 0) {
|
|
472
|
+
delete options[k];
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
const made = map.planEditor(options);
|
|
476
|
+
const refresh = () => setState(made.state());
|
|
477
|
+
made.on("change", (e) => {
|
|
478
|
+
refresh();
|
|
479
|
+
latest.current.onChange?.(e);
|
|
480
|
+
});
|
|
481
|
+
made.on("busy", (e) => {
|
|
482
|
+
refresh();
|
|
483
|
+
latest.current.onBusy?.(e.busy);
|
|
484
|
+
});
|
|
485
|
+
made.on("error", (e) => {
|
|
486
|
+
refresh();
|
|
487
|
+
latest.current.onError?.(e.error, e.kind);
|
|
488
|
+
});
|
|
489
|
+
made.on("preview", refresh);
|
|
490
|
+
made.on("snapshot", (e) => latest.current.onSnapshot?.(e));
|
|
491
|
+
applied.current = null;
|
|
492
|
+
setEditor(made);
|
|
493
|
+
latest.current.onReady?.(made);
|
|
494
|
+
return () => {
|
|
495
|
+
setEditor(null);
|
|
496
|
+
setState(EMPTY);
|
|
497
|
+
if (!removedMaps.has(map)) {
|
|
498
|
+
made.destroy();
|
|
499
|
+
} else {
|
|
500
|
+
destroyOffMap(made);
|
|
501
|
+
}
|
|
502
|
+
};
|
|
503
|
+
}, [map, credentialKey, madeKey]);
|
|
504
|
+
const incoming = planKey(props.plan);
|
|
505
|
+
(0, import_react4.useEffect)(() => {
|
|
506
|
+
if (!editor || !latest.current.plan) {
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
if (incoming === applied.current || incoming === planKey(editor.getPlan())) {
|
|
510
|
+
applied.current = incoming;
|
|
511
|
+
return;
|
|
512
|
+
}
|
|
513
|
+
applied.current = incoming;
|
|
514
|
+
editor.setPlan(latest.current.plan).catch(() => {
|
|
515
|
+
});
|
|
516
|
+
}, [editor, incoming]);
|
|
517
|
+
(0, import_react4.useEffect)(() => {
|
|
518
|
+
if (editor && editor.panel && props.language) {
|
|
519
|
+
editor.panel.setLanguage(props.language);
|
|
520
|
+
}
|
|
521
|
+
}, [editor, props.language]);
|
|
522
|
+
return { ...state, editor };
|
|
523
|
+
}
|
|
524
|
+
var PlanEditor = (0, import_react4.forwardRef)(function PlanEditor2(props, ref) {
|
|
525
|
+
const { editor } = usePlanEditor(props);
|
|
526
|
+
(0, import_react4.useImperativeHandle)(ref, () => editor, [editor]);
|
|
527
|
+
return null;
|
|
528
|
+
});
|
|
529
|
+
|
|
530
|
+
// src/interop.tsx
|
|
531
|
+
var import_react5 = require("react");
|
|
532
|
+
var sdk = __toESM(require("@superrouteca/smap"), 1);
|
|
533
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
330
534
|
function quietly(f) {
|
|
331
535
|
try {
|
|
332
536
|
f();
|
|
333
537
|
} catch {
|
|
334
538
|
}
|
|
335
539
|
}
|
|
336
|
-
var SourceContext = (0,
|
|
540
|
+
var SourceContext = (0, import_react5.createContext)(null);
|
|
337
541
|
function Source(props) {
|
|
338
542
|
const map = useSMap();
|
|
339
543
|
const { id, source, children } = props;
|
|
340
|
-
const latest = (0,
|
|
544
|
+
const latest = (0, import_react5.useRef)(source);
|
|
341
545
|
latest.current = source;
|
|
342
|
-
const inside = (0,
|
|
343
|
-
const [shown, setShown] = (0,
|
|
546
|
+
const inside = (0, import_react5.useRef)(/* @__PURE__ */ new Set());
|
|
547
|
+
const [shown, setShown] = (0, import_react5.useState)(null);
|
|
344
548
|
const sourceKey = optionsKey(source);
|
|
345
|
-
(0,
|
|
549
|
+
(0, import_react5.useEffect)(() => {
|
|
346
550
|
if (!map) {
|
|
347
551
|
return void 0;
|
|
348
552
|
}
|
|
@@ -357,7 +561,7 @@ function Source(props) {
|
|
|
357
561
|
quietly(() => map.removeSource(id));
|
|
358
562
|
};
|
|
359
563
|
}, [map, id, sourceKey]);
|
|
360
|
-
const scope = (0,
|
|
564
|
+
const scope = (0, import_react5.useMemo)(() => ({
|
|
361
565
|
id,
|
|
362
566
|
register: (layerId) => {
|
|
363
567
|
inside.current.add(layerId);
|
|
@@ -367,7 +571,7 @@ function Source(props) {
|
|
|
367
571
|
if (!map || !shown || shown.map !== map) {
|
|
368
572
|
return null;
|
|
369
573
|
}
|
|
370
|
-
return /* @__PURE__ */ (0,
|
|
574
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(SourceContext.Provider, { value: scope, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react5.Fragment, { children }, shown.generation) });
|
|
371
575
|
}
|
|
372
576
|
function effectiveLayer(layer, sourceId, visible) {
|
|
373
577
|
const out = { ...layer };
|
|
@@ -394,14 +598,14 @@ function applyDiff(prev, next, set) {
|
|
|
394
598
|
}
|
|
395
599
|
function StyleLayer(props) {
|
|
396
600
|
const map = useSMap();
|
|
397
|
-
const scope = (0,
|
|
601
|
+
const scope = (0, import_react5.useContext)(SourceContext);
|
|
398
602
|
const { layer, before, slot, visible = true } = props;
|
|
399
603
|
const current = effectiveLayer(layer, scope?.id, visible);
|
|
400
|
-
const latest = (0,
|
|
604
|
+
const latest = (0, import_react5.useRef)(current);
|
|
401
605
|
latest.current = current;
|
|
402
|
-
const shown = (0,
|
|
606
|
+
const shown = (0, import_react5.useRef)(null);
|
|
403
607
|
const structure = structureKey(current, before, slot);
|
|
404
|
-
(0,
|
|
608
|
+
(0, import_react5.useEffect)(() => {
|
|
405
609
|
if (!map) {
|
|
406
610
|
return void 0;
|
|
407
611
|
}
|
|
@@ -425,7 +629,7 @@ function StyleLayer(props) {
|
|
|
425
629
|
};
|
|
426
630
|
}, [map, structure, scope]);
|
|
427
631
|
const looks = optionsKey(current.paint) + optionsKey(current.layout) + optionsKey(current.filter);
|
|
428
|
-
(0,
|
|
632
|
+
(0, import_react5.useEffect)(() => {
|
|
429
633
|
const s = shown.current;
|
|
430
634
|
if (!map || !s || s.map !== map) {
|
|
431
635
|
return;
|
|
@@ -446,12 +650,12 @@ function StyleLayer(props) {
|
|
|
446
650
|
}
|
|
447
651
|
function useAddedLayer(method, id, options, remove) {
|
|
448
652
|
const map = useSMap();
|
|
449
|
-
const latest = (0,
|
|
653
|
+
const latest = (0, import_react5.useRef)(options);
|
|
450
654
|
latest.current = options;
|
|
451
|
-
const removeLatest = (0,
|
|
655
|
+
const removeLatest = (0, import_react5.useRef)(remove);
|
|
452
656
|
removeLatest.current = remove;
|
|
453
657
|
const looks = optionsKey(options);
|
|
454
|
-
(0,
|
|
658
|
+
(0, import_react5.useEffect)(() => {
|
|
455
659
|
if (!map) {
|
|
456
660
|
return void 0;
|
|
457
661
|
}
|
|
@@ -498,13 +702,13 @@ var dataLayerIds = (id) => [id, `${id}:lines`, `${id}:areas`];
|
|
|
498
702
|
function Data(props) {
|
|
499
703
|
const map = useSMap();
|
|
500
704
|
const { id, data, format, lat, lng, options, slot, onTap, visible = true, popupOptions } = props;
|
|
501
|
-
const latest = (0,
|
|
705
|
+
const latest = (0, import_react5.useRef)(props);
|
|
502
706
|
latest.current = props;
|
|
503
|
-
const shownVisible = (0,
|
|
707
|
+
const shownVisible = (0, import_react5.useRef)(true);
|
|
504
708
|
const hasTap = !!onTap || typeof options?.onClick === "function";
|
|
505
709
|
const hasPopup = !!props.popup || typeof options?.popup === "function";
|
|
506
710
|
const looks = optionsKey(options) + optionsKey(popupOptions) + (slot ?? "") + "|" + (format ?? "") + "|" + (lat ?? "") + "|" + (lng ?? "");
|
|
507
|
-
(0,
|
|
711
|
+
(0, import_react5.useEffect)(() => {
|
|
508
712
|
if (!map) {
|
|
509
713
|
return void 0;
|
|
510
714
|
}
|
|
@@ -547,7 +751,7 @@ function Data(props) {
|
|
|
547
751
|
ids.forEach((l) => quietly(() => map.removeLayer(l)));
|
|
548
752
|
};
|
|
549
753
|
}, [map, id, data, looks, hasTap, hasPopup]);
|
|
550
|
-
(0,
|
|
754
|
+
(0, import_react5.useEffect)(() => {
|
|
551
755
|
if (!map || shownVisible.current === visible) {
|
|
552
756
|
return;
|
|
553
757
|
}
|
|
@@ -559,10 +763,10 @@ function Data(props) {
|
|
|
559
763
|
}
|
|
560
764
|
function Layers(props) {
|
|
561
765
|
const map = useSMap();
|
|
562
|
-
const latest = (0,
|
|
766
|
+
const latest = (0, import_react5.useRef)(props.json);
|
|
563
767
|
latest.current = props.json;
|
|
564
768
|
const jsonKey = typeof props.json === "string" ? props.json : optionsKey(props.json);
|
|
565
|
-
(0,
|
|
769
|
+
(0, import_react5.useEffect)(() => {
|
|
566
770
|
if (!map) {
|
|
567
771
|
return void 0;
|
|
568
772
|
}
|
|
@@ -582,10 +786,10 @@ function Layers(props) {
|
|
|
582
786
|
function DeckLayer(props) {
|
|
583
787
|
const map = useSMap();
|
|
584
788
|
const { layer } = props;
|
|
585
|
-
const latest = (0,
|
|
789
|
+
const latest = (0, import_react5.useRef)(layer);
|
|
586
790
|
latest.current = layer;
|
|
587
|
-
const shown = (0,
|
|
588
|
-
(0,
|
|
791
|
+
const shown = (0, import_react5.useRef)(null);
|
|
792
|
+
(0, import_react5.useEffect)(() => {
|
|
589
793
|
if (!map) {
|
|
590
794
|
return void 0;
|
|
591
795
|
}
|
|
@@ -598,7 +802,7 @@ function DeckLayer(props) {
|
|
|
598
802
|
}
|
|
599
803
|
};
|
|
600
804
|
}, [map, layer.id]);
|
|
601
|
-
(0,
|
|
805
|
+
(0, import_react5.useEffect)(() => {
|
|
602
806
|
const s = shown.current;
|
|
603
807
|
if (!map || !s || s.map !== map || s.layer === layer) {
|
|
604
808
|
return;
|
|
@@ -612,7 +816,7 @@ function useRasterUrl(style, options) {
|
|
|
612
816
|
const map = useSMap();
|
|
613
817
|
const lang = options?.lang;
|
|
614
818
|
const retina = options?.retina;
|
|
615
|
-
return (0,
|
|
819
|
+
return (0, import_react5.useMemo)(() => {
|
|
616
820
|
if (!map) {
|
|
617
821
|
return null;
|
|
618
822
|
}
|
|
@@ -645,17 +849,21 @@ var import_smap2 = require("@superrouteca/smap");
|
|
|
645
849
|
DeckLayer,
|
|
646
850
|
Layers,
|
|
647
851
|
Lines,
|
|
852
|
+
PlanEditor,
|
|
648
853
|
Points,
|
|
649
854
|
Polygons,
|
|
650
855
|
RasterLayer,
|
|
651
856
|
SMap,
|
|
652
857
|
Source,
|
|
653
858
|
StyleLayer,
|
|
859
|
+
Tool,
|
|
654
860
|
VectorTiles,
|
|
655
861
|
WmsLayer,
|
|
656
862
|
WmtsLayer,
|
|
657
863
|
formats,
|
|
864
|
+
planTexts,
|
|
658
865
|
popupTemplate,
|
|
866
|
+
usePlanEditor,
|
|
659
867
|
useRasterUrl,
|
|
660
868
|
useSMap
|
|
661
869
|
});
|