ProMotion-mapbox 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +23 -24
- data/lib/ProMotion-mapbox.rb +2 -6
- data/lib/ProMotion/map/map_screen_annotation.rb +30 -43
- data/lib/ProMotion/map/map_screen_module.rb +102 -120
- metadata +30 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c26888901adec0750d41242b2120fb1c6d2e73c
|
4
|
+
data.tar.gz: 7340940dd5deb688654f3f3b47cd0124e5932f81
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79a7d189d2a8a1cd8d2c8f68a56c432139ab83e386e33e67b4134fe084f6f52400a7b8564bfe9a32d41c86f39eb5742c6ccfe5c4ae097bf8afdccf53e16e8d18
|
7
|
+
data.tar.gz: b0eb414d8389ebaf6fd139dfc88765fc729a4c488424f6f8ece6c27e8a7516939db93be252e6d4c772c17b390b38a80f39796d4a5ef94145840be7237b008107
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/ProMotion-mapbox.svg)](http://badge.fury.io/rb/ProMotion-mapbox)
|
4
4
|
|
5
|
-
ProMotion-mapbox provides a PM::MapScreen
|
5
|
+
ProMotion-mapbox provides a PM::MapScreen that users [Mapbox](https://www.mapbox.com) as the map provider. Forked from the
|
6
6
|
popular RubyMotion gem [ProMotion-map](https://github.com/clearsightstudio/ProMotion-map).
|
7
7
|
|
8
8
|
## Installation
|
@@ -23,9 +23,6 @@ Easily create a map screen, complete with annotations.
|
|
23
23
|
|
24
24
|
```ruby
|
25
25
|
class MyMapScreen < PM::MapScreen
|
26
|
-
mapbox_setup access_token: "YOU_MAPBOX_ACCESS_TOKEN",
|
27
|
-
tile_source: "mylogin.map"
|
28
|
-
|
29
26
|
title "My Map"
|
30
27
|
start_position latitude: 35.090648651123, longitude: -82.965972900391, radius: 4
|
31
28
|
tap_to_add
|
@@ -36,39 +33,40 @@ class MyMapScreen < PM::MapScreen
|
|
36
33
|
latitude: 35.090648651123,
|
37
34
|
title: "Rainbow Falls",
|
38
35
|
subtitle: "Nantahala National Forest",
|
39
|
-
|
36
|
+
left_action: :show_forest,
|
40
37
|
pin_color: :green
|
41
38
|
},{
|
42
39
|
longitude: -82.966093558105,
|
43
40
|
latitude: 35.092520895652,
|
44
41
|
title: "Turtleback Falls",
|
45
42
|
subtitle: "Nantahala National Forest",
|
46
|
-
|
47
|
-
|
43
|
+
left_action: :show_forest,
|
44
|
+
left_action_button_type: UIButtonTypeContactAdd,
|
45
|
+
pin_color: :red
|
48
46
|
},{
|
49
47
|
longitude: -82.95916,
|
50
48
|
latitude: 35.07496,
|
51
49
|
title: "Windy Falls",
|
52
|
-
|
50
|
+
left_action: :show_forest
|
53
51
|
},{
|
54
52
|
longitude: -82.943031505056,
|
55
53
|
latitude: 35.102516828489,
|
56
54
|
title: "Upper Bearwallow Falls",
|
57
55
|
subtitle: "Gorges State Park",
|
58
|
-
|
56
|
+
left_action: :show_forest
|
59
57
|
},{
|
60
58
|
longitude: -82.956244328014,
|
61
59
|
latitude: 35.085548421623,
|
62
60
|
title: "Stairway Falls",
|
63
61
|
subtitle: "Gorges State Park",
|
64
62
|
your_param: "CustomWhatever",
|
65
|
-
|
66
|
-
},
|
67
|
-
coordinate: CLLocationCoordinate2DMake(35.090648651123, -82.965972900391)
|
63
|
+
right_action: :show_forest
|
64
|
+
},{
|
65
|
+
coordinate: CLLocationCoordinate2DMake(35.090648651123, -82.965972900391),
|
68
66
|
title: "Rainbow Falls",
|
69
67
|
subtitle: "Nantahala National Forest",
|
70
68
|
image: UIImage.imageNamed("custom-pin"),
|
71
|
-
|
69
|
+
left_action: :show_forest
|
72
70
|
}]
|
73
71
|
end
|
74
72
|
|
@@ -83,7 +81,7 @@ Here's a neat way to zoom into a specific marker in an animated fashion and then
|
|
83
81
|
|
84
82
|
```ruby
|
85
83
|
def zoom_to_marker(marker)
|
86
|
-
|
84
|
+
set_region region(coordinate: marker.coordinate, radius: 5) # Radius are specified in nautical miles.
|
87
85
|
select_annotation marker
|
88
86
|
end
|
89
87
|
```
|
@@ -110,7 +108,7 @@ All possible properties:
|
|
110
108
|
title: "Stairway Falls", # REQUIRED
|
111
109
|
subtitle: "Gorges State Park",
|
112
110
|
image: "my_custom_image",
|
113
|
-
pin_color: :red, # Defaults to :red. Other options are :green or :purple
|
111
|
+
pin_color: :red, # Defaults to :red. Other options are :green or :purple. Here as a placeholder only. Modifying a marker color is not yet supported by the Mapbox GL SDK.
|
114
112
|
left_accessory: my_button,
|
115
113
|
right_accessory: my_other_button,
|
116
114
|
action: :my_action, # Overrides :right_accessory
|
@@ -124,6 +122,8 @@ Use `:image` to specify a custom image. Pass in a string to conserve memory and
|
|
124
122
|
|
125
123
|
Use `:left_accessory` and `:right_accessory` to specify a custom accessory, like a button.
|
126
124
|
|
125
|
+
Use `:left_action` and `:right_action` to specify an action for the left or right accessory view. These properties will create a button for you, and should not be used in conjunction with `:left_accessory` or `:right_accessory`. The type of the button can be specified with the optional parameter `:right_action_button_type`, and defaults to UIButtonTypeDetailDisclosure if not specified.
|
126
|
+
|
127
127
|
You can access annotation data you've arbitrarily stored in the hash by calling `annotation_instance.params[:your_param]`.
|
128
128
|
|
129
129
|
The `:action` parameter specifies a method that should be run when the detail button is tapped on the annotation. It automatically adds a `UIButtonTypeDetailDisclosure` button to the `:left_accessory`. In your method you can find out which annotation's accessory was tapped by calling `selected_annotations.first`.
|
@@ -187,13 +187,13 @@ Selects a single annotation.
|
|
187
187
|
|
188
188
|
Selects a single annotation using the annotation at the index of your `annotation_data` array.
|
189
189
|
|
190
|
-
####
|
190
|
+
#### selected_annotations
|
191
191
|
|
192
|
-
Returns
|
192
|
+
Returns an array of annotations that are selected. If no annotations are selected, returns `nil`.
|
193
193
|
|
194
|
-
####
|
194
|
+
#### deselect_annotations(animated=false)
|
195
195
|
|
196
|
-
Deselects
|
196
|
+
Deselects all selected annotations.
|
197
197
|
|
198
198
|
#### add_annotation(annotation)
|
199
199
|
|
@@ -217,7 +217,7 @@ Sets the region of the `MapScreen`. `region` should be an instance of `MKCoordin
|
|
217
217
|
|
218
218
|
#### region(center_location,radius=10)
|
219
219
|
|
220
|
-
Mapbox
|
220
|
+
Mapbox doesn't use the concept of regions. Instead, we can zoom to a virtual bounding box defined by its Sourthwest and Northeast
|
221
221
|
corners.
|
222
222
|
The ```region``` methods takes a ```center_location``` and a radius. The distance from the center to the corners (and thus the zoom level) will be the ```radius``` times 1820 meters (1 Nautical mile)
|
223
223
|
|
@@ -226,7 +226,6 @@ my_region = region({
|
|
226
226
|
CLLocationCoordinate2D.new(35.0906,-82.965),
|
227
227
|
radius: 11
|
228
228
|
})
|
229
|
-
```
|
230
229
|
|
231
230
|
---
|
232
231
|
|
@@ -293,8 +292,8 @@ class MyMapScreen < PM::MapScreen
|
|
293
292
|
end
|
294
293
|
|
295
294
|
def will_appear
|
296
|
-
NSNotificationCenter.defaultCenter.addObserver(self, selector:"pin_adding:"
|
297
|
-
NSNotificationCenter.defaultCenter.addObserver(self, selector:"pin_added:"
|
295
|
+
NSNotificationCenter.defaultCenter.addObserver(self, selector:"pin_adding:", name:"ProMotionMapWillAddPin", object:nil)
|
296
|
+
NSNotificationCenter.defaultCenter.addObserver(self, selector:"pin_added:", name:"ProMotionMapAddedPin", object:nil)
|
298
297
|
end
|
299
298
|
|
300
299
|
def will_disappear
|
@@ -364,7 +363,7 @@ rotate_enabled = (bool)enabled
|
|
364
363
|
|
365
364
|
#### `map` or `mapview`
|
366
365
|
|
367
|
-
Reference to the created
|
366
|
+
Reference to the created MLGMapView.
|
368
367
|
|
369
368
|
## Contributing
|
370
369
|
|
data/lib/ProMotion-mapbox.rb
CHANGED
@@ -3,18 +3,14 @@ unless defined?(Motion::Project::Config)
|
|
3
3
|
raise "ProMotion-mapbox must be required within a RubyMotion project."
|
4
4
|
end
|
5
5
|
|
6
|
-
require 'motion-cocoapods'
|
7
|
-
|
8
6
|
Motion::Project::App.setup do |app|
|
9
7
|
lib_dir_path = File.dirname(File.expand_path(__FILE__))
|
10
8
|
app.files << File.join(lib_dir_path, "ProMotion/map/map_screen_annotation.rb")
|
11
9
|
app.files << File.join(lib_dir_path, "ProMotion/map/map_screen_module.rb")
|
12
10
|
app.files << File.join(lib_dir_path, "ProMotion/map/map_screen.rb")
|
13
11
|
|
14
|
-
app.frameworks += %w(CoreLocation)
|
15
|
-
|
12
|
+
app.frameworks += %w(CoreLocation QuartzCore)
|
16
13
|
app.pods do
|
17
|
-
pod
|
14
|
+
pod 'Mapbox-iOS-SDK'
|
18
15
|
end
|
19
|
-
|
20
16
|
end
|
@@ -1,47 +1,35 @@
|
|
1
1
|
module ProMotion
|
2
|
-
class MapScreenAnnotation
|
2
|
+
class MapScreenAnnotation
|
3
3
|
attr_reader :params
|
4
4
|
|
5
|
-
|
5
|
+
# Creates the new annotation object
|
6
|
+
def initialize(params = {})
|
6
7
|
@params = params
|
7
|
-
@map_view = map_view
|
8
8
|
set_defaults
|
9
|
+
|
9
10
|
if @params[:coordinate]
|
10
11
|
@params[:latitude] = @params[:coordinate].latitude
|
11
12
|
@params[:longitude] = @params[:coordinate].longitude
|
12
13
|
@coordinate = @params[:coordinate]
|
13
|
-
initWithMapView(map_view, coordinate: @coordinate, andTitle: @params[:title])
|
14
14
|
elsif @params[:latitude] && @params[:longitude]
|
15
15
|
@coordinate = CLLocationCoordinate2D.new(@params[:latitude], @params[:longitude])
|
16
|
-
initWithMapView(map_view, coordinate: @coordinate, andTitle: @params[:title])
|
17
16
|
else
|
18
17
|
PM.logger.error("You are required to specify :latitude and :longitude or :coordinate for annotations.")
|
19
18
|
nil
|
20
19
|
end
|
21
|
-
self.userInfo = @params
|
22
20
|
end
|
23
|
-
|
21
|
+
|
24
22
|
def set_defaults
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
@params = {
|
36
|
-
title: @params.annotations.count,
|
37
|
-
coordinate: @params.clusterAnnotation.coordinate,
|
38
|
-
pin_color: :purple,
|
39
|
-
identifier: "Annotation-cluster",
|
40
|
-
show_callout: true,
|
41
|
-
animates_drop: false,
|
42
|
-
maki_icon: nil,
|
43
|
-
}
|
44
|
-
end
|
23
|
+
@params = {
|
24
|
+
title: "Title",
|
25
|
+
pin_color: :red,
|
26
|
+
identifier: "Annotation-#{@params[:pin_color]}-#{@params[:image]}",
|
27
|
+
show_callout: true,
|
28
|
+
animates_drop: false,
|
29
|
+
image: nil,
|
30
|
+
left_accessory: nil,
|
31
|
+
right_accessory: nil,
|
32
|
+
}.merge(@params)
|
45
33
|
end
|
46
34
|
|
47
35
|
def title
|
@@ -55,34 +43,27 @@ module ProMotion
|
|
55
43
|
def coordinate
|
56
44
|
@coordinate
|
57
45
|
end
|
58
|
-
|
59
|
-
def
|
60
|
-
@params[:
|
46
|
+
|
47
|
+
def left_accessory
|
48
|
+
@params[:left_accessory]
|
49
|
+
end
|
50
|
+
|
51
|
+
def right_accessory
|
52
|
+
@params[:right_accessory]
|
61
53
|
end
|
62
54
|
|
63
55
|
def cllocation
|
64
56
|
CLLocation.alloc.initWithLatitude(@params[:latitude], longitude:@params[:longitude])
|
65
57
|
end
|
66
58
|
|
67
|
-
def setCoordinate(new_coordinate)
|
68
|
-
super
|
59
|
+
def setCoordinate(new_coordinate);
|
69
60
|
if new_coordinate.is_a? Hash
|
70
61
|
@coordinate = CLLocationCoordinate2D.new(new_coordinate[:latitude], new_coordinate[:longitude])
|
71
62
|
else
|
72
63
|
@coordinate = new_coordinate
|
73
64
|
end
|
74
65
|
end
|
75
|
-
|
76
|
-
def self.new_with_rmannotation(rmannotation,map_view)
|
77
|
-
annotation = self.new(rmannotation.userInfo, map_view)
|
78
|
-
%w(coordinate title subtitle userInfo annotationType annotationIcon
|
79
|
-
position layer clusteringEnabled
|
80
|
-
isClusterAnnotation isUserLocationAnnotation).each do |meth|
|
81
|
-
annotation.send("#{meth}=", rmannotation.send(meth))
|
82
|
-
end
|
83
|
-
annotation
|
84
|
-
end
|
85
|
-
|
66
|
+
|
86
67
|
def method_missing(meth, *args)
|
87
68
|
if @params[meth.to_sym]
|
88
69
|
@params[meth.to_sym]
|
@@ -92,5 +73,11 @@ module ProMotion
|
|
92
73
|
end
|
93
74
|
end
|
94
75
|
|
76
|
+
# Deprecated
|
77
|
+
def annotation_params
|
78
|
+
PM.logger.warn("annotation.annotation_params is deprecated and will be removed soon. Please use annotation.params instead.")
|
79
|
+
@params
|
80
|
+
end
|
81
|
+
|
95
82
|
end
|
96
83
|
end
|
@@ -6,38 +6,22 @@ module ProMotion
|
|
6
6
|
green: UIColor.greenColor,
|
7
7
|
purple: UIColor.purpleColor
|
8
8
|
}
|
9
|
-
|
9
|
+
|
10
10
|
def screen_setup
|
11
|
-
mapbox_setup
|
12
11
|
self.view = nil
|
13
|
-
self.view =
|
12
|
+
self.view = MGLMapView.alloc.initWithFrame(self.view.bounds, styleURL: self.class.get_map_style)
|
14
13
|
self.view.delegate = self
|
14
|
+
|
15
15
|
check_annotation_data
|
16
16
|
@promotion_annotation_data = []
|
17
|
+
set_up_start_position
|
17
18
|
set_up_tap_to_add
|
18
19
|
end
|
19
|
-
|
20
|
-
def
|
21
|
-
if self.class.respond_to?(:get_mapbox_setup) && self.class.get_mapbox_setup
|
22
|
-
setup_params = self.class.get_mapbox_setup_params
|
23
|
-
else
|
24
|
-
PM.logger.error "Missing Mapbox setup data."
|
25
|
-
end
|
26
|
-
RMConfiguration.sharedInstance.setAccessToken(setup_params[:access_token]) if RMConfiguration.sharedInstance.accessToken.nil?
|
27
|
-
@tileSource = RMMapboxSource.alloc.initWithMapID(setup_params[:tile_source])
|
28
|
-
end
|
29
|
-
|
30
|
-
def view_will_appear(animated)
|
31
|
-
super
|
20
|
+
|
21
|
+
def on_appear
|
32
22
|
update_annotation_data
|
33
|
-
set_up_start_center
|
34
23
|
end
|
35
24
|
|
36
|
-
def view_did_appear(animated)
|
37
|
-
super
|
38
|
-
set_up_start_region
|
39
|
-
end
|
40
|
-
|
41
25
|
def check_annotation_data
|
42
26
|
PM.logger.error "Missing #annotation_data method in MapScreen #{self.class.to_s}." unless self.respond_to?(:annotation_data)
|
43
27
|
end
|
@@ -46,7 +30,7 @@ module ProMotion
|
|
46
30
|
clear_annotations
|
47
31
|
add_annotations annotation_data
|
48
32
|
end
|
49
|
-
|
33
|
+
|
50
34
|
def map
|
51
35
|
self.view
|
52
36
|
end
|
@@ -80,8 +64,9 @@ module ProMotion
|
|
80
64
|
set_show_user_location false
|
81
65
|
end
|
82
66
|
|
83
|
-
def set_show_user_location(show)
|
67
|
+
def set_show_user_location(show,mode=MGLUserTrackingModeFollow)
|
84
68
|
self.view.showsUserLocation = show
|
69
|
+
self.view.userTrackingMode = mode
|
85
70
|
end
|
86
71
|
|
87
72
|
def showing_user_location?
|
@@ -93,7 +78,7 @@ module ProMotion
|
|
93
78
|
end
|
94
79
|
|
95
80
|
def user_annotation
|
96
|
-
self.view.userLocation.nil? ? nil : self.view.userLocation.location
|
81
|
+
self.view.userLocation.location.nil? ? nil : self.view.userLocation.location
|
97
82
|
end
|
98
83
|
|
99
84
|
def zoom_to_user(radius = 0.05, animated=true)
|
@@ -113,65 +98,36 @@ module ProMotion
|
|
113
98
|
select_annotation(annotations[annotation_index], animated:animated)
|
114
99
|
end
|
115
100
|
|
116
|
-
def
|
117
|
-
self.view.
|
101
|
+
def selected_annotations
|
102
|
+
self.view.selectedAnnotations
|
118
103
|
end
|
119
104
|
|
120
|
-
def
|
121
|
-
unless
|
122
|
-
|
105
|
+
def deselect_annotations(animated=false)
|
106
|
+
unless selected_annotations.nil?
|
107
|
+
selected_annotations.each do |annotation|
|
108
|
+
self.view.deselectAnnotation(annotation, animated:animated)
|
109
|
+
end
|
123
110
|
end
|
124
111
|
end
|
125
112
|
|
126
113
|
def add_annotation(annotation)
|
127
|
-
@promotion_annotation_data << MapScreenAnnotation.new(annotation
|
114
|
+
@promotion_annotation_data << MapScreenAnnotation.new(annotation)
|
128
115
|
self.view.addAnnotation @promotion_annotation_data.last
|
129
116
|
end
|
130
117
|
|
131
118
|
def add_annotations(annotations)
|
132
|
-
@promotion_annotation_data = Array(annotations).map{|a| MapScreenAnnotation.new(a
|
119
|
+
@promotion_annotation_data = Array(annotations).map{|a| MapScreenAnnotation.new(a)}
|
133
120
|
self.view.addAnnotations @promotion_annotation_data
|
134
121
|
end
|
135
122
|
|
136
|
-
def
|
137
|
-
|
138
|
-
|
139
|
-
end
|
140
|
-
@promotion_annotation_data = []
|
123
|
+
def clear_annotation(annotation)
|
124
|
+
self.view.removeAnnotation(annotation)
|
125
|
+
@promotion_annotation_data.delete(annotation)
|
141
126
|
end
|
142
127
|
|
143
|
-
def
|
144
|
-
|
145
|
-
|
146
|
-
params = annotation.params
|
147
|
-
|
148
|
-
identifier = params[:identifier]
|
149
|
-
# Set the pin properties
|
150
|
-
if params[:image]
|
151
|
-
view = RMMarker.alloc.initWithUIImage(params[:image])
|
152
|
-
else
|
153
|
-
pinColor = (PIN_COLORS[params[:pin_color]] || params[:pin_color])
|
154
|
-
view = RMMarker.alloc.initWithMapboxMarkerImage(params[:maki_icon], tintColor: pinColor)
|
155
|
-
end
|
156
|
-
view.annotation = annotation
|
157
|
-
view.canShowCallout = params[:show_callout] if view.respond_to?("canShowCallout=")
|
158
|
-
|
159
|
-
if params[:left_accessory]
|
160
|
-
view.leftCalloutAccessoryView = params[:left_accessory]
|
161
|
-
end
|
162
|
-
if params[:right_accessory]
|
163
|
-
view.rightCalloutAccessoryView = params[:right_accessory]
|
164
|
-
end
|
165
|
-
|
166
|
-
if params[:action]
|
167
|
-
button_type = params[:action_button_type] || UIButtonTypeDetailDisclosure
|
168
|
-
|
169
|
-
action_button = UIButton.buttonWithType(button_type)
|
170
|
-
action_button.addTarget(self, action: params[:action], forControlEvents:UIControlEventTouchUpInside)
|
171
|
-
|
172
|
-
view.rightCalloutAccessoryView = action_button
|
173
|
-
end
|
174
|
-
view
|
128
|
+
def clear_annotations
|
129
|
+
self.view.removeAnnotations(@promotion_annotation_data)
|
130
|
+
@promotion_annotation_data = []
|
175
131
|
end
|
176
132
|
|
177
133
|
def set_start_position(params={})
|
@@ -180,26 +136,15 @@ module ProMotion
|
|
180
136
|
longitude: -122.029620,
|
181
137
|
radius: 10
|
182
138
|
}.merge(params)
|
139
|
+
|
183
140
|
initialLocation = CLLocationCoordinate2D.new(params[:latitude], params[:longitude])
|
184
141
|
region = create_region(initialLocation,params[:radius])
|
185
142
|
set_region(region, animated:false)
|
186
143
|
end
|
187
144
|
|
188
|
-
def
|
145
|
+
def set_up_start_position
|
189
146
|
if self.class.respond_to?(:get_start_position) && self.class.get_start_position
|
190
|
-
|
191
|
-
self.set_start_position start_params unless start_params[:radius].nil?
|
192
|
-
end
|
193
|
-
end
|
194
|
-
|
195
|
-
def set_up_start_center
|
196
|
-
if self.class.respond_to?(:get_start_position) && self.class.get_start_position
|
197
|
-
start_params = self.class.get_start_position_params
|
198
|
-
start_params[:zoom] ||= 5
|
199
|
-
self.view.setZoom(start_params[:zoom], atCoordinate:
|
200
|
-
CLLocationCoordinate2D.new(start_params[:latitude], start_params[:longitude]),
|
201
|
-
animated: false
|
202
|
-
)
|
147
|
+
self.set_start_position self.class.get_start_position_params
|
203
148
|
end
|
204
149
|
end
|
205
150
|
|
@@ -281,13 +226,13 @@ module ProMotion
|
|
281
226
|
end
|
282
227
|
|
283
228
|
def set_region(region, animated=true)
|
284
|
-
self.view.
|
285
|
-
region[:southWest],
|
286
|
-
northEast: region[:northEast],
|
229
|
+
self.view.setVisibleCoordinateBounds(
|
230
|
+
[region[:southWest], region[:northEast]],
|
287
231
|
animated: animated
|
288
232
|
)
|
289
233
|
end
|
290
|
-
|
234
|
+
|
235
|
+
###### REGION SETTINGS #######
|
291
236
|
def deg_to_rad(angle)
|
292
237
|
angle*Math::PI/180
|
293
238
|
end
|
@@ -308,17 +253,17 @@ module ProMotion
|
|
308
253
|
Math.cos(input_latitude) * Math.sin(distance) *
|
309
254
|
Math.cos(bearing)
|
310
255
|
)
|
311
|
-
|
256
|
+
|
312
257
|
dlon = input_longitude + Math.atan2(
|
313
258
|
Math.sin(bearing) * Math.sin(distance) *
|
314
259
|
Math.cos(input_longitude), Math.cos(distance) -
|
315
260
|
Math.sin(input_longitude) * Math.sin(output_latitude)
|
316
261
|
)
|
317
|
-
|
262
|
+
|
318
263
|
output_longitude = (dlon + 3*Math::PI) % (2*Math::PI) - Math::PI
|
319
264
|
CLLocationCoordinate2DMake(rad_to_deg(output_latitude), rad_to_deg(output_longitude))
|
320
265
|
end
|
321
|
-
|
266
|
+
|
322
267
|
def create_region(initialLocation,radius=10)
|
323
268
|
return nil unless initialLocation.is_a? CLLocationCoordinate2D
|
324
269
|
radius = radius * 1.820 # Meters equivalent to 1 Nautical Mile
|
@@ -327,7 +272,17 @@ module ProMotion
|
|
327
272
|
{:southWest => southWest, :northEast => northEast}
|
328
273
|
end
|
329
274
|
alias_method :region, :create_region
|
330
|
-
|
275
|
+
|
276
|
+
##### END REGION SETTINGS ######
|
277
|
+
##### MAP STYLE SETTINGS ######
|
278
|
+
def set_map_style
|
279
|
+
if self.class.respond_to?(:get_map_style)
|
280
|
+
self.view.styleURL = self.class.get_map_style
|
281
|
+
end
|
282
|
+
end
|
283
|
+
##### END MAP STYLE SETTINGS ######
|
284
|
+
|
285
|
+
|
331
286
|
def look_up_address(args={}, &callback)
|
332
287
|
args[:address] = args if args.is_a? String # Assume if a string is passed that they want an address
|
333
288
|
|
@@ -349,16 +304,52 @@ module ProMotion
|
|
349
304
|
end
|
350
305
|
end
|
351
306
|
|
352
|
-
|
353
|
-
|
307
|
+
########## Mapbox GL methods #################
|
308
|
+
def mapView(mapView, annotationCanShowCallout: annotation)
|
309
|
+
return nil if annotation.is_a? MGLUserLocation
|
310
|
+
annotation.params[:show_callout]
|
354
311
|
end
|
355
312
|
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
313
|
+
def mapView(mapView, imageForAnnotation: annotation)
|
314
|
+
return nil unless annotation.params[:image]
|
315
|
+
annotationImage = mapView.dequeueReusableAnnotationImageWithIdentifier(annotation.params[:image])
|
316
|
+
if !annotationImage
|
317
|
+
image = UIImage.imageNamed(annotation.params[:image])
|
318
|
+
annotationImage = MGLAnnotationImage.annotationImageWithImage(image, reuseIdentifier: annotation.params[:image])
|
319
|
+
return annotationImage
|
320
|
+
end
|
321
|
+
end
|
322
|
+
|
323
|
+
def mapView(mapview, leftCalloutAccessoryViewForAnnotation: annotation)
|
324
|
+
if annotation.params[:left_action]
|
325
|
+
button_type = annotation.params[:left_action_button_type] || UIButtonTypeDetailDisclosure
|
326
|
+
action_button = UIButton.buttonWithType(button_type)
|
327
|
+
|
328
|
+
action_button
|
329
|
+
else
|
330
|
+
annotation.left_accessory
|
331
|
+
end
|
332
|
+
end
|
333
|
+
|
334
|
+
def mapView(mapview, rightCalloutAccessoryViewForAnnotation: annotation)
|
335
|
+
if annotation.params[:right_action]
|
336
|
+
button_type = annotation.params[:right_action_button_type] || UIButtonTypeDetailDisclosure
|
337
|
+
action_button = UIButton.buttonWithType(button_type)
|
338
|
+
action_button.tag = 1
|
339
|
+
|
340
|
+
action_button
|
341
|
+
else
|
342
|
+
annotation.right_accessory
|
343
|
+
end
|
344
|
+
end
|
345
|
+
|
346
|
+
def mapView(mapView, annotation: annotation, calloutAccessoryControlTapped: accessory)
|
347
|
+
return nil unless annotation.params[:left_action] || annotation.params[:right_action]
|
348
|
+
if accessory.tag == 1
|
349
|
+
self.send(annotation.params[:right_action])
|
350
|
+
else
|
351
|
+
self.send(annotation.params[:left_action])
|
360
352
|
end
|
361
|
-
annotation_view(map_view, annotation)
|
362
353
|
end
|
363
354
|
|
364
355
|
########## Cocoa touch methods #################
|
@@ -386,22 +377,19 @@ module ProMotion
|
|
386
377
|
end
|
387
378
|
end
|
388
379
|
|
389
|
-
def tapOnCalloutAccessoryControl(control, forAnnotation: annotation, onMap: map)
|
390
|
-
control.sendActionsForControlEvents(UIControlEventTouchUpInside)
|
391
|
-
end
|
392
380
|
########## Cocoa touch Ruby counterparts #################
|
393
381
|
|
394
|
-
def
|
395
|
-
map.
|
382
|
+
def type
|
383
|
+
map.mapType
|
396
384
|
end
|
397
385
|
|
398
|
-
def
|
399
|
-
map.
|
386
|
+
def type=(type)
|
387
|
+
map.mapType = type
|
400
388
|
end
|
401
389
|
|
402
|
-
%w(
|
390
|
+
%w(zoom scroll pitch rotate).each do |meth|
|
403
391
|
define_method("#{meth}_enabled?") do
|
404
|
-
map.send("#{meth}Enabled")
|
392
|
+
map.send("is#{meth.capitalize}Enabled")
|
405
393
|
end
|
406
394
|
|
407
395
|
define_method("#{meth}_enabled=") do |argument|
|
@@ -437,21 +425,15 @@ module ProMotion
|
|
437
425
|
def get_tap_to_add
|
438
426
|
@tap_to_add ||= false
|
439
427
|
end
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
@mapbox_setup_params = params
|
444
|
-
@mapbox_setup = true
|
445
|
-
end
|
446
|
-
|
447
|
-
def get_mapbox_setup_params
|
448
|
-
@mapbox_setup_params ||= nil
|
428
|
+
|
429
|
+
def map_style(style)
|
430
|
+
@map_style_url = NSURL.URLWithString("asset://styles/#{style}.json")
|
449
431
|
end
|
450
|
-
|
451
|
-
def
|
452
|
-
@
|
432
|
+
|
433
|
+
def get_map_style
|
434
|
+
@map_style_url ||= map_style(:light)
|
453
435
|
end
|
454
|
-
|
436
|
+
|
455
437
|
|
456
438
|
end
|
457
439
|
def self.included(base)
|
metadata
CHANGED
@@ -1,83 +1,97 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ProMotion-mapbox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Diogo Andre
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ProMotion
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '2.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '2.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: motion-cocoapods
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: motion-stump
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - ~>
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0.3'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - ~>
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0.3'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: motion-redgreen
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - ~>
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0.1'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - ~>
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0.1'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: motion_print
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: rake
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
72
86
|
requirements:
|
73
|
-
- -
|
87
|
+
- - ">="
|
74
88
|
- !ruby/object:Gem::Version
|
75
89
|
version: '0'
|
76
90
|
type: :development
|
77
91
|
prerelease: false
|
78
92
|
version_requirements: !ruby/object:Gem::Requirement
|
79
93
|
requirements:
|
80
|
-
- -
|
94
|
+
- - ">="
|
81
95
|
- !ruby/object:Gem::Version
|
82
96
|
version: '0'
|
83
97
|
description: Adds PM::MapScreen support to ProMotion, using Mapbox as map provider.
|
@@ -88,10 +102,10 @@ extensions: []
|
|
88
102
|
extra_rdoc_files: []
|
89
103
|
files:
|
90
104
|
- README.md
|
105
|
+
- lib/ProMotion-mapbox.rb
|
91
106
|
- lib/ProMotion/map/map_screen.rb
|
92
107
|
- lib/ProMotion/map/map_screen_annotation.rb
|
93
108
|
- lib/ProMotion/map/map_screen_module.rb
|
94
|
-
- lib/ProMotion-mapbox.rb
|
95
109
|
homepage: https://github.com/diogoandre/ProMotion-mapbox
|
96
110
|
licenses:
|
97
111
|
- MIT
|
@@ -102,17 +116,17 @@ require_paths:
|
|
102
116
|
- lib
|
103
117
|
required_ruby_version: !ruby/object:Gem::Requirement
|
104
118
|
requirements:
|
105
|
-
- -
|
119
|
+
- - ">="
|
106
120
|
- !ruby/object:Gem::Version
|
107
121
|
version: '0'
|
108
122
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
123
|
requirements:
|
110
|
-
- -
|
124
|
+
- - ">="
|
111
125
|
- !ruby/object:Gem::Version
|
112
126
|
version: '0'
|
113
127
|
requirements: []
|
114
128
|
rubyforge_project:
|
115
|
-
rubygems_version: 2.
|
129
|
+
rubygems_version: 2.4.8
|
116
130
|
signing_key:
|
117
131
|
specification_version: 4
|
118
132
|
summary: Adds PM::MapScreen support to ProMotion, using Mapbox as map provider. Forked
|