I just used a leaflet. From the geoJSON demo page I saw if you want to include data you have to use
<script src="data/us-states.geojson"></script>
and if you open the files looks like
var ustates = {
"type": "FeatureCollection",
......
[]
};
and if you want to call them use
var data = [ustates] ;
Is there another way to call the data?
The geojson file that I have has no initial variable and looks like this:
{
"type": "FeatureCollection",
......
[]
}
I have lots of data and I have to open 1 by 1 to add variable on geojson data so I mean can I just call the data like
var ustates = <?php include "data/us-states.geojson"; ?>
var data = [ustates];
Best Answer
We use this function in our project (credits go to Roberto MF):
It uses the Fetch API to download the file. You can simply use your path
data/us-states.geojson
asurl
. Example with your data:Be aware that this doesn't work in Internet Explorer by default, but you can polyfill it by adding these lines to your HTML-
<head>
: