Specify marker as canvas instead of url?

67 views
Skip to first unread message

David Karger

unread,
Dec 18, 2011, 2:37:22 AM12/18/11
to google-map...@googlegroups.com
I'm revising a web application (http://simile-widgets.org/exhibit) to generate relatively complex marker icons using canvas.  In particular, I need to be able to specify an image (via a url), but also to crop that image to a shape that I draw.   For reasons detailed below, it would be very useful if I could specify those markers to gmaps by passing the canvas itself instead of passing a (data) url. 

Since gmaps requires marker icons to be specified as urls, I'm using the canvas.toDataURL method to create one.  This has always seemed rather hacky, since gmaps turns around and paints that dataurl onto its canvas.  But now I've run into a more serious flaw.  Some of my markers embed images drawn from other sites (I draw those images onto my canvas).  Such cross-site image rendering is permitted.  But, the canvas to which the image is rendered becomes "tainted"---out of fear that I could improperly access images from another site, I am no longer permitted to look at the canvas.  In particular, it becomes forbidden to generate a data url from the canvas.  So I can't hand it off to gmaps.  If I could pass the canvas instead, gmaps could render it for me---it wouldn't matter that the map itself becomes tainted.

alternatively, I could also accomplish this if it were possible to give gmaps _both_ a marker shape _and_ and image url, with the understanding that the image should be painted into the marker shape. 

Given that direct handoff of a canvas is more natural than the transform to/from a data url, I hope such a feature might be considered.

Ben Appleton

unread,
Jan 11, 2012, 7:56:16 PM1/11/12
to google-map...@googlegroups.com
Hi David,

This is an interesting idea. Since we support browsers that lack Canvas, we usually try to avoid exposing Canvas in the public interfaces. And there *is* a workaround (toDataURL) though it's not ideal as you say. So I suggest using the workaround for now, and we'll look into supporting this down the road.

That's the easiest way to track progress.

Thanks
Ben


--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-maps-js-api-v3/-/oUyZtoEYSuQJ.
To post to this group, send email to google-map...@googlegroups.com.
To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.

Reply all
Reply to author
Forward
0 new messages