Let's stop for a minute and rethink our workflow. When the user clicks on the map, we need to show a pin, which will be a corner of the polygon. When the user double-clicks on the map, we will close the polygon. We also need to provide some visual clues as the user drags the mouse, trying to find another point.
We'll start by writing the method that adds the handlers, as shown in the following code snippet:
_addHandlers: function(self) { this._handlers = {}; this._handlers.click = Microsoft.Maps.Events.addHandler(this._map, 'click', function(e) { self._onmapclick(e); }); this._handlers.dblclick = Microsoft.Maps.Events.addHandler(this._map, 'dblclick', function(e) { self._onmapdblclick(e); }); }
We store the click
and dblclick
handlers on a _handlers
object (instance variable), because we need to remove them when the map exits the drawing mode. First, we must add them when the drawing mode starts, as shown in the following code snippet:
_start: function() { this._changeMouseCursor...