From 421575f2f4bae2ee006641bc8a6fea835651848d Mon Sep 17 00:00:00 2001 From: rug Date: Thu, 26 Oct 2023 00:04:17 +0200 Subject: [PATCH 1/4] Adding types to events --- .../DrawingTools/IDrawingToolsEventParams.ts | 9 +++++++++ .../FileLayer/FileLayersEventsManager.ts | 10 ++++++---- .../SearchPlaces/SearchPlacesEventsManager.ts | 18 +++++++++--------- .../Maps/FileLayer/IFileLayerEventParams.ts | 7 +++++++ .../SearchPlaces/ISearchPlacesEventParams.ts | 8 ++++++++ .../Google/DrawingTools/AbstractDrawShape.ts | 19 +++++++++++-------- .../Maps/Google/FileLayer/FileLayer.ts | 13 ++++++++----- .../Maps/Google/SearchPlaces/SearchPlaces.ts | 19 +++++++++++-------- 8 files changed, 69 insertions(+), 34 deletions(-) create mode 100644 src/OSFramework/Maps/DrawingTools/IDrawingToolsEventParams.ts create mode 100644 src/OSFramework/Maps/FileLayer/IFileLayerEventParams.ts create mode 100644 src/OSFramework/Maps/SearchPlaces/ISearchPlacesEventParams.ts diff --git a/src/OSFramework/Maps/DrawingTools/IDrawingToolsEventParams.ts b/src/OSFramework/Maps/DrawingTools/IDrawingToolsEventParams.ts new file mode 100644 index 00000000..d242c236 --- /dev/null +++ b/src/OSFramework/Maps/DrawingTools/IDrawingToolsEventParams.ts @@ -0,0 +1,9 @@ +// eslint-disable-next-line @typescript-eslint/no-unused-vars +namespace OSFramework.Maps.DrawingTools { + export interface IDrawingToolsEventParams { + coordinates: string; + isNewElement: boolean; + location: string | string[]; + uniqueId: string; + } +} diff --git a/src/OSFramework/Maps/Event/FileLayer/FileLayersEventsManager.ts b/src/OSFramework/Maps/Event/FileLayer/FileLayersEventsManager.ts index fc3dffeb..f358d32d 100644 --- a/src/OSFramework/Maps/Event/FileLayer/FileLayersEventsManager.ts +++ b/src/OSFramework/Maps/Event/FileLayer/FileLayersEventsManager.ts @@ -50,8 +50,9 @@ namespace OSFramework.Maps.Event.FileLayer { */ public trigger( eventType: FileLayersEventType, - // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars - ...args: any + data?: string, + fileLayerEventParams?: Maps.FileLayer.IFileLayerEventParams, + ...args: unknown[] ): void { // Check if the FileLayer has any events associated if (this.handlers.has(eventType)) { @@ -69,8 +70,9 @@ namespace OSFramework.Maps.Event.FileLayer { this._fileLayer.map.widgetId, // Id of Map block that was clicked this._fileLayer.widgetId || this._fileLayer.uniqueId, // Id of File Layer block that was clicked - args[0].coordinates, // LatLng from the click event - args[0].featureData // FeatureData from the FileLayer that was clicked + fileLayerEventParams.coordinates, // LatLng from the click event + fileLayerEventParams.featureData, // FeatureData from the FileLayer that was clicked + ...args ); break; // If the event is not valid we can fall in the default case of the switch and throw an error diff --git a/src/OSFramework/Maps/Event/SearchPlaces/SearchPlacesEventsManager.ts b/src/OSFramework/Maps/Event/SearchPlaces/SearchPlacesEventsManager.ts index dc97143e..8bc54325 100644 --- a/src/OSFramework/Maps/Event/SearchPlaces/SearchPlacesEventsManager.ts +++ b/src/OSFramework/Maps/Event/SearchPlaces/SearchPlacesEventsManager.ts @@ -77,8 +77,8 @@ namespace OSFramework.Maps.Event.SearchPlaces { // eslint-disable-next-line @typescript-eslint/no-unused-vars searchPlaces?: OSFramework.Maps.SearchPlaces.ISearchPlaces, eventInfo?: string, - // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars - ...args: any + searchPlacesEventParams?: Maps.SearchPlaces.ISearchPlacesEventParams, + ...args: unknown[] ): void { // Check if the FileLayer has any events associated if (this.handlers.has(eventType)) { @@ -103,20 +103,20 @@ namespace OSFramework.Maps.Event.SearchPlaces { break; case SearchPlacesEventType.OnPlaceSelect: handlerEvent.trigger( - this._searchPlaces, // SearchPlaces Object where the place selection occurred. - this._searchPlaces.widgetId || - this._searchPlaces.uniqueId, // Id of SearchPlaces block that was clicked - args[0].name, // name of the place selected - args[0].coordinates, // coordinates of the place selected - args[0].address // full address of the place selected + searchPlaces, // SearchPlaces Object where the place selection occurred. + searchPlaces.widgetId || searchPlaces.uniqueId, // Id of SearchPlaces block that was clicked + searchPlacesEventParams.name, // name of the place selected + searchPlacesEventParams.coordinates, // coordinates of the place selected + searchPlacesEventParams.address // full address of the place selected ); break; // If the event is not valid we can fall in the default case of the switch and throw an error default: this._searchPlaces.searchPlacesEvents.trigger( SearchPlaces.SearchPlacesEventType.OnError, - this._searchPlaces, + searchPlaces, Enum.ErrorCodes.GEN_UnsupportedEventSearchPlaces, + undefined, `${eventType}` ); return; diff --git a/src/OSFramework/Maps/FileLayer/IFileLayerEventParams.ts b/src/OSFramework/Maps/FileLayer/IFileLayerEventParams.ts new file mode 100644 index 00000000..caf299fc --- /dev/null +++ b/src/OSFramework/Maps/FileLayer/IFileLayerEventParams.ts @@ -0,0 +1,7 @@ +// eslint-disable-next-line @typescript-eslint/no-unused-vars +namespace OSFramework.Maps.FileLayer { + export interface IFileLayerEventParams { + coordinates: string; + featureData: string; + } +} diff --git a/src/OSFramework/Maps/SearchPlaces/ISearchPlacesEventParams.ts b/src/OSFramework/Maps/SearchPlaces/ISearchPlacesEventParams.ts new file mode 100644 index 00000000..788c9fe7 --- /dev/null +++ b/src/OSFramework/Maps/SearchPlaces/ISearchPlacesEventParams.ts @@ -0,0 +1,8 @@ +// eslint-disable-next-line @typescript-eslint/no-unused-vars +namespace OSFramework.Maps.SearchPlaces { + export interface ISearchPlacesEventParams { + address: string; + coordinates: string; + name: string; + } +} diff --git a/src/Providers/Maps/Google/DrawingTools/AbstractDrawShape.ts b/src/Providers/Maps/Google/DrawingTools/AbstractDrawShape.ts index 3c861a66..21162242 100644 --- a/src/Providers/Maps/Google/DrawingTools/AbstractDrawShape.ts +++ b/src/Providers/Maps/Google/DrawingTools/AbstractDrawShape.ts @@ -28,13 +28,7 @@ namespace Provider.Maps.Google.DrawingTools { eventName: string, shapeCoordinates: OSFramework.Maps.OSStructures.OSMap.OSShapeCoordinates ) => { - this.drawingTools.drawingToolsEvents.trigger( - // EventType - OSFramework.Maps.Event.DrawingTools - .DrawingToolsEventType.ProviderEvent, - // EventName - this.completedToolEventName, - // The extra parameters, uniqueId and isNewElement set to false indicating that the element is not new + const dtparams: OSFramework.Maps.DrawingTools.IDrawingToolsEventParams = { uniqueId: _shape.uniqueId, isNewElement: false, @@ -42,7 +36,16 @@ namespace Provider.Maps.Google.DrawingTools { coordinates: JSON.stringify( shapeCoordinates.coordinates ) - } + }; + + this.drawingTools.drawingToolsEvents.trigger( + // EventType + OSFramework.Maps.Event.DrawingTools + .DrawingToolsEventType.ProviderEvent, + // EventName + this.completedToolEventName, + // The extra parameters, uniqueId and isNewElement set to false indicating that the element is not new + dtparams ); } ); diff --git a/src/Providers/Maps/Google/FileLayer/FileLayer.ts b/src/Providers/Maps/Google/FileLayer/FileLayer.ts index 0463db91..1b2b5438 100644 --- a/src/Providers/Maps/Google/FileLayer/FileLayer.ts +++ b/src/Providers/Maps/Google/FileLayer/FileLayer.ts @@ -33,10 +33,7 @@ namespace Provider.Maps.Google.FileLayer { this.provider.addListener( 'click', (event: google.maps.KmlMouseEvent) => { - this.fileLayerEvents.trigger( - OSFramework.Maps.Event.FileLayer.FileLayersEventType - .OnClick, - // Extra parameters to be passed as arguments on the callback of the OnClick event handler + const flparams: OSFramework.Maps.FileLayer.IFileLayerEventParams = { // Coordinates from the event that was triggered (by the click) coordinates: JSON.stringify({ @@ -50,7 +47,13 @@ namespace Provider.Maps.Google.FileLayer { featureData: JSON.stringify( event.featureData as google.maps.KmlFeatureData ) - } + }; + this.fileLayerEvents.trigger( + OSFramework.Maps.Event.FileLayer.FileLayersEventType + .OnClick, + undefined, + // Extra parameters to be passed as arguments on the callback of the OnClick event handler + flparams ); } ); diff --git a/src/Providers/Maps/Google/SearchPlaces/SearchPlaces.ts b/src/Providers/Maps/Google/SearchPlaces/SearchPlaces.ts index cb362fc2..5b31040b 100644 --- a/src/Providers/Maps/Google/SearchPlaces/SearchPlaces.ts +++ b/src/Providers/Maps/Google/SearchPlaces/SearchPlaces.ts @@ -178,6 +178,16 @@ namespace Provider.Maps.Google.SearchPlaces { Constants.SearchPlaces.Events.OnPlaceSelect, () => { const place = this._provider.getPlace(); + const spparams: OSFramework.Maps.SearchPlaces.ISearchPlacesEventParams = + { + name: place.name, + coordinates: JSON.stringify({ + Lat: place.geometry.location.lat(), + Lng: place.geometry.location.lng() + }), + address: place.formatted_address + }; + place.geometry && this.searchPlacesEvents.trigger( OSFramework.Maps.Event.SearchPlaces @@ -185,14 +195,7 @@ namespace Provider.Maps.Google.SearchPlaces { this, // searchPlacesObj Constants.SearchPlaces.Events.OnPlaceSelect, // event name (eventInfo) // Extra parameters to be passed as arguments on the callback of the OnPlaceSelect event handler - { - name: place.name, - coordinates: JSON.stringify({ - Lat: place.geometry.location.lat(), - Lng: place.geometry.location.lng() - }), - address: place.formatted_address - } + spparams ); } ); From 1639ac6ba2eada3168b9ea9d8357d9e9cdbbd01e Mon Sep 17 00:00:00 2001 From: rug Date: Thu, 26 Oct 2023 00:06:15 +0200 Subject: [PATCH 2/4] Missing parameter, when not passed structure --- .../Maps/Event/SearchPlaces/SearchPlacesEventsManager.ts | 1 + src/OSFramework/Maps/SearchPlaces/AbstractSearchPlaces.ts | 1 + src/Providers/Maps/Google/SearchPlaces/SearchPlaces.ts | 1 + 3 files changed, 3 insertions(+) diff --git a/src/OSFramework/Maps/Event/SearchPlaces/SearchPlacesEventsManager.ts b/src/OSFramework/Maps/Event/SearchPlaces/SearchPlacesEventsManager.ts index 8bc54325..f6431542 100644 --- a/src/OSFramework/Maps/Event/SearchPlaces/SearchPlacesEventsManager.ts +++ b/src/OSFramework/Maps/Event/SearchPlaces/SearchPlacesEventsManager.ts @@ -39,6 +39,7 @@ namespace OSFramework.Maps.Event.SearchPlaces { SearchPlaces.SearchPlacesEventType.OnError, this._searchPlaces, Enum.ErrorCodes.GEN_UnsupportedEventSearchPlaces, + undefined, `${eventType}` ); return; diff --git a/src/OSFramework/Maps/SearchPlaces/AbstractSearchPlaces.ts b/src/OSFramework/Maps/SearchPlaces/AbstractSearchPlaces.ts index ead2a904..08f9a93b 100644 --- a/src/OSFramework/Maps/SearchPlaces/AbstractSearchPlaces.ts +++ b/src/OSFramework/Maps/SearchPlaces/AbstractSearchPlaces.ts @@ -82,6 +82,7 @@ namespace OSFramework.Maps.SearchPlaces { Event.SearchPlaces.SearchPlacesEventType.OnError, this, Enum.ErrorCodes.GEN_InvalidChangePropertySearchPlaces, + undefined, `${propertyName}` ); } diff --git a/src/Providers/Maps/Google/SearchPlaces/SearchPlaces.ts b/src/Providers/Maps/Google/SearchPlaces/SearchPlaces.ts index 5b31040b..048766fb 100644 --- a/src/Providers/Maps/Google/SearchPlaces/SearchPlaces.ts +++ b/src/Providers/Maps/Google/SearchPlaces/SearchPlaces.ts @@ -115,6 +115,7 @@ namespace Provider.Maps.Google.SearchPlaces { this, OSFramework.Maps.Enum.ErrorCodes .LIB_FailedGeocodingSearchAreaLocations, + undefined, `${error}` ); }); From 0afa787941243ceaf6b7c707f4b631e0593be7ef Mon Sep 17 00:00:00 2001 From: rug Date: Thu, 26 Oct 2023 00:07:24 +0200 Subject: [PATCH 3/4] Missing parameter --- src/Providers/Maps/Google/SearchPlaces/SearchPlaces.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Providers/Maps/Google/SearchPlaces/SearchPlaces.ts b/src/Providers/Maps/Google/SearchPlaces/SearchPlaces.ts index 048766fb..9ce1f1ec 100644 --- a/src/Providers/Maps/Google/SearchPlaces/SearchPlaces.ts +++ b/src/Providers/Maps/Google/SearchPlaces/SearchPlaces.ts @@ -290,6 +290,7 @@ namespace Provider.Maps.Google.SearchPlaces { this, OSFramework.Maps.Enum.ErrorCodes .CFG_InvalidSearchPlacesSearchArea, + undefined, `${error}` ); }); From 9048e5a4214a0bdda6b66679d0d4b238f961e9a1 Mon Sep 17 00:00:00 2001 From: rug Date: Mon, 30 Oct 2023 09:47:36 +0100 Subject: [PATCH 4/4] Improving variable name --- src/Providers/Maps/Google/DrawingTools/AbstractDrawShape.ts | 4 ++-- src/Providers/Maps/Google/FileLayer/FileLayer.ts | 4 ++-- src/Providers/Maps/Google/SearchPlaces/SearchPlaces.ts | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Providers/Maps/Google/DrawingTools/AbstractDrawShape.ts b/src/Providers/Maps/Google/DrawingTools/AbstractDrawShape.ts index 21162242..bb8cbc1a 100644 --- a/src/Providers/Maps/Google/DrawingTools/AbstractDrawShape.ts +++ b/src/Providers/Maps/Google/DrawingTools/AbstractDrawShape.ts @@ -28,7 +28,7 @@ namespace Provider.Maps.Google.DrawingTools { eventName: string, shapeCoordinates: OSFramework.Maps.OSStructures.OSMap.OSShapeCoordinates ) => { - const dtparams: OSFramework.Maps.DrawingTools.IDrawingToolsEventParams = + const dtParams: OSFramework.Maps.DrawingTools.IDrawingToolsEventParams = { uniqueId: _shape.uniqueId, isNewElement: false, @@ -45,7 +45,7 @@ namespace Provider.Maps.Google.DrawingTools { // EventName this.completedToolEventName, // The extra parameters, uniqueId and isNewElement set to false indicating that the element is not new - dtparams + dtParams ); } ); diff --git a/src/Providers/Maps/Google/FileLayer/FileLayer.ts b/src/Providers/Maps/Google/FileLayer/FileLayer.ts index 1b2b5438..d185b6a9 100644 --- a/src/Providers/Maps/Google/FileLayer/FileLayer.ts +++ b/src/Providers/Maps/Google/FileLayer/FileLayer.ts @@ -33,7 +33,7 @@ namespace Provider.Maps.Google.FileLayer { this.provider.addListener( 'click', (event: google.maps.KmlMouseEvent) => { - const flparams: OSFramework.Maps.FileLayer.IFileLayerEventParams = + const flParams: OSFramework.Maps.FileLayer.IFileLayerEventParams = { // Coordinates from the event that was triggered (by the click) coordinates: JSON.stringify({ @@ -53,7 +53,7 @@ namespace Provider.Maps.Google.FileLayer { .OnClick, undefined, // Extra parameters to be passed as arguments on the callback of the OnClick event handler - flparams + flParams ); } ); diff --git a/src/Providers/Maps/Google/SearchPlaces/SearchPlaces.ts b/src/Providers/Maps/Google/SearchPlaces/SearchPlaces.ts index 9ce1f1ec..552ca56d 100644 --- a/src/Providers/Maps/Google/SearchPlaces/SearchPlaces.ts +++ b/src/Providers/Maps/Google/SearchPlaces/SearchPlaces.ts @@ -179,7 +179,7 @@ namespace Provider.Maps.Google.SearchPlaces { Constants.SearchPlaces.Events.OnPlaceSelect, () => { const place = this._provider.getPlace(); - const spparams: OSFramework.Maps.SearchPlaces.ISearchPlacesEventParams = + const spParams: OSFramework.Maps.SearchPlaces.ISearchPlacesEventParams = { name: place.name, coordinates: JSON.stringify({ @@ -196,7 +196,7 @@ namespace Provider.Maps.Google.SearchPlaces { this, // searchPlacesObj Constants.SearchPlaces.Events.OnPlaceSelect, // event name (eventInfo) // Extra parameters to be passed as arguments on the callback of the OnPlaceSelect event handler - spparams + spParams ); } );