Giter VIP home page Giter VIP logo

leaflet-locatecontrol's Introduction

Leaflet.Locate

npm version jsDelivr Hits

A useful control to geolocate the user with many options. Official Leaflet and MapBox plugin.

Tested with Leaflet 1.9.2 and Mapbox.js 3.3.1 in Firefox, Chrome and Safari.

Please check for breaking changes in the changelog.

Demo

Basic Usage

Set up:

tl;dr

  1. Get CSS and JavaScript files
  2. Include CSS and JavaScript files
  3. Initialize plugin

Download JavaScript and CSS files

For testing purposes and development, you can use the latest version directly from my repository.

For production environments, use Bower and run bower install leaflet.locatecontrol or download the files from this repository. Bower will always download the latest version and keep the code up to date. The original JS and CSS files are in \src and the minified versions suitable for production are in \dist.

You can also get the latest version of the plugin with npm. This plugin is available in the npm repository. Just run npm install leaflet.locatecontrol.

The control is available from JsDelivr CDN. If you don't need the latest version, you can use the mapbox CDN.

Add the JavaScript and CSS files

Then include the CSS and JavaScript files.

With CDN

In this example, we are loading the files from the JsDelivr CDN. In the URLs below, replace [VERSION] with the latest release number or remove @[VERSION] to always use the latest version.

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/leaflet.locatecontrol@[VERSION]/dist/L.Control.Locate.min.css" />
<script src="https://cdn.jsdelivr.net/npm/leaflet.locatecontrol@[VERSION]/dist/L.Control.Locate.min.js" charset="utf-8"></script>
With npm
import 'leaflet.locatecontrol' // Import plugin
import 'leaflet.locatecontrol/dist/L.Control.Locate.min.css' // Import styles
import L from 'leaflet' // Import L from leaflet to start using the plugin

Add the following snippet to your map initialization:

This snippet adds the control to the map. You can pass also pass a configuration.

L.control.locate().addTo(map);

Possible options

The locate controls inherits options from Leaflet Controls.

To customize the control, pass an object with your custom options to the locate control.

L.control.locate(OPTIONS).addTo(map);

Possible options are listed in the following table. More details are in the code.

Option Type Description Default
position string Position of the control topleft
layer ILayer The layer that the user's location should be drawn on. a new layer
setView boolean or string Set the map view (zoom and pan) to the user's location as it updates. Options are false, 'once', 'always', 'untilPan', or 'untilPanOrZoom' 'untilPanOrZoom'
flyTo boolean Smooth pan and zoom to the location of the marker. Only works in Leaflet 1.0+. false
keepCurrentZoomLevel boolean Only pan when setting the view. false
initialZoomLevel false or integer After 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
clickBehavior object What 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. {inView: 'stop', outOfView: 'setView', inViewNotFollowing: 'inView'}
returnToPrevBounds boolean If 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. false
cacheLocation boolean Keep 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. true
showCompass boolean Show the compass bearing on top of the location marker true
drawCircle boolean If set, a circle that shows the location accuracy is drawn. true
drawMarker boolean If set, the marker at the users' location is drawn. true
markerClass class The class to be used to create the marker. LocationMarker
compassClass class The class to be used to create the marker. CompassMarker
circleStyle Path options Accuracy circle style properties. see code
markerStyle Path options Inner marker style properties. Only works if your marker class supports setStyle. see code
compassStyle Path options Triangle compass heading marker style properties. Only works if your marker class supports setStyle. see code
followCircleStyle Path options Changes to the accuracy circle while following. Only need to provide changes. {}
followMarkerStyle Path options Changes to the inner marker while following. Only need to provide changes. {}
followCompassStyle Path options Changes to the compass marker while following. Only need to provide changes. {}
icon string The CSS class for the icon. leaflet-control-locate-location-arrow
iconLoading string The CSS class for the icon while loading. leaflet-control-locate-spinner
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
metric boolean Use metric units. true
onLocationOutsideMapBounds function Called when the user's location is outside the bounds set on the map. Called repeatedly when the user's location changes. see code
showPopup boolean Display a pop-up when the user click on the inner marker. true
strings object Strings used in the control. Options are title, text, metersUnit, feetUnit, popup and outsideMapBoundsMsg see code
strings.popup string or function The 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. see code
locateOptions Locate options The default options passed to leaflets locate method. see code

