Sha256: feb8533c8ce74d9ab3c593c03faf97574438ee2c9357cb76ece0b34ad04c2738

Contents?: true

Size: 1.89 KB

Versions: 5

Compression:

Stored size: 1.89 KB

Contents

class ADF.Minimap.Views.Main extends ADF.MVC.Views.Base
  
  mapOptions: {}
  map_id: "adf_minimap_canvas"
  
  constructor: (options) ->
    super(options) 
    @model = new ADF.Minimap.Models.Minimap(@mapOptions)
    @map_id = options.map_id if options.map_id
    
  render: () ->
    @containerArea = @make("div", {"id" : @map_id} )
    @setElement( @containerArea )
    @
    
    return this 
  
  renderMap: ->
    @bindResizeEvents()
    @model.initGMap(@map_id)
    @tooltip = new ADF.Minimap.Views.Tooltip({map: @getMap(), containerArea: @containerArea })
    @resize()
    @initTooltip()
    @onRenderCompleted()

  initTooltip: () ->
    $(@containerArea).append( @tooltip.render().el )
              
  bindResizeEvents: ->
    $(window).resize =>
      @resize()
          
    $(document).ready =>
      @resize()
  
  resize: ->
    $(@containerArea).css({"position" : "relative", "height" : "100%", "width" : "100%"})
    google.maps.event.trigger( @model.getGMap(), "resize") if @model.getGMap()

  getMap: () ->
    @model

  setCenter: (latLng) ->
    @model.setCenter(latLng)

  setCenterWithOffset: (position, offsetx, offsety) ->
    @model.setCenter(position)
    zoomLevel = @model.getGMap().getZoom()
    max = Math.pow(2,zoomLevel) * 256;
    lng = -(offsetx / max) * 100 + position.lng()
    lat = -(offsety / max) * 100 + position.lat()
    pos = new google.maps.LatLng(lat, lng)
    @model.setCenter(pos)
    
  getGMap: () ->
    @model.getGMap()
    
  fitBounds: (bounds_array, centerWithOffset) ->
    if bounds_array
      bounds = new google.maps.LatLngBounds()
      _.each bounds_array, (marker) =>
        bounds.extend(new google.maps.LatLng(marker.lat, marker.lng))
      @model.fitBounds(bounds)
      @model.getGMap().setZoom(@model.getGMap().getZoom() - 1)
      @setCenterWithOffset(@model.getGMap().getCenter(), 0, -300) if centerWithOffset
    
  # Callback methods
  onRenderCompleted: () ->

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
socmap_adf-0.0.5 lib/assets/javascripts/socmap_adf/modules/minimap/views/main.js.coffee
socmap_adf-0.0.4 lib/assets/javascripts/socmap_adf/modules/minimap/views/main.js.coffee
socmap_adf-0.0.3 lib/assets/javascripts/socmap_adf/modules/minimap/views/main.js.coffee
socmap_adf-0.0.2 lib/assets/javascripts/socmap_adf/modules/minimap/views/main.js.coffee
socmap_adf-0.0.1 lib/assets/javascripts/socmap_adf/modules/minimap/views/main.js.coffee