(function () {
'use strict';

  angular.module('hutmap.controllers').

  /*
   * This controller does configuration of the google map, as well as provides
   * functions which aren't really 'clean' enough to be in MapCtrl, i.e.
   * involve dom manipulation or calling into google.maps.
   */
  controller('MapConfigCtrl', 
    
    ['$scope', '$http', 'hutmapMapId', 'mapOptions',
    'markerOptions',

    function ($scope, $http, hutmapMapId, mapOptions,
      markerOptions) {

    var prevSelectedMarker;
    var prevIcon;

    $scope.mc = {
      hutmapMapId: hutmapMapId,
      mapOptions: mapOptions.main
    };

    // return proper google.maps.MapOptions for the given hut
    $scope.getMarkerOptions = function(hut) {
      var opts = {};

      if ($scope.h.filteredHuts && hut.id in $scope.h.filteredHutIds) {
        opts = angular.extend(opts, markerOptions.filteredHuts);
      } else {
        opts = angular.extend(opts, markerOptions.huts);
      }

      if ($scope.h.selectedHut && $scope.h.selectedHut.id === hut.id) {
        opts = angular.extend(opts, markerOptions.selected);
      }

      return opts;
    };

    $scope.unselectHut = function() {
      if (prevSelectedMarker) {
        var opts = angular.extend({}, markerOptions.huts, {icon: prevIcon});
        prevSelectedMarker.setOptions(opts);
      }
      $scope.h.selectedHut = null;
    }

    // called when marker is clicked or hut is otherwise selected
    $scope.selectHut = function(marker, hut) {
      $scope.unselectHut();
      prevSelectedMarker = marker;
      prevIcon = marker.getIcon();
      marker.setOptions(markerOptions.selected);
      $scope.h.selectedHut = hut;
    };
  }]);
})();

@@ -743,17 +743,16 @@
 s = %7B%7D;%0A
-%0A
       if
@@ -815,38 +815,38 @@
 tIds) %7B%0A        
-opts =
+return
  angular.extend(
@@ -895,38 +895,38 @@
  else %7B%0A        
-opts =
+return
  angular.extend(
@@ -964,177 +964,81 @@
   %7D%0A
-%0A
     
-  if ($scope.h.selectedHut && $scope.h.selectedHut.id === hut.id) %7B%0A        opts = angular.extend(opts, markerOptions.selected);%0A      %7D%0A%0A      return opts;%0A    %7D;%0A
+%7D;%0A%0A    // called when marker is clicked or hut is otherwise selected
 %0A   
@@ -1037,34 +1037,32 @@
 cted%0A    $scope.
-un
 selectHut = func
@@ -1066,16 +1066,27 @@
 unction(
+marker, hut
 ) %7B%0A    
@@ -1247,191 +1247,8 @@
   %7D%0A
-      $scope.h.selectedHut = null;%0A    %7D%0A%0A    // called when marker is clicked or hut is otherwise selected%0A    $scope.selectHut = function(marker, hut) %7B%0A      $scope.unselectHut();%0A
     

Revert "Don't unselect hut when map dragged."