How to load a shapefile in gwt-openlayers

190 views Asked by At

We're building an application using GWT-Openlayers (not OpenLayers) and need to allow the user to load a polygon from a shapefile. Surprisingly, there doesn't seem to be an evident solution. The closest solutions are javascript libraries for interpreting shapefiles, but a javascript solution doesn't really help in a GWT application. Any recommendations?

Thanks in advance!

1

There are 1 answers

0
Bill Compton On

Lacking a simpler solution, the approach I used was as follows:

  • Use GWT FormPanel and FileUpload to allow user to select the file to upload
  • Create a custom servlet for handling the request
  • FormPanel sends a multipart POST of the file contents to the servlet
  • Servlet feeds the file content to a parser to convert to Well Known Text (WKT)
  • Servlet returns the WKT in the HttpResponse
  • Client side code converts the WKT to a gwt-openlayers vector feature and adds it to the map

Certainly not an elegant solution but seems to work. If anyone finds a better solution, it would be great to hear.