I'm trying to port my marker cluster script (
http://cm.qfox.nl ) from
v2 to v3 but it seems that's pretty much impossible because the api
doesn't expose enough details.
The biggest problem seems to be getting the actual size of the marker
and the anchor of the marker. I've searched the group, but can't
really find related posts (which was surprising to me).
Basically I need to know precisely what area of the map is covered by
a given marker in order to compare these regions to each other.
However, there are is no api to give me this information.
So this is what I have right now...
An icon can be set by .setIcon* (or implicitly through the
constructor, but I'm going to assume both ways lead to the same
result). This method accepts a string or a MarkerImage*. The .getIcon
method of a marker returns whatever you give it, it is not normalized
(quite annoying). The .getShape method is not set implicitly, so it's
useless in this case.
Ok, so .getIcon returns a string (the url of the icon) or the
MarkerImage. If it's the url, you can load it in an Image and get the
width/height after it's loaded. Easy enough.
If it returns the MarkerImage, things get hairy. That object should
have a coords property. I checked, it's not set. It does have five
properties. Four of them are scrambled by the minifiers, but their
values clearly show that they are the properties as given in the
constructor. The other one is obviously anchor, which is undocumented
but also unscrambled (which is hardly coincidental). Maybe it's just
missing from the documentation, who knows. Of the five properties, one
is type string. Two are points and two are sizes. Since anchor is a
point, you can also infer the origin, which is "point"less.
So since I can get at least the url from MarkerImage, albeit through a
hack, I can reasonably reliably get the size of the image used for the
marker. It's not the end-goal, but at least it's something.
So my question is, am I overlooking anything here? I'd like to get the
anchor and final size of the image used for a marker when a
MarkerImage is supplied for an icon, rather than a regular string. As
it stands now, that seems impossible. Any help?
But as it stands it seems impossible to create a generic cluster
manager. You can make it safe for when .getIcon returns a string, but
when it doesn't you're pretty much screwed.
* Marker:
http://code.google.com/apis/maps/documentation/javascript/reference.html#Marker
* MarkerImage:
http://code.google.com/apis/maps/documentation/javascript/reference.html#MarkerImage