2022-08-13 20:33:44 +00:00
|
|
|
|
|
|
|
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,
|
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);
|
|
|
|
|
|
|
|
overlays.markers.forEach(m=>m.add(map));
|
|
|
|
overlays.circles.forEach(m=>m.add(map));
|
|
|
|
overlays.polygons.forEach(m=>m.add(map));
|
|
|
|
|
2022-08-14 04:18:00 +00:00
|
|
|
const createOverlayModal = new CreateOverlayModal();
|
|
|
|
|
|
|
|
const closeAllModals = (): void => {
|
|
|
|
createOverlayModal.setVisible(false);
|
|
|
|
}
|
|
|
|
|
2022-08-13 21:40:38 +00:00
|
|
|
const resetMapClick = (): void => {
|
|
|
|
try {
|
2022-08-14 04:18:00 +00:00
|
|
|
const addPointBtn = document.getElementById("addPoint-btn");
|
|
|
|
if (addPointBtn) {
|
|
|
|
addPointBtn.classList.remove("activeBtn");
|
|
|
|
}
|
2022-08-13 21:40:38 +00:00
|
|
|
map.off("click", addMarkerHandler);
|
2022-08-14 04:18:00 +00:00
|
|
|
|
2022-08-13 21:40:38 +00:00
|
|
|
} catch {}
|
|
|
|
try {
|
2022-08-14 04:18:00 +00:00
|
|
|
const addCircleBtn = document.getElementById("addCircle-btn");
|
|
|
|
if (addCircleBtn) {
|
|
|
|
addCircleBtn.classList.remove("activeBtn");
|
|
|
|
}
|
2022-08-13 21:40:38 +00:00
|
|
|
map.off("click", addCircleHandler);
|
|
|
|
} catch {}
|
|
|
|
}
|
|
|
|
|
|
|
|
const addMarkerHandler = (e: any): void => {
|
2022-08-14 04:18:00 +00:00
|
|
|
createOverlayModal.setVisible(true);
|
|
|
|
createOverlayModal.setState(OverlayType.POINT, {
|
2022-08-13 20:33:44 +00:00
|
|
|
latlng: e.latlng,
|
|
|
|
map: map,
|
|
|
|
overlays: overlays,
|
|
|
|
});
|
2022-08-14 04:18:00 +00:00
|
|
|
resetMapClick();
|
2022-08-13 20:33:44 +00:00
|
|
|
}
|
|
|
|
|
2022-08-13 21:40:38 +00:00
|
|
|
const addCircleHandler = (e: any): void => {
|
2022-08-14 04:18:00 +00:00
|
|
|
createOverlayModal.setVisible(true);
|
|
|
|
createOverlayModal.setState(OverlayType.CIRCLE, {
|
2022-08-13 21:40:38 +00:00
|
|
|
latlng: e.latlng,
|
|
|
|
map: map,
|
|
|
|
overlays: overlays,
|
|
|
|
});
|
2022-08-14 04:18:00 +00:00
|
|
|
resetMapClick();
|
2022-08-13 21:40:38 +00:00
|
|
|
}
|
|
|
|
|
2022-08-13 20:33:44 +00:00
|
|
|
const addMarkerBtn = document.getElementById("addPoint-btn");
|
|
|
|
if (addMarkerBtn) {
|
2022-08-13 21:40:38 +00:00
|
|
|
addMarkerBtn.onclick = (e: any): void => {
|
2022-08-14 04:18:00 +00:00
|
|
|
closeAllModals();
|
2022-08-13 21:40:38 +00:00
|
|
|
resetMapClick()
|
2022-08-14 04:18:00 +00:00
|
|
|
addMarkerBtn.classList.add("activeBtn");
|
2022-08-13 21:40:38 +00:00
|
|
|
map.on("click", addMarkerHandler);
|
2022-08-13 20:33:44 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-08-13 21:40:38 +00:00
|
|
|
const addCircleBtn = document.getElementById("addCircle-btn");
|
|
|
|
if (addCircleBtn) {
|
|
|
|
addCircleBtn.onclick = (e: any): void => {
|
2022-08-14 04:18:00 +00:00
|
|
|
closeAllModals();
|
2022-08-13 21:40:38 +00:00
|
|
|
resetMapClick();
|
2022-08-14 04:18:00 +00:00
|
|
|
addCircleBtn.classList.add("activeBtn");
|
2022-08-13 21:40:38 +00:00
|
|
|
map.on("click", addCircleHandler);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-13 20:33:44 +00:00
|
|
|
const saveBtn = document.getElementById("save-btn");
|
|
|
|
if (saveBtn) {
|
2022-08-13 21:40:38 +00:00
|
|
|
saveBtn.onclick = (e: any): void => {
|
2022-08-13 20:33:44 +00:00
|
|
|
OverlayState.save(overlays);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const clearBtn = document.getElementById("clear-btn");
|
|
|
|
if (clearBtn) {
|
2022-08-13 21:40:38 +00:00
|
|
|
clearBtn.onclick = (e: any): void => {
|
2022-08-13 20:33:44 +00:00
|
|
|
overlays = OverlayState.clear(overlays, map);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const tilesBtn = document.getElementById("tiles-btn");
|
|
|
|
if (tilesBtn) {
|
2022-08-13 21:40:38 +00:00
|
|
|
tilesBtn.onclick = (e: any): void => {
|
2022-08-13 20:33:44 +00:00
|
|
|
if (TileLayerWrapper.getActiveLayer() == satelliteLayer) {
|
|
|
|
TileLayerWrapper.enableOnly(streetLayer, map);
|
|
|
|
} else {
|
|
|
|
TileLayerWrapper.enableOnly(satelliteLayer, map);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2022-08-14 04:18:00 +00:00
|
|
|
|
|
|
|
const main = document.getElementById("app-container");
|
|
|
|
if (main) {
|
|
|
|
main.style.display = "initial";
|
|
|
|
}
|
2022-08-13 20:33:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
init();
|