Skip to content

Commit 35a04ea

Browse files
committed
review backgrounds map configuration
1 parent 70a2c72 commit 35a04ea

File tree

5 files changed

+28
-49
lines changed

5 files changed

+28
-49
lines changed

geonode_mapstore_client/client/js/epics/gnresource.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ import { VisualizationModes } from '@mapstore/framework/utils/MapTypeUtils';
138138
import { forceUpdateMapLayout } from '@mapstore/framework/actions/maplayout';
139139
import { getShowDetails } from '@mapstore/framework/plugins/ResourcesCatalog/selectors/resources';
140140
import { searchSelector } from '@mapstore/framework/selectors/router';
141-
import { CREATE_BACKGROUNDS_LIST } from '@mapstore/framework/actions/backgroundselector';
141+
import { CREATE_BACKGROUNDS_LIST, allowBackgroundsDeletion } from '@mapstore/framework/actions/backgroundselector';
142142

143143
const FIT_BOUNDS_CONTROL = 'fitBounds';
144144

@@ -844,7 +844,8 @@ export const gnUpdateBackgroundEditEpic = (action$, store) =>
844844
const resourceType = state.gnresource?.type;
845845
const canEdit = resourceType === ResourceTypes.MAP && resource?.perms?.includes('change_resourcebase') ? true : false;
846846
return Observable.of(
847-
setResourceContext({ canEdit })
847+
setResourceContext({ canEdit }),
848+
...(canEdit ? [allowBackgroundsDeletion(true)] : [])
848849
);
849850
});
850851

geonode_mapstore_client/client/js/plugins/index.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import TOCPlugin from '@mapstore/framework/plugins/TOC';
2121
import Isochrone from "@mapstore/framework/plugins/Isochrone";
2222
import Itinerary from "@mapstore/framework/plugins/Itinerary";
2323
import SecurityPopup from "@mapstore/framework/plugins/SecurityPopup";
24+
import BackgroundSelector from '@mapstore/framework/plugins/BackgroundSelector';
25+
import MetadataExplorer from '@mapstore/framework/plugins/MetadataExplorer';
2426

