这是indexloc提供的服务,不要输入任何密码
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ spec/reports
test/tmp
test/version_tmp
tmp
vendor/build
vendor/Pods

/build
.repl_history
Expand All @@ -30,4 +32,4 @@ tmp
*.tmproj
*.tmproject
tmtags
*.sublime-workspace
*.sublime-workspace
56 changes: 55 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,72 @@ PATH
specs:
ProMotion-map (0.7.0)
ProMotion (~> 2.0)
motion-cocoapods

GEM
remote: https://rubygems.org/
specs:
ProMotion (2.4.2)
methadone (~> 1.7)
motion_print (~> 1.0)
activesupport (4.2.1)
i18n (~> 0.7)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
claide (0.9.1)
cocoapods (0.38.2)
activesupport (>= 3.2.15)
claide (~> 0.9.1)
cocoapods-core (= 0.38.2)
cocoapods-downloader (~> 0.9.1)
cocoapods-plugins (~> 0.4.2)
cocoapods-stats (~> 0.5.3)
cocoapods-trunk (~> 0.6.1)
cocoapods-try (~> 0.4.5)
colored (~> 1.2)
escape (~> 0.0.4)
molinillo (~> 0.3.1)
nap (~> 0.8)
xcodeproj (~> 0.26.3)
cocoapods-core (0.38.2)
activesupport (>= 3.2.15)
fuzzy_match (~> 2.0.4)
nap (~> 0.8.0)
cocoapods-downloader (0.9.3)
cocoapods-plugins (0.4.2)
nap
cocoapods-stats (0.5.3)
nap (~> 0.8)
cocoapods-trunk (0.6.4)
nap (>= 0.8, < 2.0)
netrc (= 0.7.8)
cocoapods-try (0.4.5)
colored (1.2)
escape (0.0.4)
fuzzy_match (2.0.4)
i18n (0.7.0)
json (1.8.3)
methadone (1.9.1)
bundler
minitest (5.7.0)
molinillo (0.3.1)
motion-cocoapods (1.7.4)
cocoapods (>= 0.34)
motion-redgreen (0.1.0)
motion-stump (0.3.2)
motion_print (1.2.0)
nap (0.8.0)
netrc (0.7.8)
rake (10.4.2)
thread_safe (0.3.5)
tzinfo (1.2.2)
thread_safe (~> 0.1)
xcodeproj (0.26.3)
activesupport (>= 3)
claide (~> 0.9.1)
colored (~> 1.2)

PLATFORMS
ruby
Expand All @@ -24,7 +77,8 @@ DEPENDENCIES
ProMotion-map!
motion-redgreen (~> 0.1)
motion-stump (~> 0.3)
motion_print
rake

BUNDLED WITH
1.10.4
1.10.6
2 changes: 2 additions & 0 deletions ProMotion-map.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ Gem::Specification.new do |spec|
spec.require_paths = ["lib"]

spec.add_dependency "ProMotion", "~> 2.0"
spec.add_runtime_dependency "motion-cocoapods"
spec.add_development_dependency "motion-stump", "~> 0.3"
spec.add_development_dependency "motion-redgreen", "~> 0.1"
spec.add_development_dependency "motion_print"
spec.add_development_dependency "rake"
end
54 changes: 29 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
# ProMotion-map
# ProMotion-mapbox

