1

I have been looking for ways to make a WMS GetFeatureInfo request using the API of NASA Web WorldWind, however have not achieved yet. I tried picking as below, however this doesn't return the features of WMS.

  var serviceAddress = "http://localhost:8080/geoserver/wms?service=WMS&version=1.3.0&request=GetCapabilities";
  var layerName = "ubgd:cucs2012_milan";

  var createLayer = function (xmlDom) {
      var wms = new WorldWind.WmsCapabilities(xmlDom);
      var wmsLayerCapabilities = wms.getNamedLayer(layerName);
      var wmsConfig = WorldWind.WmsLayer.formLayerConfiguration(wmsLayerCapabilities);
      wmsConfig.title = "Milan - 2012";
      var wmsLayer = new WorldWind.WmsLayer(wmsConfig);
      worldWindow.addLayer(wmsLayer);
  };

  var logError = function (jqXhr, text, exception) {
    console.log("There was a failure retrieving the capabilities document: " + text + " exception: " + exception);
  };

  $.get(serviceAddress).done(createLayer).fail(logError);

  var handlePick = function(o) {
    var x = o.clientX, y = o.clientY;

    var pickList = worldWindow.pick(worldWindow.canvasCoordinates(x, y));
    if (pickList.objects.length > 0) {
      for (var i=0; i<pickList.objects.length; i++) {
        console.log(i);
        console.log(pickList.objects[i].userObject);
      }
    }
  };
  worldWindow.addEventListener("click", handlePick);

The pickList object returned looks to be the globe only, whether I click on the WMS layer or not.

Below is another trial, where I construct the URL myself, however this returns values even when I do not click on the layer. I suppose the URL has some wrong parameters. I believe x, y, width and height should be of the WMS layer, not the canvas, but I do not know how to get these values.

  var serviceAddress = "http://localhost:8080/geoserver/wms?service=WMS&version=1.3.0&request=GetCapabilities";
  var layerName = "ubgd:cucs2012_milan";
  var bbox;

  var createLayer = function (xmlDom) {
      var wms = new WorldWind.WmsCapabilities(xmlDom);
      var wmsLayerCapabilities = wms.getNamedLayer(layerName);
      bbox = wmsLayerCapabilities._boundingBoxes[1].miny + "," + wmsLayerCapabilities._boundingBoxes[1].minx + "," + wmsLayerCapabilities._boundingBoxes[1].maxy + "," + wmsLayerCapabilities._boundingBoxes[1].maxx;
      var wmsConfig = WorldWind.WmsLayer.formLayerConfiguration(wmsLayerCapabilities);
      wmsConfig.title = "Milan - 2012";
      var wmsLayer = new WorldWind.WmsLayer(wmsConfig);
      worldWindow.addLayer(wmsLayer);
  };

  var logError = function (jqXhr, text, exception) {
    console.log("There was a failure retrieving the capabilities document: " + text + " exception: " + exception);
  };

  $.get(serviceAddress).done(createLayer).fail(logError);

  var handlePick = function(o) {
    var x = o.clientX, y = o.clientY;
    var width = worldWindow.canvas.width;
    var height = worldWindow.canvas.height;

    console.log(bbox);

    $.ajax({
      url: "http://localhost:8080/geoserver/ubgd/wms?service=WMS&version=1.1.1&request=GetFeatureInfo&layers=ubgd:cucs2012_milan&query_layers=ubgd:cucs2012_milan&styles=&bbox="+bbox
           +"&height=" + height + "&width=" + width + "&info_format=application/json&srs=EPSG:3035&x=" + x + "&y=" + y,
      dataType: "html",
      type: "GET",
      success: function(data){
        console.log(data);
      }
    });
  };
  worldWindow.addEventListener("click", handlePick);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.