62 lines
2.2 KiB
CoffeeScript
62 lines
2.2 KiB
CoffeeScript
# Setting up OpenStreeMap from a generic #map element
|
|
$(document).ready ->
|
|
$('#map.list').each ->
|
|
map = L.map 'map'
|
|
|
|
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
|
|
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a>'
|
|
).addTo map
|
|
|
|
controls = L.control.layers(null, null, collapsed: false).addTo map
|
|
|
|
$('li a', this).each ->
|
|
url = $(this).attr 'href'
|
|
text = $(this).html()
|
|
if location.search && url.indexOf('?') >= 0
|
|
url += '&' + location.search.substr 1
|
|
else
|
|
url += location.search
|
|
|
|
$.getJSON url, (json) ->
|
|
if json
|
|
count = 0
|
|
layer = L.markerClusterGroup(maxClusterRadius: 30).addLayer L.geoJson json,
|
|
onEachFeature: (feature, layer) ->
|
|
# Does this feature have a property named popupContent?
|
|
if (feature.properties && feature.properties.popupContent)
|
|
layer.bindPopup feature.properties.popupContent
|
|
count++
|
|
|
|
map.addLayer layer
|
|
controls.addOverlay layer, text + ' - ' + count
|
|
|
|
if (location.href.contains('maps/') || url.contains('maps.json')) && layer.getBounds()._northEast && layer.getBounds()._southWest
|
|
# Automatic focus to all displayed events
|
|
map.fitBounds layer.getBounds()
|
|
|
|
$('#map.event, #map.orga').each ->
|
|
coord = [$(this).data('latitude'), $(this).data('longitude')]
|
|
|
|
map = L.map('map').setView [coord[0], coord[1]], 16
|
|
|
|
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
|
|
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a>'
|
|
).addTo map
|
|
|
|
url = $(this).data 'url'
|
|
if location.search && url.indexOf('?') >= 0
|
|
url += '&' + location.search.substr 1
|
|
else
|
|
url += location.search
|
|
|
|
$.getJSON url, (json) ->
|
|
layer = L.markerClusterGroup(maxClusterRadius: 30).addLayer L.geoJson json,
|
|
onEachFeature: (feature, layer) ->
|
|
# Does this feature have a property named popupContent?
|
|
if (feature.properties && feature.properties.popupContent)
|
|
layer.bindPopup(feature.properties.popupContent)
|
|
|
|
map.addLayer layer
|
|
|
|
marker = L.marker([coord[0], coord[1]]).addTo map
|