<!DOCTYPE html>
<html>
<head>
<title>Mapa z trasą</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Leaflet CSS -->
<link rel="stylesheet" href="https://unpkg.com/leaflet/dist/leaflet.css" />
<style>
#map {
height: 600px;
width: 100%;
}
</style>
</head>
<body>
<div id="map"></div>
<!-- Leaflet JS -->
<script src="https://unpkg.com/leaflet/dist/leaflet.js"></script>
<script>
// 1. Inicjalizacja mapy w elemencie #map
var map = L.map('map').setView([52.2297, 21.0122], 13); // Warszawa jako przykład
// 2. Dodanie kafelków mapy (OpenStreetMap)
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap contributors'
}).addTo(map);
// 3. Definicja punktów trasy (lat, lng)
var points = [
[52.2297, 21.0122],
[52.2305, 21.0150],
[52.2310, 21.0180],
[52.2320, 21.0200],
[52.2330, 21.0220],
[52.2340, 21.0250],
[52.2350, 21.0270],
[52.2360, 21.0300],
[52.2370, 21.0320],
[52.2380, 21.0350]
];
// 4. Dodanie markerów dla każdego punktu
points.forEach(function(point, index) {
L.marker(point).addTo(map)
.bindPopup("Punkt " + (index + 1));
});
// 5. Rysowanie trasy (Polyline)
var polyline = L.polyline(points, {color: 'red', weight: 4}).addTo(map);
// 6. Dopasowanie widoku mapy do całej trasy
map.fitBounds(polyline.getBounds());
</script>
</body>
</html>