Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ROU-4375: Add types to events #142

Merged
merged 4 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ namespace OSFramework.Maps.Event.SearchPlaces {
SearchPlaces.SearchPlacesEventType.OnError,
this._searchPlaces,
Enum.ErrorCodes.GEN_UnsupportedEventSearchPlaces,
undefined,
`${eventType}`
);
return;
Expand Down Expand Up @@ -77,8 +78,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)) {
Expand All @@ -103,20 +104,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;
Expand Down
7 changes: 7 additions & 0 deletions src/OSFramework/Maps/FileLayer/IFileLayerEventParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// eslint-disable-next-line @typescript-eslint/no-unused-vars
namespace OSFramework.Maps.FileLayer {
export interface IFileLayerEventParams {
coordinates: string;
featureData: string;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ namespace OSFramework.Maps.SearchPlaces {
Event.SearchPlaces.SearchPlacesEventType.OnError,
this,
Enum.ErrorCodes.GEN_InvalidChangePropertySearchPlaces,
undefined,
`${propertyName}`
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
19 changes: 11 additions & 8 deletions src/Providers/Maps/Google/DrawingTools/AbstractDrawShape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,24 @@ 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,
location: JSON.stringify(shapeCoordinates.location),
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
);
}
);
Expand Down
13 changes: 8 additions & 5 deletions src/Providers/Maps/Google/FileLayer/FileLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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
);
}
);
Expand Down
21 changes: 13 additions & 8 deletions src/Providers/Maps/Google/SearchPlaces/SearchPlaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ namespace Provider.Maps.Google.SearchPlaces {
this,
OSFramework.Maps.Enum.ErrorCodes
.LIB_FailedGeocodingSearchAreaLocations,
undefined,
`${error}`
);
});
Expand Down Expand Up @@ -178,21 +179,24 @@ namespace Provider.Maps.Google.SearchPlaces {
Constants.SearchPlaces.Events.OnPlaceSelect,
() => {
const place = this._provider.getPlace();
const spparams: OSFramework.Maps.SearchPlaces.ISearchPlacesEventParams =
rugoncalves marked this conversation as resolved.
Show resolved Hide resolved
{
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
.SearchPlacesEventType.OnPlaceSelect,
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
);
}
);
Expand Down Expand Up @@ -286,6 +290,7 @@ namespace Provider.Maps.Google.SearchPlaces {
this,
OSFramework.Maps.Enum.ErrorCodes
.CFG_InvalidSearchPlacesSearchArea,
undefined,
`${error}`
);
});
Expand Down
Loading