Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #146, GetFeatureInfo improvements #148

Merged
merged 1 commit into from
Sep 25, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"openlayers": "^3.8.2",
"proj4": "~2.3.6",
"react": "^0.13.3",
"react-bootstrap": "^0.24.3",
"react-bootstrap": "^0.25.2",
"react-intl": "^1.2.0",
"react-redux": "^2.0.0",
"redux": "^2.0.0",
Expand Down
78 changes: 15 additions & 63 deletions web/client/actions/__tests__/map-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,11 @@
var expect = require('expect');
var {
CHANGE_MAP_VIEW,
ERROR_FEATURE_INFO,
EXCEPTIONS_FEATURE_INFO,
LOAD_FEATURE_INFO,
CHANGE_MAPINFO_STATE,
NEW_MAPINFO_REQUEST,
PURGE_MAPINFO_RESULTS,
getFeatureInfo,
CLICK_ON_MAP,
CHANGE_MOUSE_POINTER,
changeMapView,
changeMapInfoState,
newMapInfoRequest,
purgeMapInfoResults
clickOnMap,
changeMousePointer
} = require('../map');

describe('Test correctness of the map actions', () => {
Expand All @@ -39,63 +33,21 @@ describe('Test correctness of the map actions', () => {
expect(retval.size).toBe(testSize);
});

it('get feature info data', (done) => {
getFeatureInfo('base/web/client/test-resources/featureInfo-response.json', {})((e) => {
try {
expect(e).toExist();
expect(e.type).toBe(LOAD_FEATURE_INFO);
done();
} catch(ex) {
done(ex);
}
});
});

it('get feature info exception', (done) => {
getFeatureInfo('base/web/client/test-resources/featureInfo-exception.json', {})((e) => {
try {
expect(e).toExist();
expect(e.type).toBe(EXCEPTIONS_FEATURE_INFO);
done();
} catch(ex) {
done(ex);
}
});
});

it('get feature info error', (done) => {
getFeatureInfo('requestError.json', {})((e) => {
try {
expect(e).toExist();
expect(e.type).toBe(ERROR_FEATURE_INFO);
done();
} catch(ex) {
done(ex);
}
});
});

it('change map info state', () => {
it('set a new clicked point', () => {
const testVal = "val";
const retval = changeMapInfoState(testVal);
const retval = clickOnMap(testVal);

expect(retval.type).toBe(CHANGE_MAPINFO_STATE);
expect(retval.enabled).toExist();
expect(retval.enabled).toBe(testVal);
expect(retval.type).toBe(CLICK_ON_MAP);
expect(retval.point).toExist();
expect(retval.point).toBe(testVal);
});

it('add new info request', () => {
const testVal = "val";
const retval = newMapInfoRequest(testVal);

expect(retval.type).toBe(NEW_MAPINFO_REQUEST);
expect(retval.request).toExist();
expect(retval.request).toBe(testVal);
});
it('set a new mouse pointer', () => {
const testVal = 'pointer';
const retval = changeMousePointer(testVal);

it('delete all results', () => {
const retval = purgeMapInfoResults();

expect(retval.type).toBe(PURGE_MAPINFO_RESULTS);
expect(retval).toExist();
expect(retval.type).toBe(CHANGE_MOUSE_POINTER);
expect(retval.pointer).toBe(testVal);
});
});
96 changes: 96 additions & 0 deletions web/client/actions/__tests__/mapInfo-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/**
* Copyright 2015, GeoSolutions Sas.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/

var expect = require('expect');
var {
ERROR_FEATURE_INFO,
EXCEPTIONS_FEATURE_INFO,
LOAD_FEATURE_INFO,
CHANGE_MAPINFO_STATE,
NEW_MAPINFO_REQUEST,
PURGE_MAPINFO_RESULTS,
getFeatureInfo,
changeMapInfoState,
newMapInfoRequest,
purgeMapInfoResults
} = require('../mapInfo');

describe('Test correctness of the map actions', () => {

it('get feature info data', (done) => {
getFeatureInfo('base/web/client/test-resources/featureInfo-response.json', {p: "p"}, "meta")((e) => {
try {
expect(e).toExist();
expect(e.type).toBe(LOAD_FEATURE_INFO);
expect(e.data).toExist();
expect(e.requestParams).toExist();
expect(e.requestParams.p).toBe("p");
expect(e.layerMetadata).toBe("meta");
done();
} catch(ex) {
done(ex);
}
});
});

it('get feature info exception', (done) => {
getFeatureInfo('base/web/client/test-resources/featureInfo-exception.json', {p: "p"}, "meta")((e) => {
try {
expect(e).toExist();
expect(e.type).toBe(EXCEPTIONS_FEATURE_INFO);
expect(e.exceptions).toExist();
expect(e.requestParams).toExist();
expect(e.requestParams.p).toBe("p");
expect(e.layerMetadata).toBe("meta");
done();
} catch(ex) {
done(ex);
}
});
});

it('get feature info error', (done) => {
getFeatureInfo('requestError.json', {p: "p"}, "meta")((e) => {
try {
expect(e).toExist();
expect(e.type).toBe(ERROR_FEATURE_INFO);
expect(e.error).toExist();
expect(e.requestParams).toExist();
expect(e.requestParams.p).toBe("p");
expect(e.layerMetadata).toBe("meta");
done();
} catch(ex) {
done(ex);
}
});
});

it('change map info state', () => {
const testVal = "val";
const retval = changeMapInfoState(testVal);

expect(retval.type).toBe(CHANGE_MAPINFO_STATE);
expect(retval.enabled).toExist();
expect(retval.enabled).toBe(testVal);
});

it('add new info request', () => {
const testVal = "val";
const retval = newMapInfoRequest(testVal);

expect(retval.type).toBe(NEW_MAPINFO_REQUEST);
expect(retval.request).toExist();
expect(retval.request).toBe(testVal);
});

it('delete all results', () => {
const retval = purgeMapInfoResults();

expect(retval.type).toBe(PURGE_MAPINFO_RESULTS);
});
});
109 changes: 12 additions & 97 deletions web/client/actions/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,10 @@
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
const assign = require('object-assign');
const axios = require('axios');

const CHANGE_MAP_VIEW = 'CHANGE_MAP_VIEW';
const LOAD_FEATURE_INFO = 'LOAD_FEATURE_INFO';
const ERROR_FEATURE_INFO = 'ERROR_FEATURE_INFO';
const EXCEPTIONS_FEATURE_INFO = 'EXCEPTIONS_FEATURE_INFO';
const CHANGE_MAPINFO_STATE = 'CHANGE_MAPINFO_STATE';
const NEW_MAPINFO_REQUEST = 'NEW_MAPINFO_REQUEST';
const PURGE_MAPINFO_RESULTS = 'PURGE_MAPINFO_RESULTS';
const CLICK_ON_MAP = 'CLICK_ON_MAP';
const CHANGE_MOUSE_POINTER = 'CHANGE_MOUSE_POINTER';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably don't need an action to change the mouse pointer. The mouse pointer can be a calculated property of existing state(it depends from controls state), but let's just open a new issue for this. It's ok for now. Actions should reflect events. I cannot figure out a real "change mouse pointer" event in this context.


function changeMapView(center, zoom, bbox, size) {
return {
Expand All @@ -26,104 +20,25 @@ function changeMapView(center, zoom, bbox, size) {
};
}

/**
* Private
* @return a LOAD_FEATURE_INFO action with the response data to a wms GetFeatureInfo
*/
function loadFeatureInfo(data) {
return {
type: LOAD_FEATURE_INFO,
data: data
};
}

/**
* Private
* @return a ERROR_FEATURE_INFO action with the error occured
*/
function errorFeatureInfo(e) {
return {
type: ERROR_FEATURE_INFO,
error: e
};
}

/**
* Private
* @return a EXCEPTIONS_FEATURE_INFO action with the wms exception occured
* during a GetFeatureInfo request.
*/
function exceptionsFeatureInfo(exceptions) {
return {
type: EXCEPTIONS_FEATURE_INFO,
exceptions: exceptions
};
}

/**
* Sends a wms GetFeatureInfo request and dispatches the right action
* in case of success, error or exceptions.
*
* @param wmsBasePath {string} base path to the wms service
* @param requestParams {object} map of params for a getfeatureinfo request.
*/
function getFeatureInfo(wmsBasePath, requestParams) {
const defaultParams = {
service: 'WMS',
version: '1.0.0',
request: 'GetFeatureInfo',
crs: 'EPSG:4326',
info_format: 'application/json',
feature_count: 50,
x: 0,
y: 0,
exceptions: 'application/json'
};
const param = assign({}, defaultParams, requestParams);
return (dispatch) => {
return axios.get(wmsBasePath, {params: param}).then((response) => {
if (response.data.exceptions) {
dispatch(exceptionsFeatureInfo(response.data.exceptions));
} else {
dispatch(loadFeatureInfo(response.data));
}
}).catch((e) => {
dispatch(errorFeatureInfo(e));
});
};
}

function changeMapInfoState(enabled) {
return {
type: CHANGE_MAPINFO_STATE,
enabled: enabled
};
}

function newMapInfoRequest(reqConfig) {
function clickOnMap(point) {
return {
type: NEW_MAPINFO_REQUEST,
request: reqConfig
type: CLICK_ON_MAP,
point: point
};
}

function purgeMapInfoResults() {
function changeMousePointer(pointerType) {
return {
type: PURGE_MAPINFO_RESULTS
type: CHANGE_MOUSE_POINTER,
pointer: pointerType
};
}

module.exports = {
CHANGE_MAP_VIEW,
ERROR_FEATURE_INFO,
EXCEPTIONS_FEATURE_INFO,
LOAD_FEATURE_INFO,
CHANGE_MAPINFO_STATE,
NEW_MAPINFO_REQUEST,
PURGE_MAPINFO_RESULTS,
getFeatureInfo,
CLICK_ON_MAP,
CHANGE_MOUSE_POINTER,
changeMapView,
changeMapInfoState,
newMapInfoRequest,
purgeMapInfoResults
clickOnMap,
changeMousePointer
};
Loading