Sunday 9 February 2020

javascript - allow client to upload Layers to Openlayers 3


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.



Answer



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)


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...