I want to load an external geojson file into leaflet map. I created a global variable (i.e. tracts) for json file and referenced this variable in the script file. But i receive an error message that variable is not defined. Please check the below html and JS code.
I also tried using L.GeoJSON.AJAX call, but still the geojson external file is not loading up on the leaflet map and i get an error message that 'L.GeoJSON.AJAX is not a constructor'.
<script src="/js/leaflet-0.7.2/leaflet.ajax.min.js"></script>
</head>
<body>
<div id="mapid"></div>
<script src="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.js"></script>
<script src="Lscript.js"></script>
<script src="/files_leaflet/kc-tracts.js" type = "text/javascript">
</script>
## JavaScript
var map = L.map('mapid', {
center: [5, 28],
zoom: 3,
minZoom:2,
maxZoom:18
});
L.tileLayer('http://{s}.tiles.mapbox.com/v3/ianmule.bg2v5cdi/{z}/{x}/{y}.png', {
attribution: "Mapbox"
}).addTo(map);
L.geoJson(tracts, {
style: style,
onEachFeature: onEachFeature
}).addTo(map);
# Using Ajax call.
var mystyle = {
"color": "#ff7800",
"weight": 5,
"opacity": 0.65
};
var geoJsonLayer = new L.GeoJSON.AJAX("kc-tracts.js", {
style: mystyle });
geoJsonLayer.addTo(map);