blokmap/map.js

69 lines
2.2 KiB
JavaScript
Raw Normal View History

2014-12-11 17:26:15 +00:00
$(document).ready(function() {
var popuptemplate = Handlebars.compile($('#popup-template').html());
var RedIcon = L.Icon.Default.extend({
options: {
iconUrl: 'red-marker.png'
}
});
var redIcon = new RedIcon();
var BlueIcon = L.Icon.Default.extend({});
var blueIcon = new BlueIcon();
function onEachFeature(feature, layer) {
if (feature.properties) {
layer.bindPopup(popuptemplate(feature.properties));
}
}
function pointToLayer(feature, latlng) {
if (feature.properties) {
if (!feature.properties.hours.saturday && !feature.properties.hours.sunday) {
return L.marker(latlng, {icon:blueIcon});
}
}
return L.marker(latlng, {icon: redIcon});
}
var map = L.map('map').setView([51.0475378, 3.7261835], 13);
2014-12-14 18:52:25 +00:00
L.tileLayer('http://otile{s}.mqcdn.com/tiles/1.0.0/map/{z}/{x}/{y}.jpeg', {
2014-12-14 19:24:13 +00:00
attribution: 'Made with ❤ by <a href="http://zeus.ugent.be">Zeus WPI</a> | Tiles Courtesy of <a href="http://www.mapquest.com/">MapQuest</a> | Map data &copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
2014-12-14 18:52:25 +00:00
subdomains: '1234'
}).addTo(map);
2014-12-11 17:26:15 +00:00
$.getJSON('data.json')
2014-12-11 21:54:02 +00:00
.done(function(data) {
2014-12-11 17:26:15 +00:00
var geojson = L.geoJson(data, {
onEachFeature: onEachFeature,
pointToLayer: pointToLayer
});
map.addLayer(geojson);
});
2014-12-11 21:54:02 +00:00
var SimpleControl = L.Control.extend({
initialize: function(templateId, divClass, options) {
this.template = Handlebars.compile($(templateId).html());
this.divClass = divClass;
L.Util.setOptions(this, options);
},
2014-12-11 17:26:15 +00:00
2014-12-11 21:54:02 +00:00
onAdd: function (map) {
this._div = L.DomUtil.create('div', this.divClass);
this._div.innerHTML = this.template();
2014-12-11 17:26:15 +00:00
2014-12-11 21:54:02 +00:00
return this._div;
}
});
2014-12-11 17:26:15 +00:00
2014-12-11 21:54:02 +00:00
var info = new SimpleControl('#info-template', 'info', {
position: 'topright'
}).addTo(map);
2014-12-11 17:26:15 +00:00
2014-12-11 21:54:02 +00:00
var sharePane = new SimpleControl('#share-template', 'info', {
position: 'bottomleft'
}).addTo(map);
2014-12-11 17:26:15 +00:00
2014-12-11 21:54:02 +00:00
var legend = new SimpleControl('#legend-template', 'legend', {
2014-12-12 08:50:35 +00:00
position: 'bottomright'
2014-12-11 21:54:02 +00:00
}).addTo(map);
2014-12-11 17:26:15 +00:00
});