如何访问 OpenLayers 中加载的 GML 文件的功能?
我似乎无法访问已加载的 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 :
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在 OpenLayers.Layer.Vector 对象的选项“eventListeners.featuresadded”中找到了解决方案。
这是工作中的jsfiddle: http://jsfiddle.net/AUbZn/16/
I have found the solution in the option 'eventListeners.featuresadded' of the OpenLayers.Layer.Vector object.
here is the working jsfiddle : http://jsfiddle.net/AUbZn/16/