Skip to content

Commit

Permalink
geosolutions-it#8334 Persist viewer type in the map configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
allyoucanmap committed Mar 1, 2023
1 parent 257a7f4 commit 3f7daf8
Show file tree
Hide file tree
Showing 83 changed files with 481 additions and 562 deletions.
21 changes: 0 additions & 21 deletions web/client/actions/__tests__/globeswitcher-test.js

This file was deleted.

8 changes: 1 addition & 7 deletions web/client/actions/__tests__/maptype-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import expect from 'expect';

import { MAP_TYPE_CHANGED, changeMapType, updateLast2dMapType, UPDATE_LAST_2D_MAPTYPE } from '../maptype';
import { MAP_TYPE_CHANGED, changeMapType } from '../maptype';

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

Expand All @@ -18,10 +18,4 @@ describe('Test correctness of the maptype actions', () => {
expect(retVal.type).toBe(MAP_TYPE_CHANGED);
expect(retVal.mapType).toBe('maptype');
});
it('updateLast2dMapType', () => {
const retVal = updateLast2dMapType("leaflet");
expect(retVal).toExist();
expect(retVal.type).toBe(UPDATE_LAST_2D_MAPTYPE);
expect(retVal.mapType).toBe('leaflet');
});
});
35 changes: 0 additions & 35 deletions web/client/actions/globeswitcher.js

This file was deleted.

26 changes: 10 additions & 16 deletions web/client/actions/maptype.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
*/

export const MAP_TYPE_CHANGED = 'MAP_TYPE_CHANGED';
export const UPDATE_LAST_2D_MAPTYPE = "MAP_TYPE:UPDATE_LAST_2D_MAPTYPE";
export const VISUALIZATION_MODE_CHANGED = 'MAP_TYPE:VISUALIZATION_MODE_CHANGED';

