-
Notifications
You must be signed in to change notification settings - Fork 409
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mapstore2 Elevation Slider tool (#1697)
* Issue #1560. Fix Syntax error in themeEntries with node v6.10.0 and npm 3.10.10 on windows10 64bit * Issue #1693 Elevation Slider tool Fix requested changes to Elev Slider
- Loading branch information
Showing
15 changed files
with
462 additions
and
5 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
117 changes: 117 additions & 0 deletions
117
web/client/components/TOC/fragments/settings/Elevation.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,117 @@ | ||
/** | ||
* Copyright 2016, 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 Slider = require('react-nouislider'); | ||
const ElevationChart = require('./ElevationChart'); | ||
require('react-widgets/lib/less/react-widgets.less'); | ||
require("./css/elevation.css"); | ||
|
||
module.exports = React.createClass({ | ||
propTypes: { | ||
elevationText: React.PropTypes.node, | ||
element: React.PropTypes.object, | ||
elevations: React.PropTypes.object, | ||
onChange: React.PropTypes.func, | ||
appState: React.PropTypes.object, | ||
chartStyle: React.PropTypes.object | ||
}, | ||
getDefaultProps() { | ||
return { | ||
onChange: () => {} | ||
}; | ||
}, | ||
shouldComponentUpdate(nextProps) { | ||
if (nextProps.appState && nextProps.appState.initialState && nextProps.appState.initialState.params && nextProps.element.params) { | ||
if (nextProps.appState.initialState.params[nextProps.elevations.name] !== | ||
nextProps.element.params[nextProps.elevations.name]) { | ||
return false; | ||
} | ||
return false; | ||
} | ||
return true; | ||
}, | ||
renderElevationsChart(elevations) { | ||
if (this.props.elevations.showChart) { | ||
return ( | ||
<ElevationChart | ||
onChange={this.props.onChange} | ||
elevations={elevations} | ||
chartStyle={this.props.chartStyle}/> | ||
); | ||
} | ||
}, | ||
renderElevationsSlider(elevations) { | ||
const values = elevations.values; | ||
const min = 0; | ||
const max = values.length - 1; | ||
const dif = max - min; | ||
const firstVal = parseFloat(values[0]); | ||
const lastVal = parseFloat(values[values.length - 1]); | ||
const start = this.props.element && | ||
this.props.element.params && | ||
this.props.element.params[this.props.elevations.name][0] || values[0]; | ||
const elevationName = {}; | ||
return ( | ||
<div id="mapstore-elevation"> | ||
<Slider | ||
snap= {true} | ||
start={[parseFloat((start))] || [0.0]} | ||
range= {this.calculateRange(values, min, max, dif, firstVal, lastVal)} | ||
behaviour= "tap" | ||
pips= {{ | ||
mode: 'range', | ||
stepped: true, | ||
density: 10, | ||
format: { | ||
to: function( value ) { | ||
return parseFloat(value).toFixed(1); | ||
} | ||
} | ||
}} | ||
tooltips={!this.props.elevations.showChart} | ||
onChange={(value) => { | ||
elevationName[this.props.elevations.name] = value; | ||
this.props.onChange("params", Object.assign({}, elevationName)); | ||
}}/> | ||
</div> | ||
); | ||
}, | ||
render() { | ||
const elevations = this.props.elevations; | ||
return ( | ||
<div> | ||
<label | ||
id="mapstore-elevation-label" | ||
key="elevation-label" | ||
className="control-label" | ||
style={this.props.elevations.showChart ? {marginBottom: "10px"} : {marginBottom: "90px"}}> | ||
{this.props.elevationText}: ({this.props.elevations.units}) | ||
</label> | ||
{this.renderElevationsChart(elevations)} | ||
<div> | ||
<div key="elevation"> | ||
{this.renderElevationsSlider(elevations)} | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}, | ||
calculateRange(values, min, max, dif, firstVal, lastVal) { | ||
let arr = []; | ||
let percText = ""; | ||
let range = {min: firstVal, max: lastVal}; | ||
values.forEach(function(currentValue, i) { | ||
arr[i] = ((i - min) / dif) * 100; | ||
percText = arr[i] + "%"; | ||
range[percText] = parseFloat(currentValue); | ||
}); | ||
return range; | ||
} | ||
}); |
74 changes: 74 additions & 0 deletions
74
web/client/components/TOC/fragments/settings/ElevationChart.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,74 @@ | ||
/** | ||
* Copyright 2016, 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 {LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip} = require('recharts'); | ||
const ElevationChartTooltip = require('./ElevationChartTooltip'); | ||
|
||
module.exports = React.createClass({ | ||
propTypes: { | ||
elevations: React.PropTypes.object, | ||
chartStyle: React.PropTypes.object, | ||
onChange: React.PropTypes.func | ||
}, | ||
getDefaultProps() { | ||
return { | ||
elevations: {}, | ||
onChange: () => {}, | ||
chartStyle: { | ||
margin: { | ||
top: 5, | ||
right: 20, | ||
left: 18, | ||
bottom: 45 | ||
}, | ||
width: 600, | ||
height: 200 | ||
} | ||
}; | ||
}, | ||
renderLineChart() { | ||
return ( | ||
<LineChart margin={this.props.chartStyle.margin} width={this.props.chartStyle.width} height={this.props.chartStyle.height} data={this.formatData(this.props.elevations.values)}> | ||
<XAxis | ||
hide={true} | ||
dataKey="name"/> | ||
<YAxis | ||
hide={true}/> | ||
<Tooltip content={<ElevationChartTooltip/>}/> | ||
<CartesianGrid | ||
strokeDasharray="3 3" | ||
horizontal={false}/> | ||
<Line | ||
type="monotone" | ||
dataKey="value" | ||
stroke="#82ca9d" | ||
activeDot={{r: 8}}/> | ||
</LineChart> | ||
); | ||
}, | ||
render() { | ||
return ( | ||
<div> | ||
{this.renderLineChart()} | ||
</div> | ||
); | ||
}, | ||
formatData(values) { | ||
let data = []; | ||
values.map(function(o) { | ||
data.push( | ||
{ | ||
"name": this.props.elevations.name, | ||
"value": parseFloat(this.props.elevations.positive ? o : -o) | ||
} | ||
); | ||
}, this); | ||
return data; | ||
} | ||
}); |
33 changes: 33 additions & 0 deletions
33
web/client/components/TOC/fragments/settings/ElevationChartTooltip.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,33 @@ | ||
/** | ||
* Copyright 2016, 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 CustomTooltip = React.createClass({ | ||
propTypes: { | ||
type: React.PropTypes.string, | ||
payload: React.PropTypes.array, | ||
label: React.PropTypes.string, | ||
active: React.PropTypes.bool | ||
}, | ||
render() { | ||
const {active} = this.props; | ||
|
||
if (active) { | ||
const { payload} = this.props; | ||
return ( | ||
<div className="custom-tooltip"> | ||
<p className="label">{Math.abs(payload[0].value)}</p> | ||
</div> | ||
); | ||
} | ||
return null; | ||
} | ||
}); | ||
|
||
module.exports = CustomTooltip; |
63 changes: 63 additions & 0 deletions
63
web/client/components/TOC/fragments/settings/__tests__/Elevation-test.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,63 @@ | ||
/** | ||
* 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 React = require('react'); | ||
var ReactDOM = require('react-dom'); | ||
var ReactTestUtils = require('react-addons-test-utils'); | ||
var Elevation = require('../Elevation'); | ||
|
||
var expect = require('expect'); | ||
|
||
describe('test Layer Properties Elevation component', () => { | ||
beforeEach((done) => { | ||
document.body.innerHTML = '<div id="container"></div>'; | ||
setTimeout(done); | ||
}); | ||
|
||
afterEach((done) => { | ||
ReactDOM.unmountComponentAtNode(document.getElementById("container")); | ||
document.body.innerHTML = ''; | ||
setTimeout(done); | ||
}); | ||
|
||
it('tests component rendering', () => { | ||
const l = { | ||
name: 'testworkspace:testlayer', | ||
title: 'Layer', | ||
visibility: true, | ||
storeIndex: 9, | ||
type: 'shapefile', | ||
url: 'base/web/client/test-resources/geoserver/wms', | ||
params: { | ||
"ELEVATION": ["1.5"] | ||
}, | ||
elevations: { | ||
name: "ELEVATION", | ||
units: "Meters", | ||
positive: false, | ||
showChart: true, | ||
values: ["1.5", "5.0", "10.0", "15.0", "20.0", "25.0", "30.0"] | ||
} | ||
}; | ||
const settings = { | ||
options: {opacity: 1} | ||
}; | ||
const comp = ReactDOM.render( | ||
<Elevation | ||
elevationText={"Text"} | ||
element={l} | ||
elevations={l.elevations} | ||
settings={settings} />, | ||
document.getElementById("container") | ||
); | ||
|
||
expect(comp).toExist(); | ||
const div = ReactTestUtils.scryRenderedDOMComponentsWithTag( comp, "div" ); | ||
expect(div).toExist(); | ||
}); | ||
}); |
Oops, something went wrong.