@superrouteca/smap-react 1.6.2 → 1.6.5
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 +4 -0
- package/README.md +18 -0
- package/dist/index.cjs +143 -69
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +29 -4
- package/dist/index.d.ts +29 -4
- package/dist/index.js +129 -56
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { CSSProperties, ReactNode } from 'react';
|
|
3
|
-
import { DataOptions, BasemapOverride, Map, GeoJSONFeature, CustomStyleName, FileInput, PointOptions, LineOptions, PolygonOptions, PopupContent, FileFormat, StyleLayer as StyleLayer$1, StyleFlavor, BasemapOverrides, LngLatLike, PopupOptions, ToolsOptions, ToolsChangeEvent, UnavailableEvent, LayerData, Slot, LayerEvent, CircleOptions, ClusterInfo, SearchToolOptions, SearchResult, ToolPosition, ToolKind, RasterLayerOptions, CustomMarkerOptions, DrawToolOptions, DrawEvent, DrawingEvent, DrawTool as DrawTool$1, HeatmapOptions, ImageOptions, ImageInput, ModelOptions, ThreeLayerOptions, MapPlanEditorOptions, PlanCredentials, Plan, PlanChangeEvent, PlanEditorError, PlanSnapshotEvent, MapPlanEditor, PlanEditorState, ArcGisLayerOptions, ReadOptions, LayerDescription, StyleSource, VectorTilesOptions, WmsLayerOptions, WmtsLayerOptions, GeoJSONFeatureCollection } from '@superrouteca/smap';
|
|
4
|
-
export { ArcGisLayerOptions, BasemapOverrides, CircleOptions, ClusterInfo, ClusterOptions, DrawEvent, DrawShape, DrawStyle, DrawToolOptions, DrawingEvent, EventLngLat, ExportOptions, FeatureAt, FitInput, FitOptions, FlyToOptions, GeoJSONFeature, GeoJSONFeatureCollection, HeatmapOptions, ImageInput, ImageOptions, InsertChoice, InsertChoices, LayerData, LayerDescription, LayerEvent, LineLook, LineOptions, LngLatLike, MapEvent, MapEventType, MapPlanEditor, MapPlanEditorOptions, MarkerOptions, ModelOptions, PinIcon, Plan, PlanChangeEvent, PlanCredentials, PlanEditOutcome, PlanEditorError, PlanEditorState, PlanJob, PlanLanguage, PlanLocation, PlanPreview, PlanResult, PlanRoute, PlanSnapshotEvent, PlanState, PlanSummary, PlanTextKey, PlanTokenAnswer, PlanVehicle, PlanViolation, PointLook, PointOptions, PolygonLook, PolygonOptions, PopupContent, PopupOptions, PricedRoute, PricedStop, RasterLayerOptions, ReadOptions, RotationAlignment, SearchResult, SearchToolOptions, Slot, StyleFlavor, StyleSource, StyleValue, ThreeLayerOptions, ToolKind, ToolLayers, ToolPosition, ToolState, ToolsChangeEvent, ToolsOptions, UnavailableEvent, UnavailableReason, VectorTilesOptions, WmsLayerOptions, WmtsLayerOptions, planTexts, popupTemplate } from '@superrouteca/smap';
|
|
3
|
+
import { DataOptions, BasemapOverride, Map, GeoJSONFeature, CustomStyleName, FileInput, PointOptions, LineOptions, PolygonOptions, PopupContent, FileFormat, StyleLayer as StyleLayer$1, StyleFlavor, BasemapOverrides, LngLatLike, PopupOptions, ToolsOptions, ToolsChangeEvent, UnavailableEvent, LayerData, Slot, LayerEvent, CircleOptions, ClusterInfo, IndoorOptions, IndoorSource, SearchToolOptions, SearchResult, ToolPosition, ToolKind, RasterLayerOptions, CustomMarkerOptions, DrawToolOptions, DrawEvent, DrawingEvent, DrawTool as DrawTool$1, HeatmapOptions, ImageOptions, ImageInput, ModelOptions, ThreeLayerOptions, MapPlanEditorOptions, PlanCredentials, Plan, PlanChangeEvent, PlanEditorError, PlanSnapshotEvent, MapPlanEditor, PlanEditorState, ArcGisLayerOptions, ReadOptions, LayerDescription, StyleSource, VectorTilesOptions, WmsLayerOptions, WmtsLayerOptions, GeoJSONFeatureCollection } from '@superrouteca/smap';
|
|
4
|
+
export { ArcGisLayerOptions, BasemapOverrides, CircleOptions, ClusterInfo, ClusterOptions, DrawEvent, DrawShape, DrawStyle, DrawToolOptions, DrawingEvent, EventLngLat, ExportOptions, FeatureAt, FitInput, FitOptions, FlyToOptions, GeoJSONFeature, GeoJSONFeatureCollection, HeatmapOptions, ImageInput, ImageOptions, IndoorLayerRef, IndoorLevel, IndoorLevelChangeEvent, IndoorOptions, IndoorSource, IndoorStyle, InsertChoice, InsertChoices, LayerData, LayerDescription, LayerEvent, LineLook, LineOptions, LngLatLike, MapEvent, MapEventType, MapPlanEditor, MapPlanEditorOptions, MarkerOptions, ModelOptions, PinIcon, Plan, PlanChangeEvent, PlanCredentials, PlanEditOutcome, PlanEditorError, PlanEditorState, PlanJob, PlanLanguage, PlanLocation, PlanPreview, PlanResult, PlanRoute, PlanSnapshotEvent, PlanState, PlanSummary, PlanTextKey, PlanTokenAnswer, PlanVehicle, PlanViolation, PointLook, PointOptions, PolygonLook, PolygonOptions, PopupContent, PopupOptions, PricedRoute, PricedStop, RasterLayerOptions, ReadOptions, RotationAlignment, SearchResult, SearchToolOptions, Slot, StyleFlavor, StyleSource, StyleValue, ThreeLayerOptions, ToolKind, ToolLayers, ToolPosition, ToolState, ToolsChangeEvent, ToolsOptions, UnavailableEvent, UnavailableReason, VectorTilesOptions, WmsLayerOptions, WmtsLayerOptions, planTexts, popupTemplate } from '@superrouteca/smap';
|
|
5
5
|
|
|
6
6
|
/** A Style Specification v8 layer object, passed through unchanged. */
|
|
7
7
|
type StyleLayerSpec = StyleLayer$1;
|
|
@@ -92,6 +92,10 @@ interface SMapProps {
|
|
|
92
92
|
* then never come); the page keeps working.
|
|
93
93
|
*/
|
|
94
94
|
onUnavailable?: (event: UnavailableEvent) => void;
|
|
95
|
+
/** (indoor layer) 'public': public indoor sites in view at zoom 16 and above. Read when the map is created. */
|
|
96
|
+
indoor?: 'public';
|
|
97
|
+
/** (indoor layer) The indoor service (default https://open.superroute.ca/v1/indoor). Read when the map is created. */
|
|
98
|
+
indoorUrl?: string;
|
|
95
99
|
/** Further options handed to the map when it is created (minZoom, maxZoom, maxBounds, hash, …). */
|
|
96
100
|
mapOptions?: Record<string, unknown>;
|
|
97
101
|
/** Called once the first style has loaded, with the map. */
|
|
@@ -179,6 +183,27 @@ declare function Polygons(props: PolygonsProps): null;
|
|
|
179
183
|
*/
|
|
180
184
|
declare function Circles(props: CirclesProps): null;
|
|
181
185
|
|
|
186
|
+
interface IndoorProps extends Omit<IndoorOptions, 'level' | 'onClick'> {
|
|
187
|
+
/** The indoor layer's id, unique on the map. */
|
|
188
|
+
id: string;
|
|
189
|
+
/** `{ site }`, `{ geojson }` or `{ url, headers }` (the Web SDK's addIndoor); a change adds the layer again. */
|
|
190
|
+
source: IndoorSource;
|
|
191
|
+
/** The level shown; a change shows that level without adding the layer again. */
|
|
192
|
+
level?: string;
|
|
193
|
+
/** A click on an obstacle (else the level's outline) of the shown level. */
|
|
194
|
+
onClick?: (feature: GeoJSONFeature, lngLat: [number, number]) => void;
|
|
195
|
+
/** The level shown changed (this layer's level control, or setIndoorLevel). */
|
|
196
|
+
onLevelChange?: (level: string) => void;
|
|
197
|
+
/** The layer's data is in (null), or could not be read (the error; the layer is then not on the map). */
|
|
198
|
+
onLoad?: (error: Error | null) => void;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* An indoor layer of the map (the Web SDK's `addIndoor`): a site of sIndoor drawn one level at a time under your
|
|
202
|
+
* layers, with a level control. Added when the map is ready and again when its source or look changes; its level
|
|
203
|
+
* follows `level`; removed on unmount. Must be inside `<SMap>`.
|
|
204
|
+
*/
|
|
205
|
+
declare function Indoor(props: IndoorProps): null;
|
|
206
|
+
|
|
182
207
|
interface ToolProps {
|
|
183
208
|
/** The tool id, unique on the map (1-64 letters, digits, '-', '_', '.'). */
|
|
184
209
|
id: string;
|
|
@@ -468,5 +493,5 @@ interface Formats {
|
|
|
468
493
|
*/
|
|
469
494
|
declare const formats: Formats;
|
|
470
495
|
|
|
471
|
-
export { ArcGisLayer, CanvasTiles, Circles, CustomMarkers, Data, DeckLayer, DrawTool, Heatmap, Layers, Lines, MapImage, Models, PlanEditor, Points, Polygons, RasterLayer, SMap, SearchTool, Source, StyleLayer, ThreeLayer, Tool, VectorTiles, WmsLayer, WmtsLayer, formats, useMapImage, usePlanEditor, useRasterUrl, useSMap };
|
|
472
|
-
export type { AddDataOptions, ArcGisLayerProps, BasemapClassOverride, CanvasTilesProps, CirclesProps, CustomMarkersProps, CustomStyle, DataFormat, DataInput, DataLayerOptions, DataProps, DeckLayerLike, DeckLayerProps, DrawToolProps, FeatureStates, HeatmapProps, InteropMethods, LayerProps, LayersProps, LinesProps, MapImageProps, ModelsProps, PlanEditorProps, PointsProps, PolygonsProps, PopupFunction, RasterLayerProps, SMapMap, SMapProps, SearchToolProps, SourceProps, StyleLayerProps, StyleLayerSpec, TapHandler, ThreeLayerProps, ToolProps, UsePlanEditorResult, VectorTilesProps, WmsLayerProps, WmtsLayerProps };
|
|
496
|
+
export { ArcGisLayer, CanvasTiles, Circles, CustomMarkers, Data, DeckLayer, DrawTool, Heatmap, Indoor, Layers, Lines, MapImage, Models, PlanEditor, Points, Polygons, RasterLayer, SMap, SearchTool, Source, StyleLayer, ThreeLayer, Tool, VectorTiles, WmsLayer, WmtsLayer, formats, useMapImage, usePlanEditor, useRasterUrl, useSMap };
|
|
497
|
+
export type { AddDataOptions, ArcGisLayerProps, BasemapClassOverride, CanvasTilesProps, CirclesProps, CustomMarkersProps, CustomStyle, DataFormat, DataInput, DataLayerOptions, DataProps, DeckLayerLike, DeckLayerProps, DrawToolProps, FeatureStates, HeatmapProps, IndoorProps, InteropMethods, LayerProps, LayersProps, LinesProps, MapImageProps, ModelsProps, PlanEditorProps, PointsProps, PolygonsProps, PopupFunction, RasterLayerProps, SMapMap, SMapProps, SearchToolProps, SourceProps, StyleLayerProps, StyleLayerSpec, TapHandler, ThreeLayerProps, ToolProps, UsePlanEditorResult, VectorTilesProps, WmsLayerProps, WmtsLayerProps };
|
package/dist/index.js
CHANGED
|
@@ -73,6 +73,8 @@ var SMap = forwardRef(function SMap2(props, ref) {
|
|
|
73
73
|
popupLoading: p.popupLoading,
|
|
74
74
|
tools: p.tools,
|
|
75
75
|
cooperativeGestures: p.cooperativeGestures,
|
|
76
|
+
...p.indoor ? { indoor: p.indoor } : {},
|
|
77
|
+
...p.indoorUrl ? { indoorUrl: p.indoorUrl } : {},
|
|
76
78
|
unavailableNotice: p.unavailableNotice
|
|
77
79
|
};
|
|
78
80
|
for (const k of Object.keys(options)) {
|
|
@@ -145,7 +147,7 @@ var SMap = forwardRef(function SMap2(props, ref) {
|
|
|
145
147
|
container.querySelectorAll(":scope > .smap-unavailable").forEach((n) => n.remove());
|
|
146
148
|
}
|
|
147
149
|
};
|
|
148
|
-
}, [props.apiKey, props.token, props.baseUrl, nodesKey, props.nearest, mapOptionsKey, hasGetToken]);
|
|
150
|
+
}, [props.apiKey, props.token, props.baseUrl, nodesKey, props.nearest, mapOptionsKey, hasGetToken, props.indoor, props.indoorUrl]);
|
|
149
151
|
const styleKey = key(props.style ?? "light");
|
|
150
152
|
useEffect(() => {
|
|
151
153
|
if (!map || applied.current.style === styleKey) {
|
|
@@ -411,8 +413,78 @@ function Circles(props) {
|
|
|
411
413
|
return useLayer("addCircles", props);
|
|
412
414
|
}
|
|
413
415
|
|
|
416
|
+
// src/indoor.tsx
|
|
417
|
+
import { useEffect as useEffect3, useRef as useRef3 } from "react";
|
|
418
|
+
function sourceKey(s) {
|
|
419
|
+
const g = s.geojson;
|
|
420
|
+
if (g && typeof g === "object") {
|
|
421
|
+
const l = g;
|
|
422
|
+
return JSON.stringify(["g", l.site, l.version, l.features?.length]);
|
|
423
|
+
}
|
|
424
|
+
return JSON.stringify(s);
|
|
425
|
+
}
|
|
426
|
+
function Indoor(props) {
|
|
427
|
+
const map = useSMap();
|
|
428
|
+
const latest = useRef3(props);
|
|
429
|
+
latest.current = props;
|
|
430
|
+
const { id, level } = props;
|
|
431
|
+
const src = sourceKey(props.source);
|
|
432
|
+
const looks = JSON.stringify({ c: props.control, s: props.style, m: props.minzoom, b: props.basemap, t: !!props.onClick });
|
|
433
|
+
const loaded = useRef3(false);
|
|
434
|
+
useEffect3(() => {
|
|
435
|
+
if (!map) {
|
|
436
|
+
return void 0;
|
|
437
|
+
}
|
|
438
|
+
const p = latest.current;
|
|
439
|
+
loaded.current = false;
|
|
440
|
+
let gone = false;
|
|
441
|
+
const onClick = p.onClick ? (f, at2) => latest.current.onClick?.(f, at2) : void 0;
|
|
442
|
+
const listener = (e) => {
|
|
443
|
+
if (e.id === id) {
|
|
444
|
+
latest.current.onLevelChange?.(e.level);
|
|
445
|
+
}
|
|
446
|
+
};
|
|
447
|
+
map.on("indoorlevelchange", listener);
|
|
448
|
+
let added;
|
|
449
|
+
try {
|
|
450
|
+
added = map.addIndoor(id, p.source, { level: p.level, control: p.control, style: p.style, minzoom: p.minzoom, basemap: p.basemap, onClick });
|
|
451
|
+
} catch (e) {
|
|
452
|
+
added = Promise.reject(e);
|
|
453
|
+
}
|
|
454
|
+
added.then(() => {
|
|
455
|
+
if (gone) {
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
loaded.current = true;
|
|
459
|
+
const want = latest.current.level;
|
|
460
|
+
if (want !== void 0 && want !== map.getIndoorLevel(id)) {
|
|
461
|
+
map.setIndoorLevel(id, want);
|
|
462
|
+
}
|
|
463
|
+
latest.current.onLoad?.(null);
|
|
464
|
+
}, (e) => {
|
|
465
|
+
if (!gone) {
|
|
466
|
+
latest.current.onLoad?.(e instanceof Error ? e : new Error(String(e)));
|
|
467
|
+
}
|
|
468
|
+
});
|
|
469
|
+
return () => {
|
|
470
|
+
gone = true;
|
|
471
|
+
map.off("indoorlevelchange", listener);
|
|
472
|
+
if (!removedMaps.has(map)) {
|
|
473
|
+
map.removeIndoor(id);
|
|
474
|
+
}
|
|
475
|
+
};
|
|
476
|
+
}, [map, id, src, looks]);
|
|
477
|
+
useEffect3(() => {
|
|
478
|
+
if (!map || !loaded.current || level === void 0 || map.getIndoorLevel(id) === level) {
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
map.setIndoorLevel(id, level);
|
|
482
|
+
}, [map, id, level]);
|
|
483
|
+
return null;
|
|
484
|
+
}
|
|
485
|
+
|
|
414
486
|
// src/tools.tsx
|
|
415
|
-
import { useEffect as
|
|
487
|
+
import { useEffect as useEffect4, useRef as useRef4, useState as useState2 } from "react";
|
|
416
488
|
import { createPortal } from "react-dom";
|
|
417
489
|
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
418
490
|
var optionsKey2 = (v) => JSON.stringify(v ?? null);
|
|
@@ -425,21 +497,21 @@ function Tool(props) {
|
|
|
425
497
|
const position = isLayer ? void 0 : props.position ?? (kind ? void 0 : "top-left");
|
|
426
498
|
const inPlace = !kind && !isLayer && position === "none";
|
|
427
499
|
const [box, setBox] = useState2(null);
|
|
428
|
-
|
|
500
|
+
useEffect4(() => {
|
|
429
501
|
if (!kind && !isLayer && !inPlace && !box) {
|
|
430
502
|
setBox(document.createElement("div"));
|
|
431
503
|
}
|
|
432
504
|
}, [kind, isLayer, inPlace, box]);
|
|
433
|
-
const inPlaceRef =
|
|
505
|
+
const inPlaceRef = useRef4(null);
|
|
434
506
|
const kindOptions = optionsKey2(props.options);
|
|
435
|
-
const latestOptions =
|
|
507
|
+
const latestOptions = useRef4(props.options);
|
|
436
508
|
latestOptions.current = props.options;
|
|
437
509
|
if (box) {
|
|
438
510
|
box.className = props.className ?? "";
|
|
439
511
|
box.removeAttribute("style");
|
|
440
512
|
Object.assign(box.style, props.style || {});
|
|
441
513
|
}
|
|
442
|
-
|
|
514
|
+
useEffect4(() => {
|
|
443
515
|
if (!map) {
|
|
444
516
|
return void 0;
|
|
445
517
|
}
|
|
@@ -472,11 +544,11 @@ function Tool(props) {
|
|
|
472
544
|
}
|
|
473
545
|
function SearchTool(props) {
|
|
474
546
|
const map = useSMap();
|
|
475
|
-
const latest =
|
|
547
|
+
const latest = useRef4(props);
|
|
476
548
|
latest.current = props;
|
|
477
549
|
const { id, search: _s, onPick: _p, ...rest } = props;
|
|
478
550
|
const looks = optionsKey2(rest);
|
|
479
|
-
|
|
551
|
+
useEffect4(() => {
|
|
480
552
|
if (!map) {
|
|
481
553
|
return void 0;
|
|
482
554
|
}
|
|
@@ -496,24 +568,24 @@ function SearchTool(props) {
|
|
|
496
568
|
}
|
|
497
569
|
|
|
498
570
|
// src/features.tsx
|
|
499
|
-
import { useEffect as
|
|
571
|
+
import { useEffect as useEffect5, useRef as useRef5, useState as useState3 } from "react";
|
|
500
572
|
import { createPortal as createPortal2 } from "react-dom";
|
|
501
573
|
import { Fragment, jsx as jsx3 } from "react/jsx-runtime";
|
|
502
574
|
function CustomMarkers(props) {
|
|
503
575
|
const map = useSMap();
|
|
504
576
|
const { id, data, render: _render, featureStates, ...rest } = props;
|
|
505
|
-
const latest =
|
|
577
|
+
const latest = useRef5(props);
|
|
506
578
|
latest.current = props;
|
|
507
579
|
const [entries, setEntries] = useState3(/* @__PURE__ */ new Map());
|
|
508
|
-
const held =
|
|
509
|
-
const shown =
|
|
580
|
+
const held = useRef5(/* @__PURE__ */ new Map());
|
|
581
|
+
const shown = useRef5(null);
|
|
510
582
|
const looks = optionsKey(rest);
|
|
511
583
|
const keyOf = (properties, feature) => {
|
|
512
584
|
const by = latest.current.idProperty;
|
|
513
585
|
const v = by ? properties[by] : feature.id;
|
|
514
586
|
return v === void 0 || v === null ? `@${JSON.stringify(feature.geometry)}` : String(v);
|
|
515
587
|
};
|
|
516
|
-
|
|
588
|
+
useEffect5(() => {
|
|
517
589
|
if (!map) {
|
|
518
590
|
return void 0;
|
|
519
591
|
}
|
|
@@ -552,7 +624,7 @@ function CustomMarkers(props) {
|
|
|
552
624
|
}
|
|
553
625
|
};
|
|
554
626
|
}, [map, id, looks]);
|
|
555
|
-
|
|
627
|
+
useEffect5(() => {
|
|
556
628
|
if (!map || shown.current === null || shown.current === data) {
|
|
557
629
|
return;
|
|
558
630
|
}
|
|
@@ -585,10 +657,10 @@ function CustomMarkers(props) {
|
|
|
585
657
|
}
|
|
586
658
|
function useNativeLayer(add, id, looks, data) {
|
|
587
659
|
const map = useSMap();
|
|
588
|
-
const shown =
|
|
589
|
-
const addRef =
|
|
660
|
+
const shown = useRef5(null);
|
|
661
|
+
const addRef = useRef5(add);
|
|
590
662
|
addRef.current = add;
|
|
591
|
-
|
|
663
|
+
useEffect5(() => {
|
|
592
664
|
if (!map) {
|
|
593
665
|
return void 0;
|
|
594
666
|
}
|
|
@@ -601,7 +673,7 @@ function useNativeLayer(add, id, looks, data) {
|
|
|
601
673
|
}
|
|
602
674
|
};
|
|
603
675
|
}, [map, id, looks]);
|
|
604
|
-
|
|
676
|
+
useEffect5(() => {
|
|
605
677
|
if (!map || data === void 0 || shown.current === null || shown.current === data) {
|
|
606
678
|
return;
|
|
607
679
|
}
|
|
@@ -610,7 +682,7 @@ function useNativeLayer(add, id, looks, data) {
|
|
|
610
682
|
}, [map, id, data]);
|
|
611
683
|
}
|
|
612
684
|
function useLatest(value) {
|
|
613
|
-
const ref =
|
|
685
|
+
const ref = useRef5(value);
|
|
614
686
|
ref.current = value;
|
|
615
687
|
return ref;
|
|
616
688
|
}
|
|
@@ -625,18 +697,18 @@ function Models(props) {
|
|
|
625
697
|
return null;
|
|
626
698
|
}
|
|
627
699
|
function CanvasTiles(props) {
|
|
628
|
-
const draw =
|
|
700
|
+
const draw = useRef5(props.draw);
|
|
629
701
|
draw.current = props.draw;
|
|
630
702
|
useNativeLayer((m) => m.addCanvasTiles(props.id, (...a) => draw.current(...a), props.options), props.id, optionsKey(props.options));
|
|
631
703
|
return null;
|
|
632
704
|
}
|
|
633
705
|
function DrawTool(props) {
|
|
634
706
|
const map = useSMap();
|
|
635
|
-
const latest =
|
|
707
|
+
const latest = useRef5(props);
|
|
636
708
|
latest.current = props;
|
|
637
709
|
const { onChange: _c, onTool: _t, onDrawing: _d, ...rest } = props;
|
|
638
710
|
const looks = optionsKey(rest) + (props.onDrawing ? "|drawing" : "");
|
|
639
|
-
|
|
711
|
+
useEffect5(() => {
|
|
640
712
|
if (!map) {
|
|
641
713
|
return void 0;
|
|
642
714
|
}
|
|
@@ -662,10 +734,10 @@ function useMapImage(id, image, options) {
|
|
|
662
734
|
const onError = useLatest(options?.onError);
|
|
663
735
|
const pixelRatio = options?.pixelRatio;
|
|
664
736
|
const sdf = options?.sdf;
|
|
665
|
-
const last =
|
|
666
|
-
const lastTarget =
|
|
737
|
+
const last = useRef5(null);
|
|
738
|
+
const lastTarget = useRef5({ map: null, id: "" });
|
|
667
739
|
lastTarget.current = { map, id };
|
|
668
|
-
|
|
740
|
+
useEffect5(() => {
|
|
669
741
|
if (!map || image === null || image === void 0) {
|
|
670
742
|
return void 0;
|
|
671
743
|
}
|
|
@@ -711,7 +783,7 @@ function useMapImage(id, image, options) {
|
|
|
711
783
|
function MapImage(props) {
|
|
712
784
|
const loaded = useMapImage(props.id, props.image, { pixelRatio: props.pixelRatio, sdf: props.sdf, onError: props.onError });
|
|
713
785
|
const onLoad = useLatest(props.onLoad);
|
|
714
|
-
|
|
786
|
+
useEffect5(() => {
|
|
715
787
|
if (loaded) {
|
|
716
788
|
onLoad.current?.();
|
|
717
789
|
}
|
|
@@ -723,7 +795,7 @@ function ThreeLayer(props) {
|
|
|
723
795
|
const latest = useLatest(props);
|
|
724
796
|
const { id, onAdd, render, onRemove, onError: _e, ...placement } = props;
|
|
725
797
|
const looks = optionsKey(placement) + (onAdd ? "a" : "") + (render ? "r" : "") + (onRemove ? "x" : "");
|
|
726
|
-
|
|
798
|
+
useEffect5(() => {
|
|
727
799
|
if (!map) {
|
|
728
800
|
return void 0;
|
|
729
801
|
}
|
|
@@ -744,7 +816,7 @@ function ThreeLayer(props) {
|
|
|
744
816
|
}
|
|
745
817
|
|
|
746
818
|
// src/plan.tsx
|
|
747
|
-
import { forwardRef as forwardRef2, useEffect as
|
|
819
|
+
import { forwardRef as forwardRef2, useEffect as useEffect6, useImperativeHandle as useImperativeHandle2, useRef as useRef6, useState as useState4 } from "react";
|
|
748
820
|
function destroyOffMap(made) {
|
|
749
821
|
made.layer.remove = () => {
|
|
750
822
|
};
|
|
@@ -779,9 +851,9 @@ function usePlanEditor(props) {
|
|
|
779
851
|
const map = useSMap();
|
|
780
852
|
const [editor, setEditor] = useState4(null);
|
|
781
853
|
const [state, setState] = useState4(EMPTY);
|
|
782
|
-
const latest =
|
|
854
|
+
const latest = useRef6(props);
|
|
783
855
|
latest.current = props;
|
|
784
|
-
const applied =
|
|
856
|
+
const applied = useRef6(null);
|
|
785
857
|
const credentialKey = "key" in props.credentials ? "key:" + props.credentials.key : "token";
|
|
786
858
|
const madeKey = key2({
|
|
787
859
|
baseUrl: props.baseUrl,
|
|
@@ -805,7 +877,7 @@ function usePlanEditor(props) {
|
|
|
805
877
|
insertWaitMinAge: props.insertWaitMinAge,
|
|
806
878
|
insertWaitBudget: props.insertWaitBudget
|
|
807
879
|
});
|
|
808
|
-
|
|
880
|
+
useEffect6(() => {
|
|
809
881
|
if (!map) {
|
|
810
882
|
return void 0;
|
|
811
883
|
}
|
|
@@ -871,7 +943,7 @@ function usePlanEditor(props) {
|
|
|
871
943
|
};
|
|
872
944
|
}, [map, credentialKey, madeKey]);
|
|
873
945
|
const incoming = planKey(props.plan);
|
|
874
|
-
|
|
946
|
+
useEffect6(() => {
|
|
875
947
|
if (!editor || !latest.current.plan) {
|
|
876
948
|
return;
|
|
877
949
|
}
|
|
@@ -883,7 +955,7 @@ function usePlanEditor(props) {
|
|
|
883
955
|
editor.setPlan(latest.current.plan).catch(() => {
|
|
884
956
|
});
|
|
885
957
|
}, [editor, incoming]);
|
|
886
|
-
|
|
958
|
+
useEffect6(() => {
|
|
887
959
|
if (editor && editor.panel && props.language) {
|
|
888
960
|
editor.panel.setLanguage(props.language);
|
|
889
961
|
}
|
|
@@ -897,7 +969,7 @@ var PlanEditor = forwardRef2(function PlanEditor2(props, ref) {
|
|
|
897
969
|
});
|
|
898
970
|
|
|
899
971
|
// src/interop.tsx
|
|
900
|
-
import { createContext as createContext2, Fragment as Fragment2, useContext as useContext2, useEffect as
|
|
972
|
+
import { createContext as createContext2, Fragment as Fragment2, useContext as useContext2, useEffect as useEffect7, useMemo, useRef as useRef7, useState as useState5 } from "react";
|
|
901
973
|
import * as sdk from "@superrouteca/smap";
|
|
902
974
|
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
903
975
|
function quietly(f) {
|
|
@@ -910,12 +982,12 @@ var SourceContext = createContext2(null);
|
|
|
910
982
|
function Source(props) {
|
|
911
983
|
const map = useSMap();
|
|
912
984
|
const { id, source, children } = props;
|
|
913
|
-
const latest =
|
|
985
|
+
const latest = useRef7(source);
|
|
914
986
|
latest.current = source;
|
|
915
|
-
const inside =
|
|
987
|
+
const inside = useRef7(/* @__PURE__ */ new Set());
|
|
916
988
|
const [shown, setShown] = useState5(null);
|
|
917
|
-
const
|
|
918
|
-
|
|
989
|
+
const sourceKey2 = optionsKey(source);
|
|
990
|
+
useEffect7(() => {
|
|
919
991
|
if (!map) {
|
|
920
992
|
return void 0;
|
|
921
993
|
}
|
|
@@ -929,7 +1001,7 @@ function Source(props) {
|
|
|
929
1001
|
inside.current.clear();
|
|
930
1002
|
quietly(() => map.removeSource(id));
|
|
931
1003
|
};
|
|
932
|
-
}, [map, id,
|
|
1004
|
+
}, [map, id, sourceKey2]);
|
|
933
1005
|
const scope = useMemo(() => ({
|
|
934
1006
|
id,
|
|
935
1007
|
register: (layerId) => {
|
|
@@ -970,11 +1042,11 @@ function StyleLayer(props) {
|
|
|
970
1042
|
const scope = useContext2(SourceContext);
|
|
971
1043
|
const { layer, before, slot, visible = true } = props;
|
|
972
1044
|
const current = effectiveLayer(layer, scope?.id, visible);
|
|
973
|
-
const latest =
|
|
1045
|
+
const latest = useRef7(current);
|
|
974
1046
|
latest.current = current;
|
|
975
|
-
const shown =
|
|
1047
|
+
const shown = useRef7(null);
|
|
976
1048
|
const structure = structureKey(current, before, slot);
|
|
977
|
-
|
|
1049
|
+
useEffect7(() => {
|
|
978
1050
|
if (!map) {
|
|
979
1051
|
return void 0;
|
|
980
1052
|
}
|
|
@@ -998,7 +1070,7 @@ function StyleLayer(props) {
|
|
|
998
1070
|
};
|
|
999
1071
|
}, [map, structure, scope]);
|
|
1000
1072
|
const looks = optionsKey(current.paint) + optionsKey(current.layout) + optionsKey(current.filter);
|
|
1001
|
-
|
|
1073
|
+
useEffect7(() => {
|
|
1002
1074
|
const s = shown.current;
|
|
1003
1075
|
if (!map || !s || s.map !== map) {
|
|
1004
1076
|
return;
|
|
@@ -1019,12 +1091,12 @@ function StyleLayer(props) {
|
|
|
1019
1091
|
}
|
|
1020
1092
|
function useAddedLayer(method, id, options, remove) {
|
|
1021
1093
|
const map = useSMap();
|
|
1022
|
-
const latest =
|
|
1094
|
+
const latest = useRef7(options);
|
|
1023
1095
|
latest.current = options;
|
|
1024
|
-
const removeLatest =
|
|
1096
|
+
const removeLatest = useRef7(remove);
|
|
1025
1097
|
removeLatest.current = remove;
|
|
1026
1098
|
const looks = optionsKey(options);
|
|
1027
|
-
|
|
1099
|
+
useEffect7(() => {
|
|
1028
1100
|
if (!map) {
|
|
1029
1101
|
return void 0;
|
|
1030
1102
|
}
|
|
@@ -1071,13 +1143,13 @@ var dataLayerIds = (id) => [id, `${id}:lines`, `${id}:areas`];
|
|
|
1071
1143
|
function Data(props) {
|
|
1072
1144
|
const map = useSMap();
|
|
1073
1145
|
const { id, data, format, lat, lng, options, slot, onTap, visible = true, popupOptions } = props;
|
|
1074
|
-
const latest =
|
|
1146
|
+
const latest = useRef7(props);
|
|
1075
1147
|
latest.current = props;
|
|
1076
|
-
const shownVisible =
|
|
1148
|
+
const shownVisible = useRef7(true);
|
|
1077
1149
|
const hasTap = !!onTap || typeof options?.onClick === "function";
|
|
1078
1150
|
const hasPopup = !!props.popup || typeof options?.popup === "function";
|
|
1079
1151
|
const looks = optionsKey(options) + optionsKey(popupOptions) + (slot ?? "") + "|" + (format ?? "") + "|" + (lat ?? "") + "|" + (lng ?? "");
|
|
1080
|
-
|
|
1152
|
+
useEffect7(() => {
|
|
1081
1153
|
if (!map) {
|
|
1082
1154
|
return void 0;
|
|
1083
1155
|
}
|
|
@@ -1120,7 +1192,7 @@ function Data(props) {
|
|
|
1120
1192
|
ids.forEach((l) => quietly(() => map.removeLayer(l)));
|
|
1121
1193
|
};
|
|
1122
1194
|
}, [map, id, data, looks, hasTap, hasPopup]);
|
|
1123
|
-
|
|
1195
|
+
useEffect7(() => {
|
|
1124
1196
|
if (!map || shownVisible.current === visible) {
|
|
1125
1197
|
return;
|
|
1126
1198
|
}
|
|
@@ -1132,10 +1204,10 @@ function Data(props) {
|
|
|
1132
1204
|
}
|
|
1133
1205
|
function Layers(props) {
|
|
1134
1206
|
const map = useSMap();
|
|
1135
|
-
const latest =
|
|
1207
|
+
const latest = useRef7(props.json);
|
|
1136
1208
|
latest.current = props.json;
|
|
1137
1209
|
const jsonKey = typeof props.json === "string" ? props.json : optionsKey(props.json);
|
|
1138
|
-
|
|
1210
|
+
useEffect7(() => {
|
|
1139
1211
|
if (!map) {
|
|
1140
1212
|
return void 0;
|
|
1141
1213
|
}
|
|
@@ -1155,10 +1227,10 @@ function Layers(props) {
|
|
|
1155
1227
|
function DeckLayer(props) {
|
|
1156
1228
|
const map = useSMap();
|
|
1157
1229
|
const { layer } = props;
|
|
1158
|
-
const latest =
|
|
1230
|
+
const latest = useRef7(layer);
|
|
1159
1231
|
latest.current = layer;
|
|
1160
|
-
const shown =
|
|
1161
|
-
|
|
1232
|
+
const shown = useRef7(null);
|
|
1233
|
+
useEffect7(() => {
|
|
1162
1234
|
if (!map) {
|
|
1163
1235
|
return void 0;
|
|
1164
1236
|
}
|
|
@@ -1171,7 +1243,7 @@ function DeckLayer(props) {
|
|
|
1171
1243
|
}
|
|
1172
1244
|
};
|
|
1173
1245
|
}, [map, layer.id]);
|
|
1174
|
-
|
|
1246
|
+
useEffect7(() => {
|
|
1175
1247
|
const s = shown.current;
|
|
1176
1248
|
if (!map || !s || s.map !== map || s.layer === layer) {
|
|
1177
1249
|
return;
|
|
@@ -1220,6 +1292,7 @@ export {
|
|
|
1220
1292
|
DeckLayer,
|
|
1221
1293
|
DrawTool,
|
|
1222
1294
|
Heatmap,
|
|
1295
|
+
Indoor,
|
|
1223
1296
|
Layers,
|
|
1224
1297
|
Lines,
|
|
1225
1298
|
MapImage,
|