4

我似乎无法访问加载的 GML 文件的功能。我将使用 OpenLayers 的基本示例来演示我想要做什么:

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));

无论我做什么,我只会得到 a = 0 和 b = "" ...我做错了什么?

谢谢 !

4

1 回答 1

2

我在 OpenLayers.Layer.Vector 对象的选项“eventListeners.featuresadded”中找到了解决方案。

eventListeners: {
    "featuresadded": dataLoaded
},

这是工作的jsfiddle:http: //jsfiddle.net/AUbZn/16/

于 2011-06-03T14:16:37.690 回答