forked from geosolutions-it/MapStore2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix geosolutions-it#2842. Implemented legend widget
- Loading branch information
1 parent
1e856ff
commit 9e98c4e
Showing
20 changed files
with
430 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
web/client/components/widgets/builder/wizard/LegendWizard.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright 2017, 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. | ||
*/ | ||
const React = require('react'); | ||
const {compose} = require('recompose'); | ||
const emptyState = require('../../../misc/enhancers/emptyState'); | ||
|
||
|
||
const {wizardHandlers} = require('../../../misc/wizard/enhancers'); | ||
const {Row, Col} = require('react-bootstrap'); | ||
const legendWidget = require('../../enhancers/legendWidget'); | ||
|
||
const WidgetOptions = require('./common/WidgetOptions'); | ||
const Wizard = wizardHandlers(require('../../../misc/wizard/WizardContainer')); | ||
const StepHeader = require('../../../misc/wizard/StepHeader'); | ||
const Message = require('../../../I18N/Message'); | ||
const emptyLegendState = require('../../enhancers/emptyLegendState'); | ||
|
||
const enhancePreview = compose( | ||
legendWidget, | ||
emptyState( | ||
({valid}) => !valid, | ||
{ | ||
title: <Message msgId="widgets.builder.errors.noMapAvailableForLegend" />, | ||
description: <Message msgId="widgets.builder.errors.noMapAvailableForLegendDescription" /> | ||
} | ||
), | ||
emptyLegendState(false) | ||
); | ||
const LegendPreview = enhancePreview(require('../../widget/LegendView')); | ||
module.exports = ({ | ||
onChange = () => {}, onFinish = () => {}, setPage= () => {}, | ||
step=0, | ||
dependencies, | ||
valid, | ||
data = {} | ||
} = {}) => ( | ||
<Wizard | ||
step={step} | ||
setPage={setPage} | ||
onFinish={onFinish} | ||
hideButtons> | ||
<Row> | ||
<StepHeader title={<Message msgId={`widgets.builder.wizard.preview`} />} /> | ||
<Col xs={12}> | ||
<div style={{ marginBottom: "30px" }}> | ||
<LegendPreview | ||
valid={valid} | ||
dependencies={dependencies} | ||
dependenciesMap={data.dependenciesMap} | ||
key="widget-options" | ||
onChange={onChange} | ||
/> | ||
</div> | ||
</Col> | ||
</Row> | ||
<WidgetOptions | ||
key="widget-options" | ||
onChange={onChange} | ||
/> | ||
</Wizard> | ||
); |
55 changes: 55 additions & 0 deletions
55
web/client/components/widgets/builder/wizard/legend/Toolbar.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright 2017, 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. | ||
*/ | ||
const React = require('react'); | ||
|
||
|
||
const Toolbar = require('../../../../misc/toolbar/Toolbar'); | ||
const getBackTooltipId = step => { | ||
switch (step) { | ||
case 1: | ||
return "widgets.builder.wizard.backToPreview"; | ||
case 2: | ||
return "widgets.builder.wizard.backToChartOptions"; | ||
default: | ||
return "back"; | ||
|
||
} | ||
}; | ||
const getNextTooltipId = (step, valid) => !valid | ||
? undefined | ||
: "widgets.builder.wizard.configureWidgetOptions"; | ||
|
||
const isValidStep1 = ({mapSync}) => mapSync; | ||
const getSaveTooltipId = (step, {id} = {}) => { | ||
if (id) { | ||
return "widgets.builder.wizard.updateWidget"; | ||
} | ||
return "widgets.builder.wizard.addToTheMap"; | ||
}; | ||
|
||
module.exports = ({ step = 0, editorData = {}, valid, stepButtons = [], onFinish = () => { }, setPage = () => { }} = {}) => (<Toolbar btnDefaultProps={{ | ||
bsStyle: "primary", | ||
bsSize: "sm" | ||
}} | ||
buttons={[{ | ||
onClick: () => setPage(Math.max(0, step - 1)), | ||
visible: step > 0, | ||
glyph: "arrow-left", | ||
tooltipId: getBackTooltipId(step) | ||
}, ...stepButtons, { | ||
onClick: () => setPage(Math.min(step + 1, 1)), | ||
visible: step === 0, | ||
disabled: step === 0 && !isValidStep1(editorData) || !valid, | ||
glyph: "arrow-right", | ||
tooltipId: getNextTooltipId(step, valid) | ||
}, { | ||
onClick: () => onFinish(Math.min(step + 1, 1)), | ||
visible: step === 1, | ||
glyph: "floppy-disk", | ||
tooltipId: getSaveTooltipId(step, editorData) | ||
}]} />); |
18 changes: 18 additions & 0 deletions
18
web/client/components/widgets/enhancers/emptyLegendState.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright 2018, 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. | ||
*/ | ||
const React = require('react'); | ||
const emptyState = require('../../misc/enhancers/emptyState'); | ||
const Message = require('../../I18N/Message'); | ||
|
||
module.exports = (asTooltip = true) => emptyState( | ||
({ layers = [] }) => layers.length === 0, | ||
{ | ||
[asTooltip ? "tooltip" : "title"]: <Message msgId="widgets.errors.noLegend" />, | ||
description: !asTooltip && <Message msgId="widgets.errors.noLegendDescription" /> | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright 2018, 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. | ||
*/ | ||
const {compose, withProps} = require('recompose'); | ||
const dependenciesToWidget = require('./dependenciesToWidget'); | ||
const {get} = require('lodash'); | ||
const {getScales} = require('../../../utils/MapUtils'); | ||
|
||
module.exports = compose( | ||
dependenciesToWidget, | ||
withProps(({ dependencies = {} }) => ({ | ||
layers: dependencies.layers || [], | ||
scales: getScales( | ||
// TODO: this is a fallback that checks the viewport if projection is not defined. We should use only projection | ||
dependencies.projection || dependencies.viewport && dependencies.viewport.crs || 'EPSG:3857', | ||
get( dependencies, "mapOptions.view.DPI") | ||
), | ||
currentZoomLvl: dependencies.zoom | ||
})), | ||
// filter backgrounds | ||
withProps( | ||
({ layers = [] }) => ({ layers: layers.filter((l = {}) => l.group !== "background" && l.visibility !== false && l.type !== "vector")}) | ||
), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright 2018, 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. | ||
*/ | ||
const React = require('react'); | ||
const { isNil } = require('lodash'); | ||
const SideGrid = require('../../misc/cardgrids/SideGrid'); | ||
const { Glyphicon, Grid, Row, Col} = require('react-bootstrap'); | ||
const Slider = require('../../misc/Slider'); | ||
const WMSLegend = require('../../TOC/fragments/WMSLegend'); | ||
|
||
module.exports = ({ | ||
layers = [], | ||
onChange = () => {}, | ||
legendProps = {}, | ||
currentZoomLvl, | ||
disableOpacitySlider = true, | ||
disableVisibility = true, | ||
scales | ||
}) => <SideGrid | ||
className="compact-legend-grid" | ||
size="sm" | ||
items={layers.map(layer => ({ | ||
title: layer.title, | ||
preview: disableVisibility | ||
? null | ||
: <Glyphicon className="text-primary" | ||
glyph={layer.visibility ? 'eye-open' : 'eye-close'} | ||
/>, // TODO: manage onClick | ||
style: { | ||
opacity: layer.visibility ? 1 : 0.4 | ||
}, | ||
body: !layer.visibility ? null | ||
: ( | ||
<div> | ||
<Grid fluid> | ||
<Row> | ||
<Col xs={12} className="ms-legend-container"> | ||
<WMSLegend | ||
node={{ ...layer }} | ||
currentZoomLvl={currentZoomLvl} | ||
scales={scales} | ||
{...legendProps} /> | ||
</Col> | ||
</Row> | ||
</Grid> | ||
{!disableOpacitySlider && <div className="mapstore-slider" onClick={(e) => { e.stopPropagation(); }}> | ||
<Slider | ||
disabled={!layer.visibility} | ||
start={[isNil(layer.opacity) ? 100 : Math.round(layer.opacity * 100)]} | ||
range={{ min: 0, max: 100 }} | ||
onChange={(value) => onChange(layer.id, 'layers', { opacity: parseFloat((value[0] / 100).toFixed(2)) })} /> | ||
</div>} | ||
</div> | ||
) | ||
}) | ||
)} />; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright 2017, 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. | ||
*/ | ||
const React = require('react'); | ||
const WidgetContainer = require('./WidgetContainer'); | ||
const Message = require('../../I18N/Message'); | ||
const emptyLegendState = require('../enhancers/emptyLegendState'); | ||
const InfoPopover = require('./InfoPopover'); | ||
|
||
const LegendView = emptyLegendState()(require('./LegendView')); | ||
const renderHeaderLeftTopItem = ({ title, description } = {}) => { | ||
return description ? <InfoPopover placement="top" title={title} text={description} /> : null; | ||
}; | ||
const { | ||
Glyphicon, | ||
ButtonToolbar, | ||
DropdownButton, | ||
MenuItem | ||
} = require('react-bootstrap'); | ||
|
||
module.exports = ({ | ||
onEdit = () => {}, | ||
toggleDeleteConfirm = () => {}, | ||
id, title, | ||
headerStyle, | ||
confirmDelete= false, | ||
onDelete=() => {}, | ||
loading, | ||
description, | ||
...props | ||
} = {}) => | ||
(<WidgetContainer id={`widget-text-${id}`} title={title} confirmDelete={confirmDelete} onDelete={onDelete} toggleDeleteConfirm={toggleDeleteConfirm} headerStyle={headerStyle} | ||
topLeftItems={renderHeaderLeftTopItem({ loading, title, description })} | ||
|
||
topRightItems={<ButtonToolbar> | ||
<DropdownButton pullRight bsStyle="default" className="widget-menu" title={<Glyphicon glyph="option-vertical" />} noCaret id="dropdown-no-caret"> | ||
<MenuItem onClick={() => onEdit()} eventKey="3"><Glyphicon glyph="pencil"/> <Message msgId="widgets.widget.menu.edit" /></MenuItem> | ||
<MenuItem onClick={() => toggleDeleteConfirm(true)} eventKey="2"><Glyphicon glyph="trash"/> <Message msgId="widgets.widget.menu.delete" /></MenuItem> | ||
</DropdownButton> | ||
</ButtonToolbar>} | ||
> | ||
<LegendView {...props} /> | ||
</WidgetContainer> | ||
|
||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.