vendor/plugins/google_maps/lib/google_map.rb
# Creates a JS function that centers the map on the specified center
# location if given to the initialisers, or on the maps markers if they exist, or
# at (0,0) if not.

Creates a JS function that centers the map on the specified center
location if given to the initialisers, or on the maps markers if they exist, or
at (0,0) if not.
Creates a JS function that centers the map on the specified center location if given to the initialisers or on the maps markers if they exist or at ( 0 0 ) if not .
def center_map_js
    if markers.size == 0
      set_center_js = "#{dom_id}.setCenter(new GLatLng(0, 0), 0);"
    else
      if self.center
        max_lat = @center[0] + 0.05
        min_lat = @center[0] - 0.05
        max_lng = @center[1] + 0.05
        min_lng = @center[1] - 0.05
        center_js = "new GLatLng(#{center[0]}, #{center[1]})"
      else
        for marker in markers
          min_lat = marker.lat if !min_lat or marker.lat < min_lat
          max_lat = marker.lat if !max_lat or marker.lat > max_lat
          min_lng = marker.lng if !min_lng or marker.lng < min_lng
          max_lng = marker.lng if !max_lng or marker.lng > max_lng
          center_js = "new GLatLng(#{(min_lat + max_lat) / 2}, #{(min_lng + max_lng) / 2})"
        end
      end
      if self.zoom
        zoom_js = zoom
      else
        bounds_js = "new GLatLngBounds(new GLatLng(#{min_lat}, #{min_lng}), new GLatLng(#{max_lat}, #{max_lng}))"
        zoom_js = "#{dom_id}.getBoundsZoomLevel(#{bounds_js})"
      end
      set_center_js = "#{dom_id}.setCenter(#{center_js}, #{zoom_js});"
    end
    return "function center_#{dom_id}() {\n  #{check_resize_js}\n  #{set_center_js}\n}"
  end
def center_map_js if markers . size == 0 set_center_js = "#{dom_id}.setCenter(new GLatLng(0, 0), 0);" else if self . center max_lat = @center [ 0 ] + 0.05 min_lat = @center [ 0 ] - 0.05 max_lng = @center [ 1 ] + 0.05 min_lng = @center [ 1 ] - 0.05 center_js = "new GLatLng(#{center[0]}, #{center[1]})" else for marker in markers min_lat = marker . lat if ! min_lat or marker . lat < min_lat max_lat = marker . lat if ! max_lat or marker . lat > max_lat min_lng = marker . lng if ! min_lng or marker . lng < min_lng max_lng = marker . lng if ! max_lng or marker . lng > max_lng center_js = "new GLatLng(#{(min_lat + max_lat) / 2}, #{(min_lng + max_lng) / 2})" end end if self . zoom zoom_js = zoom else bounds_js = "new GLatLngBounds(new GLatLng(#{min_lat}, #{min_lng}), new GLatLng(#{max_lat}, #{max_lng}))" zoom_js = "#{dom_id}.getBoundsZoomLevel(#{bounds_js})" end set_center_js = "#{dom_id}.setCenter(#{center_js}, #{zoom_js});" end return "function center_#{dom_id}() {\n  #{check_resize_js}\n  #{set_center_js}\n}" end
Creates a JS function that centers the map on the specified center
location if given to the initialisers, or on the maps markers if they exist, or
at (0,0) if not.
Creates a JS function that centers the map on the specified center location if given to the initialisers or on the maps markers if they exist or at ( 0 0 ) if not .