Skip to content

Commit

Permalink
Allow overrides of new map and geostory configuration (#281)
Browse files Browse the repository at this point in the history
  • Loading branch information
allyoucanmap authored Jun 28, 2021
1 parent 32b0ff6 commit 5dd41db
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 82 deletions.
14 changes: 7 additions & 7 deletions geonode_mapstore_client/client/js/api/geonode/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@

import axios from '@mapstore/framework/libs/ajax';

export const getBaseMapConfiguration = (baseMapUrl = '/static/mapstore/configs/map.json') => {
return axios.get(baseMapUrl)
.then(({ data }) => data);
export const getNewMapConfiguration = (newMapUrl = '/static/mapstore/configs/map.json') => {
return axios.get(newMapUrl)
.then(({ data }) => window.overrideNewMapConfig ? window.overrideNewMapConfig(data) : data);
};

export const getNewGeoStoryConfig = () => {
return axios.get('/static/mapstore/configs/geostory.json').then(({ data }) => data);
export const getNewGeoStoryConfig = (newGeoStoryUrl = '/static/mapstore/configs/geostory.json') => {
return axios.get(newGeoStoryUrl)
.then(({ data }) => window.overrideNewGeoStoryConfig ? window.overrideNewGeoStoryConfig(data) : data);
};

export default {
getBaseMapConfiguration,
getNewMapConfiguration,
getNewGeoStoryConfig
};

Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ describe('FiltersForm component', () => {
const applyButton = footerButtons[0];
Simulate.click(applyButton);
});
it('should trigger on change after clicking on clear', (done) => {
const onChange = (values) => {
it('should trigger on clear', (done) => {
const onClear = (values) => {
try {
expect(values).toBeTruthy();
done();
} catch (e) {
done(e);
}
};
ReactDOM.render( <FiltersForm show onChange={onChange} submitOnChangeField={false} />, document.getElementById("container"));
ReactDOM.render( <FiltersForm show onClear={onClear} submitOnChangeField={false} />, document.getElementById("container"));
const filterFormNode = document.querySelector('.gn-filter-form');
expect(filterFormNode).toBeTruthy();
const footerButtons = filterFormNode.querySelectorAll('.gn-filter-form-footer > button');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,18 @@ describe("gnviewer epics", () => {

it("should call mapConfig", (done) => {
mockAxios.onGet().reply(() => [200, {}]);
const NUM_ACTIONS = 1;
const NUM_ACTIONS = 3;
testEpic(
gnViewerRequestNewMapConfig,
NUM_ACTIONS,
requestNewMapConfig(),
(actions) => {
try {
expect(actions.map(({ type }) => type)).toEqual(["MAP_CONFIG_LOADED"]);
expect(actions.map(({ type }) => type)).toEqual([
"GEONODE:SET_NEW_RESOURCE",
"MAP_CONFIG_LOADED",
"GEONODE:SET_RESOURCE_TYPE"
]);
done();
} catch (error) {
done(error);
Expand Down
6 changes: 3 additions & 3 deletions geonode_mapstore_client/client/js/epics/gnviewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
REQUEST_NEW_GEOSTORY_CONFIG,
REQUEST_NEW_MAP_CONFIG
} from '@js/actions/gnviewer';
import { getBaseMapConfiguration, getNewGeoStoryConfig } from '@js/api/geonode/config';
import { getNewMapConfiguration, getNewGeoStoryConfig } from '@js/api/geonode/config';
import {
getLayerByPk,
getGeoStoryByPk,
Expand Down Expand Up @@ -54,7 +54,7 @@ export const gnViewerRequestLayerConfig = (action$) =>
action$.ofType(REQUEST_LAYER_CONFIG)
.switchMap(({ pk, page }) => {
return Observable.defer(() => axios.all([
getBaseMapConfiguration(),
getNewMapConfiguration(),
getLayerByPk(pk)
])).switchMap((response) => {
const [mapConfig, gnLayer] = response;
Expand Down Expand Up @@ -121,7 +121,7 @@ export const gnViewerRequestMapConfig = (action$) =>
export const gnViewerRequestNewMapConfig = (action$) =>
action$.ofType(REQUEST_NEW_MAP_CONFIG)
.switchMap(() => {
return Observable.defer(getBaseMapConfiguration
return Observable.defer(getNewMapConfiguration
).switchMap((response) => {
return Observable.of(
configureMap(response),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ describe('gnresource reducer', () => {
const state = gnresource({}, setResource(resource));
expect(state).toEqual({
error: null,
isNew: false,
data: resource,
loading: false
});
Expand Down Expand Up @@ -78,7 +79,8 @@ describe('gnresource reducer', () => {
it('should test setNewResource', () => {
const state = gnresource({}, setNewResource());
expect(state).toEqual({
isNew: true
isNew: true,
data: {}
});
});
it('should test setResourceId', () => {
Expand Down
68 changes: 2 additions & 66 deletions geonode_mapstore_client/client/static/mapstore/configs/map.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,70 +29,6 @@
20037508.34,
20037508.34
],
"layers": [
{
"type": "osm",
"title": "Open Street Map",
"name": "mapnik",
"source": "osm",
"group": "background",
"visibility": true
},
{
"type": "tileprovider",
"title": "NASAGIBS Night 2012",
"provider": "NASAGIBS.ViirsEarthAtNight2012",
"name": "Night2012",
"source": "nasagibs",
"group": "background",
"visibility": false
},
{
"type": "tileprovider",
"title": "OpenTopoMap",
"provider": "OpenTopoMap",
"name": "OpenTopoMap",
"source": "OpenTopoMap",
"group": "background",
"visibility": false
},
{
"format": "image/jpeg",
"group": "background",
"name": "s2cloudless:s2cloudless",
"opacity": 1,
"title": "Sentinel 2 Cloudless",
"type": "wms",
"url": [
"https://maps1.geosolutionsgroup.com/geoserver/wms",
"https://maps2.geosolutionsgroup.com/geoserver/wms",
"https://maps3.geosolutionsgroup.com/geoserver/wms",
"https://maps4.geosolutionsgroup.com/geoserver/wms",
"https://maps5.geosolutionsgroup.com/geoserver/wms",
"https://maps6.geosolutionsgroup.com/geoserver/wms"
],
"source": "s2cloudless",
"visibility": false,
"singleTile": false,
"credits": {
"title": "<a class=\"a-light\" xmlns:dct=\"http://purl.org/dc/terms/\" href=\"https://s2maps.eu\" property=\"dct:title\">Sentinel-2 cloudless 2016</a> by <a class=\"a-light\" xmlns:cc=\"http://creativecommons.org/ns#\" href=\"https://eox.at\" property=\"cc:attributionName\" rel=\"cc:attributionURL\">EOX IT Services GmbH</a>"
}
},
{
"source": "ol",
"group": "background",
"title": "Empty Background",
"fixed": true,
"type": "empty",
"name": "empty",
"visibility": false,
"args": [
"Empty Background",
{
"visibility": false
}
]
}
]
"layers": []
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
{% comment %}
app and map configuration need to be normalized
{% endcomment %}
{{ MAP_BASELAYERS|json_script:"settings-MAP_BASELAYERS" }}
{{ CATALOGUE_SERVICES|json_script:"settings-CATALOGUE_SERVICES" }}
{{ CATALOGUE_SELECTED_SERVICE|json_script:"settings-CATALOGUE_SELECTED_SERVICE" }}
<script>
{% autoescape off %}
(function(){
Expand Down Expand Up @@ -46,6 +49,32 @@
siteName: '{{ SITE_NAME|default:"Geonode" }}',
},
};

const baseLayerNode = document.getElementById('settings-MAP_BASELAYERS');
const baseLayers = baseLayerNode && JSON.parse(baseLayerNode.textContent) || [];
const catalogueServicesNode = document.getElementById('settings-CATALOGUE_SERVICES');
const catalogueServices = catalogueServicesNode && JSON.parse(catalogueServicesNode.textContent) || {};
const catalogueSelectedServiceNode = document.getElementById('settings-CATALOGUE_SELECTED_SERVICE');
const catalogueSelectedService = catalogueSelectedServiceNode && JSON.parse(catalogueSelectedServiceNode.textContent) || {};

// override maps configuration with properties from setting.py
window.overrideNewMapConfig = function(config) {
if (config && config.map && config.map.layers) {
config.map.layers.push(...baseLayers);
}
config.catalogServices = config.catalogServices || { services: {} };
if (catalogueServices) {
config.catalogServices.services = Object.assign(config.catalogServices.services || {}, catalogueServices);
}
if (catalogueSelectedService) {
config.catalogServices.selectedService = catalogueSelectedService;
}
return config;
};

// override new geostory configuration
// window.overrideNewGeoStoryConfig = function(config) { return config; };

})();
{% endautoescape %}
</script>
Expand Down

0 comments on commit 5dd41db

Please sign in to comment.