onyx/src/99-onyx-scry.ts

86 lines
2.5 KiB
TypeScript
Raw Normal View History

2022-08-13 20:33:44 +00:00
function init(): void {
let overlays: OverlayState = OverlayState.load() ?? new OverlayState();
const map = L.map('map').fitWorld();
// old default zoom was 13
2022-08-13 20:33:44 +00:00
const streetLayer = TileLayerWrapper.constructLayer(
"streetLayer",
L.tileLayer(
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
{
maxZoom: 19,
2022-08-14 04:18:00 +00:00
attribution: "street map tiles © OpenStreetMap"
2022-08-13 20:33:44 +00:00
}));
const satelliteLayer = TileLayerWrapper.constructLayer(
"satelliteLayer",
L.tileLayer(
'https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}',
{
maxZoom: 19,
2022-08-14 04:18:00 +00:00
attribution: "satellite tiles © Esri"
2022-08-13 20:33:44 +00:00
}));
TileLayerWrapper.enableOnly("streetLayer", map);
2022-08-13 20:33:44 +00:00
overlays.markers.forEach(m=>m.add(map));
overlays.circles.forEach(m=>m.add(map));
overlays.polygons.forEach(m=>m.add(map));
overlays.polyline.add(map);
const modals = new ModalCollection(
new CreateOverlayModal(),
new CancelModal(),
new OKCancelModal(),
new InfoModal());
2022-08-14 04:18:00 +00:00
MapHandler.init(map, overlays, TileLayerWrapper.layers, modals);
2022-08-13 20:33:44 +00:00
MapHandler.setButtonClick("home-btn", MapHandler.goHome);
MapHandler.setButtonClick("addPoint-btn", MapHandler.markerCollect);
MapHandler.setButtonClick("addCircle-btn", MapHandler.circleCollect);
MapHandler.setButtonClick("addPolygon-btn", MapHandler.polygonCollect);
2022-08-13 20:33:44 +00:00
MapHandler.setButtonClick("save-btn", MapHandler.overlaySave);
MapHandler.setButtonClick("clear-btn", MapHandler.overlayClear);
MapHandler.setButtonClick("restore-btn", MapHandler.overlayReset);
MapHandler.setButtonClick("menu-btn", ()=>{});
2022-08-14 04:18:00 +00:00
MapHandler.setButtonClick("tiles-btn", MapHandler.swapTiles);
map.on("locationfound", ()=> {
const okCancel = modals.okCancel;
okCancel.setMsg("Set Home to current location?");
const okBtn = okCancel.okBtn();
if (okBtn) {
okBtn.onclick = (e: any) => {
okCancel.setVisible(false);
MapHandler.setHome(null);
}
}
const cancelBtn = okCancel.cancelBtn();
if (cancelBtn) {
cancelBtn.onclick = () => {
okCancel.setVisible(false);
}
}
});
map.on("locationerror", ()=> {
const info = modals.info;
info.setMsg("Could not get location data");
info.setVisible(true);
});
const homeData = localStorage.getItem("home");
if (homeData) {
const home = <Point>JSON.parse(homeData);
map.setView(home, 13);
} else {
map.locate({setView: true, maxZoom: 13});
}
2022-08-13 20:33:44 +00:00
}
init();