From 8379b27bb592ec766b81ce984517f947bd374ee1 Mon Sep 17 00:00:00 2001 From: Cyperghost Date: Thu, 24 Oct 2024 13:11:16 +0200 Subject: [PATCH] Change type of `InitialMarkerPosition` --- .../Core/Component/GoogleMaps/Geocoding.ts | 13 ++++++------- .../Core/Component/GoogleMaps/Geocoding.js | 9 ++++----- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/ts/WoltLabSuite/Core/Component/GoogleMaps/Geocoding.ts b/ts/WoltLabSuite/Core/Component/GoogleMaps/Geocoding.ts index 517e202bfa..cb6497e0d1 100644 --- a/ts/WoltLabSuite/Core/Component/GoogleMaps/Geocoding.ts +++ b/ts/WoltLabSuite/Core/Component/GoogleMaps/Geocoding.ts @@ -28,7 +28,7 @@ class Geocoding { readonly #element: HTMLInputElement; readonly #map: WoltlabCoreGoogleMapsElement; #marker?: google.maps.marker.AdvancedMarkerElement; - #initialMarkerPosition?: google.maps.LatLng; + #initialMarkerPosition?: google.maps.LatLng | google.maps.LatLngLiteral | null; constructor(element: HTMLInputElement, map: WoltlabCoreGoogleMapsElement) { this.#element = element; @@ -55,7 +55,7 @@ class Geocoding { #initEvents(): void { this.#element.addEventListener("geocoding:move-marker", (event: CustomEvent) => { - void this.#moveMarkerToLocation(event.detail.latitude, event.detail.longitude); + void this.#moveMarkerToLocation(new google.maps.LatLng(event.detail.latitude, event.detail.longitude)); }); this.#element.addEventListener("geocoding:resolve", (event: CustomEvent) => { @@ -71,14 +71,14 @@ class Geocoding { this.#element.addEventListener("geocoding:reset-marker", () => { if (this.#initialMarkerPosition) { - void this.#moveMarkerToLocation(this.#initialMarkerPosition.lat(), this.#initialMarkerPosition.lng()); + void this.#moveMarkerToLocation(new google.maps.LatLng(this.#initialMarkerPosition)); } }); } async #setupMarker(): Promise { this.#marker = await addDraggableMarker(this.#map); - this.#initialMarkerPosition = this.#marker?.position as google.maps.LatLng; + this.#initialMarkerPosition = this.#marker?.position; this.#marker.addListener("dragend", () => { void this.#map.getGeocoder().then((geocoder) => { @@ -92,13 +92,12 @@ class Geocoding { }); } - async #moveMarkerToLocation(latitude: number, longitude: number): Promise { - const location = new google.maps.LatLng(latitude, longitude); + async #moveMarkerToLocation(location: google.maps.LatLng): Promise { if (this.#marker) { this.#marker.position = location; } (await this.#map.getMap()).setCenter(location); - this.#setLocation(latitude, longitude); + this.#setLocation(location.lat(), location.lng()); } async #moveMarkerToAddress(address: string): Promise { diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Component/GoogleMaps/Geocoding.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Component/GoogleMaps/Geocoding.js index 7d79d3fa0f..b9b3b7525e 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Component/GoogleMaps/Geocoding.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Component/GoogleMaps/Geocoding.js @@ -33,7 +33,7 @@ define(["require", "exports", "../../Helper/Selector", "./Geocoding/Suggestion", } #initEvents() { this.#element.addEventListener("geocoding:move-marker", (event) => { - void this.#moveMarkerToLocation(event.detail.latitude, event.detail.longitude); + void this.#moveMarkerToLocation(new google.maps.LatLng(event.detail.latitude, event.detail.longitude)); }); this.#element.addEventListener("geocoding:resolve", (event) => { void this.#map.getGeocoder().then((geocoder) => { @@ -47,7 +47,7 @@ define(["require", "exports", "../../Helper/Selector", "./Geocoding/Suggestion", }); this.#element.addEventListener("geocoding:reset-marker", () => { if (this.#initialMarkerPosition) { - void this.#moveMarkerToLocation(this.#initialMarkerPosition.lat(), this.#initialMarkerPosition.lng()); + void this.#moveMarkerToLocation(new google.maps.LatLng(this.#initialMarkerPosition)); } }); } @@ -65,13 +65,12 @@ define(["require", "exports", "../../Helper/Selector", "./Geocoding/Suggestion", }); }); } - async #moveMarkerToLocation(latitude, longitude) { - const location = new google.maps.LatLng(latitude, longitude); + async #moveMarkerToLocation(location) { if (this.#marker) { this.#marker.position = location; } (await this.#map.getMap()).setCenter(location); - this.#setLocation(latitude, longitude); + this.#setLocation(location.lat(), location.lng()); } async #moveMarkerToAddress(address) { const geocoder = await this.#map.getGeocoder(); -- 2.20.1