[OpenLayers-Users] populate vector layer from json response

Nicholas Efremov-Kendall n.e.kendall at gmail.com
Mon Jun 20 23:00:07 EDT 2011


Hi Phil et al,

Thanks for your response. The code as is does iterate through the features
as they are returned. I have a handle on it up to the plotting function. An
alert on the tweet.marker object returns [object Object], while tweet.latlng
returns readable coordinates lon=38.6834,lat=-90.4313. I guess what I'm
unsure about is how to parse the object which is passed to the third
function. Thanks again.


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()));
tweetz.addFeatures([tweet.marker]);}




On Mon, Jun 20, 2011 at 9:13 PM, Phil Scadden <p.scadden at gns.cri.nz> wrote:

> I have no idea what the object returned by twitter is but surely, but if
> you are using jsonp, then
> have in your code something like:
> jsonp_function(json)
> where jsonp_function is the name of jsonp callback and json is the
> returned object. I would guess it contains an array of feature type
> objects, so you would iterate through the array, creating feature for
> each row, and calling vectorLayer.addFeatures(features) to add them to
> the vector layer.
>
> Notice: This email and any attachments are confidential. If received in
> error please destroy and immediately notify us. Do not copy or disclose the
> contents.
>
> _______________________________________________
> Users mailing list
> Users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/openlayers-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20110620/e49bf0ba/attachment.html


More information about the Users mailing list