isard 1.6.0 → 1.8.0
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 +70 -0
- package/dist/basemap/furniture.d.ts +20 -2
- package/dist/basemap/furniture.js +72 -3
- package/dist/basemap/furniture.js.map +1 -1
- package/dist/basemap/meshes.d.ts +21 -0
- package/dist/basemap/meshes.js +159 -0
- package/dist/basemap/meshes.js.map +1 -0
- package/dist/basemap/placed.d.ts +13 -0
- package/dist/basemap/placed.js +14 -0
- package/dist/basemap/placed.js.map +1 -0
- package/dist/basemap/trees.d.ts +4 -14
- package/dist/basemap/trees.js +12 -93
- package/dist/basemap/trees.js.map +1 -1
- package/dist/basemap/vectortiles/context.d.ts +4 -2
- package/dist/basemap/vectortiles/context.js.map +1 -1
- package/dist/basemap/vectortiles/extrusions.d.ts +1 -1
- package/dist/basemap/vectortiles/extrusions.js +7 -16
- package/dist/basemap/vectortiles/extrusions.js.map +1 -1
- package/dist/basemap/vectortiles/furniture.d.ts +19 -0
- package/dist/basemap/vectortiles/furniture.js +29 -0
- package/dist/basemap/vectortiles/furniture.js.map +1 -0
- package/dist/basemap/vectortiles/labels.js +8 -1
- package/dist/basemap/vectortiles/labels.js.map +1 -1
- package/dist/basemap/vectortiles/lamps.js +11 -76
- package/dist/basemap/vectortiles/lamps.js.map +1 -1
- package/dist/basemap/vectortiles/placed.d.ts +38 -0
- package/dist/basemap/vectortiles/placed.js +143 -0
- package/dist/basemap/vectortiles/placed.js.map +1 -0
- package/dist/basemap/vectortiles/street-wind.js +4 -6
- package/dist/basemap/vectortiles/street-wind.js.map +1 -1
- package/dist/basemap/vectortiles/trees.d.ts +2 -9
- package/dist/basemap/vectortiles/trees.js +34 -165
- package/dist/basemap/vectortiles/trees.js.map +1 -1
- package/dist/basemap/vectortiles/vectors.d.ts +4 -5
- package/dist/basemap/vectortiles/vectors.js +17 -16
- package/dist/basemap/vectortiles/vectors.js.map +1 -1
- package/dist/basemap/vectortiles.d.ts +14 -4
- package/dist/basemap/vectortiles.js +40 -12
- package/dist/basemap/vectortiles.js.map +1 -1
- package/dist/basemap/wmts.js +2 -2
- package/dist/basemap/wmts.js.map +1 -1
- package/dist/basemap.worker.js +2 -2
- package/dist/basemap.worker.js.map +18 -14
- package/dist/bind/layers.d.ts +10 -3
- package/dist/bind/layers.js +11 -4
- package/dist/bind/layers.js.map +1 -1
- package/dist/data/collada.js +3 -17
- package/dist/data/collada.js.map +1 -1
- package/dist/data/crs.js +1 -1
- package/dist/data/crs.js.map +1 -1
- package/dist/data/ifc.js +21 -22
- package/dist/data/ifc.js.map +1 -1
- package/dist/geoplateforme.d.ts +16 -4
- package/dist/geoplateforme.js +26 -4
- package/dist/geoplateforme.js.map +1 -1
- package/dist/index.d.ts +5 -4
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/isard_bg.wasm +0 -0
- package/dist/isard_core_bg.wasm +0 -0
- package/dist/isard_grid_bg.wasm +0 -0
- package/dist/isard_tess_bg.wasm +0 -0
- package/dist/layers/extrusions.js +5 -4
- package/dist/layers/extrusions.js.map +1 -1
- package/dist/layers/features.d.ts +0 -2
- package/dist/layers/features.js +5 -6
- package/dist/layers/features.js.map +1 -1
- package/dist/layers/layers.d.ts +2 -0
- package/dist/layers/layers.js +11 -0
- package/dist/layers/layers.js.map +1 -1
- package/dist/layers/panoramas.d.ts +32 -10
- package/dist/layers/panoramas.js +55 -28
- package/dist/layers/panoramas.js.map +1 -1
- package/dist/layers/photos.js +5 -6
- package/dist/layers/photos.js.map +1 -1
- package/dist/layers/trees.js +7 -7
- package/dist/layers/trees.js.map +1 -1
- package/dist/layers/vectors.d.ts +1 -0
- package/dist/layers/vectors.js +23 -8
- package/dist/layers/vectors.js.map +1 -1
- package/dist/map/frame-loop.d.ts +2 -0
- package/dist/map/frame-loop.js +3 -3
- package/dist/map/frame-loop.js.map +1 -1
- package/dist/map.js +17 -0
- package/dist/map.js.map +1 -1
- package/dist/panoramax.d.ts +19 -0
- package/dist/panoramax.js +48 -3
- package/dist/panoramax.js.map +1 -1
- package/dist/react/CustomLayer.js +5 -4
- package/dist/react/CustomLayer.js.map +1 -1
- package/dist/react/Layer.d.ts +1 -1
- package/dist/react/Layer.js +6 -5
- package/dist/react/Layer.js.map +1 -1
- package/dist/react/VectorGeometry.d.ts +18 -9
- package/dist/react/VectorGeometry.js +30 -15
- package/dist/react/VectorGeometry.js.map +1 -1
- package/dist/react/VectorTiles.d.ts +65 -0
- package/dist/react/VectorTiles.js +112 -0
- package/dist/react/VectorTiles.js.map +1 -0
- package/dist/react/context.d.ts +12 -0
- package/dist/react/context.js +40 -1
- package/dist/react/context.js.map +1 -1
- package/dist/react/index.d.ts +7 -1
- package/dist/react/index.js +7 -1
- package/dist/react/index.js.map +1 -1
- package/dist/types.d.ts +2 -0
- package/dist/types.js.map +1 -1
- package/dist/util/geo.d.ts +8 -0
- package/dist/util/geo.js +8 -0
- package/dist/util/geo.js.map +1 -1
- package/dist/util/gltf.d.ts +18 -1
- package/dist/util/gltf.js +26 -1
- package/dist/util/gltf.js.map +1 -1
- package/dist/util/roofs.d.ts +8 -0
- package/dist/util/roofs.js +16 -2
- package/dist/util/roofs.js.map +1 -1
- package/dist/util/style-floats.d.ts +33 -0
- package/dist/util/style-floats.js +34 -0
- package/dist/util/style-floats.js.map +1 -0
- package/dist/util/sun.js +1 -1
- package/dist/util/sun.js.map +1 -1
- package/dist/workers/basemap/furniture.d.ts +13 -0
- package/dist/workers/basemap/geometry.d.ts +2 -5
- package/dist/workers/basemap/labels.d.ts +5 -2
- package/dist/workers/basemap/lamps.d.ts +3 -3
- package/dist/workers/basemap/tiles.d.ts +2 -0
- package/dist/workers/basemap/trees.d.ts +3 -0
- package/dist/workers/basemap.worker.d.ts +17 -1
- package/dist/workers/basemap.worker.js +12 -1
- package/dist/workers/basemap.worker.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CustomLayer.js","sourceRoot":"","sources":["../../src/react/CustomLayer.tsx"],"names":[],"mappings":"AAAA,8FAA8F;AAE9F,OAAO,EAAkB,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAEtE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"CustomLayer.js","sourceRoot":"","sources":["../../src/react/CustomLayer.tsx"],"names":[],"mappings":"AAAA,8FAA8F;AAE9F,OAAO,EAAkB,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAEtE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AASnD,iHAAiH;AACjH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,EAAE,KAAK,EAAE,KAAK,GAAG,CAAC,EAAoB,EAAa,EAAE;IAC/E,MAAM,OAAO,GAAG,UAAU,CAAC,UAAU,CAAC,CAAC;IACvC,MAAM,YAAY,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IACnC,MAAM,MAAM,GAAG,MAAM,CAAc,SAAS,CAAC,CAAC;IAC9C,MAAM,IAAI,GAAG,OAAO,EAAE,CAAC;IAEvB,sHAAsH;IACtH,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,OAAO;YAAE,OAAO;QAErB,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;QAEjD,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC;QACxB,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,EAAE,YAAY,CAAC,OAAO,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;QAE5D,OAAO,GAAG,EAAE;YACV,MAAM,CAAC,OAAO,GAAG,SAAS,CAAC;YAC3B,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAC7B,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC;gBAAE,MAAM,CAAC,MAAM,EAAE,CAAC;QACpD,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;IAE3B,2EAA2E;IAC3E,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,OAAO,IAAI,MAAM,CAAC,OAAO;YAAE,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,GAAG,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;IACrG,CAAC,EAAE,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC;IAErB,OAAO,IAAI,CAAC;AACd,CAAC,CAAC","sourcesContent":["/** `<CustomLayer>`: your WebGL code or a three.js scene among the layers of the components */\n\nimport { type ReactNode, useContext, useEffect, useRef } from 'react';\nimport type { CustomLayerInterface, Layer as LayerHandle } from '../layers/layers.ts';\nimport { MapContext, useRank } from './context.ts';\n\nexport interface CustomLayerProps {\n /** Your WebGL code: `onAdd`, `render`, `onRemove` (see `map.addCustomLayer`); another object makes it anew */\n layer: CustomLayerInterface;\n /** Its place among the layers of the components (as `<Layer order>`) */\n order?: number;\n}\n\n/** Your WebGL code or a three.js scene drawn in the map's frame and depth, among the layers of the components */\nexport const CustomLayer = ({ layer, order = 0 }: CustomLayerProps): ReactNode => {\n const binding = useContext(MapContext);\n const initialOrder = useRef(order);\n const handle = useRef<LayerHandle>(undefined);\n const rank = useRank();\n\n // Added once the map is there, in the declared order; removed when unmounted, made anew when the layer object changes\n useEffect(() => {\n if (!binding) return;\n\n const custom = binding.map.addCustomLayer(layer);\n\n handle.current = custom;\n binding.order.place(custom, initialOrder.current, { rank });\n\n return () => {\n handle.current = undefined;\n binding.order.remove(custom);\n if (binding.map.hasLayer(custom)) custom.remove();\n };\n }, [binding, layer, rank]);\n\n // A new `order`: moved to its new place among the layers of the components\n useEffect(() => {\n if (binding && handle.current) binding.order.place(handle.current, order, { old: handle.current });\n }, [binding, order]);\n\n return null;\n};\n"]}
|
package/dist/react/Layer.d.ts
CHANGED
|
@@ -29,7 +29,7 @@ export type LayerType = LayerSpec['type'];
|
|
|
29
29
|
export type LayerProps<P = Record<string, unknown>, T extends LayerType = LayerType> = Extract<BoundLayerSpec<P>, {
|
|
30
30
|
type: T;
|
|
31
31
|
}> & {
|
|
32
|
-
/** Its place among the layers of the components: from the bottom up, the same order
|
|
32
|
+
/** Its place among the layers of the components: from the bottom up, the same order as declared (default 0) */
|
|
33
33
|
order?: number;
|
|
34
34
|
/** The layer, once created and each time it is made anew */
|
|
35
35
|
onLayer?: (layer: LayerHandles<P>[T]) => void;
|
package/dist/react/Layer.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* declared order */
|
|
3
3
|
import { forwardRef, useContext, useEffect, useImperativeHandle, useRef, useState, } from 'react';
|
|
4
4
|
import { addBoundLayer, applyLayerChange, layerChange, rebuildBoundLayer, } from "../bind/layers.js";
|
|
5
|
-
import { MapContext, SwipeContext } from "./context.js";
|
|
5
|
+
import { MapContext, SwipeContext, useRank } from "./context.js";
|
|
6
6
|
const LayerComponent = forwardRef(function Layer(props, ref) {
|
|
7
7
|
const binding = useContext(MapContext);
|
|
8
8
|
const swipe = useContext(SwipeContext);
|
|
@@ -11,6 +11,7 @@ const LayerComponent = forwardRef(function Layer(props, ref) {
|
|
|
11
11
|
const mounted = useRef(undefined);
|
|
12
12
|
const latest = useRef({ spec, order, onLayer });
|
|
13
13
|
const [layer, setLayer] = useState();
|
|
14
|
+
const rank = useRank();
|
|
14
15
|
latest.current = { spec, order, onLayer };
|
|
15
16
|
useImperativeHandle(ref, () => layer, [layer]);
|
|
16
17
|
// Added once the map is there, removed when unmounted (or when the map goes)
|
|
@@ -19,7 +20,7 @@ const LayerComponent = forwardRef(function Layer(props, ref) {
|
|
|
19
20
|
return;
|
|
20
21
|
const { spec, order, onLayer } = latest.current;
|
|
21
22
|
const created = addBoundLayer(binding.map, spec);
|
|
22
|
-
binding.order.place(created, order);
|
|
23
|
+
binding.order.place(created, order, { rank });
|
|
23
24
|
mounted.current = { layer: created, spec, order };
|
|
24
25
|
swipe?.set(created);
|
|
25
26
|
setLayer(created);
|
|
@@ -34,7 +35,7 @@ const LayerComponent = forwardRef(function Layer(props, ref) {
|
|
|
34
35
|
if (binding.map.hasLayer(current.layer))
|
|
35
36
|
current.layer.remove();
|
|
36
37
|
};
|
|
37
|
-
}, [binding, swipe]);
|
|
38
|
+
}, [binding, swipe, rank]);
|
|
38
39
|
// Each render: what changed sent, or the layer made anew in its place
|
|
39
40
|
useEffect(() => {
|
|
40
41
|
const current = mounted.current;
|
|
@@ -45,7 +46,7 @@ const LayerComponent = forwardRef(function Layer(props, ref) {
|
|
|
45
46
|
if (change?.rebuild) {
|
|
46
47
|
const old = current.layer;
|
|
47
48
|
const fresh = rebuildBoundLayer(binding.map, old, spec);
|
|
48
|
-
binding.order.place(fresh, order, old);
|
|
49
|
+
binding.order.place(fresh, order, { old });
|
|
49
50
|
swipe?.unset(old);
|
|
50
51
|
swipe?.set(fresh);
|
|
51
52
|
current.layer = fresh;
|
|
@@ -58,7 +59,7 @@ const LayerComponent = forwardRef(function Layer(props, ref) {
|
|
|
58
59
|
applyLayerChange(current.layer, spec, change);
|
|
59
60
|
if (current.order !== order) {
|
|
60
61
|
current.order = order;
|
|
61
|
-
binding.order.place(current.layer, order, current.layer);
|
|
62
|
+
binding.order.place(current.layer, order, { old: current.layer });
|
|
62
63
|
}
|
|
63
64
|
});
|
|
64
65
|
return null;
|
package/dist/react/Layer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Layer.js","sourceRoot":"","sources":["../../src/react/Layer.tsx"],"names":[],"mappings":"AAAA;oBACoB;AAEpB,OAAO,EACL,UAAU,EAGV,UAAU,EACV,SAAS,EACT,mBAAmB,EACnB,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAC;AAC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ts, in its\n * declared order */\n\nimport {\n forwardRef,\n type ReactNode,\n type Ref,\n useContext,\n useEffect,\n useImperativeHandle,\n useRef,\n useState,\n} from 'react';\nimport {\n addBoundLayer,\n applyLayerChange,\n type BoundLayerSpec,\n layerChange,\n rebuildBoundLayer,\n} from '../bind/layers.ts';\nimport type { ExtrusionLayer } from '../layers/extrusions.ts';\nimport type { CircleLayer, FillLayer, LineLayer } from '../layers/features.ts';\nimport type { FlowLayer } from '../layers/flow.ts';\nimport type {\n GroundLayer,\n Layer as LayerHandle,\n ModelLayer,\n NetworkLayer,\n RasterLayer,\n Tiles3dLayer,\n} from '../layers/layers.ts';\nimport type { PointCloudLayer } from '../layers/pointclouds.ts';\nimport type { SymbolLayer } from '../layers/symbols.ts';\nimport type { LayerSpec } from '../map.ts';\nimport { MapContext, SwipeContext, useRank } from './context.ts';\n\n/** The handle of a layer by its type */\nexport interface LayerHandles<P = Record<string, unknown>> {\n lines: LineLayer<P>;\n circles: CircleLayer<P>;\n fills: FillLayer<P>;\n symbols: SymbolLayer<P>;\n extrusions: ExtrusionLayer<P>;\n raster: RasterLayer;\n ground: GroundLayer;\n network: NetworkLayer;\n tiles3d: Tiles3dLayer;\n pointcloud: PointCloudLayer;\n models: ModelLayer;\n trees: ModelLayer;\n flow: FlowLayer;\n}\n\nexport type LayerType = LayerSpec['type'];\n\nexport type LayerProps<P = Record<string, unknown>, T extends LayerType = LayerType> = Extract<\n BoundLayerSpec<P>,\n { type: T }\n> & {\n /** Its place among the layers of the components: from the bottom up, the same order as declared (default 0) */\n order?: number;\n /** The layer, once created and each time it is made anew */\n onLayer?: (layer: LayerHandles<P>[T]) => void;\n ref?: Ref<LayerHandles<P>[T] | undefined>;\n};\n\ninterface Mounted {\n layer: LayerHandle;\n spec: BoundLayerSpec;\n order: number;\n}\n\nconst LayerComponent = forwardRef<LayerHandle | undefined, Omit<LayerProps, 'ref'>>(function Layer(props, ref) {\n const binding = useContext(MapContext);\n const swipe = useContext(SwipeContext);\n const { order = 0, onLayer, ...rest } = props;\n const spec = rest as BoundLayerSpec;\n const mounted = useRef<Mounted>(undefined);\n const latest = useRef({ spec, order, onLayer });\n const [layer, setLayer] = useState<LayerHandle>();\n const rank = useRank();\n\n latest.current = { spec, order, onLayer };\n useImperativeHandle(ref, () => layer, [layer]);\n\n // Added once the map is there, removed when unmounted (or when the map goes)\n useEffect(() => {\n if (!binding) return;\n\n const { spec, order, onLayer } = latest.current;\n const created = addBoundLayer(binding.map, spec);\n\n binding.order.place(created, order, { rank });\n mounted.current = { layer: created, spec, order };\n swipe?.set(created);\n setLayer(created);\n onLayer?.(created as never);\n\n return () => {\n const current = mounted.current;\n\n mounted.current = undefined;\n if (!current) return;\n binding.order.remove(current.layer);\n swipe?.unset(current.layer);\n if (binding.map.hasLayer(current.layer)) current.layer.remove();\n };\n }, [binding, swipe, rank]);\n\n // Each render: what changed sent, or the layer made anew in its place\n useEffect(() => {\n const current = mounted.current;\n\n if (!binding || !current) return;\n\n const change = layerChange(current.spec, spec);\n\n current.spec = spec;\n if (change?.rebuild) {\n const old = current.layer;\n const fresh = rebuildBoundLayer(binding.map, old, spec);\n\n binding.order.place(fresh, order, { old });\n swipe?.unset(old);\n swipe?.set(fresh);\n current.layer = fresh;\n current.order = order;\n setLayer(fresh);\n latest.current.onLayer?.(fresh as never);\n\n return;\n }\n\n if (change) applyLayerChange(current.layer, spec, change);\n if (current.order !== order) {\n current.order = order;\n binding.order.place(current.layer, order, { old: current.layer });\n }\n });\n\n return null;\n});\n\n/**\n * A layer: the options of its `add…` method with its `type` (`map.add`), and `values` for the layers colored by\n * values. A change of data, style, filter, values or instances updates it; a change of what is set at creation (its\n * URL, grid, nodes…) makes it anew, in its place. Data, functions and arrays are compared by identity: keep them in a\n * memo or a state. The ref and `onLayer` give its handle, typed by its `type`; the properties of its features are\n * inferred from its data or its style functions (`<Layer<Building> …>` to name them)\n */\nexport const Layer = LayerComponent as <P = Record<string, unknown>, T extends LayerType = LayerType>(\n props: LayerProps<P, T>,\n) => ReactNode;\n"]}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
/** `<
|
|
2
|
-
* layers of the components */
|
|
1
|
+
/** `<Geometry>`: the fills, lines and buildings of the vector tiles around drawn as geometry (`VectorTiles.vectors`),
|
|
2
|
+
* among the layers of the components; `<VectorGeometry>`, the same with tiles of its own */
|
|
3
3
|
import { type ReactNode, type Ref } from 'react';
|
|
4
4
|
import type { Style, StyleLayer } from '../basemap/vectorstyle.ts';
|
|
5
5
|
import type { VectorLayer, VectorSublayer } from '../layers/vectors.ts';
|
|
6
|
-
import type { RoofMode } from '../
|
|
7
|
-
export interface
|
|
8
|
-
/** A style URL or object (default OpenFreeMap's Positron); another one makes the layer anew */
|
|
9
|
-
style?: string | Style;
|
|
6
|
+
import type { RoofMode } from '../util/roofs.ts';
|
|
7
|
+
export interface GeometryProps {
|
|
10
8
|
/** The style layers drawn (default all its fills and lines); another function makes the layer anew, so keep it in a
|
|
11
9
|
* memo or at the module's level */
|
|
12
10
|
layers?: (layer: StyleLayer) => boolean;
|
|
@@ -29,12 +27,23 @@ export interface VectorGeometryProps {
|
|
|
29
27
|
onLayer?: (layer: VectorLayer) => void;
|
|
30
28
|
ref?: Ref<VectorLayer | undefined>;
|
|
31
29
|
}
|
|
30
|
+
export interface VectorGeometryProps extends GeometryProps {
|
|
31
|
+
/** A style URL or object (default OpenFreeMap's Positron); another one makes the layer anew */
|
|
32
|
+
style?: string | Style;
|
|
33
|
+
}
|
|
32
34
|
/** Paint properties by style layer id */
|
|
33
35
|
type Paint = Record<string, Record<string, unknown>>;
|
|
34
36
|
/**
|
|
35
|
-
* The fills and
|
|
36
|
-
* sharp at any zoom and pitch, restyled by `paint` without cutting the tiles again,
|
|
37
|
-
* (`map.pickFeature`). The ref and `onLayer` give its handle (`VectorLayer`: `layers`, `featureAt`,
|
|
37
|
+
* The fills, lines and buildings of the vector tiles around (`<VectorTiles>`) drawn as geometry on the globe and the
|
|
38
|
+
* relief (`VectorTiles.vectors`): sharp at any zoom and pitch, restyled by `paint` without cutting the tiles again,
|
|
39
|
+
* picked by feature (`map.pickFeature`). The ref and `onLayer` give its handle (`VectorLayer`: `layers`, `featureAt`,
|
|
40
|
+
* `ready`)
|
|
41
|
+
*/
|
|
42
|
+
export declare const Geometry: (props: GeometryProps) => ReactNode;
|
|
43
|
+
/**
|
|
44
|
+
* The fills and lines of a MapLibre style drawn as geometry, with tiles of its own: a `<Geometry>` in a
|
|
45
|
+
* `<VectorTiles>` of its `style`. Beside its trees, labels or lamps, a `<VectorTiles>` with each of them as children
|
|
46
|
+
* shares one set of tiles
|
|
38
47
|
*/
|
|
39
48
|
export declare const VectorGeometry: (props: VectorGeometryProps) => ReactNode;
|
|
40
49
|
export {};
|
|
@@ -1,32 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/** `<Geometry>`: the fills, lines and buildings of the vector tiles around drawn as geometry (`VectorTiles.vectors`),
|
|
3
|
+
* among the layers of the components; `<VectorGeometry>`, the same with tiles of its own */
|
|
3
4
|
import { forwardRef, useContext, useEffect, useImperativeHandle, useRef, useState, } from 'react';
|
|
4
|
-
import { MapContext, SwipeContext } from "./context.js";
|
|
5
|
+
import { MapContext, SwipeContext, useRank, VectorTilesContext } from "./context.js";
|
|
6
|
+
import { VectorTiles } from "./VectorTiles.js";
|
|
5
7
|
/** The paint properties of `next` that differ from those of `sent`, as `[layer, name, value]` */
|
|
6
8
|
const changed = (sent, next) => Object.entries(next ?? {}).flatMap(([layer, properties]) => Object.entries(properties)
|
|
7
9
|
.filter(([name, value]) => JSON.stringify(sent?.[layer]?.[name]) !== JSON.stringify(value))
|
|
8
10
|
.map(([name, value]) => [layer, name, value]));
|
|
9
|
-
const
|
|
11
|
+
const GeometryComponent = forwardRef(function Geometry({ layers, streets, roofs, facades = false, paint, visible = true, order = 0, onLayer }, ref) {
|
|
10
12
|
const binding = useContext(MapContext);
|
|
13
|
+
const tiles = useContext(VectorTilesContext);
|
|
11
14
|
const swipe = useContext(SwipeContext);
|
|
12
15
|
const latest = useRef({ order, onLayer });
|
|
13
16
|
/** The paint properties sent to the current layer */
|
|
14
17
|
const sent = useRef(undefined);
|
|
15
18
|
const [layer, setLayer] = useState();
|
|
19
|
+
const rank = useRank();
|
|
16
20
|
latest.current = { order, onLayer };
|
|
17
21
|
useImperativeHandle(ref, () => layer, [layer]);
|
|
18
|
-
// The
|
|
19
|
-
//
|
|
22
|
+
// The geometry layer created once the tiles are there, in the declared order; made anew when the layers kept, the
|
|
23
|
+
// streets or the roofs change; removed when unmounted
|
|
20
24
|
useEffect(() => {
|
|
21
|
-
if (!binding)
|
|
25
|
+
if (!binding || !tiles)
|
|
22
26
|
return;
|
|
23
|
-
const tiles = binding.map.vectorTiles(style === undefined ? {} : { style });
|
|
24
27
|
const created = tiles.vectors({
|
|
25
28
|
...(layers && { layers }),
|
|
26
29
|
...(streets && { streets }),
|
|
27
30
|
...(roofs && { roofs }),
|
|
28
31
|
});
|
|
29
|
-
binding.order.place(created, latest.current.order);
|
|
32
|
+
binding.order.place(created, latest.current.order, { rank });
|
|
30
33
|
swipe?.set(created);
|
|
31
34
|
sent.current = undefined;
|
|
32
35
|
setLayer(created);
|
|
@@ -34,10 +37,12 @@ const VectorGeometryComponent = forwardRef(function VectorGeometry({ style, laye
|
|
|
34
37
|
return () => {
|
|
35
38
|
binding.order.remove(created);
|
|
36
39
|
swipe?.unset(created);
|
|
37
|
-
tiles
|
|
40
|
+
// Gone already with its tiles, or with the map
|
|
41
|
+
if (binding.map.hasLayer(created))
|
|
42
|
+
created.remove();
|
|
38
43
|
setLayer(undefined);
|
|
39
44
|
};
|
|
40
|
-
}, [binding, swipe,
|
|
45
|
+
}, [binding, swipe, tiles, layers, streets, roofs, rank]);
|
|
41
46
|
// The paint properties changed since the last ones sent (all of them to a layer made anew), those of a function
|
|
42
47
|
// once the style is loaded; a later render or layer drops the wait
|
|
43
48
|
useEffect(() => {
|
|
@@ -77,14 +82,24 @@ const VectorGeometryComponent = forwardRef(function VectorGeometry({ style, laye
|
|
|
77
82
|
// A new `order`: moved to its new place among the layers of the components
|
|
78
83
|
useEffect(() => {
|
|
79
84
|
if (binding && layer)
|
|
80
|
-
binding.order.place(layer, order, layer);
|
|
85
|
+
binding.order.place(layer, order, { old: layer });
|
|
81
86
|
}, [binding, layer, order]);
|
|
82
87
|
return null;
|
|
83
88
|
});
|
|
84
89
|
/**
|
|
85
|
-
* The fills and
|
|
86
|
-
* sharp at any zoom and pitch, restyled by `paint` without cutting the tiles again,
|
|
87
|
-
* (`map.pickFeature`). The ref and `onLayer` give its handle (`VectorLayer`: `layers`, `featureAt`,
|
|
90
|
+
* The fills, lines and buildings of the vector tiles around (`<VectorTiles>`) drawn as geometry on the globe and the
|
|
91
|
+
* relief (`VectorTiles.vectors`): sharp at any zoom and pitch, restyled by `paint` without cutting the tiles again,
|
|
92
|
+
* picked by feature (`map.pickFeature`). The ref and `onLayer` give its handle (`VectorLayer`: `layers`, `featureAt`,
|
|
93
|
+
* `ready`)
|
|
94
|
+
*/
|
|
95
|
+
export const Geometry = GeometryComponent;
|
|
96
|
+
const VectorGeometryComponent = forwardRef(function VectorGeometry({ style, ...props }, ref) {
|
|
97
|
+
return (_jsx(VectorTiles, { ...(style === undefined ? {} : { style }), children: _jsx(GeometryComponent, { ref: ref, ...props }) }));
|
|
98
|
+
});
|
|
99
|
+
/**
|
|
100
|
+
* The fills and lines of a MapLibre style drawn as geometry, with tiles of its own: a `<Geometry>` in a
|
|
101
|
+
* `<VectorTiles>` of its `style`. Beside its trees, labels or lamps, a `<VectorTiles>` with each of them as children
|
|
102
|
+
* shares one set of tiles
|
|
88
103
|
*/
|
|
89
104
|
export const VectorGeometry = VectorGeometryComponent;
|
|
90
105
|
//# sourceMappingURL=VectorGeometry.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VectorGeometry.js","sourceRoot":"","sources":["../../src/react/Vector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V,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC;QACpB,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;IAEnB,kCAAkC;IAClC,SAAS,CAAC,GAAG,EAAE;QACb,KAAK,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC;IAC7B,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC;IAErB,kBAAkB;IAClB,SAAS,CAAC,GAAG,EAAE;QACb,KAAK,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC;IAC7B,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC;IAErB,2EAA2E;IAC3E,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,OAAO,IAAI,KAAK;YAAE,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IACjE,CAAC,EAAE,CAAC,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;IAE5B,OAAO,IAAI,CAAC;AACd,CAAC,CACF,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,uBAAoE,CAAC","sourcesContent":["/** `<VectorGeometry>`: the fills and lines of a MapLibre style drawn as geometry (`vectorTiles().vectors()`), among the\n * layers of the components */\n\nimport {\n forwardRef,\n type ReactNode,\n type Ref,\n useContext,\n useEffect,\n useImperativeHandle,\n useRef,\n useState,\n} from 'react';\nimport type { Style, StyleLayer } from '../basemap/vectorstyle.ts';\nimport type { VectorLayer, VectorSublayer } from '../layers/vectors.ts';\nimport type { RoofMode } from '../workers/basemap/geometry.ts';\nimport { MapContext, SwipeContext } from './context.ts';\n\nexport interface VectorGeometryProps {\n /** A style URL or object (default OpenFreeMap's Positron); another one makes the layer anew */\n style?: string | Style;\n /** The style layers drawn (default all its fills and lines); another function makes the layer anew, so keep it in a\n * memo or at the module's level */\n layers?: (layer: StyleLayer) => boolean;\n /** The line layers that glow at night (default those whose id names a road); another function makes the layer anew,\n * as `layers` */\n streets?: (layer: StyleLayer) => boolean;\n /** The buildings' roofs (as `vectors({ roofs })`: `'data'` by default); another one makes the layer anew */\n roofs?: RoofMode;\n /** The buildings' walls show their windows (default false: `setFacades`, the tiles not cut again) */\n facades?: boolean;\n /** Paint properties over the style's (`setPaintProperty`), by style layer id, or by style layer drawn once the style\n * is loaded (a function of its id, kind, source layer): compared by value, only those changed sent; one taken out\n * keeps its last value */\n paint?: Paint | ((layer: VectorSublayer) => Record<string, unknown> | undefined);\n /** Shown (default true) */\n visible?: boolean;\n /** Its place among the layers of the components (as `<Layer order>`) */\n order?: number;\n /** The layer, once created and each time it is made anew */\n onLayer?: (layer: VectorLayer) => void;\n ref?: Ref<VectorLayer | undefined>;\n}\n\n/** Paint properties by style layer id */\ntype Paint = Record<string, Record<string, unknown>>;\n\n/** The paint properties of `next` that differ from those of `sent`, as `[layer, name, value]` */\nconst changed = (sent: Paint | undefined, next: Paint | undefined): [layer: string, name: string, value: unknown][] =>\n Object.entries(next ?? {}).flatMap(([layer, properties]) =>\n Object.entries(properties)\n .filter(([name, value]) => JSON.stringify(sent?.[layer]?.[name]) !== JSON.stringify(value))\n .map(([name, value]): [string, string, unknown] => [layer, name, value]),\n );\n\nconst VectorGeometryComponent = forwardRef<VectorLayer | undefined, Omit<VectorGeometryProps, 'ref'>>(\n function VectorGeometry(\n { style, layers, streets, roofs, facades = false, paint, visible = true, order = 0, onLayer },\n ref,\n ) {\n const binding = useContext(MapContext);\n const swipe = useContext(SwipeContext);\n const latest = useRef({ order, onLayer });\n /** The paint properties sent to the current layer */\n const sent = useRef<Paint>(undefined);\n const [layer, setLayer] = useState<VectorLayer>();\n\n latest.current = { order, onLayer };\n useImperativeHandle(ref, () => layer, [layer]);\n\n // The tiles and their geometry layer created once the map is there, in the declared order; made anew when the\n // style, the layers kept, the streets or the roofs change; the tiles (and their layer) destroyed when unmounted\n useEffect(() => {\n if (!binding) return;\n\n const tiles = binding.map.vectorTiles(style === undefined ? {} : { style });\n const created = tiles.vectors({\n ...(layers && { layers }),\n ...(streets && { streets }),\n ...(roofs && { roofs }),\n });\n\n binding.order.place(created, latest.current.order);\n swipe?.set(created);\n sent.current = undefined;\n setLayer(created);\n latest.current.onLayer?.(created);\n\n return () => {\n binding.order.remove(created);\n swipe?.unset(created);\n tiles.destroy();\n setLayer(undefined);\n };\n }, [binding, swipe, style, layers, streets, roofs]);\n\n // The paint properties changed since the last ones sent (all of them to a layer made anew), those of a function\n // once the style is loaded; a later render or layer drops the wait\n useEffect(() => {\n if (!layer) return;\n\n const apply = (next: Paint | undefined) => {\n changed(sent.current, next).forEach(([id, name, value]) => {\n layer.setPaintProperty(id, name, value);\n });\n sent.current = next;\n };\n\n if (typeof paint !== 'function') {\n apply(paint);\n\n return;\n }\n\n const wait = { live: true };\n\n layer.ready.then(\n () => {\n if (!wait.live) return;\n apply(\n Object.fromEntries(\n layer.layers.flatMap((l) => {\n const properties = paint(l);\n\n return properties ? [[l.id, properties]] : [];\n }),\n ),\n );\n },\n () => undefined,\n );\n\n return () => {\n wait.live = false;\n };\n }, [layer, paint]);\n\n // The walls' windows shown or not\n useEffect(() => {\n layer?.setFacades(facades);\n }, [layer, facades]);\n\n // Shown or hidden\n useEffect(() => {\n layer?.setVisible(visible);\n }, [layer, visible]);\n\n // A new `order`: moved to its new place among the layers of the components\n useEffect(() => {\n if (binding && layer) binding.order.place(layer, order, layer);\n }, [binding, layer, order]);\n\n return null;\n },\n);\n\n/**\n * The fills and lines of a MapLibre style drawn as geometry on the globe and the relief (`vectorTiles().vectors()`):\n * sharp at any zoom and pitch, restyled by `paint` without cutting the tiles again, picked by feature\n * (`map.pickFeature`). The ref and `onLayer` give its handle (`VectorLayer`: `layers`, `featureAt`, `ready`)\n */\nexport const VectorGeometry = VectorGeometryComponent as (props: VectorGeometryProps) => ReactNode;\n"]}
|
|
1
|
+
{"version":3,"file":"VectorGeometry.js","source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AAE,GAAG,KAAM,KAAK,GAAI,GAC9B,CACf,CAAC;AACJ,CAAC,CACF,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,uBAAoE,CAAC","sourcesContent":["/** `<Geometry>`: the fills, lines and buildings of the vector tiles around drawn as geometry (`VectorTiles.vectors`),\n * among the layers of the components; `<VectorGeometry>`, the same with tiles of its own */\n\nimport {\n forwardRef,\n type ReactNode,\n type Ref,\n useContext,\n useEffect,\n useImperativeHandle,\n useRef,\n useState,\n} from 'react';\nimport type { Style, StyleLayer } from '../basemap/vectorstyle.ts';\nimport type { VectorLayer, VectorSublayer } from '../layers/vectors.ts';\nimport type { RoofMode } from '../util/roofs.ts';\nimport { MapContext, SwipeContext, useRank, VectorTilesContext } from './context.ts';\nimport { VectorTiles } from './VectorTiles.tsx';\n\nexport interface GeometryProps {\n /** The style layers drawn (default all its fills and lines); another function makes the layer anew, so keep it in a\n * memo or at the module's level */\n layers?: (layer: StyleLayer) => boolean;\n /** The line layers that glow at night (default those whose id names a road); another function makes the layer anew,\n * as `layers` */\n streets?: (layer: StyleLayer) => boolean;\n /** The buildings' roofs (as `vectors({ roofs })`: `'data'` by default); another one makes the layer anew */\n roofs?: RoofMode;\n /** The buildings' walls show their windows (default false: `setFacades`, the tiles not cut again) */\n facades?: boolean;\n /** Paint properties over the style's (`setPaintProperty`), by style layer id, or by style layer drawn once the style\n * is loaded (a function of its id, kind, source layer): compared by value, only those changed sent; one taken out\n * keeps its last value */\n paint?: Paint | ((layer: VectorSublayer) => Record<string, unknown> | undefined);\n /** Shown (default true) */\n visible?: boolean;\n /** Its place among the layers of the components (as `<Layer order>`) */\n order?: number;\n /** The layer, once created and each time it is made anew */\n onLayer?: (layer: VectorLayer) => void;\n ref?: Ref<VectorLayer | undefined>;\n}\n\nexport interface VectorGeometryProps extends GeometryProps {\n /** A style URL or object (default OpenFreeMap's Positron); another one makes the layer anew */\n style?: string | Style;\n}\n\n/** Paint properties by style layer id */\ntype Paint = Record<string, Record<string, unknown>>;\n\n/** The paint properties of `next` that differ from those of `sent`, as `[layer, name, value]` */\nconst changed = (sent: Paint | undefined, next: Paint | undefined): [layer: string, name: string, value: unknown][] =>\n Object.entries(next ?? {}).flatMap(([layer, properties]) =>\n Object.entries(properties)\n .filter(([name, value]) => JSON.stringify(sent?.[layer]?.[name]) !== JSON.stringify(value))\n .map(([name, value]): [string, string, unknown] => [layer, name, value]),\n );\n\nconst GeometryComponent = forwardRef<VectorLayer | undefined, Omit<GeometryProps, 'ref'>>(function Geometry(\n { layers, streets, roofs, facades = false, paint, visible = true, order = 0, onLayer },\n ref,\n) {\n const binding = useContext(MapContext);\n const tiles = useContext(VectorTilesContext);\n const swipe = useContext(SwipeContext);\n const latest = useRef({ order, onLayer });\n /** The paint properties sent to the current layer */\n const sent = useRef<Paint>(undefined);\n const [layer, setLayer] = useState<VectorLayer>();\n const rank = useRank();\n\n latest.current = { order, onLayer };\n useImperativeHandle(ref, () => layer, [layer]);\n\n // The geometry layer created once the tiles are there, in the declared order; made anew when the layers kept, the\n // streets or the roofs change; removed when unmounted\n useEffect(() => {\n if (!binding || !tiles) return;\n\n const created = tiles.vectors({\n ...(layers && { layers }),\n ...(streets && { streets }),\n ...(roofs && { roofs }),\n });\n\n binding.order.place(created, latest.current.order, { rank });\n swipe?.set(created);\n sent.current = undefined;\n setLayer(created);\n latest.current.onLayer?.(created);\n\n return () => {\n binding.order.remove(created);\n swipe?.unset(created);\n // Gone already with its tiles, or with the map\n if (binding.map.hasLayer(created)) created.remove();\n setLayer(undefined);\n };\n }, [binding, swipe, tiles, layers, streets, roofs, rank]);\n\n // The paint properties changed since the last ones sent (all of them to a layer made anew), those of a function\n // once the style is loaded; a later render or layer drops the wait\n useEffect(() => {\n if (!layer) return;\n\n const apply = (next: Paint | undefined) => {\n changed(sent.current, next).forEach(([id, name, value]) => {\n layer.setPaintProperty(id, name, value);\n });\n sent.current = next;\n };\n\n if (typeof paint !== 'function') {\n apply(paint);\n\n return;\n }\n\n const wait = { live: true };\n\n layer.ready.then(\n () => {\n if (!wait.live) return;\n apply(\n Object.fromEntries(\n layer.layers.flatMap((l) => {\n const properties = paint(l);\n\n return properties ? [[l.id, properties]] : [];\n }),\n ),\n );\n },\n () => undefined,\n );\n\n return () => {\n wait.live = false;\n };\n }, [layer, paint]);\n\n // The walls' windows shown or not\n useEffect(() => {\n layer?.setFacades(facades);\n }, [layer, facades]);\n\n // Shown or hidden\n useEffect(() => {\n layer?.setVisible(visible);\n }, [layer, visible]);\n\n // A new `order`: moved to its new place among the layers of the components\n useEffect(() => {\n if (binding && layer) binding.order.place(layer, order, { old: layer });\n }, [binding, layer, order]);\n\n return null;\n});\n\n/**\n * The fills, lines and buildings of the vector tiles around (`<VectorTiles>`) drawn as geometry on the globe and the\n * relief (`VectorTiles.vectors`): sharp at any zoom and pitch, restyled by `paint` without cutting the tiles again,\n * picked by feature (`map.pickFeature`). The ref and `onLayer` give its handle (`VectorLayer`: `layers`, `featureAt`,\n * `ready`)\n */\nexport const Geometry = GeometryComponent as (props: GeometryProps) => ReactNode;\n\nconst VectorGeometryComponent = forwardRef<VectorLayer | undefined, Omit<VectorGeometryProps, 'ref'>>(\n function VectorGeometry({ style, ...props }, ref) {\n return (\n <VectorTiles {...(style === undefined ? {} : { style })}>\n <GeometryComponent ref={ref} {...props} />\n </VectorTiles>\n );\n },\n);\n\n/**\n * The fills and lines of a MapLibre style drawn as geometry, with tiles of its own: a `<Geometry>` in a\n * `<VectorTiles>` of its `style`. Beside its trees, labels or lamps, a `<VectorTiles>` with each of them as children\n * shares one set of tiles\n */\nexport const VectorGeometry = VectorGeometryComponent as (props: VectorGeometryProps) => ReactNode;\n"]}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/** `<VectorTiles>`: the vector tiles of a MapLibre style, the parts drawn from them as its children (`<Geometry>`,
|
|
2
|
+
* `<Trees>`, `<Lamps>`, `<Furniture>`, `<Labels>`) sharing its tiles and its workers */
|
|
3
|
+
import { type ReactNode, type Ref } from 'react';
|
|
4
|
+
import type { VectorExtrusionOptions } from '../basemap/vectortiles/extrusions.ts';
|
|
5
|
+
import type { FurnitureOptions } from '../basemap/vectortiles/furniture.ts';
|
|
6
|
+
import type { LabelsOptions } from '../basemap/vectortiles/labels.ts';
|
|
7
|
+
import type { LampsOptions } from '../basemap/vectortiles/lamps.ts';
|
|
8
|
+
import type { TreesOptions } from '../basemap/vectortiles/trees.ts';
|
|
9
|
+
import type { VectorTiles as VectorTilesHandle, VectorTilesOptions } from '../basemap/vectortiles.ts';
|
|
10
|
+
import type { ExtrusionLayer } from '../layers/extrusions.ts';
|
|
11
|
+
import type { ModelLayer } from '../layers/layers.ts';
|
|
12
|
+
import type { SymbolLayer } from '../layers/symbols.ts';
|
|
13
|
+
import type { LabelCandidate } from '../workers/basemap.worker.ts';
|
|
14
|
+
export interface VectorTilesProps extends VectorTilesOptions {
|
|
15
|
+
/** The vector tiles, once made and each time they are made anew (another style, other workers) */
|
|
16
|
+
onTiles?: (tiles: VectorTilesHandle) => void;
|
|
17
|
+
ref?: Ref<VectorTilesHandle | undefined>;
|
|
18
|
+
/** The parts drawn from its tiles: `<Geometry>`, `<Trees>`, `<Lamps>`, `<Furniture>`, `<Labels>`, or a component of
|
|
19
|
+
* your own using `useVectorTiles` */
|
|
20
|
+
children?: ReactNode;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The vector tiles of a MapLibre style (`map.vectorTiles`), its children drawing from them: the style's fills, lines
|
|
24
|
+
* and buildings as geometry (`<Geometry>`), its trees, street lamps, street furniture, labels. One set of tiles and
|
|
25
|
+
* workers for all of them: the tiles fetched and decoded once. Its options (`style`, `workers`…) compared by value: an
|
|
26
|
+
* inline object keeps the tiles, another style makes them anew. The ref and `onTiles` give its handle
|
|
27
|
+
* (`VectorTiles`).
|
|
28
|
+
*
|
|
29
|
+
* ```tsx
|
|
30
|
+
* <VectorTiles style={OPENFREEMAP_STYLES.liberty}>
|
|
31
|
+
* <Geometry roofs="generated" />
|
|
32
|
+
* <Trees />
|
|
33
|
+
* <Labels />
|
|
34
|
+
* </VectorTiles>
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare const VectorTiles: (props: VectorTilesProps) => ReactNode;
|
|
38
|
+
/** The vector tiles of the `<VectorTiles>` around, once made (undefined before): a part of your own drawn from them
|
|
39
|
+
* (`streetWind`, `raster`…) */
|
|
40
|
+
export declare const useVectorTiles: () => VectorTilesHandle | undefined;
|
|
41
|
+
/** What a part drawn from the vector tiles around takes besides its options */
|
|
42
|
+
interface PartHandle<L> {
|
|
43
|
+
/** The layer, once made and each time it is made anew */
|
|
44
|
+
onLayer?: (layer: L) => void;
|
|
45
|
+
}
|
|
46
|
+
/** The props of a part: its options (those of its `VectorTiles` method), its handle */
|
|
47
|
+
type PartProps<O, L> = O & PartHandle<L> & {
|
|
48
|
+
ref?: Ref<L | undefined>;
|
|
49
|
+
};
|
|
50
|
+
/** The trees of the vector tiles around on their woods, forests and grass, as 3D models (`VectorTiles.trees`: its
|
|
51
|
+
* options as props) */
|
|
52
|
+
export declare const Trees: (props: PartProps<TreesOptions, ModelLayer>) => ReactNode;
|
|
53
|
+
/** Street lamps along the streets of the vector tiles around, lit at night (`VectorTiles.lamps`) */
|
|
54
|
+
export declare const Lamps: (props: PartProps<LampsOptions, ModelLayer>) => ReactNode;
|
|
55
|
+
/** The street furniture of the vector tiles around: bus shelters, waste baskets, post boxes, fountains, bicycle racks,
|
|
56
|
+
* benches (`VectorTiles.furniture`) */
|
|
57
|
+
export declare const Furniture: (props: PartProps<FurnitureOptions, ModelLayer>) => ReactNode;
|
|
58
|
+
/** The labels of the vector tiles around (`VectorTiles.labels`): hidden by the buildings of a `<Geometry>` beside
|
|
59
|
+
* them */
|
|
60
|
+
export declare const Labels: (props: PartProps<LabelsOptions, SymbolLayer<LabelCandidate>>) => ReactNode;
|
|
61
|
+
/** The buildings of the vector tiles around as an extrusion layer, its style per feature (`VectorTiles.extrusions`:
|
|
62
|
+
* its options as props; functions compared by identity, so at the module's level or in a memo). The properties of
|
|
63
|
+
* its features named by `<Extrusions<Building> …>` */
|
|
64
|
+
export declare const Extrusions: <P = Record<string, unknown>>(props: PartProps<VectorExtrusionOptions<P>, ExtrusionLayer<P>>) => ReactNode;
|
|
65
|
+
export {};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/** `<VectorTiles>`: the vector tiles of a MapLibre style, the parts drawn from them as its children (`<Geometry>`,
|
|
3
|
+
* `<Trees>`, `<Lamps>`, `<Furniture>`, `<Labels>`) sharing its tiles and its workers */
|
|
4
|
+
import { forwardRef, useContext, useEffect, useImperativeHandle, useRef, useState, } from 'react';
|
|
5
|
+
import { MapContext, useStableOptions, VectorTilesContext } from "./context.js";
|
|
6
|
+
const VectorTilesComponent = forwardRef(function VectorTiles({ children, onTiles, ...options }, ref) {
|
|
7
|
+
const binding = useContext(MapContext);
|
|
8
|
+
const stable = useStableOptions(options);
|
|
9
|
+
const latest = useRef(onTiles);
|
|
10
|
+
const [tiles, setTiles] = useState();
|
|
11
|
+
latest.current = onTiles;
|
|
12
|
+
useImperativeHandle(ref, () => tiles, [tiles]);
|
|
13
|
+
// Made once the map is there, anew when its options change; destroyed with its parts when unmounted
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
if (!binding)
|
|
16
|
+
return;
|
|
17
|
+
const made = binding.map.vectorTiles(stable);
|
|
18
|
+
setTiles(made);
|
|
19
|
+
latest.current?.(made);
|
|
20
|
+
return () => {
|
|
21
|
+
made.destroy();
|
|
22
|
+
setTiles(undefined);
|
|
23
|
+
};
|
|
24
|
+
}, [binding, stable]);
|
|
25
|
+
return _jsx(VectorTilesContext.Provider, { value: tiles, children: children });
|
|
26
|
+
});
|
|
27
|
+
/**
|
|
28
|
+
* The vector tiles of a MapLibre style (`map.vectorTiles`), its children drawing from them: the style's fills, lines
|
|
29
|
+
* and buildings as geometry (`<Geometry>`), its trees, street lamps, street furniture, labels. One set of tiles and
|
|
30
|
+
* workers for all of them: the tiles fetched and decoded once. Its options (`style`, `workers`…) compared by value: an
|
|
31
|
+
* inline object keeps the tiles, another style makes them anew. The ref and `onTiles` give its handle
|
|
32
|
+
* (`VectorTiles`).
|
|
33
|
+
*
|
|
34
|
+
* ```tsx
|
|
35
|
+
* <VectorTiles style={OPENFREEMAP_STYLES.liberty}>
|
|
36
|
+
* <Geometry roofs="generated" />
|
|
37
|
+
* <Trees />
|
|
38
|
+
* <Labels />
|
|
39
|
+
* </VectorTiles>
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export const VectorTiles = VectorTilesComponent;
|
|
43
|
+
/** The vector tiles of the `<VectorTiles>` around, once made (undefined before): a part of your own drawn from them
|
|
44
|
+
* (`streetWind`, `raster`…) */
|
|
45
|
+
export const useVectorTiles = () => useContext(VectorTilesContext);
|
|
46
|
+
/** A part drawn from the vector tiles around: made by `make` once they are there, anew when its options change
|
|
47
|
+
* (compared by value, `useStableOptions`), removed when unmounted */
|
|
48
|
+
const usePart = (make, props, ref) => {
|
|
49
|
+
const binding = useContext(MapContext);
|
|
50
|
+
const tiles = useContext(VectorTilesContext);
|
|
51
|
+
// Its options: its props but `onLayer` (a function written inline would make it anew at each render)
|
|
52
|
+
const stable = useStableOptions({ ...props, onLayer: undefined });
|
|
53
|
+
const latest = useRef(props.onLayer);
|
|
54
|
+
const [layer, setLayer] = useState();
|
|
55
|
+
latest.current = props.onLayer;
|
|
56
|
+
useImperativeHandle(ref, () => layer, [layer]);
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
if (!binding || !tiles)
|
|
59
|
+
return;
|
|
60
|
+
const made = make(tiles, stable);
|
|
61
|
+
setLayer(made);
|
|
62
|
+
latest.current?.(made);
|
|
63
|
+
return () => {
|
|
64
|
+
// Gone already with its tiles, or with the map
|
|
65
|
+
if (binding.map.hasLayer(made))
|
|
66
|
+
made.remove();
|
|
67
|
+
setLayer(undefined);
|
|
68
|
+
};
|
|
69
|
+
}, [binding, tiles, stable, make]);
|
|
70
|
+
};
|
|
71
|
+
/** The parts' layers made from the vector tiles (at the module's level: the same functions from render to render) */
|
|
72
|
+
const makeTrees = (tiles, options) => tiles.trees(options);
|
|
73
|
+
const makeLamps = (tiles, options) => tiles.lamps(options);
|
|
74
|
+
const makeFurniture = (tiles, options) => tiles.furniture(options);
|
|
75
|
+
const makeLabels = (tiles, options) => tiles.labels(options);
|
|
76
|
+
const makeExtrusions = (tiles, options) => tiles.extrusions(options);
|
|
77
|
+
const TreesComponent = forwardRef(function Trees(props, ref) {
|
|
78
|
+
usePart(makeTrees, props, ref);
|
|
79
|
+
return null;
|
|
80
|
+
});
|
|
81
|
+
const LampsComponent = forwardRef(function Lamps(props, ref) {
|
|
82
|
+
usePart(makeLamps, props, ref);
|
|
83
|
+
return null;
|
|
84
|
+
});
|
|
85
|
+
const FurnitureComponent = forwardRef(function Furniture(props, ref) {
|
|
86
|
+
usePart(makeFurniture, props, ref);
|
|
87
|
+
return null;
|
|
88
|
+
});
|
|
89
|
+
const LabelsComponent = forwardRef(function Labels(props, ref) {
|
|
90
|
+
usePart(makeLabels, props, ref);
|
|
91
|
+
return null;
|
|
92
|
+
});
|
|
93
|
+
const ExtrusionsComponent = forwardRef(function Extrusions(props, ref) {
|
|
94
|
+
usePart(makeExtrusions, props, ref);
|
|
95
|
+
return null;
|
|
96
|
+
});
|
|
97
|
+
/** The trees of the vector tiles around on their woods, forests and grass, as 3D models (`VectorTiles.trees`: its
|
|
98
|
+
* options as props) */
|
|
99
|
+
export const Trees = TreesComponent;
|
|
100
|
+
/** Street lamps along the streets of the vector tiles around, lit at night (`VectorTiles.lamps`) */
|
|
101
|
+
export const Lamps = LampsComponent;
|
|
102
|
+
/** The street furniture of the vector tiles around: bus shelters, waste baskets, post boxes, fountains, bicycle racks,
|
|
103
|
+
* benches (`VectorTiles.furniture`) */
|
|
104
|
+
export const Furniture = FurnitureComponent;
|
|
105
|
+
/** The labels of the vector tiles around (`VectorTiles.labels`): hidden by the buildings of a `<Geometry>` beside
|
|
106
|
+
* them */
|
|
107
|
+
export const Labels = LabelsComponent;
|
|
108
|
+
/** The buildings of the vector tiles around as an extrusion layer, its style per feature (`VectorTiles.extrusions`:
|
|
109
|
+
* its options as props; functions compared by identity, so at the module's level or in a memo). The properties of
|
|
110
|
+
* its features named by `<Extrusions<Building> …>` */
|
|
111
|
+
export const Extrusions = ExtrusionsComponent;
|
|
112
|
+
//# sourceMappingURL=VectorTiles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VectorTiles.js","sourceRoot":"","sources":["../../src/react/VectorTiles.tsx"],"names":[],"mappings":";AAAA;wFACwF;AAExF,OAAO,EAEL,UAAU,EAGV,UAAU,EACV,SAAS,EACT,mBAAmB,EACnB,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAC;AAWf,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAWhF,MAAM,oBAAoB,GAAG,UAAU,CACrC,SAAS,WAAW,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,OAAO,EAAE,EAAE,GAAG;IACzD,MAAM,OAAO,GAAG,UAAU,CAAC,UAAU,CAAC,CAAC;IACvC,MAAM,MAAM,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;IACzC,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;IAC/B,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,EAAqB,CAAC;IAExD,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,mBAAmB,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IAE/C,oGAAoG;IACpG,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,OAAO;YAAE,OAAO;QAErB,MAAM,IAAI,GAAG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AE/B,OAAO,IAAI,CAAC;AACd,CAAC,CACF,CAAC;AAEF,MAAM,cAAc,GAAG,UAAU,CAC/B,SAAS,KAAK,CAAC,KAAK,EAAE,GAAG;IACvB,OAAO,CAAC,SAAS,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;IAE/B,OAAO,IAAI,CAAC;AACd,CAAC,CACF,CAAC;AAEF,MAAM,kBAAkB,GAAG,UAAU,CACnC,SAAS,SAAS,CAAC,KAAK,EAAE,GAAG;IAC3B,OAAO,CAAC,aAAa,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;IAEnC,OAAO,IAAI,CAAC;AACd,CAAC,CACF,CAAC;AAEF,MAAM,eAAe,GAAG,UAAU,CAGhC,SAAS,MAAM,CAAC,KAAK,EAAE,GAAG;IAC1B,OAAO,CAAC,UAAU,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;IAEhC,OAAO,IAAI,CAAC;AACd,CAAC,CAAC,CAAC;AAEH,MAAM,mBAAmB,GAAG,UAAU,CAGpC,SAAS,UAAU,CAAC,KAAK,EAAE,GAAG;IAC9B,OAAO,CAAC,cAAc,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;IAEpC,OAAO,IAAI,CAAC;AACd,CAAC,CAAC,CAAC;AAEH;uBACuB;AACvB,MAAM,CAAC,MAAM,KAAK,GAAG,cAA2E,CAAC;AAEjG,oGAAoG;AACpG,MAAM,CAAC,MAAM,KAAK,GAAG,cAA2E,CAAC;AAEjG;uCACuC;AACvC,MAAM,CAAC,MAAM,SAAS,GAAG,kBAAmF,CAAC;AAE7G;UACU;AACV,MAAM,CAAC,MAAM,MAAM,GAAG,eAA8F,CAAC;AAErH;;sDAEsD;AACtD,MAAM,CAAC,MAAM,UAAU,GAAG,mBAEZ,CAAC","sourcesContent":["/** `<VectorTiles>`: the vector tiles of a MapLibre style, the parts drawn from them as its children (`<Geometry>`,\n * `<Trees>`, `<Lamps>`, `<Furniture>`, `<Labels>`) sharing its tiles and its workers */\n\nimport {\n type ForwardedRef,\n forwardRef,\n type ReactNode,\n type Ref,\n useContext,\n useEffect,\n useImperativeHandle,\n useRef,\n useState,\n} from 'react';\nimport type { VectorExtrusionOptions } from '../basemap/vectortiles/extrusions.ts';\nimport type { FurnitureOptions } from '../basemap/vectortiles/furniture.ts';\nimport type { LabelsOptions } from '../basemap/vectortiles/labels.ts';\nimport type { LampsOptions } from '../basemap/vectortiles/lamps.ts';\nimport type { TreesOptions } from '../basemap/vectortiles/trees.ts';\nimport type { VectorTiles as VectorTilesHandle, VectorTilesOptions } from '../basemap/vectortiles.ts';\nimport type { ExtrusionLayer } from '../layers/extrusions.ts';\nimport type { Layer as LayerHandle, ModelLayer } from '../layers/layers.ts';\nimport type { SymbolLayer } from '../layers/symbols.ts';\nimport type { LabelCandidate } from '../workers/basemap.worker.ts';\nimport { MapContext, useStableOptions, VectorTilesContext } from './context.ts';\n\nexport interface VectorTilesProps extends VectorTilesOptions {\n /** The vector tiles, once made and each time they are made anew (another style, other workers) */\n onTiles?: (tiles: VectorTilesHandle) => void;\n ref?: Ref<VectorTilesHandle | undefined>;\n /** The parts drawn from its tiles: `<Geometry>`, `<Trees>`, `<Lamps>`, `<Furniture>`, `<Labels>`, or a component of\n * your own using `useVectorTiles` */\n children?: ReactNode;\n}\n\nconst VectorTilesComponent = forwardRef<VectorTilesHandle | undefined, Omit<VectorTilesProps, 'ref'>>(\n function VectorTiles({ children, onTiles, ...options }, ref) {\n const binding = useContext(MapContext);\n const stable = useStableOptions(options);\n const latest = useRef(onTiles);\n const [tiles, setTiles] = useState<VectorTilesHandle>();\n\n latest.current = onTiles;\n useImperativeHandle(ref, () => tiles, [tiles]);\n\n // Made once the map is there, anew when its options change; destroyed with its parts when unmounted\n useEffect(() => {\n if (!binding) return;\n\n const made = binding.map.vectorTiles(stable);\n\n setTiles(made);\n latest.current?.(made);\n\n return () => {\n made.destroy();\n setTiles(undefined);\n };\n }, [binding, stable]);\n\n return <VectorTilesContext.Provider value={tiles}>{children}</VectorTilesContext.Provider>;\n },\n);\n\n/**\n * The vector tiles of a MapLibre style (`map.vectorTiles`), its children drawing from them: the style's fills, lines\n * and buildings as geometry (`<Geometry>`), its trees, street lamps, street furniture, labels. One set of tiles and\n * workers for all of them: the tiles fetched and decoded once. Its options (`style`, `workers`…) compared by value: an\n * inline object keeps the tiles, another style makes them anew. The ref and `onTiles` give its handle\n * (`VectorTiles`).\n *\n * ```tsx\n * <VectorTiles style={OPENFREEMAP_STYLES.liberty}>\n * <Geometry roofs=\"generated\" />\n * <Trees />\n * <Labels />\n * </VectorTiles>\n * ```\n */\nexport const VectorTiles = VectorTilesComponent as (props: VectorTilesProps) => ReactNode;\n\n/** The vector tiles of the `<VectorTiles>` around, once made (undefined before): a part of your own drawn from them\n * (`streetWind`, `raster`…) */\nexport const useVectorTiles = (): VectorTilesHandle | undefined => useContext(VectorTilesContext);\n\n/** What a part drawn from the vector tiles around takes besides its options */\ninterface PartHandle<L> {\n /** The layer, once made and each time it is made anew */\n onLayer?: (layer: L) => void;\n}\n\n/** The props of a part: its options (those of its `VectorTiles` method), its handle */\ntype PartProps<O, L> = O & PartHandle<L> & { ref?: Ref<L | undefined> };\n\n/** A part drawn from the vector tiles around: made by `make` once they are there, anew when its options change\n * (compared by value, `useStableOptions`), removed when unmounted */\nconst usePart = <O extends object, L extends LayerHandle>(\n make: (tiles: VectorTilesHandle, options: O) => L,\n props: O & PartHandle<L>,\n ref: ForwardedRef<L | undefined>,\n): void => {\n const binding = useContext(MapContext);\n const tiles = useContext(VectorTilesContext);\n // Its options: its props but `onLayer` (a function written inline would make it anew at each render)\n const stable = useStableOptions({ ...props, onLayer: undefined });\n const latest = useRef(props.onLayer);\n const [layer, setLayer] = useState<L>();\n\n latest.current = props.onLayer;\n useImperativeHandle(ref, () => layer, [layer]);\n useEffect(() => {\n if (!binding || !tiles) return;\n\n const made = make(tiles, stable);\n\n setLayer(made);\n latest.current?.(made);\n\n return () => {\n // Gone already with its tiles, or with the map\n if (binding.map.hasLayer(made)) made.remove();\n setLayer(undefined);\n };\n }, [binding, tiles, stable, make]);\n};\n\n/** The parts' layers made from the vector tiles (at the module's level: the same functions from render to render) */\nconst makeTrees = (tiles: VectorTilesHandle, options: TreesOptions) => tiles.trees(options);\nconst makeLamps = (tiles: VectorTilesHandle, options: LampsOptions) => tiles.lamps(options);\nconst makeFurniture = (tiles: VectorTilesHandle, options: FurnitureOptions) => tiles.furniture(options);\nconst makeLabels = (tiles: VectorTilesHandle, options: LabelsOptions) => tiles.labels(options);\nconst makeExtrusions = (tiles: VectorTilesHandle, options: VectorExtrusionOptions<Record<string, unknown>>) =>\n tiles.extrusions(options);\n\nconst TreesComponent = forwardRef<ModelLayer | undefined, TreesOptions & PartHandle<ModelLayer>>(\n function Trees(props, ref) {\n usePart(makeTrees, props, ref);\n\n return null;\n },\n);\n\nconst LampsComponent = forwardRef<ModelLayer | undefined, LampsOptions & PartHandle<ModelLayer>>(\n function Lamps(props, ref) {\n usePart(makeLamps, props, ref);\n\n return null;\n },\n);\n\nconst FurnitureComponent = forwardRef<ModelLayer | undefined, FurnitureOptions & PartHandle<ModelLayer>>(\n function Furniture(props, ref) {\n usePart(makeFurniture, props, ref);\n\n return null;\n },\n);\n\nconst LabelsComponent = forwardRef<\n SymbolLayer<LabelCandidate> | undefined,\n LabelsOptions & PartHandle<SymbolLayer<LabelCandidate>>\n>(function Labels(props, ref) {\n usePart(makeLabels, props, ref);\n\n return null;\n});\n\nconst ExtrusionsComponent = forwardRef<\n ExtrusionLayer<Record<string, unknown>> | undefined,\n VectorExtrusionOptions<Record<string, unknown>> & PartHandle<ExtrusionLayer<Record<string, unknown>>>\n>(function Extrusions(props, ref) {\n usePart(makeExtrusions, props, ref);\n\n return null;\n});\n\n/** The trees of the vector tiles around on their woods, forests and grass, as 3D models (`VectorTiles.trees`: its\n * options as props) */\nexport const Trees = TreesComponent as (props: PartProps<TreesOptions, ModelLayer>) => ReactNode;\n\n/** Street lamps along the streets of the vector tiles around, lit at night (`VectorTiles.lamps`) */\nexport const Lamps = LampsComponent as (props: PartProps<LampsOptions, ModelLayer>) => ReactNode;\n\n/** The street furniture of the vector tiles around: bus shelters, waste baskets, post boxes, fountains, bicycle racks,\n * benches (`VectorTiles.furniture`) */\nexport const Furniture = FurnitureComponent as (props: PartProps<FurnitureOptions, ModelLayer>) => ReactNode;\n\n/** The labels of the vector tiles around (`VectorTiles.labels`): hidden by the buildings of a `<Geometry>` beside\n * them */\nexport const Labels = LabelsComponent as (props: PartProps<LabelsOptions, SymbolLayer<LabelCandidate>>) => ReactNode;\n\n/** The buildings of the vector tiles around as an extrusion layer, its style per feature (`VectorTiles.extrusions`:\n * its options as props; functions compared by identity, so at the module's level or in a memo). The properties of\n * its features named by `<Extrusions<Building> …>` */\nexport const Extrusions = ExtrusionsComponent as <P = Record<string, unknown>>(\n props: PartProps<VectorExtrusionOptions<P>, ExtrusionLayer<P>>,\n) => ReactNode;\n"]}
|
package/dist/react/context.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/** What the components of a map share: the map, the order of their layers, the viewsheds, the swipe and the marker
|
|
2
2
|
* around; the hooks */
|
|
3
|
+
import type { VectorTiles } from '../basemap/vectortiles.ts';
|
|
3
4
|
import type { LayerOrder } from '../bind/layers.ts';
|
|
4
5
|
import type { Layer as LayerHandle } from '../layers/layers.ts';
|
|
5
6
|
import type { GeoMap } from '../map.ts';
|
|
@@ -25,9 +26,20 @@ export declare const MarkerContext: import("react").Context<{
|
|
|
25
26
|
marker: MarkerHandle;
|
|
26
27
|
lonLat: LonLat;
|
|
27
28
|
} | undefined>;
|
|
29
|
+
/** The vector tiles of the `<VectorTiles>` around, once the map is there */
|
|
30
|
+
export declare const VectorTilesContext: import("react").Context<VectorTiles | undefined>;
|
|
31
|
+
/** A component's rank among the layers of the components (`LayerOrder.rank`): taken at its first render, in the
|
|
32
|
+
* declared order, kept after */
|
|
33
|
+
export declare const useRank: () => number | undefined;
|
|
28
34
|
/** The map of the `<IsardMap>` around, once created (undefined before) */
|
|
29
35
|
export declare const useMap: () => GeoMap | undefined;
|
|
30
36
|
/** Listens to an event of the map around while the component is mounted; the listener may change at each render */
|
|
31
37
|
export declare const useMapEvent: <K extends keyof MapEvents>(type: K, listener: (event: MapEvents[K]) => void) => void;
|
|
32
38
|
/** The entries of an object whose value is defined (`exactOptionalPropertyTypes`) */
|
|
33
39
|
export declare const defined: <T extends object>(object: T) => { [K in keyof T]?: Exclude<T[K], undefined>; };
|
|
40
|
+
/** A key of options that changes when they do: plain data compared by value (an object written inline in the JSX
|
|
41
|
+
* keeps its key), functions, layers and binary data by identity */
|
|
42
|
+
export declare const propsKey: (options: object) => string;
|
|
43
|
+
/** The same options while their `propsKey` stays: an object written inline in the JSX, the same from render to render
|
|
44
|
+
* until a value in it changes */
|
|
45
|
+
export declare const useStableOptions: <T extends object>(options: T) => T;
|
package/dist/react/context.js
CHANGED
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
/** What the components of a map share: the map, the order of their layers, the viewsheds, the swipe and the marker
|
|
2
2
|
* around; the hooks */
|
|
3
|
-
import { createContext, useContext, useEffect, useRef } from 'react';
|
|
3
|
+
import { createContext, useContext, useEffect, useRef, useState } from 'react';
|
|
4
4
|
export const MapContext = createContext(undefined);
|
|
5
5
|
export const SwipeContext = createContext(undefined);
|
|
6
6
|
/** The marker of a `<Marker>` around and its position (a `<Popup>` in it opens on its click, at that position) */
|
|
7
7
|
export const MarkerContext = createContext(undefined);
|
|
8
|
+
/** The vector tiles of the `<VectorTiles>` around, once the map is there */
|
|
9
|
+
export const VectorTilesContext = createContext(undefined);
|
|
10
|
+
/** A component's rank among the layers of the components (`LayerOrder.rank`): taken at its first render, in the
|
|
11
|
+
* declared order, kept after */
|
|
12
|
+
export const useRank = () => {
|
|
13
|
+
const binding = useContext(MapContext);
|
|
14
|
+
const [rank] = useState(() => binding?.order.rank());
|
|
15
|
+
return rank;
|
|
16
|
+
};
|
|
8
17
|
/** The map of the `<IsardMap>` around, once created (undefined before) */
|
|
9
18
|
export const useMap = () => useContext(MapContext)?.map;
|
|
10
19
|
/** Listens to an event of the map around while the component is mounted; the listener may change at each render */
|
|
@@ -17,4 +26,34 @@ export const useMapEvent = (type, listener) => {
|
|
|
17
26
|
};
|
|
18
27
|
/** The entries of an object whose value is defined (`exactOptionalPropertyTypes`) */
|
|
19
28
|
export const defined = (object) => Object.fromEntries(Object.entries(object).filter(([, value]) => value !== undefined));
|
|
29
|
+
/** Numbers standing for the values compared by identity in `propsKey`, the next one */
|
|
30
|
+
const identities = { of: new WeakMap(), next: 1 };
|
|
31
|
+
/** The number of a value compared by identity */
|
|
32
|
+
const identity = (value) => {
|
|
33
|
+
const known = identities.of.get(value);
|
|
34
|
+
if (known !== undefined)
|
|
35
|
+
return known;
|
|
36
|
+
identities.of.set(value, identities.next);
|
|
37
|
+
identities.next += 1;
|
|
38
|
+
return identities.next - 1;
|
|
39
|
+
};
|
|
40
|
+
/** A value compared by identity: a function, a class's instance (a layer), binary data */
|
|
41
|
+
const byIdentity = (value) => typeof value === 'function' ||
|
|
42
|
+
(typeof value === 'object' &&
|
|
43
|
+
value !== null &&
|
|
44
|
+
!Array.isArray(value) &&
|
|
45
|
+
Object.getPrototypeOf(value) !== Object.prototype &&
|
|
46
|
+
Object.getPrototypeOf(value) !== null);
|
|
47
|
+
/** A key of options that changes when they do: plain data compared by value (an object written inline in the JSX
|
|
48
|
+
* keeps its key), functions, layers and binary data by identity */
|
|
49
|
+
export const propsKey = (options) => JSON.stringify(options, (_, value) => (byIdentity(value) ? `#${identity(value)}` : value));
|
|
50
|
+
/** The same options while their `propsKey` stays: an object written inline in the JSX, the same from render to render
|
|
51
|
+
* until a value in it changes */
|
|
52
|
+
export const useStableOptions = (options) => {
|
|
53
|
+
const kept = useRef({ key: propsKey(options), options });
|
|
54
|
+
const key = propsKey(options);
|
|
55
|
+
if (kept.current.key !== key)
|
|
56
|
+
kept.current = { key, options };
|
|
57
|
+
return kept.current.options;
|
|
58
|
+
};
|
|
20
59
|
//# sourceMappingURL=context.js.map
|