Browse Source

Map widget: removed the built-in Google and HERE API keys and the Esri layers from the default map layers, added the Esri provider with an optional ArcGIS API key (#16832)

* UI: Map - load Esri reference layer styles from ArcGIS Online instead of bundling them

The styles are Esri content under the Esri Master License Agreement, which
prohibits redistributing or self-hosting it.

* UI: Map - retry a failed reference layer style load on the next map load and log the error

* UI: Map - remove Esri layers from the default map layers and the built-in Google and HERE API keys

* UI: Map - make the Google and HERE API keys optional with a warning, show the layers without a key without using ours

* UI: Map - add the Esri provider with an optional ArcGIS API key, use the key for the Esri reference layers and the ArcGIS vector basemap styles

* UI: Map - make the legacy Google and HERE API keys optional, show an accurate warning for a missing ArcGIS API key and add the Esri attribution to the raster Esri layers

* Update license headers of the modified map files

* UI: Map - drop the hidden reference layer API key, show the Esri attribution on the reference and legacy Esri layers and describe the missing API key warning to screen readers
pull/16847/head
Vladyslav Prykhodko 1 week ago
committed by GitHub
parent
commit
ce52cf5a34
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 33
      application/src/main/data/json/demo/dashboards/thermostats.json
  2. 44
      application/src/main/data/json/solutions/fleet_tracking/dashboards/mine_site_monitoring.json
  3. 2
      application/src/main/data/json/system/widget_types/google_map.json
  4. 2
      application/src/main/data/json/system/widget_types/here_map.json
  5. 2
      application/src/main/data/json/system/widget_types/markers_placement___google_maps.json
  6. 2
      application/src/main/data/json/system/widget_types/route_map.json
  7. 2
      application/src/main/data/json/system/widget_types/route_map___google.json
  8. 2
      application/src/main/data/json/system/widget_types/trip_map.json
  9. 7
      ui-ngx/src/app/modules/home/components/widget/lib/maps-legacy/map-models.ts
  10. 4
      ui-ngx/src/app/modules/home/components/widget/lib/maps-legacy/providers/google-map.ts
  11. 20
      ui-ngx/src/app/modules/home/components/widget/lib/maps-legacy/providers/here-map.ts
  12. 3
      ui-ngx/src/app/modules/home/components/widget/lib/maps-legacy/providers/openstreet-map.ts
  13. 2
      ui-ngx/src/app/modules/home/components/widget/lib/maps/leaflet/leaflet-tb.ts
  14. 164
      ui-ngx/src/app/modules/home/components/widget/lib/maps/map-layer.ts
  15. 15
      ui-ngx/src/app/modules/home/components/widget/lib/settings/common/map/map-layer-row.component.html
  16. 22
      ui-ngx/src/app/modules/home/components/widget/lib/settings/common/map/map-layer-row.component.ts
  17. 55
      ui-ngx/src/app/modules/home/components/widget/lib/settings/common/map/map-layer-settings-panel.component.html
  18. 41
      ui-ngx/src/app/modules/home/components/widget/lib/settings/common/map/map-layer-settings-panel.component.ts
  19. 20
      ui-ngx/src/app/modules/home/components/widget/lib/settings/map/legacy/google-map-provider-settings.component.html
  20. 5
      ui-ngx/src/app/modules/home/components/widget/lib/settings/map/legacy/google-map-provider-settings.component.ts
  21. 20
      ui-ngx/src/app/modules/home/components/widget/lib/settings/map/legacy/here-map-provider-settings.component.html
  22. 8
      ui-ngx/src/app/modules/home/components/widget/lib/settings/map/legacy/here-map-provider-settings.component.ts
  23. 96
      ui-ngx/src/app/shared/models/widget/maps/map.models.ts
  24. 8
      ui-ngx/src/assets/locale/locale.constant-en_US.json
  25. 7937
      ui-ngx/src/assets/map/enhanced_contrast_hybrid_reference_style.json
  26. 25803
      ui-ngx/src/assets/map/openstreetmap_hybrid_reference_style.json
  27. 57840
      ui-ngx/src/assets/map/world_edition_hybrid_reference_style.json

33
application/src/main/data/json/demo/dashboards/thermostats.json

@ -1303,17 +1303,6 @@
"label": "{i18n:widgets.maps.layer.roadmap}",
"provider": "openstreet",
"layerType": "OpenStreetMap.Mapnik"
},
{
"label": "{i18n:widgets.maps.layer.satellite}",
"provider": "openstreet",
"layerType": "Esri.WorldImagery"
},
{
"label": "{i18n:widgets.maps.layer.hybrid}",
"provider": "openstreet",
"layerType": "Esri.WorldImagery",
"referenceLayer": "openstreetmap_hybrid"
}
],
"imageSource": null,
@ -1561,17 +1550,6 @@
"label": "{i18n:widgets.maps.layer.roadmap}",
"provider": "openstreet",
"layerType": "OpenStreetMap.Mapnik"
},
{
"label": "{i18n:widgets.maps.layer.satellite}",
"provider": "openstreet",
"layerType": "Esri.WorldImagery"
},
{
"label": "{i18n:widgets.maps.layer.hybrid}",
"provider": "openstreet",
"layerType": "Esri.WorldImagery",
"referenceLayer": "openstreetmap_hybrid"
}
],
"imageSource": null,
@ -1820,17 +1798,6 @@
"label": "{i18n:widgets.maps.layer.roadmap}",
"provider": "openstreet",
"layerType": "OpenStreetMap.Mapnik"
},
{
"label": "{i18n:widgets.maps.layer.satellite}",
"provider": "openstreet",
"layerType": "Esri.WorldImagery"
},
{
"label": "{i18n:widgets.maps.layer.hybrid}",
"provider": "openstreet",
"layerType": "Esri.WorldImagery",
"referenceLayer": "openstreetmap_hybrid"
}
],
"imageSource": null,

44
application/src/main/data/json/solutions/fleet_tracking/dashboards/mine_site_monitoring.json

