@tileflow/dom 0.0.0-bootstrap.0 → 0.1.0-alpha.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/README.md +108 -4
- package/REFERENCE.md +80 -0
- package/dist/index.d.ts +198 -0
- package/dist/index.js +1768 -0
- package/package.json +48 -7
package/README.md
CHANGED
|
@@ -1,7 +1,111 @@
|
|
|
1
1
|
# @tileflow/dom
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
Mount an interactive Tileflow map in any DOM element, without a framework. One function creates
|
|
4
|
+
the map, loads its manifest and style, keeps its theme, colours, camera, annotations and
|
|
5
|
+
interactions current, and takes everything down again. It draws nothing of its own around the map:
|
|
6
|
+
marker, popup and tooltip views, loading and error states belong to your page.
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
Use it for plain pages and web components. The React, Vue and Svelte packages are the easier way in
|
|
9
|
+
those frameworks.
|
|
10
|
+
|
|
11
|
+
> Related packages and guides: [documentation index](https://raw.githubusercontent.com/tileflow/tileflow-sdk/main/llms.txt).
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
Supported peers are MapLibre GL JS `>=6.4.1 <7`. The local build workflow below requires
|
|
16
|
+
Node.js 22 or newer.
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
npm install @tileflow/dom@alpha @tileflow/core@alpha @tileflow/maps@alpha "maplibre-gl@^6.4.1"
|
|
20
|
+
npm install --save-dev --save-exact tileflow@alpha
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Build a map into `public/tileflow` with `npx tileflow build --out public/tileflow`, as the
|
|
24
|
+
[React guide](https://github.com/tileflow/tileflow-sdk/blob/main/packages/react/README.md#prepare-a-map)
|
|
25
|
+
shows.
|
|
26
|
+
|
|
27
|
+
With Vite, the plugin from `@tileflow/vite` gives every map MapLibre's worker, in development and
|
|
28
|
+
in production builds, so the application configures nothing. `tileflow()` prepares maps and adds
|
|
29
|
+
the worker. When the CLI build or a hosted manifest provides the maps, add only the worker
|
|
30
|
+
(`npm install --save-dev @tileflow/vite@alpha`):
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import {defineConfig} from 'vite';
|
|
34
|
+
import {tileflowMapLibreWorker} from '@tileflow/vite';
|
|
35
|
+
|
|
36
|
+
export default defineConfig({plugins: [tileflowMapLibreWorker()]});
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
The worker comes from the same installed MapLibre as the map's main module.
|
|
40
|
+
|
|
41
|
+
With another bundler, configure the worker once before the first map, with the URL at which the
|
|
42
|
+
page serves `maplibre-gl/dist/maplibre-gl-worker.mjs`. An explicit configuration wins over the
|
|
43
|
+
Vite plugin's:
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
import {configureTileflowMapLibre} from '@tileflow/dom';
|
|
47
|
+
|
|
48
|
+
configureTileflowMapLibre({workerUrl: '/assets/maplibre-gl-worker.mjs'});
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Mount a map
|
|
52
|
+
|
|
53
|
+
The container needs a size; the map fills it and follows its resizes.
|
|
54
|
+
|
|
55
|
+
<!-- docs:check -->
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
import 'maplibre-gl/dist/maplibre-gl.css';
|
|
59
|
+
import {createTileflowMap} from '@tileflow/dom';
|
|
60
|
+
|
|
61
|
+
const container = document.querySelector<HTMLElement>('#map')!;
|
|
62
|
+
const map = createTileflowMap(container, {
|
|
63
|
+
source: {map: 'madrid'},
|
|
64
|
+
theme: 'system',
|
|
65
|
+
annotations: [
|
|
66
|
+
{
|
|
67
|
+
ariaLabel: 'Prado Museum',
|
|
68
|
+
coordinate: [-3.6921, 40.4138],
|
|
69
|
+
id: 'prado',
|
|
70
|
+
kind: 'marker',
|
|
71
|
+
popup: {content: {kind: 'view', name: 'museum'}},
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
views: {
|
|
75
|
+
popup(element, {close}) {
|
|
76
|
+
const button = document.createElement('button');
|
|
77
|
+
button.textContent = 'Close';
|
|
78
|
+
button.addEventListener('click', close);
|
|
79
|
+
element.append(button);
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
onError: ({code, error}) => console.warn(code, error),
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
await map.ready;
|
|
86
|
+
map.setTheme('dark');
|
|
87
|
+
map.setColors({water: 'var(--brand)'});
|
|
88
|
+
map.destroy();
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
`createTileflowMap` returns at once. `ready` settles with the MapLibre map when it first loads.
|
|
92
|
+
Each setter applies one option; `update` applies several and does no work for values that did not
|
|
93
|
+
change, so an adapter can hand over all of its props on every render. The container carries
|
|
94
|
+
`data-tileflow-state` (`loading`, `idle` or `error`) for capture, and `getStatus` with
|
|
95
|
+
`onStatusChange` give the same readiness, the theme shown and interaction diagnostics to your own
|
|
96
|
+
loading or error view.
|
|
97
|
+
|
|
98
|
+
A view renderer fills the element it receives. It runs again on an emptied element when its context
|
|
99
|
+
changes, unless it returns `update`; `destroy` runs when the view leaves the map. A marker view
|
|
100
|
+
receives hover, focus and whether its popup is open in `state`.
|
|
101
|
+
|
|
102
|
+
`mode: "image"` shows a static image of the map instead, without loading MapLibre; `ready` then
|
|
103
|
+
settles with `null` once the image has loaded.
|
|
104
|
+
|
|
105
|
+
See [REFERENCE.md](REFERENCE.md) for every option and controller method.
|
|
106
|
+
|
|
107
|
+
## Next steps
|
|
108
|
+
|
|
109
|
+
- [Show a popup on click](https://tileflow.dev/docs/examples/show-a-popup-on-click)
|
|
110
|
+
- [Themes and tokens](https://tileflow.dev/docs/map-design/themes-and-tokens)
|
|
111
|
+
- [Capture a map](https://github.com/tileflow/tileflow-sdk/blob/main/packages/capture/README.md)
|
package/REFERENCE.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# @tileflow/dom reference
|
|
2
|
+
|
|
3
|
+
## `createTileflowMap(container, options, createOptions?)`
|
|
4
|
+
|
|
5
|
+
Mounts a map in `container` and returns a controller at once. MapLibre loads lazily, after the
|
|
6
|
+
manifest and style are ready. Throws a `TypeError` for an invalid `source`, `theme`, `timeOfDay`,
|
|
7
|
+
`themeBlend` or `themeTransition`, and when both `views` and `renderTargets` are given.
|
|
8
|
+
|
|
9
|
+
### Options
|
|
10
|
+
|
|
11
|
+
Every option except `source` is optional and can change after mount through `update` or a setter.
|
|
12
|
+
|
|
13
|
+
| Option | Meaning |
|
|
14
|
+
| ------------------------------------------------ | --------------------------------------------------------------------------------------------------------- |
|
|
15
|
+
| `source` | `{map, manifestUrl?}`: the map by name, from the default manifest or `manifestUrl`. |
|
|
16
|
+
| `theme`, `timeOfDay` | A concrete theme or `"system"`, which follows the page's colour scheme; an optional artistic preset. |
|
|
17
|
+
| `themeBlend` | `{themes, position, hold?}`: a continuous blend of two to eight themes instead of `theme`. |
|
|
18
|
+
| `themeTransition` | `{duration}` in milliseconds, used for theme, blend, colour and emphasis changes. |
|
|
19
|
+
| `colors`, `emphasis` | Colour token or knob overrides (CSS variables are read where the map sits); modules that recede. |
|
|
20
|
+
| `vegetation`, `viewMode` | 3D scene inputs; `viewMode` defaults to `"3d"`. |
|
|
21
|
+
| `center`, `zoom` | The view until `bounds` or `fitAnnotations` is given; a change moves the camera at once. |
|
|
22
|
+
| `bounds`, `fitBoundsOptions`, `fitAnnotations` | Bounds to show, how they are fitted, or a fit to all annotations. The first fit is immediate. |
|
|
23
|
+
| `interactive`, `navigationControl` | Whether the map takes input; zoom and compass buttons, none unless asked. |
|
|
24
|
+
| `mapOptions` | MapLibre options apart from `container` and `style`. A structurally different value recreates the map. |
|
|
25
|
+
| `analytics` | Analytics fields merged with the style's own. |
|
|
26
|
+
| `annotations`, `annotationClusters` | Portable annotations and optional clustering. |
|
|
27
|
+
| `dataSources`, `dataOverlays` | Application GeoJSON and the overlays drawn over it, keyed as in `defineMap`. |
|
|
28
|
+
| `interactions` | Semantic interaction bindings on map features. |
|
|
29
|
+
| `interactionState` or `defaultInteractionState` | The open popup, controlled or initial. Which of the two is used is fixed when the map is created. |
|
|
30
|
+
| `views` | `{marker?, popup?, tooltip?}` renderers that fill a plain element. |
|
|
31
|
+
| `renderTargets` | `{marker?, popup?, tooltip?, onChange}` for a framework that draws views itself; replaces `views`. |
|
|
32
|
+
| `onLoad`, `onError`, `onThemeChange` | The loaded MapLibre map; `{code, error}` failures (`console.error` without a handler); theme transitions. |
|
|
33
|
+
| `onInteractionEvent`, `onInteractionStateChange` | Pointer and popup events; requested popup state. |
|
|
34
|
+
| `onInteractionDiagnostic` | Each distinct interaction diagnostic, once. |
|
|
35
|
+
| `onStatusChange` | Every change to the status `getStatus` returns. |
|
|
36
|
+
| `mode`, `imageUrl`, `alt`, `imageLoading` | `"image"` shows a static image instead of a map: `imageUrl`, or one the map's style resolves. |
|
|
37
|
+
| `image` | In image mode, an `<img>` your page renders (or `null` until it does); otherwise the map adds its own. |
|
|
38
|
+
|
|
39
|
+
### Image mode
|
|
40
|
+
|
|
41
|
+
With `mode: "image"` no MapLibre loads. The map shows `imageUrl`, or an image of the style at the
|
|
42
|
+
view and container size, and is `idle` once that image has loaded and decoded. Annotations,
|
|
43
|
+
interactions, interaction state, interaction callbacks and views are unavailable there and report
|
|
44
|
+
`UNSUPPORTED_MODE`. A framework that renders on the server passes its own `<img>` as `image` and
|
|
45
|
+
sets its `src` from `status.imageUrl`.
|
|
46
|
+
|
|
47
|
+
### Create options
|
|
48
|
+
|
|
49
|
+
Read once: `captureId` (written as `data-tileflow-capture-id`), `sessionSource` (names the
|
|
50
|
+
integration in session analytics) and `statusElement` (the element that receives the capture
|
|
51
|
+
attributes; the container unless given, none when `null`).
|
|
52
|
+
|
|
53
|
+
### Views
|
|
54
|
+
|
|
55
|
+
A renderer is `(element, context) => void | {update?, destroy?}`. It runs when the view appears,
|
|
56
|
+
and again on an emptied element when its context changes, unless it returned `update`. `destroy`
|
|
57
|
+
runs when the view leaves the map. A marker context has `state: {hovered, focused, selected}`;
|
|
58
|
+
popup and tooltip contexts belong to an annotation or to a map feature and carry `close`. A kind
|
|
59
|
+
with no renderer keeps the default view.
|
|
60
|
+
|
|
61
|
+
## Controller
|
|
62
|
+
|
|
63
|
+
| Member | Meaning |
|
|
64
|
+
| -------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
65
|
+
| `ready` | Settles with the MapLibre map on its first load (`null` once an image shows); rejects when it cannot start or is destroyed first. |
|
|
66
|
+
| `update(options)` | Applies changed options; left-out keys keep their value, `undefined` clears one. |
|
|
67
|
+
| `setTheme`, `setThemeBlend`, `setColors`, `setEmphasis` | One option each. |
|
|
68
|
+
| `setView({center, zoom})`, `setBounds(bounds, options?)` | Camera options. |
|
|
69
|
+
| `setAnnotations`, `setInteractions`, `setViews` | Content options. |
|
|
70
|
+
| `setInteractionState(state)` | Opens or closes a popup; on a controlled map the same as passing `interactionState`. |
|
|
71
|
+
| `getStatus()` | `{readiness, theme, diagnostics, imageUrl}`: `loading`, `idle` or `error`, the theme shown, interaction diagnostics and, in image mode, the image. |
|
|
72
|
+
| `getMap()`, `getThemeController()` | The MapLibre map and theme controller, `null` until the map exists and after it is taken down. |
|
|
73
|
+
| `getInteractionState()`, `getRenderTargets()` | The open popup; the view elements the map handed out. |
|
|
74
|
+
| `destroy()` | Takes the map down, removes the capture attributes and stops every listener. Later calls do nothing. |
|
|
75
|
+
|
|
76
|
+
## `getTileflowMapInitialStatus(options, controlledInteractionState?)`
|
|
77
|
+
|
|
78
|
+
The status a map with these options has before it mounts: its declarative diagnostics, `error` or
|
|
79
|
+
`loading`, the theme it names and, in image mode, `imageUrl`. It touches no DOM, so a framework can
|
|
80
|
+
render capture attributes on the server and before the controller exists.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import * as maplibre_gl from 'maplibre-gl';
|
|
2
|
+
import { Map, MapOptions } from 'maplibre-gl';
|
|
3
|
+
import { TileflowMapLibreOverlay, TileflowGeoJsonSource } from '@tileflow/core';
|
|
4
|
+
import { TileflowThemeController, TileflowBounds, TileflowFitBoundsOptions, TileflowColorOverrides, TileflowEmphasis, TileflowBrowserThemeBlendSelection, TileflowThemeTransitionOptions, TileflowViewMode, TileflowNavigationControlInput, TileflowMapError, TileflowThemeTransition } from '@tileflow/core/browser';
|
|
5
|
+
import { TileflowThemeSelection, TileflowRuntimeSource, TileflowTimeOfDay, TileflowAnalytics } from '@tileflow/core/runtime';
|
|
6
|
+
import { TileflowAnnotation, TileflowAnnotationViewContext, TileflowInteractionViewContext, TileflowInteractionState, TileflowInteractionDiagnostic, TileflowInteractionBinding, TileflowInteractionEvent } from '@tileflow/interactions';
|
|
7
|
+
import { TileflowMapLibreDomRenderTarget, TileflowMapLibreSemanticDomRenderTarget, TileflowAnnotationClusterOptions } from '@tileflow/interactions/maplibre';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* What a view renderer may return: `update` receives the next context instead of the view being
|
|
11
|
+
* rendered again from an empty element, and `destroy` runs when the view leaves the map.
|
|
12
|
+
*/
|
|
13
|
+
type TileflowMapViewInstance<TContext> = Readonly<{
|
|
14
|
+
destroy?: () => void;
|
|
15
|
+
update?: (context: TContext) => void;
|
|
16
|
+
}>;
|
|
17
|
+
/**
|
|
18
|
+
* Fills `element` with a view. It runs when the view appears and again, on an emptied element,
|
|
19
|
+
* whenever its context changes, unless it returned an `update`.
|
|
20
|
+
*/
|
|
21
|
+
type TileflowMapViewRenderer<TContext> = (element: HTMLElement, context: TContext) => TileflowMapViewInstance<TContext> | void;
|
|
22
|
+
/** Views drawn into marker, popup and tooltip elements. Each kind left out keeps the default view. */
|
|
23
|
+
type TileflowMapViews<TAnnotation extends TileflowAnnotation = TileflowAnnotation> = Readonly<{
|
|
24
|
+
marker?: TileflowMapViewRenderer<TileflowAnnotationViewContext<TAnnotation>>;
|
|
25
|
+
popup?: TileflowMapViewRenderer<TileflowInteractionViewContext<TAnnotation>>;
|
|
26
|
+
tooltip?: TileflowMapViewRenderer<TileflowInteractionViewContext<TAnnotation>>;
|
|
27
|
+
}>;
|
|
28
|
+
type TileflowMapRenderTargetList<TAnnotation extends TileflowAnnotation> = Readonly<{
|
|
29
|
+
annotations: readonly TileflowMapLibreDomRenderTarget<TAnnotation>[];
|
|
30
|
+
semantic: readonly TileflowMapLibreSemanticDomRenderTarget[];
|
|
31
|
+
}>;
|
|
32
|
+
|
|
33
|
+
/** MapLibre options a map passes through, apart from the container and style it owns. */
|
|
34
|
+
type TileflowMapLibreOptions = Omit<MapOptions, 'container' | 'style'>;
|
|
35
|
+
type TileflowMapReadiness = 'error' | 'idle' | 'loading';
|
|
36
|
+
/**
|
|
37
|
+
* Where the map stands, for capture and for an application's own loading or error view. The map
|
|
38
|
+
* draws nothing for it: `diagnostics` are for the application to show.
|
|
39
|
+
*/
|
|
40
|
+
type TileflowMapStatus = Readonly<{
|
|
41
|
+
/** Interaction problems: invalid annotations, interactions or state, and runtime failures. */
|
|
42
|
+
diagnostics: readonly TileflowInteractionDiagnostic[];
|
|
43
|
+
/** `idle` once the map, its theme and its views have settled; `error` when one cannot. */
|
|
44
|
+
readiness: TileflowMapReadiness;
|
|
45
|
+
/** The concrete theme shown, once it is known. */
|
|
46
|
+
theme: string | undefined;
|
|
47
|
+
/** In image mode, the image to show, once it is known. */
|
|
48
|
+
imageUrl: string | undefined;
|
|
49
|
+
}>;
|
|
50
|
+
/**
|
|
51
|
+
* For a framework that draws views itself, such as through portals: the map leaves the elements of
|
|
52
|
+
* the kinds marked `true` empty and hands every element to `onChange`.
|
|
53
|
+
*/
|
|
54
|
+
type TileflowMapRenderTargetsOptions<TAnnotation extends TileflowAnnotation> = Readonly<{
|
|
55
|
+
marker?: boolean;
|
|
56
|
+
onChange: (targets: TileflowMapRenderTargetList<TAnnotation>) => void;
|
|
57
|
+
popup?: boolean;
|
|
58
|
+
tooltip?: boolean;
|
|
59
|
+
}>;
|
|
60
|
+
type TileflowMapInteractionStateOptions = Readonly<{
|
|
61
|
+
defaultInteractionState?: never;
|
|
62
|
+
interactionState?: TileflowInteractionState;
|
|
63
|
+
}> | Readonly<{
|
|
64
|
+
defaultInteractionState?: TileflowInteractionState;
|
|
65
|
+
interactionState?: never;
|
|
66
|
+
}>;
|
|
67
|
+
type TileflowMapControllerOptions<TAnnotation extends TileflowAnnotation = TileflowAnnotation> = TileflowMapInteractionStateOptions & {
|
|
68
|
+
/** The map to show, by name, from the manifest at `manifestUrl` or the default one. */
|
|
69
|
+
source: TileflowRuntimeSource;
|
|
70
|
+
/**
|
|
71
|
+
* `image` shows a static image of the map instead of MapLibre: `imageUrl`, or one the map's
|
|
72
|
+
* static renderer makes for the container's size, `center`, `zoom` and theme.
|
|
73
|
+
*/
|
|
74
|
+
mode?: 'image' | 'interactive';
|
|
75
|
+
imageUrl?: string;
|
|
76
|
+
/** The image's alternative text; empty unless given. */
|
|
77
|
+
alt?: string;
|
|
78
|
+
/** How the browser loads the image; `eager` unless given. */
|
|
79
|
+
imageLoading?: 'eager' | 'lazy';
|
|
80
|
+
/**
|
|
81
|
+
* The `<img>` a framework renders itself (with `imageUrl` from the status), so the image can be
|
|
82
|
+
* rendered on the server. Without it, the map adds its own image to the container.
|
|
83
|
+
*/
|
|
84
|
+
image?: HTMLImageElement | null;
|
|
85
|
+
theme?: TileflowThemeSelection;
|
|
86
|
+
/** Optional artistic preset; ignored by maps without this capability. */
|
|
87
|
+
timeOfDay?: TileflowTimeOfDay;
|
|
88
|
+
/** Shows a continuous blend of the map's themes instead of `theme`. */
|
|
89
|
+
themeBlend?: TileflowBrowserThemeBlendSelection;
|
|
90
|
+
/** Cross-fades theme, blend, colour and emphasis changes. */
|
|
91
|
+
themeTransition?: TileflowThemeTransitionOptions;
|
|
92
|
+
/** Colour token or knob overrides, which may use CSS variables read where the map sits. */
|
|
93
|
+
colors?: TileflowColorOverrides;
|
|
94
|
+
/** Makes chosen modules of the map recede so the application's content reads first. */
|
|
95
|
+
emphasis?: TileflowEmphasis;
|
|
96
|
+
vegetation?: boolean;
|
|
97
|
+
viewMode?: TileflowViewMode;
|
|
98
|
+
center?: [number, number];
|
|
99
|
+
zoom?: number;
|
|
100
|
+
/** Shows these bounds; `center` and `zoom` set the view only until bounds are given. */
|
|
101
|
+
bounds?: TileflowBounds;
|
|
102
|
+
/** Fits the map to all annotations, and again whenever their positions change. */
|
|
103
|
+
fitAnnotations?: boolean | TileflowFitBoundsOptions;
|
|
104
|
+
fitBoundsOptions?: TileflowFitBoundsOptions;
|
|
105
|
+
interactive?: boolean;
|
|
106
|
+
/** Zoom and compass buttons; none unless asked. */
|
|
107
|
+
navigationControl?: TileflowNavigationControlInput;
|
|
108
|
+
mapOptions?: TileflowMapLibreOptions;
|
|
109
|
+
analytics?: TileflowAnalytics;
|
|
110
|
+
/** Group `annotations` into accessible cluster buttons. Up to 1,000 annotations. */
|
|
111
|
+
annotationClusters?: TileflowAnnotationClusterOptions;
|
|
112
|
+
annotations?: readonly TAnnotation[];
|
|
113
|
+
dataOverlays?: Readonly<Record<string, TileflowMapLibreOverlay>>;
|
|
114
|
+
dataSources?: Readonly<Record<string, TileflowGeoJsonSource>>;
|
|
115
|
+
interactions?: readonly TileflowInteractionBinding[];
|
|
116
|
+
/** Views drawn into marker, popup and tooltip elements. */
|
|
117
|
+
views?: TileflowMapViews<TAnnotation>;
|
|
118
|
+
/** Hands view elements to a framework that draws them; replaces `views`. */
|
|
119
|
+
renderTargets?: TileflowMapRenderTargetsOptions<TAnnotation>;
|
|
120
|
+
onError?: (event: TileflowMapError) => void;
|
|
121
|
+
onLoad?: (map: Map) => void;
|
|
122
|
+
onThemeChange?: (transition: TileflowThemeTransition) => void;
|
|
123
|
+
onInteractionDiagnostic?: (diagnostic: TileflowInteractionDiagnostic) => void;
|
|
124
|
+
onInteractionEvent?: (event: TileflowInteractionEvent<TAnnotation>) => void;
|
|
125
|
+
onInteractionStateChange?: (state: TileflowInteractionState) => void;
|
|
126
|
+
onStatusChange?: (status: TileflowMapStatus) => void;
|
|
127
|
+
};
|
|
128
|
+
/** Options read once, when the map is created. */
|
|
129
|
+
type TileflowMapCreateOptions = Readonly<{
|
|
130
|
+
/** Names the map in deterministic capture, as `data-tileflow-capture-id`. */
|
|
131
|
+
captureId?: string;
|
|
132
|
+
/** Names the integration in session analytics; adapters pass their framework. */
|
|
133
|
+
sessionSource?: string;
|
|
134
|
+
/**
|
|
135
|
+
* Receives `data-tileflow-map`, `data-tileflow-theme`, `data-tileflow-state` and
|
|
136
|
+
* `data-tileflow-capture-id`; the container unless given, none when `null`.
|
|
137
|
+
*/
|
|
138
|
+
statusElement?: HTMLElement | null;
|
|
139
|
+
}>;
|
|
140
|
+
type TileflowMapController<TAnnotation extends TileflowAnnotation = TileflowAnnotation> = Readonly<{
|
|
141
|
+
container: HTMLElement;
|
|
142
|
+
/**
|
|
143
|
+
* Settles with the MapLibre map when it first loads, or with `null` once an image-mode map has
|
|
144
|
+
* shown its image; rejects when it cannot start or when the controller is destroyed first.
|
|
145
|
+
*/
|
|
146
|
+
ready: Promise<Map | null>;
|
|
147
|
+
/** Takes the map down, empties what it added to the container, and stops every listener. */
|
|
148
|
+
destroy(): void;
|
|
149
|
+
getInteractionState(): TileflowInteractionState;
|
|
150
|
+
/** The MapLibre map, or `null` before it is created and after it is taken down. */
|
|
151
|
+
getMap(): Map | null;
|
|
152
|
+
getRenderTargets(): TileflowMapRenderTargetList<TAnnotation>;
|
|
153
|
+
getStatus(): TileflowMapStatus;
|
|
154
|
+
/** Changes theme, colours and emphasis; `null` until the map exists or when it has no themes. */
|
|
155
|
+
getThemeController(): TileflowThemeController | null;
|
|
156
|
+
setAnnotations(annotations: readonly TAnnotation[] | undefined): void;
|
|
157
|
+
setBounds(bounds: TileflowBounds | undefined, options?: TileflowFitBoundsOptions): void;
|
|
158
|
+
setColors(colors: TileflowColorOverrides | undefined): void;
|
|
159
|
+
setEmphasis(emphasis: TileflowEmphasis | undefined): void;
|
|
160
|
+
setInteractions(interactions: readonly TileflowInteractionBinding[] | undefined): void;
|
|
161
|
+
/** Opens or closes a popup; on a controlled map it is the same as passing `interactionState`. */
|
|
162
|
+
setInteractionState(state: TileflowInteractionState): void;
|
|
163
|
+
setTheme(theme: TileflowThemeSelection | undefined): void;
|
|
164
|
+
setThemeBlend(themeBlend: TileflowBrowserThemeBlendSelection | undefined): void;
|
|
165
|
+
setView(view: Readonly<{
|
|
166
|
+
center?: [number, number];
|
|
167
|
+
zoom?: number;
|
|
168
|
+
}>): void;
|
|
169
|
+
setViews(views: TileflowMapViews<TAnnotation> | undefined): void;
|
|
170
|
+
/**
|
|
171
|
+
* Applies changed options. Keys left out keep their value; a key given as `undefined` clears it.
|
|
172
|
+
* Unchanged values do no work, so an adapter can pass all of its props on every render.
|
|
173
|
+
*/
|
|
174
|
+
update(options: Partial<TileflowMapControllerOptions<TAnnotation>>): void;
|
|
175
|
+
}>;
|
|
176
|
+
/**
|
|
177
|
+
* Mounts a Tileflow map in `container` and returns its controller. The container should have a
|
|
178
|
+
* size; the map fills it and follows its resizes. Nothing is drawn around the map: loading,
|
|
179
|
+
* error and diagnostic views belong to the application, from `getStatus` and `onStatusChange`.
|
|
180
|
+
*/
|
|
181
|
+
declare function createTileflowMap<TAnnotation extends TileflowAnnotation = TileflowAnnotation>(container: HTMLElement, initialOptions: TileflowMapControllerOptions<TAnnotation>, createOptions?: TileflowMapCreateOptions): TileflowMapController<TAnnotation>;
|
|
182
|
+
/**
|
|
183
|
+
* The status a map with these options has before it mounts: for server rendering and a framework's
|
|
184
|
+
* first render, so the page shows the same theme, diagnostics and image before and after mount.
|
|
185
|
+
* `controlledInteractionOwnership` is whether the map started with `interactionState`.
|
|
186
|
+
*/
|
|
187
|
+
declare function getTileflowMapInitialStatus<TAnnotation extends TileflowAnnotation = TileflowAnnotation>(options: TileflowMapControllerOptions<TAnnotation>, controlledInteractionOwnership?: boolean): TileflowMapStatus;
|
|
188
|
+
|
|
189
|
+
type TileflowMapLibre = typeof maplibre_gl;
|
|
190
|
+
type TileflowMapLibreConfiguration = Readonly<{
|
|
191
|
+
workerUrl: string;
|
|
192
|
+
}>;
|
|
193
|
+
/** Configure the application-owned worker before mounting an interactive Tileflow map. */
|
|
194
|
+
declare function configureTileflowMapLibre(configuration: TileflowMapLibreConfiguration): void;
|
|
195
|
+
/** Load the interactive renderer only after a browser map requests it. */
|
|
196
|
+
declare function loadTileflowMapLibre(): Promise<TileflowMapLibre>;
|
|
197
|
+
|
|
198
|
+
export { type TileflowMapController, type TileflowMapControllerOptions, type TileflowMapCreateOptions, type TileflowMapLibre, type TileflowMapLibreConfiguration, type TileflowMapLibreOptions, type TileflowMapReadiness, type TileflowMapRenderTargetList, type TileflowMapRenderTargetsOptions, type TileflowMapStatus, type TileflowMapViewInstance, type TileflowMapViewRenderer, type TileflowMapViews, configureTileflowMapLibre, createTileflowMap, getTileflowMapInitialStatus, loadTileflowMapLibre };
|