]> git.openstreetmap.org Git - rails.git/blob - app/assets/javascripts/welcome.js
5409c9ec9487d893177954a51c3a8cabc478d301
[rails.git] / app / assets / javascripts / welcome.js
1 $(document).ready(function() {
2   var params = OSM.params();
3
4   if (params.lat && params.lon) {
5     $('.edit-located').show();
6
7     $.ajax({
8       url: "http://nominatim.openstreetmap.org/reverse",
9       data: {
10         lat: params.lat,
11         lon: params.lon,
12         zoom: 10
13       },
14       success: function(xml) {
15         var result = $(xml).find('result');
16         if (result.length) {
17           $('.edit-located').hide();
18           $('.edit-geocoded').show();
19           $('.edit-geocoded-location').text(result.text());
20         }
21       }
22     });
23
24     $('.start-mapping').on('click', function(e) {
25       window.location = '/edit?zoom=17&lat=' + params.lat + '&lon=' + params.lon;
26     });
27
28   } else if (navigator.geolocation) {
29     $('.edit-geolocated').show();
30
31     function geoSuccess(position) {
32       window.location = '/edit?zoom=17&lat=' + position.coords.latitude + '&lon=' + position.coords.longitude;
33     }
34
35     function geoError() {
36       $('.start-mapping')
37         .removeClass('loading')
38         .addClass('error');
39     }
40
41     $('.start-mapping').on('click', function(e) {
42       e.preventDefault();
43
44       $('.start-mapping')
45         .addClass('loading');
46
47       // handle firefox's weird implementation
48       // https://bugzilla.mozilla.org/show_bug.cgi?id=675533
49       window.setTimeout(geoError, 4000);
50
51       navigator.geolocation.getCurrentPosition(geoSuccess, geoError);
52     });
53   }
54 });