@ -20,21 +20,10 @@
"settings": {
"mapType": "geoMap",
"layers": [
{
"label": "{i18n:widgets.maps.layer.hybrid}",
"provider": "openstreet",
"layerType": "Esri.WorldImagery",
"referenceLayer": "openstreetmap_hybrid"
},
{
"label": "{i18n:widgets.maps.layer.roadmap}",
"provider": "openstreet",
"layerType": "OpenStreetMap.Mapnik"
},
{
"label": "{i18n:widgets.maps.layer.satellite}",
"provider": "openstreet",
"layerType": "Esri.WorldImagery"
}
],
"imageSource": null,
@ -1284,21 +1273,10 @@
"settings": {
"mapType": "geoMap",
"layers": [
{
"label": "{i18n:widgets.maps.layer.satellite}",
"provider": "openstreet",
"layerType": "Esri.WorldImagery"
},
{
"label": "{i18n:widgets.maps.layer.roadmap}",
"provider": "openstreet",
"layerType": "OpenStreetMap.Mapnik"
},
{
"label": "{i18n:widgets.maps.layer.hybrid}",
"provider": "openstreet",
"layerType": "Esri.WorldImagery",
"referenceLayer": "openstreetmap_hybrid"
}
],
"trips": [
@ -2764,21 +2742,10 @@
"settings": {
"mapType": "geoMap",
"layers": [
{
"label": "{i18n:widgets.maps.layer.satellite}",
"provider": "openstreet",
"layerType": "Esri.WorldImagery"
},
{
"label": "{i18n:widgets.maps.layer.roadmap}",
"provider": "openstreet",
"layerType": "OpenStreetMap.Mapnik"
},
{
"label": "{i18n:widgets.maps.layer.hybrid}",
"provider": "openstreet",
"layerType": "Esri.WorldImagery",
"referenceLayer": "openstreetmap_hybrid"
}
],
"trips": [
@ -4371,21 +4338,10 @@
"settings": {
"mapType": "geoMap",
"layers": [
{
"label": "{i18n:widgets.maps.layer.satellite}",
"provider": "openstreet",
"layerType": "Esri.WorldImagery"
},
{
"label": "{i18n:widgets.maps.layer.roadmap}",
"provider": "openstreet",
"layerType": "OpenStreetMap.Mapnik"
},
{
"label": "{i18n:widgets.maps.layer.hybrid}",
"provider": "openstreet",
"layerType": "Esri.WorldImagery",
"referenceLayer": "openstreetmap_hybrid"
}
],
"imageSource": null,

2
application/src/main/data/json/system/widget_types/google_map.json

File diff suppressed because one or more lines are too long

2
application/src/main/data/json/system/widget_types/here_map.json

File diff suppressed because one or more lines are too long

2
application/src/main/data/json/system/widget_types/markers_placement___google_maps.json

@ -13,7 +13,7 @@
"templateCss": ".error {\n color: red;\n}\n.tb-labels {\n color: #222;\n font: 12px/1.5 \"Helvetica Neue\", Arial, Helvetica, sans-serif;\n text-align: center;\n width: 200px;\n white-space: nowrap;\n}",
"controllerScript": "self.onInit = function() {\n self.ctx.map = new TbMapWidgetV2('google-map', false, self.ctx, null, true);\n}\n\nself.onDataUpdated = function() {\n self.ctx.map.update();\n}\n\nself.onResize = function() {\n self.ctx.map.resize();\n}\n\nself.actionSources = function() {\n return TbMapWidgetV2.actionSources();\n}\n\nself.onDestroy = function() {\n self.ctx.map.destroy();\n}\n\nself.typeParameters = function() {\n return {\n hasDataPageLink: true\n };\n}",
"settingsDirective": "tb-map-widget-settings-legacy",
"defaultConfig": "{\"datasources\":[{\"type\":\"function\",\"name\":\"First point\",\"dataKeys\":[{\"name\":\"f(x)\",\"type\":\"function\",\"label\":\"latitude\",\"color\":\"#2196f3\",\"settings\":{},\"_hash\":0.05427416942713381,\"funcBody\":\"var value = prevValue || 15.833293;\\nif (time % 5000 < 500) {\\n value += Math.random() * 0.05 - 0.025;\\n}\\nreturn value;\"},{\"name\":\"f(x)\",\"type\":\"function\",\"label\":\"longitude\",\"color\":\"#4caf50\",\"settings\":{},\"_hash\":0.680594833308841,\"funcBody\":\"var value = prevValue || -90.454350;\\nif (time % 5000 < 500) {\\n value += Math.random() * 0.05 - 0.025;\\n}\\nreturn value;\"}]},{\"type\":\"function\",\"name\":\"Second point\",\"dataKeys\":[{\"name\":\"f(x)\",\"type\":\"function\",\"label\":\"latitude\",\"color\":\"#f44336\",\"settings\":{},\"_hash\":0.05012157428742059,\"funcBody\":\"var value = prevValue || 14.450463;\\nif (time % 4000 < 500) {\\n value += Math.random() * 0.05 - 0.025;\\n}\\nreturn value;\"},{\"name\":\"f(x)\",\"type\":\"function\",\"label\":\"longitude\",\"color\":\"#ffc107\",\"settings\":{},\"_hash\":0.6742359401617628,\"funcBody\":\"var value = prevValue || -84.845334;\\nif (time % 4000 < 500) {\\n value += Math.random() * 0.05 - 0.025;\\n}\\nreturn value;\"}]}],\"showTitle\":true,\"backgroundColor\":\"#fff\",\"color\":\"rgba(0, 0, 0, 0.87)\",\"padding\":\"8px\",\"settings\":{\"fitMapBounds\":true,\"latKeyName\":\"latitude\",\"lngKeyName\":\"longitude\",\"showLabel\":true,\"label\":\"${entityName}\",\"tooltipPattern\":\"<b>${entityName}</b><br/><br/><b>Latitude:</b> ${latitude:7}<br/><b>Longitude:</b> ${longitude:7}<br/><br/><link-act name='delete'>Delete</link-act>\",\"markerImageSize\":34,\"gmDefaultMapType\":\"roadmap\",\"gmApiKey\":\"AIzaSyDoEx2kaGz3PxwbI9T7ccTSg5xjdw8Nw8Q\",\"useColorFunction\":false,\"markerImages\":[],\"useMarkerImageFunction\":false,\"colorFunction\":\"\\n\",\"color\":\"#fe7569\",\"showTooltip\":true,\"autocloseTooltip\":true,\"defaultCenterPosition\":\"0,0\",\"showTooltipAction\":\"click\",\"polygonKeyName\":\"coordinates\",\"polygonOpacity\":0.5,\"polygonStrokeOpacity\":1,\"polygonStrokeWeight\":1,\"zoomOnClick\":true,\"defaultZoomLevel\":5,\"provider\":\"google-map\",\"showCoverageOnHover\":true,\"animate\":true,\"maxClusterRadius\":80,\"removeOutsideVisibleBounds\":true,\"mapProvider\":\"HERE.normalDay\",\"draggableMarker\":true,\"editablePolygon\":true,\"mapPageSize\":16384,\"showPolygon\":false,\"polygonTooltipPattern\":\"<b>${entityName}</b><br/><br/><b>TimeStamp:</b> ${coordinates|ts:7}<br/><br/><link-act name='delete_polygon'>Delete</link-act>\",\"showPolygonTooltip\":false},\"title\":\"Markers Placement - Google Maps\",\"dropShadow\":true,\"enableFullscreen\":true,\"titleStyle\":{\"fontSize\":\"16px\",\"fontWeight\":400},\"showLegend\":false,\"widgetStyle\":{},\"actions\":{\"tooltipAction\":[{\"name\":\"delete\",\"icon\":\"more_horiz\",\"type\":\"custom\",\"customFunction\":\"var entityDatasource = widgetContext.map.map.datasources.filter(\\n function(entity) {\\n return entity.entityId === entityId.id;\\n });\\n\\nwidgetContext.map.setMarkerLocation(entityDatasource[0], null, null).subscribe(() => widgetContext.updateAliases());\",\"id\":\"8d3c0156-0a14-7a6f-0ddd-0ec16b9ffc91\"},{\"name\":\"delete_polygon\",\"icon\":\"more_horiz\",\"type\":\"custom\",\"customFunction\":\"var entityDatasource = widgetContext.map.map.datasources.filter(\\n function(entity) {\\n return entity.entityId === entityId.id\\n });\\n\\nwidgetContext.map.savePolygonLocation(entityDatasource[0], null).subscribe(() => widgetContext.updateAliases());\",\"id\":\"46bf69cd-8906-234c-a879-e2e4c92f5b67\"}]},\"showTitleIcon\":false,\"titleIcon\":\"more_horiz\",\"iconColor\":\"rgba(0, 0, 0, 0.87)\",\"iconSize\":\"24px\",\"titleTooltip\":\"\"}"
"defaultConfig": "{\"datasources\":[{\"type\":\"function\",\"name\":\"First point\",\"dataKeys\":[{\"name\":\"f(x)\",\"type\":\"function\",\"label\":\"latitude\",\"color\":\"#2196f3\",\"settings\":{},\"_hash\":0.05427416942713381,\"funcBody\":\"var value = prevValue || 15.833293;\\nif (time % 5000 < 500) {\\n value += Math.random() * 0.05 - 0.025;\\n}\\nreturn value;\"},{\"name\":\"f(x)\",\"type\":\"function\",\"label\":\"longitude\",\"color\":\"#4caf50\",\"settings\":{},\"_hash\":0.680594833308841,\"funcBody\":\"var value = prevValue || -90.454350;\\nif (time % 5000 < 500) {\\n value += Math.random() * 0.05 - 0.025;\\n}\\nreturn value;\"}]},{\"type\":\"function\",\"name\":\"Second point\",\"dataKeys\":[{\"name\":\"f(x)\",\"type\":\"function\",\"label\":\"latitude\",\"color\":\"#f44336\",\"settings\":{},\"_hash\":0.05012157428742059,\"funcBody\":\"var value = prevValue || 14.450463;\\nif (time % 4000 < 500) {\\n value += Math.random() * 0.05 - 0.025;\\n}\\nreturn value;\"},{\"name\":\"f(x)\",\"type\":\"function\",\"label\":\"longitude\",\"color\":\"#ffc107\",\"settings\":{},\"_hash\":0.6742359401617628,\"funcBody\":\"var value = prevValue || -84.845334;\\nif (time % 4000 < 500) {\\n value += Math.random() * 0.05 - 0.025;\\n}\\nreturn value;\"}]}],\"showTitle\":true,\"backgroundColor\":\"#fff\",\"color\":\"rgba(0, 0, 0, 0.87)\",\"padding\":\"8px\",\"settings\":{\"fitMapBounds\":true,\"latKeyName\":\"latitude\",\"lngKeyName\":\"longitude\",\"showLabel\":true,\"label\":\"${entityName}\",\"tooltipPattern\":\"<b>${entityName}</b><br/><br/><b>Latitude:</b> ${latitude:7}<br/><b>Longitude:</b> ${longitude:7}<br/><br/><link-act name='delete'>Delete</link-act>\",\"markerImageSize\":34,\"gmDefaultMapType\":\"roadmap\",\"gmApiKey\":null,\"useColorFunction\":false,\"markerImages\":[],\"useMarkerImageFunction\":false,\"colorFunction\":\"\\n\",\"color\":\"#fe7569\",\"showTooltip\":true,\"autocloseTooltip\":true,\"defaultCenterPosition\":\"0,0\",\"showTooltipAction\":\"click\",\"polygonKeyName\":\"coordinates\",\"polygonOpacity\":0.5,\"polygonStrokeOpacity\":1,\"polygonStrokeWeight\":1,\"zoomOnClick\":true,\"defaultZoomLevel\":5,\"provider\":\"google-map\",\"showCoverageOnHover\":true,\"animate\":true,\"maxClusterRadius\":80,\"removeOutsideVisibleBounds\":true,\"mapProvider\":\"HERE.normalDay\",\"draggableMarker\":true,\"editablePolygon\":true,\"mapPageSize\":16384,\"showPolygon\":false,\"polygonTooltipPattern\":\"<b>${entityName}</b><br/><br/><b>TimeStamp:</b> ${coordinates|ts:7}<br/><br/><link-act name='delete_polygon'>Delete</link-act>\",\"showPolygonTooltip\":false},\"title\":\"Markers Placement - Google Maps\",\"dropShadow\":true,\"enableFullscreen\":true,\"titleStyle\":{\"fontSize\":\"16px\",\"fontWeight\":400},\"showLegend\":false,\"widgetStyle\":{},\"actions\":{\"tooltipAction\":[{\"name\":\"delete\",\"icon\":\"more_horiz\",\"type\":\"custom\",\"customFunction\":\"var entityDatasource = widgetContext.map.map.datasources.filter(\\n function(entity) {\\n return entity.entityId === entityId.id;\\n });\\n\\nwidgetContext.map.setMarkerLocation(entityDatasource[0], null, null).subscribe(() => widgetContext.updateAliases());\",\"id\":\"8d3c0156-0a14-7a6f-0ddd-0ec16b9ffc91\"},{\"name\":\"delete_polygon\",\"icon\":\"more_horiz\",\"type\":\"custom\",\"customFunction\":\"var entityDatasource = widgetContext.map.map.datasources.filter(\\n function(entity) {\\n return entity.entityId === entityId.id\\n });\\n\\nwidgetContext.map.savePolygonLocation(entityDatasource[0], null).subscribe(() => widgetContext.updateAliases());\",\"id\":\"46bf69cd-8906-234c-a879-e2e4c92f5b67\"}]},\"showTitleIcon\":false,\"titleIcon\":\"more_horiz\",\"iconColor\":\"rgba(0, 0, 0, 0.87)\",\"iconSize\":\"24px\",\"titleTooltip\":\"\"}"
},
"tags": [
"mapping",

2
application/src/main/data/json/system/widget_types/route_map.json

File diff suppressed because one or more lines are too long

2
application/src/main/data/json/system/widget_types/route_map___google.json

File diff suppressed because one or more lines are too long

2
application/src/main/data/json/system/widget_types/trip_map.json

File diff suppressed because one or more lines are too long

7
ui-ngx/src/app/modules/home/components/widget/lib/maps-legacy/map-models.ts

@ -1,5 +1,6 @@
// SPDX-FileCopyrightText: Copyright The ThingsBoard Authors
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Modifications Copyright ThingsBoard, Inc.
// SPDX-License-Identifier: Apache-2.0 AND BUSL-1.1
import { Datasource, FormattedData } from '@app/shared/models/widget.models';
import tinycolor from 'tinycolor2';
import { BaseIconOptions, Icon } from 'leaflet';
@ -64,7 +65,7 @@ export interface GoogleMapProviderSettings {
}
export const defaultGoogleMapProviderSettings: GoogleMapProviderSettings = {
gmApiKey: 'AIzaSyDoEx2kaGz3PxwbI9T7ccTSg5xjdw8Nw8Q',
gmApiKey: null,
gmDefaultMapType: GoogleMapType.roadmap
};
@ -128,7 +129,7 @@ export interface HereMapProviderSettings {
export const defaultHereMapProviderSettings: HereMapProviderSettings = {
mapProviderHere: HereMapProvider.hereNormalDay,
credentials: {
apiKey: 'kVXykxAfZ6LS4EbCTO02soFVfjA7HoBzNVVH9u7nzoE'
apiKey: null
}
};

4
ui-ngx/src/app/modules/home/components/widget/lib/maps-legacy/providers/google-map.ts

@ -44,11 +44,11 @@ export class GoogleMap extends LeafletMap {
}, options.gmApiKey);
}
private loadGoogle(callback: () => void, apiKey = 'AIzaSyDoEx2kaGz3PxwbI9T7ccTSg5xjdw8Nw8Q') {
private loadGoogle(callback: () => void, apiKey: string) {
if (gmGlobals[apiKey]) {
callback();
} else {
this.resource.loadResource(`https://maps.googleapis.com/maps/api/js?key=${apiKey}`).subscribe({
this.resource.loadResource(`https://maps.googleapis.com/maps/api/js${apiKey ? `?key=${apiKey}` : ''}`).subscribe({
next: () => {
gmGlobals[apiKey] = true;
callback();

20
ui-ngx/src/app/modules/home/components/widget/lib/maps-legacy/providers/here-map.ts

@ -3,7 +3,7 @@
// SPDX-License-Identifier: Apache-2.0 AND BUSL-1.1
import L from 'leaflet';
import LeafletMap from '../leaflet-map';
import { DEFAULT_ZOOM_LEVEL, defaultHereMapProviderSettings, WidgetUnitedMapSettings } from '../map-models';
import { DEFAULT_ZOOM_LEVEL, WidgetUnitedMapSettings } from '../map-models';
import { WidgetContext } from '@home/models/widget-component.models';
import { hereV3Provider } from '@shared/models/widget/maps/map.models';
@ -19,13 +19,17 @@ export class HEREMap extends LeafletMap {
zoomControl: !this.options.disableZoomControl,
fadeAnimation: !ctx.reportService.reportView
}).setView(options?.parsedDefaultCenterPosition, options?.defaultZoomLevel || DEFAULT_ZOOM_LEVEL);
const apiKey = options.credentials?.apiKey || defaultHereMapProviderSettings.credentials.apiKey;
const tileLayer = L.tileLayer.provider(hereV3Provider(options.mapProviderHere), {apiKey});
tileLayer.addTo(map);
if (this.ctx.reportService.reportView) {
tileLayer.once('load', () => {
this.ctx.reportService.onMapLoaded(mapUuid);
});
const apiKey = options.credentials?.apiKey;
if (apiKey) {
const tileLayer = L.tileLayer.provider(hereV3Provider(options.mapProviderHere), {apiKey});
tileLayer.addTo(map);
if (this.ctx.reportService.reportView) {
tileLayer.once('load', () => {
this.ctx.reportService.onMapLoaded(mapUuid);
});
}
} else if (this.ctx.reportService.reportView) {
this.ctx.reportService.onMapLoaded(mapUuid);
}
super.setMap(map);
}

3
ui-ngx/src/app/modules/home/components/widget/lib/maps-legacy/providers/openstreet-map.ts

@ -23,6 +23,9 @@ export class OpenStreetMap extends LeafletMap {
tileLayer = L.tileLayer(options.customProviderTileUrl);
} else {
tileLayer = L.tileLayer.provider(options.mapProvider || 'OpenStreetMap.Mapnik');
if (tileLayer.options.attribution && options.mapProvider?.startsWith('Esri.')) {
L.Util.setOptions(tileLayer, {attribution: `Powered by Esri | ${tileLayer.options.attribution}`});
}
}
tileLayer.addTo(map);
if (this.ctx.reportService.reportView) {

2
ui-ngx/src/app/modules/home/components/widget/lib/maps/leaflet/leaflet-tb.ts

@ -1391,7 +1391,7 @@ class MapLibreGLLayer extends L.Layer implements TB.MapLibreGL.MapLibreGLLayer {
const style = options.style;
if (typeof style !== 'string' && style.glyphs) {
const glyphs = style.glyphs;
const glyphsRegexString = glyphs.replace(/\//g, '\\/').replace(/\./g, '\\.').replace('{fontstack}', '(.*)').replace('{range}', '(.*)');
const glyphsRegexString = glyphs.replace(/[.*+?^$()|[\]\\/]/g, '\\$&').replace('{fontstack}', '(.*)').replace('{range}', '(.*)');
const glyphsRegex = new RegExp(glyphsRegexString);
options.transformRequest = (url, resourceType) => {
if (resourceType === 'Glyphs' && glyphsRegex && glyphsRegex.test(url)) {

164
ui-ngx/src/app/modules/home/components/widget/lib/maps/map-layer.ts

@ -1,16 +1,20 @@
// SPDX-FileCopyrightText: Copyright The ThingsBoard Authors
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Modifications Copyright ThingsBoard, Inc.
// SPDX-License-Identifier: Apache-2.0 AND BUSL-1.1
import {
CartoMapLayerSettings,
CustomMapLayerSettings,
defaultCartoMapLayerSettings,
defaultCustomMapLayerSettings,
defaultEsriMapLayerSettings,
defaultGoogleMapLayerSettings,
defaultHereMapLayerSettings,
defaultLayerTitle,
defaultOpenFreeMapLayerSettings,
defaultOpenStreetMapLayerSettings,
defaultTencentMapLayerSettings,
EsriLayerType,
EsriMapLayerSettings,
GoogleMapLayerSettings,
HereMapLayerSettings,
hereV3Provider,
@ -31,23 +35,78 @@ import { CustomTranslatePipe } from '@shared/pipe/custom-translate.pipe';
import L, { LeafletEvent } from 'leaflet';
import { catchError, map } from 'rxjs/operators';
import { ResourcesService } from '@core/services/resources.service';
import { StyleSpecification } from '@maplibre/maplibre-gl-style-spec';
import { StyleSpecification, VectorSourceSpecification } from '@maplibre/maplibre-gl-style-spec';
const referenceLayerStyleUrlMap = new Map<ReferenceLayerType, string>(
const poweredByEsriAttribution = 'Powered by Esri';
const esriWorldBasemapAttribution =
'Sources: Esri, TomTom, Garmin, FAO, NOAA, USGS, © OpenStreetMap contributors, and the GIS User Community';
// Esri content (Esri Master License Agreement): must not be bundled or self-hosted, so it is loaded from ArcGIS Online,
// with the user's own ArcGIS API key when one is specified.
const referenceLayerStyleMap = new Map<ReferenceLayerType, { itemId: string; attribution: string }>(
[
[ReferenceLayerType.openstreetmap_hybrid, {
itemId: 'f240fe360b434afc87dd989bf0c0b825',
attribution: 'Map data (c) OpenStreetMap contributors, Microsoft, Facebook, Google, Esri Community Maps contributors, Map layer by Esri'
}],
[ReferenceLayerType.world_edition_hybrid, {itemId: '30d6b8271e1849cd9c3042060001f425', attribution: esriWorldBasemapAttribution}],
[ReferenceLayerType.enhanced_contrast_hybrid, {itemId: 'c8ec7c62427d484a81397aefb7e59c5f', attribution: esriWorldBasemapAttribution}]
]
);
// With an API key: the World Street Map and World Topo Map raster services are retired (mature support),
// ArcGIS replaces them with the ArcGIS Streets and ArcGIS Topographic vector basemap styles.
const esriWorldImageryTokenTilesUrl = 'https://ibasemaps-api.arcgis.com/arcgis/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}';
const esriBasemapStylesUrl = 'https://basemapstyles-api.arcgis.com/arcgis/rest/services/styles/v2/styles';
const esriLayerTokenStyles = new Map<EsriLayerType, string>(
[
[ReferenceLayerType.openstreetmap_hybrid, '/assets/map/openstreetmap_hybrid_reference_style.json'],
[ReferenceLayerType.world_edition_hybrid, '/assets/map/world_edition_hybrid_reference_style.json'],
[ReferenceLayerType.enhanced_contrast_hybrid, '/assets/map/enhanced_contrast_hybrid_reference_style.json']
[EsriLayerType.esriWorldStreetMap, `${esriBasemapStylesUrl}/arcgis/streets`],
[EsriLayerType.esriWorldTopoMap, `${esriBasemapStylesUrl}/arcgis/topographic`]
]
);
const referenceLayerCache = new Map<ReferenceLayerType, Observable<StyleSpecification>>();
const withArcGISToken = (url: string, token: string): string =>
token ? `${url}${url.includes('?') ? '&' : '?'}token=${encodeURIComponent(token)}` : url;
// ArcGIS VectorTileServer metadata is not TileJSON: relative tile URL, no attribution
const prepareReferenceLayerStyle = (spec: StyleSpecification, attribution: string, token: string): StyleSpecification => {
const source = spec.sources.esri as VectorSourceSpecification;
return {
...spec,
sprite: typeof spec.sprite === 'string' ? withArcGISToken(spec.sprite, token) : spec.sprite,
glyphs: spec.glyphs ? withArcGISToken(spec.glyphs, token) : spec.glyphs,
sources: {
esri: {
...source,
attribution,
url: withArcGISToken(source.url, token),
tiles: [withArcGISToken(`${source.url}/tile/{z}/{y}/{x}.pbf`, token)]
}
}
};
};
const referenceLayerCache = new Map<string, Observable<StyleSpecification>>();
interface TbMapLayerData {
layer: L.Layer;
attribution: boolean;
}
// Placeholder for a provider layer without the required API key
class TbEmptyMapLayer extends L.Layer {
onAdd(): this {
// The map waits for the 'load' event of its default layer, e.g. to generate a report
setTimeout(() => this.fire('load'));
return this;
}
onRemove(): this {
return this;
}
}
export abstract class TbMapLayer<S extends MapLayerSettings> {
static fromSettings(ctx: WidgetContext,
@ -61,6 +120,8 @@ export abstract class TbMapLayer<S extends MapLayerSettings> {
return new TbOpenStreetMapLayer(ctx, inputSettings);
case MapProvider.carto:
return new TbCartoMapLayer(ctx, inputSettings);
case MapProvider.esri:
return new TbEsriMapLayer(ctx, inputSettings);
case MapProvider.google:
return new TbGoogleMapLayer(ctx, inputSettings);
case MapProvider.tencent:
@ -110,7 +171,7 @@ export abstract class TbMapLayer<S extends MapLayerSettings> {
switchMap((baseLayer) => {
if (baseLayer) {
if (this.settings.referenceLayer) {
return this.loadReferenceLayer(this.settings.referenceLayer).pipe(
return this.loadReferenceLayer(this.settings.referenceLayer, this.referenceLayerApiKey()).pipe(
map((referenceLayer) => {
if (referenceLayer) {
const layer = L.featureGroup();
@ -161,22 +222,34 @@ export abstract class TbMapLayer<S extends MapLayerSettings> {
));
}
private loadReferenceLayer(referenceLayer: ReferenceLayerType): Observable<L.Layer> {
let spec$ = referenceLayerCache.get(referenceLayer);
private loadReferenceLayer(referenceLayer: ReferenceLayerType, token: string): Observable<L.Layer> {
const cacheKey = `${referenceLayer}:${token || ''}`;
let spec$ = referenceLayerCache.get(cacheKey);
if (!spec$) {
const styleUrl = referenceLayerStyleUrlMap.get(referenceLayer);
spec$ = this.ctx.http.get<StyleSpecification>(styleUrl).pipe(
const {itemId, attribution} = referenceLayerStyleMap.get(referenceLayer);
spec$ = this.ctx.http.get<StyleSpecification>(withArcGISToken(
`https://cdn.arcgis.com/sharing/rest/content/items/${itemId}/resources/styles/root.json`, token)
).pipe(
map(spec => prepareReferenceLayerStyle(spec, attribution, token)),
catchError((e) => {
console.error(`Map reference layer style load failed!`, e);
referenceLayerCache.delete(cacheKey);
return of(null);
}),
shareReplay({
bufferSize: 1,
refCount: true
})
);
referenceLayerCache.set(referenceLayer, spec$);
referenceLayerCache.set(cacheKey, spec$);
}
return spec$.pipe(
map(spec => {
if (!spec) {
return null;
}
return L.TB.MapLibreGL.mapLibreGLLayer({
style: spec,
style: this.referenceLayerStyle(spec),
// The reference layer is drawn over a raster base, so the base layer's zoom limit applies
maxZoom: undefined
});
@ -184,6 +257,18 @@ export abstract class TbMapLayer<S extends MapLayerSettings> {
);
}
protected referenceLayerApiKey(): string {
return this.settings.referenceLayerApiKey;
}
protected referenceLayerStyle(spec: StyleSpecification): StyleSpecification {
const source = spec.sources.esri as VectorSourceSpecification;
return {
...spec,
sources: {...spec.sources, esri: {...source, attribution: `${poweredByEsriAttribution} | ${source.attribution}`}}
};
}
private title(): string {
const customTranslate = this.ctx.$injector.get(CustomTranslatePipe);
if (this.settings.label) {
@ -270,6 +355,47 @@ class TbCartoMapLayer extends TbMapLayer<CartoMapLayerSettings> {
}
class TbEsriMapLayer extends TbMapLayer<EsriMapLayerSettings> {
constructor(protected ctx: WidgetContext,
protected inputSettings: DeepPartial<MapLayerSettings>) {
super(ctx, inputSettings);
}
protected defaultSettings(): EsriMapLayerSettings {
return defaultEsriMapLayerSettings;
}
protected referenceLayerApiKey(): string {
return this.settings.apiKey;
}
// The base Esri layer already shows 'Powered by Esri'
protected referenceLayerStyle(spec: StyleSpecification): StyleSpecification {
return spec;
}
protected createLayer(): Observable<L.Layer> {
const apiKey = this.settings.apiKey;
const tokenStyle = esriLayerTokenStyles.get(this.settings.layerType);
if (apiKey && tokenStyle) {
return of(L.TB.MapLibreGL.mapLibreGLLayer({
style: withArcGISToken(tokenStyle, apiKey),
attributionControl: {
customAttribution: `${poweredByEsriAttribution} | ${esriWorldBasemapAttribution}`
}
}));
}
const layer = L.tileLayer.provider(this.settings.layerType);
L.Util.setOptions(layer, {attribution: `${poweredByEsriAttribution} | ${layer.options.attribution}`});
if (apiKey && this.settings.layerType === EsriLayerType.esriWorldImagery) {
layer.setUrl(withArcGISToken(esriWorldImageryTokenTilesUrl, apiKey), true);
}
return of(layer);
}
}
class TbGoogleMapLayer extends TbMapLayer<GoogleMapLayerSettings> {
static loadedApiKeysGlobal: {[key: string]: boolean} = {};
@ -298,12 +424,12 @@ class TbGoogleMapLayer extends TbMapLayer<GoogleMapLayerSettings> {
}
private loadGoogle(): Observable<boolean> {
const apiKey = this.settings.apiKey || defaultGoogleMapLayerSettings.apiKey;
const apiKey = this.settings.apiKey || '';
if (TbGoogleMapLayer.loadedApiKeysGlobal[apiKey]) {
return of(true);
} else {
const resourceService = this.ctx.$injector.get(ResourcesService);
return resourceService.loadResource(`https://maps.googleapis.com/maps/api/js?key=${apiKey}&loading=async`).pipe(
return resourceService.loadResource(`https://maps.googleapis.com/maps/api/js?${apiKey ? `key=${apiKey}&` : ''}loading=async`).pipe(
map(() => {
TbGoogleMapLayer.loadedApiKeysGlobal[apiKey] = true;
return true;
@ -350,8 +476,10 @@ class TbHereMapLayer extends TbMapLayer<HereMapLayerSettings> {
}
protected createLayer(): Observable<L.Layer> {
const apiKey = this.settings.apiKey || defaultHereMapLayerSettings.apiKey;
const layer = L.tileLayer.provider(hereV3Provider(this.settings.layerType), {apiKey});
if (!this.settings.apiKey) {
return of(new TbEmptyMapLayer());
}
const layer = L.tileLayer.provider(hereV3Provider(this.settings.layerType), {apiKey: this.settings.apiKey});
return of(layer);
}

15
ui-ngx/src/app/modules/home/components/widget/lib/settings/common/map/map-layer-row.component.html

@ -1,7 +1,8 @@
<!--
SPDX-FileCopyrightText: Copyright The ThingsBoard Authors
SPDX-License-Identifier: Apache-2.0
SPDX-FileCopyrightText: Modifications Copyright ThingsBoard, Inc.
SPDX-License-Identifier: Apache-2.0 AND BUSL-1.1
-->
<div [formGroup]="layerFormGroup" class="tb-form-table-row tb-map-layer-row">
@ -53,6 +54,18 @@
</mat-select>
</mat-form-field>
}
@if (MapProvider.esri === layerFormGroup.get('provider').value) {
<mat-form-field
class="tb-inline-field tb-layer-field" appearance="outline" subscriptSizing="dynamic">
<mat-select formControlName="layerType" required>
@for (layerType of esriLayerTypes; track layerType) {
<mat-option [value]="layerType">
{{ esriLayerTranslationMap.get(layerType) | translate }}
</mat-option>
}
</mat-select>
</mat-form-field>
}
@if (MapProvider.google === layerFormGroup.get('provider').value) {
<mat-form-field
class="tb-inline-field tb-layer-field" appearance="outline" subscriptSizing="dynamic">

22
ui-ngx/src/app/modules/home/components/widget/lib/settings/common/map/map-layer-row.component.ts

@ -1,5 +1,6 @@
// SPDX-FileCopyrightText: Copyright The ThingsBoard Authors
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Modifications Copyright ThingsBoard, Inc.
// SPDX-License-Identifier: Apache-2.0 AND BUSL-1.1
import {
ChangeDetectorRef,
Component,
@ -29,6 +30,8 @@ import {
cartoLayerTypes,
defaultLayerTitle,
defaultMapLayerSettings,
esriLayerTranslationMap,
esriLayerTypes,
googleMapLayerTranslationMap,
googleMapLayerTypes,
hereLayerTranslationMap,
@ -39,8 +42,8 @@ import {
mapProviderTranslationMap,
openFreeMapStyleTranslationMap,
openFreeMapStyleTypes,
mapLayerHasReferenceLayerApiKey,
mapProviderHasApiKey,
mapProviderRequiresApiKey,
openStreetLayerTypes,
openStreetMapLayerTranslationMap,
tencentLayerTranslationMap,
@ -85,6 +88,10 @@ export class MapLayerRowComponent implements ControlValueAccessor, OnInit {
cartoLayerTranslationMap = cartoLayerTranslationMap;
esriLayerTypes = esriLayerTypes;
esriLayerTranslationMap = esriLayerTranslationMap;
googleMapLayerTypes = googleMapLayerTypes;
googleMapLayerTranslationMap = googleMapLayerTranslationMap;
@ -126,8 +133,9 @@ export class MapLayerRowComponent implements ControlValueAccessor, OnInit {
tileUrl: [null, [Validators.required]],
vectorTiles: [false, []],
customAttribution: [null, []],
apiKey: [null, [Validators.required]],
referenceLayer: [null, []]
apiKey: [null, []],
referenceLayer: [null, []],
referenceLayerApiKey: [null, []]
});
this.layerFormGroup.valueChanges.pipe(
takeUntilDestroyed(this.destroyRef)
@ -228,11 +236,15 @@ export class MapLayerRowComponent implements ControlValueAccessor, OnInit {
this.layerFormGroup.get('layerType').enable({emitEvent: false});
}
if (mapProviderHasApiKey(provider)) {
this.layerFormGroup.get('apiKey').setValidators(mapProviderRequiresApiKey(provider) ? [Validators.required] : []);
this.layerFormGroup.get('apiKey').enable({emitEvent: false});
} else {
this.layerFormGroup.get('apiKey').disable({emitEvent: false});
}
if (mapLayerHasReferenceLayerApiKey(provider, this.layerFormGroup.get('referenceLayer').value)) {
this.layerFormGroup.get('referenceLayerApiKey').enable({emitEvent: false});
} else {
this.layerFormGroup.get('referenceLayerApiKey').disable({emitEvent: false});
}
}
private updateModel() {

55
ui-ngx/src/app/modules/home/components/widget/lib/settings/common/map/map-layer-settings-panel.component.html

@ -1,7 +1,8 @@
<!--
SPDX-FileCopyrightText: Copyright The ThingsBoard Authors
SPDX-License-Identifier: Apache-2.0
SPDX-FileCopyrightText: Modifications Copyright ThingsBoard, Inc.
SPDX-License-Identifier: Apache-2.0 AND BUSL-1.1
-->
<div class="tb-map-layer-settings-panel" [formGroup]="layerFormGroup">
@ -72,6 +73,18 @@
</mat-select>
</mat-form-field>
}
@if (MapProvider.esri === layerFormGroup.get('provider').value) {
<mat-form-field
class="flex" appearance="outline" subscriptSizing="dynamic">
<mat-select formControlName="layerType" required>
@for (layerType of esriLayerTypes; track layerType) {
<mat-option [value]="layerType">
{{ esriLayerTranslationMap.get(layerType) | translate }}
</mat-option>
}
</mat-select>
</mat-form-field>
}
@if (MapProvider.google === layerFormGroup.get('provider').value) {
<mat-form-field
class="flex" appearance="outline" subscriptSizing="dynamic">
@ -121,7 +134,22 @@
<div class="tb-form-row space-between column-xs">
<div class="fixed-title-width" translate>widgets.maps.layer.credentials.api-key</div>
<mat-form-field class="flex" appearance="outline" subscriptSizing="dynamic">
<input matInput formControlName="apiKey" placeholder="{{ 'widget-config.set' | translate }}">
<input matInput formControlName="apiKey" placeholder="{{ 'widget-config.set' | translate }}"
[aria-describedby]="apiKeyMissingWarning() ? 'tb-map-layer-api-key-warning' : null">
@if (apiKeyMissingWarning(); as warning) {
<mat-icon matSuffix
id="tb-map-layer-api-key-warning"
class="tb-warning"
tabindex="0"
role="img"
aria-hidden="false"
[attr.aria-label]="warning | translate"
matTooltipPosition="above"
matTooltipClass="tb-warning-tooltip"
[matTooltip]="warning | translate">
warning
</mat-icon>
}
</mat-form-field>
</div>
</div>
@ -139,6 +167,29 @@
</mat-select>
</mat-form-field>
</div>
@if (referenceLayerHasOwnApiKey()) {
<div class="tb-form-row space-between column-xs">
<div class="fixed-title-width" translate>widgets.maps.layer.reference.api-key</div>
<mat-form-field class="flex" appearance="outline" subscriptSizing="dynamic">
<input matInput formControlName="referenceLayerApiKey" placeholder="{{ 'widget-config.set' | translate }}"
[aria-describedby]="referenceLayerApiKeyMissing() ? 'tb-map-layer-reference-api-key-warning' : null">
@if (referenceLayerApiKeyMissing()) {
<mat-icon matSuffix
id="tb-map-layer-reference-api-key-warning"
class="tb-warning"
tabindex="0"
role="img"
aria-hidden="false"
[attr.aria-label]="'widgets.maps.layer.credentials.arcgis-api-key-missing' | translate"
matTooltipPosition="above"
matTooltipClass="tb-warning-tooltip"
matTooltip="{{ 'widgets.maps.layer.credentials.arcgis-api-key-missing' | translate }}">
warning
</mat-icon>
}
</mat-form-field>
</div>
}
@if (MapProvider.custom === layerFormGroup.get('provider').value) {
<div class="tb-form-row space-between column-xs">
<div class="fixed-title-width" tb-hint-tooltip-icon="{{ 'widgets.maps.layer.provider.custom.attribution-hint' | translate }}" translate>widgets.maps.layer.provider.custom.attribution</div>

41
ui-ngx/src/app/modules/home/components/widget/lib/settings/common/map/map-layer-settings-panel.component.ts

@ -1,5 +1,6 @@
// SPDX-FileCopyrightText: Copyright The ThingsBoard Authors
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Modifications Copyright ThingsBoard, Inc.
// SPDX-License-Identifier: Apache-2.0 AND BUSL-1.1
import { Component, DestroyRef, EventEmitter, Input, OnInit, Output, ViewEncapsulation } from '@angular/core';
import { TbPopoverComponent } from '@shared/components/popover.component';
import { UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms';
@ -9,6 +10,8 @@ import {
cartoLayerTypes,
defaultLayerTitle,
defaultMapLayerSettings,
esriLayerTranslationMap,
esriLayerTypes,
googleMapLayerTranslationMap,
googleMapLayerTypes,
hereLayerTranslationMap,
@ -19,8 +22,9 @@ import {
mapProviderTranslationMap,
openFreeMapStyleTranslationMap,
openFreeMapStyleTypes,
mapLayerHasReferenceLayerApiKey,
mapProviderHasApiKey,
mapProviderRequiresApiKey,
mapProviderApiKeyMissingWarningMap,
openStreetLayerTypes,
openStreetMapLayerTranslationMap, referenceLayerTypes, referenceLayerTypeTranslationMap,
tencentLayerTranslationMap,
@ -56,6 +60,10 @@ export class MapLayerSettingsPanelComponent implements OnInit {
cartoLayerTranslationMap = cartoLayerTranslationMap;
esriLayerTypes = esriLayerTypes;
esriLayerTranslationMap = esriLayerTranslationMap;
googleMapLayerTypes = googleMapLayerTypes;
googleMapLayerTranslationMap = googleMapLayerTranslationMap;
@ -97,8 +105,9 @@ export class MapLayerSettingsPanelComponent implements OnInit {
tileUrl: [null, [Validators.required]],
vectorTiles: [false, []],
customAttribution: [null, []],
apiKey: [null, [Validators.required]],
referenceLayer: [null, []]
apiKey: [null, []],
referenceLayer: [null, []],
referenceLayerApiKey: [null, []]
}
);
this.layerFormGroup.patchValue(
@ -109,6 +118,11 @@ export class MapLayerSettingsPanelComponent implements OnInit {
).subscribe((newProvider: MapProvider) => {
this.onProviderChanged(newProvider);
});
this.layerFormGroup.get('referenceLayer').valueChanges.pipe(
takeUntilDestroyed(this.destroyRef)
).subscribe(() => {
this.updateValidators();
});
this.layerFormGroup.get('vectorTiles').valueChanges.pipe(
takeUntilDestroyed(this.destroyRef)
).subscribe(() => {
@ -133,6 +147,19 @@ export class MapLayerSettingsPanelComponent implements OnInit {
return mapProviderHasApiKey(this.layerFormGroup.get('provider').value);
}
referenceLayerHasOwnApiKey(): boolean {
return mapLayerHasReferenceLayerApiKey(this.layerFormGroup.get('provider').value, this.layerFormGroup.get('referenceLayer').value);
}
apiKeyMissingWarning(): string {
return this.layerFormGroup.get('apiKey').value ? null :
mapProviderApiKeyMissingWarningMap.get(this.layerFormGroup.get('provider').value);
}
referenceLayerApiKeyMissing(): boolean {
return !this.layerFormGroup.get('referenceLayerApiKey').value;
}
applyLayerSettings() {
const layerSettings: MapLayerSettings = this.layerFormGroup.value;
this.mapLayerSettingsApplied.emit(layerSettings);
@ -161,10 +188,14 @@ export class MapLayerSettingsPanelComponent implements OnInit {
this.layerFormGroup.get('layerType').enable({emitEvent: false});
}
if (mapProviderHasApiKey(provider)) {
this.layerFormGroup.get('apiKey').setValidators(mapProviderRequiresApiKey(provider) ? [Validators.required] : []);
this.layerFormGroup.get('apiKey').enable({emitEvent: false});
} else {
this.layerFormGroup.get('apiKey').disable({emitEvent: false});
}
if (mapLayerHasReferenceLayerApiKey(provider, this.layerFormGroup.get('referenceLayer').value)) {
this.layerFormGroup.get('referenceLayerApiKey').enable({emitEvent: false});
} else {
this.layerFormGroup.get('referenceLayerApiKey').disable({emitEvent: false});
}
}
}

20
ui-ngx/src/app/modules/home/components/widget/lib/settings/map/legacy/google-map-provider-settings.component.html

@ -1,13 +1,29 @@
<!--
SPDX-FileCopyrightText: Copyright The ThingsBoard Authors
SPDX-License-Identifier: Apache-2.0
SPDX-FileCopyrightText: Modifications Copyright ThingsBoard, Inc.
SPDX-License-Identifier: Apache-2.0 AND BUSL-1.1
-->
<section class="tb-widget-settings" [formGroup]="providerSettingsFormGroup">
<mat-form-field class="mat-block">
<mat-label translate>widgets.maps.google-maps-api-key</mat-label>
<input required matInput formControlName="gmApiKey">
<input matInput formControlName="gmApiKey"
[aria-describedby]="providerSettingsFormGroup.get('gmApiKey').value ? null : 'tb-google-maps-api-key-warning'">
@if (!providerSettingsFormGroup.get('gmApiKey').value) {
<mat-icon matSuffix
id="tb-google-maps-api-key-warning"
class="tb-warning"
tabindex="0"
role="img"
aria-hidden="false"
[attr.aria-label]="'widgets.maps.layer.credentials.api-key-missing' | translate"
matTooltipPosition="above"
matTooltipClass="tb-warning-tooltip"
matTooltip="{{ 'widgets.maps.layer.credentials.api-key-missing' | translate }}">
warning
</mat-icon>
}
</mat-form-field>
<mat-form-field class="mat-block">
<mat-label translate>widgets.maps.default-map-type</mat-label>

5
ui-ngx/src/app/modules/home/components/widget/lib/settings/map/legacy/google-map-provider-settings.component.ts

@ -1,5 +1,6 @@
// SPDX-FileCopyrightText: Copyright The ThingsBoard Authors
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Modifications Copyright ThingsBoard, Inc.
// SPDX-License-Identifier: Apache-2.0 AND BUSL-1.1
import { Component, DestroyRef, forwardRef, Input, OnInit } from '@angular/core';
import {
ControlValueAccessor,
@ -64,7 +65,7 @@ export class GoogleMapProviderSettingsComponent extends PageComponent implements
ngOnInit(): void {
this.providerSettingsFormGroup = this.fb.group({
gmApiKey: [null, [Validators.required]],
gmApiKey: [null, []],
gmDefaultMapType: [null, [Validators.required]]
});
this.providerSettingsFormGroup.valueChanges.pipe(

20
ui-ngx/src/app/modules/home/components/widget/lib/settings/map/legacy/here-map-provider-settings.component.html

@ -1,7 +1,8 @@
<!--
SPDX-FileCopyrightText: Copyright The ThingsBoard Authors
SPDX-License-Identifier: Apache-2.0
SPDX-FileCopyrightText: Modifications Copyright ThingsBoard, Inc.
SPDX-License-Identifier: Apache-2.0 AND BUSL-1.1
-->
<section class="tb-widget-settings" [formGroup]="providerSettingsFormGroup">
@ -20,7 +21,22 @@
<legend class="group-title" translate>widgets.maps.credentials</legend>
<mat-form-field>
<mat-label translate>widgets.maps.here-api-key</mat-label>
<input required matInput formControlName="apiKey">
<input matInput formControlName="apiKey"
[aria-describedby]="providerSettingsFormGroup.get('credentials.apiKey').value ? null : 'tb-here-maps-api-key-warning'">
@if (!providerSettingsFormGroup.get('credentials.apiKey').value) {
<mat-icon matSuffix
id="tb-here-maps-api-key-warning"
class="tb-warning"
tabindex="0"
role="img"
aria-hidden="false"
[attr.aria-label]="'widgets.maps.layer.credentials.api-key-missing' | translate"
matTooltipPosition="above"
matTooltipClass="tb-warning-tooltip"
matTooltip="{{ 'widgets.maps.layer.credentials.api-key-missing' | translate }}">
warning
</mat-icon>
}
</mat-form-field>
</fieldset>
</section>

8
ui-ngx/src/app/modules/home/components/widget/lib/settings/map/legacy/here-map-provider-settings.component.ts

@ -1,5 +1,6 @@
// SPDX-FileCopyrightText: Copyright The ThingsBoard Authors
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Modifications Copyright ThingsBoard, Inc.
// SPDX-License-Identifier: Apache-2.0 AND BUSL-1.1
import { Component, DestroyRef, forwardRef, Input, OnInit } from '@angular/core';
import {
ControlValueAccessor,
@ -16,7 +17,6 @@ import { Store } from '@ngrx/store';
import { AppState } from '@core/core.state';
import { TranslateService } from '@ngx-translate/core';
import {
defaultHereMapProviderSettings,
HereMapProvider,
HereMapProviderSettings,
hereMapProviderTranslationMap
@ -67,7 +67,7 @@ export class HereMapProviderSettingsComponent extends PageComponent implements O
this.providerSettingsFormGroup = this.fb.group({
mapProviderHere: [null, [Validators.required]],
credentials: this.fb.group({
apiKey: [null, [Validators.required]]
apiKey: [null, []]
})
});
this.providerSettingsFormGroup.valueChanges.pipe(
@ -98,7 +98,7 @@ export class HereMapProviderSettingsComponent extends PageComponent implements O
this.providerSettingsFormGroup.patchValue({
mapProviderHere: value?.mapProviderHere,
credentials: {
apiKey: value?.credentials?.apiKey || defaultHereMapProviderSettings.credentials.apiKey
apiKey: value?.credentials?.apiKey
}
}, {emitEvent: false});
}

96
ui-ngx/src/app/shared/models/widget/maps/map.models.ts

@ -929,6 +929,7 @@ export enum MapProvider {
openfreemap = 'openfreemap',
openstreet = 'openstreet',
carto = 'carto',
esri = 'esri',
google = 'google',
here = 'here',
tencent = 'tencent',
@ -942,6 +943,7 @@ export const mapProviderTranslationMap = new Map<MapProvider, string>(
[MapProvider.openfreemap, 'widgets.maps.layer.provider.openfreemap.title'],
[MapProvider.openstreet, 'widgets.maps.layer.provider.openstreet.title'],
[MapProvider.carto, 'widgets.maps.layer.provider.carto.title'],
[MapProvider.esri, 'widgets.maps.layer.provider.esri.title'],
[MapProvider.google, 'widgets.maps.layer.provider.google.title'],
[MapProvider.here, 'widgets.maps.layer.provider.here.title'],
[MapProvider.tencent, 'widgets.maps.layer.provider.tencent.title'],
@ -969,6 +971,7 @@ export interface MapLayerSettings {
label?: string;
provider: MapProvider;
referenceLayer?: ReferenceLayerType;
referenceLayerApiKey?: string;
}
export const mapLayerValid = (layer: MapLayerSettings): boolean => {
@ -985,6 +988,9 @@ export const mapLayerValid = (layer: MapLayerSettings): boolean => {
case MapProvider.carto:
const cartoLayer = layer as CartoMapLayerSettings;
return !!cartoLayer.layerType;
case MapProvider.esri:
const esriLayer = layer as EsriMapLayerSettings;
return !!esriLayer.layerType;
case MapProvider.google:
const googleLayer = layer as GoogleMapLayerSettings;
return !!googleLayer.layerType;
@ -1024,6 +1030,9 @@ export const defaultLayerTitle = (layer: MapLayerSettings): string => {
case MapProvider.carto:
const cartoLayer = layer as CartoMapLayerSettings;
return cartoLayerTranslationMap.get(cartoLayer.layerType);
case MapProvider.esri:
const esriLayer = layer as EsriMapLayerSettings;
return esriLayerTranslationMap.get(esriLayer.layerType);
case MapProvider.google:
const googleLayer = layer as GoogleMapLayerSettings;
return googleMapLayerTranslationMap.get(googleLayer.layerType);
@ -1040,10 +1049,7 @@ export const defaultLayerTitle = (layer: MapLayerSettings): string => {
export enum OpenStreetLayerType {
openStreetMapnik = 'OpenStreetMap.Mapnik',
openStreetHot = 'OpenStreetMap.HOT',
esriWorldStreetMap = 'Esri.WorldStreetMap',
esriWorldTopoMap = 'Esri.WorldTopoMap',
esriWorldImagery = 'Esri.WorldImagery'
openStreetHot = 'OpenStreetMap.HOT'
}
export const openStreetLayerTypes = Object.values(OpenStreetLayerType) as OpenStreetLayerType[];
@ -1051,10 +1057,7 @@ export const openStreetLayerTypes = Object.values(OpenStreetLayerType) as OpenSt
export const openStreetMapLayerTranslationMap = new Map<OpenStreetLayerType, string>(
[
[OpenStreetLayerType.openStreetMapnik, 'widgets.maps.layer.provider.openstreet.mapnik'],
[OpenStreetLayerType.openStreetHot, 'widgets.maps.layer.provider.openstreet.hot'],
[OpenStreetLayerType.esriWorldStreetMap, 'widgets.maps.layer.provider.openstreet.esri-street'],
[OpenStreetLayerType.esriWorldTopoMap, 'widgets.maps.layer.provider.openstreet.esri-topo'],
[OpenStreetLayerType.esriWorldImagery, 'widgets.maps.layer.provider.openstreet.esri-imagery']
[OpenStreetLayerType.openStreetHot, 'widgets.maps.layer.provider.openstreet.hot']
]
);
@ -1120,6 +1123,34 @@ export const defaultCartoMapLayerSettings: CartoMapLayerSettings = {
apiKey: null
}
export enum EsriLayerType {
esriWorldImagery = 'Esri.WorldImagery',
esriWorldStreetMap = 'Esri.WorldStreetMap',
esriWorldTopoMap = 'Esri.WorldTopoMap'
}
export const esriLayerTypes = Object.values(EsriLayerType) as EsriLayerType[];
export const esriLayerTranslationMap = new Map<EsriLayerType, string>(
[
[EsriLayerType.esriWorldImagery, 'widgets.maps.layer.provider.openstreet.esri-imagery'],
[EsriLayerType.esriWorldStreetMap, 'widgets.maps.layer.provider.openstreet.esri-street'],
[EsriLayerType.esriWorldTopoMap, 'widgets.maps.layer.provider.openstreet.esri-topo']
]
);
export interface EsriMapLayerSettings extends MapLayerSettings {
provider: MapProvider.esri;
layerType: EsriLayerType;
apiKey?: string;
}
export const defaultEsriMapLayerSettings: EsriMapLayerSettings = {
provider: MapProvider.esri,
layerType: EsriLayerType.esriWorldImagery,
apiKey: null
};
export enum GoogleLayerType {
roadmap = 'roadmap',
satellite = 'satellite',
@ -1147,7 +1178,7 @@ export interface GoogleMapLayerSettings extends MapLayerSettings {
export const defaultGoogleMapLayerSettings: GoogleMapLayerSettings = {
provider: MapProvider.google,
layerType: GoogleLayerType.roadmap,
apiKey: 'AIzaSyDoEx2kaGz3PxwbI9T7ccTSg5xjdw8Nw8Q'
apiKey: null
};
export enum HereLayerType {
@ -1177,7 +1208,7 @@ export interface HereMapLayerSettings extends MapLayerSettings {
export const defaultHereMapLayerSettings: HereMapLayerSettings = {
provider: MapProvider.here,
layerType: HereLayerType.hereNormalDay,
apiKey: 'kVXykxAfZ6LS4EbCTO02soFVfjA7HoBzNVVH9u7nzoE'
apiKey: null
}
const hereV3Variants: {[v2Variant: string]: string} = {
@ -1229,18 +1260,34 @@ export const defaultCustomMapLayerSettings: CustomMapLayerSettings = {
}
export const mapProviderHasApiKey = (provider: MapProvider): boolean =>
[MapProvider.carto, MapProvider.google, MapProvider.here].includes(provider);
[MapProvider.carto, MapProvider.esri, MapProvider.google, MapProvider.here].includes(provider);
// An Esri layer uses its own ArcGIS API key for the reference layer too
export const mapLayerHasReferenceLayerApiKey = (provider: MapProvider, referenceLayer: ReferenceLayerType): boolean =>
!!referenceLayer && provider !== MapProvider.esri;
export const mapProviderRequiresApiKey = (provider: MapProvider): boolean =>
[MapProvider.google, MapProvider.here].includes(provider);
// The API key is optional; without it these providers may limit the layer or its use
export const mapProviderApiKeyMissingWarningMap = new Map<MapProvider, string>(
[
[MapProvider.esri, 'widgets.maps.layer.credentials.arcgis-api-key-missing'],
[MapProvider.google, 'widgets.maps.layer.credentials.api-key-missing'],
[MapProvider.here, 'widgets.maps.layer.credentials.api-key-missing']
]
);
const legacyOpenStreetCartoLayerTypes = new Set<string>(cartoLayerTypes);
const legacyOpenStreetEsriLayerTypes = new Set<string>(esriLayerTypes);
// CARTO layers used to be stored under the OpenStreetMap provider, keep reading them as CARTO layers
// CARTO and Esri layers used to be stored under the OpenStreetMap provider, keep reading them as CARTO and Esri layers
export const normalizeMapLayerSettings = (layer: MapLayerSettings): MapLayerSettings => {
if (layer?.provider === MapProvider.openstreet &&
legacyOpenStreetCartoLayerTypes.has((layer as OpenStreetMapLayerSettings).layerType)) {
return {...layer, provider: MapProvider.carto};
if (layer?.provider === MapProvider.openstreet) {
const layerType = (layer as OpenStreetMapLayerSettings).layerType;
if (legacyOpenStreetCartoLayerTypes.has(layerType)) {
return {...layer, provider: MapProvider.carto};
}
if (legacyOpenStreetEsriLayerTypes.has(layerType)) {
return {...layer, provider: MapProvider.esri};
}
}
return layer;
};
@ -1253,6 +1300,8 @@ export const defaultMapLayerSettings = (provider: MapProvider): MapLayerSettings
return defaultOpenStreetMapLayerSettings;
case MapProvider.carto:
return defaultCartoMapLayerSettings;
case MapProvider.esri:
return defaultEsriMapLayerSettings;
case MapProvider.google:
return defaultGoogleMapLayerSettings;
case MapProvider.here:
@ -1269,18 +1318,7 @@ export const defaultMapLayers: MapLayerSettings[] = [
label: '{i18n:widgets.maps.layer.roadmap}',
provider: MapProvider.openfreemap,
layerType: OpenFreeMapStyleType.bright,
} as OpenFreeMapLayerSettings,
{
label: '{i18n:widgets.maps.layer.satellite}',
provider: MapProvider.openstreet,
layerType: OpenStreetLayerType.esriWorldImagery,
} as OpenStreetMapLayerSettings,
{
label: '{i18n:widgets.maps.layer.hybrid}',
provider: MapProvider.openstreet,
layerType: OpenStreetLayerType.esriWorldImagery,
referenceLayer: ReferenceLayerType.openstreetmap_hybrid
} as OpenStreetMapLayerSettings
} as OpenFreeMapLayerSettings
];
export interface GeoMapSettings extends BaseMapSettings {

8
ui-ngx/src/assets/locale/locale.constant-en_US.json

@ -12745,6 +12745,7 @@
"webgl-not-available": "The selected map layer requires graphics acceleration to display. Please enable 'Hardware acceleration' in your browser settings, or switch to a different layer.",
"reference": {
"reference-layer": "Reference layer",
"api-key": "ArcGIS API Key",
"no-layer": "No layer",
"openstreetmap-hybrid": "OpenStreetMap Hybrid",
"world-edition-hybrid": "World Edition Hybrid",
@ -12765,6 +12766,9 @@
"positron": "Positron",
"dark-matter": "DarkMatter"
},
"esri": {
"title": "Esri"
},
"google": {
"title": "Google",
"roadmap": "Roadmap",
@ -12803,7 +12807,9 @@
},
"credentials": {
"credentials": "Credentials",
"api-key": "API Key"
"api-key": "API Key",
"api-key-missing": "Without an API key, the provider may not show this layer or may show it with a watermark. Specify your API key.",
"arcgis-api-key-missing": "Without an ArcGIS API key, the layer is loaded from the public ArcGIS Online services. The Esri terms of use may require an ArcGIS account for your use of this content. Specify your ArcGIS API key."
}
},
"overlays": {

7937
ui-ngx/src/assets/map/enhanced_contrast_hybrid_reference_style.json

File diff suppressed because it is too large

25803
ui-ngx/src/assets/map/openstreetmap_hybrid_reference_style.json

File diff suppressed because it is too large

57840
ui-ngx/src/assets/map/world_edition_hybrid_reference_style.json

File diff suppressed because it is too large
Loading…
Cancel
Save