Add a "Start Mapping" button
Position is determined in one of two ways: lat/lon query parameters (with helpful text from a nominatim reverse geocode), or HTML5 geolocation.
This commit is contained in:
parent
3b74fc2579
commit
1a51f21871
6 changed files with 99 additions and 4 deletions
54
app/assets/javascripts/welcome.js
Normal file
54
app/assets/javascripts/welcome.js
Normal file
|
@ -0,0 +1,54 @@
|
|||
$(document).ready(function() {
|
||||
var params = OSM.params();
|
||||
|
||||
if (params.lat && params.lon) {
|
||||
$('.edit-located').show();
|
||||
|
||||
$.ajax({
|
||||
url: "http://nominatim.openstreetmap.org/reverse",
|
||||
data: {
|
||||
lat: params.lat,
|
||||
lon: params.lon,
|
||||
zoom: 10
|
||||
},
|
||||
success: function(xml) {
|
||||
var result = $(xml).find('result');
|
||||
if (result.length) {
|
||||
$('.edit-located').hide();
|
||||
$('.edit-geocoded').show();
|
||||
$('.edit-geocoded-location').text(result.text());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$('.start-mapping').on('click', function(e) {
|
||||
window.location = '/edit?zoom=17&lat=' + params.lat + '&lon=' + params.lon;
|
||||
});
|
||||
|
||||
} else if (navigator.geolocation) {
|
||||
$('.edit-geolocated').show();
|
||||
|
||||
function geoSuccess(position) {
|
||||
window.location = '/edit?zoom=17&lat=' + position.coords.latitude + '&lon=' + position.coords.longitude;
|
||||
}
|
||||
|
||||
function geoError() {
|
||||
$('.start-mapping')
|
||||
.removeClass('loading')
|
||||
.addClass('error');
|
||||
}
|
||||
|
||||
$('.start-mapping').on('click', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
$('.start-mapping')
|
||||
.addClass('loading');
|
||||
|
||||
// handle firefox's weird implementation
|
||||
// https://bugzilla.mozilla.org/show_bug.cgi?id=675533
|
||||
window.setTimeout(geoError, 4000);
|
||||
|
||||
navigator.geolocation.getCurrentPosition(geoSuccess, geoError);
|
||||
});
|
||||
}
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue