Skip to content

Commit

Permalink
Merge pull request #202 from emilhe/1.0.9
Browse files Browse the repository at this point in the history
1.0.9
  • Loading branch information
emilhe authored Sep 25, 2023
2 parents db3d3ab + 1269029 commit a7efdf8
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All notable changes to this project will be documented in this file.

## [1.0.9] - 2023-09-25

### Added

- Add `viewport` property for the `Map` component to enable easy manipulation of the viewport (i.e. zoom/center)

## [1.0.8] - 2023-08-30

### Added
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dash-leaflet",
"version": "1.0.8",
"version": "1.0.9",
"description": "Dash Leaflet is a light wrapper around React-Leaflet. The syntax is similar to other Dash components, with naming conventions following the React-Leaflet API.",
"main": "index.ts",
"repository": {
Expand Down
41 changes: 40 additions & 1 deletion src/ts/components/MapContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {ClickEvents, KeyboardEvents, LoadEvents, MapContainerProps, DashComponen
const trackViewport = (map, props) => {
const bounds = map.getBounds()
props.setProps({
zoom: map.zoom, center: map.center,
zoom: map.getZoom(), center: map.getCenter(),
bounds: [[bounds.getSouth(), bounds.getWest()], [bounds.getNorth(), bounds.getEast()]]
})
}
Expand All @@ -32,6 +32,30 @@ function EventSubscriber(props) {
}
}, [props.invalidateSize])

useEffect(function updateViewport(){
if(props.viewport === undefined){
return;
}
let {transition, center, zoom, options} = props.viewport;
if(!center){
center = map.getCenter();
}
if(!zoom){
zoom = map.getZoom();
}
// TODO: Maybe check for change before invoking transition?
switch (transition) {
case 'flyTo':
map.flyTo(center, zoom, options)
return;
case 'panTo':
map.panTo(center, options)
return;
default:
map.setView(center, zoom, options)
}
}, [props.viewport])

return null
}

Expand All @@ -54,6 +78,21 @@ type Props = Modify<MapContainerProps, {
*/
invalidateSize?: string | number | object;

/**
* This property can be used to manipulate the viewport after initializing the map. [DL]
*/
viewport?: {
center?: number[],
zoom?: number
transition?: "flyTo" | "panTo" | "setView"
options?: {
animate?: boolean,
duration?: number,
easeLinearity?: number,
noMoveStart?: boolean
}
};

/**
* If true (default), zoom, center, and bounds properties are updated on whenReady/moveend. [DL]
*/
Expand Down

0 comments on commit a7efdf8

Please sign in to comment.