0

How can i download zip file, made by geoserver WFS request, implemented in javascript? i'm using OpenLayers.Request.POST to send request.

  • It isn't very clear what you want here. Can you try to expand your question to a few paragraphs, perhaps showing what you're actually sending, what results you get, and what you expect to happen instead? – BradHards Feb 15 '15 at 3:30
2

You could use a hidden form to realize that:

Button to start the Download:

    <input type="button" value="Download Layer Streams as Shapefile (ZIP)" 
     onclick="shapedownload('og:streams')">

Function to be called:

function shapedownload(layername) {

    var form = document.createElement("form");
    form.method = "POST";
    form.action = "http://demo.opengeo.org/geoserver/wfs?";

    // set options here

    var input = document.createElement("input");
    input.type = "hidden";
    input.name = "request";
    input.value = "GetFeature";
    form.appendChild(input);

    // repeat the above 5 lines for all parameters

    var input = document.createElement("input");
    input.type = "hidden";
    input.name = "service";
    input.value = "WFS";
    form.appendChild(input);


    var input = document.createElement("input");
    input.type = "hidden";
    input.name = "version";
    input.value = "1.0.0";
    form.appendChild(input);


    var input = document.createElement("input");
    input.type = "hidden";
    input.name = "outputFormat"
    input.value = "shape-zip";
    form.appendChild(input);


    var input = document.createElement("input");
    input.type = "hidden";
    input.name = "typeName";
    // input.value="og:archsites";  // static layername replaced by parameter
    input.value = layername;
    form.appendChild(input);


    document.body.appendChild(form);
    form.submit();

    //  see http://lists.osgeo.org/pipermail/openlayers-users/2011-July/021473.html 

}

It's not incredibly elegant code but it works ;)

If you change the parameter with which you want to call the function you can download different layers, for example replace 'og:streams' with 'og:roads'.

Here is a working jsfiddle: http://jsfiddle.net/expedio/vjasu3k8/

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.