Search code examples
angularjsng-gridgeoserver

Angular and WFS


Is it possible to populate a AngularJS table (ui-grid) via a WFS GetFeatures call?

I've tried to methods:

Method 1:

    $http.get('http://WFSTestsite:8080/geoserver/test/wfsTest?service=WFS&version=1.0.0&request=GetFeature&typeName=test&maxFeatures=50&outputFormat=application/json')
  .success(function(data) {
    $scope.gridOptions.data = data;
  });

Method 2:

    $http.get('http://WFSTestSite:8080/geoserver/test/wfsTest', 
          { params: {
              service:"WFS"
              version:"1.0.0"
              request:"GetFeature"
              typeName:"test"
              outputFormat:"application/json"
              maxFeatures:"50"}}).success(function(data) {
                  $scope.gridOptions.data = data;
  });

Neither method seems to work. I'm having trouble finding any documentation on using Angular and WFS...is this not possible?


Solution

  • So I realized I was getting a Access-Control-Allow-Origin issue from the server...this was resolved by enabling CORS on the server. Once I did that Method 1 worked, but I had to change one line:

    instead of: $scope.gridOptions.data = data;

    I changed it to: $scope.gridOptions.data = data.features;

    Then it worked just fine.

    Hope this helps someone! :)