"use strict";

var App = App || {};

let CircleSelectorController = function(buttonID) {
  let self = {
    button: null,
    dragLayer: null,
    svg: null,

    drawable: false,
    drawing: false,
    drawingCircle: false,
    drawingStart: null
  };

  init();

  function init() {
    self.button = d3.select(buttonID)
      .on("click", handleButtonClick);
  }

  function attachDragLayer(id) {
    self.dragLayer = d3.select(id).select(function() {
        return this.parentNode.appendChild(this.cloneNode(false));
      })
      .attr("id", "dragLayer")
      .attr("class", "disabled")

    self.svg = self.dragLayer.append("svg")
      .on("mousedown", startCircleCreation)
      .on("mousemove", resizeCircle)
      .on("mouseup", finalizeCircle);

    self.drawingCircle = self.svg.append("circle");
  }

  function handleButtonClick() {
    self.drawable = !self.drawable;

    if (self.drawable) {
      self.button.attr("class", "btn btn-danger navbar-btn");
      self.dragLayer.classed("disabled", false);
    } else {
      self.button.attr("class", "btn btn-success navbar-btn");
      self.dragLayer.classed("disabled", true);
    }
  }

  function startCircleCreation() {
    console.log("startCircleCreation", d3.event);

    self.drawingStart = {
      x: d3.event.layerX,
      y: d3.event.layerY
    };

    self.drawingCircle
      .attr("cx", d3.event.layerX)
      .attr("cy", d3.event.layerY)
      .attr("r", 0);
  }

  function resizeCircle() {
    if (self.drawingStart) {
      let radius = Math.sqrt(
        Math.pow(d3.event.layerX - self.drawingStart.x, 2) +
        Math.pow(d3.event.layerY - self.drawingStart.y, 2)
      );

      self.drawingCircle.attr("r", radius);
    }
  }

  function finalizeCircle() {
    console.log("finalizeCircle", d3.event);

    // send final values to map to create map circle, etc.

    self.drawable = false;
    self.button.attr("class", "btn btn-success navbar-btn");
    self.dragLayer.classed("disabled", true);

    self.drawingStart = null;
  }

  return {
    attachDragLayer
  };
}

@@ -1191,59 +1191,8 @@
 ) %7B%0A
-    console.log(%22startCircleCreation%22, d3.event);%0A%0A
     
@@ -1697,54 +1697,8 @@
 ) %7B%0A
-    console.log(%22finalizeCircle%22, d3.event);%0A%0A
     

Remove a few console statemnets