SeriouslyAwesome/democratictravelers

View on GitHub
app/assets/javascripts/map.js.coffee.erb

Summary

Maintainability
Test Coverage
DemocraticTravelers.Map =
  Router: new Router()
  Search: {}
  Marker: {}
  Auth: {}
  CurrentLocation: {}
  Suggestions: {}
  mapObject: null
  searchLayer: null
  locationsLayer: null
  markers: []
  
  init: ->
    # Initialize Map
    @mapObject = L.mapbox.map 'map', 'seriouslyawesome.i675cgi9',
      center: [37.09024, -95.71289100000001]
      zoom: 4
      minZoom: 4
      maxZoom: 12
  
    offset = @mapObject.getSize().x * 0.15
    @mapObject.panBy new L.Point(offset, 0), { animate: false }
    @mapObject.zoomControl.setPosition 'bottomleft'

    # Initialize Markers
    @locationsLayer = L.layerGroup().addTo(@mapObject)
    @CurrentLocation.init(@mapObject)
    @Suggestions.initialize()
    @Suggestions.fetch()
    @Search.initialize(@mapObject)
    @Auth.initialize()

    # Setup Map/List view toggler
    @initDragFiltering()
    $('#show-map, #show-list').click ->
      DemocraticTravelers.Map.toggleView this
      
    $('#map-list').on 'click', '.map-user-link', (e)->
      e.preventDefault();
      DemocraticTravelers.Map.Router.navigate($(this).attr('href'), "#{$(this).html()}'s Suggestions | The Democratic Travelers")

  toggleView: (button) ->
    $(button).hide()
    $(button).siblings().show()
    $('#map-list').slideToggle('fast')

  toggleForm: ->
    $('#new-suggestion').slideToggle('fast').reset()

  renderMarkers: (locations) ->
    for location in locations
      @Marker.render(location)
      
  initDragFiltering: ->
    # Initialize list filtering on map move
    @mapObject.on 'moveend', =>
      DemocraticTravelers.Map.Experiences.filterList()