Announcement

Collapse
No announcement yet.

WMS GetFeatureInfo

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • WMS GetFeatureInfo

    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 as pickEnabled is one of the member variables, however this doesn't return the features of WMS.

    Code:
    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.

    Code:
    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);
    Thanks for your time.
    Last edited by kilsedar; 03-12-2018, 01:17 PM.

  • #2
    kilsedar, You seem to be using the right components here, but what you're doing with them doesn't make sense to me. What are you trying to accomplish, at a high level?
    Dave
    WW Team

    Comment


    • #3
      I need to query the features in the layer, as per feature there is an attribute with values that I will use to draw a chart. There are two things I can do. First one is using WMS and WMS GetFeatureInfo to get the attributes of the feature. Or I can use GeoJSON and query each point. I could not achieve neither so far.

      I tried to add GeoJSON (http://ugbd.get-it.it/proxy/?proxyTo...putFormat=json) to the globe, however this is not placed on the map. I downloaded the data and removed the crs attribute at the end, in which case it works. So, another question would be is it possible to make GeoJSON from GeoServer work? Second question would be can I query the GeoJSON? The approach I can think of for this is to get the GeoJSON, create placemarks in a loop assigning the features as the labels of the userObject, and then query placemarks with picking. Is this the suggested way?

      Thank you for your time.

      Comment


      • #4
        GeoJSON is likely a better choice given what you're trying to do. Vector features are pickable in WorldWind, and that includes GeoJSON. Let's get into the specific details of what you need to make this work:

        1. What is it about GeoJSON from GeoServer that does not seem to work?
        2. Yes, picking vector features is the suggested way to enable user interaction with the map. Are you encountering any issues doing that?
        Dave
        WW Team

        Comment


        • #5
          1. What makes GeoJSON from GeoServer not working is the way CRS is defined, more specifically '"crs":{"type":"EPSG","properties":{"cod e":"4326"}}' at the end of the GeoJSON file. First, in the setCRSString function in the GeoJSONCRS class, since both this.isNamed() and this.isLinked() return false, in the GeoJSONParser class in the setGeoJSONCRS function this.addRenderablesForGeoJSON(this.layer ) is never executed for this layer.

          And then even if I add
          else {
          crsCallback();
          }
          to the setCRSString function to avoid this, in the addRenderablesForPoint function if (!this.crs || this.crs.isCRSSupported()) will not return true, so the placemarks will not be added.

          Sorry for this detailed explanation, in short the way the CRS defined for this layer is not supported by the WorldWind library.

          2. I can pick the vector features, but as far as I can see the properties of features in the GeoJSON is not in the attributes of the Placemark or the PickedObject, or maybe I am missing it.

          Thank you for your time.

          Comment


          • #6
            I could achieve the same as below, but I preferred initially to rely on the GeoJSON object.

            var placemark;
            var placemarkLayer = new WorldWind.RenderableLayer("Placemarks");
            var placemarkAttributes = new WorldWind.PlacemarkAttributes(null);
            placemarkAttributes.imageSource = "WebWorldWind-develop/images/pushpins/push-pin-yellow-32.png";
            placemarkAttributes.imageOffset = new WorldWind.Offset(WorldWind.OFFSET_FRACTI ON, 0.3, WorldWind.OFFSET_FRACTION, 0.0);
            var highlightAttributes = new WorldWind.PlacemarkAttributes(placemarkA ttributes);
            highlightAttributes.imageScale = 1.2;
            var highlightedItems = [];
            var redrawRequired = false;

            $.ajax({
            dataType: "json",
            url: "http://ugbd.get-it.it/proxy/?proxyTo=http://ugbd.get-it.it/geoserver/geonode/ows?service=WFS&version=1.0.0&request=Ge tFeature&typeName=geonode:NAPOLI_DEFORMA ZIONE_MAP&outputFormat=json",
            success: function(data) {
            for (var i = 0; i < data.features.length; i++) {
            placemark = new WorldWind.Placemark(new WorldWind.Position(data.features[i].geometry.coordinates[1], data.features[i].geometry.coordinates[0], 1e2), true, null);
            placemark.label = {"average_velocity": data.features[i].properties.vel, "time_series": data.features[i].properties.wfs_ts};
            placemark.altitudeMode = WorldWind.RELATIVE_TO_GROUND;
            placemark.attributes = placemarkAttributes;
            placemark.highlightAttributes = highlightAttributes;
            placemarkLayer.addRenderable(placemark);
            }
            worldWindow.addLayer(placemarkLayer);
            }
            });

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

            if (highlightedItems.length > 0)
            redrawRequired = true;

            for (var h = 0; h < highlightedItems.length; h++) {
            highlightedItems[h].highlighted = false;
            }
            highlightedItems = [];

            var pickList = worldWindow.pick(worldWindow.canvasCoord inates(x, y));
            if (pickList.objects.length > 0) {
            redrawRequired = true;
            for (var i = 0; i < pickList.objects.length; i++) {
            if(pickList.objects[i].userObject.label != undefined) {
            pickList.objects[i].userObject.highlighted = true;
            highlightedItems.push(pickList.objects[i].userObject);
            console.log(pickList.objects[i].userObject.label);
            }
            }
            }
            if (redrawRequired)
            worldWindow.redraw();
            };
            worldWindow.addEventListener("click", handlePick);
            Last edited by kilsedar; 03-21-2018, 11:46 AM.

            Comment


            • #7
              Thanks for the details, kilsedar.

              1. We'll need the ESA WorldWind development team to look into this GeoJSON CRS incompatibility in more detail. They're out of the office this week. Do whatever you can to work around it for the moment.

              2. Use GeoJSONParser's shapeConfigurationCallback to augment the picked object that gets returned. For example:
              Code:
              GeoJSONParser parser;
              function myConfigCallback (geometry, properties) {
              var config = parser.defaultShapeConfigurationCallback (geometry, properties);
              // Causes the GeoJSON attribute-value pairs to be stored in the WorldWind Renderable's userProperties bundle.
              // Look for pickedObject.userObject.userProperties during picking.
              config.userProperties = properties;
              return config.
              }
              Dave
              WW Team

              Comment

              Working...
              X