1

I am having trouble executing WPS processes with the OpenLayers WPS Client. I can execute the processes in Geoserver, however when I try to execute the process from my OpenLayers test app I keep getting errors in my browsers javascript console relating to JSON and xmlhttprequest.

My JS code for creating the client, geometry and executing the process is below - In the Javascript console I can see the WPS XML and it all looks well formed and good to go. Is the issue with my code trying to decipher the results? JS console image below.

enter image description here

    runoff = OpenLayers.Geometry.fromWKT('Point(148 -36)');

client = new OpenLayers.WPSClient({
    servers: {
        local: '/geoserver/wps'
    }
});

client.execute({
        server: 'local',
        process: 'gs:PointBuffers',
        inputs: {
            center: runoff,
            crs: 'EPSG:4326',
            distance: 1000
        },
        success: function(outputs) {
            for (var i=0, ii=outputs.result.length; i<ii; ++i) {
            alert(outputs.result[i].geometry.toString());
        }
        }
    });

Thanks Andrew

  • Ando, I have the same problem "Uncaught SyntaxError: Unexpected token <" the line is #97 "object = JSON.parse(json,filter); Have you found solution???????? – Lefox Mar 30 '14 at 6:48
  • Hey Lefox - I ended up building the WPS request in a different way and sending it to the server by OpenLayers Post request as shown in this SE article gis.stackexchange.com/questions/29382/… . Basically I copied the WPS request from Geoserver, stored it in a variable then used it in the Openlayers Post Request. A guy at work thinks the error is to do with my JSON response, he said that these issues tend to pop up when you receive a different mime type than the one you request or vice versa?! Not sure if this qualifies as a solution but it worked. – Ando Apr 1 '14 at 23:05
  • 1 vote for Ando, it runs smoothly. thks – Lefox Apr 4 '14 at 6:20
2

It looks to me that the problem is about the runoff variable (WKT) you're passing, because JS console is complaining about an unexpected token, probably you need to wrap your geometry with double quotes rather than single quotes as shown here:

Here you can find some more discussions about it: https://stackoverflow.com/questions/7936610/json-uncaught-syntaxerror-unexpected-token

| improve this answer | |
  • Unfortunately I keep getting the same result. – Ando Feb 1 '14 at 9:59
  • even though you use the WKT in the same way of the jsfiddle example? in any case, it would be good if you post code of the pointed lines in the console. – Gery Feb 1 '14 at 10:12
  • The lines that are mentioned in the JS console are referring to JS files that I have not created. I formed the WKT as you had in your JS fiddle example – Ando Feb 2 '14 at 20:14
  • what do they say? that's the question, you add that too to narrow down the problem. – Gery Feb 3 '14 at 17:52
  • The first error points to a line in the JSON.js file which reads "Uncaught SyntaxError: Unexpected token <" the line is #97 "object = JSON.parse(json,filter); – Ando Feb 3 '14 at 23:36
-1
<!DOCTYPE html>
<html>
  <head>
    <title>jts_buffer</title>
   <!-- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/openlayers/2.13.1/theme/default/style.css"> -->
     <link rel="stylesheet " href="http://dev.openlayers.org/theme/default/style.css">
    <!-- The line below is only needed for old environments like Internet Explorer and Android 4.x -->

<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/openlayers/2.13.1/lib/OpenLayers.js"></script> -->
<script src="http://dev.openlayers.org/OpenLayers.js"></script>
</head>
  <body>

   <div id="map" style="position: absolute;
    width: 800px;
    height: 802px;" ></div>
      <script>
 var map = new OpenLayers.Map({
        div: "map",
        allOverlays: true
    });
     var osm = new OpenLayers.Layer.OSM();
     var wpsClient = new OpenLayers.WPSClient({
    servers: {
        local: 'http://localhost:9999/geoserver/wps'
    } 
});
var wkt = new OpenLayers.Format.WKT();
var point = wkt.read(
   'POINT(615732.134982157 3344996.87257526)'
);

    var vectors = new OpenLayers.Layer.Vector("Vector Layer");
    vectors.addFeatures([point]);
    map.addLayers([osm, vectors] );

    map.zoomToMaxExtent();

    wpsClient.execute({
    server: 'local',
    process: 'JTS:buffer',
    inputs: {
        geom: point ,
   distance: 5000000,
   quadrantSegments : 0,
   capStyle : 'Round'
    },
    success: function(outputs) {
         for (var i=0, ii=outputs.result.length; i<ii; ++i) {
            console.log(outputs);

            var polygonFeature = wkt.read(outputs.result[i].geometry.toString());
            bounds = polygonFeature.geometry.getBounds();    
            vectors.addFeatures([polygonFeature]);
            map.zoomToExtent(bounds);
            //alert(outputs.result[i].geometry.toString());
        }
    }
});
</script>
  </body>
</html>
| improve this answer | |
  • 1
    this is an example of jts:buffer process please refer to it. – Pratishruti Dasgupta Jun 12 '19 at 8:59
  • All code and no explanatory text generates a "low quality post" review queue event. Please frame your answer with some context. – Vince Jun 12 '19 at 15:51

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.