138 lines
5.0 KiB
HTML
138 lines
5.0 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>UPlanet Map</title>
|
|
<link rel="stylesheet" href="leaflet.css" />
|
|
<style>
|
|
.map-container {
|
|
position: fixed;
|
|
top: 0;
|
|
left: 0;
|
|
width: 100%;
|
|
height: 100%;
|
|
}
|
|
|
|
.button-container {
|
|
position: absolute;
|
|
bottom: 0;
|
|
left: 0;
|
|
width: 50%;
|
|
height: 50%;
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
}
|
|
|
|
.button {
|
|
background-color: #3498db;
|
|
color: #fff;
|
|
padding: 10px 20px;
|
|
border: none;
|
|
cursor: pointer;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div id="map" class="map-container"></div>
|
|
<!-- Add a button container if sectorIPNS is not empty -->
|
|
<div class="button-container" id="buttonContainer"></div>
|
|
|
|
<script src="leaflet.js"></script>
|
|
|
|
<script>
|
|
// const desiredImageWidthInKm = 11; // Now Is calculated from northEastLon - southWestLon
|
|
const tileSizeInPixels = 256;
|
|
|
|
function calculateZoomLevel(desiredImageWidthInKm, latitude) {
|
|
const earthEquatorialCircumference = 40075016.686; // Earth's equatorial circumference in meters
|
|
// Calculate the distance covered by one degree of longitude at the given latitude
|
|
const metersPerLongitudeDegree = earthEquatorialCircumference * Math.cos((Math.PI / 180) * latitude) / 360;
|
|
const metersPerPixel = metersPerLongitudeDegree * 360 / (tileSizeInPixels * Math.pow(2, 20));
|
|
// Calculate the number of pixels needed to achieve the desired width
|
|
const numberOfPixelsHorizontally = (desiredImageWidthInKm * 1000) / metersPerPixel;
|
|
// Calculate the appropriate zoom level
|
|
const zoomLevel = Math.log2(tileSizeInPixels * Math.pow(2, 20) / numberOfPixelsHorizontally);
|
|
return zoomLevel;
|
|
}
|
|
|
|
// Function to extract URL parameters
|
|
function getUrlParameter(name) {
|
|
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
|
|
const regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
|
|
const results = regex.exec(location.search);
|
|
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
|
|
}
|
|
|
|
const defaultIPNS = '';
|
|
const sectorIPNS = getUrlParameter('ipns') || defaultIPNS;
|
|
console.log('sectorIPNS: /ipns/', sectorIPNS);
|
|
|
|
const defaultSouthWestLat = 0.00;
|
|
const defaultSouthWestLon = 0.00;
|
|
const defaultOffsetDegrees = 10.00; // 10° offset
|
|
|
|
const southWestLat = parseFloat(getUrlParameter('southWestLat')) || defaultSouthWestLat;
|
|
console.log('Lat:', southWestLat);
|
|
const southWestLon = parseFloat(getUrlParameter('southWestLon')) || defaultSouthWestLon;
|
|
console.log('Lon:', southWestLon);
|
|
|
|
const deg = parseFloat(getUrlParameter('deg')) || defaultOffsetDegrees;
|
|
console.log('Offset:', deg);
|
|
|
|
// Calculate northEastLat and northEastLon with deg° offset only if parameters are empty
|
|
const northEastLatParam = getUrlParameter('northEastLat');
|
|
const northEastLonParam = getUrlParameter('northEastLon');
|
|
|
|
const northEastLat = northEastLatParam ? parseFloat(northEastLatParam) : southWestLat + deg;
|
|
const northEastLon = northEastLonParam ? parseFloat(northEastLonParam) : southWestLon + deg;
|
|
|
|
// Calculate the longitudinal distance in degrees
|
|
const lonDistanceInDegrees = Math.abs(northEastLon - southWestLon);
|
|
console.log('lonDistanceInDegrees:', lonDistanceInDegrees);
|
|
|
|
// Calculate the desired image width in kilometers
|
|
const earthEquatorialCircumference = 40075016.686; // Earth's equatorial circumference in meters
|
|
const metersPerLongitudeDegree = Math.abs(earthEquatorialCircumference * Math.cos((Math.PI / 180) * southWestLat) / 360);
|
|
const desiredImageWidthInMeters = lonDistanceInDegrees * metersPerLongitudeDegree;
|
|
const desiredImageWidthInKm = desiredImageWidthInMeters / 1000;
|
|
console.log('desiredImageWidthInKm:', desiredImageWidthInKm);
|
|
|
|
const centerLat = (southWestLat + northEastLat) / 2;
|
|
const centerLon = (southWestLon + northEastLon) / 2;
|
|
|
|
// Provide the latitude for adjustment
|
|
const latitude = centerLat;
|
|
const zoomLevel = calculateZoomLevel(desiredImageWidthInKm, latitude);
|
|
// const zoomLevel = calculateZoomLevel(desiredImageWidthInKm, latitude) + 2;
|
|
|
|
console.log('Recommended zoom level:', zoomLevel);
|
|
|
|
const map = L.map('map', {
|
|
zoomControl: false // Disable the default zoom control
|
|
}).setView([centerLat, centerLon], zoomLevel);
|
|
|
|
const tileLayer = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
|
attribution: `U Planet | Astroport | ${southWestLat} : ${southWestLon}`
|
|
}).addTo(map);
|
|
|
|
const buttonContainer = document.getElementById('buttonContainer');
|
|
|
|
// Check if sectorIPNS is not empty
|
|
if (sectorIPNS !== '') {
|
|
const button = document.createElement('button');
|
|
button.innerText = 'EXPLORE';
|
|
button.className = 'button';
|
|
|
|
// Add an event listener to the button
|
|
button.addEventListener('click', function() {
|
|
window.open( '/ipns/'+ sectorIPNS, "AstroTab");
|
|
});
|
|
|
|
// Append the button to the button container
|
|
buttonContainer.appendChild(button);
|
|
}
|
|
|
|
</script>
|
|
</body>
|
|
</html>
|