position: 'topleft',
drawCircle: true,
follow: false, // follow with zoom and pan the user's location
- stopFollowingOnDrag: false, // if follow is true, stop following when map is dragged
+ stopFollowingOnDrag: false, // if follow is true, stop following when map is dragged (deprecated)
// range circle
circleStyle: {
color: '#136AEC',
//color: '#FFA500',
//fillColor: '#FFB000'
},
+ circlePadding: [0, 0],
metric: true,
onLocationError: function(err) {
// this event is called in case of any location error
isOutsideMapBounds())) {
stopLocate();
} else {
- if (self.options.setView) {
- self._locateOnNextLocationFound = true;
- }
- if(!self._active) {
- map.locate(self._locateOptions);
- }
- self._active = true;
- if (self.options.follow) {
- startFollowing();
- }
- if (!self._event) {
- L.DomUtil.addClass(self._container, "requesting");
- L.DomUtil.removeClass(self._container, "active");
- L.DomUtil.removeClass(self._container, "following");
- } else {
- visualizeLocation();
- }
+ locate();
}
})
.on(link, 'dblclick', L.DomEvent.stopPropagation);
+ var locate = function () {
+ if (self.options.setView) {
+ self._locateOnNextLocationFound = true;
+ }
+ if(!self._active) {
+ map.locate(self._locateOptions);
+ }
+ self._active = true;
+ if (self.options.follow) {
+ startFollowing();
+ }
+ if (!self._event) {
+ L.DomUtil.addClass(self._container, "requesting");
+ L.DomUtil.removeClass(self._container, "active");
+ L.DomUtil.removeClass(self._container, "following");
+ } else {
+ visualizeLocation();
+ }
+ };
+
var onLocationFound = function (e) {
// no need to do anything if the location has not changed
if (self._event &&
- (self._event.latlng.lat == e.latlng.lat &&
- self._event.latlng.lng == e.latlng.lng)) {
+ (self._event.latlng.lat === e.latlng.lat &&
+ self._event.latlng.lng === e.latlng.lng &&
+ self._event.accuracy === e.accuracy)) {
return;
}
};
var startFollowing = function() {
+ map.fire('startfollowing');
self._following = true;
if (self.options.stopFollowingOnDrag) {
map.on('dragstart', stopFollowing);
};
var stopFollowing = function() {
+ map.fire('stopfollowing');
self._following = false;
if (self.options.stopFollowingOnDrag) {
map.off('dragstart', stopFollowing);
if (isOutsideMapBounds()) {
self.options.onLocationOutsideMapBounds(self);
} else {
- map.fitBounds(self._event.bounds);
+ map.fitBounds(self._event.bounds, { padding: self.options.circlePadding });
}
self._locateOnNextLocationFound = false;
}
// circle with the radius of the location's accuracy
- var style;
+ var style, o;
if (self.options.drawCircle) {
if (self._following) {
style = self.options.followCircleStyle;
.addTo(self._layer);
} else {
self._circle.setLatLng(self._event.latlng).setRadius(radius);
+ for (o in style) {
+ self._circle.options[o] = style[o];
+ }
}
}
}
// small inner marker
- var m;
+ var mStyle;
if (self._following) {
- m = self.options.followMarkerStyle;
+ mStyle = self.options.followMarkerStyle;
} else {
- m = self.options.markerStyle;
+ mStyle = self.options.markerStyle;
}
var t = self.options.strings.popup;
if (!self._circleMarker) {
- self._circleMarker = L.circleMarker(self._event.latlng, m)
+ self._circleMarker = L.circleMarker(self._event.latlng, mStyle)
.bindPopup(L.Util.template(t, {distance: distance, unit: unit}))
.addTo(self._layer);
} else {
self._circleMarker.setLatLng(self._event.latlng)
.bindPopup(L.Util.template(t, {distance: distance, unit: unit}))
._popup.setLatLng(self._event.latlng);
+ for (o in mStyle) {
+ self._circleMarker.options[o] = mStyle[o];
+ }
}
if (!self._container)
map.on('locationfound', onLocationFound, self);
map.on('locationerror', onLocationError, self);
+ // make locate functions available to outside world
+ this.locate = locate;
+ this.stopLocate = stopLocate;
+ this.stopFollowing = stopFollowing;
+
return container;
}
});