ProMotion-amap 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +269 -0
- data/lib/ProMotion-map.rb +18 -0
- data/lib/ProMotion/map/map_screen.rb +6 -0
- data/lib/ProMotion/map/map_screen_annotation.rb +67 -0
- data/lib/ProMotion/map/map_screen_module.rb +308 -0
- metadata +122 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3d553efc4a20071ec4a296503fc1aea40cadcc3c
|
4
|
+
data.tar.gz: 4264934552eed6acc9d861bf12b57083c9355621
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 742d5731c72d41e998a6993d1d4ce83964dc87aac7d571aaecb404cdcd9a5afd7ffe5a02c6458ac0c5cd9810b4129c715c9b01e24f3e0e1b3466f002fdccb07b
|
7
|
+
data.tar.gz: 6e528ce3640347edbe261cbbf119d175c9d7e7efa6a09ffca6b6931929ba903eba4a8e814d85e4842954ddf221602372bdd906e52f3cf0290936b947160c8f5a
|
data/README.md
ADDED
@@ -0,0 +1,269 @@
|
|
1
|
+
# ProMotion-amap
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/ProMotion-map.svg)](http://badge.fury.io/rb/ProMotion-map) [![Build Status](https://travis-ci.org/clearsightstudio/ProMotion-map.svg)](https://travis-ci.org/clearsightstudio/ProMotion-map) [![Code Climate](https://codeclimate.com/github/clearsightstudio/ProMotion-map.png)](https://codeclimate.com/github/clearsightstudio/ProMotion-map)
|
4
|
+
|
5
|
+
ProMotion-map provides a PM::MapScreen, extracted from the
|
6
|
+
popular RubyMotion gem [ProMotion](https://github.com/clearsightstudio/ProMotion).
|
7
|
+
AMap link: http://lbs.amap.com/api/ios-sdk/summary/
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'ProMotion-map'
|
13
|
+
```
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
Easily create a map screen, complete with annotations.
|
18
|
+
|
19
|
+
*Has all the methods of PM::Screen*
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
class MyMapScreen < PM::MapScreen
|
23
|
+
title "My Map"
|
24
|
+
start_position latitude: 35.090648651123, longitude: -82.965972900391, radius: 4
|
25
|
+
|
26
|
+
def annotation_data
|
27
|
+
[{
|
28
|
+
longitude: -82.965972900391,
|
29
|
+
latitude: 35.090648651123,
|
30
|
+
title: "Rainbow Falls",
|
31
|
+
subtitle: "Nantahala National Forest",
|
32
|
+
action: :show_forest
|
33
|
+
},{
|
34
|
+
longitude: -82.966093558105,
|
35
|
+
latitude: 35.092520895652,
|
36
|
+
title: "Turtleback Falls",
|
37
|
+
subtitle: "Nantahala National Forest",
|
38
|
+
action: :show_forest
|
39
|
+
},{
|
40
|
+
longitude: -82.95916,
|
41
|
+
latitude: 35.07496,
|
42
|
+
title: "Windy Falls",
|
43
|
+
action: :show_forest
|
44
|
+
},{
|
45
|
+
longitude: -82.943031505056,
|
46
|
+
latitude: 35.102516828489,
|
47
|
+
title: "Upper Bearwallow Falls",
|
48
|
+
subtitle: "Gorges State Park",
|
49
|
+
action: :show_forest
|
50
|
+
},{
|
51
|
+
longitude: -82.956244328014,
|
52
|
+
latitude: 35.085548421623,
|
53
|
+
title: "Stairway Falls",
|
54
|
+
subtitle: "Gorges State Park",
|
55
|
+
your_param: "CustomWhatever",
|
56
|
+
action: :show_forest
|
57
|
+
}, {
|
58
|
+
longitude: -82.965972900391,
|
59
|
+
latitude: 35.090648651123,
|
60
|
+
title: "Rainbow Falls",
|
61
|
+
subtitle: "Nantahala National Forest",
|
62
|
+
image: UIImage.imageNamed("custom-pin"),
|
63
|
+
action: :show_forest
|
64
|
+
}]
|
65
|
+
end
|
66
|
+
|
67
|
+
def show_forest
|
68
|
+
selected = selected_annotations.first
|
69
|
+
# Do something with the selected annotation.
|
70
|
+
end
|
71
|
+
end
|
72
|
+
```
|
73
|
+
|
74
|
+
Here's a neat way to zoom into a specific marker in an animated fashion and then select the marker:
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
def zoom_to_marker(marker)
|
78
|
+
set_region region(coordinate: marker.coordinate, span: [0.05, 0.05])
|
79
|
+
select_annotation marker
|
80
|
+
end
|
81
|
+
```
|
82
|
+
|
83
|
+
---
|
84
|
+
|
85
|
+
### Methods
|
86
|
+
|
87
|
+
#### annotation_data
|
88
|
+
|
89
|
+
Method that is called to get the map's annotation data and build the map. If you do not want any annotations, simply return an empty array.
|
90
|
+
|
91
|
+
All possible properties:
|
92
|
+
|
93
|
+
```ruby
|
94
|
+
{
|
95
|
+
longitude: -82.956244328014, # REQUIRED
|
96
|
+
latitude: 35.085548421623, # REQUIRED
|
97
|
+
title: "Stairway Falls", # REQUIRED
|
98
|
+
subtitle: "Gorges State Park",
|
99
|
+
image: "my_custom_image",
|
100
|
+
left_accessory: my_button,
|
101
|
+
right_accessory: my_other_button,
|
102
|
+
action: :my_action, # Overrides :right_accessory
|
103
|
+
action_button_type: UIButtonTypeContactAdd # Defaults to UIButtonTypeDetailDisclosure
|
104
|
+
}
|
105
|
+
```
|
106
|
+
|
107
|
+
You may pass whatever properties you want in the annotation hash, but `:longitude`, `:latitude`, and `:title` are required.
|
108
|
+
|
109
|
+
Use `:image` to specify a custom image. Pass in a string to conserve memory and it will be converted using `UIImage.imageNamed(your_string)`. If you pass in a `UIImage`, we'll use that, but keep in mind that there will be another unnecessary copy of the UIImage in memory.
|
110
|
+
|
111
|
+
Use `:left_accessory` and `:right_accessory` to specify a custom accessory, like a button.
|
112
|
+
|
113
|
+
You can access annotation data you've arbitrarily stored in the hash by calling `annotation_instance.params[:your_param]`.
|
114
|
+
|
115
|
+
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`.
|
116
|
+
|
117
|
+
#### update_annotation_data
|
118
|
+
|
119
|
+
Forces a reload of all the annotations
|
120
|
+
|
121
|
+
#### annotations
|
122
|
+
|
123
|
+
Returns an array of all the annotations.
|
124
|
+
|
125
|
+
#### center
|
126
|
+
|
127
|
+
Returns a `CLLocation2D` instance with the center coordinates of the map.
|
128
|
+
|
129
|
+
#### center=({latitude: Float, longitude: Float, animated: Boolean})
|
130
|
+
|
131
|
+
Sets the center of the map. `animated` property defaults to `true`.
|
132
|
+
|
133
|
+
#### show_user_location
|
134
|
+
|
135
|
+
Shows the user's location on the map.
|
136
|
+
|
137
|
+
##### iOS 8 Location Requirements
|
138
|
+
|
139
|
+
iOS 8 introduced stricter location services requirements. You are now required to add a few key/value pairs to the `Info.plist`. Add these two lines to your `Rakefile` (with your descriptions, obviously):
|
140
|
+
|
141
|
+
```ruby
|
142
|
+
app.info_plist['NSLocationAlwaysUsageDescription'] = 'Description'
|
143
|
+
app.info_plist['NSLocationWhenInUseUsageDescription'] = 'Description'
|
144
|
+
```
|
145
|
+
|
146
|
+
*Note: you need both keys to use `get_once`, so it's probably best to just include both no matter what.* See [Apple's documentation](https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html#//apple_ref/doc/uid/TP40009251-SW18) on iOS 8 location services requirements for more information.
|
147
|
+
|
148
|
+
#### hide_user_location
|
149
|
+
|
150
|
+
Hides the user's location on the map.
|
151
|
+
|
152
|
+
#### showing_user_location?
|
153
|
+
|
154
|
+
Returns a `Boolean` of whether or not the map view is currently showing the user's location.
|
155
|
+
|
156
|
+
#### user_location
|
157
|
+
|
158
|
+
Returns a `CLLocation2D` object of the user's location or `nil` if the user location is not being tracked
|
159
|
+
|
160
|
+
#### zoom_to_user(radius = 0.05, animated=true)
|
161
|
+
|
162
|
+
Zooms to the user's location. If the user's location is not currently being shown on the map, it will show it first. `radius` is a `CLLocationDegrees` of the latitude and longitude deltas. _See Apple documentation for `MKCoordinateSpan` for more information._
|
163
|
+
|
164
|
+
#### select_annotation(annotation, animated=true)
|
165
|
+
|
166
|
+
Selects a single annotation.
|
167
|
+
|
168
|
+
#### select_annotation_at(annotation_index, animated=true)
|
169
|
+
|
170
|
+
Selects a single annotation using the annotation at the index of your `annotation_data` array.
|
171
|
+
|
172
|
+
#### selected_annotations
|
173
|
+
|
174
|
+
Returns an array of annotations that are selected. If no annotations are selected, returns `nil`.
|
175
|
+
|
176
|
+
#### deselect_annotations(animated=false)
|
177
|
+
|
178
|
+
Deselects all selected annotations.
|
179
|
+
|
180
|
+
#### add_annotation(annotation)
|
181
|
+
|
182
|
+
Adds a new annotation to the map. Refer to `annotation_data` (above) for hash properties.
|
183
|
+
|
184
|
+
#### add_annotations(annotations)
|
185
|
+
|
186
|
+
Adds more than one annotation at a time to the map.
|
187
|
+
|
188
|
+
#### clear_annotations
|
189
|
+
|
190
|
+
Removes all annotations from the `MapScreen`.
|
191
|
+
|
192
|
+
#### zoom_to_fit_annotations({animated:true, include_user:false})
|
193
|
+
|
194
|
+
Changes the zoom and center point of the `MapScreen` to fit all the annotations. Passing `include_user` as `true` will cause the zoom to not only include the annotations from `annotation_data` but also the user pin in the zoom region calculation.
|
195
|
+
|
196
|
+
#### set_region(region, animated=true)
|
197
|
+
|
198
|
+
Sets the region of the `MapScreen`. `region` should be an instance of `MKCoordinateRegion`.
|
199
|
+
|
200
|
+
#### region(params)
|
201
|
+
|
202
|
+
Helper method to create an `MKCoordinateRegion`. Expects a hash in the form of:
|
203
|
+
|
204
|
+
```ruby
|
205
|
+
my_region = region({
|
206
|
+
coordinate:{
|
207
|
+
latitude: 35.0906,
|
208
|
+
longitude: -82.965
|
209
|
+
},
|
210
|
+
# span is the latitude and longitude delta
|
211
|
+
span: [0.5, 0.5]
|
212
|
+
})
|
213
|
+
```
|
214
|
+
|
215
|
+
---
|
216
|
+
|
217
|
+
### Class Methods
|
218
|
+
|
219
|
+
#### start_position(latitude: Float, longitude: Float, radius: Float)
|
220
|
+
|
221
|
+
Class method to set the initial starting position of the `MapScreen`.
|
222
|
+
|
223
|
+
```ruby
|
224
|
+
class MyMapScreen < PM::MapScreen
|
225
|
+
start_position latitude: 36.10, longitude: -80.26, radius: 4
|
226
|
+
end
|
227
|
+
```
|
228
|
+
|
229
|
+
`radius` is the zoom level of the map in miles (default: 10).
|
230
|
+
|
231
|
+
---
|
232
|
+
|
233
|
+
### CocoaTouch Property Convenience Methods
|
234
|
+
|
235
|
+
`MKMapView` contains multiple property setters and getters that can be accessed in a more ruby-like syntax:
|
236
|
+
|
237
|
+
```ruby
|
238
|
+
type # Returns a MKMapType
|
239
|
+
type = (MKMapType)new_type
|
240
|
+
|
241
|
+
zoom_enabled?
|
242
|
+
zoom_enabled = (bool)enabled
|
243
|
+
|
244
|
+
scroll_enabled?
|
245
|
+
scroll_enabled = (bool)enabled
|
246
|
+
|
247
|
+
pitch_enabled?
|
248
|
+
pitch_enabled = (bool)enabled
|
249
|
+
|
250
|
+
rotate_enabled?
|
251
|
+
rotate_enabled = (bool)enabled
|
252
|
+
```
|
253
|
+
|
254
|
+
---
|
255
|
+
|
256
|
+
### Accessors
|
257
|
+
|
258
|
+
#### `map` or `mapview`
|
259
|
+
|
260
|
+
Reference to the created UIMapView.
|
261
|
+
|
262
|
+
## Contributing
|
263
|
+
|
264
|
+
1. Fork it
|
265
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
266
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
267
|
+
4. Make some specs pass
|
268
|
+
5. Push to the branch (`git push origin my-new-feature`)
|
269
|
+
6. Create new Pull Request
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'motion-cocoapods'
|
3
|
+
unless defined?(Motion::Project::Config)
|
4
|
+
raise "ProMotion-map must be required within a RubyMotion project."
|
5
|
+
end
|
6
|
+
|
7
|
+
Motion::Project::App.setup do |app|
|
8
|
+
lib_dir_path = File.dirname(File.expand_path(__FILE__))
|
9
|
+
app.files << File.join(lib_dir_path, "ProMotion/map/map_screen_annotation.rb")
|
10
|
+
app.files << File.join(lib_dir_path, "ProMotion/map/map_screen_module.rb")
|
11
|
+
app.files << File.join(lib_dir_path, "ProMotion/map/map_screen.rb")
|
12
|
+
|
13
|
+
app.frameworks += %w(CoreLocation MapKit)
|
14
|
+
|
15
|
+
app.pods do
|
16
|
+
pod 'AMap2DMap', '~> 2.4.2'
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module ProMotion
|
2
|
+
class MapScreenAnnotation
|
3
|
+
attr_reader :params
|
4
|
+
|
5
|
+
# Creates the new annotation object
|
6
|
+
def initialize(params = {})
|
7
|
+
@params = params
|
8
|
+
set_defaults
|
9
|
+
|
10
|
+
unless @params[:latitude] && @params[:longitude]
|
11
|
+
PM.logger.error("You are required to specify :latitude and :longitude for annotations.")
|
12
|
+
return nil
|
13
|
+
end
|
14
|
+
@coordinate = CLLocationCoordinate2D.new(@params[:latitude], @params[:longitude])
|
15
|
+
end
|
16
|
+
|
17
|
+
def set_defaults
|
18
|
+
@params = {
|
19
|
+
title: "Title",
|
20
|
+
pin_color: MAPinAnnotationColorRed,
|
21
|
+
identifier: "Annotation-#{@params[:pin_color]}-#{@params[:image]}",
|
22
|
+
show_callout: true,
|
23
|
+
animates_drop: false
|
24
|
+
}.merge(@params)
|
25
|
+
end
|
26
|
+
|
27
|
+
def title
|
28
|
+
@params[:title]
|
29
|
+
end
|
30
|
+
|
31
|
+
def subtitle
|
32
|
+
@params[:subtitle] ||= nil
|
33
|
+
end
|
34
|
+
|
35
|
+
def coordinate
|
36
|
+
@coordinate
|
37
|
+
end
|
38
|
+
|
39
|
+
def cllocation
|
40
|
+
CLLocation.alloc.initWithLatitude(@params[:latitude], longitude:@params[:longitude])
|
41
|
+
end
|
42
|
+
|
43
|
+
def setCoordinate(new_coordinate);
|
44
|
+
if new_coordinate.is_a? Hash
|
45
|
+
@coordinate = CLLocationCoordinate2D.new(new_coordinate[:latitude], new_coordinate[:longitude])
|
46
|
+
else
|
47
|
+
@coordinate = new_coordinate
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def method_missing(meth, *args)
|
52
|
+
if @params[meth.to_sym]
|
53
|
+
@params[meth.to_sym]
|
54
|
+
else
|
55
|
+
PM.logger.warn "The annotation parameter \"#{meth}\" does not exist on this pin."
|
56
|
+
nil
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# Deprecated
|
61
|
+
def annotation_params
|
62
|
+
PM.logger.warn("annotation.annotation_params is deprecated and will be removed soon. Please use annotation.params instead.")
|
63
|
+
@params
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,308 @@
|
|
1
|
+
module ProMotion
|
2
|
+
module MapScreenModule
|
3
|
+
|
4
|
+
def screen_setup
|
5
|
+
self.view = nil
|
6
|
+
NSLog NSBundle.mainBundle.bundleIdentifier
|
7
|
+
MAMapServices.sharedServices.apiKey = "d479b065447f24f12381a58a1aa41f00"
|
8
|
+
self.view = MAMapView.alloc.initWithFrame(self.view.bounds)
|
9
|
+
self.view.delegate = self
|
10
|
+
|
11
|
+
check_annotation_data
|
12
|
+
@promotion_annotation_data = []
|
13
|
+
set_up_start_position
|
14
|
+
end
|
15
|
+
|
16
|
+
def view_will_appear(animated)
|
17
|
+
super
|
18
|
+
update_annotation_data
|
19
|
+
end
|
20
|
+
|
21
|
+
def check_annotation_data
|
22
|
+
PM.logger.error "Missing #annotation_data method in MapScreen #{self.class.to_s}." unless self.respond_to?(:annotation_data)
|
23
|
+
end
|
24
|
+
|
25
|
+
def update_annotation_data
|
26
|
+
clear_annotations
|
27
|
+
add_annotations annotation_data
|
28
|
+
end
|
29
|
+
|
30
|
+
def map
|
31
|
+
self.view
|
32
|
+
end
|
33
|
+
alias_method :mapview, :map
|
34
|
+
|
35
|
+
def center
|
36
|
+
self.view.centerCoordinate
|
37
|
+
end
|
38
|
+
|
39
|
+
def center=(params={})
|
40
|
+
PM.logger.error "Missing #:latitude property in call to #center=." unless params[:latitude]
|
41
|
+
PM.logger.error "Missing #:longitude property in call to #center=." unless params[:longitude]
|
42
|
+
params[:animated] ||= true
|
43
|
+
|
44
|
+
# Set the new region
|
45
|
+
self.view.setCenterCoordinate(
|
46
|
+
CLLocationCoordinate2D.new(params[:latitude], params[:longitude]),
|
47
|
+
animated:params[:animated]
|
48
|
+
)
|
49
|
+
end
|
50
|
+
|
51
|
+
def show_user_location
|
52
|
+
if location_manager.respondsToSelector('requestWhenInUseAuthorization')
|
53
|
+
location_manager.requestWhenInUseAuthorization
|
54
|
+
end
|
55
|
+
|
56
|
+
set_show_user_location true
|
57
|
+
end
|
58
|
+
|
59
|
+
def hide_user_location
|
60
|
+
set_show_user_location false
|
61
|
+
end
|
62
|
+
|
63
|
+
def set_show_user_location(show)
|
64
|
+
self.view.showsUserLocation = show
|
65
|
+
end
|
66
|
+
|
67
|
+
def showing_user_location?
|
68
|
+
self.view.showsUserLocation
|
69
|
+
end
|
70
|
+
|
71
|
+
def user_location
|
72
|
+
user_annotation.nil? ? nil : user_annotation.coordinate
|
73
|
+
end
|
74
|
+
|
75
|
+
def user_annotation
|
76
|
+
self.view.userLocation.location.nil? ? nil : self.view.userLocation.location
|
77
|
+
end
|
78
|
+
|
79
|
+
def zoom_to_user(radius = 0.05, animated=true)
|
80
|
+
show_user_location unless showing_user_location?
|
81
|
+
set_region(MACoordinateRegionMakeWithDistance(user_location, radius, radius), animated)
|
82
|
+
end
|
83
|
+
|
84
|
+
def annotations
|
85
|
+
@promotion_annotation_data
|
86
|
+
end
|
87
|
+
|
88
|
+
def select_annotation(annotation, animated=true)
|
89
|
+
self.view.selectAnnotation(annotation, animated:animated)
|
90
|
+
end
|
91
|
+
|
92
|
+
def select_annotation_at(annotation_index, animated=true)
|
93
|
+
select_annotation(annotations[annotation_index], animated:animated)
|
94
|
+
end
|
95
|
+
|
96
|
+
def selected_annotations
|
97
|
+
self.view.selectedAnnotations
|
98
|
+
end
|
99
|
+
|
100
|
+
def deselect_annotations(animated=false)
|
101
|
+
unless selected_annotations.nil?
|
102
|
+
selected_annotations.each do |annotation|
|
103
|
+
self.view.deselectAnnotation(annotation, animated:animated)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def add_annotation(annotation)
|
109
|
+
@promotion_annotation_data << MapScreenAnnotation.new(annotation)
|
110
|
+
self.view.addAnnotation @promotion_annotation_data.last
|
111
|
+
end
|
112
|
+
|
113
|
+
def add_annotations(annotations)
|
114
|
+
@promotion_annotation_data = Array(annotations).map{|a| MapScreenAnnotation.new(a)}
|
115
|
+
self.view.addAnnotations @promotion_annotation_data
|
116
|
+
end
|
117
|
+
|
118
|
+
def clear_annotations
|
119
|
+
@promotion_annotation_data.each do |a|
|
120
|
+
self.view.removeAnnotation(a)
|
121
|
+
end
|
122
|
+
@promotion_annotation_data = []
|
123
|
+
end
|
124
|
+
|
125
|
+
def annotation_view(map_view, annotation)
|
126
|
+
return if annotation.is_a? MAUserLocation
|
127
|
+
|
128
|
+
params = annotation.params
|
129
|
+
|
130
|
+
identifier = params[:identifier]
|
131
|
+
if view = map_view.dequeueReusableAnnotationViewWithIdentifier(identifier)
|
132
|
+
view.annotation = annotation
|
133
|
+
else
|
134
|
+
# Set the pin properties
|
135
|
+
if params[:image]
|
136
|
+
view = MAAnnotationView.alloc.initWithAnnotation(annotation, reuseIdentifier:identifier)
|
137
|
+
else
|
138
|
+
view = MAPinAnnotationView.alloc.initWithAnnotation(annotation, reuseIdentifier:identifier)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
view.image = params[:image] if view.respond_to?("image=") && params[:image]
|
142
|
+
view.animatesDrop = params[:animates_drop] if view.respond_to?("animatesDrop=")
|
143
|
+
view.pinColor = params[:pin_color] if view.respond_to?("pinColor=")
|
144
|
+
view.canShowCallout = params[:show_callout] if view.respond_to?("canShowCallout=")
|
145
|
+
|
146
|
+
if params[:left_accessory]
|
147
|
+
view.leftCalloutAccessoryView = params[:left_accessory]
|
148
|
+
end
|
149
|
+
if params[:right_accessory]
|
150
|
+
view.rightCalloutAccessoryView = params[:right_accessory]
|
151
|
+
end
|
152
|
+
|
153
|
+
if params[:action]
|
154
|
+
button_type = params[:action_button_type] || UIButtonTypeDetailDisclosure
|
155
|
+
|
156
|
+
action_button = UIButton.buttonWithType(button_type)
|
157
|
+
action_button.addTarget(self, action: params[:action], forControlEvents:UIControlEventTouchUpInside)
|
158
|
+
|
159
|
+
view.rightCalloutAccessoryView = action_button
|
160
|
+
end
|
161
|
+
view
|
162
|
+
end
|
163
|
+
|
164
|
+
def set_start_position(params={})
|
165
|
+
params[:latitude] ||= 37.331789
|
166
|
+
params[:longitude] ||= -122.029620
|
167
|
+
params[:radius] ||= 10
|
168
|
+
|
169
|
+
meters_per_mile = 1609.344
|
170
|
+
|
171
|
+
initialLocation = CLLocationCoordinate2D.new(params[:latitude], params[:longitude])
|
172
|
+
region = MACoordinateRegionMakeWithDistance(initialLocation, params[:radius] * meters_per_mile, params[:radius] * meters_per_mile)
|
173
|
+
set_region(region, animated:false)
|
174
|
+
end
|
175
|
+
|
176
|
+
def set_up_start_position
|
177
|
+
if self.class.respond_to?(:get_start_position) && self.class.get_start_position
|
178
|
+
self.set_start_position self.class.get_start_position_params
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
# TODO: Why is this so complex?
|
183
|
+
def zoom_to_fit_annotations(args={})
|
184
|
+
# Preserve backwards compatibility
|
185
|
+
args = {animated: args} if args == true || args == false
|
186
|
+
args = {animated: true, include_user: false}.merge(args)
|
187
|
+
|
188
|
+
ann = args[:include_user] ? (annotations + [user_annotation]).compact : annotations
|
189
|
+
|
190
|
+
#Don't attempt the rezoom of there are no pins
|
191
|
+
return if ann.count == 0
|
192
|
+
|
193
|
+
#Set some crazy boundaries
|
194
|
+
topLeft = CLLocationCoordinate2D.new(-90, 180)
|
195
|
+
bottomRight = CLLocationCoordinate2D.new(90, -180)
|
196
|
+
|
197
|
+
#Find the bounds of the pins
|
198
|
+
ann.each do |a|
|
199
|
+
topLeft.longitude = [topLeft.longitude, a.coordinate.longitude].min
|
200
|
+
topLeft.latitude = [topLeft.latitude, a.coordinate.latitude].max
|
201
|
+
bottomRight.longitude = [bottomRight.longitude, a.coordinate.longitude].max
|
202
|
+
bottomRight.latitude = [bottomRight.latitude, a.coordinate.latitude].min
|
203
|
+
end
|
204
|
+
|
205
|
+
#Find the bounds of all the pins and set the map_view
|
206
|
+
coord = CLLocationCoordinate2D.new(
|
207
|
+
topLeft.latitude - (topLeft.latitude - bottomRight.latitude) * 0.5,
|
208
|
+
topLeft.longitude + (bottomRight.longitude - topLeft.longitude) * 0.5
|
209
|
+
)
|
210
|
+
|
211
|
+
# Add some padding to the edges
|
212
|
+
#span = MACoordinateSpanMake(
|
213
|
+
# long = ((topLeft.latitude - bottomRight.latitude) * 1.075).abs,
|
214
|
+
# lat = ((bottomRight.longitude - topLeft.longitude) * 1.075).abs
|
215
|
+
#)
|
216
|
+
|
217
|
+
region = MACoordinateRegionMakeWithDistance(coord, long, lat)
|
218
|
+
fits = self.view.regionThatFits(region)
|
219
|
+
|
220
|
+
set_region(fits, animated: args[:animated])
|
221
|
+
end
|
222
|
+
|
223
|
+
def set_region(region, animated=true)
|
224
|
+
self.view.setRegion(region, animated:animated)
|
225
|
+
end
|
226
|
+
|
227
|
+
def region(params)
|
228
|
+
return nil unless params.is_a? Hash
|
229
|
+
|
230
|
+
params[:coordinate] = CLLocationCoordinate2D.new(params[:coordinate][:latitude], params[:coordinate][:longitude]) if params[:coordinate].is_a? Hash
|
231
|
+
#params[:span] = MACoordinateSpanMake(params[:span][0], params[:span][1]) if params[:span].is_a? Array
|
232
|
+
|
233
|
+
if params[:coordinate] && params[:span]
|
234
|
+
MACoordinateRegionMakeWithDistance( params[:coordinate], params[:span][0], params[:span][1] )
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
def look_up_address(args={}, &callback)
|
239
|
+
args[:address] = args if args.is_a? String # Assume if a string is passed that they want an address
|
240
|
+
|
241
|
+
geocoder = CLGeocoder.new
|
242
|
+
return geocoder.geocodeAddressDictionary(args[:address], completionHandler: callback) if args[:address].is_a?(Hash)
|
243
|
+
return geocoder.geocodeAddressString(args[:address].to_s, completionHandler: callback) unless args[:region]
|
244
|
+
return geocoder.geocodeAddressString(args[:address].to_s, inRegion:args[:region].to_s, completionHandler: callback) if args[:region]
|
245
|
+
end
|
246
|
+
|
247
|
+
########## Cocoa touch methods #################
|
248
|
+
def mapView(map_view, viewForAnnotation:annotation)
|
249
|
+
annotation_view(map_view, annotation)
|
250
|
+
end
|
251
|
+
|
252
|
+
def mapView(map_view, didUpdateUserLocation:userLocation)
|
253
|
+
if self.respond_to?(:on_user_location)
|
254
|
+
on_user_location(userLocation)
|
255
|
+
else
|
256
|
+
PM.logger.info "You're tracking the user's location but have not implemented the #on_user_location(location) method in MapScreen #{self.class.to_s}."
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
########## Cocoa touch Ruby counterparts #################
|
261
|
+
|
262
|
+
def type
|
263
|
+
map.mapType
|
264
|
+
end
|
265
|
+
|
266
|
+
def type=(type)
|
267
|
+
map.mapType = type
|
268
|
+
end
|
269
|
+
|
270
|
+
%w(zoom scroll pitch rotate).each do |meth|
|
271
|
+
define_method("#{meth}_enabled?") do
|
272
|
+
map.send("is#{meth.capitalize}Enabled")
|
273
|
+
end
|
274
|
+
|
275
|
+
define_method("#{meth}_enabled=") do |argument|
|
276
|
+
map.send("#{meth}Enabled=", argument)
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
module MapClassMethods
|
281
|
+
def start_position(params={})
|
282
|
+
@start_position_params = params
|
283
|
+
@start_position = true
|
284
|
+
end
|
285
|
+
|
286
|
+
def get_start_position_params
|
287
|
+
@start_position_params ||= nil
|
288
|
+
end
|
289
|
+
|
290
|
+
def get_start_position
|
291
|
+
@start_position ||= false
|
292
|
+
end
|
293
|
+
end
|
294
|
+
def self.included(base)
|
295
|
+
base.extend(MapClassMethods)
|
296
|
+
end
|
297
|
+
|
298
|
+
private
|
299
|
+
|
300
|
+
def location_manager
|
301
|
+
@location_manager ||= CLLocationManager.alloc.init
|
302
|
+
@location_manager.delegate ||= self
|
303
|
+
@location_manager
|
304
|
+
end
|
305
|
+
|
306
|
+
|
307
|
+
end
|
308
|
+
end
|
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ProMotion-amap
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mark Rickert
|
8
|
+
- Jamon Holmgren
|
9
|
+
- David Ruan
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2015-02-05 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: ProMotion
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - "~>"
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '2.0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - "~>"
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '2.0'
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: motion-cocoapods
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - "~>"
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '1'
|
36
|
+
type: :runtime
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - "~>"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '1'
|
43
|
+
- !ruby/object:Gem::Dependency
|
44
|
+
name: motion-stump
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0.3'
|
50
|
+
type: :development
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - "~>"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0.3'
|
57
|
+
- !ruby/object:Gem::Dependency
|
58
|
+
name: motion-redgreen
|
59
|
+
requirement: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - "~>"
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0.1'
|
64
|
+
type: :development
|
65
|
+
prerelease: false
|
66
|
+
version_requirements: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - "~>"
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0.1'
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: rake
|
73
|
+
requirement: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
type: :development
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
description: Adds PM::MapScreen support to ProMotion. Using AMap
|
86
|
+
email:
|
87
|
+
- mark@mohawkapps.com
|
88
|
+
- jamon@clearsightstudio.com
|
89
|
+
executables: []
|
90
|
+
extensions: []
|
91
|
+
extra_rdoc_files: []
|
92
|
+
files:
|
93
|
+
- README.md
|
94
|
+
- lib/ProMotion-map.rb
|
95
|
+
- lib/ProMotion/map/map_screen.rb
|
96
|
+
- lib/ProMotion/map/map_screen_annotation.rb
|
97
|
+
- lib/ProMotion/map/map_screen_module.rb
|
98
|
+
homepage: https://github.com/ruanwz/ProMotion-amap
|
99
|
+
licenses:
|
100
|
+
- MIT
|
101
|
+
metadata: {}
|
102
|
+
post_install_message:
|
103
|
+
rdoc_options: []
|
104
|
+
require_paths:
|
105
|
+
- lib
|
106
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
requirements: []
|
117
|
+
rubyforge_project:
|
118
|
+
rubygems_version: 2.4.5
|
119
|
+
signing_key:
|
120
|
+
specification_version: 4
|
121
|
+
summary: Adds PM::MapScreen support to ProMotion. Extracted from ProMotion.
|
122
|
+
test_files: []
|