2527
import OperationPlugin from '@js/plugins/Operation';
2628
import MetadataEditorPlugin from '@js/plugins/MetadataEditor';
@@ -87,6 +89,8 @@ export const plugins = {
8789
IsochronePlugin: Isochrone,
8890
ItineraryPlugin: Itinerary,
8991
SecurityPopupPlugin: SecurityPopup,
92+
BackgroundSelectorPlugin: BackgroundSelector,
93+
MetadataExplorerPlugin: MetadataExplorer,
9094
LayerDownloadPlugin: toModulePlugin(
9195
'LayerDownload',
9296
() => import(/* webpackChunkName: 'plugins/layer-download' */ '@mapstore/framework/plugins/LayerDownload'),
@@ -131,10 +135,6 @@ export const plugins = {
131135
'StyleEditor',
132136
() => import(/* webpackChunkName: 'plugins/style-editor' */ '@mapstore/framework/plugins/StyleEditor')
133137
),
134-
MetadataExplorerPlugin: toModulePlugin(
135-
'MetadataExplorer',
136-
() => import(/* webpackChunkName: 'plugins/metadata-explorer' */ '@mapstore/framework/plugins/MetadataExplorer')
137-
),
138138
QueryPanelPlugin: toModulePlugin(
139139
'QueryPanel',
140140
() => import(/* webpackChunkName: 'plugins/query-panel' */ '@mapstore/framework/plugins/QueryPanel')
@@ -258,10 +258,6 @@ export const plugins = {
258258
'MapLoading',
259259
() => import(/* webpackChunkName: 'plugins/map-loading-plugin' */ '@mapstore/framework/plugins/MapLoading')
260260
),
261-
BackgroundSelectorPlugin: toModulePlugin(
262-
'BackgroundSelector',
263-
() => import(/* webpackChunkName: 'plugins/background-selector-plugin' */ '@mapstore/framework/plugins/BackgroundSelector')
264-
),
265261
ZoomInPlugin: toModulePlugin(
266262
'ZoomIn',
267263
() => import(/* webpackChunkName: 'plugins/zoom-in-plugin' */ '@mapstore/framework/plugins/ZoomIn')

geonode_mapstore_client/client/js/utils/ResourceUtils.js

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -620,32 +620,9 @@ export function toGeoNodeMapConfig(data) {
620620
};
621621
}
622622

623-
export function compareBackgroundLayers(aLayer, bLayer) {
624-
return aLayer.type === bLayer.type
625-
&& aLayer.name === bLayer.name
626-
&& aLayer.source === bLayer.source
627-
&& aLayer.provider === bLayer.provider
628-
&& aLayer.url === bLayer.url;
629-
}
630-
631623
export function toMapStoreMapConfig(resource, baseConfig) {
632624
const { maplayers = [], data } = resource || {};
633-
const baseMapBackgroundLayers = (baseConfig?.map?.layers || []).filter(layer => layer.group === 'background');
634-
const dataBackgroundLayers = (data?.map?.layers || []).filter(layer => layer.group === 'background');
635-
const currentBackgroundLayer = dataBackgroundLayers.find(layer => layer.visibility);
636-
const backgroundLayers = currentBackgroundLayer
637-
? [
638-
...dataBackgroundLayers,
639-
...baseMapBackgroundLayers
640-
.filter(baseLayer => !dataBackgroundLayers.find(dataLayer => compareBackgroundLayers(dataLayer, baseLayer)))
641-
.map(layer => ({ ...layer, visibility: false }))
642-
]
643-
: [
644-
...dataBackgroundLayers,
645-
...baseMapBackgroundLayers
646-
.filter(baseLayer => !dataBackgroundLayers.find(dataLayer => compareBackgroundLayers(dataLayer, baseLayer)))
647-
];
648-
625+
const backgroundLayers = (data?.map?.layers || []).filter(layer => layer.group === 'background');
649626
const layers = (data?.map?.layers || [])
650627
.filter(layer => layer.group !== 'background')
651628
.map((layer) => {

geonode_mapstore_client/client/js/utils/__tests__/ResourceUtils-test.js

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import {
1717
setAvailableResourceTypes,
1818
getGeoNodeMapLayers,
1919
toGeoNodeMapConfig,
20-
compareBackgroundLayers,
2120
toMapStoreMapConfig,
2221
parseStyleName,
2322
canCopyResource,
@@ -198,9 +197,6 @@ describe('Test Resource Utils', () => {
198197
const geoNodeMapConfig = toGeoNodeMapConfig(data, mapState);
199198
expect(geoNodeMapConfig.maplayers.length).toBe(1);
200199
});
201-
it('should be able to compare background layers with different ids', () => {
202-
expect(compareBackgroundLayers({ type: 'osm', source: 'osm', id: '11' }, { type: 'osm', source: 'osm' })).toBe(true);
203-
});
204200
it('should transform a resource to a mapstore map config', () => {
205201
const resource = {
206202
maplayers: [
@@ -354,7 +350,7 @@ describe('Test Resource Utils', () => {
354350
}
355351
);
356352
});
357-
it('should transform a resource to a mapstore map config and update backgrounds', () => {
353+
it('should transform a resource to a mapstore map config and to not update backgrounds', () => {
358354
const resource = {
359355
maplayers: [
360356
{
@@ -416,14 +412,6 @@ describe('Test Resource Utils', () => {
416412
group: 'background',
417413
visibility: true
418414
},
419-
{
420-
name: 'OpenTopoMap',
421-
provider: 'OpenTopoMap',
422-
source: 'OpenTopoMap',
423-
type: 'tileprovider',
424-
visibility: false,
425-
group: 'background'
426-
},
427415
{ id: '02', type: 'vector', features: [] },
428416
{
429417
id: '03',
@@ -499,8 +487,8 @@ describe('Test Resource Utils', () => {
499487
const mapStoreMapConfig = toMapStoreMapConfig(resource, baseConfig);
500488
expect(mapStoreMapConfig).toBeTruthy();
501489
const layers = mapStoreMapConfig.map.layers;
502-
expect(layers.length).toBe(2);
503-
expect(layers[1].featureInfo).toEqual({ template, format: FEATURE_INFO_FORMAT });
490+
expect(layers.length).toBe(1);
491+
expect(layers[0].featureInfo).toEqual({ template, format: FEATURE_INFO_FORMAT });
504492
});
505493

506494
it('should parse style name into accepted format', () => {

geonode_mapstore_client/templates/geonode-mapstore-client/_geonode_config.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,23 @@
185185
endpointV1: siteUrl + 'api',
186186
endpointV2: siteUrl + 'api/v2/'
187187
},
188+
initialState: {
189+
defaultState: {
190+
catalog: {
191+
default: {
192+
staticServices: {
193+
default_map_backgrounds: {
194+
type: 'backgrounds',
195+
title: 'Default Backgrounds',
196+
titleMsgId: 'defaultMapBackgroundsServiceTitle',
197+
autoload: true,
198+
backgrounds: baseLayers
199+
}
200+
}
201+
}
202+
}
203+
}
204+
},
188205
projectionDefs: projectionDefs,
189206
geoNodeCustomFilters: customFilters,
190207
geoNodeCardsMenuItems: cardsMenuItems,

0 commit comments

Comments
 (0)