0

I would like display in popup a various set of attributes depends of selected layer. I have:

    var selectControl =  new OpenLayers.Control.SelectFeature( 
    [layer1, layer2],
    { 
    clickout: true, toggle: false,
    multiple: false, hover: false,
    toggleKey: "ctrlKey", // ctrl key removes from selection
    multipleKey: "shiftKey" // shift key adds to selection
    }
);

and:

    function onFeatureSelect(event) {
    var feature = event.feature;
    var selectedFeature = feature;
    var text = ""
        if(feature.cluster) {
            for(var i=0; i<feature.cluster.length; i++) {
//and here should be something about which layer is selected eg. 
//if ( selectControl == layer1 ) 
//then {first set of attributes} else {second set of attributes} 
//... How to do htis? 
//This idea doesn't work, I received undefined value of attributes

text += [i+1]+". "+feature.cluster[i].attributes.gis_id +"<br>";
}
else {
    text = feature.attributes.gis_id;
    }
    var popup = new OpenLayers.Popup.FramedCloud("chicken", 
        feature.geometry.getBounds().getCenterLonLat(),
        new OpenLayers.Size(100,100),
        text,
        null, true, 
        onPopupClose,
        function() { controls['selectControl'].unselectAll(); }//
    );
    feature.popup = popup;
    feature.popup.closeOnMove = true;//
    map.addPopup(popup);
};

2 Answers 2

0

If you need to get attributes depending on the selected features and layers, you may need this one:

http://openlayers.org/dev/examples/select-feature-multilayer.html

then you can pass the selected info to the popup.

I'm wondering if you need to first make the popup and then there display the attributes. If so, this may help you out:

http://openlayers.org/dev/examples/light-basic.html

0
0

I find solution, ->event.feature.layer.name<-:

    if(feature.cluster && (event.feature.layer.name == 'Layer1')) 
    {...} else if {...} else {...}

It works fine.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.