For example, to customize the position and the title, you could write

var lc = L.control
  .locate({
    position: "topright",
    strings: {
      title: "Show me where I am, yo!"
    }
  })
  .addTo(map);

Screenshot

screenshot

Users

Sites that use this locate control:

Advanced Usage

Methods

You can call start() or stop() on the locate control object to set the location on page load for example.

// create control and add to map
var lc = L.control.locate().addTo(map);

// request location update and set location
lc.start();

You can keep the plugin active but stop following using lc.stopFollowing().

Events

You can leverage the native Leaflet events locationfound and locationerror to handle when geolocation is successful or produces an error. You can find out more about these events in the Leaflet documentation.

Additionally, the locate control fires locateactivate and locatedeactivate events on the map object when it is activated and deactivated, respectively.

Extending

To customize the behavior of the plugin, use L.extend to override start, stop, _drawMarker and/or _removeMarker. Please be aware that functions may change and customizations become incompatible.

L.Control.MyLocate = L.Control.Locate.extend({
  _drawMarker: function () {
    // override to customize the marker
  }
});

var lc = new L.Control.MyLocate();

FAQ

How do I set the maximum zoom level?

Set the maxZoom in locateOptions (keepCurrentZoomLevel must not be set to true).

map.addControl(
  L.control.locate({
    locateOptions: {
      maxZoom: 10
    }
  })
);

How do I enable high accuracy?

To enable high accuracy (GPS) mode, set the enableHighAccuracy in locateOptions.

map.addControl(
  L.control.locate({
    locateOptions: {
      enableHighAccuracy: true
    }
  })
);

Safari does not work with Leaflet 1.7.1

This is a bug in Leaflet. Disable tap to fix it for now. See this issue for details.

let map = new L.Map('map', {
    tap: false,
    ...
});

Developers

Run the demo locally with yarn start or npm run start and then open localhost:9000/demo/index.html.

To generate the minified JS and CSS files, use grunt and run grunt. However, don't include new minified files or a new version as part of a pull request. If you need SASS, install it with brew install sass/sass/sass.

Prettify and linting

Before a Pull Request please check the code style.

Run npm run lint to check if there are code style or linting issues.

Run npm run:fix to automatically fix style and linting issues.

Making a release (only core developer)

A new version is released with npm run bump:minor. Then push the new code with git push && git push --tags and publish to npm with npm publish.

Terms

  • active: After we called map.locate() and before map.stopLocate(). Any time, the map can fire the locationfound or locationerror events.
  • following: Following refers to whether the map zooms and pans automatically when a new location is found.

Thanks

To all contributors and issue reporters.

License

MIT

SVG icons from Font Awesome v5.15.4: Creative Commons Attribution 4.0

leaflet-locatecontrol's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

leaflet-locatecontrol's Issues

Error: Map container is already initialized.

Can you point me why I have this error in the javascript console?

My code:

var capaOSM = new L.tileLayer(tileLayers[mapIndex], options);
mapa.addLayer(capaOSM);
L.control.locate({
strings: {
title: 'Localizame en el mapa',
popup: 'Rango de error: {distance} {unit}',
outsideMapBoundsMsg: 'Parece que estas fuera de los margenes de este mapa'
}
}).addTo(mapa);

Thanks!

Write tests

Possibly with mocha or something similar.

Hardcoded setView option in _locateOptions

Hi everyone,

I would like to use leaflet-locatecontrol but I encounter an issue with the locate() functionality.

As far as I can understand here [1] you force setView option to be false in order to override it with a different value. The thing is that by forcing setView to be false in _locateOptions you render it unusable to enable the maxZoom locate() option.

What I would like to do is, on locate, zoom up to a point and setView. Is that possible somehow?

Thank you

[1] https://github.com/domoritz/leaflet-locatecontrol/blob/gh-pages/src/L.Control.Locate.js#L70

NPM install

I did not want to bother you. I found that that NPM can do direct installs from GIT. (Yes it is better to register it in the NPM registry, so that the version can be tracked. But, I did not want to trouble you).

BOWER is not working through our firewalls, and it much easier to combine node.js stuff if you use NPM. I can also customize the build.

