Sha256: bbcc55581189d1dc7735199c7a2bb4dbd40d78de4888ef99e3302f11d0537528

Contents?: true

Size: 1.72 KB

Versions: 3

Compression:

Stored size: 1.72 KB

Contents

class @Location extends Backbone.View

  initElements : () ->
    @$map = @$el.find('.map')
    @$latitude = @$el.find('[data-location-attribute="latitude"]')
    @$longitude = @$el.find('[data-location-attribute="longitude"]')
    @$zoom = @$el.find('[data-location-attribute="zoom"]')

  initMap : () ->
    @_initMap()
    @_initLayer()
    @_initMarker()

  _initMap : () ->
    @center = [@$latitude.val(), @$longitude.val()]
    @map = L.map(@$map.attr('id')).setView(@center, @$zoom.val())
    @map.on 'zoomend', (event) =>
      @$zoom.val event.target.getZoom()

  _initLayer : () ->
    L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
      attribution : '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
    }).addTo(@map)

  _initMarker : () ->
    marker = new L.marker @center,
      icon : L.icon
        iconUrl : '<%= asset_path('rademade_admin/leaflet/marker-icon.png') %>'
        shadowUrl : '<%= asset_path('rademade_admin/leaflet/marker-shadow.png') %>'
        iconSize : [25, 41]
        shadowSize : [41, 41]
        iconAnchor : [12, 41]
        shadowAnchor: [12, 41]
      draggable : true
    marker.on 'dragend', (event) =>
      @_updateLatLng event.target.getLatLng()
    marker.addTo(@map)

  _updateLatLng : (latLng) ->
    @$latitude.val latLng.lat
    @$longitude.val latLng.lng

  @init : ($el) ->
    location = new this
      el : $el
    location.initElements()
    location.initMap()

  @initAll : () ->
    $('.location').each (index, el) =>
      $location = $(el)
      unless $location.data('initialized')
        @init $location
        $location.data('initialized', true)

  @initPlugin : () =>
    @initAll()

$ ->
  $(document).on 'page:load ready init-plugins', Location.initPlugin

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rademade_admin-0.2.2 app/assets/javascripts/rademade_admin/app/common/location.coffee.erb
rademade_admin-0.2.1 app/assets/javascripts/rademade_admin/app/common/location.coffee.erb
rademade_admin-0.2.0 app/assets/javascripts/rademade_admin/app/common/location.coffee.erb