Change type of `InitialMarkerPosition`
authorCyperghost <olaf_schmitz_1@t-online.de>
Thu, 24 Oct 2024 11:11:16 +0000 (13:11 +0200)
committerCyperghost <olaf_schmitz_1@t-online.de>
Thu, 24 Oct 2024 11:11:16 +0000 (13:11 +0200)
ts/WoltLabSuite/Core/Component/GoogleMaps/Geocoding.ts
wcfsetup/install/files/js/WoltLabSuite/Core/Component/GoogleMaps/Geocoding.js

index 517e202bfa0a9b8802b3ceb0399c77d5c0e6cb4a..cb6497e0d1da992a8a36fa845f4c1dafa3eb9527 100644 (file)
@@ -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<MoveMarkerEventPayload>) => {
-      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<ResolveEventPayload>) => {
@@ -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<void> {
     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<void> {
-    const location = new google.maps.LatLng(latitude, longitude);
+  async #moveMarkerToLocation(location: google.maps.LatLng): Promise<void> {
     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<void> {
index 7d79d3fa0fbe805091fcae8c730663b24cbeaf6c..b9b3b7525e407d89912338b9fb82ea58f3391127 100644 (file)
@@ -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();