         addWaysToLayer(ways, waysLayer)
         map.zoomToExtent(waysLayer.getDataExtent())
 
-  setNode = (input) ->
-    id = nodesLayer.selectedFeatures.length > 0 and nodesLayer.selectedFeatures[0].attributes.node.id
-    input.val(id) if id?
+  setNodeAsDestination = () ->
+    destination = selectedNodeId()
+    retrieveDirections(source, destination) if source? and destination?
 
   setNodeAsSource = () ->
-    setNode($("#source"))
-
-  setNodeAsDestination = () ->
-    setNode($("#destination"))
+    source = selectedNodeId()
+    retrieveDirections(source, destination) if source? and destination?
 
   toggleDisabledProperty = (elementId) ->
     if $("##{ elementId }").prop("disabled") is true

        nodesLayer.addFeatures(features)
        map.zoomToExtent(nodesLayer.getDataExtent())

  retrieveDirections = () ->
    destination = $("#destination").val()
    source = $("#source").val()
    $.get "/directions", {
      destination
      source
      },
      (directions) ->
        displayDirections(directions)

        retrieveWays()
  })
  selectFeatureControl = new OpenLayers.Control.SelectFeature([nodesLayer, waysLayer]);
  source = null

  $(() ->
    map = new OpenLayers.Map "map"
