Skip to content

Commit

Permalink
feat: convert altitude to ca. zoom, popup options
Browse files Browse the repository at this point in the history
  • Loading branch information
nobkd committed Mar 31, 2023
1 parent d8d7c4f commit d80971b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/map/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const tileProviders: Tiles = {
satellite: {
layer: 'https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}', // Esri.WorldImagery
attr: 'Tiles © Esri — Source: Esri, i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community',
},
}, // TODO: add street layer etc to satellite
};

const gPos: string = 'pb';
Expand All @@ -42,12 +42,15 @@ if (params.has(gPos)) {
}

if (params.has(gZoom)) {
mapData.zoom = Number(params.get(gZoom) as string);
mapData.zoom = parseInt(params.get(gZoom) as string);
}

const map: L.Map = L.map('map', {
scrollWheelZoom: false, // TODO: on pc allow ctrl + scroll
zoom: mapData.zoom ?? 17,
zoomSnap: 0.1,
zoomDelta: 0.5,
minZoom: 0.5,
});

if (mapData.area) {
Expand All @@ -58,7 +61,7 @@ if (mapData.markers) {
mapData.markers.forEach((marker) => {
let mapMarker = L.marker([marker.lat, marker.lon]).addTo(map);
if (marker.label) {
mapMarker.bindPopup(marker.label).openPopup();
mapMarker.bindPopup(marker.label, { closeButton: false }).openPopup();
}
});

Expand All @@ -70,5 +73,5 @@ if (mapData.markers) {

L.tileLayer(tileProviders[mapData.tile ?? 'roadmap'].layer, {
maxZoom: 19,
//attribution: tileProviders[mapData.tile ?? 'roadmap'].attr,
attribution: tileProviders[mapData.tile ?? 'roadmap'].attr,
}).addTo(map);
3 changes: 3 additions & 0 deletions src/map/utils/read.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { parsePB, tileTypes, type TileType } from './parsePB';
import { parseDMS } from './parseDMS';
import { getMapZoom } from './zoom';

const nominatimQ: string = 'https://nominatim.openstreetmap.org/search/?limit=1&format=json&q=';
const cidMatch: RegExp = /^0x[\da-f]+:0x[\da-f]+$/i;
Expand Down Expand Up @@ -39,6 +40,8 @@ export async function readPB(param: string): Promise<MapData> {
lon: mapArea[1],
};

mapData.zoom = getMapZoom(mapArea[0]);

let currMarkers: any[] | string = data[1];
if (typeof currMarkers !== 'string') {
for (let markers of currMarkers[0] as string[]) {
Expand Down
18 changes: 18 additions & 0 deletions src/map/utils/zoom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// https://groups.google.com/g/google-earth-browser-plugin/c/eSL9GlAkWBk/m/T4mdToJz_FgJ

const factor: number = 35200000;

export function getMapZoom(alt: number): number {
console.log(alt);

// convert GE lookAt range to GMap zoom
let zoom = Math.log2(factor / alt) * 1.225;
console.log(zoom);

if (zoom < 0) {
zoom = 0;
} else if (zoom > 19) {
zoom = 19;
}
return zoom;
}

0 comments on commit d80971b

Please sign in to comment.