     return
 
   return
+forge.MapController.$inject = ['$scope', 'NgMap']
 
-.controller 'BuildingCtrl', ($scope) ->
+forge.BuildingController = ($scope) -> return
+forge.BuildingController.$inject = ['$scope']
+
+
+
+angular
+  .module('forge', ['ngMap'])
+  .controller('ForgeCtrl', forge.ForgeController)
+  .controller('LayersCtrl', forge.LayersController)
+  .controller('ForgeMapCtrl', forge.MapController)
+  .controller('BuildingCtrl', forge.BuildingController)

  $http.get('/buildings.json').then (response) ->
    $scope.buildings = response.data?.buildings or []
  return

.controller 'LayersCtrl', ($scope) ->
  $scope.selectLayer = ->
    console.log "Layer selected: ", $scope.layer.name
    $scope.$parent.layer = $scope.layer
    return
  return

.controller 'ForgeMapCtrl', ($scope, NgMap) ->
  kmlLayer = null
  $scope.showBuilding = (event, building) ->
    console.log building
    $scope.$parent.building = building
    return
  # $scope.$watch 'layer', (newValue, oldValue) ->
  #   kmlLayer?.setMap(null)
  #   if newValue
  #     NgMap.getMap().then (map) ->
  #       kml_url = "http://historyforge.dev/layers/#{newValue.id}.kml"
  #       kml_options =
  #         suppressInfoWindows: yes
  #         preserveViewport: no
  #         map: map
  #       kmlLayer = new google.maps.KmlLayer kml_url, kml_options
  #       return
  $scope.$watch 'buildings', (newValue, oldValue) ->
    return unless newValue
    if newValue.length is 1

#= require 'ng-map.min'

forge = {}

forge.ForgeController = ($scope, $http) ->
  $scope.buildings = []
  $scope.building  = null
  $scope.layers = []
