I have csv files with coordinates, I was wondering how to read the coordinates directly and render them on the map. It seems openlayers two OpenLayers.Format.Text
before, but I can not find similar options in ol4
You have multiple choices.
You can use a third party library that convert CSV to GeoJSON and consume the GeoJSON using ol.format.GeoJSON
. I have a demo that just do that.
You could also convert CSV to JSON with a library like d3-fetch (not tied to D3 nowadays contrary to what the naming could suggest) or another "csv to json" JavaScript library. Then, you will create with more boilerplate code an array of ol.Feature
populated with ol.geom.Point
and your fields attributes and provide the array to an ol.source.Vector
attached to an ol.layer.Vector
.