2015-03-01 16:50:02 +01:00
|
|
|
# Setting up OpenStreeMap from a generic #map element
|
2016-07-02 16:48:47 +02:00
|
|
|
$(document).on 'turbolinks:load', ->
|
2016-05-21 23:15:49 +02:00
|
|
|
markerColors = ['blue', 'red', 'darkred', 'orange', 'green', 'darkgreen', 'purple', 'darkpuple', 'cadetblue']
|
|
|
|
idx = 0
|
2016-04-16 23:08:03 +02:00
|
|
|
$('#map.list').each ->
|
2014-09-21 14:32:59 +02:00
|
|
|
map = L.map 'map'
|
2014-07-31 01:32:47 +02:00
|
|
|
|
2014-10-05 13:35:42 +02:00
|
|
|
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
|
2014-08-23 16:59:42 +02:00
|
|
|
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a>'
|
|
|
|
).addTo map
|
|
|
|
|
2016-04-17 01:40:34 +02:00
|
|
|
controls = L.control.layers(null, null, collapsed: false).addTo map
|
2014-10-29 11:42:07 +01:00
|
|
|
|
2016-04-16 23:08:03 +02:00
|
|
|
$('li a', this).each ->
|
|
|
|
url = $(this).attr 'href'
|
|
|
|
text = $(this).html()
|
2016-05-21 23:15:49 +02:00
|
|
|
markerColor = markerColors[idx++ %% markerColors.length]
|
2016-04-16 23:08:03 +02:00
|
|
|
if location.search && url.indexOf('?') >= 0
|
|
|
|
url += '&' + location.search.substr 1
|
|
|
|
else
|
|
|
|
url += location.search
|
2014-08-23 16:59:42 +02:00
|
|
|
|
2016-04-16 23:08:03 +02:00
|
|
|
$.getJSON url, (json) ->
|
|
|
|
if json
|
|
|
|
layer = L.markerClusterGroup(maxClusterRadius: 30).addLayer L.geoJson json,
|
2016-05-21 23:15:49 +02:00
|
|
|
pointToLayer: (feature, latlng) ->
|
|
|
|
# Marker with the proper icon
|
|
|
|
marker = L.AwesomeMarkers.icon
|
|
|
|
prefix: 'fa',
|
|
|
|
icon: feature.properties.icon || 'calendar',
|
|
|
|
markerColor: markerColor
|
|
|
|
L.marker latlng, icon: marker
|
|
|
|
,
|
2016-04-16 23:08:03 +02:00
|
|
|
onEachFeature: (feature, layer) ->
|
|
|
|
# Does this feature have a property named popupContent?
|
|
|
|
if (feature.properties && feature.properties.popupContent)
|
|
|
|
layer.bindPopup feature.properties.popupContent
|
2014-10-28 00:23:11 +01:00
|
|
|
|
2016-04-16 23:08:03 +02:00
|
|
|
map.addLayer layer
|
2016-05-21 23:15:49 +02:00
|
|
|
controls.addOverlay layer, text + ' - ' + json.length
|
2016-04-16 23:08:03 +02:00
|
|
|
|
2016-06-25 16:16:05 +02:00
|
|
|
if (/maps\//.test(location.href) || /maps.json/.test url) && layer.getBounds()._northEast && layer.getBounds()._southWest
|
2016-04-16 23:08:03 +02:00
|
|
|
# Automatic focus to all displayed events
|
|
|
|
map.fitBounds layer.getBounds()
|
2014-08-23 16:59:42 +02:00
|
|
|
|
2016-04-09 16:06:22 +02:00
|
|
|
$('#map.event, #map.orga').each ->
|
2014-10-28 00:23:11 +01:00
|
|
|
coord = [$(this).data('latitude'), $(this).data('longitude')]
|
2014-08-02 15:51:45 +02:00
|
|
|
|
2014-08-23 16:59:42 +02:00
|
|
|
map = L.map('map').setView [coord[0], coord[1]], 16
|
|
|
|
|
2014-10-05 13:35:42 +02:00
|
|
|
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
|
2014-08-23 16:59:42 +02:00
|
|
|
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a>'
|
2014-07-31 01:32:47 +02:00
|
|
|
).addTo map
|
|
|
|
|
2014-10-29 11:42:07 +01:00
|
|
|
url = $(this).data 'url'
|
2016-05-22 01:23:17 +02:00
|
|
|
markerColor = markerColors[idx++ %% markerColors.length]
|
2014-12-13 12:32:05 +01:00
|
|
|
if location.search && url.indexOf('?') >= 0
|
2014-10-29 11:42:07 +01:00
|
|
|
url += '&' + location.search.substr 1
|
|
|
|
else
|
|
|
|
url += location.search
|
|
|
|
|
2016-05-23 01:11:22 +02:00
|
|
|
# Marker with the proper icon
|
|
|
|
marker = L.AwesomeMarkers.icon
|
|
|
|
prefix: 'fa',
|
|
|
|
icon: 'calendar'
|
|
|
|
L.marker([coord[0], coord[1]], icon: marker).addTo map
|
2016-05-22 01:12:30 +02:00
|
|
|
|
2014-10-29 11:42:07 +01:00
|
|
|
$.getJSON url, (json) ->
|
2016-04-16 23:08:03 +02:00
|
|
|
layer = L.markerClusterGroup(maxClusterRadius: 30).addLayer L.geoJson json,
|
2016-05-22 01:12:30 +02:00
|
|
|
pointToLayer: (feature, latlng) ->
|
2016-05-22 01:23:17 +02:00
|
|
|
# Marker with the proper icon
|
|
|
|
marker = L.AwesomeMarkers.icon
|
|
|
|
prefix: 'fa',
|
|
|
|
icon: feature.properties.icon || 'calendar',
|
|
|
|
markerColor: markerColor
|
2016-05-22 01:12:30 +02:00
|
|
|
L.marker latlng, icon: marker
|
|
|
|
,
|
2014-07-31 01:32:47 +02:00
|
|
|
onEachFeature: (feature, layer) ->
|
|
|
|
# Does this feature have a property named popupContent?
|
|
|
|
if (feature.properties && feature.properties.popupContent)
|
2014-09-21 14:32:59 +02:00
|
|
|
layer.bindPopup(feature.properties.popupContent)
|
2014-08-23 16:59:42 +02:00
|
|
|
|
2016-04-16 23:08:03 +02:00
|
|
|
map.addLayer layer
|