$( document ).ready(function() { // Defaults defaults = { lat: 47.218371, lng: -1.553621, zoom: 13, } // Create map var map = L.map('map', {scrollWheelZoom: false}).setView([defaults.lat,defaults.lng], defaults.zoom); L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { attribution: 'Map data © OpenStreetMap contributors, CC-BY-SA, Imagery © Mapbox', maxZoom: 18 }).addTo(map); // Get JSON var GeoJsonPath = $('#map').data('json') $.getJSON(GeoJsonPath, function(data){ function buildPopupContent(feature, layer) { feature.properties.popupContent = ''; if (feature.properties.name) { feature.properties.popupContent += '

#'+feature.id+': '+feature.properties.name+'

'; } else { feature.properties.popupContent += '

#'+feature.id+'

'; } if (feature.properties.place) { feature.properties.popupContent += '' } if (feature.properties.comment) { feature.properties.popupContent += '

'+feature.properties.comment+'

'; } layer.bindPopup(feature.properties.popupContent); } function drawSemiCircles(feature, layer) { orientations_to_angle = { 'N': 0, 'NO': -45, 'O': -90, 'SO': -135, 'S': 180, 'SE': 135, 'E': 90, 'NE': 45 }; if (feature.properties.place) { feature.properties.place.orientations.map(function(orien) { // Strangely enough, we need to invert the coordinates. L.circle([feature.geometry.coordinates[1], feature.geometry.coordinates[0]], 150) .setDirection(orientations_to_angle[orien], 45) .addTo(map); }); } } // Add to map var featureLayer = L.geoJson(data, { onEachFeature: function(feature, layer) { buildPopupContent(feature, layer); drawSemiCircles(feature, layer); } }).addTo(map); // Auto Zoom // Strange leaflet bug, we need to set a null timeout setTimeout(function () { map.fitBounds(featureLayer.getBounds()) }, 2); }); });