Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I did an implementation similar to http://openlayers.org/dev/examples/sundials.html The difference is that I have two or more kml layers at the same location and want to show their information combined.

The problem is that the featureselected layer's event fires only once, for the top most kml layer.

Does anyone know how to get this working, or a possible workarround?

Here is my code:

function createFetureInfoService() {
var wmsServerArray = [];
var dictionary = {};
var items = [];
var location;

for (var i = 0; i < wmsControls.length; i++) {
    wmsControls[i].deactivate();
}

for (var i = 0; i < kmlControls.length; i++) {
    mapa.removeControl(kmlControls[i]);
    kmlControls[i].deactivate();
}

kmlControls.length = 0;
wmsControls.length = 0;
totalWMSServerCount = 0;
currentWMSServerCount = 0;
totalKMLCount = 0;
currentKMLCount = 0;

for (var i = 0; i < mapa.getNumLayers(); i++) {
    layer = mapa.layers[i];
    if ((layer instanceof OpenLayers.Layer.WMS) && !layer.isBaseLayer) {
        if (!dictionary.hasOwnProperty(layer.url)) {
            totalWMSServerCount++;
            wmsServerArray.push(layer.url);
            dictionary[layer.url] = "";
        }
    }
    else if ((layer instanceof OpenLayers.Layer.Vector) && (layer.hasOwnProperty("options")) && (layer.options.hasOwnProperty("protocol")) &&
    (layer.options.protocol.hasOwnProperty("format")) && (layer.options.protocol.format instanceof OpenLayers.Format.KML) && !layer.isBaseLayer) {
        layer.displayOutsideMaxExtent = true;
        select = new OpenLayers.Control.SelectFeature(layer);
        kmlControls.push(select);
        layer.events.on({
            featureselected: function (e) {
                var feature = e.feature;
                location = e.xy;
                items.push({
                    xtype: "propertygrid",
                    autoHeight: true,
                    title: feature.layer.name,
                    source: feature.attributes
                });
                currentKMLCount++;
                showGetFeaturePopup(items, location);
                feature.layer.selectedFeatures.length = 0;
            }
        });
        mapa.addControl(select);
        select.activate();
    }
}

for (var i = 0; i < wmsServerArray.length; i++) {
    var wmsFeatureInfo = new OpenLayers.Control.WMSGetFeatureInfo({
        url: wmsServerArray[i],
        map: mapa,
        infoFormat: "application/vnd.ogc.gml"
    });
    wmsControls.push(wmsFeatureInfo);
    wmsFeatureInfo.events.on({
        getfeatureinfo: function (e) {
            location = e.xy;
            Ext.each(e.features, function (feature) {
                items.push({
                    xtype: "propertygrid",
                    autoHeight: true,
                    title: feature.fid,
                    source: feature.attributes
                });
            });
            currentWMSServerCount++;
            showGetFeaturePopup(items, location);
        },
        beforegetfeatureinfo: function (e) {
            this.layers = filterQueryableLayers(this.url);
            },
        nogetfeatureinfo: function (e) {
            currentWMSServerCount++;
            showGetFeaturePopup(items, location);
        }
    });
    wmsFeatureInfo.activate();
} 

}

function showGetFeaturePopup(items, location) {
totalKMLCount = 0;
var layers = mapa.getLayersBy("visibility", true);    
for (var i = 0, len = layers.length; i < len; i++) {
    if ((layers[i] instanceof OpenLayers.Layer.Vector) && (layers[i].hasOwnProperty("options")) && (layers[i].options.hasOwnProperty("protocol")) &&
    (layers[i].options.protocol.hasOwnProperty("format")) && (layers[i].options.protocol.format instanceof OpenLayers.Format.KML) && !layers[i].isBaseLayer) {
        totalKMLCount++;
    }
}

if ((currentWMSServerCount + currentKMLCount) < (totalWMSServerCount + totalKMLCount))
    return;
currentWMSServerCount = 0;
currentKMLCount = 0;

if (items.length == 0)
    showInfoPopup(mapa.getLonLatFromPixel(location), 'Nenhuma informa\u00E7\u00E3o dispon\u00EDvel');
else {
    var popUp = new GeoExt.Popup({
        title: "Informa\u00E7\u00E3o sobre as Camadas WMS",
        layout: "accordion",
        anchored: false,
        resizable: true,
        map: mapa,
        location: location,
        items: items,
        autoScroll: true,
        width: 600,
        height: 600,
        unpinnable: false,
        draggable: true,
        closeAction: 'hide'
    });
    popUp.show();
}
items.length = 0;

}

share|improve this question

1 Answer 1

Try to change file extension from kml to xml

share|improve this answer

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

3  
Could you edit your answer to add some more details, such as why you think this will help? –  BradHards Nov 14 '13 at 7:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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