/**
* changes the map type
* @deprecated
* @memberof actions.maptype
* @param {string} mapType the mapType.
* @return {action} the action of type `MAP_TYPE_CHANGED` with mapType
* @return {action} the action of type `MAP_TYPE_CHANGED` with mapType
*/
export function changeMapType(mapType) {
return {
Expand All @@ -22,24 +23,17 @@ export function changeMapType(mapType) {
};
}
/**
* Saves the last 2d map
* @memberof actions.globeswitcher
* @param {string} mapType last maptype
* @return {object} action
* ```
* {
* type: MAPTYPE_2D_SELECTED,
* mapType
* }
* ```
* changes the visualization mode
* @memberof actions.maptype
* @param {string} visualizationMode eg: 2D or 3D.
* @return {action} the action of type `VISUALIZATION_MODE_CHANGED` with visualizationMode
*/
export function updateLast2dMapType(mapType) {
export function changeVisualizationMode(visualizationMode) {
return {
type: UPDATE_LAST_2D_MAPTYPE,
mapType
type: VISUALIZATION_MODE_CHANGED,
visualizationMode
};
}

/**
* Actions for map type management.Allow to manage the default map type.
* @name actions.maptype
Expand Down
2 changes: 1 addition & 1 deletion web/client/api.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<script type="text/javascript">
function init() {
MapStore2.create('container', {
originalUrl: "./#viewer/leaflet/0"
originalUrl: "./#viewer/0"
});
}
</script>
Expand Down
3 changes: 2 additions & 1 deletion web/client/api/media/__tests__/geostore-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ describe('GeoStore media api', () => {
canEdit: true,
name: 'Name',
description: 'Description',
type: 'map'
type: 'map',
visualizationMode: '2D'
});
done();
},
Expand Down
5 changes: 3 additions & 2 deletions web/client/api/media/geostore.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Observable } from 'rxjs';
import castArray from 'lodash/castArray';
import { excludeGoogleBackground, extractTileMatrixFromSources } from '../../utils/LayersUtils';
import { convertFromLegacy, normalizeConfig } from '../../utils/ConfigUtils';

import { VisualizationModes } from "../../utils/MapTypeUtils";
import { getResource, getResources } from '../persistence';
import uuid from 'uuid';

Expand Down Expand Up @@ -88,7 +88,8 @@ export const getData = ({ selectedItem }) => {
const tileMatrix = extractTileMatrixFromSources(mapState.map.sources, layer);
return { ...layer, ...tileMatrix };
})
: layers
: layers,
visualizationMode: config?.visualizationMode || VisualizationModes._2D
};

return Observable.of({
Expand Down
2 changes: 1 addition & 1 deletion web/client/components/buttons/GoFullButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class GoFullButton extends React.Component {
glyph: "share",
tooltip: "fullscreen.viewLargerMap",
urlRegex: "^(.*?)embedded.html.*?#\\/(\\d?)",
urlReplaceString: "$1#/viewer/leaflet/$2"
urlReplaceString: "$1#/viewer/$2"
};

render() {
Expand Down
3 changes: 2 additions & 1 deletion web/client/components/contextcreator/ConfigureMapStep.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import React from 'react';
import Message from '../I18N/Message';
import ConfirmDialog from '../misc/ConfirmDialog';
import MapViewer from '../../containers/MapViewer';
import { MapLibraries } from '../../utils/MapTypeUtils';

export default ({
pluginsConfig = {},
plugins = {},
mapType = 'openlayers',
mapType = MapLibraries.OPENLAYERS,
className = 'viewer context-creator-viewer',
showConfirm = false,
confirmMessage = 'contextCreator.configureMap.confirm',
Expand Down
3 changes: 2 additions & 1 deletion web/client/components/contextcreator/ContextCreator.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,8 @@ export default class ContextCreator extends React.Component {
"Undo",
"Redo",
"Expander",
"FilterLayer"
"FilterLayer",
"GlobeViewSwitcher"
],
ignoreViewerPlugins: false,
allAvailablePlugins: [],
Expand Down
3 changes: 2 additions & 1 deletion web/client/components/data/featuregrid/toolbars/Toolbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { getApi } from '../../../../api/userPersistedStorage';
import TSplitButtonComp from "./TSplitButton";
import Spinner from "react-spinkit";
import Select from "react-select";
import { MapLibraries } from '../../../../utils/MapTypeUtils';

const TButton = withHint(TButtonComp);
const TSplitButton = withHint(TSplitButtonComp);
Expand Down Expand Up @@ -172,7 +173,7 @@ const standardButtons = {
id="snap-button"
keyProp="snap-button"
tooltipId={snapping ? "featuregrid.toolbar.disableSnapping" : "featuregrid.toolbar.enableSnapping"}
visible={mode === "EDIT" && (pluginCfg?.snapTool ?? true) && mapType === 'openlayers'}
visible={mode === "EDIT" && (pluginCfg?.snapTool ?? true) && mapType === MapLibraries.OPENLAYERS}
onClick={() => {
events.toggleSnapping && events.toggleSnapping(!snapping);
}}
Expand Down
10 changes: 6 additions & 4 deletions web/client/components/geostory/common/map/Controls.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Message from '../../../I18N/Message';
import Select from "react-select";
import {isNil} from "lodash";
import { applyDefaults } from '../../../../utils/GeoStoryUtils';
import { VisualizationModes } from '../../../../utils/MapTypeUtils';

import SwitchButton from '../../../misc/switch/SwitchButton';
import localizedProps from '../../../misc/enhancers/localizedProps';
Expand All @@ -30,8 +31,9 @@ export const Controls = ({
zoomControl: !isNil(map.zoomControl) ? map.zoomControl : true,
mapInfoControl: !isNil(map.mapInfoControl) ? map.mapInfoControl : false
});
const is3D = map?.visualizationMode === VisualizationModes._3D;
return (<Form className="ms-geostory-map-controls">
<FormGroup>
{!is3D && <FormGroup>
<ControlLabel><Message msgId="geostory.mapEditor.zoom"/></ControlLabel>
<SwitchButton
onChange={() => {
Expand Down Expand Up @@ -60,7 +62,7 @@ export const Controls = ({
onChange={(val) => onChangeMap("mapOptions.zoomPosition", val && val.value ? val.value : "topLeft")}
placeholder="geostory.builder.settings.titlePlaceholder"
/>
</FormGroup>
</FormGroup>}
<FormGroup>
<ControlLabel><Message msgId="geostory.mapEditor.pan"/></ControlLabel>
<SwitchButton
Expand All @@ -75,7 +77,7 @@ export const Controls = ({
checked={options.mapOptions && options.mapOptions.interactions && options.mapOptions.interactions.dragPan}
/>
</FormGroup>
<FormGroup>
{!is3D && <FormGroup>
<ControlLabel><Message msgId="geostory.mapEditor.identify"/></ControlLabel>
<SwitchButton
onChange={() => {
Expand All @@ -93,7 +95,7 @@ export const Controls = ({
selectProps={{
wrapperStyle: { marginTop: 10 }
}}/>}
</FormGroup>
</FormGroup>}
</Form>);
};

Expand Down
5 changes: 3 additions & 2 deletions web/client/components/geostory/common/map/FitBounds.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import PropTypes from 'prop-types';

import { reprojectBbox, reproject } from '../../../../utils/CoordinatesUtils';
import Point from 'ol/geom/Point';
import { MapLibraries } from '../../../../utils/MapTypeUtils';

const zoomTo = {
openlayers: {
[MapLibraries.OPENLAYERS]: {
fit: ({ map, geometry, padding, geometryProjection, fixedZoom, maxZoom, duration }) => {
const view = map.getView();
const mapProjection = view.getProjection().getCode();
Expand All @@ -32,7 +33,7 @@ const zoomTo = {
});
}
},
leaflet: {
[MapLibraries.LEAFLET]: {
fit: ({ map, geometry, padding, geometryProjection, fixedZoom, maxZoom, duration }) => {
const zoom = fixedZoom ? map.getZoom() : maxZoom;
const { top = 0, right = 0, bottom = 0, left = 0 } = padding;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import React, { useState, useEffect } from "react";
import PropTypes from 'prop-types';
import DrawSupport from '../../../map/openlayers/DrawSupport';

import { MapLibraries } from '../../../../utils/MapTypeUtils';
/**
* A draw support interface to use as component instead of plugin
* @prop {object} map map library instance object
Expand Down Expand Up @@ -37,7 +37,7 @@ function LocalDrawSupport({
setStatus(active ? 'drawOrEdit' : 'clean');
}, [active]);

if (mapType !== 'openlayers') {
if (mapType !== MapLibraries.OPENLAYERS) {
return null;
}

Expand Down
4 changes: 3 additions & 1 deletion web/client/components/geostory/media/Map.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import Portal from '../../../components/misc/Portal';
import tooltip from '../../../components/misc/enhancers/tooltip';
import { withResizeDetector } from 'react-resize-detector';

import { MapLibraries } from '../../../utils/MapTypeUtils';

import ButtonRB from '../../misc/Button';
const Button = tooltip(ButtonRB);

Expand All @@ -37,7 +39,7 @@ export default compose(
size,
showCaption,
caption: contentCaption,
mapType = "leaflet", // default for when map MediaViewer is not connected to redux
mapType = MapLibraries.LEAFLET, // default for when map MediaViewer is not connected to redux
onMapTypeLoaded,
layers: geoStoryLayers,
children,
Expand Down
3 changes: 2 additions & 1 deletion web/client/components/import/ShapefileUploadAndStyle.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
import Button from '../misc/Button';
import SelectShape from './SelectShape';
import { Promise } from 'es6-promise';
import { MapLibraries } from '../../utils/MapTypeUtils';

class ShapeFileUploadAndStyle extends React.Component {
static propTypes = {
Expand Down Expand Up @@ -98,7 +99,7 @@ class ShapeFileUploadAndStyle extends React.Component {
}
return null;
}),
mapType: "leaflet",
mapType: MapLibraries.LEAFLET,
stylers: {},
buttonSize: "small",
uploadOptions: {},
Expand Down
3 changes: 2 additions & 1 deletion web/client/components/import/style/StylePanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { toVectorStyle } from '../../../utils/StyleUtils';

import Button from '../../misc/Button';
import { checkFeaturesStyle } from '../../../utils/ImporterUtils';
import { MapLibraries } from '../../../utils/MapTypeUtils';

class StylePanel extends React.Component {
static propTypes = {
Expand Down Expand Up @@ -53,7 +54,7 @@ class StylePanel extends React.Component {
};

static defaultProps = {
mapType: "leaflet",
mapType: MapLibraries.LEAFLET,
buttonSize: "small",
setLayers: () => {},
addLayer: () => {},
Expand Down
12 changes: 8 additions & 4 deletions web/client/components/map/BaseMap.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,14 @@ class BaseMap extends React.Component {
};

renderTools = () => {
return this.props.tools.map((tool) => {
const {impl: Tool, name, ...options} = this.getTool(tool);
return <Tool key={name} {...options} />;
});
return this.props.tools
.filter((tool) => {
return this.props?.plugins?.tools?.[isString(tool) ? tool : tool?.name];
})
.map((tool) => {
const {impl: Tool, name, ...options} = this.getTool(tool);
return <Tool key={name} {...options} />;
});
};

render() {
Expand Down
Loading

0 comments on commit 3f7daf8

Please sign in to comment.