Skip to content

Commit

Permalink
Add getLocationBounds callback #218 (#219)
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanheywood authored and domoritz committed Nov 8, 2018
1 parent 1e2aa25 commit 4115f3d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -100,6 +100,7 @@ Possible options are listed in the following table. More details are [in the cod
| `iconElementTag` | `string` | The element to be created for icons. | `span` |
| `circlePadding` | `array` | Padding around the accuracy circle. | `[0, 0]` |
| `createButtonCallback` | `function` | This callback can be used in case you would like to override button creation behavior. | see code |
| `getLocationBounds` | `function` | This callback can be used to override the viewport tracking behavior. | see code |
| `onLocationError` | `function` | This even is called when the user's location is outside the bounds set on the map. | see code |
| `onLocationOutsideMapBounds` | `function` | Use metric units. | see code |
| `showPopup` | `boolean` | Display a pop-up when the user click on the inner marker. | `true` |
Expand Down
15 changes: 14 additions & 1 deletion src/L.Control.Locate.js
Expand Up @@ -168,6 +168,19 @@ You can find the project at: https://github.com/domoritz/leaflet-locatecontrol
setView: 'untilPanOrZoom',
/** Keep the current map zoom level when setting the view and only pan. */
keepCurrentZoomLevel: false,
/**
* This callback can be used to override the viewport tracking
* This function should return a LatLngBounds object.
*
* For example to extend the viewport to ensure that a particular LatLng is visible:
*
* getLocationBounds: function(locationEvent) {
* return locationEvent.bounds.extend([-33.873085, 151.219273]);
* },
*/
getLocationBounds: function (locationEvent) {
return locationEvent.bounds;
},
/** Smooth pan and zoom to the location of the marker. Only works in Leaflet 1.0+. */
flyTo: false,
/**
Expand Down Expand Up @@ -482,7 +495,7 @@ You can find the project at: https://github.com/domoritz/leaflet-locatecontrol
f.bind(this._map)([this._event.latitude, this._event.longitude]);
} else {
var f = this.options.flyTo ? this._map.flyToBounds : this._map.fitBounds;
f.bind(this._map)(this._event.bounds, {
f.bind(this._map)(this.options.getLocationBounds(this._event), {
padding: this.options.circlePadding,
maxZoom: this.options.locateOptions.maxZoom
});
Expand Down

0 comments on commit 4115f3d

Please sign in to comment.