let generateMap = () => {
let recentPoints = JSON.parse(jQuery("div#geojson-data-holder > div").text())
let lastPoint = recentPoints.features[recentPoints.features.length-1]
let map = L.map('geojson-map-holder').setView([lastPoint.geometry.coordinates[1], lastPoint.geometry.coordinates[0]], 13);
L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw', {
maxZoom: 18,
attribution: 'Map data © <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, ' +
'<a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ' +
'Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
id: 'mapbox.light'
}).addTo(map);
var baseballIcon = L.icon({
iconUrl: 'baseball-marker.png',
iconSize: [32, 37],
iconAnchor: [16, 37],
popupAnchor: [0, -28]
});
function onEachFeature(feature, layer) {
var popupContent = (new Date(feature.properties.tst * 1000)).toString();
if (feature.properties && feature.properties.popupContent) {
popupContent += feature.properties.popupContent;
}
layer.bindPopup(popupContent);
}
L.geoJSON(recentPoints, {
filter: function (feature, layer) {
if (feature.properties) {
return feature.properties.underConstruction !== undefined ? !feature.properties.underConstruction : true;
}
return false;
},
onEachFeature: onEachFeature
}).addTo(map);
}
jQuery('head').append('<link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.1/dist/leaflet.css">');
jQuery.getScript( "https://unpkg.com/leaflet@1.3.1/dist/leaflet.js", function() { generateMap() });