Хөдөөгийн зам
Хиймэл дагуулаас хэмжсэн хөдөөгийн замын коридорууд, баримт бүр итгэлийн түвшинтэй.
Код
html
<!doctype html>
<html lang="mn">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Steppe tracks</title>
<link href="https://dock.mn/sdk/v1/dock.css" rel="stylesheet">
<script src="https://dock.mn/sdk/v1/dock.js"></script>
<style>
body { margin: 0; font: 14px system-ui, sans-serif; }
#map { position: absolute; inset: 0; }
.panel { position: absolute; top: 10px; left: 10px; z-index: 1; max-width: 300px; padding: 8px 10px;
background: #fff; border-radius: 6px; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25); }
.panel button { margin: 2px; }
</style>
</head>
<body>
<div id="map"></div>
<div class="panel"><div id="out"></div><p id="fact"></p></div>
<script>
const client = new dock.Client({ key: 'dk_...' });
const map = dock.createMap(client, { container: 'map', center: [104.5, 47.2], zoom: 5.5 });
const get = (path) => fetch(client.transformRequest(`${client.baseUrl}/v1/corridors${path}`).url).then((r) => r.json());
get('').then((all) => {
const list = document.getElementById('out');
for (const row of all.compare.rows) {
const b = document.createElement('button');
b.textContent = row.label ?? row.name;
b.onclick = async () => {
const c = await get(`/${row.name}`);
const at = c.facts.find((f) => f.point)?.point;
if (at) map.flyTo({ center: at, zoom: 11 });
const braided = c.facts.find((f) => f.key === 'braided_share');
document.getElementById('fact').textContent = braided ? braided.text : '';
};
list.append(b);
}
});
</script>
</body>
</html>