function init(): void { let overlays: OverlayState = OverlayState.load() ?? new OverlayState(); const map = L.map('map').fitWorld(); // old default zoom was 13 const streetLayer = TileLayerWrapper.constructLayer( "streetLayer", L.tileLayer( 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { maxZoom: 19, attribution: "street map data © OpenStreetMap contributors" })); const satelliteLayer = TileLayerWrapper.constructLayer( "satelliteLayer", L.tileLayer( 'https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}', { maxZoom: 19, attribution: "satellite data © Esri" })); TileLayerWrapper.enableOnly("streetLayer", map); 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(), new OverlayManagementModal(), new ImportExportModal()); MapHandler.init(map, overlays, TileLayerWrapper.layers, modals); MapHandler.setButtonClick("home-btn", MapHandler.goHome); MapHandler.setButtonClick("addPoint-btn", MapHandler.markerCollect); MapHandler.setButtonClick("addCircle-btn", MapHandler.circleCollect); MapHandler.setButtonClick("addPolygon-btn", MapHandler.polygonCollect); MapHandler.setButtonClick("tiles-btn", MapHandler.swapTiles); MapHandler.setButtonClick("save-btn", MapHandler.overlaySave); MapHandler.setButtonClick("clear-btn", MapHandler.overlayClear); MapHandler.setButtonClick("restore-btn", MapHandler.overlayReset); MapHandler.setButtonClick("menu-btn", MapHandler.toggleMenu); MapHandler.setButtonClick("set-home-btn", MapHandler.setHome); MapHandler.setButtonClick("export-all-btn", MapHandler.exportAll); MapHandler.setButtonClick("import-export-cancel-btn", MapHandler.closeImportExport); MapHandler.setButtonClick("import-btn", MapHandler.import); map.on("locationfound", MapHandler.setHome); map.on("locationerror", ()=> { const info = modals.info; info.setMsg("Could not get location data"); info.setVisible(true); }); // the menu doesn't open on the first click unless we do this first... not sure why modals.closeAll(); const homeData = localStorage.getItem("home"); if (homeData) { const home = JSON.parse(homeData); map.setView(home, 13); } else { map.locate({setView: true, maxZoom: 13}); } } init();