/*! BingMapFFDraw - v0.0.1 - 2013-08-29 * https://github.com/dannyrscott/BingMapFreeFormDraw * Copyright (c) 2013 Danny Scott; Licensed MIT */ (function(n){"use strict";var o=function(n,o){var t,e,i,r,a,s=n,c=this,d=Microsoft.Maps,u=new d.EntityCollection,l=new d.Polyline,v=[],h=!1,f=!1,w="click",g="click",p=o||{};p.onDrawEnd=p.onDrawEnd||function(){},p.polygon=p.polygon||{},p.holdToDraw=p.holdToDraw||!1,p.holdToDraw&&(w="mousedown",g="mouseup"),t=new d.Polygon(null,p.polygon),s.entities.push(u),u.push(l),u.push(t);var E=function(){a=d.Events.addHandler(s,"mousemove",function(n){n.handled=!0})},D=function(){d.Events.removeHandler(a)},m=function(){o=o||{};var n=o.onDrawEnd||function(){};h||(h=!0,t.setLocations([]),E(),e=d.Events.addThrottledHandler(s,"mousemove",function(n){v=l.getLocations()||[];var o,t=new d.Point(n.getX(),n.getY());try{o=s.tryPixelToLocation(t)}catch(e){o=!1}o&&(v.push(o),l.setLocations(v))},100),i=d.Events.addHandler(s,g,function(){y(n),D(),d.Events.removeHandler(i),c.endDrawingMode()}))},y=function(){d.Events.removeHandler(e);var n=l.getLocations();n.length&&n.push(n[0]),l.setLocations([]),t.setLocations(n),h=!1,p.onDrawEnd(t)};this.enterDrawingMode=function(){f||(f=!0,r=d.Events.addHandler(s,w,function(){d.Events.removeHandler(r),m()}))},this.endDrawingMode=function(){f=!1,d.Events.removeHandler(r),h&&(h=!1,y())},this.inDrawingMode=function(){return f},this.isDrawing=function(){return h},this.getShape=function(){return t},this.getLayer=function(){return u}};n.BingDrawFF=o})("object"==typeof exports&&exports||this);