如何访问 OpenLayers 中加载的 GML 文件的功能?

发布于 2024-11-13 10:51:51 字数 993 浏览 3 评论 0原文

我似乎无法访问已加载的 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 = "" ...我错了什么?

谢谢 !

I seem not to be able to access features of a loaded GML file. I will use the 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 !

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

初吻给了烟 2024-11-20 10:51:51

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

eventListeners: {
    "featuresadded": dataLoaded
},

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

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/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文