BORUSSEN11
BORUSSEN11

Reputation: 65

get overlapping features informations on popup using WFS layer in Openlayers 3

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

Answers (1)

Sumanth Shastry
Sumanth Shastry

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

Related Questions