424 lines
15 KiB
HTML
424 lines
15 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<link rel="icon" type="image/x-icon" href="./favicon.ico">
|
|
<title>UPlanet Grid Navigator - Layers Zoom In -</title>
|
|
<link rel="stylesheet" href="leaflet.css" />
|
|
<style>
|
|
.clickable-area {
|
|
fill-opacity: 0.2; /* Adjust the opacity as needed */
|
|
fill: #0074d9; /* Adjust the color as needed */
|
|
stroke: #001f3f;
|
|
}
|
|
#coordinates-display {
|
|
position: absolute;
|
|
bottom: 20px; /* Adjust the bottom position as needed */
|
|
left: 10px; /* Adjust the left position as needed */
|
|
background-color: white;
|
|
padding: 5px;
|
|
border: 1px solid black;
|
|
z-index: 1000;
|
|
}
|
|
#map-container {
|
|
position: fixed;
|
|
top: 0;
|
|
left: 0;
|
|
width: 100%;
|
|
height: 100%;
|
|
}
|
|
.button {
|
|
background-color: #3498db;
|
|
color: #fff;
|
|
padding: 10px 20px;
|
|
border: none;
|
|
cursor: pointer;
|
|
}
|
|
.grid-number {
|
|
position: absolute;
|
|
font-size: 16px;
|
|
font-weight: bold;
|
|
color: #fff;
|
|
z-index: 1300;
|
|
|
|
}
|
|
#upper-layer-button {
|
|
position: absolute;
|
|
top: 10px;
|
|
right: 10px;
|
|
z-index: 1002;
|
|
background-color: #3498db;
|
|
color: #fff;
|
|
padding: 10px 20px;
|
|
border: none;
|
|
cursor: pointer;
|
|
}
|
|
</style>
|
|
|
|
</head>
|
|
<body>
|
|
<div id="map-container" style="position: relative;">
|
|
<div id="coordinates-display"></div> <!-- Coordinates display element -->
|
|
<div id="map" style="width: 100%; height: 100vh;"></div>
|
|
</div>
|
|
<button id="upper-layer-button">⬆️</button>
|
|
<script src="leaflet.js"></script>
|
|
|
|
<script>
|
|
|
|
// 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 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;
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
// Extract the hostname (e.g., "https://ipfs.domain.tld" or "http://ipfs.localhost:8080")
|
|
var currentURL = new URL(window.location.href);
|
|
var hostname = currentURL.hostname;
|
|
var port = currentURL.port;
|
|
var protocol = currentURL.protocol.split(":")[0];
|
|
// Check and replace the port if it's 8080
|
|
if (port === "8080") {
|
|
port = "1234";
|
|
}
|
|
var zHost = hostname.replace("ipfs", "astroport");
|
|
// Create the "station" variable with the specified format
|
|
var station = protocol + "://" + zHost + (port ? (":" + port) : "");
|
|
console.log(station)
|
|
//////////////////////////////////////////////////////////////// fetchAstroport
|
|
async function fetchAstroport(myURL, retryCount = 3) {
|
|
try {
|
|
let one = await fetch(myURL);
|
|
var doc = await one.text();
|
|
var regex = /url='([^']+)/i;
|
|
var redirectURL = doc.match(regex)[1];
|
|
|
|
console.log(redirectURL);
|
|
|
|
return new Promise(async (resolve, reject) => {
|
|
let retry = 0;
|
|
|
|
const fetchData = async () => {
|
|
try {
|
|
let two = await fetch(redirectURL);
|
|
const data = await two.json();
|
|
console.log(data);
|
|
resolve(data);
|
|
} catch (error) {
|
|
if (retry < retryCount) {
|
|
console.log(`Retry ${retry + 1} after 3000ms...`);
|
|
retry++;
|
|
setTimeout(fetchData, 3000);
|
|
} else {
|
|
console.log('Max retries reached. Fetch error:', error);
|
|
reject(error);
|
|
}
|
|
}
|
|
};
|
|
|
|
setTimeout(fetchData, 3000);
|
|
});
|
|
} catch (err) {
|
|
console.log('Fetch error:', err);
|
|
return Promise.reject(err);
|
|
}
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
const defaultIPNS = '';
|
|
const sectorIPNS = getUrlParameter('ipns') || defaultIPNS;
|
|
console.log('sectorIPNS: /ipns/', sectorIPNS);
|
|
|
|
if (sectorIPNS !== '') {
|
|
const buttonContainer = document.createElement('div');
|
|
buttonContainer.id = 'button-container'
|
|
buttonContainer.style.position = 'absolute';
|
|
buttonContainer.style.bottom = '10px';
|
|
buttonContainer.style.left = '10px';
|
|
buttonContainer.style.width = '200px';
|
|
buttonContainer.style.height = '150px';
|
|
buttonContainer.style.zIndex = '1001';
|
|
buttonContainer.style.display = 'flex';
|
|
buttonContainer.style.flexDirection = 'column';
|
|
buttonContainer.style.alignItems = 'center';
|
|
buttonContainer.style.justifyContent = 'center';
|
|
|
|
const button = document.createElement('button');
|
|
button.innerText = 'INLINE LINK';
|
|
button.className = 'button';
|
|
|
|
// Add an event listener to the button
|
|
button.addEventListener('click', function() {
|
|
window.open( '/ipns/'+ sectorIPNS, "_blank");
|
|
});
|
|
|
|
// Append the button to the button container
|
|
buttonContainer.appendChild(button);
|
|
document.body.appendChild(buttonContainer);
|
|
}
|
|
|
|
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);
|
|
console.log('Recommended zoom level:', zoomLevel);
|
|
|
|
const map = L.map('map').setView([centerLat, centerLon], zoomLevel);
|
|
|
|
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
|
attribution: 'U Planet'
|
|
}).addTo(map);
|
|
|
|
|
|
const gridSize = 10; // Number of rows and columns in the grid
|
|
const NSize = deg / 10; // Size of each grid cell
|
|
|
|
document.getElementById('upper-layer-button').addEventListener('click', function() {
|
|
if (deg >= 10) {
|
|
window.location.href = 'welcome.html';
|
|
} else {
|
|
const newDeg = deg * 10;
|
|
const decalage = 2.5 * deg;
|
|
const adjustedSouthWestLat = (parseFloat(southWestLat) - decalage).toFixed(2);
|
|
const adjustedSouthWestLon = (parseFloat(southWestLon) - decalage).toFixed(2);
|
|
const url = `map_render.html?southWestLat=${adjustedSouthWestLat}&southWestLon=${adjustedSouthWestLon}°=${newDeg}`;
|
|
window.location.href = url;
|
|
}
|
|
});
|
|
|
|
|
|
// Create a HTML element for displaying coordinates
|
|
const coordinatesDisplay = document.getElementById('coordinates-display');
|
|
|
|
// Check if deg is less than or equal to 0.01
|
|
if (deg <= 0.01) {
|
|
const container = document.createElement('div');
|
|
container.style.position = 'fixed';
|
|
container.style.top = '0';
|
|
container.style.left = '0';
|
|
container.style.width = '100vw';
|
|
container.style.height = '100vh';
|
|
container.style.backgroundColor = 'rgba(255, 255, 255, 0.4)';
|
|
container.style.border = 'none';
|
|
container.style.zIndex = '999';
|
|
container.style.display = 'flex';
|
|
container.style.flexDirection = 'column';
|
|
container.style.alignItems = 'center';
|
|
container.style.justifyContent = 'center';
|
|
|
|
|
|
const button = document.createElement('button');
|
|
button.textContent = '>>> (✜‿‿✜) <<<';
|
|
button.style.width = '100%';
|
|
button.style.height = '100px'; // Customize the button height
|
|
button.style.backgroundColor = '#0074d9';
|
|
button.style.border = 'none';
|
|
button.style.fontFamily = 'Arial, sans-serif'; // Customize the font family
|
|
button.style.fontSize = '24px'; // Customize the font size
|
|
button.style.color = '#fff'; // Customize the font color
|
|
|
|
button.addEventListener('click', () => {
|
|
const url = `${station}/?uplanet=@&zlat=${southWestLat}&zlon=${southWestLon}`;
|
|
window.location.href = url;
|
|
});
|
|
|
|
container.appendChild(button);
|
|
|
|
document.body.appendChild(container);
|
|
|
|
} else {
|
|
|
|
// Add a mousemove event listener to the map
|
|
map.on('mousemove', (event) => {
|
|
const latLng = event.latlng;
|
|
const lat = latLng.lat.toFixed(6);
|
|
const lng = latLng.lng.toFixed(6);
|
|
coordinatesDisplay.textContent = `Latitude: ${lat}, Longitude: ${lng}`;
|
|
});
|
|
|
|
///// UPPER THAN 0.01
|
|
}
|
|
|
|
// Add a click event listener to the map container
|
|
document.getElementById('map-container').addEventListener('click', (event) => {
|
|
const isInsideRectangle = event.target.classList.contains('clickable-area');
|
|
if (!isInsideRectangle) {
|
|
history.back(); // Trigger browser's back functionality
|
|
}
|
|
});
|
|
|
|
/////////////////
|
|
async function loadGridNumbers(myURL) {
|
|
try {
|
|
const data = await fetchAstroport(myURL);
|
|
return data.gridNumbers || [];
|
|
} catch (error) {
|
|
console.error('Error loading grid numbers:', error);
|
|
return [];
|
|
}
|
|
}
|
|
|
|
// Function to overlay grid numbers on the map
|
|
function overlayGridNumbers(rectangle, number) {
|
|
const latLng = rectangle.getBounds().getCenter();
|
|
const containerPoint = map.latLngToContainerPoint(latLng);
|
|
|
|
const numberElement = document.createElement('div');
|
|
numberElement.className = 'grid-number';
|
|
numberElement.textContent = number;
|
|
numberElement.style.position = 'absolute';
|
|
numberElement.style.fontSize = '16px';
|
|
numberElement.style.fontWeight = 'bold';
|
|
numberElement.style.color = 'red';
|
|
numberElement.style.top = `${containerPoint.y}px`;
|
|
numberElement.style.left = `${containerPoint.x}px`;
|
|
|
|
document.getElementById('map-container').appendChild(numberElement);
|
|
}
|
|
|
|
const zquery = 'zone='+NSize+'&ulat='+southWestLat+'&ulon='+southWestLon; // Replace with your actual query parameters
|
|
const zoneURL = station+'/?' + zquery;
|
|
|
|
console.log('ZONE URL:', zoneURL);
|
|
|
|
// Create a clickable rectangle for each grid cell
|
|
const rectangles = [];
|
|
for (let latIndex = 0; latIndex < gridSize; latIndex++) {
|
|
for (let lonIndex = 0; lonIndex < gridSize; lonIndex++) {
|
|
const lat = southWestLat + latIndex * NSize;
|
|
const lon = southWestLon + lonIndex * NSize;
|
|
//~ const lat = southWestLat + (southWestLat < 0 ? -latIndex * NSize : latIndex * NSize);
|
|
//~ const lon = southWestLon + (southWestLon < 0 ? -lonIndex * NSize : lonIndex * NSize);
|
|
|
|
// Create a clickable rectangle
|
|
const rectangle = L.rectangle(
|
|
[[lat, lon], [lat + NSize, lon + NSize]],
|
|
{ color: 'transparent', weight: 1, className: 'clickable-area' } // Add CSS class
|
|
);
|
|
|
|
// Add a click event to the rectangle
|
|
rectangle.on('click', () => {
|
|
// Calculate new northEastLat and northEastLon based on the clicked grid cell
|
|
const newNorthEastLat = lat.toFixed(2);
|
|
const newNorthEastLon = lon.toFixed(2);
|
|
|
|
// Update URL parameters with the new values
|
|
const url = `map_render.html?southWestLat=${newNorthEastLat}&southWestLon=${newNorthEastLon}°=${NSize}`;
|
|
window.location.href = url;
|
|
});
|
|
|
|
// Add the rectangle to the map and to the array
|
|
rectangle.addTo(map);
|
|
rectangles.push(rectangle);
|
|
}
|
|
}
|
|
|
|
// Load grid numbers and overlay them on the map
|
|
loadGridNumbers(zoneURL).then(gridNumbers => {
|
|
gridNumbers.forEach(({ lat, lon, number, ipns }) => {
|
|
// Calculate the center of the rectangle based on lat + NSize and lon + NSize
|
|
const latCenter = lat + (lat < 0 ? -NSize / 2 : NSize / 2);
|
|
const lonCenter = lon + (lon < 0 ? -NSize / 2 : NSize / 2);
|
|
|
|
const latLng = L.latLng(latCenter, lonCenter);
|
|
|
|
// Find the corresponding rectangle
|
|
const matchingRectangle = rectangles.find(rectangle =>
|
|
rectangle.getBounds().contains(latLng)
|
|
);
|
|
|
|
if (matchingRectangle) {
|
|
overlayGridNumbers(matchingRectangle, number);
|
|
}
|
|
|
|
if (ipns !== '') {
|
|
const buttonContainer = document.createElement('div');
|
|
buttonContainer.id = 'button-container'
|
|
buttonContainer.style.position = 'absolute';
|
|
buttonContainer.style.bottom = '10px';
|
|
buttonContainer.style.left = '10px';
|
|
buttonContainer.style.width = '200px';
|
|
buttonContainer.style.height = '150px';
|
|
buttonContainer.style.zIndex = '1001';
|
|
buttonContainer.style.display = 'flex';
|
|
buttonContainer.style.flexDirection = 'column';
|
|
buttonContainer.style.alignItems = 'center';
|
|
buttonContainer.style.justifyContent = 'center';
|
|
|
|
const button = document.createElement('button');
|
|
if (NSize === 0.001) { button.innerText = 'EXPLORE UMAP'; }
|
|
if (NSize === 0.01) { button.innerText = 'EXPLORE SECTOR'; }
|
|
if (NSize === 0.1) { button.innerText = 'EXPLORE REGION'; }
|
|
if (NSize == "") { button.innerText = 'EXPLORE ZONE'; }
|
|
button.className = 'button';
|
|
|
|
// Add an event listener to the button
|
|
button.addEventListener('click', function() {
|
|
window.open( ipns , "_blank");
|
|
});
|
|
|
|
// Append the button to the button container
|
|
buttonContainer.appendChild(button);
|
|
document.body.appendChild(buttonContainer);
|
|
}
|
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
</script>
|
|
</body>
|
|
</html>
|