Canvas Pushpins

Author: Ricky Brundritt

Category: Layout

Module Size: 3 kb (minified 1 kb)

Original Source: TBA

Dependencies: Requires browser to support HTML5 canvas. use excanvas to support IE7/8

Description:

This module wraps the standard pushpin class to create a new HTML5 Canvas pushpin class. There are a lot of cool and interesting things we can do with the canvas that would require a lot more work using traditional HTML and JavaScript. By using this module tasks such as rotating a pushpin or programmatically changing the color can be easily achieved.

Screenshots of samples:

image

image

image

Last edited Feb 8, 2014 at 9:38 PM by rbrundritt, version 6

Comments

cheznoid Dec 16, 2013 at 6:48 PM 
I tried adding the above comment about moving the new line of code to the page linked above, but kept getting an error, so couldn't add my comment there. :-(

cheznoid Dec 16, 2013 at 6:46 PM 
I figured out the answers to the above questions:

- Text for the pin is generated by adding a call to context.strokeText(pin.getText(), x, y) in the CanvasPushpin's img.onload implementation.

- See the comments at this page for what needs to be added for the click event handler to work: http://www.bing.com/blogs/site_blogs/b/maps/archive/2013/04/10/html5-canvas-pushpins-in-javascript.aspx. I still had a problem after implementing that solution - the last pin added would not respond to click events. That problem was resolved by moving the the new line added (containing .find('.MapPushpinBase')) AFTER the canvasLayer.push(pin) line. Once that was done, all pushpins responded to the click event.

cheznoid Dec 14, 2013 at 7:36 AM 
Once the new CanvasPushpin is created, I call setOptions on the returned Microsoft.Maps.Pushpin to set its text, and also call Microsoft.Maps.Events.addHandler() to add a click handler for the pin. However, when the pin is rendered there is no text on the pin, and my click event handler isn't called when the pin is clicked. Am I doing something wrong, or or those capabilities lost with the CanvasPushpin class?