-
Notifications
You must be signed in to change notification settings - Fork 377
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2031 from TerriaJS/rd_wps_linestring
Geojson linestring in known WPS input parameters
- Loading branch information
Showing
7 changed files
with
251 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
'use strict'; | ||
|
||
/*global require*/ | ||
var defineProperties = require('terriajs-cesium/Source/Core/defineProperties'); | ||
var defined = require('terriajs-cesium/Source/Core/defined'); | ||
var FunctionParameter = require('./FunctionParameter'); | ||
var inherit = require('../Core/inherit'); | ||
|
||
/** | ||
* A parameter that specifies a line on the globe. | ||
* | ||
* @alias LineParameter | ||
* @constructor | ||
* @extends FunctionParameter | ||
* | ||
* @param {Object} options Object with the following properties: | ||
* @param {Terria} options.terria The Terria instance. | ||
* @param {String} options.id The unique ID of this parameter. | ||
* @param {String} [options.name] The name of this parameter. If not specified, the ID is used as the name. | ||
* @param {String} [options.description] The description of the parameter. | ||
* @param {Boolean} [options.defaultValue] The default value. | ||
*/ | ||
var LineParameter = function(options) { | ||
FunctionParameter.call(this, options); | ||
|
||
this.defaultValue = options.defaultValue; | ||
}; | ||
|
||
inherit(FunctionParameter, LineParameter); | ||
|
||
defineProperties(LineParameter.prototype, { | ||
/** | ||
* Gets the type of this parameter. | ||
* @memberof LineParameter.prototype | ||
* @type {String} | ||
*/ | ||
type: { | ||
get: function() { | ||
return 'line'; | ||
} | ||
}, | ||
}); | ||
|
||
LineParameter.prototype.formatValueAsString = function(value) { | ||
if (!defined(value)) { | ||
return '-'; | ||
} | ||
|
||
let line = ''; | ||
for (let i = 0; i < value.length; i++) { | ||
line += '[' + value[i][0].toFixed(3) + ', ' + value[i][1].toFixed(3) + ']'; | ||
if (i !== value.length - 1) { | ||
line += ', '; | ||
} | ||
} | ||
if (line.length > 0) { | ||
return line; | ||
} else { | ||
return ''; | ||
} | ||
}; | ||
|
||
module.exports = LineParameter; |
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
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,107 @@ | ||
import React from 'react'; | ||
|
||
import CesiumMath from 'terriajs-cesium/Source/Core/Math'; | ||
import defined from 'terriajs-cesium/Source/Core/defined'; | ||
import Ellipsoid from 'terriajs-cesium/Source/Core/Ellipsoid'; | ||
|
||
import UserDrawing from '../../Models/UserDrawing'; | ||
import ObserveModelMixin from '../ObserveModelMixin'; | ||
import Styles from './parameter-editors.scss'; | ||
|
||
const LineParameterEditor = React.createClass({ | ||
mixins: [ObserveModelMixin], | ||
|
||
propTypes: { | ||
previewed: React.PropTypes.object, | ||
parameter: React.PropTypes.object, | ||
viewState: React.PropTypes.object | ||
}, | ||
|
||
getInitialState() { | ||
return { | ||
value: this.getValue(), | ||
userDrawing: new UserDrawing( | ||
{ | ||
terria: this.props.previewed.terria, | ||
onPointClicked: this.onPointClicked, | ||
onCleanUp: this.onCleanUp, | ||
allowPolygon: false | ||
}) | ||
}; | ||
}, | ||
|
||
onTextChange(e) { | ||
this.setValue(e.target.value); | ||
this.setState({ | ||
value: e.target.value | ||
}); | ||
}, | ||
|
||
getValue() { | ||
const pointsLongLats = this.props.previewed.parameterValues[this.props.parameter.id]; | ||
if (!defined(pointsLongLats) || pointsLongLats.length < 1) { | ||
return ''; | ||
} | ||
|
||
let line = ''; | ||
for (let i = 0; i < pointsLongLats.length; i++) { | ||
line += '[' + pointsLongLats[i][0].toFixed(3) + ', ' + pointsLongLats[i][1].toFixed(3) + ']'; | ||
if (i !== pointsLongLats.length - 1) { | ||
line += ', '; | ||
} | ||
} | ||
if (line.length > 0) { | ||
return line; | ||
} else { | ||
return ''; | ||
} | ||
}, | ||
|
||
setValue(value) { | ||
this.setState({ | ||
value: value | ||
}); | ||
}, | ||
|
||
onCleanUp() { | ||
this.props.viewState.openAddData(); | ||
}, | ||
|
||
onPointClicked(pointEntities) { | ||
const pointEnts = pointEntities.entities.values; | ||
const pointsLongLats = []; | ||
for (let i=0; i < pointEnts.length; i++) { | ||
const currentPoint = pointEnts[i]; | ||
const currentPointPos = currentPoint.position.getValue(this.props.previewed.terria.clock.currentTime); | ||
const cartographic = Ellipsoid.WGS84.cartesianToCartographic(currentPointPos); | ||
const points = []; | ||
points.push(CesiumMath.toDegrees(cartographic.longitude)); | ||
points.push(CesiumMath.toDegrees(cartographic.latitude)); | ||
pointsLongLats.push(points); | ||
} | ||
this.props.previewed.setParameterValue(this.props.parameter.id, pointsLongLats); | ||
}, | ||
|
||
selectLineOnMap() { | ||
this.state.userDrawing.enterDrawMode(); | ||
this.props.viewState.explorerPanelIsVisible = false; | ||
}, | ||
|
||
render() { | ||
return ( | ||
<div> | ||
<input className={Styles.parameterEditor} | ||
type="text" | ||
onChange={this.onTextChange} | ||
value={this.state.value}/> | ||
<button type="button" | ||
onClick={this.selectLineOnMap} | ||
className={Styles.btnSelector}> | ||
Click to draw line | ||
</button> | ||
</div> | ||
); | ||
} | ||
}); | ||
|
||
module.exports = LineParameterEditor; |
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