GeoCommons GeoJSON in OpenLayers

So, with GeoCommons you can export all the features from a dataset in GeoJSON format. This is very useful. Then can it be displayed in Openlayers? Why yes it can!

I use the following strategy, wrapping the response with a little bit extra so that the GeoJSON format can read it properly.

var url = "http://geocommons.com/overlays/128725/features.json?limit=100";

var p = new OpenLayers.Format.GeoJSON();

OpenLayers.loadURL(url, {}, null, function (response) {
 var gformat = new OpenLayers.Format.GeoJSON();
 gg = '{"type":"FeatureCollection", "features":' +
      response.responseText + '}';
 var feats = gformat.read(gg);

 vector_layer.addFeatures(feats);
});

Have a look a the live demo of this example of loading points from a Geocommons dataset straight into an OpenLayers map
(Note that I am using an OpenLayers.ProxyHost proxy to make it work in FF)

It is of course very basic in terms of styling, but it’s a start!

Incidentally the points are from “CARMA, India Power Plant Emissions, India, 2000/ 2007/Future” (carbon monitoring)

About these ads

9 thoughts on “GeoCommons GeoJSON in OpenLayers

  1. Pingback: Pubs in England: How to do it with Polymaps and GeoCommons Filters « thinkwhere

  2. Pingback: Pubs in England: How to do it with Polymaps and GeoCommons Filters | J2ME GPS

  3. Pingback: Open Mobile Map » Pubs in England: How to do it with Polymaps and GeoCommons Filters

  4. Pingback: Leaflet & GeoCommons JSON | GeoIQ Developer

  5. Pingback: Leaflet & GeoCommons JSON « Another Word For It

  6. Pingback: Leaving GeoIQ/Esri. Retrospective and future plans. « thinkwhere

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s