Reputation: 65
I'm trying to get information from WFS layer that contain several overlapping features. i use this function to get information but i receive juste the information of the top feature. Some one can help me ?
olMap.on('click', function(evt) {
var feature = olMap.forEachFeatureAtPixel(evt.pixel, function(feature, layer) {
return feature;
});
if (feature) {
var coordinate = evt.coordinate;
var viewResolution = /** @type {number} */ (view.getResolution());
var coord = feature.getGeometry().getCoordinates();
var props = feature.getProperties();
content.innerHTML = '<p><b>City</b>:'+props.nam+'<br> ZIP CODE:'+props.f_code+'</p>';
overlay.setPosition(coordinate);
}
else{
overlay.setPosition(undefined);
}
Upvotes: 0
Views: 414
Reputation: 1159
Dont return the feature from forEachFeatureAtPixel
method instead move if
code inside the that method only.
olMap.on('click', function(evt) {
var feature = olMap.forEachFeatureAtPixel(evt.pixel, function(feature, layer) {
var coordinate = evt.coordinate;
var viewResolution = /** @type {number} */ (view.getResolution());
var coord = feature.getGeometry().getCoordinates();
var props = feature.getProperties();
content.innerHTML = '<p><b>City</b>:'+props.nam+'<br> ZIP CODE:'+props.f_code+'</p>';
overlay.setPosition(coordinate);
});
Upvotes: 1