[OpenLayers-Users] populate vector layer from json response

Nick Kendall n.e.kendall at gmail.com
Tue Jun 21 04:23:46 EDT 2011


Thanks! Will take another crack at this Tom! 

Sent from my mobile device

On Jun 21, 2011, at 2:37 AM, "Sveen Atle Frenvik (Geomatikk IKT)" <Atle.Frenvik.Sveen at geomatikk.no> wrote:

> try using an OpenLayers.Geometry.Point instead of an OpenLayers.LonLat
> 
> ie (untested, but i think this is rather correct):
> 
> function parseTweetsQ(){
>     if (tweetsQ.length > 0) {
>         var tweet = tweetsQ.pop();
>         if (tweet.geo){
>             tweet.point = new OpenLayers.Geometry.Point(tweet.geo.coordinates[0],tweet.geo.coordinates[1]).transform(new OpenLayers.Projection("EPSG:4326"),map.getProjectionObject());
>             tweet.attributes = {}; //in this you coukd stuff attributes of the tweet for easy access on clicks etc.
>             plotTwt(tweet);
>         }
>     }
> }
> 
> function plotTwt(tweet){
>     //why do you keep adding the layer for each tweet? 
>     map.addLayer(tweetz);
>     tweet.marker = new OpenLayers.Feature.Vector(tweet.point,{attributes:{tweet.attributes]});
>     tweetz.addFeatures([tweet.marker]);
> }
> 
> 
> 
> On 2011-06-21 05:00, Nicholas Efremov-Kendall wrote:
>> 
>> 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
>> 
>> 
>> _______________________________________________
>> Users mailing list
>> Users at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/openlayers-users
> 
> 
> -- 
> Atle Frenvik Sveen
> Utvikler
> Geomatikk IKT AS
> tlf: 45 27 86 89
> atle.frenvik.sveen at geomatikk.no
> _______________________________________________
> 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/20110621/372421c5/attachment.html


More information about the Users mailing list