[OpenLayers-Users] populate vector layer from json response

Nicholas Efremov-Kendall n.e.kendall at gmail.com
Mon Jun 20 21:27:15 EDT 2011


Hi all,

I'm (now) successfully pulling a json response from the twitter API using
jquery's $.getJSON but I'm unsure of how to read the json response into a
Layer.Vector. My guess is that this could be achieved through either the
script or http protocols, or through a filter strategy, but I'm not sure how
to implement this, where I get hazy is the third function below.
Suggestions?

function acquireTweets(){
$.getJSON(createTWTsrcURL(), function(data){
if(data.results)
$.each(data.results, function(i, tweet){
if (tweet.geo || tweet.location)
tweetsQ.push(tweet);
});
refreshQuery = data.refresh_url;
});
}

function parseTweetsQ(){
if (tweetsQ.length > 0) {
var tweet = tweetsQ.pop();
if (tweet.geo){
tweet.latlng = new
OpenLayers.LonLat(tweet.geo.coordinates[0],tweet.geo.coordinates[1]);
plotTwt(tweet);}}}

function plotTwt(tweet){
map.addLayer(tweetz);
tweet.marker = new OpenLayers.Feature.Vector(new
OpenLayers.Geometry.Point(tweet.latlng).transform(new
OpenLayers.Projection("EPSG:4326"),map.getProjectionObject()));
alert(tweet.marker);
tweetz.addFeatures(tweet.marker);
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20110620/2c9f6348/attachment.html


More information about the Users mailing list