if (document.getElementById("placesmap") !== null) { places_base_path = "/places"; mapbox_map_id = "<%= Rails.env == 'test' ? 0 : Rails.application.config.mapbox_map_id %>"; mapbox_access_token = "<%= Rails.env == 'test' ? 0 : Rails.application.config.mapbox_access_token %>"; mapbox_base_url = "http://a.tiles.mapbox.com/v4/" + mapbox_map_id + "/{z}/{x}/{y}.png?access_token=" + mapbox_access_token; nominatim_base_url = 'http://nominatim.openstreetmap.org/search/'; nominatim_user_agent_email = "<%= Rails.env == 'test' ? 0 : Rails.application.config.user_agent_email %>"; L.Icon.Default.imagePath = '/assets' if (location.pathname === places_base_path) { //places index page placesmap = L.map('placesmap').setView([0.0, -0.0], 2); showMap(placesmap); } else { // specific place page place = location.pathname.replace(places_base_path + "/", ''); nominatim_query_url = nominatim_base_url + place; nominatim_options = { format: "json", callback: "placeholder", limit: 1, email: nominatim_user_agent_email }; $.getJSON(nominatim_query_url, nominatim_options, function(data) { placesmap = L.map('placesmap').setView([data[0].lat, data[0].lon], 5); showMap(placesmap); }) } } function showMap(placesmap) { L.tileLayer(mapbox_base_url, { attribution: 'Map data © OpenStreetMap contributors under ODbL | Map imagery © Mapbox', maxZoom: 18 }).addTo(placesmap); markers = new L.MarkerClusterGroup({showCoverageOnHover: false, maxClusterRadius: 20 }); things_to_map = location.pathname + '.json'; $.getJSON(things_to_map, function(members) { $.each(members, function(i, m) { if (m.latitude && m.longitude) { marker = new L.Marker(new L.LatLng(m.latitude, m.longitude)); link = "

" + m.login_name + "

"; where = "

" + m.location + "

"; marker.bindPopup(link + where).openPopup(); markers.addLayer(marker); } }); }); placesmap.addLayer(markers); }