I'm trying to create custom markers in GMaps using the GIcon object.
I don't wish to ask the user to specify the width/height themselves
and rather fetch it.
While it works in FF, Safari (webkit) browsers don't calculate width/
height on an image until it's loaded.
var img = new Image();
img.src = 'http://adsf.com/path/to/image';
var w = img.width;
var h = img.height;
// FF has the correct w/h for img here
// Safari/chrome gives w/h as 0
I tried waiting until the image is loaded to add those props to the
icon (using jQuery's load()), but I think Gmaps might be making a copy
of my icon when I pass it in instead of by ref because when I change
the icon it doesn't effect the icon on the map.
var icon = new GIcon();
icon.image=url;
icon.shadow=ActionMap.UI.shadowIcon;
icon.iconSize=new GSize(w, h);
icon.iconAnchor=new GPoint(Math.round(w/2), h);
icon.infoWindowAnchor=new GPoint(Math.round(w/2), h);
icon.shadowSize=new GSize(w, h);
$(img).load(function() {
// get width for Safari after img is finished loading
w = this.width;
h = this.height;
icon.iconSize=new GSize(w, h);
icon.iconAnchor=new GPoint(Math.round(w/2), h);
icon.infoWindowAnchor=new GPoint(Math.round(w/2), h);
icon.shadowSize=new GSize(w, h);
});
any ideas? i think its more elegant to just ask for a url.. but it
looks like i may need to ask for the width/height too. :/
j
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Maps API" 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-API?hl=en
-~----------~----~----~----~------~----~------~--~---