@tileflow/core 0.1.0-alpha.30 → 0.1.0-alpha.32

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.
@@ -8,8 +8,9 @@ blend when the application controls the appearance continuously, such as a slide
8
8
  passes from night to day.
9
9
 
10
10
  Both work on the one MapLibre map the application already has. They create no second map, add no
11
- map views, and request the same tiles as a map that does not change theme. They need a browser
12
- document and MapLibre GL JS; the React Native package does not offer them.
11
+ map views, and request the same tiles as a map that does not change theme. The React, Vue, and
12
+ Svelte maps offer them with MapLibre GL JS, and the React Native map with MapLibre Native on iOS
13
+ and Android; see [React Native](#react-native) for what differs there.
13
14
 
14
15
  ## Cross-fade a theme change
15
16
 
@@ -82,7 +83,8 @@ While a blend is shown, `data-tileflow-theme` names the theme nearest to the pos
82
83
  - Colours and numbers of the ground, such as land, water, roads, buildings, and their widths and
83
84
  opacities, follow the position continuously. Colours mix in the OKLab colour space, so halfway
84
85
  between two themes looks halfway to the eye.
85
- - Patterns, the sky, and light follow the position too. Pattern artwork is mixed in its pixels.
86
+ - Patterns, the sky, and light follow the position too. Pattern artwork is mixed in its pixels;
87
+ artwork two neighbouring themes share, by name or pixel for pixel, is not uploaded again.
86
88
  - Labels, icons, and other symbols change when the nearest theme changes, with a short cross-fade.
87
89
  Light lettering on a dark plate and dark lettering on a light plate would meet in the same grey
88
90
  halfway, so symbols do not follow the position.
@@ -117,6 +119,48 @@ For a detailed city map this takes a few milliseconds on a mid-range phone. Posi
117
119
  four-hundredth of a theme are not applied, so a slowly moving position leaves the map at rest
118
120
  between changes.
119
121
 
122
+ ## React Native
123
+
124
+ The `Map` of `@tileflow/react-native` accepts the same `themeTransition` and `themeBlend` props:
125
+
126
+ ```tsx
127
+ import {Map} from '@tileflow/react-native';
128
+
129
+ export function DayMap({position}: {position: number}) {
130
+ return (
131
+ <Map
132
+ source={{map: 'city', manifestUrl: 'https://maps.example.com/tileflow/manifest.json'}}
133
+ themeTransition={{duration: 450}}
134
+ themeBlend={{position, themes: ['night', 'dusk', 'day']}}
135
+ style={{flex: 1}}
136
+ />
137
+ );
138
+ }
139
+ ```
140
+
141
+ A transition covers the drawn map with a snapshot of its current frame, below markers and map
142
+ controls. The snapshot follows the camera and fades out once the new style is drawn.
143
+ `onReadinessChange` and `onThemeChange` report `ready` after the fade. The device's reduce-motion
144
+ setting (iOS) or removed animations (Android) change at once.
145
+
146
+ A blend loads every blended theme's style once and replaces the map's style once. Position changes
147
+ then apply in batches on the main thread, at most one at a time, and later positions replace any
148
+ that are still waiting. MapLibre Native's style transition smooths values between batches.
149
+
150
+ What follows the position differs from the browser in a few ways:
151
+
152
+ - Ground colours and numbers, pattern artwork, and light follow the position. Native maps have no
153
+ sky.
154
+ - Labels, icons, and switched values change at the nearest theme under a short cross-fade of the
155
+ whole map. Icon artwork changes by image name instead of mixing pixels, so stretchable images
156
+ keep their stretch and content areas.
157
+ - A value that depends on feature data and cannot be split by class, such as a road casing chosen
158
+ by access and zoom together, is drawn once per theme. Only the nearest theme's copy is shown.
159
+ The map has a few more layers while the blend is shown.
160
+
161
+ If the application's native build predates these props, for example after an over-the-air
162
+ JavaScript update, themes change at once and a blend shows its nearest theme.
163
+
120
164
  ## Use the core controller
121
165
 
122
166
  Framework adapters use `createTileflowThemeController` from `@tileflow/core/browser`. A direct
@@ -124,12 +168,12 @@ MapLibre integration can use it too. Resolve runtime styles from the published m
124
168
  `resolveTileflowRuntimeStyle` and `resolveTileflowRuntimeThemeBlend` from `@tileflow/core/runtime`:
125
169
 
126
170
  ```ts
171
+ import type {Map as MapLibreMap} from 'maplibre-gl';
127
172
  import {createTileflowThemeController} from '@tileflow/core/browser';
128
173
  import {
129
174
  resolveTileflowRuntimeStyle,
130
175
  resolveTileflowRuntimeThemeBlend,
131
176
  } from '@tileflow/core/runtime';
132
- import type {Map as MapLibreMap} from 'maplibre-gl';
133
177
  import type {TileflowRuntimeManifestMap} from '@tileflow/core/runtime';
134
178
 
135
179
  export async function moveThroughTheDay(map: MapLibreMap, manifestMap: TileflowRuntimeManifestMap) {
@@ -152,7 +196,8 @@ export async function moveThroughTheDay(map: MapLibreMap, manifestMap: TileflowR
152
196
  await controller.setBlend({position: 0.5, themes});
153
197
  // The same themes: the position applies at once.
154
198
  await controller.setBlend({position: 0.6, themes});
155
- return controller.getBlend(); // {position: 0.6, themes: ['night', 'dusk', 'day']}
199
+ // {held: false, position: 0.6, relayoutAt: [...], themes: ['night', 'dusk', 'day']}
200
+ return controller.getBlend();
156
201
  }
157
202
  ```
158
203
 
@@ -163,3 +208,53 @@ latest wins. A failed change restores the previous appearance and reports `faile
163
208
  The controller loads blended themes' style documents with the same request policy it uses for
164
209
  style font metadata: same-origin credentials, no redirects, and a bounded size. Pass `loadStyle`
165
210
  when styles need another loader.
211
+
212
+ The controller also shows [map emphasis](https://github.com/tileflow/tileflow-sdk/blob/main/packages/core/docs/map-emphasis.md),
213
+ which stays through theme changes and follows every blend position.
214
+ Its [dynamic style images](dynamic-style-images.md) receive theme, blend and declared state inputs
215
+ under one resource owner, with fixed geometry and restoration after a style reload.
216
+
217
+ ## Fast sweeps on slower devices
218
+
219
+ Each position change makes MapLibre evaluate the paint of every layer whose value changed. A clock
220
+ that moves slowly changes few values per frame, and positions closer than a four-hundredth of a
221
+ theme are skipped. A sweep that crosses a whole theme in a few seconds while the camera also moves
222
+ changes most ground layers on every frame. Measured in Chromium on Apple silicon at 1440 × 900 for
223
+ a detailed city map, such a sweep kept 76 frames a second; with the processor slowed four times, as
224
+ on a mid-range phone, it fell to about 11, against 28 for the same camera move without the sweep.
225
+ On slower devices, prefer short sweeps or move the position less often.
226
+
227
+ ## Camera moves and recordings
228
+
229
+ Some changes make MapLibre lay tiles out again: when the nearest theme changes, the values that
230
+ switch with it (icon names, layout values, and values that read feature data or feature state),
231
+ and each step of pattern or icon artwork that is mixed in pixels. A camera move or a screen
232
+ recording shows that work as dropped frames. `getBlend().relayoutAt` lists the positions where the
233
+ nearest theme changes over such values, so a sequence can be planned around them.
234
+
235
+ Pass `hold: true` to hold that work back. Colours, numbers, the sky, and light keep following the
236
+ position; the nearest theme, the values that switch with it, and mixed artwork wait.
237
+ `getBlend().held` reports whether anything waits. The next request without `hold` brings it in at
238
+ once, so make it while the camera rests:
239
+
240
+ ```ts
241
+ import type {TileflowThemeController} from '@tileflow/core/browser';
242
+ import type {TileflowRuntimeStyle} from '@tileflow/core/runtime';
243
+
244
+ export async function duskWhileFlying(
245
+ controller: TileflowThemeController,
246
+ themes: readonly TileflowRuntimeStyle[],
247
+ flight: Promise<void>,
248
+ ) {
249
+ // Through the camera move the ground darkens towards night with no layout work.
250
+ for (const position of [0.25, 0.5, 0.75])
251
+ await controller.setBlend({hold: true, position, themes});
252
+ await flight;
253
+ // The camera rests: labels, icons, and artwork follow at once.
254
+ await controller.setBlend({position: 0.75, themes});
255
+ }
256
+ ```
257
+
258
+ The React, Vue, and Svelte maps take the same flag in `themeBlend`: pass
259
+ `themeBlend={{hold: true, position, themes}}` while the camera moves and drop `hold` when it rests.
260
+ The React Native `Map` blends natively and does not take `hold`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tileflow/core",
3
- "version": "0.1.0-alpha.30",
3
+ "version": "0.1.0-alpha.32",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Typed Tileflow config and MapLibre style compiler.",
6
6
  "type": "module",