Skip to content

Commit

Permalink
legacy map loading and merge support #31
Browse files Browse the repository at this point in the history
  • Loading branch information
offtherailz committed Aug 12, 2015
1 parent 946fdb7 commit 78f0856
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 69 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
/**
* ES6
*/
//"no-var": 2, // http://eslint.org/docs/rules/no-var
"no-var": 0, // http://eslint.org/docs/rules/no-var
"prefer-const": 0, // http://eslint.org/docs/rules/prefer-const

/**
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
"object-assign": "^3.0.0",
"proj4": "~2.3.6",
"react": "^0.13.3",
"react-bootstrap": "^0.24.3"
"react-bootstrap": "^0.24.3",
"url": "~0.10.3"
},
"scripts": {
"clean": "rm -Rf ./web/dist",
Expand Down
25 changes: 22 additions & 3 deletions web/client/api/MapConfigDAO.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/


var axios = require('axios');

var ConfigUtils = require('../utils/ConfigUtils');
/**
* API for local config
*/
Expand All @@ -18,6 +16,27 @@ var Api = {
// render map
return response.data;
});
},

/**
* Returns Merged configurations from base url and GeoStore
*/
getMergedConfig: function(baseConfigURL, mapId, geoStoreBase) {
var url = ( geoStoreBase || "/rest/geostore/" ) + "data/" + mapId;
var me = this;
if (!mapId) {
return this.get(baseConfigURL);
}

return axios.all([axios.get(baseConfigURL), axios.get(url)])
.then( function(args) {
var baseConfig = args[0];
var mapConfig = args[1];
return ConfigUtils.mergeConfigs(baseConfig, mapConfig);
}).catch(function() {
// TODO manage the error
return me.get(baseConfigURL);
});
}
};

Expand Down
5 changes: 3 additions & 2 deletions web/client/examples/viewer/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
var React = require('react');
var MapViewController = require('../../components/Map/MapViewController');
var InfoButton = require('../../components/InfoButton/InfoButton');

var ConfigUtils = require('../../utils/ConfigUtils');
var url = require('url');

var Api = require('../../api/MapConfigDAO');

