[GIS] add text layer in openlayers

coordinatesjavascriptopenlayersopenstreetmap

I have a text file that contains longitude and latitude of some items. How can i load this file onto a map?

<script src="http://openlayers.org/en/v3.0.0/build/ol.js" type="text/javascript"></script>
<script>
var attribution = new ol.control.Attribution({
                                    collapsible: false
                                });
                                var maptwo = new ol.Map({
                                    target: 'maptwo',
                                    layers: [
                                        new ol.layer.Tile({
                                            source: new ol.source.OSM()
                                        })
                                    ],
                                    controls: ol.control.defaults({attribution: false}).extend([attribution]),
                                    view: new ol.View({
                                        center: ol.proj.transform([37.41, 8.82], 'EPSG:4326', 'EPSG:3857'),
                                        zoom: 2
                                    })
                                });
</script>

                            <style>
                                .maptwo {
                                    height: 100%;
                                    width:100%;
                                }
                            </style>

Best Answer

You can look at this OpenLayers 3 sample I produced some time ago. It relies on the library csv2geojson.

I choose this solution because there are no native CSV support in OpenLayers 3 but GeoJSON is well supported.