GeotriggerEditor.module('Map.Draw', function(Draw, App, Backbone, Marionette, $, _) {

  this.startWithParent = false;

  // Draw Submodule
  // --------------

  _.extend(Draw, {

    _tools: {
      polygon: null,
      radius: null
    },

    _setup: function() {
      // Initialize new Draw Handlers
      this._tools.polygon = new L.Draw.Polygon(App.map, App.config.editOptions);
      this._tools.radius = new L.Draw.Circle(App.map, App.config.editOptions);

      this._eventBindings();
    },

    _eventBindings: function() {
      App.vent.on('draw:new', function(layer) {
        this.editLayer(layer);
      }, this);

      App.vent.on('index trigger:list trigger:edit', function(){
        this.clear();
      }, this);

      App.vent.on('trigger:new:ready', function() {
        var layer = App.request('draw:layer');
        if (layer){
          App.Map.panToLayer(layer);
        }
      }, this);

      App.vent.on('trigger:edit', function(triggerId) {
        var layer = this.newShape(triggerId);
        this.editLayer(layer);
        App.Map.panToLayer(layer);
      }, this);

      App.map.on('draw:created', function(e) {
        var type = e.layerType;
        var layer = e.layer;

        App.vent.trigger('draw:new', layer);
      });

      App.reqres.setHandler('draw:layer', _.bind(function(){
        return App.Map.Layers.edit.getLayers()[0];
      }, this));

      App.commands.setHandler('draw:clear', _.bind(function(){
        this.clear();
      }, this));

      App.vent.on('draw:enable', _.bind(function(tool){
        this.enableTool(tool);
      }, this));

      App.vent.on('draw:disable', _.bind(function(tool){
        this.disableTool(tool);
      }, this));
    },

    newShape: function(triggerId) {
      var model = App.collections.triggers.get(triggerId);
      var id = model.get('triggerId');
      var geo = model.get('condition').geo;
      var shape;

      if (geo.geojson) {
        shape = App.Map.polygon(geo.geojson, App.config.editOptions.shapeOptions, false).getLayers()[0];
      } else {
        shape = App.Map.circle(geo, App.config.editOptions.shapeOptions, false);
      }

      return shape;
    },

    editLayer: function(layer) {
      this.clear();
      layer.editing.enable();
      App.Map.Layers.edit.addLayer(layer);
    },

    clear: function() {
      App.Map.Layers.edit.clearLayers();
    },

    enableTool: function(name) {
      this.disableTool();
      this._tools[name].enable();
    },

    disableTool: function(name) {
      for (var i in this._tools) {
        if (typeof name === 'undefined' || i === name) {
          this._tools[i].disable();
        }
      }
    }

  });

  // Draw Layer initializer
  // ----------------------

  Draw.addInitializer(function() {
    this._setup();
  });

});

@@ -564,64 +564,162 @@
 w', 
-function(layer) %7B%0A        this.editLayer(layer);%0A      %7D
+this.editLayer, this);%0A      App.vent.on('index trigger:list trigger:edit', this.clear, this);%0A      App.vent.on('trigger:new:ready', this.panToNewTrigger
 , th
@@ -715,33 +715,32 @@
 Trigger, this);%0A
-%0A
       App.vent.o
@@ -738,38 +738,32 @@
 pp.vent.on('
-index 
 trigger:
 list trigger
@@ -754,117 +754,373 @@
 ger:
-list trigger:edit', function()%7B%0A        this.clear(
+edit', this.panToTrigger, this);%0A      App.vent.on('draw:enable', this.enableTool, this);%0A      App.vent.on('draw:disable', this.disableTool, this
 );%0A
+%0A
       
-%7D, this);%0A%0A      App.vent.on('trigger:new:ready',
+App.map.on('draw:created', this.broadcastLayer);%0A%0A      App.reqres.setHandler('draw:layer', this.getEditLayer, this);%0A      App.commands.setHandler('draw:clear', this.clear, this);%0A    %7D,%0A%0A    panToNewTrigger:
  fun
@@ -1127,34 +1127,32 @@
 ction() %7B%0A      
- 
- 
 var layer = App.
@@ -1176,26 +1176,24 @@
 er');%0A      
-  
 if (layer)%7B%0A
@@ -1190,16 +1190,17 @@
  (layer)
+ 
 %7B%0A      
@@ -1197,26 +1197,24 @@
 ) %7B%0A        
-  
 App.Map.panT
@@ -1238,62 +1238,35 @@
     
- 
- 
 %7D%0A
-  
     %7D,
- this);%0A%0A      App.vent.on('t
+%0A%0A    panToT
 rigger:
-edit',
  fun
@@ -1262,32 +1262,33 @@
 rigger: function
+ 
 (triggerId) %7B%0A  
@@ -1287,26 +1287,24 @@
 Id) %7B%0A      
- 
- 
 var layer = 
@@ -1331,26 +1331,24 @@
 rId);%0A      
-  
 this.editLay
@@ -1360,26 +1360,24 @@
 yer);%0A      
- 
- 
 App.Map.panT
@@ -1399,53 +1399,31 @@
     
-  %7D, this);%0A%0A      App.map.on('draw:created',
+%7D,%0A%0A    broadcastLayer:
  fun
@@ -1431,16 +1431,15 @@
 tion
+ 
 (e) %7B%0A
-  
     
@@ -1466,26 +1466,24 @@
 Type;%0A      
-  
 var layer = 
@@ -1492,18 +1492,16 @@
 layer;%0A%0A
-  
       Ap
@@ -1543,64 +1543,30 @@
     
-  %7D);%0A%0A      App.reqres.setHandler('draw:layer', _.bind(
+%7D,%0A%0A    getEditLayer: 
 func
@@ -1567,28 +1567,27 @@
 : function()
+ 
 %7B%0A
-  
       return
@@ -1627,340 +1627,8 @@
 0%5D;%0A
-      %7D, this));%0A%0A      App.commands.setHandler('draw:clear', _.bind(function()%7B%0A        this.clear();%0A      %7D, this));%0A%0A      App.vent.on('draw:enable', _.bind(function(tool)%7B%0A        this.enableTool(tool);%0A      %7D, this));%0A%0A      App.vent.on('draw:disable', _.bind(function(tool)%7B%0A        this.disableTool(tool);%0A      %7D, this));%0A
     

clean up draw event bindings