Module: Mappable

Extended by:
ActiveSupport::Concern
Included in:
Geocodeable
Defined in:
app/models/concerns/mappable.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.adminObject


92
93
94
# File 'app/models/concerns/mappable.rb', line 92

def self.admin
  RocketCMS.map_config
end

Instance Method Details

#coordinatesObject


23
24
25
26
27
28
29
# File 'app/models/concerns/mappable.rb', line 23

def coordinates
  if latitude.nil? || longitude.nil?
    nil
  else
    [longitude, latitude]
  end
end

#do_geocodeObject


32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/models/concerns/mappable.rb', line 32

def do_geocode
  if geo_address.blank?
    if RocketCMS.mongoid?
      self.coordinates = nil
    else
      self.latitude = nil
      self.longitude = nil
    end
  else
    if (lat.nil? || lon.nil?) && (new_record? || address_changed? || coordinates.nil? || map_address_changed?)
      geocode
    end
  end
end

#geo_addressObject


84
85
86
87
88
89
90
# File 'app/models/concerns/mappable.rb', line 84

def geo_address
  if map_address.blank?
    address
  else
    map_address
  end
end

#get_latObject


47
48
49
50
51
52
53
54
55
56
57
# File 'app/models/concerns/mappable.rb', line 47

def get_lat
  if lat.blank? 
    if coordinates.nil?
      nil
    else
      coordinates[1]
    end
  else
    lat
  end
end

#get_lonObject


58
59
60
61
62
63
64
65
66
67
68
# File 'app/models/concerns/mappable.rb', line 58

def get_lon
  if lon.blank? 
    if coordinates.nil?
      nil
    else
      coordinates[0]
    end
  else
    lon
  end
end

#has_map?Boolean

Returns:

  • (Boolean)

70
71
72
# File 'app/models/concerns/mappable.rb', line 70

def has_map?
  (!lat.blank? && !lon.blank?) || !coordinates.nil?
end

#to_mapObject


74
75
76
77
78
79
80
81
82
# File 'app/models/concerns/mappable.rb', line 74

def to_map
  {
    id: id.to_s,
    hint: map_hint,
    addr: address,
    lat: get_lat,
    lon: get_lon,
  }
end