Module: Mappable
- Extended by:
- ActiveSupport::Concern
- Included in:
- Geocodeable
- Defined in:
- app/models/concerns/mappable.rb
Class Method Summary collapse
Instance Method Summary collapse
- #coordinates ⇒ Object
- #do_geocode ⇒ Object
- #geo_address ⇒ Object
- #get_lat ⇒ Object
- #get_lon ⇒ Object
- #has_map? ⇒ Boolean
- #to_map ⇒ Object
Class Method Details
.admin ⇒ Object
92 93 94 |
# File 'app/models/concerns/mappable.rb', line 92 def self.admin RocketCMS.map_config end |
Instance Method Details
#coordinates ⇒ Object
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_geocode ⇒ Object
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_address ⇒ Object
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_lat ⇒ Object
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_lon ⇒ Object
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
70 71 72 |
# File 'app/models/concerns/mappable.rb', line 70 def has_map? (!lat.blank? && !lon.blank?) || !coordinates.nil? end |
#to_map ⇒ Object
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 |