@tileflow/react 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 +10 -1
- package/dist/index.d.ts +6 -5
- package/dist/index.js +14 -38
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -3,11 +3,20 @@
|
|
|
3
3
|
React components for rendering Tileflow maps with MapLibre.
|
|
4
4
|
|
|
5
5
|
```tsx
|
|
6
|
-
import {
|
|
6
|
+
import {Map} from '@tileflow/react';
|
|
7
7
|
|
|
8
8
|
export function App() {
|
|
9
9
|
return <Map map="madrid" center={[-3.7038, 40.4168]} zoom={12} />;
|
|
10
10
|
}
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
+
For simple hosted static images, use image mode:
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
<Map map="madrid" mode="image" center={[-3.7038, 40.4168]} zoom={12} />
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
For full static scenes with bounds, overlays, and server-side precache, use
|
|
20
|
+
`StaticMap` from `@tileflow/react/static` or helpers from `@tileflow/static`.
|
|
21
|
+
|
|
13
22
|
Docs: https://tileflow.dev/docs
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { CSSProperties, ImgHTMLAttributes } from 'react';
|
|
3
|
-
import { TileflowConfig, MapLibreStyle } from '@tileflow/core';
|
|
4
3
|
import { Map as Map$1 } from 'maplibre-gl';
|
|
4
|
+
import { TileflowConfig, MapLibreStyle, TileflowThemeConfig } from '@tileflow/core';
|
|
5
5
|
|
|
6
6
|
type MapMarker = {
|
|
7
7
|
id: string;
|
|
@@ -22,26 +22,27 @@ type TileflowAnalytics = {
|
|
|
22
22
|
};
|
|
23
23
|
type MapProps = {
|
|
24
24
|
map?: string;
|
|
25
|
-
mode?:
|
|
25
|
+
mode?: 'interactive' | 'image';
|
|
26
26
|
config?: TileflowConfig;
|
|
27
27
|
style?: MapLibreStyle;
|
|
28
28
|
styleUrl?: string;
|
|
29
29
|
imageUrl?: string;
|
|
30
30
|
styleBaseUrl?: string;
|
|
31
31
|
tileBaseUrl?: string;
|
|
32
|
+
themes?: Record<string, TileflowThemeConfig>;
|
|
32
33
|
manifestUrl?: string;
|
|
33
34
|
preferLocalDev?: boolean;
|
|
34
35
|
alt?: string;
|
|
35
36
|
center?: [number, number];
|
|
36
37
|
zoom?: number;
|
|
37
38
|
className?: string;
|
|
38
|
-
height?: CSSProperties[
|
|
39
|
-
imageLoading?: ImgHTMLAttributes<HTMLImageElement>[
|
|
39
|
+
height?: CSSProperties['height'];
|
|
40
|
+
imageLoading?: ImgHTMLAttributes<HTMLImageElement>['loading'];
|
|
40
41
|
interactive?: boolean;
|
|
41
42
|
markers?: MapMarker[];
|
|
42
43
|
analytics?: TileflowAnalytics;
|
|
43
44
|
onLoad?: (map: Map$1) => void;
|
|
44
45
|
};
|
|
45
|
-
declare function Map({ map: mapName, mode, config, style, styleUrl, imageUrl, styleBaseUrl, tileBaseUrl, manifestUrl, preferLocalDev, alt, center, zoom, className, height, imageLoading, interactive, markers, analytics, onLoad, }: MapProps): react.JSX.Element;
|
|
46
|
+
declare function Map({ map: mapName, mode, config, style, styleUrl, imageUrl, styleBaseUrl, tileBaseUrl, themes, manifestUrl, preferLocalDev, alt, center, zoom, className, height, imageLoading, interactive, markers, analytics, onLoad, }: MapProps): react.JSX.Element;
|
|
46
47
|
|
|
47
48
|
export { Map, type MapMarker, type MapProps };
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
// src/map.tsx
|
|
2
|
-
import {
|
|
3
|
-
createStyle
|
|
4
|
-
} from "@tileflow/core";
|
|
5
|
-
import maplibregl from "maplibre-gl";
|
|
6
2
|
import {
|
|
7
3
|
useEffect,
|
|
8
4
|
useMemo,
|
|
9
5
|
useRef,
|
|
10
6
|
useState
|
|
11
7
|
} from "react";
|
|
8
|
+
import maplibregl from "maplibre-gl";
|
|
9
|
+
import {
|
|
10
|
+
createStyle
|
|
11
|
+
} from "@tileflow/core";
|
|
12
12
|
import { jsx } from "react/jsx-runtime";
|
|
13
13
|
var defaultCenter = [0, 20];
|
|
14
14
|
var defaultMarkers = [];
|
|
@@ -25,6 +25,7 @@ function Map({
|
|
|
25
25
|
imageUrl,
|
|
26
26
|
styleBaseUrl,
|
|
27
27
|
tileBaseUrl,
|
|
28
|
+
themes,
|
|
28
29
|
manifestUrl = defaultManifestUrl,
|
|
29
30
|
preferLocalDev = true,
|
|
30
31
|
alt = "",
|
|
@@ -41,30 +42,18 @@ function Map({
|
|
|
41
42
|
const containerRef = useRef(null);
|
|
42
43
|
const mapRef = useRef(null);
|
|
43
44
|
const sessionId = useMemo(() => createSessionId(), []);
|
|
44
|
-
const [manifestMap, setManifestMap] = useState(
|
|
45
|
-
null
|
|
46
|
-
);
|
|
45
|
+
const [manifestMap, setManifestMap] = useState(null);
|
|
47
46
|
const [imageSize, setImageSize] = useState(null);
|
|
48
47
|
const isImageMode = mode === "image";
|
|
49
48
|
const useExplicitStyleBaseUrl = useMemo(
|
|
50
|
-
() => Boolean(
|
|
51
|
-
!isImageMode && mapName && !style && !styleUrl && !config && styleBaseUrl
|
|
52
|
-
),
|
|
49
|
+
() => Boolean(!isImageMode && mapName && !style && !styleUrl && !config && styleBaseUrl),
|
|
53
50
|
[config, isImageMode, mapName, style, styleBaseUrl, styleUrl]
|
|
54
51
|
);
|
|
55
52
|
const useLocalDevFallback = useMemo(
|
|
56
53
|
() => Boolean(
|
|
57
54
|
!isImageMode && mapName && !style && !styleUrl && !config && !styleBaseUrl && preferLocalDev && isLocalDevHost()
|
|
58
55
|
),
|
|
59
|
-
[
|
|
60
|
-
config,
|
|
61
|
-
isImageMode,
|
|
62
|
-
mapName,
|
|
63
|
-
preferLocalDev,
|
|
64
|
-
style,
|
|
65
|
-
styleBaseUrl,
|
|
66
|
-
styleUrl
|
|
67
|
-
]
|
|
56
|
+
[config, isImageMode, mapName, preferLocalDev, style, styleBaseUrl, styleUrl]
|
|
68
57
|
);
|
|
69
58
|
useEffect(() => {
|
|
70
59
|
const shouldLoadManifest = Boolean(
|
|
@@ -79,9 +68,7 @@ function Map({
|
|
|
79
68
|
if (cancelled) {
|
|
80
69
|
return;
|
|
81
70
|
}
|
|
82
|
-
setManifestMap(
|
|
83
|
-
manifest ? resolveManifestMap(manifest, mapName) : null
|
|
84
|
-
);
|
|
71
|
+
setManifestMap(manifest ? resolveManifestMap(manifest, mapName) : null);
|
|
85
72
|
}).catch((error) => {
|
|
86
73
|
if (!cancelled) {
|
|
87
74
|
console.error("Failed to load Tileflow manifest", error);
|
|
@@ -133,7 +120,7 @@ function Map({
|
|
|
133
120
|
}
|
|
134
121
|
return null;
|
|
135
122
|
}
|
|
136
|
-
return { style: createStyle(config, { tileBaseUrl }) };
|
|
123
|
+
return { style: createStyle(config, { themes, tileBaseUrl }) };
|
|
137
124
|
}, [
|
|
138
125
|
config,
|
|
139
126
|
isImageMode,
|
|
@@ -142,6 +129,7 @@ function Map({
|
|
|
142
129
|
style,
|
|
143
130
|
styleBaseUrl,
|
|
144
131
|
styleUrl,
|
|
132
|
+
themes,
|
|
145
133
|
tileBaseUrl,
|
|
146
134
|
useExplicitStyleBaseUrl,
|
|
147
135
|
useLocalDevFallback
|
|
@@ -264,14 +252,7 @@ function Map({
|
|
|
264
252
|
}
|
|
265
253
|
) : null });
|
|
266
254
|
}
|
|
267
|
-
return /* @__PURE__ */ jsx(
|
|
268
|
-
"div",
|
|
269
|
-
{
|
|
270
|
-
className,
|
|
271
|
-
ref: containerRef,
|
|
272
|
-
style: frameStyle
|
|
273
|
-
}
|
|
274
|
-
);
|
|
255
|
+
return /* @__PURE__ */ jsx("div", { className, ref: containerRef, style: frameStyle });
|
|
275
256
|
}
|
|
276
257
|
function resolveStyleUrl(mapName, styleBaseUrl) {
|
|
277
258
|
const baseUrl = normalizeUrl(styleBaseUrl ?? getDefaultStyleBaseUrl());
|
|
@@ -429,9 +410,7 @@ function resolveStaticImageUrl(input) {
|
|
|
429
410
|
if (!input.manifestMap?.mapId || !input.imageSize) {
|
|
430
411
|
return void 0;
|
|
431
412
|
}
|
|
432
|
-
const apiUrl = normalizeUrl(
|
|
433
|
-
input.manifestMap.apiUrl ?? "https://api.tileflow.dev"
|
|
434
|
-
);
|
|
413
|
+
const apiUrl = normalizeUrl(input.manifestMap.apiUrl ?? "https://api.tileflow.dev");
|
|
435
414
|
const url = new URL(`/maps/${input.manifestMap.mapId}/static.png`, apiUrl);
|
|
436
415
|
url.searchParams.set("center", input.center.join(","));
|
|
437
416
|
url.searchParams.set("zoom", String(input.zoom));
|
|
@@ -454,10 +433,7 @@ function clampDimension(value) {
|
|
|
454
433
|
if (!Number.isFinite(value) || value <= 0) {
|
|
455
434
|
return 640;
|
|
456
435
|
}
|
|
457
|
-
return Math.max(
|
|
458
|
-
64,
|
|
459
|
-
Math.min(maxStaticImageDimension, Math.round(value))
|
|
460
|
-
);
|
|
436
|
+
return Math.max(64, Math.min(maxStaticImageDimension, Math.round(value)));
|
|
461
437
|
}
|
|
462
438
|
function inferAnalyticsFromStyleUrl(styleUrl) {
|
|
463
439
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tileflow/react",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.1",
|
|
4
4
|
"description": "React components for rendering Tileflow maps with MapLibre.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"homepage": "https://tileflow.dev",
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"access": "public"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@tileflow/
|
|
44
|
-
"@tileflow/
|
|
43
|
+
"@tileflow/static": "0.1.0-alpha.1",
|
|
44
|
+
"@tileflow/core": "0.1.0-alpha.1"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"maplibre-gl": ">=5",
|