Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I was under the impression that it was.

Here is my example:

<html lang='en'>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>GeoRSS</title>
<script src="http://maps.google.com/maps/api/js?v=3.5&amp;sensor=false"></script>
<script src="http://openlayers.org/api/OpenLayers.js"></script>
<script src="google-v3.js"></script>

<script type="text/javascript">

var map;

function init() {
    var restrictedExtent = new OpenLayers.Bounds(-180, -90, 180, 90);

    map = new OpenLayers.Map("map_element"
    );
    map.addControl(new OpenLayers.Control.MousePosition());
    map.addControl(new OpenLayers.Control.LayerSwitcher());

    var layer = new OpenLayers.Layer.Google("Google", {"sphericalMercator": true});

    var usgs = new OpenLayers.Layer.Vector("Earthquakes", {
        projection: new OpenLayers.Projection("EPSG:4326"),
        strategies: [new OpenLayers.Strategy.Fixed()],
        protocol: new OpenLayers.Protocol.HTTP({
            url: "http://earthquake.usgs.gov/earthquakes/catalogs/7day-M2.5.xml",
            format: new OpenLayers.Format.GeoRSS()
        })
    });
    map.addLayers([layer, usgs]);
    map.setCenter(new OpenLayers.LonLat(-11682133.90525, 4676768.13795), 4);
}

</script>

</head>
<body onload="init()">
    <div id="map_element">
    </div>
</body>
</html>

For me this is only working on IE. I would like to keep this xml file on the USGS server and call it dynamically rather than save it locally. Is there anyway to get this to work, on other browsers (besides IE) without using a proxy script?

Thanks!

share|improve this question

2 Answers 2

up vote 7 down vote accepted

JSONP is a way of getting around the same-origin policy by obtaining data via using "script" tags rather than trying to remotely extract information. In your case you can wrap the whole USGS response in jsonp using for example online service http://jsonpwrapper.com/.

Here is modified example:

<html lang='en'>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>GeoRSS</title>
<script src="http://maps.google.com/maps/api/js?v=3.5&amp;sensor=false"></script>
<script src="http://openlayers.org/api/OpenLayers.js"></script>
<script src="google-v3.js"></script>

<script type="text/javascript">

var map;

function init() {
    var restrictedExtent = new OpenLayers.Bounds(-180, -90, 180, 90);

    map = new OpenLayers.Map("map_element");
    map.addControl(new OpenLayers.Control.MousePosition());
    map.addControl(new OpenLayers.Control.LayerSwitcher());

    var layer = new OpenLayers.Layer.Google("Google", {"sphericalMercator": true});

    var usgs = new OpenLayers.Layer.Vector("Earthquakes", {
        projection: new OpenLayers.Projection("EPSG:4326"),
        strategies: [new OpenLayers.Strategy.Fixed()],
        protocol: new OpenLayers.Protocol.Script({
            url: "http://jsonpwrapper.com/?urls[]=http://earthquake.usgs.gov/earthquakes/catalogs/7day-M2.5.xml",
            format: new OpenLayers.Format.GeoRSS(),
            parseFeatures: function(data) {
                return this.format.read(data[0]['body'])
            }
        })
    });
    map.addLayers([layer, usgs]);
    map.setCenter(new OpenLayers.LonLat(-11682133.90525, 4676768.13795), 4);
}

</script>

</head>
<body onload="init()">
    <div id="map_element">
    </div>
</body>
</html>

Live demo.

share|improve this answer
    
jsonpwrapper looks to be just an outsourced proxy. you have no control over the stability of the proxy server and can't extend it's features [e.g. unzipping KMZ on the fly into KML]. Either way, the OP's solution is still to "get a proxy". –  Vadim Dec 13 '11 at 18:34
    
@Vadim you are correct about the weaknesses of this solution. But Im glad that drnextgis posted it. I had never seen jsonwrapper before. –  glw Dec 14 '11 at 7:31

You will have to setup a server-side proxy to retrieve vector data. Proxy documentation

You can search around online for sample proxy implementations. ESRI happens to have a few different languages implemented here including php, jsp and .net. These samples will be specific to ArcGIS, so you'll have to remove some restrictions; or just roll your own.

share|improve this answer
    
Thanks Vadim. Ill see what I can find. –  glw Dec 14 '11 at 7:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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