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());
})
info feature
oflayerB
within polygon offeature
fromlayerA
.getFeaturesAtCoordinate
orgetFeaturesInExtent
? I can only use WMS because the layer data is so large. Or some way I can achieve what I wantgetFeatureInfoUrl
with CQL filter (using operatorINTERSECTS
) might work, but that's not my area of knowledge, so I can't help you here.