Anyway, I can use the NPM url trick for this leaflet.minimap git repostory

npm install git+https://github.com/Norkart/Leaflet-MiniMap.git --save

However, when I try that with this repository I get the errors:

> npm install git://github.com/domoritz/leaflet-locatecontrol.git --save

0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\\\node.exe',
1 verbose cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'install',
1 verbose cli   'git://github.com/domoritz/leaflet-locatecontrol.git',
1 verbose cli   '--save' ]
2 info using [email protected]
3 info using [email protected]
4 verbose node symlink C:\Program Files\nodejs\\node.exe
5 verbose readDependencies using package.json deps
6 verbose cache add [ 'git://github.com/domoritz/leaflet-locatecontrol.git', null ]
7 verbose cache add name=undefined spec="git://github.com/domoritz/leaflet-locatecontrol.git" args=["git://github.com/domoritz/leaflet-locatecontrol.git",null]
8 verbose parsed url { protocol: 'git:',
8 verbose parsed url   slashes: true,
8 verbose parsed url   auth: null,
8 verbose parsed url   host: 'github.com',
8 verbose parsed url   port: null,
8 verbose parsed url   hostname: 'github.com',
8 verbose parsed url   hash: null,
8 verbose parsed url   search: null,
8 verbose parsed url   query: null,
8 verbose parsed url   pathname: '/domoritz/leaflet-locatecontrol.git',
8 verbose parsed url   path: '/domoritz/leaflet-locatecontrol.git',
8 verbose parsed url   href: 'git://github.com/domoritz/leaflet-locatecontrol.git' }
9 silly lockFile d1e4cc4d-moritz-leaflet-locatecontrol-git git://github.com/domoritz/leaflet-locatecontrol.git
10 verbose lock git://github.com/domoritz/leaflet-locatecontrol.git C:\Users\ysg4206\AppData\Roaming\npm-cache\d1e4cc4d-moritz-leaflet-locatecontrol-git.lock
11 verbose addRemoteGit [ 'git://github.com/domoritz/leaflet-locatecontrol.git',
11 verbose addRemoteGit   'master' ]
12 verbose git clone git://github.com/domoritz/leaflet-locatecontrol.git Cloning into bare repository 'C:\Users\ysg4206\AppData\Roaming\npm-cache\_git-remotes\git-github-com-domoritz-leaflet-locatecontrol-git-d1e4cc4d'...
13 verbose git fetch -a origin (git://github.com/domoritz/leaflet-locatecontrol.git)
14 silly verifyOwnership skipping for windows
15 error Failed resolving git HEAD (git://github.com/domoritz/leaflet-locatecontrol.git) fatal: ambiguous argument 'master': unknown revision or path not in the working tree.
15 error Failed resolving git HEAD (git://github.com/domoritz/leaflet-locatecontrol.git) Use '--' to separate paths from revisions, like this:
15 error Failed resolving git HEAD (git://github.com/domoritz/leaflet-locatecontrol.git) 'git <command> [<revision>...] -- [<file>...]'
16 silly lockFile d1e4cc4d-moritz-leaflet-locatecontrol-git git://github.com/domoritz/leaflet-locatecontrol.git
17 silly lockFile d1e4cc4d-moritz-leaflet-locatecontrol-git git://github.com/domoritz/leaflet-locatecontrol.git
18 error Error: Command failed: fatal: ambiguous argument 'master': unknown revision or path not in the working tree.
18 error Use '--' to separate paths from revisions, like this:
18 error 'git <command> [<revision>...] -- [<file>...]'
18 error
18 error     at ChildProcess.exithandler (child_process.js:648:15)
18 error     at ChildProcess.emit (events.js:98:17)
18 error     at maybeClose (child_process.js:756:16)
18 error     at Process.ChildProcess._handle.onexit (child_process.js:823:5)
19 error If you need help, you may report this *entire* log,
19 error including the npm and node versions, at:
19 error     <http://github.com/npm/npm/issues>
20 error System Windows_NT 6.1.7601
21 error command "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "git://github.com/domoritz/leaflet-locatecontrol.git" "--save"
22 error cwd G:\wwwroot\NodeToby
23 error node -v v0.10.30
24 error npm -v 1.4.21
25 error code 128
26 verbose exit [ 1, true ]

Accuracy circle and circle marker not removed on stopLocate()...

When stopLocate fires self._layer.clearLayers(); executes to remove the _circle and _circleMarker from the LayerGroup.

On Android 4.2.2, Samsung Galaxy tab 7, I am noticing that clearLayers() does not remove the accuracy circle or circleMarker. I have to manually re-position the map for the circle and circleMarker marker to disappear (i assume a redraw or invalidate is being fired?)

I am using the leaflet 0.6.2 & latest version of the leaflet-locatecontrol as of Oct 12, '13.

How to change the path for the images

Hi!
Is there any equivalent L.Icon.Default.imagePath for this plug-in?

What does it do?
It sets a custom path for the images

Now it try to load from the path to the leaflet-locatecontrol css (including it) /images

Thanks!

Add missing bower.json.

Hey, maintainer(s) of domoritz/leaflet-locatecontrol!

We at VersionEye are working hard to keep up the quality of the bower's registry.

We just finished our initial analysis of the quality of the Bower.io registry:

7530 - registered packages, 224 of them doesnt exists anymore;

We analysed 7306 existing packages and 1070 of them don't have bower.json on the master branch ( that's where a Bower client pulls a data ).

Sadly, your library domoritz/leaflet-locatecontrol is one of them.

Can you spare 15 minutes to help us to make Bower better?

Just add a new file bower.json and change attributes.

{
  "name": "domoritz/leaflet-locatecontrol",
  "version": "1.0.0",
  "main": "path/to/main.css",
  "description": "please add it",
  "license": "Eclipse",
  "ignore": [
    ".jshintrc",
    "**/*.txt"
  ],
  "dependencies": {
    "<dependency_name>": "<semantic_version>",
    "<dependency_name>": "<Local_folder>",
    "<dependency_name>": "<package>"
  },
  "devDependencies": {
    "<test-framework-name>": "<version>"
  }
}

Read more about bower.json on the official spefication and nodejs semver library has great examples of proper versioning.

NB! Please validate your bower.json with jsonlint before commiting your updates.

Thank you!

Timo,
twitter: @versioneye
email: [email protected]
VersionEye - no more legacy software!

NaN Error Radius

I upgraded to Leaflet 0.6 and the latest Locate control. I am getting a new type of error. On FireFox V20, I am finding that the error radius is NaN. So I am getting errors on creating the circle:

var locateControl = new L.control.locate({
    position: "topleft",
    drawCircle: true
});

If I turn off the drawCircle: false, I do get the correct location (with the marker, and with the tooltip saying that you are within NaN of this location).

I tried this again with Chrome v26, and I am getting that I am within 1200 meters.

The really odd thing is that your demo at http://domoritz.de/leaflet-locatecontrol/demo/ does work for me in FireFox, and it also says that I am withing 1200 meters.

I am testing on a desktop machine (win7).

Create a callback function

On the standard locate function, there's an option to call another function when the location is found and when the location is not found. I have an "onLocationFound" function that runs some custom tasks like building a marker that has a popup with options to save the location among other tasks.

I thought I could just reference my function in var onLocationError = function (err) {}); but it's not getting called.

My custom functions are defined in the HTML after Leaflet and before this plugin.

When NOT using coords 4326 - fail to get correct bounds

Under

var visualizeLocation = function() {

the fitBounds sets the wrong bounds for the map if not in 4326 and in local country circuit.

//  map.fitBounds(self._event.bounds, { padding: self.options.circlePadding });

But if you use panTo it works to get to the correct place?

map.panTo(self._event.latlng);

Accuracy radius

I coudn't find any references, but I suppose the accuracy value returned by the geolocator is alredy meant to be the displayed as the accuracy radius, and not the diameter. So you probably shoudn't divide that by 2.
At least that's what Google Maps seems to display.

An external locate button

Hi, great plugin, I was just wondering if the "locate functionality" can be invoked by a button outside of the map. I'd like to make it more obvious for my users.

Feature: stopFollowingOnEvents

I introduced the stopFollowingOnDrag functionality in #22. This has proven to be a very handy feature for our uses, but it has recently come to our attention that one might want following to cancel on any number of events, dragstart (or any of the other drage events) being one.

In our local copy, I've written functionality for stopFollowingOnEvents into the library. Upon initialization, you declare something like the following in the init options:

stopFollowingOnEvents: [
    'dragstart',
    'mousedown',
    'customEvent'
]

Inside the library, each item from the provided array is taken and the following-cancellation event handler is bound to it.

This works well. However, we have further customization inserted (awareness of custom events we added into an old version of Leaflet), so I'll have to rework it for a patch, which I'm happy to do.

So, this issue exists in effect to find out if this would be a welcome feature, and if so, what should be done with stopFollowingOnDrag. If desired, stopFollowingOnDrag could simply become an alias to stopFollowingOnEvents: ['dragstart'] to preserve backward compatibility.

Anyhow, lemme know. As I said, I'll be happy to make a pull request, but I wanted to see if it'd be welcome, first.

Initialize locate on page load

Is there any way to have this activated already when the page is loaded? I'd like to have this in a "pressed" state so that it zooms to the user's location automatically once the page loads and they can click it to deactivate. Thanks!

onLocationFound

Is it possible to define a function raise when the location process finish?

In the code I can find onLocationFound that seems the correct place but I don't want to override it and it doesn't call any function or event

Thanks!

Bower package

I plan to create an AngularJS module that integrates your leaflet-locatecontrol with angular-leaflet-directive but it would be great to simply have a bower package for your library.

Can you create one ? Also, I think that it would be better to store sources in a master branch and the demonstration in gh-pages branch... And it will be a little bit easier to create the bower package ;-)

Consider the map boundaries

There is a possibility to define map boundaries in Leaflet (maxBounds option), such that the user cannot pan outside some defined area. It would be interesting to catch the cases when the location is outside the map boundaries, and offer the developer an option to not set the view to this location.

stopLocate if isOutsideMapBounds()

I was having an issue in that if the user is outside the map bounds the appropriate method would be called, but the user had to click the locate button "off" before being able to try the operation again.

It looks like maybe this is intended to be solved here:

        L.DomEvent
            .on(link, 'click', L.DomEvent.stopPropagation)       
            .on(link, 'click', L.DomEvent.preventDefault)
            .on(link, 'click', function() {
                if (self._active && (self._event === undefined || map.getBounds().contains(self._event.latlng) ||$
                    isOutsideMapBounds())) {               
                    stopLocate();
                } else {
                    locate();
                }
            })           
            .on(link, 'dblclick', L.DomEvent.stopPropagation);

To get the expected behavior I added this, though:
                if (isOutsideMapBounds()) {
                    self.options.onLocationOutsideMapBounds(self);
=>                    stopLocate();
                } else {
                    map.fitBounds(self._event.bounds, {
                        padding: self.options.circlePadding,
                        maxZoom: self._locateOptions.maxZoom
                    });
                }

You might have a better fix for this but wanted to let you know.

setView: false not working

I assume when setView: false is set, the map should not change zoom, or set focus to the location. It should just show the blue dot for location, correct? If I'm right in assuming this, it seems setView: false is broken as it zooms right into the marker's positon (well actually it zooms into another location and when clicked again, zooms to the correct location.)

Retina icon

Right now there's a @1x icon & SVG files. Should be a pretty quick task to render out a @2x icon for this. Will do when I get a moment.

Question: maxZoom

It's kind of simple but I have stuck. How can I set the map zoom upon location discovery?

With simply .locate() I used:

.locate({
       setView: true, 
       maxZoom: 10
});

But now I try and this doesn't work.

map.addControl(L.control.locate({
       setView: true, 
       maxZoom: 10
}));

Thanks

id's for circle and point geometries

Is it possible to add special id's to theese objects (or make on option to add)? It'll be nice to have a possibility to controll appearence of circle and point through css. For example, through media queries in case of different styles for desktop and mobile devices.

Draw trace line

Is it possible to draw line where user walks and store it to some variable where I can access that shape (line)? So, something like L.Path or L.Polyline is created when user calls stopLocate()?

Thanks.

Enhancement Request: onLocationFound

As an advanced option it might be nice if we could override the default locationfound logic with an onLocationFound option.

The bosses are pushing an idea that would require a more complex boundary detection algorithm (based on a polygon rather than the Leaflet map boundaries) and I'd need to apply any such logic at that level.

I do realize this would negate some of the functionality included in this software but it'd still be nice to use for the remaining pieces (control, following, etc.)

Allow imperial/English units

I don't know how pull requests work, but I added some code to show imperial/English units instead of metric.

Inside visualizeLocation:

var distance;
            var unit;
            if(self.options.metric == false) {
                distance = Math.round(radius * 3.28); // feet
                unit = "feet"
            } else {
                distance = radius.toFixed(0);
                unit = "meters";
            }

// small inner marker
            L.circleMarker(self._event.latlng, self.options.markerStyle)
                .bindPopup("You are within " + distance + " " + unit + " of this point")
                .addTo(self._layer);

Inside options:

// inner marker
        markerStyle: {
            color: '#136AEC',
            fillColor: '#2A93EE',
            fillOpacity: 0.7,
            weight: 2,
            opacity: 0.9,
            radius: 4
        },
        debug: false,
        metric:false

Join the discussion: New icon

I noticed that the locate icon is not as obvious as I thought. So, here are two suggestions (old and new one). The new icon is inspired by the icon at http://www.openstreetmap.org/.

Old (normal, located, following):
locate_old

New (normal, located, following):
locate_new

I'd like to know what you think!

Tag?

We're looking at using this for OpenStreetMap, any chance you can tag the current state to have something stable to hang on to?

Manually enable, disable control

Is there any way to manually enable and disable this control? I'd like to be able to toggle the locate control from a button outside of the map element. Thanks!

Fallback to ip based location

Wouldn't it be a goof idea to add a fallback to an ip based location if there is nothing else available?

This has been done before by other develops (see https://github.com/onury/geolocator for example).

However, I would suggest to add something like a accuracy_indicator to indicate, that an ip based location is less accurate than a HTML based one (at least usually, isn't it?)

Issues between this control and awesome-markers

Hello, if I use this Leaflet plugin with another plugin called Awesome-Markers (https://github.com/lvoogdt/Leaflet.awesome-markers), the Fontawesome icons within the Leaflet markers don't show anymore.

Solution for me was to comment out the following lines from L.control.locate.css:

@import url('font/locate-fa.woff');
@import url('css/locate-fa.css');

No issues were displayed on Chrome console, though. This took me some trial-and-error.

Enhancement request: keep current map zoom level when located

The maxZoom level is used when the location. Is it possible to add an option to choose to keep the current map zoom level?

This is actually quite simple :

  • In locateOptions, add a useCurrentZoomLevel option:
    locateOptions: {
    useCurrentZoomLevel : true,
    }
  • In the visualizeLocation() function, add a check to this option in fitBound when setting the maxZoom, and get the current zoom level if needed :
    maxZoom: self._locateOptions.useCurrentZoomLevel?map.getZoom():self._locateOptions.maxZoom

(Sorry, I don't know how to do a pull request)

Maybe it's related to #23

Thanks.

Update for Leaflet 0.5

The style of the zoom buttons has significantly changed. I think it makes sense to have a separate style for Leaflet 0.4 and 0.5.

Custom marker

Is it possible to set a custom marker instead of the stadard blue dot?

Clicks should toggle between on/off, but enters on state just once

Thanks for the control, nice work.

When clicking on the icon once, it activates the location search. Another click deactivates it. I'd expect subsequent clicks on it to activate it again, but that's not the case here. I believe this is because map.locate() does not generate more onLocationFound events after the first one.

In practice this means that (with autoRemoveCircle=true) the location circle is shown after the first click, but then never again after one and more clicks.

undef error when clicking spinner

When clicking the spinner while first location fix is not yet available I get an undef ref error.

Checking self._event before accessing it fixes it:

diff --git a/src/L.Control.Locate.js b/src/L.Control.Locate.js
index 8f1568f..29cf987 100644
--- a/src/L.Control.Locate.js
+++ b/src/L.Control.Locate.js
@@ -88,7 +88,7 @@ L.Control.Locate = L.Control.extend({
.on(link, 'click', L.DomEvent.stopPropagation)
.on(link, 'click', L.DomEvent.preventDefault)
.on(link, 'click', function() {

  •            if (self._active && (map.getBounds().contains(self._event.latlng) || !self.options.setView ||
    
  •            if (self._active && (self._event && map.getBounds().contains(self._event.latlng) || !self.options.setView ||
    

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.