Skip to content

Commit

Permalink
Added GeoJSON support
Browse files Browse the repository at this point in the history
  • Loading branch information
jvanulde committed Feb 7, 2013
1 parent 26f2f6b commit 99d5b8b
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 15 deletions.
22 changes: 18 additions & 4 deletions Overlays.js
Expand Up @@ -44,7 +44,7 @@ var wet_boew_geomap = {
fillColor: '#999999'
},
{
title: 'JSON Demo',
title: 'JSON (GeoGratis)',
caption: 'This is a sample dataset loaded from a remote JSON resource, in this case the GeoGratis API.',
type: 'json',
url: 'http://geogratis.gc.ca/api/en/nrcan-rncan/ess-sst',
Expand All @@ -56,12 +56,26 @@ var wet_boew_geomap = {
root: 'products',
attributes: {
title: 'title',
description: 'summary',
geometry: 'geometry',
description: 'summary'
author: 'author'
},
strokeColor: '#336600',
fillColor: '#00CC00'
}
},
{
title: 'GeoJSON (CartoDB)',
caption: 'This is a sample dataset loaded from a remote JSON resource, in this case the CartoDB API.',
type: 'geojson',
url: 'http://stephenott.cartodb.com/api/v2/sql',
params: {
'format': 'GeoJSON',
'q': 'SELECT * FROM traffic_cameras LIMIT 10'
},
visible: true,
attributes: {
title: 'cartodb_id',
description: 'location_desc'
}
}
]
};
54 changes: 43 additions & 11 deletions src/js/workers/geomap.js
Expand Up @@ -704,7 +704,7 @@
for (var i = 0; i < items.length; i++) {
row = items[i];
feature = new OpenLayers.Feature.Vector();
feature.geometry = this.parseGeometry(row.geometry);
feature.geometry = this.parseGeometry(row.geometry);

// parse and store the attributes
atts = {};
Expand All @@ -731,14 +731,14 @@
"featuresadded": function (evt) {
$.each(evt.features, function(index, feature) {
var context = {
'id': feature.id.replace(/\W/g, "_"),
'title': feature.attributes.title,
'description': feature.attributes.description,
'feature': feature,
'selectControl': selectControl
};
$row = pe.fn.geomap.createRow(context);
$table.append($row);
'id': feature.id.replace(/\W/g, "_"),
'title': feature.attributes.title,
'description': feature.attributes.description,
'feature': feature,
'selectControl': selectControl
};
$row = pe.fn.geomap.createRow(context);
$table.append($row);
});
}

Expand All @@ -750,9 +750,41 @@
queryLayers.push(olLayer);
map.addLayer(olLayer);
pe.fn.geomap.createTable(olLayer);
pe.fn.geomap.addLayerData($table, layer.visible, olLayer.id);
} else if (layer.type=='geojson') {
var olLayer = new OpenLayers.Layer.Vector(
layer.title, {
projection: map.displayProjection,
strategies: [new OpenLayers.Strategy.Fixed()],
protocol: new OpenLayers.Protocol.Script({
url: layer.url,
params: layer.params,
format: new OpenLayers.Format.GeoJSON()
}),
eventListeners: {
"featuresadded": function (evt) {
$.each(evt.features, function(index, feature) {
var context = {
'id': feature.id.replace(/\W/g, "_"),
'title': feature.attributes.cartodb_id,
'description': feature.attributes.location_desc,
'feature': feature,
'selectControl': selectControl
};
$row = pe.fn.geomap.createRow(context);
$table.append($row);
});
}
},
styleMap: pe.fn.geomap.getStyleMap(wet_boew_geomap.overlays[index])
}
)
olLayer.visibility=layer.visible;
queryLayers.push(olLayer);
map.addLayer(olLayer);
pe.fn.geomap.createTable(olLayer);
pe.fn.geomap.addLayerData($table, layer.visible, olLayer.id);
}

}
});
}

Expand Down

0 comments on commit 99d5b8b

Please sign in to comment.