2

I am trying to get features from remote GeoRSS file with Openlayers... But I am stuck. Openlayers can not read remote file. I have searched on the net but I could not find any solution... Here is the code:

map = new OpenLayers.Map('map');

var wms = new OpenLayers.Layer.WMS("Osgeo WMS",
    "http://vmap0.tiles.osgeo.org/wms/vmap0", {
    layers: "basic"
});
map.addLayer(wms);

var earthquakes = new OpenLayers.Layer.Vector("T", {
    strategies: [new OpenLayers.Strategy.Fixed()],
    protocol: new OpenLayers.Protocol.HTTP({
        url: "http://brainoff.com/test/rss.xml",
        format: new OpenLayers.Format.GeoRSS()
    }),
});
map.addLayer(earthquakes);

var select = new OpenLayers.Control.SelectFeature([earthquakes]);
map.addControl(select);
select.activate();

var draw = new OpenLayers.Control.DrawFeature(
    earthquakes, OpenLayers.Handler.Point);
map.addControl(draw);

function toggle() {
    if (document.getElementById("toggle-id").checked) {
        draw.activate();
    } else {
        draw.deactivate();
    }
}
document.getElementById("toggle-id").onclick = toggle;
toggle();
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.zoomToMaxExtent();
6
  • Can you edit your question to add details of the problem? Exactly what you meant by "can not read remote file" - what error do you see, what other symptoms, what debugging have you tried?
    – BradHards
    Commented Mar 31, 2013 at 2:59
  • Have you tried using a proxy? trac.osgeo.org/openlayers/wiki/… Commented Mar 31, 2013 at 5:17
  • your GeoRSS link does not seem to be a valid GeoRSS. Commented Apr 1, 2013 at 7:26
  • I meant that fatures does not appear on the screen. I am new in Openlayers. I have read that i have to build a proxy but i dont know about it.
    – mete7
    Commented Apr 1, 2013 at 14:01
  • #Devdatta Tengshe, you are wrong because when i uploaded that georss data to my host and Openlayers read it succesfully and Qgis opens it. The GeoRSS data is valid !!! #BradHards I meant that features does not appear on the screen. I am new in Openlayers. I have read about using proxy but i dont know about it. Is there anyway to work with remote located data in Openlayers. Do i have to upload all data to my host...
    – mete7
    Commented Apr 1, 2013 at 14:07

1 Answer 1

3
+50

Try:

var map = new OpenLayers.Map({
    div: "map",
    layers: [
        new OpenLayers.Layer.OSM(),
        new OpenLayers.Layer.Vector("Vectors", {
            projection: new OpenLayers.Projection("EPSG:4326"),
            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://brainoff.com/test/rss.xml'"
                },
                format: new OpenLayers.Format.GeoRSS(),
                parseFeatures: function(data) {
                    return this.format.read(data.results[0]);
                }
            }),
            eventListeners: {
                "featuresadded": function () {
                    this.map.zoomToExtent(this.getDataExtent());
                }
            }
        })
    ]
});

adaptation of http://openlayers.org/dev/examples/cross-origin-xml.html

1
  • People just talk idly but you give the solution. Thanks for your help...
    – mete7
    Commented Apr 4, 2013 at 11:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.