Class: Formotion::RowType::MapRow
- Inherits:
-
Base
show all
- Includes:
- BW::KVO
- Defined in:
- lib/formotion/row_type/map_row.rb
Constant Summary
collapse
- MAP_VIEW_TAG =
1100
Instance Attribute Summary
Attributes inherited from Base
#row, #tableView
Instance Method Summary
collapse
Methods inherited from Base
#_on_select, #after_build, #after_delete, #break_with_semaphore, #button?, #cellEditingStyle, #cell_style, #delete_row, field_buffer, #indentWhileEditing?, #initialize, #on_delete, #update_cell, #with_semaphore
Instance Method Details
#annotations ⇒ Object
48
49
50
|
# File 'lib/formotion/row_type/map_row.rb', line 48
def annotations
@map_view.annotations
end
|
#build_cell(cell) ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/formotion/row_type/map_row.rb', line 52
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
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
end
|
#on_select(tableView, tableViewDelegate) ⇒ Object
88
89
90
91
92
|
# File 'lib/formotion/row_type/map_row.rb', line 88
def on_select(tableView, tableViewDelegate)
if !row.editable?
return
end
end
|
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/formotion/row_type/map_row.rb', line 36
def set_pin
return unless row.value
coord = (row.value.is_a?(Array) and row.value.size==2) ? CLLocationCoordinate2D.new(row.value[0], row.value[1]) : row.value
if coord.is_a?(CLLocationCoordinate2D)
@map_view.removeAnnotation(@map_row_data) if @map_row_data
region = MKCoordinateRegionMakeWithDistance(coord, 400.0, 480.0)
@map_row_data = MapRowData.new(nil, nil, coord)
@map_view.setRegion(region, animated:true)
@map_view.addAnnotation(@map_row_data)
end
end
|