Skip to content

LocateControl

The VMapLocateControl component is used to geolocate the user.

Required @leaflet-extensions/locatecontrol extension.

Installation

bash
$ npm install @leaflet-extensions/locatecontrol
$ npm install @leaflet-extensions/locatecontrol

Add

js
import '@leaflet-extensions/locatecontrol';
import '@leaflet-extensions/locatecontrol/dist/leaflet-locatecontrol.css';
import '@leaflet-extensions/locatecontrol';
import '@leaflet-extensions/locatecontrol/dist/leaflet-locatecontrol.css';

For Nuxt

vue
<script setup lang="ts">
if (process.client) {
  await Promise.all([
    // @ts-ignore
    import('@leaflet-extensions/locatecontrol'),
    import('@leaflet-extensions/locatecontrol/dist/leaflet-locatecontrol.css')
  ]);
}
</script>
<script setup lang="ts">
if (process.client) {
  await Promise.all([
    // @ts-ignore
    import('@leaflet-extensions/locatecontrol'),
    import('@leaflet-extensions/locatecontrol/dist/leaflet-locatecontrol.css')
  ]);
}
</script>

Basic usage

API

Attributes

NameTypeDescriptionDefault
positionThe position of the control (one of the corners of the map). See types for possible values.ControlPosition | ExtraControlPosition'centerright'
layerThe layer that the user's location should be drawn on.Layera new layer
setViewSet the map view (zoom and pan) to the user's location as it updates. Options are false, 'once', 'always', 'untilPan', or 'untilPanOrZoom'boolean | string'untilPanOrZoom'
flyToSmooth pan and zoom to the location of the marker. Only works in Leaflet 1.0+.booleanfalse
keepCurrentZoomLevelOnly pan when setting the view.booleanfalse
initialZoomLevelAfter activating the plugin by clicking on the icon, zoom to the selected zoom level, even when keepCurrentZoomLevel is true. Set to false to disable this feature.false | integerfalse
clickBehaviorWhat to do when the user clicks on the control. Has three options inView, inViewNotFollowing and outOfView. Possible values are stop and setView, or the name of a behaviour to inherit from.object{inView: 'stop', outOfView: 'setView', inViewNotFollowing: 'inView'}
returnToPrevBoundsIf set, save the map bounds just before centering to the user's location. When control is disabled, set the view back to the bounds that were saved.booleanfalse
cacheLocationKeep a cache of the location after the user deactivates the control. If set to false, the user has to wait until the locate API returns a new location before they see where they are again.booleantrue
showCompassShow the compass bearing on top of the location marker.booleantrue
drawCircleIf set, a circle that shows the location accuracy is drawn.booleantrue
drawMarkerIf set, the marker at the users' location is drawn.booleantrue
markerClassThe class to be used to create the marker.classLocationMarker
compassClassThe class to be used to create the marker.classCompassMarker
circleStyleAccuracy circle style properties.PathOptionssee code
markerStyleInner marker style properties. Only works if your marker class supports setStyle.PathOptionssee code
compassStyleTriangle compass heading marker style properties. Only works if your marker class supports setStyle.PathOptionssee code
followCircleStyleChanges to the accuracy circle while following. Only need to provide changes.PathOptions{}
followMarkerStyleChanges to the inner marker while following. Only need to provide changes.PathOptions{}
followCompassStyleChanges to the compass marker while following. Only need to provide changes.PathOptions{}
iconThe CSS class for the icon.string'leaflet-control-locate-location-arrow'
iconLoadingThe CSS class for the icon while loading.string'leaflet-control-locate-spinner'
iconElementTagThe element to be created for icons.string'span'
circlePaddingPadding around the accuracy circle.array[0, 0]
createButtonCallbackThis callback can be used in case you would like to override button creation behavior.functionsee code
getLocationBoundsThis callback can be used to override the viewport tracking behavior.functionsee code
onLocationErrorThis even is called when the user's location is outside the bounds set on the map.functionsee code
metricUse metric units.booleantrue
onLocationOutsideMapBoundsCalled when the user's location is outside the bounds set on the map. Called repeatedly when the user's location changes.functionsee code
showPopupDisplay a pop-up when the user click on the inner marker.booleantrue
stringsStrings used in the control. Options are title, text, metersUnit, feetUnit, popup and outsideMapBoundsMsgobjectsee code
strings.popupThe string shown as popup. May contain the placeholders {distance} and {unit}. If this option is specified as function, it will be executed with a single parameter {distance, unit} and expected to return a string.string | functionsee code
locateOptionsThe default options passed to leaflets locate method.LocateOptionssee code

Events

No events.

Slots

NameDescription
defaultThe default slot can be used to extend behavior.

Exposes

NameDescriptionType
locateControlLeaflet locate control instance.Ref<LocateControlExtension | null>

Released under the MIT License.