Skip to content

Commit

Permalink
Merge pull request #829 from theduckylittle/gm-828/zoom-buttons-broken
Browse files Browse the repository at this point in the history
Fix bug resolving resolution to zoom in map controls
  • Loading branch information
klassenjs committed Apr 25, 2023
2 parents 714d6b9 + 621e365 commit 6e2366d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/gm3/components/map/context-controls.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useEffect, useCallback } from "react";
import View from "ol/View";

import { EDIT_LAYER_NAME } from "../../defaults";
import { featureToJson } from "../../util";
Expand Down Expand Up @@ -190,6 +191,7 @@ const ContextControls = ({
setEditPath,
setEditTools,
zoom,
resolution,
}) => {
let controls = false;
// do not bother rendering anything if the interaction is null
Expand Down Expand Up @@ -223,20 +225,27 @@ const ContextControls = ({
);
}

const getZoom = () => {
if (zoom) {
return zoom;
}
return new View().getZoomForResolution(resolution);
};

return (
<React.Fragment>
<MapButton
label="zoom-in"
icon="icon zoom-in"
index={0}
onClick={() => setZoom(zoom + 1)}
onClick={() => setZoom(getZoom() + 1)}
/>

<MapButton
label="zoom-out"
icon="icon zoom-out"
index={0}
onClick={() => setZoom(zoom - 1)}
onClick={() => setZoom(getZoom() - 1)}
/>

<span style={{ display: "inline-block", width: 16 }}></span>
Expand Down
1 change: 1 addition & 0 deletions src/gm3/components/map/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,7 @@ class Map extends React.Component {
interactionType={this.props.mapView.interactionType}
activeSource={this.props.mapView.activeSource}
setZoom={this.props.setZoom}
resolution={this.props.mapView.resolution}
zoom={this.props.mapView.zoom}
showZoom={config.showZoom === true}
setEditPath={this.props.setEditPath}
Expand Down

0 comments on commit 6e2366d

Please sign in to comment.