feat(graph): add to web
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
# Кабинет: раздел Граф + инструкции
|
||||||
|
|
||||||
|
Нав «Граф» → `/graph`: выбор округа, bbox, токен, превью метаданных/рёбер, копируемые URL.
|
||||||
|
Инструкции: отдельный блок (meta/nodes/edges, curl, fetch+пагинация).
|
||||||
|
`GET /api/v1/sources` → `graphReady`.
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using TileServer.Application.Configuration;
|
using TileServer.Application.Configuration;
|
||||||
|
using TileServer.Application.Graph;
|
||||||
using TileServer.Application.Tiles;
|
using TileServer.Application.Tiles;
|
||||||
using TileServer.Domain;
|
using TileServer.Domain;
|
||||||
using TileServer.Domain.Exceptions;
|
using TileServer.Domain.Exceptions;
|
||||||
@@ -12,6 +13,7 @@ public sealed class ExtractService(
|
|||||||
IExtractCatalog catalog,
|
IExtractCatalog catalog,
|
||||||
IExtractStateStore stateStore,
|
IExtractStateStore stateStore,
|
||||||
ITileStore tileStore,
|
ITileStore tileStore,
|
||||||
|
IRoadGraphStore roadGraphStore,
|
||||||
IOptions<TileServerOptions> options) : IExtractService
|
IOptions<TileServerOptions> options) : IExtractService
|
||||||
{
|
{
|
||||||
public async Task<IReadOnlyList<ExtractResponse>> ListAsync(string baseUrl, CancellationToken ct)
|
public async Task<IReadOnlyList<ExtractResponse>> ListAsync(string baseUrl, CancellationToken ct)
|
||||||
@@ -88,6 +90,7 @@ public sealed class ExtractService(
|
|||||||
state.BuiltAt,
|
state.BuiltAt,
|
||||||
state.PbfBytes,
|
state.PbfBytes,
|
||||||
state.LastError,
|
state.LastError,
|
||||||
bounds);
|
bounds,
|
||||||
|
roadGraphStore.Exists(extract.Id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,8 @@ public sealed record ExtractResponse(
|
|||||||
DateTimeOffset? BuiltAt,
|
DateTimeOffset? BuiltAt,
|
||||||
long? PbfBytes,
|
long? PbfBytes,
|
||||||
string? LastError,
|
string? LastError,
|
||||||
TilesetBounds? Bounds);
|
TilesetBounds? Bounds,
|
||||||
|
bool GraphReady);
|
||||||
|
|
||||||
public sealed record TilesetBounds(double MinLon, double MinLat, double MaxLon, double MaxLat);
|
public sealed record TilesetBounds(double MinLon, double MinLat, double MaxLon, double MaxLat);
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { StylesPage } from "./features/styles/StylesPage";
|
|||||||
import { StyleEditorPage } from "./features/styles/StyleEditorPage";
|
import { StyleEditorPage } from "./features/styles/StyleEditorPage";
|
||||||
import { TokensPage } from "./features/tokens/TokensPage";
|
import { TokensPage } from "./features/tokens/TokensPage";
|
||||||
import { GuidesPage } from "./features/guides/GuidesPage";
|
import { GuidesPage } from "./features/guides/GuidesPage";
|
||||||
|
import { GraphPage } from "./features/graph/GraphPage";
|
||||||
import { CookieBanner } from "./legal/CookieBanner";
|
import { CookieBanner } from "./legal/CookieBanner";
|
||||||
import { LegalPage } from "./legal/LegalPage";
|
import { LegalPage } from "./legal/LegalPage";
|
||||||
|
|
||||||
@@ -66,6 +67,14 @@ export function App() {
|
|||||||
</Guard>
|
</Guard>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
<Route
|
||||||
|
path="/graph"
|
||||||
|
element={
|
||||||
|
<Guard>
|
||||||
|
<GraphPage />
|
||||||
|
</Guard>
|
||||||
|
}
|
||||||
|
/>
|
||||||
<Route
|
<Route
|
||||||
path="/tokens"
|
path="/tokens"
|
||||||
element={
|
element={
|
||||||
|
|||||||
@@ -88,6 +88,14 @@ export type SourceItem = {
|
|||||||
name: string;
|
name: string;
|
||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
center: number[];
|
center: number[];
|
||||||
|
status?: string;
|
||||||
|
graphReady?: boolean;
|
||||||
|
bounds?: {
|
||||||
|
minLon: number;
|
||||||
|
minLat: number;
|
||||||
|
maxLon: number;
|
||||||
|
maxLat: number;
|
||||||
|
} | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const api = {
|
export const api = {
|
||||||
|
|||||||
@@ -2,5 +2,6 @@ export const PRIMARY_NAV = [
|
|||||||
{ id: "overview", to: "/", label: "Обзор", soon: false },
|
{ id: "overview", to: "/", label: "Обзор", soon: false },
|
||||||
{ id: "guides", to: "/guides", label: "Инструкции", soon: false },
|
{ id: "guides", to: "/guides", label: "Инструкции", soon: false },
|
||||||
{ id: "styles", to: "/styles", label: "Стили", soon: false },
|
{ id: "styles", to: "/styles", label: "Стили", soon: false },
|
||||||
|
{ id: "graph", to: "/graph", label: "Граф", soon: false },
|
||||||
{ id: "tokens", to: "/tokens", label: "Токены", soon: false },
|
{ id: "tokens", to: "/tokens", label: "Токены", soon: false },
|
||||||
] as const;
|
] as const;
|
||||||
|
|||||||
@@ -0,0 +1,305 @@
|
|||||||
|
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||||
|
import { Link } from "react-router-dom";
|
||||||
|
import {
|
||||||
|
api,
|
||||||
|
getPreviewToken,
|
||||||
|
setPreviewToken,
|
||||||
|
type SourceItem
|
||||||
|
} from "../../api";
|
||||||
|
import { Button, Flash, PageHeader, Section } from "../../components/ui";
|
||||||
|
import { AppSelect, AppTextField } from "../../ui";
|
||||||
|
import { useAuth } from "../auth/AuthContext";
|
||||||
|
import "./graph.css";
|
||||||
|
|
||||||
|
type GraphMeta = {
|
||||||
|
extractId: string;
|
||||||
|
nodeCount: number;
|
||||||
|
edgeCount: number;
|
||||||
|
bounds?: { minLon: number; minLat: number; maxLon: number; maxLat: number } | null;
|
||||||
|
builtAt: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
type GraphEdge = {
|
||||||
|
id: number;
|
||||||
|
fromId: number;
|
||||||
|
toId: number;
|
||||||
|
highway: string;
|
||||||
|
name?: string | null;
|
||||||
|
oneway: boolean;
|
||||||
|
lengthM: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
type GraphPage<T> = {
|
||||||
|
items: T[];
|
||||||
|
nextAfter?: number | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
function formatNumber(value: number): string {
|
||||||
|
return value.toLocaleString("ru-RU");
|
||||||
|
}
|
||||||
|
|
||||||
|
function CopyField({ label, value }: { label: string; value: string }) {
|
||||||
|
const [copied, setCopied] = useState(false);
|
||||||
|
return (
|
||||||
|
<figure className="graph-copy">
|
||||||
|
<figcaption>
|
||||||
|
<span>{label}</span>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => {
|
||||||
|
void navigator.clipboard.writeText(value).then(() => {
|
||||||
|
setCopied(true);
|
||||||
|
window.setTimeout(() => setCopied(false), 1400);
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{copied ? "скопировано" : "копировать"}
|
||||||
|
</button>
|
||||||
|
</figcaption>
|
||||||
|
<pre>{value}</pre>
|
||||||
|
</figure>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function defaultBbox(center: number[] | undefined): string {
|
||||||
|
const lon = center?.[0] ?? 37.6173;
|
||||||
|
const lat = center?.[1] ?? 55.7558;
|
||||||
|
const d = 0.08;
|
||||||
|
return `${(lon - d).toFixed(4)},${(lat - d).toFixed(4)},${(lon + d).toFixed(4)},${(lat + d).toFixed(4)}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function GraphPage() {
|
||||||
|
const { user } = useAuth();
|
||||||
|
const [sources, setSources] = useState<SourceItem[]>([]);
|
||||||
|
const [sourceId, setSourceId] = useState("");
|
||||||
|
const [bbox, setBbox] = useState("37.5373,55.6758,37.6973,55.8358");
|
||||||
|
const [token, setToken] = useState(() => getPreviewToken() ?? "");
|
||||||
|
const [meta, setMeta] = useState<GraphMeta | null>(null);
|
||||||
|
const [edges, setEdges] = useState<GraphEdge[]>([]);
|
||||||
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [creating, setCreating] = useState(false);
|
||||||
|
|
||||||
|
const source = sources.find((item) => item.id === sourceId) ?? sources[0];
|
||||||
|
const slug = user?.slug ?? "{slug}";
|
||||||
|
const origin = window.location.origin;
|
||||||
|
const activeToken = token.trim() || "ts_…";
|
||||||
|
|
||||||
|
const urls = useMemo(() => {
|
||||||
|
const id = source?.id ?? "central-fed-district";
|
||||||
|
const q = `token=${encodeURIComponent(activeToken)}`;
|
||||||
|
return {
|
||||||
|
meta: `${origin}/u/${slug}/graph/${id}?${q}`,
|
||||||
|
nodes: `${origin}/u/${slug}/graph/${id}/nodes?bbox=${bbox}&${q}`,
|
||||||
|
edges: `${origin}/u/${slug}/graph/${id}/edges?bbox=${bbox}&limit=50&${q}`
|
||||||
|
};
|
||||||
|
}, [origin, slug, source?.id, bbox, activeToken]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
void api
|
||||||
|
.sources()
|
||||||
|
.then((list) => {
|
||||||
|
const enabled = list.filter((item) => item.enabled);
|
||||||
|
setSources(enabled);
|
||||||
|
setSourceId((current) => {
|
||||||
|
if (current && enabled.some((item) => item.id === current)) {
|
||||||
|
return current;
|
||||||
|
}
|
||||||
|
return enabled[0]?.id ?? "";
|
||||||
|
});
|
||||||
|
const first = enabled[0];
|
||||||
|
if (first) {
|
||||||
|
setBbox(defaultBbox(first.center));
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((err: unknown) => setError(err instanceof Error ? err.message : "Не удалось загрузить источники"));
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const loadGraph = useCallback(async () => {
|
||||||
|
if (!user || !source) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const secret = token.trim();
|
||||||
|
if (!secret) {
|
||||||
|
setError("Нужен токен — создайте в «Токены» или вставьте сюда.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setLoading(true);
|
||||||
|
setError(null);
|
||||||
|
const q = `token=${encodeURIComponent(secret)}`;
|
||||||
|
const metaUrl = `${origin}/u/${user.slug}/graph/${source.id}?${q}`;
|
||||||
|
const edgesUrl = `${origin}/u/${user.slug}/graph/${source.id}/edges?bbox=${encodeURIComponent(bbox)}&limit=50&${q}`;
|
||||||
|
try {
|
||||||
|
const metaRes = await fetch(metaUrl);
|
||||||
|
if (!metaRes.ok) {
|
||||||
|
const text = await metaRes.text();
|
||||||
|
throw new Error(text || `${metaRes.status} ${metaRes.statusText}`);
|
||||||
|
}
|
||||||
|
const nextMeta = (await metaRes.json()) as GraphMeta;
|
||||||
|
setMeta(nextMeta);
|
||||||
|
|
||||||
|
const edgesRes = await fetch(edgesUrl);
|
||||||
|
if (!edgesRes.ok) {
|
||||||
|
const text = await edgesRes.text();
|
||||||
|
throw new Error(text || `${edgesRes.status} ${edgesRes.statusText}`);
|
||||||
|
}
|
||||||
|
const page = (await edgesRes.json()) as GraphPage<GraphEdge>;
|
||||||
|
setEdges(page.items ?? []);
|
||||||
|
} catch (err: unknown) {
|
||||||
|
setMeta(null);
|
||||||
|
setEdges([]);
|
||||||
|
setError(err instanceof Error ? err.message : "Не удалось загрузить граф");
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
}, [user, source, token, origin, bbox]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="graph-page">
|
||||||
|
<PageHeader
|
||||||
|
eyebrow="Данные"
|
||||||
|
title="Граф дорог"
|
||||||
|
description="Лёгкий граф из OSM highway=* рядом с тайлами. Только персональный URL и токен."
|
||||||
|
/>
|
||||||
|
<Flash error={error} />
|
||||||
|
|
||||||
|
<Section title="Источник и bbox" description="Сторона bbox ≤ 2°. Вокруг центра округа — удобная стартовая рамка.">
|
||||||
|
<div className="form-row graph-page__row">
|
||||||
|
<AppSelect
|
||||||
|
id="graph-source"
|
||||||
|
label="Округ"
|
||||||
|
value={source?.id ?? ""}
|
||||||
|
onChange={(e) => {
|
||||||
|
const next = e.target.value;
|
||||||
|
setSourceId(next);
|
||||||
|
const item = sources.find((s) => s.id === next);
|
||||||
|
setBbox(defaultBbox(item?.center));
|
||||||
|
setMeta(null);
|
||||||
|
setEdges([]);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{sources.map((item) => (
|
||||||
|
<option key={item.id} value={item.id}>
|
||||||
|
{item.name}
|
||||||
|
{item.graphReady === false ? " (граф ещё нет)" : ""}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</AppSelect>
|
||||||
|
<AppTextField
|
||||||
|
id="graph-bbox"
|
||||||
|
label="bbox minLon,minLat,maxLon,maxLat"
|
||||||
|
value={bbox}
|
||||||
|
onChange={(e) => setBbox(e.target.value.trim())}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="form-row graph-page__row">
|
||||||
|
<AppTextField
|
||||||
|
id="graph-token"
|
||||||
|
label="Токен ts_…"
|
||||||
|
value={token}
|
||||||
|
onChange={(e) => {
|
||||||
|
const value = e.target.value.trim();
|
||||||
|
setToken(value);
|
||||||
|
if (value.startsWith("ts_")) {
|
||||||
|
setPreviewToken(value);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
placeholder="ts_…"
|
||||||
|
/>
|
||||||
|
<Button variant="primary" disabled={loading || !source} onClick={() => void loadGraph()}>
|
||||||
|
{loading ? "Загрузка…" : "Загрузить превью"}
|
||||||
|
</Button>
|
||||||
|
{!token ? (
|
||||||
|
<Button
|
||||||
|
variant="secondary"
|
||||||
|
disabled={creating}
|
||||||
|
onClick={() => {
|
||||||
|
setCreating(true);
|
||||||
|
void api
|
||||||
|
.createToken("Граф")
|
||||||
|
.then((created) => {
|
||||||
|
setPreviewToken(created.token);
|
||||||
|
setToken(created.token);
|
||||||
|
})
|
||||||
|
.catch((err: unknown) => setError(err instanceof Error ? err.message : "Не удалось создать токен"))
|
||||||
|
.finally(() => setCreating(false));
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Создать токен
|
||||||
|
</Button>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
{source?.graphReady === false ? (
|
||||||
|
<p className="graph-page__hint">
|
||||||
|
Для «{source.name}» граф ещё не собран. Дождитесь sync или вызовите{" "}
|
||||||
|
<code>POST /api/v1/sync/{source.id}</code> — тайлы пересобирать не обязательно.
|
||||||
|
</p>
|
||||||
|
) : null}
|
||||||
|
</Section>
|
||||||
|
|
||||||
|
<Section title="URL">
|
||||||
|
<CopyField label="Метаданные" value={urls.meta} />
|
||||||
|
<CopyField label="Узлы" value={urls.nodes} />
|
||||||
|
<CopyField label="Рёбра" value={urls.edges} />
|
||||||
|
<p className="graph-page__hint">
|
||||||
|
Примеры кода и контракт ответа — в <Link to="/guides">Инструкциях</Link>, блок «Граф дорог».
|
||||||
|
</p>
|
||||||
|
</Section>
|
||||||
|
|
||||||
|
{meta ? (
|
||||||
|
<Section title="Метаданные">
|
||||||
|
<dl className="graph-meta">
|
||||||
|
<div>
|
||||||
|
<dt>Extract</dt>
|
||||||
|
<dd>{meta.extractId}</dd>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<dt>Узлы</dt>
|
||||||
|
<dd>{formatNumber(meta.nodeCount)}</dd>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<dt>Рёбра</dt>
|
||||||
|
<dd>{formatNumber(meta.edgeCount)}</dd>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<dt>Собран</dt>
|
||||||
|
<dd>{new Date(meta.builtAt).toLocaleString("ru-RU")}</dd>
|
||||||
|
</div>
|
||||||
|
</dl>
|
||||||
|
</Section>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
{edges.length > 0 ? (
|
||||||
|
<Section title={`Рёбра в bbox (${edges.length})`}>
|
||||||
|
<table className="data-table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>id</th>
|
||||||
|
<th>from → to</th>
|
||||||
|
<th>highway</th>
|
||||||
|
<th>имя</th>
|
||||||
|
<th>м</th>
|
||||||
|
<th>oneway</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{edges.map((edge) => (
|
||||||
|
<tr key={edge.id}>
|
||||||
|
<td>{edge.id}</td>
|
||||||
|
<td>
|
||||||
|
{edge.fromId} → {edge.toId}
|
||||||
|
</td>
|
||||||
|
<td>{edge.highway}</td>
|
||||||
|
<td>{edge.name ?? "—"}</td>
|
||||||
|
<td>{Math.round(edge.lengthM)}</td>
|
||||||
|
<td>{edge.oneway ? "да" : "нет"}</td>
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</Section>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
.graph-page {
|
||||||
|
width: min(960px, 100%);
|
||||||
|
margin: 0 auto;
|
||||||
|
padding-bottom: var(--space-8);
|
||||||
|
}
|
||||||
|
|
||||||
|
.graph-page__row {
|
||||||
|
align-items: end;
|
||||||
|
}
|
||||||
|
|
||||||
|
.graph-page__hint {
|
||||||
|
margin: var(--space-3) 0 0;
|
||||||
|
color: var(--secondary-label);
|
||||||
|
font-size: var(--text-footnote);
|
||||||
|
}
|
||||||
|
|
||||||
|
.graph-page__hint code {
|
||||||
|
font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
|
||||||
|
}
|
||||||
|
|
||||||
|
.graph-copy {
|
||||||
|
margin: 0 0 var(--space-3);
|
||||||
|
border-radius: var(--radius-lg);
|
||||||
|
overflow: hidden;
|
||||||
|
background: #11161c;
|
||||||
|
color: #e8eef4;
|
||||||
|
}
|
||||||
|
|
||||||
|
.graph-copy figcaption {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
padding: 8px 12px;
|
||||||
|
font-size: var(--text-caption1);
|
||||||
|
letter-spacing: 0.04em;
|
||||||
|
text-transform: uppercase;
|
||||||
|
color: rgb(232 238 244 / 55%);
|
||||||
|
border-bottom: 1px solid rgb(255 255 255 / 8%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.graph-copy button {
|
||||||
|
border: 0;
|
||||||
|
background: transparent;
|
||||||
|
color: #3cd68c;
|
||||||
|
cursor: pointer;
|
||||||
|
text-transform: none;
|
||||||
|
letter-spacing: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.graph-copy pre {
|
||||||
|
margin: 0;
|
||||||
|
padding: 12px 14px 14px;
|
||||||
|
overflow: auto;
|
||||||
|
font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
|
||||||
|
font-size: 12.5px;
|
||||||
|
line-height: 1.45;
|
||||||
|
white-space: pre-wrap;
|
||||||
|
word-break: break-all;
|
||||||
|
}
|
||||||
|
|
||||||
|
.graph-meta {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr));
|
||||||
|
gap: var(--space-3);
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.graph-meta div {
|
||||||
|
padding: var(--space-3);
|
||||||
|
border-radius: var(--radius-lg);
|
||||||
|
background: var(--grouped-background);
|
||||||
|
}
|
||||||
|
|
||||||
|
.graph-meta dt {
|
||||||
|
margin: 0 0 4px;
|
||||||
|
font-size: var(--text-caption1);
|
||||||
|
letter-spacing: 0.04em;
|
||||||
|
text-transform: uppercase;
|
||||||
|
color: var(--secondary-label);
|
||||||
|
}
|
||||||
|
|
||||||
|
.graph-meta dd {
|
||||||
|
margin: 0;
|
||||||
|
font-size: var(--text-title3);
|
||||||
|
letter-spacing: -0.02em;
|
||||||
|
}
|
||||||
@@ -38,6 +38,7 @@ export function GuidesPage() {
|
|||||||
const source = sources[0]?.id ?? "central-fed-district";
|
const source = sources[0]?.id ?? "central-fed-district";
|
||||||
const origin = window.location.origin;
|
const origin = window.location.origin;
|
||||||
const slug = user?.slug ?? "{slug}";
|
const slug = user?.slug ?? "{slug}";
|
||||||
|
const tokenSuffix = token ? `token=${token}` : "token=ts_…";
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
void api
|
void api
|
||||||
@@ -46,10 +47,11 @@ export function GuidesPage() {
|
|||||||
.catch((err: unknown) => setError(err instanceof Error ? err.message : "Не удалось загрузить источники"));
|
.catch((err: unknown) => setError(err instanceof Error ? err.message : "Не удалось загрузить источники"));
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const styleUrl = `${origin}/u/${slug}/styles/osm-bright?source=${source}${token ? `&token=${token}` : "&token=ts_…"}`;
|
const styleUrl = `${origin}/u/${slug}/styles/osm-bright?source=${source}&${tokenSuffix}`;
|
||||||
const tilesUrl = `${origin}/u/${slug}/tiles/${source}/{z}/{x}/{y}.pbf?token=${token ?? "ts_…"}`;
|
const tilesUrl = `${origin}/u/${slug}/tiles/${source}/{z}/{x}/{y}.pbf?${tokenSuffix}`;
|
||||||
const graphUrl = `${origin}/u/${slug}/graph/${source}?token=${token ?? "ts_…"}`;
|
const graphUrl = `${origin}/u/${slug}/graph/${source}?${tokenSuffix}`;
|
||||||
const graphEdgesUrl = `${origin}/u/${slug}/graph/${source}/edges?bbox=37.5,55.7,37.7,55.8&token=${token ?? "ts_…"}`;
|
const graphNodesUrl = `${origin}/u/${slug}/graph/${source}/nodes?bbox=37.5,55.7,37.7,55.8&${tokenSuffix}`;
|
||||||
|
const graphEdgesUrl = `${origin}/u/${slug}/graph/${source}/edges?bbox=37.5,55.7,37.7,55.8&limit=100&${tokenSuffix}`;
|
||||||
|
|
||||||
const html = useMemo(
|
const html = useMemo(
|
||||||
() => `<link href="https://unpkg.com/maplibre-gl@5.6.1/dist/maplibre-gl.css" rel="stylesheet" />
|
() => `<link href="https://unpkg.com/maplibre-gl@5.6.1/dist/maplibre-gl.css" rel="stylesheet" />
|
||||||
@@ -79,6 +81,31 @@ const map = new maplibregl.Map({
|
|||||||
[styleUrl]
|
[styleUrl]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const graphFetch = useMemo(
|
||||||
|
() => `const token = "ts_…";
|
||||||
|
const source = "${source}";
|
||||||
|
const bbox = "37.5,55.7,37.7,55.8"; // minLon,minLat,maxLon,maxLat, сторона ≤ 2°
|
||||||
|
|
||||||
|
const meta = await fetch(\`/u/${slug}/graph/\${source}?token=\${token}\`).then((r) => r.json());
|
||||||
|
// { extractId, nodeCount, edgeCount, bounds, builtAt, links }
|
||||||
|
|
||||||
|
let after = 0;
|
||||||
|
const edges = [];
|
||||||
|
for (;;) {
|
||||||
|
const page = await fetch(
|
||||||
|
\`/u/${slug}/graph/\${source}/edges?bbox=\${bbox}&after=\${after}&limit=5000&token=\${token}\`
|
||||||
|
).then((r) => r.json());
|
||||||
|
edges.push(...page.items);
|
||||||
|
if (page.nextAfter == null) break;
|
||||||
|
after = page.nextAfter;
|
||||||
|
}
|
||||||
|
// page.items[]: { id, fromId, toId, highway, name, oneway, lengthM }
|
||||||
|
// oneway=false → ребро двустороннее (ездить можно в обе стороны)`,
|
||||||
|
[slug, source]
|
||||||
|
);
|
||||||
|
|
||||||
|
const graphCurl = `curl -s "${graphEdgesUrl}"`;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="guides">
|
<div className="guides">
|
||||||
<PageHeader
|
<PageHeader
|
||||||
@@ -91,7 +118,10 @@ const map = new maplibregl.Map({
|
|||||||
<ol className="guide-steps">
|
<ol className="guide-steps">
|
||||||
<li>
|
<li>
|
||||||
<strong>1. Токен</strong>
|
<strong>1. Токен</strong>
|
||||||
<p>В разделе «Токены» создайте ключ. Он показывается один раз и дальше уходит только в query <code>token=</code> или Bearer.</p>
|
<p>
|
||||||
|
В разделе <Link to="/tokens">Токены</Link> создайте ключ. Он показывается один раз и дальше уходит только в
|
||||||
|
query <code>token=</code> или Bearer.
|
||||||
|
</p>
|
||||||
{!token ? (
|
{!token ? (
|
||||||
<Button
|
<Button
|
||||||
variant="primary"
|
variant="primary"
|
||||||
@@ -123,7 +153,7 @@ const map = new maplibregl.Map({
|
|||||||
</p>
|
</p>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<strong>3. URL</strong>
|
<strong>3. URL карты</strong>
|
||||||
<p>MapLibre просит style JSON. Сервер сам подставит тайлы с тем же токеном.</p>
|
<p>MapLibre просит style JSON. Сервер сам подставит тайлы с тем же токеном.</p>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
@@ -136,20 +166,31 @@ const map = new maplibregl.Map({
|
|||||||
<li>
|
<li>
|
||||||
<strong>5. Граф дорог</strong>
|
<strong>5. Граф дорог</strong>
|
||||||
<p>
|
<p>
|
||||||
После sync рядом с тайлами лежит SQLite-граф (<code>highway=*</code>, рёбра между перекрёстками). Отдаётся только с
|
На sync из того же PBF собирается SQLite-граф (<code>highway</code> motorway…service): узлы — перекрёстки,
|
||||||
токеном. Узлы/рёбра — по <code>bbox</code> (≤ 2°), пагинация <code>after</code>.
|
рёбра — сегменты с <code>lengthM</code> и <code>oneway</code>. Смотреть и дергать API — в разделе{" "}
|
||||||
|
<Link to="/graph">Граф</Link>.
|
||||||
</p>
|
</p>
|
||||||
</li>
|
</li>
|
||||||
</ol>
|
</ol>
|
||||||
|
|
||||||
|
<h2 className="guides__h">Карта</h2>
|
||||||
<CopyBlock label="Style JSON" value={styleUrl} />
|
<CopyBlock label="Style JSON" value={styleUrl} />
|
||||||
<CopyBlock
|
<CopyBlock
|
||||||
label="Несколько округов"
|
label="Несколько округов"
|
||||||
value={`${origin}/u/${slug}/styles/osm-bright?source=${sources.map((item) => item.id).join(",") || "central-fed-district,volga-fed-district"}${token ? `&token=${token}` : "&token=ts_…"}`}
|
value={`${origin}/u/${slug}/styles/osm-bright?source=${sources.map((item) => item.id).join(",") || "central-fed-district,volga-fed-district"}&${tokenSuffix}`}
|
||||||
/>
|
/>
|
||||||
<CopyBlock label="Тайлы MVT" value={tilesUrl} />
|
<CopyBlock label="Тайлы MVT" value={tilesUrl} />
|
||||||
<CopyBlock label="Граф (метаданные)" value={graphUrl} />
|
|
||||||
<CopyBlock label="Граф: рёбра в bbox" value={graphEdgesUrl} />
|
<h2 className="guides__h">Граф дорог</h2>
|
||||||
|
<p className="guides__lead">
|
||||||
|
Только с токеном. Выгрузка всего округа целиком запрещена: всегда указывайте <code>bbox</code> (сторона ≤ 2°),
|
||||||
|
дальше листайте через <code>after</code> / <code>nextAfter</code>.
|
||||||
|
</p>
|
||||||
|
<CopyBlock label="Метаданные" value={graphUrl} />
|
||||||
|
<CopyBlock label="Узлы в bbox" value={graphNodesUrl} />
|
||||||
|
<CopyBlock label="Рёбра в bbox" value={graphEdgesUrl} />
|
||||||
|
<CopyBlock label="curl" value={graphCurl} />
|
||||||
|
<CopyBlock label="fetch + пагинация" value={graphFetch} />
|
||||||
|
|
||||||
<h2 className="guides__h">HTML</h2>
|
<h2 className="guides__h">HTML</h2>
|
||||||
<CopyBlock label="Минимальная страница" value={html} />
|
<CopyBlock label="Минимальная страница" value={html} />
|
||||||
|
|||||||
@@ -14,6 +14,17 @@
|
|||||||
letter-spacing: -0.02em;
|
letter-spacing: -0.02em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.guides__lead {
|
||||||
|
margin: 0 var(--gutter) var(--space-4);
|
||||||
|
color: var(--secondary-label);
|
||||||
|
font-size: var(--text-subhead);
|
||||||
|
}
|
||||||
|
|
||||||
|
.guides__lead code {
|
||||||
|
font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
|
||||||
|
font-size: 0.92em;
|
||||||
|
}
|
||||||
|
|
||||||
.guide-steps {
|
.guide-steps {
|
||||||
list-style: none;
|
list-style: none;
|
||||||
margin: 0 var(--gutter) var(--space-5);
|
margin: 0 var(--gutter) var(--space-5);
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ export function TokensPage() {
|
|||||||
<PageHeader
|
<PageHeader
|
||||||
eyebrow="Доступ"
|
eyebrow="Доступ"
|
||||||
title="Токены"
|
title="Токены"
|
||||||
description="Ключ показывается один раз. Им открывают персональные /u/{slug}/tiles и стили."
|
description="Ключ показывается один раз. Им открывают /u/{slug}/tiles, стили и граф дорог."
|
||||||
/>
|
/>
|
||||||
<Section title="Создать">
|
<Section title="Создать">
|
||||||
<div className="form-row">
|
<div className="form-row">
|
||||||
|
|||||||
@@ -66,7 +66,8 @@ export function DashboardPage() {
|
|||||||
/>
|
/>
|
||||||
<Section title="Подключение" description="Публичные стили и тайлы закрыты — только /u/{slug} и токен.">
|
<Section title="Подключение" description="Публичные стили и тайлы закрыты — только /u/{slug} и токен.">
|
||||||
<p className="section__desc" style={{ padding: 0 }}>
|
<p className="section__desc" style={{ padding: 0 }}>
|
||||||
Примеры кода, HTML и живая карта — в разделе <Link to="/guides">Инструкции</Link>.
|
Примеры кода — в <Link to="/guides">Инструкциях</Link>. Граф дорог — в разделе{" "}
|
||||||
|
<Link to="/graph">Граф</Link>.
|
||||||
</p>
|
</p>
|
||||||
</Section>
|
</Section>
|
||||||
<Section title="По дням">
|
<Section title="По дням">
|
||||||
|
|||||||
Reference in New Issue
Block a user