function init(): void { let overlays: OverlayState = OverlayState.load() ?? new OverlayState(); const map = L.map('map').setView([35.6653, -105.9507], 13); const streetLayer = TileLayerWrapper.constructLayer( "streetLayer", L.tileLayer( 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { maxZoom: 19, attribution: "street map tiles © OpenStreetMap" })); 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 tiles © 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)); const createOverlayModal = new CreateOverlayModal(); const closeAllModals = (): void => { createOverlayModal.setVisible(false); } const resetMapClick = (): void => { try { const addPointBtn = document.getElementById("addPoint-btn"); if (addPointBtn) { addPointBtn.classList.remove("activeBtn"); } map.off("click", addMarkerHandler); } catch {} try { const addCircleBtn = document.getElementById("addCircle-btn"); if (addCircleBtn) { addCircleBtn.classList.remove("activeBtn"); } map.off("click", addCircleHandler); } catch {} } const addMarkerHandler = (e: any): void => { createOverlayModal.setVisible(true); createOverlayModal.setState(OverlayType.POINT, { latlng: e.latlng, map: map, overlays: overlays, }); resetMapClick(); } const addCircleHandler = (e: any): void => { createOverlayModal.setVisible(true); createOverlayModal.setState(OverlayType.CIRCLE, { latlng: e.latlng, map: map, overlays: overlays, }); resetMapClick(); } const addMarkerBtn = document.getElementById("addPoint-btn"); if (addMarkerBtn) { addMarkerBtn.onclick = (e: any): void => { closeAllModals(); resetMapClick() addMarkerBtn.classList.add("activeBtn"); map.on("click", addMarkerHandler); }; } const addCircleBtn = document.getElementById("addCircle-btn"); if (addCircleBtn) { addCircleBtn.onclick = (e: any): void => { closeAllModals(); resetMapClick(); addCircleBtn.classList.add("activeBtn"); map.on("click", addCircleHandler); } } const saveBtn = document.getElementById("save-btn"); if (saveBtn) { saveBtn.onclick = (e: any): void => { OverlayState.save(overlays); }; } const clearBtn = document.getElementById("clear-btn"); if (clearBtn) { clearBtn.onclick = (e: any): void => { overlays = OverlayState.clear(overlays, map); } } const tilesBtn = document.getElementById("tiles-btn"); if (tilesBtn) { tilesBtn.onclick = (e: any): void => { if (TileLayerWrapper.getActiveLayer() == satelliteLayer) { TileLayerWrapper.enableOnly(streetLayer, map); } else { TileLayerWrapper.enableOnly(satelliteLayer, map); } }; } const main = document.getElementById("app-container"); if (main) { main.style.display = "initial"; } } init();