 
   addWaysToLayer = (ways, layer, style, selectedStyle) ->
     for way in ways
-      polyline = new L.Polyline((for node in way.nodes
+      polyline = L.polyline((for node in way.nodes
         [node.latitude, node.longitude]), style)
+      polyline.selectedStyle = selectedStyle
+      polyline.style = style
       polyline.way = way
-      polyline.on("click", (e) -> selectWay(e.target, style, selectedStyle)).addTo(layer)
+      polyline.on("click", (e) -> selectWay(e.target)).addTo(layer)
 
   disable = (elementId) ->
     $("##{ elementId }").prop("disabled", true)

      selectedNode.setStyle(styles.node)
      selectedNode = null

  deselectWay = (style) ->
    if selectedWay?
      clearWayData()
      selectedWay.setStyle(style)
      selectedWay = null

  displayNodeData = (node) ->

      displayNodeData(selectedNode.node)
      retrieveNode(selectedNode.node.id)

  selectWay = (way) ->
    shouldSelect = !selectedWay? or way != selectedWay
    deselectWay()
    if shouldSelect
      selectedWay = way
      selectedWay.setStyle(selectedWay.selectedStyle)
      displayWayData(way.way)

  $(() ->
