-
Notifications
You must be signed in to change notification settings - Fork 1
Define the new optional properties "centerToReset" and "centerToZoom" #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { createControlComponent } from "@react-leaflet/core"; | ||
import { Control, DomUtil, DomEvent, Util } from "leaflet"; | ||
|
||
import type { Map, ControlOptions, LatLng } from "leaflet"; | ||
import type { Map, ControlOptions, LatLng, LatLngExpression } from "leaflet"; | ||
|
||
export type ResetViewControlOptions = { | ||
/** | ||
|
@@ -14,15 +14,22 @@ export type ResetViewControlOptions = { | |
* It renders a box by default. | ||
*/ | ||
icon?: string; | ||
|
||
/** | ||
* "zoomToReset" and "centerToReset" properties are useful when the map is mounted in a particular position | ||
* and you need this button to reset the view to another position. | ||
*/ | ||
zoomToReset?: number; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think of naming these There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At the start of this contribution, I also thought of these names. <MapContainer zoom={defaultMapZoom} center={defaultMapCenter}>
<ResetViewControl
defaultZoom={defaultZoom}
defaultCenter={defaultCenter}
/>
</MapContainer> Maybe the couple There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any though about this @valentinogagliardi? |
||
centerToReset?: LatLngExpression; | ||
} & ControlOptions; | ||
|
||
const _getControl = Control.extend({ | ||
options: { position: "topleft", title: "Reset map view", icon: "\u2610" }, | ||
options: { position: "topleft", title: "Reset map view", icon: "\u2610", zoomToReset: null, centerToReset: null }, | ||
|
||
onAdd: function (map: Map) { | ||
Util.setOptions(this, { | ||
zoom: map.getZoom(), | ||
center: map.getCenter(), | ||
zoom: this.options.zoomToReset ?? map.getZoom(), | ||
center: this.options.centerToReset ?? map.getCenter(), | ||
}); | ||
|
||
const { title, icon } = this.options; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you document these with a comment per property, like
title
andicon
?