Skip to content

Commit 6b117b7

Browse files
committed
feat(Routing): allow choosing inteval units
1 parent d8152cc commit 6b117b7

1 file changed

Lines changed: 33 additions & 2 deletions

File tree

plugins/Routing.jsx

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class Routing extends React.Component {
6969
showPinLabels: PropTypes.bool,
7070
task: PropTypes.object,
7171
theme: PropTypes.object,
72+
units: PropTypes.object,
7273
/** Automatically zoom to the extent of the route */
7374
zoomAuto: PropTypes.bool,
7475
zoomToExtent: PropTypes.func
@@ -85,6 +86,16 @@ class Routing extends React.Component {
8586
side: 'left'
8687
},
8788
showPinLabels: true,
89+
units: {
90+
time: {
91+
min: 1,
92+
s: 60,
93+
},
94+
distance: {
95+
km: 1,
96+
m: 1000,
97+
}
98+
},
8899
zoomAuto: true
89100
};
90101
state = {
@@ -137,6 +148,10 @@ class Routing extends React.Component {
137148
{text: '', pos: null, crs: null}
138149
],
139150
mode: 'time',
151+
units: {
152+
time: 'min',
153+
distance: 'km'
154+
},
140155
intervals: '5, 10',
141156
result: null
142157
},
@@ -496,7 +511,22 @@ class Routing extends React.Component {
496511
<td>
497512
<input className={isoConfig.intervals && !intervalValid ? "routing-input-invalid" : ""} onChange={(ev) => this.updateIsoConfig({intervals: ev.target.value})} placeholder="5, 10, 15" type="text" value={isoConfig.intervals} />
498513
</td>
499-
<td>{isoConfig.mode === "time" ? "min" : "km"}</td>
514+
<td>
515+
<select onChange={ev => {
516+
this.setState((state) => ({
517+
isoConfig: {
518+
...state.isoConfig,
519+
units: {
520+
...state.isoConfig.units,
521+
[state.isoConfig.mode]: ev.target.value
522+
}
523+
}
524+
}));
525+
this.recomputeIfNeeded();
526+
}} value={isoConfig.units[isoConfig.mode]}>
527+
{Object.keys(this.props.units[isoConfig.mode]).map(unit => <option key={unit} value={unit}>{unit}</option>)}
528+
</select>
529+
</td>
500530
</tr>
501531
</tbody>
502532
</table>
@@ -789,9 +819,10 @@ class Routing extends React.Component {
789819
});
790820
this.props.removeLayer("routinggeometries");
791821
this.updateIsoConfig({busy: true, result: null}, false);
822+
const unitsFactor = this.props.units[this.state.isoConfig.mode][this.state.isoConfig.units[this.state.isoConfig.mode]];
792823
const contourOptions = {
793824
mode: this.state.isoConfig.mode,
794-
intervals: this.state.isoConfig.intervals.split(",").map(entry => parseInt(entry.trim(), 10)).sort()
825+
intervals: this.state.isoConfig.intervals.split(",").map(entry => parseInt(entry.trim(), 10) / unitsFactor).sort()
795826
};
796827
RoutingInterface.computeIsochrone(this.state.mode, locations, contourOptions, this.state.settings[this.state.mode], (success, result) => {
797828
if (success) {

0 commit comments

Comments
 (0)