Load geojson data to HTML table
Load geojson data to HTML table
I'm using leafletjs map where I fetch two URL's that then draw circles in the map.
Also I added datpicker to show data based on range.
Now I would like that data which shows on the map based on date range also show beside the map in the table.
I have tried examples from this page but none of them shows anything in the table.
My code fetch URL in geojson
var FEED1 = 'https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_day.geojson';
Then here goes code which format circles on the map and below is code that fetch above FEED1 geojson
fetch(FEED1, {
method:'GET'
})
.then(r => r.json())
.then(json => {
console.log(json);
earthquakes.addData(json);
});
Please can you advise how to create table based on above_
Thanks
This question has an accepted answers - jump to answer
Answers
We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin
Thank you please check this
http://live.datatables.net/vabotoga/1/edit?html,js,console
I will update ajax url to FEED1 I mentioned at begining.
As you can see I tried and changed "data" to "features" as that s in geojson, then use "properties.mag" for example to pull that data and so on for others.
If I download geojson and point to that file then replace "feature" word with "data" it loads data but problem is as soon as I change word data to anything else it fails.
Also in this geojson line there are Type, metadata etc.
Your test case as an ajax error. This is the response from the server:
You need to use
columns.data
to define the object structure. Use theajax.dataSrc
to point Datatables to an alternate data location (features).I changed the URL to use the one in your original post and added
ajax.dataSrc
now this error is occurring:You have
{ "data": "properties.magtype" }
. The names are case sensitive. I changed the example to use{ "data": "properties.magType" }
.Now this error:
properties.lon
and some of the others you defined don't see to exist in the data. Maybe this exists in the URL you want to use but it sounds like you need to fix one or more of the parameters being sent.Updated example:
http://live.datatables.net/xewerara/1/edit
Kevin
Thank you.
In my live example my original link is used.
Please check this.
http://live.datatables.net/xewerara/1/edit?html,css,js,console
Not sure if you are asking a question or still having problems.
Kevin
Hi
still doesn't work. as per my example bellow.
http://live.datatables.net/xewerara/1/edit?html,css,js,console
I placed URL that I'm using and there is an error.
Checked case sensitive and other things but..
What is the URL?
What is the error?
Can you update the test case to show the error?
Kevin
Hi Kevin,
thank you for your effort.
It works if I save json locally and for ajax url set that local gjson file but via the URL it doesnt load.
Error is http://datatables.net/tn/7
here is the test
http://live.datatables.net/xewerara/6/edit?html,css,js,console,output
Web browser's won't allow for local file access via Ajax. See this thread for more details.
How are you fetching the json to save locally?
Can you update the test case with the URL you want to use?
Kevin
I open link which is FDSNWS with json format and just save it.
So when I load that file with ajax url it works but when I use full link then it provide an error I mentioned earlier.
I have updated that url in test example bellow.
Check this please.
http://live.datatables.net/xewerara/7/edit?html,css,js,console,output
Use the browser's network inspector to see what is returned and you will see this error:
Seems like the server doesn't like the cache option of
_=1623530
. You can usecache: true
to remove this option from the URL. See the jQuery ajax()](https://api.jquery.com/jquery.ajax/) docs for more details.You can use the
ajax.data
option as a function to dynamically build the parameters sent. See the example in the docs and this running example. I updated the example to show both of these changes:http://live.datatables.net/xewerara/8/edit
For simplicity I kept the starttime, endtime and format parameters.
Kevin
Thank you so much this solved this problem.
I have another one to solve as I fetch two urls in my code but I will try to solve it by myself as I saw some examples but not sure if it will work for me.