开发者

How to access features of a loaded GML file in OpenLayers?

I seem not to be able to access features of a loaded GML file. I will use the 开发者_JAVA技巧basic example of OpenLayers to demonstrate what I want to do :

http://jsfiddle.net/AUbZn/14/

var map;

map = new OpenLayers.Map('map');
var wms = new OpenLayers.Layer.WMS("OpenLayers WMS", "http://vmap0.tiles.osgeo.org/wms/vmap0", {
    layers: 'basic'
});

var layer = new OpenLayers.Layer.Vector("GML", {
    strategies: [new OpenLayers.Strategy.Fixed()],
    protocol: new OpenLayers.Protocol.HTTP({
        url: "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%3D'http%3A%2F%2Fopenlayers.org%2Fdev%2Fexamples%2Fgml%2Fpolygon.xml'",
        format: new OpenLayers.Format.GML(),
    }),

});

console.log("Layer features # = " + layer.features.length) //a
console.log("Layer features = " + layer.features) //b

map.addLayers([wms, layer]);
map.zoomToExtent(new OpenLayers.Bounds(-3.92, 44.34, 4.87, 49.55));

Whatever I do I only get a = 0 and b = "" ... What am I getting wrong ?

Thanks !


I have found the solution in the option 'eventListeners.featuresadded' of the OpenLayers.Layer.Vector object.

eventListeners: {
    "featuresadded": dataLoaded
},

here is the working jsfiddle : http://jsfiddle.net/AUbZn/16/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