0

A while ago, I had this fiddle working thanks to stackoverflow : http://jsfiddle.net/AUbZn/16/ Now it's not anymore :/

Seems that for whatever reason, the request is being sent to yahoo in OPTION method. This is the relevant part, as this url is being option'ed :

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

Any idea why and how to correct it ?

Choumarin
  • 400
  • 1
  • 6
  • 16

1 Answers1

0

Found the solution :)

Using OpenLayers.Protocol.Script instead of OpenLayers.Protocol.HTTP following this example : http://openlayers.org/dev/examples/cross-origin-xml.html

Working code :

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
    },
});
Choumarin
  • 400
  • 1
  • 6
  • 16