Skip to content

Commit

Permalink
Add zoom props in geolocation control (#38)
Browse files Browse the repository at this point in the history
<!--

Thank you for submitting a pull request!

Here's a checklist you might find useful.
[ ] There is an associated issue that is labelled
  'Bug' or 'help wanted' or is in the Community milestone
[ ] Code is up-to-date with the `main` branch
[ ] You've successfully run `npm test` locally
[ ] There are new or updated tests validating the change

-->

Fixes #
- Add `zoom` props in geolocation control. After clicking on the button,
the map sets the specified zoom.
  • Loading branch information
matthew44-mappable authored Oct 25, 2024
1 parent 5e3669e commit 7a75d27
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion example/controls/react/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async function main() {
<MMapDefaultFeaturesLayer />
<MMapControls position="left">
<MMapZoomControl />
<MMapGeolocationControl />
<MMapGeolocationControl zoom={11} />
</MMapControls>
<MMapControls position="bottom">
<MMapZoomControl />
Expand Down
4 changes: 3 additions & 1 deletion example/controls/vanilla/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ async function main() {
[new MMapDefaultSchemeLayer({}), new MMapDefaultFeaturesLayer({})]
);

map.addChild(new MMapControls({position: 'left'}, [new MMapZoomControl({}), new MMapGeolocationControl({})]));
map.addChild(
new MMapControls({position: 'left'}, [new MMapZoomControl({}), new MMapGeolocationControl({zoom: 11})])
);
map.addChild(new MMapControls({position: 'bottom'}, [new MMapZoomControl({})]));
map.addChild(
new MMapControls({position: 'right'}, [
Expand Down
2 changes: 1 addition & 1 deletion example/controls/vue/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async function main() {
<MMapDefaultFeaturesLayer />
<MMapControls position="left">
<MMapZoomControl />
<MMapGeolocationControl />
<MMapGeolocationControl :zoom="11" />
</MMapControls>
<MMapControls position="bottom">
<MMapZoomControl />
Expand Down
6 changes: 5 additions & 1 deletion src/controls/MMapGeolocationControl/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ type MMapGeolocationControlProps = {
easing?: EasingFunctionDescription;
/** Map location animate duration */
duration?: number;
/** Map zoom after geolocate position */
zoom?: number;
};

const defaultProps = Object.freeze({duration: 500});
Expand All @@ -28,7 +30,8 @@ const MMapGeolocationControlVuefyOptions: CustomVuefyOptions<MMapGeolocationCont
onGeolocatePosition: Function as TVue.PropType<MMapGeolocationControlProps['onGeolocatePosition']>,
source: String,
easing: [String, Object, Function] as TVue.PropType<EasingFunctionDescription>,
duration: {type: Number, default: defaultProps.duration}
duration: {type: Number, default: defaultProps.duration},
zoom: {type: Number}
}
};

Expand Down Expand Up @@ -88,6 +91,7 @@ class MMapGeolocationControl extends mappable.MMapGroupEntity<MMapGeolocationCon
map?.update({
location: {
center: this._position,
zoom: this._props.zoom,
duration: this._props.duration,
easing: this._props.easing
}
Expand Down
2 changes: 1 addition & 1 deletion src/controls/MMapGeolocationControl/self.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7a75d27

Please sign in to comment.