class Formotion::RowType::MapRow
Constants
- MAP_VIEW_TAG
Public Instance Methods
annotations()
click to toggle source
# File lib/formotion/row_type/map_row.rb, line 81 def annotations @map_view.annotations end
build_cell(cell)
click to toggle source
# File lib/formotion/row_type/map_row.rb, line 89 def build_cell(cell) cell.selectionStyle = self.row.selection_style || UITableViewCellSelectionStyleBlue @map_view = MKMapView.alloc.init @map_view.delegate = self set_pin observe(self.row, "value") do |old_value, new_value| break_with_semaphore do set_pin end end @map_view.tag = MAP_VIEW_TAG @map_view.contentMode = UIViewContentModeScaleAspectFit @map_view.backgroundColor = UIColor.clearColor cell.addSubview(@map_view) cell.swizzle(:layoutSubviews) do def layoutSubviews old_layoutSubviews # viewWithTag is terrible, but I think it's ok to use here... formotion_field = self.viewWithTag(MAP_VIEW_TAG) field_frame = formotion_field.frame field_frame.origin.y = 10 field_frame.origin.x = self.textLabel.frame.origin.x + self.textLabel.frame.size.width + Formotion::RowType::Base.field_buffer field_frame.size.width = self.frame.size.width - field_frame.origin.x - Formotion::RowType::Base.field_buffer field_frame.size.height = self.frame.size.height - Formotion::RowType::Base.field_buffer formotion_field.frame = field_frame end end nil end
layoutSubviews()
click to toggle source
# File lib/formotion/row_type/map_row.rb, line 109 def layoutSubviews old_layoutSubviews # viewWithTag is terrible, but I think it's ok to use here... formotion_field = self.viewWithTag(MAP_VIEW_TAG) field_frame = formotion_field.frame field_frame.origin.y = 10 field_frame.origin.x = self.textLabel.frame.origin.x + self.textLabel.frame.size.width + Formotion::RowType::Base.field_buffer field_frame.size.width = self.frame.size.width - field_frame.origin.x - Formotion::RowType::Base.field_buffer field_frame.size.height = self.frame.size.height - Formotion::RowType::Base.field_buffer formotion_field.frame = field_frame end
map()
click to toggle source
# File lib/formotion/row_type/map_row.rb, line 85 def map @map_view end
on_select(tableView, tableViewDelegate)
click to toggle source
# File lib/formotion/row_type/map_row.rb, line 127 def on_select(tableView, tableViewDelegate) if !row.editable? return end end
set_pin()
click to toggle source
# File lib/formotion/row_type/map_row.rb, line 40 def set_pin return unless row.value unless row.value.is_a?(Hash) coord = (row.value.is_a?(Array) and row.value.size==2) ? CLLocationCoordinate2D.new(row.value[0], row.value[1]) : row.value row.value = {coord: coord, pin: {coord:coord}} end # Set Defaults row.value = { animated: true, type: MKMapTypeStandard, enabled: true }.merge(row.value) if row.value[:coord].is_a?(CLLocationCoordinate2D) region = MKCoordinateRegionMakeWithDistance(row.value[:coord], 400.0, 480.0) elsif row.value[:coord].is_a?(CLCircularRegion) region = MKCoordinateRegionMakeWithDistance( row.value[:coord].center, row.value[:coord].radius * 2, row.value[:coord].radius * 2 ) else return end if row.value[:pin] row.value[:pin] = {title: nil, subtitle:nil}.merge(row.value[:pin]) #Defaults @map_row_data = MapRowData.new(row.value[:pin]) @map_view.removeAnnotations(@map_view.annotations) @map_view.addAnnotation(@map_row_data) @map_view.selectAnnotation(@map_row_data, animated:row.value[:animated]) if row.value[:pin][:title] end @map_view.setUserInteractionEnabled(row.value[:enabled]) @map_view.setMapType(row.value[:type]) @map_view.setRegion(region, animated:row.value[:animated]) end