]> git.openstreetmap.org Git - rails.git/blob - app/assets/javascripts/user.js
Add comment describing the overpass queries we use
[rails.git] / app / assets / javascripts / user.js
1 //= require leaflet.locate
2
3 $(document).ready(function () {
4   var map = L.map("map", {
5     attributionControl: false,
6     zoomControl: false
7   }).addLayer(new L.OSM.Mapnik());
8
9   var position = $('html').attr('dir') === 'rtl' ? 'topleft' : 'topright';
10
11   L.OSM.zoom({position: position})
12     .addTo(map);
13
14   L.control.locate({
15     position: position,
16     strings: {
17       title: I18n.t('javascripts.map.locate.title'),
18       popup: I18n.t('javascripts.map.locate.popup')
19     }
20   }).addTo(map);
21
22   if (OSM.home) {
23     map.setView([OSM.home.lat, OSM.home.lon], 12);
24   } else {
25     map.setView([0, 0], 0);
26   }
27
28   if ($("#map").hasClass("set_location")) {
29     var marker = L.marker([0, 0], {icon: getUserIcon()});
30
31     if (OSM.home) {
32       marker.setLatLng([OSM.home.lat, OSM.home.lon]);
33       marker.addTo(map);
34     }
35
36     map.on("click", function (e) {
37       if ($('#updatehome').is(':checked')) {
38         var zoom = map.getZoom(),
39             precision = OSM.zoomPrecision(zoom),
40             location = e.latlng.wrap();
41
42         $('#homerow').removeClass();
43         $('#home_lat').val(location.lat.toFixed(precision));
44         $('#home_lon').val(location.lng.toFixed(precision));
45
46         marker.setLatLng(e.latlng);
47         marker.addTo(map);
48       }
49     });
50   } else {
51     $("[data-user]").each(function () {
52       var user = $(this).data('user');
53       if (user.lon && user.lat) {
54         L.marker([user.lat, user.lon], {icon: getUserIcon(user.icon)}).addTo(map)
55           .bindPopup(user.description);
56       }
57     });
58   }
59 });