         zoom = ->
           App.map.zoomTo box, keep_center, 'default'
         setTimeout zoom, 1000
+
+      clear_and_rezoom: (cb) ->
+        @clear_map(cb)
+        @reset_zoom()
+        @zoom_to_bounding_box App.user_bounding_box
 
       place_user_marker: ->
         App.user_marker = (new

        @rack_directions_shown = false


    direct_to_nearest_loo: ->
      $.getJSON '/toilets.geojson', (data) =>
        nearest_loo = @actions.find_nearest_geojson_point data
        loo_coords = [nearest_loo.lat, nearest_loo.lon]
        $.getJSON 'cycle-racks.geojson', (rdata) =>
          nearest_rack = @actions.find_nearest_geojson_point rdata, loo_coords
          @actions.show_path_from_user_via_rack nearest_rack, nearest_loo


    show_cycle_racks: ->

  App.$poi_button = $ '#poi_button'
  App.$clear_poi = $ '#clear_poi'

  Controller = {
    toggle_cycle_racks: ->
      if not App.cycle_racks_shown
        App.show_cycle_racks()
        App.$cycle_racks.text "Hide cycle-racks"
      else
        App.hide_cycle_racks()
        App.$cycle_racks.text "Show all cycle-racks"

    toggle_nearest_rack_direction: ->
      if not App.rack_directions_shown
        App.direct_to_nearest_rack()
        App.$find_nearest.text "Hide directions"
      else
        App.rack_directions_shown = false
        App.actions.clear_and_rezoom ->
          App.$find_nearest.text "Direct me to the nearest cycle-rack"

    lock_buttons_after_poi: ->
      App.$find_nearest.click() if App.rack_directions_shown
      for button in [App.$poi_button, App.$find_nearest]
        button.attr 'disabled', 'disabled'
      App.$clear_poi.show()

    show_nearest_loo: ->
      App.$poi_button.text 'Public Toilet'
      console.log this
      Controller.lock_buttons_after_poi()
      console.log this
      App.direct_to_nearest_object '/toilets.geojson'

    reset_after_poi: ->
      App.actions.clear_and_rezoom ->
        App.$poi_button.html 'place of interest <span class="caret"></span>'
        for button in [App.$poi_button, App.$find_nearest]
          button.removeAttr 'disabled'
        App.$clear_poi.hide()
  }

  navigator.geolocation.getCurrentPosition (user_location) ->
    App.create_map user_location

  App.$cycle_racks.click Controller.toggle_cycle_racks
  App.$find_nearest.click Controller.toggle_nearest_rack_direction
  ($ '#find_me_a_loo').click Controller.show_nearest_loo
  App.$clear_poi.click Controller.reset_after_poi

  window.App = App

