Skip to content

Commit

Permalink
Code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
rugoncalves committed Feb 16, 2024
1 parent a2926c9 commit 0ae84ac
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 39 deletions.
7 changes: 1 addition & 6 deletions src/OSFramework/Maps/FileLayer/AbstractFileLayer.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
// eslint-disable-next-line @typescript-eslint/no-unused-vars
namespace OSFramework.Maps.FileLayer {
export abstract class AbstractFileLayer<
W,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
T extends Configuration.IConfigurationFileLayer,
> implements IFileLayer
{
export abstract class AbstractFileLayer<W, T extends Configuration.IConfigurationFileLayer> implements IFileLayer {
/** Configuration reference */
private _config: T;
private _map: OSMap.IMap;
Expand Down
3 changes: 1 addition & 2 deletions src/OSFramework/Maps/FileLayer/IFileLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ namespace OSFramework.Maps.FileLayer {
fileLayerEvents: Event.FileLayer.FileLayersEventsManager;
isReady: boolean;
map: OSMap.IMap; //IMap
// eslint-disable-next-line @typescript-eslint/no-explicit-any
provider: any;
provider: unknown;
uniqueId: string;
widgetId: string;

Expand Down
3 changes: 1 addition & 2 deletions src/OSFramework/Maps/Marker/IMarker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ namespace OSFramework.Maps.Marker {
isReady: boolean;
map: OSMap.IMap; //IMap
markerEvents: Event.Marker.MarkerEventsManager;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
provider: any;
provider: unknown;
uniqueId: string;
widgetId: string;

Expand Down
2 changes: 1 addition & 1 deletion src/OSFramework/Maps/OSMap/AbstractMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ namespace OSFramework.Maps.OSMap {
return Array.from(this._markersSet);
}

public get markersReady(): W[] {
public get markersReady(): unknown[] {
// We need to go through all the markers and only get the ones that are ready (or have the provider defined)
// Then we need to return the providers inside a list
return this.markers.filter((marker) => marker.isReady).map((marker) => marker.provider);
Expand Down
8 changes: 6 additions & 2 deletions src/OutSystems/Maps/MapAPI/MarkerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,16 @@ namespace OutSystems.Maps.MapAPI.MarkerManager {
if (map.providerType === OSFramework.Maps.Enum.ProviderType.Google) {
// Check if the feature is enabled!
if (map.hasMarkerClusterer()) {
const marker = map.markers.find((marker) => marker.provider.location === markerPosition);
const marker = map.markers.find((marker) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return (marker.provider as any).location === markerPosition;
});

// Check if there is a marker with the given Position/Location
if (marker !== undefined) {
map.features.markerClusterer.removeMarker(marker);
marker.provider.setMap(map.provider);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(marker.provider as any).setMap(map.provider);
} else {
responseObj.isSuccess = false;
responseObj.message = `There are not a marker with position:'${markerPosition}' to be removed.`;
Expand Down
12 changes: 7 additions & 5 deletions src/Providers/Maps/Google/DrawingTools/DrawMarker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,22 @@ namespace Provider.Maps.Google.DrawingTools {
}

private _setOnChangeEvent(_marker: OSFramework.Maps.Marker.IMarker): void {
const markerProvider = _marker.provider as google.maps.Marker;
_marker.markerEvents.addHandler(
// changing the marker location is only available via the drag-and-drop, so the solution passes by adding the dragend event listener as the marker's OnChanged event
'dragend' as OSFramework.Maps.Event.Marker.MarkerEventType,
// Trigger the onDrawingChangeEvent with the extra information (marker uniqueId and flag indicating that the element is not new)
() =>
() => {
this.triggerOnDrawingChangeEvent(
_marker.uniqueId,
false,
JSON.stringify({
Lat: _marker.provider.getPosition().lat(),
Lng: _marker.provider.getPosition().lng(),
Lat: markerProvider.getPosition().lat(),
Lng: markerProvider.getPosition().lng(),
}),
`${_marker.provider.getPosition().lat()},${_marker.provider.getPosition().lng()}`
)
`${markerProvider.getPosition().lat()}, ${markerProvider.getPosition().lng()}`
);
}
);
}

Expand Down
4 changes: 3 additions & 1 deletion src/Providers/Maps/Google/Features/GoogleMarkerClusterer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ namespace Provider.Maps.Google.Feature {
this._rebuildClusters();
} else {
this._markerClusterer.clearMarkers();
this._map.markers.forEach((marker) => marker.provider.setMap(this._map.provider));
this._map.markers.forEach((marker) => {
(marker.provider as google.maps.Marker).setMap(this._map.provider);
});
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Providers/Maps/Google/Features/InfoWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace Provider.Maps.Google.Feature {
if (this._popupIsOpened === true) {
this.closePopup();
}
this._infoWindow.open(this._map.provider, marker.provider);
this._infoWindow.open(this._map.provider, marker.provider as google.maps.Marker);
this._popupIsOpened = true;
}

Expand Down
12 changes: 7 additions & 5 deletions src/Providers/Maps/Leaflet/DrawingTools/DrawMarker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,22 @@ namespace Provider.Maps.Leaflet.DrawingTools {
}

private _setOnChangeEvent(_marker: OSFramework.Maps.Marker.IMarker): void {
const markerProvider = _marker.provider as L.Marker;
_marker.markerEvents.addHandler(
// changing the marker location is only available via the drag-and-drop, so the solution passes by adding the dragend event listener as the marker's OnChanged event
'dragend' as OSFramework.Maps.Event.Marker.MarkerEventType,
// Trigger the onDrawingChangeEvent with the extra information (marker uniqueId and flag indicating that the element is not new)
() =>
() => {
this.triggerOnDrawingChangeEvent(
_marker.uniqueId,
false,
JSON.stringify({
Lat: _marker.provider.getLatLng().lat,
Lng: _marker.provider.getLatLng().lng,
Lat: markerProvider.getLatLng().lat,
Lng: markerProvider.getLatLng().lng,
}),
`${_marker.provider.getLatLng().lat},${_marker.provider.getLatLng().lng}`
)
`${markerProvider.getLatLng().lat}, ${markerProvider.getLatLng().lng}`
);
}
);
}

Expand Down
15 changes: 5 additions & 10 deletions src/Providers/Maps/Leaflet/Features/InfoWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,11 @@
namespace Provider.Maps.Leaflet.Feature {
export class InfoWindow implements OSFramework.Maps.Feature.IInfoWindow, OSFramework.Maps.Interface.IBuilder {
private _infoWindow: L.Popup;
private _map: OSMap.IMapLeaflet;
private _popupIsOpened: boolean;

constructor(map: OSMap.IMapLeaflet) {
this._map = map;
}

// This method is a way of getting the options which include the offset.
// The offset needs to be acquired dynamically as it should change according to the height of the icon applied to the marker.
private _getOptions(marker: OSFramework.Maps.Marker.IMarkerPopup): L.PopupOptions {
private _getOptions(marker: Marker.MarkerPopup): L.PopupOptions {
// Let's use the height of the marker icon as the offsetY. But if the height of the icon is not defined: use the runtime offsetHeight of the marker element
const offsetHeight =
marker.config.iconHeight > 0 ? marker.config.iconHeight : marker.provider.getElement().offsetHeight;
Expand All @@ -31,7 +26,7 @@ namespace Provider.Maps.Leaflet.Feature {
this._popupIsOpened = false;
}

public closePopup(marker: OSFramework.Maps.Marker.IMarkerPopup): void {
public closePopup(marker: Marker.MarkerPopup): void {
if (this._popupIsOpened) {
marker.provider.closePopup();
// Let's make sure the popup gets unlinked from the Marker
Expand All @@ -40,7 +35,7 @@ namespace Provider.Maps.Leaflet.Feature {
}
}

public openPopup(marker: OSFramework.Maps.Marker.IMarkerPopup): void {
public openPopup(marker: Marker.MarkerPopup): void {
if (this._popupIsOpened === true) {
this.closePopup(marker);
}
Expand All @@ -49,10 +44,10 @@ namespace Provider.Maps.Leaflet.Feature {
this._popupIsOpened = true;
}

public setPopupContent(content: string, marker: OSFramework.Maps.Marker.IMarkerPopup): void {
public setPopupContent(content: string, marker: Marker.MarkerPopup): void {
this._infoWindow.setContent(content);
this._infoWindow.update();
marker.provider.setPopupContent(this._infoWindow.getContent());
marker.provider.setPopupContent(this._infoWindow.getContent() as L.Content);
}
}
}
2 changes: 1 addition & 1 deletion src/Providers/Maps/Leaflet/Features/Zoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Provider.Maps.Leaflet.Feature {
let bounds: L.LatLngBounds;
this._map.markers.forEach(function (marker) {
if (marker.provider === undefined) return;
const loc: L.LatLng = marker.provider.getLatLng();
const loc: L.LatLng = (marker.provider as L.Marker).getLatLng();
bounds = bounds ? bounds.extend(loc) : new L.LatLngBounds(loc, loc);
});
if (useShapes) {
Expand Down
7 changes: 4 additions & 3 deletions src/Providers/Maps/Leaflet/OSMap/OSMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,23 +269,24 @@ namespace Provider.Maps.Leaflet.OSMap {
//If there are markers, let's choose the map center accordingly.
//Otherwise, the map center will be the one defined in the configs.
if (this.markers.length > 0) {
const markerProvider = this.markers[0].provider as L.Marker;
if (this.markers.length > 1) {
//As the map has more than one marker, let's see if the map
//center should be changed.
if (this.allowRefreshZoom) {
//If the user hasn't change zoom, or the developer is ignoring
//it (current behavior), then the map will be centered tentatively
//in the first marker.
position = this.markers[0].provider.getLatLng();
position = markerProvider.getLatLng();
} else {
//If the user has zoomed and the developer intends to respect user zoom
//then the current map center will be used.
position = this.provider.getCenter();
}
} else if (this.markers[0].provider !== undefined) {
} else if (markerProvider !== undefined) {
//If there's only one marker, and is already created, its location will be
//used as the map center.
position = this.markers[0].provider.getLatLng();
position = markerProvider.getLatLng();
}
}

Expand Down

0 comments on commit 0ae84ac

Please sign in to comment.