-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #184 from OutSystems/ROU-4776
ROU-4776: adding ability to change google maps version
- Loading branch information
Showing
16 changed files
with
276 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
namespace OSFramework.Maps.Helper.LocalStorage { | ||
/** | ||
* Get an item from the local storage. | ||
* | ||
* @export | ||
* @param {string} key | ||
* @return {*} {string} | ||
*/ | ||
export function GetItem(key: string): string { | ||
return window.localStorage.getItem(key); | ||
} | ||
|
||
/** | ||
* Checks if an item exists in the local storage. | ||
* | ||
* @export | ||
* @param {string} key | ||
* @return {*} {boolean} | ||
*/ | ||
export function HasItem(key: string): boolean { | ||
return window.localStorage.getItem(key) !== null; | ||
} | ||
|
||
/** | ||
* Set an item in the local storage. | ||
* | ||
* @export | ||
* @param {string} key | ||
* @param {string} value | ||
*/ | ||
export function SetItem(key: string, value: string): void { | ||
window.localStorage.setItem(key, value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
namespace OSFramework.Maps.ProviderVersion { | ||
/** | ||
* Function that allows to set the version of a specific the provider. | ||
* If the forceRefresh is set to true and the version has changed, the page will be reloaded. | ||
* Otherwise, the version will be updated in the local storage. | ||
* | ||
* @export | ||
* @param {OSFramework.Maps.Enum.ProviderType} provider | ||
* @param {string} version | ||
* @param {boolean} [forceRefresh=false] | ||
*/ | ||
export function Change(provider: OSFramework.Maps.Enum.ProviderType, version: string, forceRefresh = false): void { | ||
let versionChanged = false; | ||
switch (provider) { | ||
case OSFramework.Maps.Enum.ProviderType.Google: | ||
versionChanged = Provider.Maps.Google.Version.Change(version); | ||
break; | ||
case OSFramework.Maps.Enum.ProviderType.Leaflet: | ||
versionChanged = Provider.Maps.Leaflet.Version.Change(version); | ||
break; | ||
default: | ||
throw new Error(`There provider '${provider}' is not supported.`); | ||
} | ||
|
||
if (forceRefresh && versionChanged) { | ||
// Force refresh the library | ||
window.location.reload(); | ||
} | ||
} | ||
|
||
/** | ||
* Function that allows to get the version of a specific the provider | ||
* | ||
* @export | ||
* @param {OSFramework.Maps.Enum.ProviderType} provider | ||
* @return {*} {string} | ||
*/ | ||
export function Get(provider: OSFramework.Maps.Enum.ProviderType): string { | ||
let version = ''; | ||
switch (provider) { | ||
case OSFramework.Maps.Enum.ProviderType.Google: | ||
version = Provider.Maps.Google.Version.Get(); | ||
break; | ||
case OSFramework.Maps.Enum.ProviderType.Leaflet: | ||
version = Provider.Maps.Leaflet.Version.Get(); | ||
break; | ||
default: | ||
throw new Error(`There provider '${provider}' is not supported.`); | ||
} | ||
return version; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
namespace OutSystems.Maps.MapAPI.ProviderLibrary { | ||
/** | ||
* API that allows to get the version of the provider | ||
* | ||
* @export | ||
* @param {OSFramework.Maps.Enum.ProviderType} provider | ||
* @return {*} {string} | ||
*/ | ||
export function GetVersion(provider: OSFramework.Maps.Enum.ProviderType): string { | ||
return OSFramework.Maps.ProviderVersion.Get(provider); | ||
} | ||
|
||
/** | ||
* API that allows to set the version of the provider | ||
* | ||
* @export | ||
* @param {OSFramework.Maps.Enum.ProviderType} provider | ||
* @param {string} version | ||
* @param {boolean} [forceRefresh=false] | ||
*/ | ||
export function SetVersion( | ||
provider: OSFramework.Maps.Enum.ProviderType, | ||
version: string, | ||
forceRefresh = false | ||
): void { | ||
OSFramework.Maps.ProviderVersion.Change(provider, version, forceRefresh); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
namespace Provider.Maps.Google.Constants { | ||
// Name of the Google Maps Version in the LocalStorage | ||
export const googleMapsLocalStorageVersionKey = 'gmVersion'; | ||
|
||
// Default Failure auth code | ||
export const googleMapsAuthFailure = 'gm_authFailure'; | ||
|
||
// Tag used to find the google-maps-script | ||
export const googleMapsScript = 'google-maps-script'; | ||
|
||
/** Default gradient heatmap colors from google provider */ | ||
export const gradientHeatmapColors = [ | ||
'rgba(102, 255, 0, 0)', | ||
'rgba(102, 255, 0, 1)', | ||
'rgba(147, 255, 0, 1)', | ||
'rgba(193, 255, 0, 1)', | ||
'rgba(238, 255, 0, 1)', | ||
'rgba(244, 227, 0, 1)', | ||
'rgba(249, 198, 0, 1)', | ||
'rgba(255, 170, 0, 1)', | ||
'rgba(255, 113, 0, 1)', | ||
'rgba(255, 57, 0, 1)', | ||
'rgba(255, 0, 0, 1)', | ||
]; | ||
|
||
/************************** */ | ||
/** URL for GoogleMapsApis */ | ||
/************************** */ | ||
export const googleMapsApiURL = 'https://maps.googleapis.com/maps/api'; | ||
// URL for GoogleMaps API to make use of the Google Map | ||
export const googleMapsApiMap = `${googleMapsApiURL}/js`; | ||
// URL for GoogleMaps API to make use of the Google StaticMap | ||
export const googleMapsApiStaticMap = `${googleMapsApiURL}/staticmap`; | ||
// 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 GoogleMapsLibraries = 'drawing,visualization,places,marker'; | ||
// Version of the Google Maps to be loaded. | ||
export const googleMapsVersion = '3.58'; //Stable version Mid-November 2024. | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
namespace Provider.Maps.Google.Version { | ||
/** | ||
* Auxiliary function to get the current version of Google Maps loaded on the page. | ||
* | ||
* @return {*} {string} | ||
*/ | ||
function GetGoogleMapsVersion(): string { | ||
let version = undefined; | ||
if (window.google && window.google.maps && window.google.maps.version) { | ||
const gmVersion = window.google.maps.version; | ||
const indexMajorMinor = gmVersion.lastIndexOf('.'); | ||
version = gmVersion.substring(0, indexMajorMinor); | ||
} | ||
return version; | ||
} | ||
|
||
/** | ||
* Set the version of Google Maps to be used on the page. | ||
* | ||
* @export | ||
* @param {string} newVersion | ||
* @return {*} {boolean} | ||
*/ | ||
export function Change(newVersion: string): boolean { | ||
const currentVersion = | ||
OSFramework.Maps.Helper.LocalStorage.GetItem(Constants.googleMapsLocalStorageVersionKey) || | ||
Constants.googleMapsVersion; | ||
|
||
const googleVersion = GetGoogleMapsVersion(); | ||
|
||
// If the version that the developer set is different from the current version, and is different from the version loaded, set the return value to true. | ||
const versionChanged = currentVersion !== newVersion && newVersion !== googleVersion; | ||
|
||
OSFramework.Maps.Helper.LocalStorage.SetItem(Constants.googleMapsLocalStorageVersionKey, newVersion); | ||
|
||
return versionChanged; | ||
} | ||
|
||
/** | ||
* Get the current version of Google Maps loaded on the page. | ||
* | ||
* @export | ||
* @return {*} {string} | ||
*/ | ||
export function Get(): string { | ||
let currentVersion = | ||
OSFramework.Maps.Helper.LocalStorage.GetItem(Constants.googleMapsLocalStorageVersionKey) || | ||
Provider.Maps.Google.Constants.googleMapsVersion; | ||
const googleVersion = GetGoogleMapsVersion(); | ||
|
||
// If the version that the developer set is still not being used, log a warning message and return the current loaded version. | ||
if (googleVersion !== undefined && currentVersion !== googleVersion) { | ||
OSFramework.Maps.Helper.LogWarningMessage( | ||
`Current version of Google Maps loaded is '${googleVersion}', but on the next page refresh the version will tentatively be '${currentVersion}'.` | ||
); | ||
currentVersion = googleVersion; | ||
} | ||
|
||
return currentVersion; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace Provider.Maps.Leaflet.Constants { | ||
// Version of Leaflet | ||
export const leafletVersion = '1.0.2'; | ||
|
||
/* Default name for drawing completed event - Leaflet*/ | ||
export const drawingLeafletCompleted = 'draw:created'; | ||
|
||
/******************** */ | ||
/** URLs for Leaflet */ | ||
/******************** */ | ||
export const openStreetMapTileLayer = { | ||
url: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png', | ||
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors', | ||
}; | ||
} |
Oops, something went wrong.