From 03ad72b29ccac3984df6c3bd9ded666e62b7216f Mon Sep 17 00:00:00 2001 From: Willem Grobler Date: Tue, 21 Jun 2022 21:15:24 +0000 Subject: [PATCH 1/5] added disableStyles --- .../attributes/useCommonServerAttributes.js | 8 +++ modern/src/map/core/useMapStyles.js | 53 +++++++++++-------- modern/src/settings/ServerPage.js | 4 +- 3 files changed, 42 insertions(+), 23 deletions(-) create mode 100644 modern/src/common/attributes/useCommonServerAttributes.js diff --git a/modern/src/common/attributes/useCommonServerAttributes.js b/modern/src/common/attributes/useCommonServerAttributes.js new file mode 100644 index 0000000000..ecfdae22ac --- /dev/null +++ b/modern/src/common/attributes/useCommonServerAttributes.js @@ -0,0 +1,8 @@ +import { useMemo } from 'react'; + +export default (t) => useMemo(() => ({ + disableStyles: { + name: t('attributeUiDisableStylesAttributes'), + type: 'string', + }, +}), [t]); diff --git a/modern/src/map/core/useMapStyles.js b/modern/src/map/core/useMapStyles.js index 72f18ebc69..e119c1574d 100644 --- a/modern/src/map/core/useMapStyles.js +++ b/modern/src/map/core/useMapStyles.js @@ -30,29 +30,31 @@ export default () => { const hereKey = useAttributePreference('hereKey'); const mapboxAccessToken = useAttributePreference('mapboxAccessToken'); const customMapUrl = useSelector((state) => state.session.server?.mapUrl); + const disabledStyles = new Set((useSelector((state) => state.session.server.attributes?.disableStyles) || '').split(',') || []); + const activeStyles = []; - return [ - { + const Styles = { + locationIqStreets: { id: 'locationIqStreets', title: t('mapLocationIqStreets'), style: `https://tiles.locationiq.com/v3/streets/vector.json?key=${locationIqKey || 'pk.0f147952a41c555a5b70614039fd148b'}`, available: true, }, - { + locationIqEarth: { id: 'locationIqEarth', title: t('mapLocationIqEarth'), style: `https://tiles.locationiq.com/v3/earth/vector.json?key=${locationIqKey}`, available: !!locationIqKey, attribute: 'locationIqKey', }, - { + locationIqHybrid: { id: 'locationIqHybrid', title: t('mapLocationIqHybrid'), style: `https://tiles.locationiq.com/v3/hybrid/vector.json?key=${locationIqKey}`, available: !!locationIqKey, attribute: 'locationIqKey', }, - { + osm: { id: 'osm', title: t('mapOsm'), style: styleCustom( @@ -61,7 +63,7 @@ export default () => { ), available: true, }, - { + carto: { id: 'carto', title: t('mapCarto'), style: styleCustom( @@ -70,21 +72,21 @@ export default () => { ), available: true, }, - { + mapTilerBasic: { id: 'mapTilerBasic', title: t('mapMapTilerBasic'), style: `https://api.maptiler.com/maps/basic/style.json?key=${mapTilerKey}`, available: !!mapTilerKey, attribute: 'mapTilerKey', }, - { + mapTilerHybrid: { id: 'mapTilerHybrid', title: t('mapMapTilerHybrid'), style: `https://api.maptiler.com/maps/hybrid/style.json?key=${mapTilerKey}`, available: !!mapTilerKey, attribute: 'mapTilerKey', }, - { + bingRoad: { id: 'bingRoad', title: t('mapBingRoad'), style: styleCustom( @@ -93,7 +95,7 @@ export default () => { available: !!bingMapsKey, attribute: 'bingMapsKey', }, - { + bingAerial: { id: 'bingAerial', title: t('mapBingAerial'), style: styleCustom( @@ -102,7 +104,7 @@ export default () => { available: !!bingMapsKey, attribute: 'bingMapsKey', }, - { + bingHybrid: { id: 'bingHybrid', title: t('mapBingHybrid'), style: styleCustom( @@ -111,21 +113,21 @@ export default () => { available: !!bingMapsKey, attribute: 'bingMapsKey', }, - { + tomTomBasic: { id: 'tomTomBasic', title: t('mapTomTomBasic'), style: `https://api.tomtom.com/map/1/style/20.0.0-8/basic_main.json?key=${tomTomKey}`, available: !!tomTomKey, attribute: 'tomTomKey', }, - { + hereBasic: { id: 'hereBasic', title: t('mapHereBasic'), style: `https://assets.vector.hereapi.com/styles/berlin/base/mapbox/tilezen?apikey=${hereKey}`, available: !!hereKey, attribute: 'hereKey', }, - { + hereHybrid: { id: 'hereHybrid', title: t('mapHereHybrid'), style: styleCustom( @@ -134,7 +136,7 @@ export default () => { available: !!hereKey, attribute: 'hereKey', }, - { + hereSatellite: { id: 'hereSatellite', title: t('mapHereSatellite'), style: styleCustom( @@ -143,7 +145,7 @@ export default () => { available: !!hereKey, attribute: 'hereKey', }, - { + autoNavi: { id: 'autoNavi', title: t('mapAutoNavi'), style: styleCustom( @@ -151,7 +153,7 @@ export default () => { ), available: true, }, - { + mapboxStreets: { id: 'mapboxStreets', title: t('mapMapboxStreets'), style: styleCustom( @@ -160,7 +162,7 @@ export default () => { available: !!mapboxAccessToken, attribute: 'mapboxAccessToken', }, - { + mapboxOutdoors: { id: 'mapboxOutdoors', title: t('mapMapboxOutdoors'), style: styleCustom( @@ -169,8 +171,8 @@ export default () => { available: !!mapboxAccessToken, attribute: 'mapboxAccessToken', }, - { - id: 'mapboxSatelliteStreet', + mapboxSatellite: { + id: 'mapboxSatellite', title: t('mapMapboxSatellite'), style: styleCustom( [`https://api.mapbox.com/styles/v1/mapbox/satellite-streets-v11/tiles/{z}/{x}/{y}?access_token=${mapboxAccessToken}`], @@ -178,11 +180,18 @@ export default () => { available: !!mapboxAccessToken, attribute: 'mapboxAccessToken', }, - { + custom: { id: 'custom', title: t('mapCustom'), style: styleCustom([customMapUrl]), available: !!customMapUrl, }, - ]; + }; + + Object.keys(Styles).forEach((key) => { + if (!disabledStyles.has(key)) { + activeStyles.push(Styles[key]); + } + }); + return activeStyles; }; diff --git a/modern/src/settings/ServerPage.js b/modern/src/settings/ServerPage.js index 26ef5bbf31..1aea5561d2 100644 --- a/modern/src/settings/ServerPage.js +++ b/modern/src/settings/ServerPage.js @@ -28,6 +28,7 @@ import PageLayout from '../common/components/PageLayout'; import SettingsMenu from './components/SettingsMenu'; import useCommonDeviceAttributes from '../common/attributes/useCommonDeviceAttributes'; import useCommonUserAttributes from '../common/attributes/useCommonUserAttributes'; +import useCommonServerAttributes from '../common/attributes/useCommonServerAttributes'; import { useCatch } from '../reactHelper'; const useStyles = makeStyles((theme) => ({ @@ -58,6 +59,7 @@ const ServerPage = () => { const t = useTranslation(); const commonUserAttributes = useCommonUserAttributes(t); + const commonServerAttributes = useCommonServerAttributes(t); const commonDeviceAttributes = useCommonDeviceAttributes(t); const original = useSelector((state) => state.session.server); @@ -238,7 +240,7 @@ const ServerPage = () => { setItem({ ...item, attributes })} - definitions={{ ...commonUserAttributes, ...commonDeviceAttributes }} + definitions={{ ...commonUserAttributes, ...commonDeviceAttributes, ...commonServerAttributes }} /> From b9fae9c41ed29891aaf39f9fc7917c80f17a2f17 Mon Sep 17 00:00:00 2001 From: Willem Grobler Date: Tue, 21 Jun 2022 21:16:36 +0000 Subject: [PATCH 2/5] added attributeUiDisableStylesAttributes --- web/l10n/en.json | 1 + 1 file changed, 1 insertion(+) diff --git a/web/l10n/en.json b/web/l10n/en.json index b00ecc03a4..dec08be16a 100644 --- a/web/l10n/en.json +++ b/web/l10n/en.json @@ -118,6 +118,7 @@ "attributeUiDisableCalendars": "UI: Disable Calendars", "attributeUiDisableMaintenance": "UI: Disable Maintenance", "attributeUiHidePositionAttributes": "UI: Hide Position Attributes", + "attributeUiDisableStylesAttributes": "UI: Disable Styles", "attributeNotificationTokens": "Notification Tokens", "errorTitle": "Error", "errorGeneral": "Invalid parameters or constraints violation", From 60995ed858af7da0493c4fd84f38f3c7709e2474 Mon Sep 17 00:00:00 2001 From: Willem Grobler Date: Wed, 22 Jun 2022 06:21:40 +0000 Subject: [PATCH 3/5] changed useCommonServerAttributes to useServerAttributes --- .../{useCommonServerAttributes.js => useServerAttributes .js} | 0 modern/src/settings/ServerPage.js | 4 ++-- 2 files changed, 2 insertions(+), 2 deletions(-) rename modern/src/common/attributes/{useCommonServerAttributes.js => useServerAttributes .js} (100%) diff --git a/modern/src/common/attributes/useCommonServerAttributes.js b/modern/src/common/attributes/useServerAttributes .js similarity index 100% rename from modern/src/common/attributes/useCommonServerAttributes.js rename to modern/src/common/attributes/useServerAttributes .js diff --git a/modern/src/settings/ServerPage.js b/modern/src/settings/ServerPage.js index 1aea5561d2..6b7cb573e7 100644 --- a/modern/src/settings/ServerPage.js +++ b/modern/src/settings/ServerPage.js @@ -28,7 +28,7 @@ import PageLayout from '../common/components/PageLayout'; import SettingsMenu from './components/SettingsMenu'; import useCommonDeviceAttributes from '../common/attributes/useCommonDeviceAttributes'; import useCommonUserAttributes from '../common/attributes/useCommonUserAttributes'; -import useCommonServerAttributes from '../common/attributes/useCommonServerAttributes'; +import useServerAttributes from '../common/attributes/useServerAttributes '; import { useCatch } from '../reactHelper'; const useStyles = makeStyles((theme) => ({ @@ -59,7 +59,7 @@ const ServerPage = () => { const t = useTranslation(); const commonUserAttributes = useCommonUserAttributes(t); - const commonServerAttributes = useCommonServerAttributes(t); + const commonServerAttributes = useServerAttributes(t); const commonDeviceAttributes = useCommonDeviceAttributes(t); const original = useSelector((state) => state.session.server); From 22ef038f139f0bc6be7f97f792f0988356593204 Mon Sep 17 00:00:00 2001 From: Willem Grobler Date: Wed, 22 Jun 2022 06:26:56 +0000 Subject: [PATCH 4/5] changed map styles to layers --- modern/src/common/attributes/useServerAttributes .js | 4 ++-- modern/src/map/core/useMapStyles.js | 2 +- web/l10n/en.json | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modern/src/common/attributes/useServerAttributes .js b/modern/src/common/attributes/useServerAttributes .js index ecfdae22ac..fd749f20a7 100644 --- a/modern/src/common/attributes/useServerAttributes .js +++ b/modern/src/common/attributes/useServerAttributes .js @@ -1,8 +1,8 @@ import { useMemo } from 'react'; export default (t) => useMemo(() => ({ - disableStyles: { - name: t('attributeUiDisableStylesAttributes'), + disableMapLayers: { + name: t('attributeUiDisableMapLayers'), type: 'string', }, }), [t]); diff --git a/modern/src/map/core/useMapStyles.js b/modern/src/map/core/useMapStyles.js index e119c1574d..b4f8955b57 100644 --- a/modern/src/map/core/useMapStyles.js +++ b/modern/src/map/core/useMapStyles.js @@ -30,7 +30,7 @@ export default () => { const hereKey = useAttributePreference('hereKey'); const mapboxAccessToken = useAttributePreference('mapboxAccessToken'); const customMapUrl = useSelector((state) => state.session.server?.mapUrl); - const disabledStyles = new Set((useSelector((state) => state.session.server.attributes?.disableStyles) || '').split(',') || []); + const disabledStyles = new Set((useSelector((state) => state.session.server.attributes?.disableMapLayers) || '').split(',') || []); const activeStyles = []; const Styles = { diff --git a/web/l10n/en.json b/web/l10n/en.json index dec08be16a..b66ea0cb7e 100644 --- a/web/l10n/en.json +++ b/web/l10n/en.json @@ -117,8 +117,8 @@ "attributeUiDisableComputedAttributes": "UI: Disable Computed Attributes", "attributeUiDisableCalendars": "UI: Disable Calendars", "attributeUiDisableMaintenance": "UI: Disable Maintenance", + "attributeUiDisableMapLayers": "UI: Disable Map Layers", "attributeUiHidePositionAttributes": "UI: Hide Position Attributes", - "attributeUiDisableStylesAttributes": "UI: Disable Styles", "attributeNotificationTokens": "Notification Tokens", "errorTitle": "Error", "errorGeneral": "Invalid parameters or constraints violation", From d17e1b3e2d6d539695e03c49c6c30b1481c06750 Mon Sep 17 00:00:00 2001 From: Willem Grobler Date: Wed, 22 Jun 2022 06:54:45 +0000 Subject: [PATCH 5/5] changed Styles dict to array --- modern/src/map/core/useMapStyles.js | 50 ++++++++++++++--------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/modern/src/map/core/useMapStyles.js b/modern/src/map/core/useMapStyles.js index b4f8955b57..8bac74a3df 100644 --- a/modern/src/map/core/useMapStyles.js +++ b/modern/src/map/core/useMapStyles.js @@ -33,28 +33,28 @@ export default () => { const disabledStyles = new Set((useSelector((state) => state.session.server.attributes?.disableMapLayers) || '').split(',') || []); const activeStyles = []; - const Styles = { - locationIqStreets: { + const Styles = [ + { id: 'locationIqStreets', title: t('mapLocationIqStreets'), style: `https://tiles.locationiq.com/v3/streets/vector.json?key=${locationIqKey || 'pk.0f147952a41c555a5b70614039fd148b'}`, available: true, }, - locationIqEarth: { + { id: 'locationIqEarth', title: t('mapLocationIqEarth'), style: `https://tiles.locationiq.com/v3/earth/vector.json?key=${locationIqKey}`, available: !!locationIqKey, attribute: 'locationIqKey', }, - locationIqHybrid: { + { id: 'locationIqHybrid', title: t('mapLocationIqHybrid'), style: `https://tiles.locationiq.com/v3/hybrid/vector.json?key=${locationIqKey}`, available: !!locationIqKey, attribute: 'locationIqKey', }, - osm: { + { id: 'osm', title: t('mapOsm'), style: styleCustom( @@ -63,7 +63,7 @@ export default () => { ), available: true, }, - carto: { + { id: 'carto', title: t('mapCarto'), style: styleCustom( @@ -72,21 +72,21 @@ export default () => { ), available: true, }, - mapTilerBasic: { + { id: 'mapTilerBasic', title: t('mapMapTilerBasic'), style: `https://api.maptiler.com/maps/basic/style.json?key=${mapTilerKey}`, available: !!mapTilerKey, attribute: 'mapTilerKey', }, - mapTilerHybrid: { + { id: 'mapTilerHybrid', title: t('mapMapTilerHybrid'), style: `https://api.maptiler.com/maps/hybrid/style.json?key=${mapTilerKey}`, available: !!mapTilerKey, attribute: 'mapTilerKey', }, - bingRoad: { + { id: 'bingRoad', title: t('mapBingRoad'), style: styleCustom( @@ -95,7 +95,7 @@ export default () => { available: !!bingMapsKey, attribute: 'bingMapsKey', }, - bingAerial: { + { id: 'bingAerial', title: t('mapBingAerial'), style: styleCustom( @@ -104,7 +104,7 @@ export default () => { available: !!bingMapsKey, attribute: 'bingMapsKey', }, - bingHybrid: { + { id: 'bingHybrid', title: t('mapBingHybrid'), style: styleCustom( @@ -113,21 +113,21 @@ export default () => { available: !!bingMapsKey, attribute: 'bingMapsKey', }, - tomTomBasic: { + { id: 'tomTomBasic', title: t('mapTomTomBasic'), style: `https://api.tomtom.com/map/1/style/20.0.0-8/basic_main.json?key=${tomTomKey}`, available: !!tomTomKey, attribute: 'tomTomKey', }, - hereBasic: { + { id: 'hereBasic', title: t('mapHereBasic'), style: `https://assets.vector.hereapi.com/styles/berlin/base/mapbox/tilezen?apikey=${hereKey}`, available: !!hereKey, attribute: 'hereKey', }, - hereHybrid: { + { id: 'hereHybrid', title: t('mapHereHybrid'), style: styleCustom( @@ -136,7 +136,7 @@ export default () => { available: !!hereKey, attribute: 'hereKey', }, - hereSatellite: { + { id: 'hereSatellite', title: t('mapHereSatellite'), style: styleCustom( @@ -145,7 +145,7 @@ export default () => { available: !!hereKey, attribute: 'hereKey', }, - autoNavi: { + { id: 'autoNavi', title: t('mapAutoNavi'), style: styleCustom( @@ -153,7 +153,7 @@ export default () => { ), available: true, }, - mapboxStreets: { + { id: 'mapboxStreets', title: t('mapMapboxStreets'), style: styleCustom( @@ -162,7 +162,7 @@ export default () => { available: !!mapboxAccessToken, attribute: 'mapboxAccessToken', }, - mapboxOutdoors: { + { id: 'mapboxOutdoors', title: t('mapMapboxOutdoors'), style: styleCustom( @@ -171,7 +171,7 @@ export default () => { available: !!mapboxAccessToken, attribute: 'mapboxAccessToken', }, - mapboxSatellite: { + { id: 'mapboxSatellite', title: t('mapMapboxSatellite'), style: styleCustom( @@ -180,18 +180,18 @@ export default () => { available: !!mapboxAccessToken, attribute: 'mapboxAccessToken', }, - custom: { + { id: 'custom', title: t('mapCustom'), style: styleCustom([customMapUrl]), available: !!customMapUrl, }, - }; + ]; - Object.keys(Styles).forEach((key) => { - if (!disabledStyles.has(key)) { - activeStyles.push(Styles[key]); + for (let i = 0; i < Styles.length; i += 1) { + if (!disabledStyles.has(Styles[i].id)) { + activeStyles.push(Styles[i]); } - }); + } return activeStyles; };