[![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)
[![Gem Version](https://badge.fury.io/rb/ProMotion-mapbox.svg)](http://badge.fury.io/rb/ProMotion-mapbox)

ProMotion-map provides a PM::MapScreen, extracted from the
popular RubyMotion gem [ProMotion](https://github.com/clearsightstudio/ProMotion).
ProMotion-mapbox provides a PM::MapScreen that users [Mapbox](https://www.mapbox.com) as the map provider. Forked from the
popular RubyMotion gem [ProMotion-map](https://github.com/clearsightstudio/ProMotion-map).

## Installation

```ruby
gem 'ProMotion-map'
gem 'ProMotion-mapbox'
```
```ruby
rake pod:install
```


## Usage

Expand All @@ -29,39 +33,40 @@ class MyMapScreen < PM::MapScreen
latitude: 35.090648651123,
title: "Rainbow Falls",
subtitle: "Nantahala National Forest",
action: :show_forest,
left_action: :show_forest,
pin_color: :green
},{
longitude: -82.966093558105,
latitude: 35.092520895652,
title: "Turtleback Falls",
subtitle: "Nantahala National Forest",
action: :show_forest,
pin_color: MKPinAnnotationColorPurple
left_action: :show_forest,
left_action_button_type: UIButtonTypeContactAdd,
pin_color: :red
},{
longitude: -82.95916,
latitude: 35.07496,
title: "Windy Falls",
action: :show_forest
left_action: :show_forest
},{
longitude: -82.943031505056,
latitude: 35.102516828489,
title: "Upper Bearwallow Falls",
subtitle: "Gorges State Park",
action: :show_forest
left_action: :show_forest
},{
longitude: -82.956244328014,
latitude: 35.085548421623,
title: "Stairway Falls",
subtitle: "Gorges State Park",
your_param: "CustomWhatever",
action: :show_forest
right_action: :show_forest
},{
coordinate: CLLocationCoordinate2DMake(35.090648651123, -82.965972900391),
title: "Rainbow Falls",
subtitle: "Nantahala National Forest",
image: UIImage.imageNamed("custom-pin"),
action: :show_forest
left_action: :show_forest
}]
end

Expand All @@ -76,7 +81,7 @@ Here's a neat way to zoom into a specific marker in an animated fashion and then

```ruby
def zoom_to_marker(marker)
set_region region(coordinate: marker.coordinate, span: [0.05, 0.05])
set_region region(coordinate: marker.coordinate, radius: 5) # Radius are specified in nautical miles.
select_annotation marker
end
```
Expand All @@ -103,7 +108,7 @@ All possible properties:
title: "Stairway Falls", # REQUIRED
subtitle: "Gorges State Park",
image: "my_custom_image",
pin_color: :red, # Defaults to :red. Other options are :green or :purple or any MKPinAnnotationColor
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.
left_accessory: my_button,
right_accessory: my_other_button,
action: :my_action, # Overrides :right_accessory
Expand All @@ -117,6 +122,8 @@ Use `:image` to specify a custom image. Pass in a string to conserve memory and

Use `:left_accessory` and `:right_accessory` to specify a custom accessory, like a button.

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.

You can access annotation data you've arbitrarily stored in the hash by calling `annotation_instance.params[:your_param]`.

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`.
Expand Down Expand Up @@ -170,7 +177,7 @@ Returns a `CLLocation2D` object of the user's location or `nil` if the user loca

#### zoom_to_user(radius = 0.05, animated=true)

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._
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 the distance in nautical miles from the center point (user location) to the corners of a virtual bounding box.

#### select_annotation(annotation, animated=true)

Expand Down Expand Up @@ -208,20 +215,17 @@ Changes the zoom and center point of the `MapScreen` to fit all the annotations.

Sets the region of the `MapScreen`. `region` should be an instance of `MKCoordinateRegion`.

#### region(params)
#### region(center_location,radius=10)

Helper method to create an `MKCoordinateRegion`. Expects a hash in the form of:
Mapbox doesn't use the concept of regions. Instead, we can zoom to a virtual bounding box defined by its Sourthwest and Northeast
corners.
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)

```ruby
my_region = region({
coordinate:{
latitude: 35.0906,
longitude: -82.965
},
# span is the latitude and longitude delta
span: [0.5, 0.5]
CLLocationCoordinate2D.new(35.0906,-82.965),
radius: 11
})
```

---

Expand Down Expand Up @@ -359,7 +363,7 @@ rotate_enabled = (bool)enabled

#### `map` or `mapview`

Reference to the created UIMapView.
Reference to the created MLGMapView.

## Contributing

Expand Down
10 changes: 7 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ require 'bundler'
Bundler.require(:development)
require 'ProMotion'
require 'ProMotion-map'
require 'motion-cocoapods'

Motion::Project::App.setup do |app|
# Use `rake config' to see complete project settings.
app.name = 'ProMotion-map'

# app.sdk_version = "8.1"
# app.deployment_target = '7.1'
app.info_plist['MGLMapboxAccessToken'] = 'pk.eyJ1IjoiZGlvZ29hbmRyZSIsImEiOiJvT0lWd0JJIn0.9K1ORT72EUNOVIiGMIGUPA'
app.info_plist['MGLMapboxMetricsEnabledSettingShownInApp'] = true
app.info_plist['NSLocationAlwaysUsageDescription'] = "User tracking"
app.info_plist['UIBackgroundModes'] = ['location','fetch']
# app.sdk_version = "8.4"
# app.deployment_target = '8.4'
end
47 changes: 26 additions & 21 deletions app/test_screens/test_map_screen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ class TestMapScreen < PM::MapScreen
attr_accessor :infinite_loop_points, :request_complete, :action_called
attr_accessor :got_will_change_region, :got_on_change_region

start_position latitude: 35.090648651123, longitude: -82.965972900391, radius: 4
title "Gorges State Park, NC"
start_position latitude: -22.969368, longitude: -43.179837, radius: 10
title "Rio de Janeiro, Brasil"
map_style "mapbox-streets-v7"
tap_to_add length: 1.5, annotation: {animates_drop: false, title: "A new park?"}

def on_load
Expand All @@ -19,29 +20,33 @@ def promotion_annotation_data
def annotation_data
# Partial set of data from "GPS Map of Gorges State Park": http://www.hikewnc.info/maps/gorges-state-park/gps-map
@data ||= [{
longitude: -82.965972900391,
latitude: 35.090648651123,
title: "Rainbow Falls",
subtitle: "Nantahala National Forest",
},{
# Example of using :coordinate instead of :latitude & :longitude
coordinate: CLLocationCoordinate2DMake(35.092520895652, -82.966093558105),
title: "Turtleback Falls",
subtitle: "Nantahala National Forest",
coordinate: CLLocationCoordinate2DMake(-22.969368, -43.179837),
title: "Praia de Copacabana",
subtitle: "Rio de Janeiro",
left_accessory: UIButton.buttonWithType(3),
},{
longitude: -43.285188,
latitude: -22.945641,
title: "Floresta da Tijuca",
subtitle: "Floresta Nacional da Tijuca",
image: "park2",
left_action: :my_action
},{
longitude: -82.95916,
latitude: 35.07496,
title: "Windy Falls"
longitude: -43.156084,
latitude: -22.949318,
title: "Pão de Açucar",
subtitle: "Sugar Loaf",
right_action: :my_action,
},{
longitude: -82.943031505056,
latitude: 35.102516828489,
title: "Upper Bearwallow Falls",
subtitle: "Gorges State Park",
longitude: -43.175977,
latitude: -22.909438,
title: "Teatro Municipal",
},{
longitude: -82.956244328014,
latitude: 35.085548421623,
title: "Stairway Falls",
subtitle: "Gorges State Park",
longitude: -43.179191,
latitude: -22.915285,
title: "Escadaria Selaron",
subtitle: "Lapa",
}]
end

Expand Down
5 changes: 4 additions & 1 deletion lib/ProMotion-map.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@
app.files << File.join(lib_dir_path, "ProMotion/map/map_screen_module.rb")
app.files << File.join(lib_dir_path, "ProMotion/map/map_screen.rb")

app.frameworks += %w(CoreLocation MapKit)
app.frameworks += %w(CoreLocation MapKit QuartzCore)
app.pods do
pod 'Mapbox-iOS-SDK'
end
end
13 changes: 12 additions & 1 deletion lib/ProMotion/map/map_screen_annotation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ def set_defaults
pin_color: :red,
identifier: "Annotation-#{@params[:pin_color]}-#{@params[:image]}",
show_callout: true,
animates_drop: false
animates_drop: false,
image: nil,
left_accessory: nil,
right_accessory: nil,
}.merge(@params)
end

Expand All @@ -41,6 +44,14 @@ def coordinate
@coordinate
end

def left_accessory
@params[:left_accessory]
end

def right_accessory
@params[:right_accessory]
end

def cllocation
CLLocation.alloc.initWithLatitude(@params[:latitude], longitude:@params[:longitude])
end
Expand Down
Loading