Skip to content

Commit

Permalink
WMS legend is taking in account the current scale of the map (#1669)
Browse files Browse the repository at this point in the history
  • Loading branch information
ndufrane authored and offtherailz committed Apr 3, 2017
1 parent 7ac597b commit 0987dd7
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 12 deletions.
6 changes: 4 additions & 2 deletions web/client/components/TOC/DefaultLayer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ var DefaultLayer = React.createClass({
settingsOptions: React.PropTypes.object,
visibilityCheckType: React.PropTypes.string,
includeDeleteButtonInSettings: React.PropTypes.bool,
groups: React.PropTypes.array
groups: React.PropTypes.array,
currentZoomLvl: React.PropTypes.number,
scales: React.PropTypes.array
},
getDefaultProps() {
return {
Expand Down Expand Up @@ -135,7 +137,7 @@ var DefaultLayer = React.createClass({
}
return (<div position="collapsible" className="collapsible-toc">
<div style={{minHeight: "35px"}}>{tools}</div>
<div><WMSLegend node={this.props.node}/></div>
<div><WMSLegend node={this.props.node} currentZoomLvl={this.props.currentZoomLvl} scales={this.props.scales}/></div>
</div>);
},
renderTools() {
Expand Down
6 changes: 4 additions & 2 deletions web/client/components/TOC/fragments/WMSLegend.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ var Legend = require('./legend/Legend');
var WMSLegend = React.createClass({
propTypes: {
node: React.PropTypes.object,
showOnlyIfVisible: React.PropTypes.bool
showOnlyIfVisible: React.PropTypes.bool,
currentZoomLvl: React.PropTypes.number,
scales: React.PropTypes.array
},
getDefaultProps() {
return {
Expand All @@ -22,7 +24,7 @@ var WMSLegend = React.createClass({
render() {
let node = this.props.node || {};
if (this.canShow(node) && node.type === "wms" && node.group !== "background") {
return <div style={{marginLeft: "15px"}}><Legend layer={node}/></div>;
return <div style={{marginLeft: "15px"}}><Legend layer={node} currentZoomLvl={this.props.currentZoomLvl} scales={this.props.scales}/></div>;
}
return null;
},
Expand Down
8 changes: 5 additions & 3 deletions web/client/components/TOC/fragments/legend/Legend.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ const Legend = React.createClass({
layer: React.PropTypes.object,
legendHeigth: React.PropTypes.number,
legendWidth: React.PropTypes.number,
legendOptions: React.PropTypes.string
legendOptions: React.PropTypes.string,
currentZoomLvl: React.PropTypes.number,
scales: React.PropTypes.array
},
getDefaultProps() {
return {
Expand Down Expand Up @@ -39,10 +41,10 @@ const Legend = React.createClass({
version: layer.version || "1.3.0",
SLD_VERSION: "1.1.0",
LEGEND_OPTIONS: this.props.legendOptions
// SCALE TODO
}, layer.legendParams || {},
layer.params || {},
layer.params && layer.params.SLD_BODY ? {SLD_BODY: layer.params.SLD_BODY} : {});
layer.params && layer.params.SLD_BODY ? {SLD_BODY: layer.params.SLD_BODY} : {},
this.props.scales && this.props.currentZoomLvl ? {SCALE: Math.round(this.props.scales[this.props.currentZoomLvl])} : {});
SecurityUtils.addAuthenticationParameter(url, query);

let legendUrl = urlUtil.format({
Expand Down
22 changes: 17 additions & 5 deletions web/client/plugins/TOC.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ const {changeLayerProperties, changeGroupProperties, toggleNode,
const {getLayerCapabilities} = require('../actions/layerCapabilities');
const {zoomToExtent} = require('../actions/map');
const {groupsSelector} = require('../selectors/layers');
const {mapSelector} = require('../selectors/map');

const LayersUtils = require('../utils/LayersUtils');
const mapUtils = require('../utils/MapUtils');

const Message = require('./locale/Message');
const assign = require('object-assign');
Expand Down Expand Up @@ -127,12 +129,18 @@ const tocSelector = createSelector(
(state) => state.controls && state.controls.toolbar && state.controls.toolbar.active === 'toc',
groupsSelector,
(state) => state.layers && state.layers.settings || {expanded: false, options: {opacity: 1}},
(state) => state.controls && state.controls.queryPanel && state.controls.queryPanel.enabled || false
], (enabled, groups, settings, querypanelEnabled) => ({
(state) => state.controls && state.controls.queryPanel && state.controls.queryPanel.enabled || false,
mapSelector
], (enabled, groups, settings, querypanelEnabled, map) => ({
enabled,
groups,
settings,
querypanelEnabled
querypanelEnabled,
currentZoomLvl: map && map.zoom,
scales: mapUtils.getScales(
map && map.projection || 'EPSG:3857',
map && map.mapOptions && map.mapOptions.view && map.mapOptions.view.DPI || null
)
})
);

Expand Down Expand Up @@ -168,7 +176,9 @@ const LayerTree = React.createClass({
activateQueryTool: React.PropTypes.bool,
activateSettingsTool: React.PropTypes.bool,
visibilityCheckType: React.PropTypes.string,
settingsOptions: React.PropTypes.object
settingsOptions: React.PropTypes.object,
currentZoomLvl: React.PropTypes.number,
scales: React.PropTypes.array
},
getDefaultProps() {
return {
Expand Down Expand Up @@ -230,7 +240,9 @@ const LayerTree = React.createClass({
opacityText={<Message msgId="opacity"/>}
saveText={<Message msgId="save"/>}
closeText={<Message msgId="close"/>}
groups={this.props.groups}/>);
groups={this.props.groups}
currentZoomLvl={this.props.currentZoomLvl}
scales={this.props.scales}/>);
return (
<div>
<TOC onSort={this.props.onSort} filter={this.getNoBackgroundLayers}
Expand Down

0 comments on commit 0987dd7

Please sign in to comment.