0

I have a WMS query with url like this.

http://giswebservices.massgis.state.ma.us/geoserver/wms?VERSION=1.1.1&REQUEST=GetFeatureInfo&LAYERS=massgis:GISDATA.ACECS_POLY&SRS=EPSG:26986&BBOX=11830.0,776202.9449152543,348201.0,961492.0550847457&WIDTH=708&HEIGHT=390&INFO_FORMAT=text/javascript&FEATURE_COUNT=10&QUERY_LAYERS=massgis:GISDATA.ACECS_POLY&X=120&Y=109&FORMAT&STYLES=&SERVICE=WMS

This url returns JSON result parseResponse( ...json...)

I want to create angularjs $http jsonp but it did not work.

function appCtrl($scope, $http){
    function parseResponse(data) {
        $scope.data = data
    } 

    var httpOptions = {
        url: "http://giswebservices.massgis.state.ma.us/geoserver/wms?VERSION=1.1.1&LAYERS=massgis:GISDATA.ACECS_POLY&SRS=EPSG:26986&BBOX=11830.0,776202.9449152543,348201.0,961492.0550847457&WIDTH=708&HEIGHT=390&INFO_FORMAT=text/javascript&FEATURE_COUNT=10&QUERY_LAYERS=massgis:GISDATA.ACECS_POLY&X=120&Y=109&FORMAT&STYLES=&SERVICE=WMS",
        method: "JSONP",
        params : {
            REQUEST: 'GetFeatureInfo',
        },
    };

    $http(httpOptions).
        success(function(data){
            console.log(data);
            $scope.data = data;
        }).
        error(function(data){
            console.log(data);
        });
}

This gives error "parseResponse is not defined" But I defined that function

2
  • Are you trying to do an http.get? Or how I'm interpreting, trying to ping a server and getting a json back? Commented Jul 15, 2014 at 18:04
  • I don't think you should modify your question to an entirely new question, else my answer doesn't make sense. Can you revert and ask a new question? Commented Jul 15, 2014 at 22:00

2 Answers 2

1

You can try set format_options in params, Because angularjs default callback function name is JSON_CALLBACK

var httpOptions = {
    url: "http://giswebservices.massgis.state.ma.us/geoserver/wms?VERSION=1.1.1&LAYERS=massgis:GISDATA.ACECS_POLY&SRS=EPSG:26986&BBOX=11830.0,776202.9449152543,348201.0,961492.0550847457&WIDTH=708&HEIGHT=390&INFO_FORMAT=text/javascript&FEATURE_COUNT=10&QUERY_LAYERS=massgis:GISDATA.ACECS_POLY&X=120&Y=109&FORMAT&STYLES=&SERVICE=WMS",
    method: "JSONP",
    params : {
        REQUEST: 'GetFeatureInfo',
        format_options: 'callback: JSON_CALLBACK'
    },
};
Sign up to request clarification or add additional context in comments.

Comments

0

Here is how to access your AngularJS callback result using jsonp:

http://jsfiddle.net/jCUSh/138/

function WMSCtrl($scope, $http) {
    $scope.nums = [1,2,3]
    $scope.data = null;
    $scope.get_data = function() {
      var url2 = 'http://giswebservices.massgis.state.ma.us/geoserver/wms?VERSION=1.1.1&LAYERS=massgis:GISDATA.ACECS_POLY&SRS=EPSG:26986&BBOX=11830.0,776202.9449152543,348201.0,961492.0550847457&WIDTH=708&HEIGHT=390&INFO_FORMAT=text/javascript&FEATURE_COUNT=10&QUERY_LAYERS=massgis:GISDATA.ACECS_POLY&X=120&Y=109&FORMAT&STYLES=&SERVICE=WMS'
      $http.jsonp(url2, {params : {REQUEST: 'GetFeatureInfo'}});
    }

    window.parseResponse = function(data) {
      $scope.data = data
    }
}

I took off a vital param on the url (which was REQUEST=GetFeatureInfo) and included it in the params argument on the jsonp function call to show an example of how the params arguments is passed.

7 Comments

how can I separate query string as json parameters and send
and why did you defined window.parseResponse?
Actually, here's a post that show's how you specify params in a jsonp call stackoverflow.com/questions/18676085/…
And I defined window.parseResponse to deliver the data out of the JSON callback, since it's wrapped in a parseResponse function. I assumed you just wanted the JSON?
Your solution is great, I tried this jsfiddle.net/barteloma/Wqu68 but can not catch callback and success function did not work
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.