0

不久前,由于stackoverflow,我让这个小提琴工作了:http: //jsfiddle.net/AUbZn/16/现在它不再是了:/

似乎无论出于何种原因,请求都以 OPTION 方法发送到雅虎。这是相关部分,因为这个 url 正在被选择:

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(),
}),
eventListeners: {
    "featuresadded": dataLoaded
},
});

知道为什么以及如何纠正它吗?

4

1 回答 1

0

找到了解决方案:)

在此示例之后使用 OpenLayers.Protocol.Script 而不是 OpenLayers.Protocol.HTTP:http: //openlayers.org/dev/examples/cross-origin-xml.html

工作代码:

var layer = new OpenLayers.Layer.Vector("GML", {
    strategies: [new OpenLayers.Strategy.Fixed()],
    protocol: new OpenLayers.Protocol.Script({
        url: "http://query.yahooapis.com/v1/public/yql",
        params: {
            q: "select * from xml where url='http%3A%2F%2Fopenlayers.org%2Fdev%2Fexamples%2Fgml%2Fpolygon.xml'",
        },
        format: new OpenLayers.Format.GML(),
        parseFeatures: function(data) {
            return this.format.read(data.results[0]);
        },
    }),
    eventListeners: {
        "featuresadded": featuresLoaded
    },
});
于 2013-01-12T10:46:28.043 回答