diff --git a/frontend/react/src/events.ts b/frontend/react/src/events.ts index b8693d13..a6f4f9f3 100644 --- a/frontend/react/src/events.ts +++ b/frontend/react/src/events.ts @@ -892,3 +892,19 @@ export class WeaponsRefreshedEvent { if (DEBUG) console.log(`Event ${this.name} dispatched`); } } + +export class CoordinatesFreezeEvent { + static on(callback: () => void) { + document.addEventListener( + this.name, + (ev: CustomEventInit) => { + callback(); + } + ) + } + + static dispatch() { + document.dispatchEvent(new CustomEvent(this.name)); + if (DEBUG) console.log(`Event ${this.name} dispatched`); + } +} diff --git a/frontend/react/src/map/map.ts b/frontend/react/src/map/map.ts index 48ec8bde..d146c1c9 100644 --- a/frontend/react/src/map/map.ts +++ b/frontend/react/src/map/map.ts @@ -49,6 +49,7 @@ import { ConfigLoadedEvent, ContextActionChangedEvent, ContextActionSetChangedEvent, + CoordinatesFreezeEvent, HiddenTypesChangedEvent, MapContextMenuRequestEvent, MapOptionsChangedEvent, @@ -509,7 +510,7 @@ export class Map extends L.Map { code: "ShiftLeft", altKey: false, ctrlKey: false, - }); + }) } setLayerName(layerName: string) { @@ -1031,6 +1032,7 @@ export class Map extends L.Map { } #onLeftShortClick(e: L.LeafletMouseEvent) { + CoordinatesFreezeEvent.dispatch(); if (Date.now() - this.#leftMouseDownEpoch < SHORT_PRESS_MILLISECONDS) { this.#debounceTimeout = window.setTimeout(() => { if (!this.#isSelecting) { diff --git a/frontend/react/src/other/utils.ts b/frontend/react/src/other/utils.ts index df0b6577..4b39e816 100644 --- a/frontend/react/src/other/utils.ts +++ b/frontend/react/src/other/utils.ts @@ -83,6 +83,13 @@ export function ConvertDDToDMS(D: number, lng: boolean) { else return zeroPad(deg, 2) + "°" + zeroPad(min, 2) + "'" + zeroPad(sec, 2) + "." + zeroPad(dec, 2) + '"'; } +export function DDToDDM(decimalDegrees) { + const degrees = Math.trunc(decimalDegrees); + const minutes = Math.abs((decimalDegrees - degrees) * 60); + + return `${Math.abs(degrees)}° ${minutes.toFixed(4)}'`; +} + export function deg2rad(deg: number) { var pi = Math.PI; return deg * (pi / 180); @@ -762,4 +769,8 @@ export function secondsToTimeString(seconds: number) { const secs = Math.floor(seconds % 60); return `${zeroPad(hours, 2)}:${zeroPad(minutes, 2)}:${zeroPad(secs, 2)}`; +} + +export function isTrustedEnvironment() { + return window.location.protocol === "https:"; } \ No newline at end of file diff --git a/frontend/react/src/ui/components/ollocation.tsx b/frontend/react/src/ui/components/ollocation.tsx index 34e142f5..f5ab162a 100644 --- a/frontend/react/src/ui/components/ollocation.tsx +++ b/frontend/react/src/ui/components/ollocation.tsx @@ -1,8 +1,8 @@ import React, { useState } from "react"; import { LatLng } from "leaflet"; -import { ConvertDDToDMS, latLngToMGRS, latLngToUTM, zeroAppend } from "../../other/utils"; +import { ConvertDDToDMS, DDToDDM, latLngToMGRS, latLngToUTM, zeroAppend } from "../../other/utils"; -export function OlLocation(props: { location: LatLng; className?: string; referenceSystem?: string; onClick?: () => void }) { +export function OlLocation(props: { location: LatLng; className?: string; referenceSystem?: string; onClick?: () => void; onRefSystemChange?: (refSystem: string) => any }) { const [referenceSystem, setReferenceSystem] = props.referenceSystem ? [props.referenceSystem, () => {}] : useState("LatLngDec"); const MGRS = latLngToMGRS(props.location.lat, props.location.lng, 6); if (referenceSystem === "MGRS") { @@ -17,6 +17,7 @@ export function OlLocation(props: { location: LatLng; className?: string; refere ? props.onClick : (ev) => { setReferenceSystem("LatLngDec"); + props.onRefSystemChange ? props.onRefSystemChange("LatLngDec") : null; ev.stopPropagation(); } } @@ -44,6 +45,7 @@ export function OlLocation(props: { location: LatLng; className?: string; refere ? props.onClick : (ev) => { setReferenceSystem("LatLngDMS"); + props.onRefSystemChange ? props.onRefSystemChange("LatLngDMS") : null; ev.stopPropagation(); } } @@ -82,7 +84,8 @@ export function OlLocation(props: { location: LatLng; className?: string; refere props.onClick ? props.onClick : (ev) => { - setReferenceSystem("MGRS"); + setReferenceSystem("LatLngDDM"); + props.onRefSystemChange ? props.onRefSystemChange("LatLngDDM") : null; ev.stopPropagation(); } } @@ -109,6 +112,46 @@ export function OlLocation(props: { location: LatLng; className?: string; refere ); + } else if (referenceSystem === "LatLngDDM") { + return ( +