161 lines
3.9 KiB
HTML
161 lines
3.9 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<base target="_top">
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
|
|
<title>Quick Start - Leaflet</title>
|
|
|
|
<link rel="shortcut icon" type="image/x-icon" href="docs/images/favicon.ico" />
|
|
|
|
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY=" crossorigin=""/>
|
|
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js" integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo=" crossorigin=""></script>
|
|
|
|
<style>
|
|
html, body {
|
|
height: 100%;
|
|
margin: 0;
|
|
}
|
|
.leaflet-container {
|
|
height: 400px;
|
|
width: 600px;
|
|
max-width: 100%;
|
|
max-height: 100%;
|
|
}
|
|
</style>
|
|
|
|
|
|
</head>
|
|
<body>
|
|
|
|
|
|
|
|
<div id="map" style="width: 600px; height: 400px;"></div>
|
|
<script>
|
|
|
|
var Kennedyallee_18 = [
|
|
[50.7024044, 7.1522011],
|
|
[50.7024193, 7.152445],
|
|
[50.7025108, 7.152652],
|
|
[50.7026283, 7.1529199],
|
|
[50.7027407, 7.1532263],
|
|
[50.7028256, 7.1534808],
|
|
[50.7029354, 7.1538683],
|
|
[50.7030046, 7.1541476],
|
|
[50.703052, 7.1543684],
|
|
[50.7030948, 7.1545908],
|
|
[50.7031075, 7.1546643],
|
|
[50.7031221, 7.1547482],
|
|
[50.7031414, 7.1548639],
|
|
[50.7031773, 7.1550791],
|
|
[50.7032251, 7.155402],
|
|
[50.7032586, 7.1556214],
|
|
[50.7032865, 7.1558294],
|
|
[50.7033214, 7.1561731],
|
|
[50.7033291, 7.1562563],
|
|
[50.7033347, 7.1563181],
|
|
[50.7033544, 7.1565642],
|
|
[50.7033639, 7.1567531],
|
|
[50.7033734, 7.1570199],
|
|
[50.7033753, 7.1572494],
|
|
[50.7033735, 7.1576616],
|
|
[50.7033566, 7.1580302],
|
|
[50.703345, 7.1582227],
|
|
[50.7033307, 7.158379],
|
|
[50.7033174, 7.1585524],
|
|
[50.7032707, 7.1589466],
|
|
[50.7032079, 7.1593587],
|
|
[50.7031844, 7.1594936],
|
|
[50.7031701, 7.1596051],
|
|
[50.7031391, 7.1597899],
|
|
[50.7030517, 7.1602379],
|
|
[50.7029535, 7.1607034],
|
|
[50.7028796, 7.1610266],
|
|
[50.7028348, 7.1612158],
|
|
[50.7028103, 7.1613202],
|
|
[50.7027092, 7.1617351],
|
|
[50.7026355, 7.1619778],
|
|
];
|
|
|
|
function getPixelsFor10Meters(map, latlng) {
|
|
var meters = 10;
|
|
|
|
// 1 Grad Länge in Metern an dieser Position
|
|
var metersPerDegreeLng = 111320 * Math.cos(latlng.lat * Math.PI / 180);
|
|
var lngDelta = meters / metersPerDegreeLng;
|
|
|
|
// Projektion ins globale Pixel-Koordinatensystem der Karte beim aktuellen Zoom
|
|
var p1 = map.project(latlng, map.getZoom());
|
|
var p2 = map.project(L.latLng(latlng.lat, latlng.lng + lngDelta), map.getZoom());
|
|
|
|
// Differenz als Pixelwert
|
|
return p1.distanceTo(p2);
|
|
}
|
|
|
|
const map = L.map('map').setView([51.505, -0.09], 13);
|
|
|
|
const tiles = L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
|
maxZoom: 19,
|
|
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
|
|
}).addTo(map);
|
|
|
|
/**
|
|
const marker = L.marker([51.5, -0.09]).addTo(map)
|
|
.bindPopup('<b>Hello world!</b><br />I am a popup.').openPopup();
|
|
|
|
const circle = L.circle([51.508, -0.11], {
|
|
color: 'red',
|
|
fillColor: '#f03',
|
|
fillOpacity: 0.5,
|
|
radius: 500
|
|
}).addTo(map).bindPopup('I am a circle.');
|
|
|
|
const polygon = L.polygon([
|
|
[51.509, -0.08],
|
|
[51.503, -0.06],
|
|
[51.51, -0.047]
|
|
]).addTo(map).bindPopup('I am a polygon.');
|
|
|
|
|
|
const popup = L.popup()
|
|
.setLatLng([51.513, -0.09])
|
|
.setContent('I am a standalone popup.')
|
|
.openOn(map);
|
|
|
|
function onMapClick(e) {
|
|
popup
|
|
.setLatLng(e.latlng)
|
|
.setContent(`You clicked the map at ${e.latlng.toString()}`)
|
|
.openOn(map);
|
|
}
|
|
|
|
map.on('click', onMapClick);
|
|
|
|
**/
|
|
|
|
// 2. Create the polyline and style it
|
|
var polyline = L.polyline(Kennedyallee_18, {
|
|
color: 'yellow',
|
|
weight: 10,
|
|
opacity: 0.7
|
|
}).addTo(map);
|
|
|
|
function onZoom(e) {
|
|
// Anwendung:
|
|
console.log("10 m in pixel:");
|
|
var pixelCount = getPixelsFor10Meters(map, map.getCenter());
|
|
console.log(pixelCount);
|
|
polyline.setStyle( { weight: 5*pixelCount });
|
|
}
|
|
map.on('zoom', onZoom);
|
|
|
|
map.fitBounds(polyline.getBounds());
|
|
|
|
</script>
|
|
|
|
|
|
|
|
</body>
|
|
</html>
|