Skip to content

Commit

Permalink
#9363 Wrong scale value reported using the scroll wheel (#9401) (#9440)
Browse files Browse the repository at this point in the history
  • Loading branch information
allyoucanmap authored Sep 14, 2023
1 parent b769c90 commit f22fecb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
11 changes: 6 additions & 5 deletions web/client/components/mapcontrols/scale/ScaleBox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class ScaleBox extends React.Component {
}

onComboChange = (event) => {
var selectedZoomLvl = parseInt(event.nativeEvent.target.value, 10);
let selectedZoomLvl = parseInt(event.nativeEvent.target.value, 10);
this.props.onChange(selectedZoomLvl, this.props.scales[selectedZoomLvl]);
};

Expand All @@ -58,22 +58,23 @@ class ScaleBox extends React.Component {
};

render() {
var control = null;
let control = null;
const currentZoomLvl = Math.round(this.props.currentZoomLvl);
if (this.props.readOnly) {
control =
<label>{this.props.template(this.props.scales[this.props.currentZoomLvl], this.props.currentZoomLvl)}</label>
<label>{this.props.template(this.props.scales[currentZoomLvl], currentZoomLvl)}</label>
;
} else if (this.props.useRawInput) {
control =
(<select label={this.props.label} onChange={this.onComboChange} bsSize="small" value={this.props.currentZoomLvl || ""}>
(<select label={this.props.label} onChange={this.onComboChange} bsSize="small" value={currentZoomLvl || ""}>
{this.getOptions()}
</select>)
;
} else {
control =
(<Form inline><FormGroup bsSize="small">
<ControlLabel>{this.props.label}</ControlLabel>
<FormControl componentClass="select" onChange={this.onComboChange} value={this.props.currentZoomLvl || ""}>
<FormControl componentClass="select" onChange={this.onComboChange} value={currentZoomLvl || ""}>
{this.getOptions()}
</FormControl>
</FormGroup></Form>)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,10 @@ describe('ScaleBox', () => {
expect(domLabel).toExist();
expect(domLabel.innerHTML).toContain("Scale:");
});

it('should support not rounded zoom levels', () => {
TestUtils.act(() => { ReactDOM.render(<ScaleBox currentZoomLvl={5.1}/>, document.getElementById('container')); });
const select = document.querySelector('select');
expect(select.value).toBe('5');
});
});

0 comments on commit f22fecb

Please sign in to comment.