2022-08-23 20:44:15 +00:00
|
|
|
const helpLink = "<br>ONYX/scry v0.1.0 [ <a target='_blank' href='https://nilfm.cc/git/onyx-scry/about/LICENSE'>license</a> | <a target='_blank' href='https://nilfm.cc/git/onyx-scry/about'>manual</a> ]";
|
2022-08-23 19:44:37 +00:00
|
|
|
|
2022-08-13 20:33:44 +00:00
|
|
|
|
|
|
|
function init(): void {
|
|
|
|
let overlays: OverlayState = OverlayState.load() ?? new OverlayState();
|
2022-08-15 04:29:03 +00:00
|
|
|
const map = L.map('map').fitWorld();
|
|
|
|
|
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-23 19:44:37 +00:00
|
|
|
attribution: "street map data © OpenStreetMap contributors" + helpLink
|
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-23 19:44:37 +00:00
|
|
|
attribution: "satellite data © Esri" + helpLink
|
2022-08-13 20:33:44 +00:00
|
|
|
}));
|
|
|
|
|
2022-08-14 05:50:36 +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));
|
2022-08-15 02:44:00 +00:00
|
|
|
overlays.polyline.add(map);
|
|
|
|
|
2022-08-14 05:50:36 +00:00
|
|
|
const modals = new ModalCollection(
|
2022-08-15 02:44:00 +00:00
|
|
|
new CreateOverlayModal(),
|
|
|
|
new CancelModal(),
|
2022-08-15 03:30:47 +00:00
|
|
|
new OKCancelModal(),
|
2022-08-16 05:45:50 +00:00
|
|
|
new InfoModal(),
|
2022-08-20 23:20:01 +00:00
|
|
|
new OverlayManagementModal(),
|
|
|
|
new ImportExportModal());
|
2022-08-14 04:18:00 +00:00
|
|
|
|
2022-08-14 05:50:36 +00:00
|
|
|
MapHandler.init(map, overlays, TileLayerWrapper.layers, modals);
|
2022-08-13 20:33:44 +00:00
|
|
|
|
2022-08-15 04:29:03 +00:00
|
|
|
MapHandler.setButtonClick("home-btn", MapHandler.goHome);
|
2022-08-14 05:50:36 +00:00
|
|
|
MapHandler.setButtonClick("addPoint-btn", MapHandler.markerCollect);
|
|
|
|
MapHandler.setButtonClick("addCircle-btn", MapHandler.circleCollect);
|
2022-08-15 02:44:00 +00:00
|
|
|
MapHandler.setButtonClick("addPolygon-btn", MapHandler.polygonCollect);
|
2022-08-13 20:33:44 +00:00
|
|
|
|
2022-08-20 23:20:01 +00:00
|
|
|
MapHandler.setButtonClick("tiles-btn", MapHandler.swapTiles);
|
2022-08-14 05:50:36 +00:00
|
|
|
MapHandler.setButtonClick("save-btn", MapHandler.overlaySave);
|
|
|
|
MapHandler.setButtonClick("clear-btn", MapHandler.overlayClear);
|
2022-08-15 03:30:47 +00:00
|
|
|
MapHandler.setButtonClick("restore-btn", MapHandler.overlayReset);
|
2022-08-16 05:45:50 +00:00
|
|
|
MapHandler.setButtonClick("menu-btn", MapHandler.toggleMenu);
|
|
|
|
|
|
|
|
MapHandler.setButtonClick("set-home-btn", MapHandler.setHome);
|
2022-08-20 23:20:01 +00:00
|
|
|
MapHandler.setButtonClick("export-all-btn", MapHandler.exportAll);
|
|
|
|
MapHandler.setButtonClick("import-export-cancel-btn", MapHandler.closeImportExport);
|
|
|
|
MapHandler.setButtonClick("import-btn", MapHandler.import);
|
2022-08-15 04:29:03 +00:00
|
|
|
|
2022-08-16 05:45:50 +00:00
|
|
|
map.on("locationfound", MapHandler.setHome);
|
2022-08-15 04:29:03 +00:00
|
|
|
|
|
|
|
map.on("locationerror", ()=> {
|
|
|
|
const info = modals.info;
|
|
|
|
info.setMsg("Could not get location data");
|
|
|
|
info.setVisible(true);
|
|
|
|
});
|
|
|
|
|
2022-08-20 23:20:01 +00:00
|
|
|
// the menu doesn't open on the first click unless we do this first... not sure why
|
|
|
|
modals.closeAll();
|
|
|
|
|
2022-08-15 04:29:03 +00:00
|
|
|
const homeData = localStorage.getItem("home");
|
|
|
|
if (homeData) {
|
|
|
|
const home = <Point>JSON.parse(homeData);
|
|
|
|
map.setView(home, 13);
|
|
|
|
} else {
|
2022-08-23 19:44:37 +00:00
|
|
|
const okCancel = modals.okCancel;
|
|
|
|
const okBtn = okCancel.okBtn();
|
|
|
|
if (okBtn) {
|
|
|
|
okBtn.onclick = () => {
|
|
|
|
modals.closeAll();
|
|
|
|
map.locate({setView: true, maxZoom: 13});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const cancelBtn = okCancel.cancelBtn();
|
|
|
|
if (cancelBtn) {
|
|
|
|
cancelBtn.onclick = () => {
|
|
|
|
modals.closeAll();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
okCancel.setMsg("Would you like to use location data to set Home?");
|
|
|
|
okCancel.setVisible(true);
|
2022-08-15 04:29:03 +00:00
|
|
|
}
|
2022-08-13 20:33:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
init();
|