I've searched far and wide and tried a number of different options but I cannot get more than one GeoJSON into my Leaflet web app. I can get one, and once I try anything else, the map itself will go blank!
Below is the code I have for the input of the first GeoJSON.
<script src="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.js"></script>
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="JSONFILE-1.js" type="text/javascript"></script>
<script src="JSONFILE-2.js" type="text/javascript"></script>
<style>
#my-map {
width:2000px;
height:1000px;
left: -50%;
top: 1%;
}
</style>
</head>
<body>
<div id="my-map"></div>
<script>
window.onload = function () {
var basemap = L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
});
$.getJSON("turk.geojson", function(data) {
var geojson = L.geoJson(data, {
onEachFeature: function (feature, layer) {
layer.bindPopup(feature.properties.Area_Name);
}
});
var map = L.map('my-map')
.fitBounds(geojson.getBounds());
// .setView([0.0,100], 2);
basemap.addTo(map);
geojson.addTo(map);
});
};
</script>
Below is the line I tried to add, I've tried 5 different solutions with no success.
$.getJSON("turk.geojson", function(data) {
var geojson = L.geoJson(data, {
onEachFeature: function (feature, layer) {
layer.bindPopup(feature.properties.Area_Name);
}
});
var myStyle = {
"color": "#ff7800",
"weight": 5,
"opacity": 0.65
};
var geojsonLayer = new L.GeoJSON.AJAX("data/tur_route_geo.geojson" , {style:myStyle});
var map = L.map('my-map')
.fitBounds(geojson.getBounds());
// .setView([0.0,100], 2);
basemap.addTo(map);
geojson.addTo(map);
geojsonLayer.addTo(map);
});
};
</script>
</body>
</html>
#error
127.0.0.1 - - [10/Jul/2019 10:03:39] "GET /tur_route_geo.geojson HTTP/1.1" 304 -
127.0.0.1 - - [10/Jul/2019 10:03:52] "GET / HTTP/1.1" 200 -