From 85c8bdf0ff81fa32cf735509bba225cc57756e1c Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Tue, 8 Jan 2013 12:14:05 -0500 Subject: [PATCH] Refactor geolocate control --- index.html | 1 + js/id/id.js | 13 +------------ js/id/ui/geolocate.js | 22 ++++++++++++++++++++++ 3 files changed, 24 insertions(+), 12 deletions(-) create mode 100644 js/id/ui/geolocate.js diff --git a/index.html b/index.html index fa957b991..9d9a1ed60 100644 --- a/index.html +++ b/index.html @@ -46,6 +46,7 @@ + diff --git a/js/id/id.js b/js/id/id.js index 8ee5a0e4a..b6b6ed4ae 100644 --- a/js/id/id.js +++ b/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') diff --git a/js/id/ui/geolocate.js b/js/id/ui/geolocate.js new file mode 100644 index 000000000..1d4e1a491 --- /dev/null +++ b/js/id/ui/geolocate.js @@ -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); + }); + }; + +};