[OpenLayers-Users] Problem loading external GeoJSON

guirreri christian at guirreri.com
Wed Jul 20 15:12:19 EDT 2011


The following seems like it should work fine, but I'm getting a not
well-formed error. This is straight from the GeoJSON OpenLayers example,
just with an eternal file instead, so I know the JSON is well-formed.

The external GeoJSON file is here - OpenLayers code follows it:

{
"type": "FeatureCollection", 
"features": [
{"geometry": {
    "type": "GeometryCollection", 
    "geometries": [
        {
            "type": "Polygon", 
            "coordinates": 
                [[[11.0878902207, 45.1602390564], 
                  [14.931640625, 40.9228515625], 
                  [0.8251953125, 41.0986328125], 
                  [7.63671875, 48.96484375], 
                  [11.0878902207, 45.1602390564]]]
        }
    ]
}, 
"type": "Feature", 
"properties": {}}
]
}

var lon = 5;
var lat = 40;
var zoom = 5;
var map, layer;

function init() {
	map = new OpenLayers.Map( 'map' );
	layer = new OpenLayers.Layer.WMS( "OpenLayers WMS");
	map.addLayer(layer);
	map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);
	var geojson_format = new OpenLayers.Format.GeoJSON();
	var vector_layer = new OpenLayers.Layer.Vector(); 
	map.addLayer(vector_layer);

	OpenLayers.loadURL("c_2001_raw.json", {}, null, onLoad, onLoadFailed);
}
function onLoad(r) {
	if (r.status == 200) {
		var p = new OpenLayers.Format.GeoJSON();
		var f = p.read(r.responseText);
		vector_layer.addFeatures(f);
	}
}
function onLoadFailed(r) {
	alert('Load Failed');
}

--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/Problem-loading-external-GeoJSON-tp6603955p6603955.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.


More information about the Users mailing list