Skip to content

Matrix ​

Times from two couriers to three entrances: who is nearest.

↗

Code ​

html
<!doctype html>
<html lang="mn">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Matrix</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); }
</style>
</head>
<body>
<div id="map"></div>
<div class="panel" id="out"></div>
<script>
  const client = new dock.Client({ key: 'dk_...' });
  const map = dock.createMap(client, { container: 'map', center: [106.9165, 47.8880], zoom: 15 });
  const couriers = [[106.9105, 47.8930], [106.9200, 47.8860]];
  const doors = [[106.9148664, 47.8874968], [106.9161926, 47.8877812], [106.9166933, 47.8877179]];
  for (const p of couriers) new dock.maplibregl.Marker({ color: '#d9541f' }).setLngLat(p).addTo(map);
  for (const p of doors) new dock.maplibregl.Marker({ color: '#1f6e63' }).setLngLat(p).addTo(map);
  client.matrix(couriers, doors).then((t) => {
    document.getElementById('out').innerHTML = t.durations_s.map((row, i) =>
      `Курьер ${i + 1}: ${row.map((s) => (s == null ? '—' : Math.round(s / 60) + ' мин')).join(', ')}`).join('<br>');
  });
</script>
</body>
</html>