diff --git a/cms/config/sync/admin-role.strapi-super-admin.json b/cms/config/sync/admin-role.strapi-super-admin.json index 5b3a8e32..753c5772 100644 --- a/cms/config/sync/admin-role.strapi-super-admin.json +++ b/cms/config/sync/admin-role.strapi-super-admin.json @@ -879,7 +879,8 @@ "legend_config.items.icon", "legend_config.items.color", "legend_config.items.value", - "legend_config.items.description" + "legend_config.items.description", + "default" ], "locales": [ "en", @@ -937,7 +938,8 @@ "legend_config.items.icon", "legend_config.items.color", "legend_config.items.value", - "legend_config.items.description" + "legend_config.items.description", + "default" ], "locales": [ "en", @@ -969,7 +971,8 @@ "legend_config.items.icon", "legend_config.items.color", "legend_config.items.value", - "legend_config.items.description" + "legend_config.items.description", + "default" ], "locales": [ "en", diff --git a/cms/config/sync/core-store.plugin_content_manager_configuration_content_types##api##layer.layer.json b/cms/config/sync/core-store.plugin_content_manager_configuration_content_types##api##layer.layer.json index 568c63a1..9295fa2e 100644 --- a/cms/config/sync/core-store.plugin_content_manager_configuration_content_types##api##layer.layer.json +++ b/cms/config/sync/core-store.plugin_content_manager_configuration_content_types##api##layer.layer.json @@ -76,20 +76,6 @@ "sortable": false } }, - "legend_config": { - "edit": { - "label": "legend_config", - "description": "", - "placeholder": "", - "visible": true, - "editable": true - }, - "list": { - "label": "legend_config", - "searchable": false, - "sortable": false - } - }, "interaction_config": { "edit": { "label": "interaction_config", @@ -133,6 +119,34 @@ "sortable": true } }, + "legend_config": { + "edit": { + "label": "legend_config", + "description": "", + "placeholder": "", + "visible": true, + "editable": true + }, + "list": { + "label": "legend_config", + "searchable": false, + "sortable": false + } + }, + "default": { + "edit": { + "label": "default", + "description": "Whether the layer is shown by default on the map", + "placeholder": "", + "visible": true, + "editable": true + }, + "list": { + "label": "default", + "searchable": true, + "sortable": true + } + }, "createdAt": { "edit": { "label": "createdAt", @@ -193,12 +207,6 @@ } }, "layouts": { - "list": [ - "id", - "title", - "type", - "metadata" - ], "edit": [ [ { @@ -210,6 +218,16 @@ "size": 6 } ], + [ + { + "name": "dataset", + "size": 6 + }, + { + "name": "default", + "size": 4 + } + ], [ { "name": "config", @@ -239,13 +257,13 @@ "name": "metadata", "size": 12 } - ], - [ - { - "name": "dataset", - "size": 6 - } ] + ], + "list": [ + "id", + "title", + "type", + "metadata" ] } }, diff --git a/cms/src/api/layer/content-types/layer/schema.json b/cms/src/api/layer/content-types/layer/schema.json index 31adacd9..eb15b6ae 100644 --- a/cms/src/api/layer/content-types/layer/schema.json +++ b/cms/src/api/layer/content-types/layer/schema.json @@ -89,6 +89,15 @@ } }, "component": "legend.legend" + }, + "default": { + "pluginOptions": { + "i18n": { + "localized": false + } + }, + "type": "boolean", + "default": false } } } diff --git a/cms/types/generated/contentTypes.d.ts b/cms/types/generated/contentTypes.d.ts index 277c7c98..c5cfc2b0 100644 --- a/cms/types/generated/contentTypes.d.ts +++ b/cms/types/generated/contentTypes.d.ts @@ -1447,6 +1447,13 @@ export interface ApiLayerLayer extends Schema.CollectionType { localized: true; }; }>; + default: Attribute.Boolean & + Attribute.SetPluginOptions<{ + i18n: { + localized: false; + }; + }> & + Attribute.DefaultTo; createdAt: Attribute.DateTime; updatedAt: Attribute.DateTime; publishedAt: Attribute.DateTime; diff --git a/frontend/src/containers/map/content/map/index.tsx b/frontend/src/containers/map/content/map/index.tsx index 5d76cb40..07ba765b 100644 --- a/frontend/src/containers/map/content/map/index.tsx +++ b/frontend/src/containers/map/content/map/index.tsx @@ -23,7 +23,7 @@ import EEZLayerPopup from '@/containers/map/content/map/popup/eez'; import GenericPopup from '@/containers/map/content/map/popup/generic'; import ProtectedAreaPopup from '@/containers/map/content/map/popup/protected-area'; import RegionsPopup from '@/containers/map/content/map/popup/regions'; -import { useSyncMapSettings } from '@/containers/map/content/map/sync-settings'; +import { useSyncMapLayers, useSyncMapSettings } from '@/containers/map/content/map/sync-settings'; import { sidebarAtom } from '@/containers/map/store'; import { bboxLocation, @@ -45,6 +45,7 @@ const MainMap: FCWithMessages = () => { const locale = useLocale(); const [{ bbox: URLBbox }, setMapSettings] = useSyncMapSettings(); + const [, setMapLayers] = useSyncMapLayers(); const { default: map } = useMap(); const drawState = useAtomValue(drawStateAtom); const isSidebarOpen = useAtomValue(sidebarAtom); @@ -92,6 +93,30 @@ const MainMap: FCWithMessages = () => { } ); + const { data: defaultLayers } = useGetLayers( + { + locale, + fields: 'id', + filters: { + default: { + $eq: true, + }, + }, + }, + { + query: { + select: ({ data }) => data.map(({ id }) => id), + }, + } + ); + + // Once we have fetched from the CMS which layers are active by default, we set toggle them on + useEffect(() => { + if (defaultLayers) { + setMapLayers(defaultLayers); + } + }, [setMapLayers, defaultLayers]); + useEffect(() => { setLocationBbox(locationsQuery?.data?.bounds as CustomMapProps['bounds']['bbox']); }, [locationCode, locationsQuery, setLocationBbox]); diff --git a/frontend/src/containers/map/content/map/sync-settings.ts b/frontend/src/containers/map/content/map/sync-settings.ts index 36a326d5..b08be8ee 100644 --- a/frontend/src/containers/map/content/map/sync-settings.ts +++ b/frontend/src/containers/map/content/map/sync-settings.ts @@ -20,7 +20,7 @@ export const useSyncMapSettings = () => { }; export const useSyncMapLayers = () => { - return useQueryState('layers', parseAsArrayOf(parseAsInteger).withDefault([6, 7])); + return useQueryState('layers', parseAsArrayOf(parseAsInteger).withDefault([])); }; export const useSyncMapLayerSettings = () => { diff --git a/frontend/src/types/generated/strapi.schemas.ts b/frontend/src/types/generated/strapi.schemas.ts index b22451b9..485c4c3b 100644 --- a/frontend/src/types/generated/strapi.schemas.ts +++ b/frontend/src/types/generated/strapi.schemas.ts @@ -6695,6 +6695,7 @@ export interface Layer { metadata?: DocumentationMetadataComponent; dataset?: LayerDataset; legend_config?: LegendLegendComponent; + default?: boolean; createdAt?: string; updatedAt?: string; publishedAt?: string; @@ -6756,6 +6757,7 @@ export type LayerDatasetDataAttributesLayersDataItemAttributes = { metadata?: LayerDatasetDataAttributesLayersDataItemAttributesMetadata; dataset?: LayerDatasetDataAttributesLayersDataItemAttributesDataset; legend_config?: LayerDatasetDataAttributesLayersDataItemAttributesLegendConfig; + default?: boolean; createdAt?: string; updatedAt?: string; publishedAt?: string; @@ -7095,6 +7097,7 @@ export type LayerRequestData = { metadata?: DocumentationMetadataComponent; dataset?: LayerRequestDataDataset; legend_config?: LegendLegendComponent; + default?: boolean; locale?: string; }; @@ -7123,6 +7126,7 @@ export interface LayerLocalizationRequest { metadata?: DocumentationMetadataComponent; dataset?: LayerLocalizationRequestDataset; legend_config?: LegendLegendComponent; + default?: boolean; locale: string; } @@ -9195,6 +9199,7 @@ export type DatasetLayersDataItemAttributes = { metadata?: DatasetLayersDataItemAttributesMetadata; dataset?: DatasetLayersDataItemAttributesDataset; legend_config?: DatasetLayersDataItemAttributesLegendConfig; + default?: boolean; createdAt?: string; updatedAt?: string; publishedAt?: string;