Skip to content

Commit

Permalink
Fix zoom&bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
ringsaturn committed Sep 11, 2023
1 parent a3adaa6 commit 1b10a03
Showing 1 changed file with 87 additions and 70 deletions.
157 changes: 87 additions & 70 deletions internal/handler/template/click.html
Original file line number Diff line number Diff line change
@@ -1,90 +1,107 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>TZF Server Clickable Debugger</title>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />
<style>
html, body, #map {
height: 100%;
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<div id="map"></div>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>TZF Server Clickable Debugger</title>
<link
rel="stylesheet"
href="https://unpkg.com/[email protected]/dist/leaflet.css"
/>
<style>
html,
body,
#map {
height: 100%;
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<div id="map"></div>

<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
<script src="https://unpkg.com/[email protected]/dist/axios.min.js"></script>
<script>
var map = L.map('map').setView([40.7128, -74.0060], 5);
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
<script src="https://unpkg.com/[email protected]/dist/axios.min.js"></script>
<script>
var southWest = L.latLng(-90, -180);
var northEast = L.latLng(90, 180);
var bounds = L.latLngBounds(southWest, northEast);
var map = L.map("map", {
maxBounds: bounds,
maxBoundsViscosity: 1,
worldCopyJump: true,
maxZoom: 18,
minZoom: 3,
}).setView([40.7128, -74.006], 5);

L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: 'Map data &copy; <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors'
}).addTo(map);
L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
maxZoom: 19,
attribution:
'Map data &copy; <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors',
}).addTo(map);

var markers = [];
var polygons = [];
var markers = [];
var polygons = [];

map.on('click', function(e) {
var lng = e.latlng.wrap().lng.toFixed(4);
var lat = e.latlng.wrap().lat.toFixed(4);
map.on("click", function (e) {
var lng = e.latlng.wrap().lng.toFixed(4);
var lat = e.latlng.wrap().lat.toFixed(4);

axios.get('/api/v1/tz', {
params: {
lng: lng,
lat: lat
}
})
.then(function(response) {
var timezone = response.data.timezone;
var abbreviation = response.data.abbreviation;
var offset = response.data.offset;
var popupContent = `
axios
.get("/api/v1/tz", {
params: {
lng: lng,
lat: lat,
},
})
.then(function (response) {
var timezone = response.data.timezone;
var abbreviation = response.data.abbreviation;
var offset = response.data.offset;
var popupContent = `
<b>Timezone:</b> ${timezone}<br>
<b>Abbreviation:</b> ${abbreviation}<br>
<b>Offset:</b> ${offset}<br>
<b>Latitude:</b> ${lat}<br>
<b>Longitude:</b> ${lng}
`;

var marker = L.marker(e.latlng).addTo(map);
marker.bindPopup(popupContent).openPopup();
markers.push(marker);
})
.catch(function(error) {
console.error(error);
});
var marker = L.marker(e.latlng).addTo(map);
marker.bindPopup(popupContent).openPopup();
markers.push(marker);
})
.catch(function (error) {
console.error(error);
});

axios.get('/api/v1/tz/geojson', {
params: {
lng: lng,
lat: lat
}
})
.then(function(response) {
var tzid = response.data.properties.tzid;
if (!isPolygonAdded(tzid)) {
var geojson = L.geoJSON(response.data).addTo(map);
polygons.push({tzid: tzid, geojson: geojson});
}
})
.catch(function(error) {
console.error(error);
axios
.get("/api/v1/tz/geojson", {
params: {
lng: lng,
lat: lat,
},
})
.then(function (response) {
var tzid = response.data.properties.tzid;
if (!isPolygonAdded(tzid)) {
var geojson = L.geoJSON(response.data).addTo(map);
polygons.push({ tzid: tzid, geojson: geojson });
}
})
.catch(function (error) {
console.error(error);
});
});
});

function isPolygonAdded(tzid) {
for (var i = 0; i < polygons.length; i++) {
if (polygons[i].tzid === tzid) {
return true;
function isPolygonAdded(tzid) {
for (var i = 0; i < polygons.length; i++) {
if (polygons[i].tzid === tzid) {
return true;
}
}
return false;
}
return false;
}
</script>
</body>
</script>
</body>
</html>

0 comments on commit 1b10a03

Please sign in to comment.