B
Berend
My question: can width and height be derived from a preloaded image?
I'm trying to load a dynamically generated image as marker in my Google
Maps mashup. However, a GIcon (Google Icon) object requires width and
height to be set before loading. I therefore created a hidden <img> in
my source which I point to the right location using javascript and
retrieve width and height once loaded.
This doesn't seem to work, since the marker first scales to an absurd
width (250px+) and only resizes to the correct measurements after
reloading all markers.
Please review my code below. What am I doing wrong? Any hints?
TIA!
The code that I thought would do the trick:
====================================================
First, pointing <img> source to the right location:
HTML: <img src="" id="preloader" style="visibility: hidden;" />
JAVASCRIPT:
document.getElementById("preloader").src = "./dynMarker.aspx?...";
document.getElementById("preloader").onload = createMarker();
^^^
Once the preloading is done, I try to retrieve the width and height:
(generated imgsize is at least 50px wide and always 35px high)
function createMarker() {
var width = document.getElementById("preloader").width;
var height = document.getElementById("preloader").height;
var icon = new GIcon();
icon.image = document.getElementById("preloader").src;
icon.shadow = "grfx/marker_shadow.png";
icon.shadowSize = new GSize((100/50)*width, 35);
icon.iconSize = new GSize(width, height);
icon.iconAnchor = new GPoint(parseInt(width/2), height);
...
}
^^^
I'm trying to load a dynamically generated image as marker in my Google
Maps mashup. However, a GIcon (Google Icon) object requires width and
height to be set before loading. I therefore created a hidden <img> in
my source which I point to the right location using javascript and
retrieve width and height once loaded.
This doesn't seem to work, since the marker first scales to an absurd
width (250px+) and only resizes to the correct measurements after
reloading all markers.
Please review my code below. What am I doing wrong? Any hints?
TIA!
The code that I thought would do the trick:
====================================================
First, pointing <img> source to the right location:
HTML: <img src="" id="preloader" style="visibility: hidden;" />
JAVASCRIPT:
document.getElementById("preloader").src = "./dynMarker.aspx?...";
document.getElementById("preloader").onload = createMarker();
^^^
Once the preloading is done, I try to retrieve the width and height:
(generated imgsize is at least 50px wide and always 35px high)
function createMarker() {
var width = document.getElementById("preloader").width;
var height = document.getElementById("preloader").height;
var icon = new GIcon();
icon.image = document.getElementById("preloader").src;
icon.shadow = "grfx/marker_shadow.png";
icon.shadowSize = new GSize((100/50)*width, 35);
icon.iconSize = new GSize(width, height);
icon.iconAnchor = new GPoint(parseInt(width/2), height);
...
}
^^^