@tileflow/static 0.1.0-alpha.0 → 0.1.0-alpha.1
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 +9 -5
- package/dist/index.d.ts +7 -6
- package/dist/index.js +18 -32
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,13 +3,17 @@
|
|
|
3
3
|
Static map schemas, overlay helpers, and request utilities for Tileflow static map rendering.
|
|
4
4
|
|
|
5
5
|
```ts
|
|
6
|
-
import {
|
|
6
|
+
import {marker, precacheStaticMap, validateStaticScene} from '@tileflow/static';
|
|
7
7
|
|
|
8
8
|
const scene = validateStaticScene({
|
|
9
|
-
map:
|
|
10
|
-
camera: {
|
|
11
|
-
size: {
|
|
12
|
-
overlays: [marker({
|
|
9
|
+
map: 'madrid',
|
|
10
|
+
camera: {type: 'center', center: [-3.7038, 40.4168], zoom: 12},
|
|
11
|
+
size: {width: 1200, height: 800},
|
|
12
|
+
overlays: [marker({coordinate: [-3.7038, 40.4168]})],
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
await precacheStaticMap(scene.scene, {
|
|
16
|
+
apiKey: process.env.TILEFLOW_API_KEY,
|
|
13
17
|
});
|
|
14
18
|
```
|
|
15
19
|
|
package/dist/index.d.ts
CHANGED
|
@@ -202,17 +202,17 @@ type StaticMapResult = {
|
|
|
202
202
|
cached: boolean;
|
|
203
203
|
hash: string;
|
|
204
204
|
imageUrl: string;
|
|
205
|
-
status:
|
|
205
|
+
status: 'ready';
|
|
206
206
|
};
|
|
207
207
|
type StaticMapCreateOptions = {
|
|
208
208
|
apiKey?: string;
|
|
209
209
|
apiUrl?: string;
|
|
210
210
|
fetch?: typeof fetch;
|
|
211
211
|
};
|
|
212
|
-
declare function line(input: Omit<z.input<typeof lineOverlaySchema>,
|
|
213
|
-
declare function circle(input: Omit<z.input<typeof circleOverlaySchema>,
|
|
214
|
-
declare function marker(input: Omit<z.input<typeof markerOverlaySchema>,
|
|
215
|
-
declare function polygon(input: Omit<z.input<typeof polygonOverlaySchema>,
|
|
212
|
+
declare function line(input: Omit<z.input<typeof lineOverlaySchema>, 'type'>): StaticOverlay;
|
|
213
|
+
declare function circle(input: Omit<z.input<typeof circleOverlaySchema>, 'type'>): StaticOverlay;
|
|
214
|
+
declare function marker(input: Omit<z.input<typeof markerOverlaySchema>, 'type'>): StaticOverlay;
|
|
215
|
+
declare function polygon(input: Omit<z.input<typeof polygonOverlaySchema>, 'type'>): StaticOverlay;
|
|
216
216
|
declare function validateStaticScene(input: unknown): {
|
|
217
217
|
ok: true;
|
|
218
218
|
scene: StaticScene;
|
|
@@ -242,6 +242,7 @@ declare function compileStaticOverlays(overlays: StaticOverlay[]): {
|
|
|
242
242
|
sources: Record<string, Record<string, unknown>>;
|
|
243
243
|
};
|
|
244
244
|
declare function createStaticMap(scene: StaticSceneInput, options?: StaticMapCreateOptions): Promise<StaticMapResult>;
|
|
245
|
+
declare function precacheStaticMap(scene: StaticSceneInput, options?: StaticMapCreateOptions): Promise<StaticMapResult>;
|
|
245
246
|
declare function stableStringify(value: unknown): string;
|
|
246
247
|
|
|
247
|
-
export { type StaticCoordinate, type StaticMapCreateOptions, type StaticMapResult, type StaticOverlay, type StaticOverlayInput, type StaticRenderManifest, type StaticScene, type StaticSceneInput, circle, compileStaticOverlays, createRenderManifest, createStaticMap, hashRenderManifest, line, marker, normalizeStaticScene, polygon, stableStringify, staticOverlaySchema, staticRenderManifestSchema, staticRendererSchemaVersion, staticSceneLimits, staticSceneSchema, staticSceneSchemaVersion, validateStaticRenderManifest, validateStaticScene };
|
|
248
|
+
export { type StaticCoordinate, type StaticMapCreateOptions, type StaticMapResult, type StaticOverlay, type StaticOverlayInput, type StaticRenderManifest, type StaticScene, type StaticSceneInput, circle, compileStaticOverlays, createRenderManifest, createStaticMap, hashRenderManifest, line, marker, normalizeStaticScene, polygon, precacheStaticMap, stableStringify, staticOverlaySchema, staticRenderManifestSchema, staticRendererSchemaVersion, staticSceneLimits, staticSceneSchema, staticSceneSchemaVersion, validateStaticRenderManifest, validateStaticScene };
|
package/dist/index.js
CHANGED
|
@@ -10,12 +10,9 @@ var staticSceneLimits = {
|
|
|
10
10
|
maxPhysicalPixels: 1280 * 1280,
|
|
11
11
|
minDimension: 64
|
|
12
12
|
};
|
|
13
|
-
var coordinateSchema = z.tuple([z.number().finite(), z.number().finite()]).refine(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
message: "Expected [lng, lat] within world bounds"
|
|
17
|
-
}
|
|
18
|
-
);
|
|
13
|
+
var coordinateSchema = z.tuple([z.number().finite(), z.number().finite()]).refine(([lng, lat]) => lng >= -180 && lng <= 180 && lat >= -90 && lat <= 90, {
|
|
14
|
+
message: "Expected [lng, lat] within world bounds"
|
|
15
|
+
});
|
|
19
16
|
var colorSchema = z.string().regex(/^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/, {
|
|
20
17
|
message: "Expected a hex color like #C6A15B"
|
|
21
18
|
});
|
|
@@ -37,12 +34,7 @@ var centerCameraSchema = z.object({
|
|
|
37
34
|
});
|
|
38
35
|
var boundsCameraSchema = z.object({
|
|
39
36
|
bearing: z.number().finite().min(-180).max(180).optional(),
|
|
40
|
-
bounds: z.tuple([
|
|
41
|
-
z.number().finite(),
|
|
42
|
-
z.number().finite(),
|
|
43
|
-
z.number().finite(),
|
|
44
|
-
z.number().finite()
|
|
45
|
-
]).refine(
|
|
37
|
+
bounds: z.tuple([z.number().finite(), z.number().finite(), z.number().finite(), z.number().finite()]).refine(
|
|
46
38
|
([west, south, east, north]) => west >= -180 && west <= 180 && east >= -180 && east <= 180 && south >= -90 && south <= 90 && north >= -90 && north <= 90 && west !== east && south !== north,
|
|
47
39
|
{ message: "Expected bounds as [west, south, east, north]" }
|
|
48
40
|
),
|
|
@@ -79,9 +71,7 @@ var markerOverlaySchema = z.object({
|
|
|
79
71
|
type: z.literal("marker")
|
|
80
72
|
});
|
|
81
73
|
var polygonOverlaySchema = z.object({
|
|
82
|
-
coordinates: z.array(
|
|
83
|
-
z.array(coordinateSchema).min(4).max(staticSceneLimits.maxPathCoordinates)
|
|
84
|
-
).min(1).max(16),
|
|
74
|
+
coordinates: z.array(z.array(coordinateSchema).min(4).max(staticSceneLimits.maxPathCoordinates)).min(1).max(16),
|
|
85
75
|
fill: colorSchema.default("#C6A15B"),
|
|
86
76
|
id: z.string().trim().min(1).max(64).optional(),
|
|
87
77
|
opacity: z.number().finite().min(0).max(1).default(0.28),
|
|
@@ -96,10 +86,7 @@ var staticOverlaySchema = z.discriminatedUnion("type", [
|
|
|
96
86
|
polygonOverlaySchema
|
|
97
87
|
]);
|
|
98
88
|
var staticSceneSchema = z.object({
|
|
99
|
-
camera: z.discriminatedUnion("type", [
|
|
100
|
-
centerCameraSchema,
|
|
101
|
-
boundsCameraSchema
|
|
102
|
-
]),
|
|
89
|
+
camera: z.discriminatedUnion("type", [centerCameraSchema, boundsCameraSchema]),
|
|
103
90
|
map: z.string().trim().min(1).max(128),
|
|
104
91
|
overlays: z.array(staticOverlaySchema).max(staticSceneLimits.maxOverlays).default([]),
|
|
105
92
|
size: sizeSchema
|
|
@@ -147,9 +134,7 @@ function validateStaticRenderManifest(input) {
|
|
|
147
134
|
const parsed = staticRenderManifestSchema.safeParse(input);
|
|
148
135
|
if (!parsed.success) {
|
|
149
136
|
return {
|
|
150
|
-
error: parsed.error.issues.map(
|
|
151
|
-
(issue) => `${issue.path.join(".") || "manifest"}: ${issue.message}`
|
|
152
|
-
).join("; "),
|
|
137
|
+
error: parsed.error.issues.map((issue) => `${issue.path.join(".") || "manifest"}: ${issue.message}`).join("; "),
|
|
153
138
|
ok: false
|
|
154
139
|
};
|
|
155
140
|
}
|
|
@@ -222,9 +207,7 @@ function compileStaticOverlays(overlays) {
|
|
|
222
207
|
const sources = {};
|
|
223
208
|
const layers = [];
|
|
224
209
|
for (const [index, overlay] of overlays.entries()) {
|
|
225
|
-
const id = safeLayerId(
|
|
226
|
-
`overlay-${index + 1}-${overlay.id ?? overlay.type}`
|
|
227
|
-
);
|
|
210
|
+
const id = safeLayerId(`overlay-${index + 1}-${overlay.id ?? overlay.type}`);
|
|
228
211
|
const sourceId = `${id}-source`;
|
|
229
212
|
if (overlay.type === "line") {
|
|
230
213
|
sources[sourceId] = {
|
|
@@ -292,6 +275,12 @@ function compileStaticOverlays(overlays) {
|
|
|
292
275
|
return { layers, sources };
|
|
293
276
|
}
|
|
294
277
|
async function createStaticMap(scene, options = {}) {
|
|
278
|
+
return requestStaticMap(scene, options, "/v1/static/maps");
|
|
279
|
+
}
|
|
280
|
+
async function precacheStaticMap(scene, options = {}) {
|
|
281
|
+
return requestStaticMap(scene, options, "/v1/static/maps/precache");
|
|
282
|
+
}
|
|
283
|
+
async function requestStaticMap(scene, options, path) {
|
|
295
284
|
const validation = validateStaticScene(scene);
|
|
296
285
|
if (!validation.ok) {
|
|
297
286
|
throw new Error(`Invalid Tileflow static scene: ${validation.error}`);
|
|
@@ -304,7 +293,7 @@ async function createStaticMap(scene, options = {}) {
|
|
|
304
293
|
if (options.apiKey) {
|
|
305
294
|
headers.Authorization = `Bearer ${options.apiKey}`;
|
|
306
295
|
}
|
|
307
|
-
const response = await fetcher(`${apiUrl}
|
|
296
|
+
const response = await fetcher(`${apiUrl}${path}`, {
|
|
308
297
|
body: JSON.stringify(validation.scene),
|
|
309
298
|
headers,
|
|
310
299
|
method: "POST"
|
|
@@ -322,9 +311,7 @@ function normalizeOverlay(overlay) {
|
|
|
322
311
|
const parsed = staticOverlaySchema.parse(overlay);
|
|
323
312
|
const normalized = stripUndefined({ ...parsed });
|
|
324
313
|
if ("coordinate" in normalized) {
|
|
325
|
-
normalized.coordinate = normalizeCoordinate(
|
|
326
|
-
normalized.coordinate
|
|
327
|
-
);
|
|
314
|
+
normalized.coordinate = normalizeCoordinate(normalized.coordinate);
|
|
328
315
|
}
|
|
329
316
|
if ("coordinates" in normalized) {
|
|
330
317
|
normalized.coordinates = normalizeCoordinates(normalized.coordinates);
|
|
@@ -350,9 +337,7 @@ function stripUndefined(value) {
|
|
|
350
337
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
351
338
|
return value;
|
|
352
339
|
}
|
|
353
|
-
return Object.fromEntries(
|
|
354
|
-
Object.entries(value).filter(([, entry]) => entry !== void 0)
|
|
355
|
-
);
|
|
340
|
+
return Object.fromEntries(Object.entries(value).filter(([, entry]) => entry !== void 0));
|
|
356
341
|
}
|
|
357
342
|
function sortJson(value) {
|
|
358
343
|
if (Array.isArray(value)) {
|
|
@@ -398,6 +383,7 @@ export {
|
|
|
398
383
|
marker,
|
|
399
384
|
normalizeStaticScene,
|
|
400
385
|
polygon,
|
|
386
|
+
precacheStaticMap,
|
|
401
387
|
stableStringify,
|
|
402
388
|
staticOverlaySchema,
|
|
403
389
|
staticRenderManifestSchema,
|