-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #358 from systemli/add-fit-bounds-functionality
🚸 Set map view to defined point(s)
- Loading branch information
Showing
6 changed files
with
35 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { LeafletEvent } from 'leaflet' | ||
|
||
export const leafletOnDataAddFitToBounds = (event: LeafletEvent) => { | ||
const leafletLayer = event.target | ||
const features = Object.values(leafletLayer._layers) | ||
|
||
if ( | ||
features.length === 1 && | ||
// type is currently not defined | ||
// @ts-ignore | ||
features[0].feature.geometry.type === 'Point' | ||
) { | ||
// @ts-ignore | ||
const coords = features[0].feature.geometry.coordinates | ||
leafletLayer._map.setView([coords[1], coords[0]], 13) | ||
} else if (features.length > 1) { | ||
leafletLayer._map.fitBounds(leafletLayer.getBounds()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.