mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 09:12:52 +00:00
Refactor geolocate control
This commit is contained in:
@@ -46,6 +46,7 @@
|
||||
<script src='js/id/ui/layerswitcher.js'></script>
|
||||
<script src='js/id/ui/contributors.js'></script>
|
||||
<script src='js/id/ui/geocoder.js'></script>
|
||||
<script src='js/id/ui/geolocate.js'></script>
|
||||
<script src='js/id/ui/notice.js'></script>
|
||||
<script src='js/id/ui/tag_reference.js'></script>
|
||||
|
||||
|
||||
13
js/id/id.js
13
js/id/id.js
@@ -184,20 +184,9 @@ window.iD = function(container) {
|
||||
return d[0] + ' icon';
|
||||
});
|
||||
|
||||
function geolocateSuccess(position) {
|
||||
map.center([position.coords.longitude, position.coords.latitude]);
|
||||
}
|
||||
function geolocateError() { }
|
||||
if (navigator.geolocation) {
|
||||
container.append('div')
|
||||
.attr('class', 'geolocate-control map-control')
|
||||
.append('button')
|
||||
.attr('class', 'narrow')
|
||||
.attr('title', 'Show My Location')
|
||||
.text('G')
|
||||
.on('click', function() {
|
||||
navigator.geolocation.getCurrentPosition(geolocateSuccess, geolocateError);
|
||||
});
|
||||
.call(iD.geolocate(map));
|
||||
}
|
||||
|
||||
var gc = container.append('div').attr('class', 'geocode-control map-control')
|
||||
|
||||
22
js/id/ui/geolocate.js
Normal file
22
js/id/ui/geolocate.js
Normal file
@@ -0,0 +1,22 @@
|
||||
iD.geolocate = function(map) {
|
||||
|
||||
function success(position) {
|
||||
map.center([position.coords.longitude, position.coords.latitude]);
|
||||
}
|
||||
|
||||
function error() { }
|
||||
|
||||
return function(selection) {
|
||||
selection
|
||||
.attr('class', 'geolocate-control map-control')
|
||||
.append('button')
|
||||
.attr('class', 'narrow')
|
||||
.attr('title', 'Show My Location')
|
||||
.text('G')
|
||||
.on('click', function() {
|
||||
navigator.geolocation.getCurrentPosition(
|
||||
success, error);
|
||||
});
|
||||
};
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user