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-11055: Adding Google Advanced Markers and Map Style Id properties #183

Merged
merged 23 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 21 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# OutSystems Maps · v1.8.0
# OutSystems Maps · v2.0.0

![GitHub License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg) ![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)

Expand Down
2 changes: 1 addition & 1 deletion gulp/DefaultSpecs.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const constants = {

// Store the default project specifications
const specs = {
version: '1.8.0',
version: '2.0.0',
name: 'OutSystems Maps',
description: '',
url: 'Website:\n • ' + constants.websiteUrl,
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "outsystems-maps",
"version": "1.8.0",
"version": "2.0.0",
"description": "OutSystems Maps",
"author": "UI Components Team",
"license": "BSD-3-Clause",
Expand All @@ -25,7 +25,7 @@
"homepage": "https://outsystemsui.outsystems.com/OutSystemsMapsSample/",
"devDependencies": {
"@googlemaps/markerclusterer": "^2.5.3",
"@types/google.maps": "^3.46.0",
"@types/google.maps": "^3.55.10",
"@types/leaflet-routing-machine": "^3.2.3",
"@types/leaflet": "^1.7.5",
"@typescript-eslint/eslint-plugin": "^6.21.0",
Expand Down
1 change: 1 addition & 0 deletions src/Global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ declare global {
type GoogleMapsAlgorithm = OriginalAlgorithm;
type GoogleMapsCluster = OriginalCluster;
type GoogleMapsMarker = google.maps.Marker | google.maps.marker.AdvancedMarkerElement;
type GoogleMapsMarkerOptions = google.maps.MarkerOptions | google.maps.marker.AdvancedMarkerElementOptions;
type GoogleMapsMarkerClusterer = OriginalMarkerClusterer;
type GoogleMapsMarkerClustererOptions = OriginalMarkerClustererOptions;
type GoogleMapsClusterRenderer = OriginalRenderer;
Expand Down
2 changes: 1 addition & 1 deletion src/OSFramework/Maps/Constants.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// eslint-disable-next-line @typescript-eslint/no-unused-vars
namespace OSFramework.Maps.Constants {
/* OutSystems Maps Version */
export const OSMapsVersion = '1.8.0';
export const OSMapsVersion = '2.0.0';

/**
* DataGrid Set platform in use.
Expand Down
1 change: 1 addition & 0 deletions src/OSFramework/Maps/Enum/ErrorCodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ namespace OSFramework.Maps.Enum {
GEN_InvalidChangePropertyShape = 'MAPS-GEN-05001',
GEN_InvalidChangePropertyDrawingTools = 'MAPS-GEN-06001',
GEN_InvalidChangePropertyTools = 'MAPS-GEN-06002',
GEN_InvalidChangePropertyUseAdvancedMarkers = 'MAPS-GEN-06005',
GEN_UnsupportedEventShape = 'MAPS-GEN-05002',
GEN_UnsupportedEventDrawingTools = 'MAPS-GEN-06003',
GEN_ToolTypeAlreadyExists = 'MAPS-GEN-06004',
Expand Down
2 changes: 2 additions & 0 deletions src/OSFramework/Maps/Enum/OS_Config_Map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace OSFramework.Maps.Enum {
height,
center,
localization,
mapStyleId,
markerClustererActive,
markerClustererMaxZoom,
markerClustererMinClusterSize,
Expand All @@ -20,6 +21,7 @@ namespace OSFramework.Maps.Enum {
style,
type,
uniqueId,
useAdvancedMarkers,
zoom,
}
}
4 changes: 2 additions & 2 deletions src/OSFramework/Maps/Helper/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ namespace OSFramework.Maps.Helper.Constants {
/** URL for GoogleMaps API to make use of the Google StaticMap */
export const googleMapsApiStaticMap = `${googleMapsApiURL}/staticmap`;
/** Version of the Google Maps to be loaded. */
export const gmversion = '3.55'; //Stable version Mid-February 2024.
export const gmversion = '3.57'; //Stable version Mid-February 2024.
// In order to use the drawingTools we need to add it into the libraries via the URL = drawing
// In order to use the heatmap we need to add it into the libraries via the URL = visualization
// In order to use the searchplaces we need to add it into the libraries via the URL = places (in case the Map is the first to import the scripts)
export const gmlibraries = 'drawing,visualization,places';
export const gmlibraries = 'drawing,visualization,places,marker';

/******************** */
/** URLs for Leaflet */
Expand Down
13 changes: 13 additions & 0 deletions src/OSFramework/Maps/Marker/AbstractMarker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,19 @@ namespace OSFramework.Maps.Marker {
return id === this._uniqueId || id === this._widgetId;
}

public getPosition(): OSFramework.Maps.OSStructures.OSMap.ICoordenates {
// As we don't have the provider defined in the interface, we need to cast it
// to any to access the position property that is different between providers
// and even versions of Markers being used (google maps).
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const provider = this._provider as any;
// Until version 3.55 of google maps the position of the marker is a function
// same as in Leaflet maps. From version 3.56 the position is an object, when
// using the AdvancedMarkerElement.
const position = provider.getPosition ? provider.getPosition() : provider.position;
return position as OSFramework.Maps.OSStructures.OSMap.ICoordenates;
}

public getProviderConfig(): unknown {
return this.config.getProviderConfig();
}
Expand Down
2 changes: 2 additions & 0 deletions src/OSFramework/Maps/Marker/IMarker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ namespace OSFramework.Maps.Marker {
build(): void;
changeProperty(propertyName: string, propertyValue: unknown): void;
dispose(): void;

getPosition(): OSFramework.Maps.OSStructures.OSMap.ICoordenates;
/**
* Refreshes the Events of the Marker Provider after Subscribing/Unsubscribing events
*/
Expand Down
7 changes: 6 additions & 1 deletion src/OSFramework/Maps/OSStructures/OSMap.Coordinates.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
// eslint-disable-next-line @typescript-eslint/no-unused-vars
namespace OSFramework.Maps.OSStructures.OSMap {
export class Coordinates {
export interface ICoordenates {
lat: number | (() => number);
lng: number | (() => number);
}

export class Coordinates implements ICoordenates {
public lat: number | (() => number);
public lng: number | (() => number);
}
Expand Down
93 changes: 47 additions & 46 deletions src/OutSystems/Maps/MapAPI/MarkerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,35 @@ namespace OutSystems.Maps.MapAPI.MarkerManager {
const markerMap = new Map<string, string>(); //marker.uniqueId -> map.uniqueId
const markerArr = new Array<OSFramework.Maps.Marker.IMarker>();

/**
* Gets the Map to which the Marker belongs to
*
* @param {string} markerId Id of the Marker that exists on the Map
* @returns {*} {MarkerMapper} this structure has the id of Map, and the reference to the instance of the Map
*/
function GetMapByMarkerId(markerId: string): OSFramework.Maps.OSMap.IMap {
let map: OSFramework.Maps.OSMap.IMap;

//markerId is the UniqueId
if (markerMap.has(markerId)) {
map = MapManager.GetMapById(markerMap.get(markerId), false);
}
//UniqueID not found
else {
// Try to find its reference on DOM
const elem = OSFramework.Maps.Helper.GetElementByUniqueId(markerId, false);

// If element is found, means that the DOM was rendered
if (elem !== undefined) {
//Find the closest Map
const mapId = OSFramework.Maps.Helper.GetClosestMapId(elem);
map = MapManager.GetMapById(mapId);
}
}

return map;
}

/**
* Creates and adds a marker to a map.
*
Expand Down Expand Up @@ -97,8 +126,7 @@ namespace OutSystems.Maps.MapAPI.MarkerManager {
// Check if the feature is enabled!
if (map.hasMarkerClusterer()) {
const marker = map.markers.find((marker) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return (marker.provider as any).location === markerPosition;
return marker.config.location === markerPosition;
});

// Check if there is a marker with the given Position/Location
Expand Down Expand Up @@ -140,20 +168,24 @@ namespace OutSystems.Maps.MapAPI.MarkerManager {
*/
export function CreateMarker(mapId: string, markerId: string, configs: string): OSFramework.Maps.Marker.IMarker {
const map = MapManager.GetMapById(mapId, true);
if (!map.hasMarker(markerId)) {
const _marker = Provider.Maps.Google.Marker.MarkerFactory.MakeMarker(
map,
markerId,
OSFramework.Maps.Enum.MarkerType.Marker,
JSON.parse(configs)
);
markerArr.push(_marker);
markerMap.set(markerId, map.uniqueId);
map.addMarker(_marker);

return _marker;
if (map.providerType === OSFramework.Maps.Enum.ProviderType.Google) {
OS-giulianasilva marked this conversation as resolved.
Show resolved Hide resolved
if (!map.hasMarker(markerId)) {
const _marker = Provider.Maps.Google.Marker.MarkerFactory.MakeMarker(
map,
markerId,
OSFramework.Maps.Enum.MarkerType.Marker,
JSON.parse(configs)
);
markerArr.push(_marker);
markerMap.set(markerId, map.uniqueId);
map.addMarker(_marker);

return _marker;
} else {
throw new Error(`There is already a Marker registered on the specified Map under id:${markerId}`);
}
} else {
throw new Error(`There is already a Marker registered on the specified Map under id:${markerId}`);
throw new Error(`The provider type '${map.providerType}' does not support this operation.`);
}
}

Expand Down Expand Up @@ -189,37 +221,6 @@ namespace OutSystems.Maps.MapAPI.MarkerManager {
}
}

/**
* [Not used]
* Gets the Map to which the Marker belongs to
*
* @param {string} markerId Id of the Marker that exists on the Map
* @returns {*} {MarkerMapper} this structure has the id of Map, and the reference to the instance of the Map
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
function GetMapByMarkerId(markerId: string): OSFramework.Maps.OSMap.IMap {
let map: OSFramework.Maps.OSMap.IMap;

//markerId is the UniqueId
if (markerMap.has(markerId)) {
map = MapManager.GetMapById(markerMap.get(markerId), false);
}
//UniqueID not found
else {
// Try to find its reference on DOM
const elem = OSFramework.Maps.Helper.GetElementByUniqueId(markerId, false);

// If element is found, means that the DOM was rendered
if (elem !== undefined) {
//Find the closest Map
const mapId = OSFramework.Maps.Helper.GetClosestMapId(elem);
map = MapManager.GetMapById(mapId);
}
}

return map;
}

/**
* Returns a Marker based on Id
* @param markerId Id of the Marker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ namespace Provider.Maps.Google.Configuration.DrawingTools {

public getProviderConfig(): unknown[] {
const provider = super.getProviderConfig();
// The property icon is used by the DeprecatedMarker
provider.icon = this.iconUrl;
// The property iconUrl is used by the AdvancedMarker
provider.iconUrl = this.iconUrl;

Object.keys(provider).forEach((key) => {
if (provider[key] === undefined) delete provider[key];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/// <reference path="../../../../../OSFramework/Maps/Configuration/AbstractConfiguration.ts" />

// eslint-disable-next-line @typescript-eslint/no-unused-vars
namespace Provider.Maps.Google.Configuration.Marker {
export class DeprecatedGoogleMarkerConfig
extends OSFramework.Maps.Configuration.AbstractConfiguration
implements OSFramework.Maps.Configuration.IConfigurationMarker
{
public allowDrag: boolean;
public iconHeight: number;
public iconUrl: string;
public iconWidth: number;
public label: string;
public location: string;
public title: string;

public getProviderConfig(): unknown {
const provider = {
draggable: this.allowDrag,
icon: this.iconUrl,
label: this.label,
location: this.location,
title: this.title,
};

//Deleting all the undefined properties
Object.keys(provider).forEach((key) => {
if (provider[key] === undefined) delete provider[key];
});

return provider;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ namespace Provider.Maps.Google.Configuration.Marker {

public getProviderConfig(): unknown {
const provider = {
draggable: this.allowDrag,
icon: this.iconUrl,
label: this.label,
location: this.location,
gmpDraggable: this.allowDrag,
title: this.title,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,41 @@ namespace Provider.Maps.Google.Configuration.OSMap {
public center: string | OSFramework.Maps.OSStructures.OSMap.Coordinates;
public height: string;
public localization: OSFramework.Maps.OSStructures.OSMap.Localization;
public mapStyleId: string;
public markerClusterer: OSFramework.Maps.Configuration.IConfigurationMarkerClusterer;
public offset: OSFramework.Maps.OSStructures.OSMap.Offset;
public respectUserZoom: boolean;
public showTraffic: boolean;
public style: OSFramework.Maps.Enum.OSMap.Style;
public type: OSFramework.Maps.Enum.OSMap.Type;
public uniqueId: string;
public useAdvancedMarkers: boolean;
public zoom: OSFramework.Maps.Enum.OSMap.Zoom;

public getProviderConfig(): unknown {
let mapStyleId = this.mapStyleId;
let style = this.style;

//Safe guard to assure that the mapId is not set when advancedMarkers is false
if (this.useAdvancedMarkers === false) {
mapStyleId = undefined;
} else {
// In Low-Code the style is 1-based, so we need to subtract 1 to match the enum
// which is 0-based.
const styleId = this.style - 1;
if (styleId === OSFramework.Maps.Enum.OSMap.Style.Standard) {
// If the developer is using the advanced markers and the style is standard, the style will be set
// to undefined (and subsequently removed) to avoid conflicts with the mapId.
style = undefined;
}
}

const provider = {
center: this.center,
zoom: this.zoom,
styles: this.style,
mapId: mapStyleId,
mapTypeId: this.type,
styles: style,
zoom: this.zoom,
};

//Cleanning undefined properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace Provider.Maps.Google.Configuration.OSMap {
public localization: OSFramework.Maps.OSStructures.OSMap.Localization;
public type: OSFramework.Maps.Enum.OSMap.Type;
public uniqueId: string;
public useAdvancedMarkers: boolean;
public zoom: OSFramework.Maps.Enum.OSMap.Zoom;

public getProviderConfig(): unknown {
Expand Down
30 changes: 30 additions & 0 deletions src/Providers/Maps/Google/Constants/Marker/DeprecatedEvents.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// eslint-disable-next-line @typescript-eslint/no-unused-vars
namespace Provider.Maps.Google.Constants.Marker {
/**
* Enum that defines the available Provider Events
*/
export enum DeprecatedProviderEventNames {
changed = 'animation_changed',
click = 'click',
clickable_changed = 'clickable_changed',
contextmenu = 'contextmenu',
cursor_changed = 'cursor_changed',
dblclick = 'dblclick',
drag = 'drag',
dragend = 'dragend',
draggable_changed = 'draggable_changed',
dragstart = 'dragstart',
flat_changed = 'flat_changed',
icon_changed = 'icon_changed',
mousedown = 'mousedown',
mouseout = 'mouseout',
mouseover = 'mouseover',
mouseup = 'mouseup',
position_changed = 'position_changed',
rightclick = 'rightclick',
shape_changed = 'shape_changed',
title_changed = 'title_changed',
visible_changed = 'visible_changed',
zindex_changed = 'zindex_changed',
}
}
Loading
Loading