I want to allow the clients to add vector layers in form of a geojson to openlayers 3. It should look like in this fiddle . I know how to add multiple layers but I want the client to be able to add a Layer and see his added layer. The layer doesn't have to be saved for his next visit at the page.
there are two different way you can try,
1) you need to host your web server to receive the file that client uploaded. The file will be processed in your server and return the geojson file to the front-end.
here is an example (with php)
then you will get a geojson file to show in ol3.
2) the other one is using File API to process the file without write the server side code, and read the file content to show in ol3.
(this demo support .prj so no need to set EPSG and assign proper Encoding to show correct attribure in ol3)
I was able to upload a KML file at client side using HTML5 FileReader.readAsDataURL()
I followed this for uploading simple text file and restrict to kml files
Following the above tutorial, use reader.result as URL to set source of a vector layer to the kml file to be uploaded. Then add the vector layer on to the map object. I hope its clear if you have some experience with OpenLayers 3.