2

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.

4

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.
dev.w3.org/2006/webapi/FileAPI/

i also make a pure javascript lib to convert zip file with shp, dbf to geojson, just like user upload their file and show in ol3.

(this demo support .prj so no need to set EPSG and assign proper Encoding to show correct attribure in ol3)

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.