AW: [OpenLayers-Users] Vector Feature External Graphic Sizing

MarcusRobbins mrobbins at generic-software.com
Tue Aug 2 04:39:33 EDT 2011


Thankyou, yes that would work. But the onload callback function happens
asynchronously. 

This means that I would have to break apart my existing synchronous code
which is carrying in it's context/scope a whole load of info which is used
to create the vector feature.

To pass these on to the callback function I'd have to push these up to the
global scope, i.e. the page. But the trouble is, since the callback function
is assigned in a loop and the context changes with each iteration of that
loop, I can't see a way of linking the scope variables of that iteration of
the loop to the call back function.

I could use JQuery to place the objects as data against the image element
using data(). But that feels, for a reason I can't put my finger on, like a
horrible thing to do.

This is now getting involved and is way outside the scope of this board, but
I'll forge on in case anyone is interested.

Pseudo code:

function soso()
{
        var oVectorFeature = new VectorFeature();
        oVectorFeature.storeStuff(vectorDataStuff[i].thingIDOrSomething);
        alert(tata.height + ", " + tata.width);
}

var vectorDataStuff = ajaxyThing.getMeStuff();

for (var i = 0; i < 20; i++)
{        
        var tata = new Image();
        tata.src="http://urltoimage/" + vectorDataStuff[i].imageLocation;
        tata.onload = soso; 
}

The problem is the the i variable inside the soso function is reffering to
the i variable in the closure formed by the for loop, which is way out of
scope. The other problem is that you are willy nilly creating image elements
on the page and yet another problem is that the code is now horribly
fragmented.

Maybe I'm just grumpy with javascript, lol.

I think I'm just going to include image size with the data returned from my
webservice call.

If you've followed my rant/grump, thanks. If you're just reading this last
line, I don't blame you!

Marcus

--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/Vector-Feature-External-Graphic-Sizing-tp6640467p6644035.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.


More information about the Users mailing list