Api.get("../data/mapStoreConfig.json").then( function(legacyConfig) {
// window.geoStoreBase = "http://mapstore.geo-solutions.it/geostore/rest/"
Api.getMergedConfig("../data/mapStoreConfig.json", url.parse(window.location.href, true).query.mapId, window.geoStoreBase).then( function(legacyConfig) {
const mapId = "map";
// convert from legacy
const conf = ConfigUtils.convertFromLegacy(legacyConfig);
Expand Down
8 changes: 8 additions & 0 deletions web/client/utils/ConfigUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ var ConfigUtils = {
if (candidateVisible) {
candidateVisible.visibility = true;
}
},
/**
* Utility to merge different configs
*/
mergeConfigs: function(baseConfig, mapConfig) {
baseConfig.map = mapConfig.map;
baseConfig.gsSources = mapConfig.gsSources || mapConfig.sources;
return baseConfig;
}
};

Expand Down
170 changes: 109 additions & 61 deletions web/client/utils/__tests__/ConfigUtils-test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,72 +7,113 @@
*/
var expect = require('expect');
var ConfigUtils = require('../ConfigUtils');
var lconfig = {
"gsSources": {
"mapquest": {
"ptype": "gxp_mapquestsource"
},
"osm": {
"ptype": "gxp_osmsource"
},
"google": {
"ptype": "gxp_googlesource"
},
"bing": {
"ptype": "gxp_bingsource"
},
"ol": {
"ptype": "gxp_olsource"
var lconfig = {};
var testMap = {
"defaultSourceType": "gxp_wmssource",
"map": {
"center": [
1361886.8627049,
5723464.1181097
],
"extent": [
-2.003750834E7,
-2.003750834E7,
2.003750834E7,
2.003750834E7
],
"zoom": 10,
"layers": [
{
"title": "c1101031_iba",
"source": "gxp-source-508",
"visibility": true,
"name": "cite:c1101031_iba",
"opacity": 1
}
],
"projection": "EPSG:900913",
"units": "m"
},
"sources": {
"gxp-source-508": {
"projection": "EPSG:900913",
"url": "http://test.org"
}

}
};
function resetLConfig() {
lconfig = {
"gsSources": {
"mapquest": {
"ptype": "gxp_mapquestsource"
},
"osm": {
"ptype": "gxp_osmsource"
},
"google": {
"ptype": "gxp_googlesource"
},
"bing": {
"ptype": "gxp_bingsource"
},
"ol": {
"ptype": "gxp_olsource"
},
"demo": {
"url": "http://demo.geo-solutions.it/geoserver/wms"
}
},
"demo": {
"url": "http://demo.geo-solutions.it/geoserver/wms"
"map": {
"projection": "EPSG:900913",
"units": "m",
"center": [1250000.000000, 5370000.000000],
"zoom": 5,
"maxExtent": [
-20037508.34, -20037508.34,
20037508.34, 20037508.34
],
"layers": [{
"source": "google",
"title": "Google Hybrid",
"name": "HYBRID",
"group": "background"
}, {
"source": "mapquest",
"title": "MapQuest OpenStreetMap",
"name": "osm",
"group": "background"
}, {
"source": "osm",
"title": "Open Street Map",
"name": "mapnik",
"group": "background",
"visibility": true // this should be replaced with false
}, {
"source": "osm",
"title": "Open Street Map",
"name": "mapnik",
"group": "background",
"visibility": true
}, {
"source": "demo",
"visibility": true,
"opacity": 0.5,
"title": "Weather data",
"name": "nurc:Arc_Sample",
"group": "Meteo",
"format": "image/png"
}]
}
},
"map": {
"projection": "EPSG:900913",
"units": "m",
"center": [1250000.000000, 5370000.000000],
"zoom": 5,
"maxExtent": [
-20037508.34, -20037508.34,
20037508.34, 20037508.34
],
"layers": [{
"source": "google",
"title": "Google Hybrid",
"name": "HYBRID",
"group": "background"
}, {
"source": "mapquest",
"title": "MapQuest OpenStreetMap",
"name": "osm",
"group": "background"
}, {
"source": "osm",
"title": "Open Street Map",
"name": "mapnik",
"group": "background",
"visibility": true // this should be replaced with false
}, {
"source": "osm",
"title": "Open Street Map",
"name": "mapnik",
"group": "background",
"visibility": true
}, {
"source": "demo",
"visibility": true,
"opacity": 0.5,
"title": "Weather data",
"name": "nurc:Arc_Sample",
"group": "Meteo",
"format": "image/png"
}]
}
};
};
}
describe('ConfigUtils', () => {
beforeEach( () => {
resetLConfig();
});
afterEach((done) => {
document.body.innerHTML = '';

setTimeout(done);
});
it('convert from legacy and check projection conversion', () => {
Expand Down Expand Up @@ -108,4 +149,11 @@ describe('ConfigUtils', () => {
expect(config.layers[3].visibility).toBe(true);
expect(config.layers[4].visibility).toBe(true);
});

it('check merge config', () => {
var config = ConfigUtils.mergeConfigs(lconfig, testMap);
// check layers replaced
expect(config.map.layers.length).toBe(1);
expect(config.gsSources["gxp-source-508"]).toExist();
});
});
14 changes: 13 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
var path = require("path");

var rewriteUrl = function(replacePath) {
return function(req, opt) { // gets called with request and proxy object
var queryIndex = req.url.indexOf('?');
var query = queryIndex >= 0 ? req.url.substr(queryIndex) : "";
req.url = req.path.replace(opt.path, replacePath) + query;
};
};
module.exports = {
entry: path.join(__dirname, "web", "client", "examples", "viewer", "app"),
output: {
Expand All @@ -16,7 +22,13 @@ module.exports = {
]
},
devServer: {
proxy: [{
path: new RegExp("/rest/geostore/(.*)"),
rewrite: rewriteUrl("/geostore/rest/$1"),
target: "http://mapstore.geo-solutions.it"
}]
},

devtool: 'inline-source-map',
debug: true
};

0 comments on commit 78f0856

Please sign in to comment.