2

I found this example here - (question details for example). It allows to get all the features in the drawn polygon. It's almost what i needed, but instead of drawing, I want when clicking on the feature of the upper layer(layerA) to get all the feature info of layer B within polygon of layerA.

Here is two layers that I have:

Layer A

var layerA = new ol.layer.Image({
    source: new ol.source.ImageWMS({
        url: 'https://xxxxxxx/geoserver/xxx/wms',
        params: {LAYERS: 'xxx:xxxa', 'TILED':true, 'format':'image/png8'},
        serverType: 'geoserver',
        ratio: 1,
    }),
    minZoom: 10,
    visible: true,
})
map.addLayer(layerA);

Layer B

var layerB = new ol.layer.Image({
    source: new ol.source.ImageWMS({
        url: 'https://xxxxxxx/geoserver/xxx/wms',
        params: {LAYERS: 'xxx:xxxb', 'TILED':true, 'format':'image/png8'},
        serverType: 'geoserver',
        ratio: 1,
    }),
    minZoom: 10,
    visible: true,
})
map.addLayer(layerB);

By this way I can get feature info but only at click position:

function showInfo(coord, resol) {
  var content = document.getElementById('info');
  var url = layerA.getSource().getFeatureInfoUrl(
    coord,
    resol,
    'EPSG:3857',
    {
      'INFO_FORMAT': 'application/json',
      'propertyName':'name,id'
    },
  );
  if(url) {
    $.getJSON(url, function(data) {
      var feature = data.features[0];
      var props = feature.properties;
      content.innerHTML = '<h5>name : </h5><p>' + props.name + '</p>' + ...
    });
    }
  else {
    content.innerHTML = ''
  }
}

map.on('click', function(evt) {
  showInfo(evt.coordinate, map.getView().getResolution());
})
6
  • The example you are citing does not give all the feature within drawn polygon, but all the features within bounding box of drawn polygon.
    – TomazicM
    Dec 14, 2022 at 9:51
  • As you say. But it's almost like what i wanted. Instead of all the features within bounding box, I want to get all info feature of layerB within polygon of feature from layerA.
    – Jayzz
    Dec 14, 2022 at 10:05
  • The example you are citing deals with vector layer. You can't achieve what you want with WMS layer, since here you can only get feature info for specified point.
    – TomazicM
    Dec 14, 2022 at 10:30
  • Is it possible to use getFeaturesAtCoordinate or getFeaturesInExtent? I can only use WMS because the layer data is so large. Or some way I can achieve what I want
    – Jayzz
    Dec 14, 2022 at 10:33
  • getFeatureInfoUrl with CQL filter (using operator INTERSECTS) might work, but that's not my area of knowledge, so I can't help you here.
    – TomazicM
    Dec 14, 2022 at 11:24

0

Your Answer

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

Browse other questions tagged or ask your own question.