1 //= require leaflet.locate
3 $(document).ready(function () {
4 if ($("#map").length) {
5 var map = L.map("map", {
6 attributionControl: false,
8 }).addLayer(new L.OSM.Mapnik());
10 var position = $('html').attr('dir') === 'rtl' ? 'topleft' : 'topright';
12 L.OSM.zoom({position: position})
15 var locate = L.control.locate({
17 icon: 'icon geolocate',
18 iconLoading: 'icon geolocate',
20 title: I18n.t('javascripts.map.locate.title'),
21 popup: I18n.t('javascripts.map.locate.popup')
25 var locateContainer = locate.getContainer();
28 .removeClass('leaflet-control-locate leaflet-bar')
29 .addClass('control-locate')
31 .removeClass('leaflet-bar-part leaflet-bar-part-single')
32 .addClass('control-button');
35 map.setView([OSM.home.lat, OSM.home.lon], 12);
37 map.setView([0, 0], 0);
40 if ($("#map").hasClass("set_location")) {
41 var marker = L.marker([0, 0], {icon: OSM.getUserIcon()});
44 marker.setLatLng([OSM.home.lat, OSM.home.lon]);
48 map.on("click", function (e) {
49 if ($('#updatehome').is(':checked')) {
50 var zoom = map.getZoom(),
51 precision = OSM.zoomPrecision(zoom),
52 location = e.latlng.wrap();
54 $('#homerow').removeClass();
55 $('#home_lat').val(location.lat.toFixed(precision));
56 $('#home_lon').val(location.lng.toFixed(precision));
58 marker.setLatLng(e.latlng);
63 $("[data-user]").each(function () {
64 var user = $(this).data('user');
65 if (user.lon && user.lat) {
66 L.marker([user.lat, user.lon], {icon: OSM.getUserIcon(user.icon)}).addTo(map)
67 .bindPopup(user.description);
73 function updateAuthUID() {
74 var provider = $("select#user_auth_provider").val();
76 if (provider === "openid") {
77 $("input#user_auth_uid").show().prop("disabled", false);
79 $("input#user_auth_uid").hide().prop("disabled", true);
85 $("select#user_auth_provider").on("change", updateAuthUID);
87 function enableAuth() {
88 $("#auth_prompt").hide();
89 $("#auth_field").show();
90 $("#user_auth_uid").prop("disabled", false);
93 function disableAuth() {
94 $("#auth_prompt").show();
95 $("#auth_field").hide();
96 $("#user_auth_uid").prop("disabled", true);
99 $("#auth_enable").click(enableAuth);
101 if ($("select#user_auth_provider").val() === "") {