On 22 January 2012 14:00, alex <[email protected]> wrote: > > For some reason, when loading the page from scratch, the width and height of > the Javascript Image object are Null, after setting the correct > src-attribute, causing the variable img_ratio to be NaN. Now that I know > that, I can set img_ratio arbitrarily to 1, which causes the icons to be > quadratic, but at least they appear. > > Somebody have an idea, why this is happening?
Relevant lines are > var icon = unescape(value.Photo); > var img = new Image(); > img.src = icon; > var img_ratio = parseFloat(img.height) / parseFloat(img.width); Setting img.src to the url is instantaneous and the code moves on; but the Image() won't have loaded that file by the time the height and width attributes are required. They are still unset. What you may be able to do is to use an onload handler to calculate and use the img_ratio. var img = new Image(); img.onload = calculateAndDisplay(img); img.src = icon; // move everything that needs to happen with the icon into that function Apparently setting src before onload can be unreliable, so it needs to be this way round. -- You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.
