blokmap/js/map.js

82 lines
2.7 KiB
JavaScript
Raw Normal View History

2014-12-11 18:26:15 +01:00
$(document).ready(function() {
/* change image path */
L.Icon.Default.imagePath = 'img';
2014-12-11 18:26:15 +01:00
var popuptemplate = Handlebars.compile($('#popup-template').html());
var RedIcon = L.Icon.Default.extend({
options: {
iconUrl: 'img/red-marker.png'
2014-12-11 18:26:15 +01:00
}
});
2015-12-24 17:50:50 +01:00
var ChristmasIcon = L.Icon.Default.extend({
options: {
iconUrl: 'img/christmas-marker.png'
}
});
2014-12-11 18:26:15 +01:00
var redIcon = new RedIcon();
var BlueIcon = L.Icon.Default.extend({});
var blueIcon = new BlueIcon();
2015-12-24 17:50:50 +01:00
var christmasIcon = new ChristmasIcon();
var christmasHoliday = Date.now() < new Date("2016-01-04").getTime();
2014-12-11 18:26:15 +01:00
function onEachFeature(feature, layer) {
if (feature.properties) {
layer.bindPopup(popuptemplate(feature.properties));
}
}
function pointToLayer(feature, latlng) {
if (feature.properties) {
2015-12-24 17:50:50 +01:00
if (feature.properties.holidays && christmasHoliday) {
return L.marker(latlng, {icon:christmasIcon});
}
2014-12-11 18:26:15 +01:00
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);
2016-05-14 14:37:30 +02:00
var osm = L.tileLayer('https://{s}.tiles.mapbox.com/v3/feliciaan.keoaj8d5/{z}/{x}/{y}{r}.png', {
2016-05-14 14:23:42 +02:00
attribution: '© <a href="https://www.mapbox.com/map-feedback/">Mapbox</a> | © <a href="https://www.openstreetmap.org/copyright" target="_blank">OpenStreetMap</a>-contributors | Made with ❤ by <a href="https://zeus.ugent.be">Zeus WPI</a>',
detectRetina: true
2015-02-13 18:52:57 +01:00
}).addTo(map);
2014-12-11 18:26:15 +01:00
$.getJSON('data.json')
2014-12-11 22:54:02 +01:00
.done(function(data) {
2014-12-11 18:26:15 +01:00
var geojson = L.geoJson(data, {
onEachFeature: onEachFeature,
pointToLayer: pointToLayer
});
map.addLayer(geojson);
});
2014-12-11 22:54:02 +01: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 18:26:15 +01:00
2014-12-11 22:54:02 +01:00
onAdd: function (map) {
this._div = L.DomUtil.create('div', this.divClass);
this._div.innerHTML = this.template();
2014-12-11 18:26:15 +01:00
2014-12-11 22:54:02 +01:00
return this._div;
}
});
2014-12-11 21:36:36 +01:00
2014-12-11 22:54:02 +01:00
var info = new SimpleControl('#info-template', 'info', {
position: 'topright'
}).addTo(map);
2014-12-11 21:36:36 +01:00
2014-12-11 22:54:02 +01:00
var sharePane = new SimpleControl('#share-template', 'info', {
position: 'bottomleft'
}).addTo(map);
2014-12-11 21:36:36 +01:00
2015-12-24 17:50:50 +01:00
var legend = new SimpleControl('#legend-template', christmasHoliday ? "holiday-legend" : "legend", {
2014-12-12 09:50:35 +01:00
position: 'bottomright'
2014-12-11 22:54:02 +01:00
}).addTo(map);
2014-12-11 18:26:15 +01:00
});