Skip to content
Open
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
42 changes: 41 additions & 1 deletion web/client/actions/__tests__/longitudinalPfofile-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
import expect from "expect";

import {CONTROL_DOCK_NAME} from '../../plugins/longitudinalProfile/constants';
import {CONTROL_DOCK_NAME, LONGITUDINAL_DISTANCES} from '../../plugins/longitudinalProfile/constants';
import {SET_CONTROL_PROPERTY} from "../controls";
import {
ADD_PROFILE_DATA,
Expand All @@ -24,6 +24,7 @@ import {
loading,
LOADING,
openDock,
setup,
setupPlugin,
SETUP,
TEAR_DOWN,
Expand All @@ -33,6 +34,22 @@ import {
toggleMaximize,
toggleMode
} from "../longitudinalProfile";
import longitudinalProfile from '../../reducers/longitudinalProfile';

/**
* runs the setup thunk against the real reducer and returns the dispatched actions
*/
const runSetup = (config) => {
let state = { longitudinalProfile: longitudinalProfile(undefined, {}) };
const actions = [];
const dispatch = (action) => {
actions.push(action);
state = { longitudinalProfile: longitudinalProfile(state.longitudinalProfile, action) };
};
setup(config)(dispatch, () => state);
return { actions, state };
};
const REFERENTIALS = [{ layerName: "sfdem", title: "sfdem" }];

describe('Test correctness of the actions', () => {
it('setup', () => {
Expand Down Expand Up @@ -137,3 +154,26 @@ describe('Test correctness of the actions', () => {
expect(action.type).toBe(TOGGLE_MAXIMIZE);
});
});

describe('Test setup thunk (defaultDistance / distances)', () => {
it('setup without defaultDistance and distances uses the default distance', () => {
const { actions, state } = runSetup({ referentials: REFERENTIALS });
const distanceAction = actions.find(a => a.type === CHANGE_DISTANCE);
expect(distanceAction).toExist();
expect(distanceAction.distance).toBe(100);
expect(state.longitudinalProfile.config.distances).toEqual(LONGITUDINAL_DISTANCES);
expect(actions[actions.length - 1].type).toBe(INITIALIZED);
});
it('setup with defaultDistance uses the configured value', () => {
const { actions } = runSetup({ referentials: REFERENTIALS, defaultDistance: 75 });
expect(actions.find(a => a.type === CHANGE_DISTANCE).distance).toBe(75);
});
it('setup with distances only keeps the default distance', () => {
const { actions } = runSetup({ referentials: REFERENTIALS, distances: [20, 40] });
expect(actions.find(a => a.type === CHANGE_DISTANCE).distance).toBe(100);
});
it('setup with defaultDistance null falls back to the first of distances', () => {
const { actions } = runSetup({ referentials: REFERENTIALS, defaultDistance: null, distances: [20, 40] });
expect(actions.find(a => a.type === CHANGE_DISTANCE).distance).toBe(20);
});
});
13 changes: 11 additions & 2 deletions web/client/actions/longitudinalProfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from "../actions/maplayout";
import {error} from "../actions/notifications";
import {
LONGITUDINAL_DISTANCES,
CONTROL_DOCK_NAME,
LONGITUDINAL_OWNER,
LONGITUDINAL_VECTOR_LAYER_ID,
Expand Down Expand Up @@ -197,14 +198,22 @@ export const toggleMode = (mode) => ({
export const setup = (config) => {
return (dispatch, getState) => {
dispatch(setupPlugin(config));
const { referentials, distances, defaultDistance, defaultReferentialName } = config || configSelector(getState());
const {
referentials = [],
distances = LONGITUDINAL_DISTANCES,
defaultDistance,
defaultReferentialName
} = configSelector(getState()) || {};
if (!referentials.length) {
dispatch(error({ title: "Error", message: "longitudinalProfile.errors.loadingError", autoDismiss: 10 }));
}
const defaultReferential = referentials.find(el => el.layerName === defaultReferentialName);
if (defaultReferentialName && !defaultReferential) {
dispatch(error({ title: "Error", message: "longitudinalProfile.errors.defaultReferentialNotFound", autoDismiss: 10 }));
}

dispatch(updateDockPanelsList(CONTROL_DOCK_NAME, "add", "right"));
dispatch(changeReferential(defaultReferentialName ?? referentials[0].layerName));
dispatch(changeReferential(defaultReferentialName || referentials[0]?.layerName));
dispatch(changeDistance(defaultDistance ?? distances[0]));
dispatch(updateAdditionalLayer(
LONGITUDINAL_VECTOR_LAYER_ID,
Expand Down
6 changes: 3 additions & 3 deletions web/client/plugins/LongitudinalProfileTool.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ import { createPlugin } from '../utils/PluginsUtils';
* @prop {Object} cfg.config the plugin configuration
* @prop {string} cfg.config.wpsurl optional, the geoserver url the the wps endpoint to use. It can be an absolute url. default is "/geoserver/wps".
* @prop {string} cfg.config.chartTitle the default title of the chart
* @prop {number} cfg.config.noDataThreshold the number that beyond it will exclude data
* @prop {number} cfg.config.defaultDistance the default distance value in meters
* @prop {number} cfg.config.noDataThreshold the number that beyond it will exclude data. Default is 999999
* @prop {number} cfg.config.defaultDistance optional, the initial value of the distance (in meters) shown in the settings and used by the WPS process. Default is 100
* @prop {string} cfg.config.identifier the profile to use in the wps request, defaulted to gs:LongitudinalProfile
* @prop {string} cfg.config.defaultReferentialName the default referential name
* @prop {string} cfg.config.defaultReferentialName optional, the default referential name. If not set, the first item of `referentials` is used
* @prop {Object[]} cfg.config.referentials (required) the layers that can be used as referentials
* @prop {string[]} cfg.filterAllowedCRS the allowed crs to be proposed when dropping a DXF file, (needs to be supported by mapstore)
* @prop {Object} cfg.additionalCRS the crs object that allow to define also a label
Expand Down
3 changes: 2 additions & 1 deletion web/client/plugins/longitudinalProfile/Menu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ const Menu = ({
const ButtonElement = document.getElementById("longitudinal-tool");
const offsetTop = getOffsetTop(ButtonElement);
const offsetBottom = getOffsetBottom(ButtonElement);
const dropUpVal = offsetTop > 130 || offsetBottom < 130;
const MAX_OFFSET_TOP = 140; // this value is tested both for Mapstore and GeoNode layout (DON'T reduce it)
const dropUpVal = offsetTop > MAX_OFFSET_TOP || offsetBottom < MAX_OFFSET_TOP;
setDropUp(dropUpVal);
}, []);
const [open, setMenuOpen ] = useState(false);
Expand Down
6 changes: 6 additions & 0 deletions web/client/themes/default/less/longitudinal-profile.less
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
.longitude-help {
.background-color-var(@theme-vars[mask-bg]);
.color-var(@theme-vars[main-bg]);
.border-color-var(@theme-vars[main-border-color]);
}
.longitudinal-tool-container {
.background-color-var(@theme-vars[main-bg]);
Expand Down Expand Up @@ -75,6 +76,11 @@
top: 45px;
width: 300px;
border-radius: 3px;
// keep the message visible on light basemaps: border + shadow around the box,
// dark text-shadow around the light (main-bg) text
border: 1px solid;
.shadow();
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
z-index: 1;
padding: 10px;
opacity: 0.8;
Expand Down
Loading