Module: MapKit::ZoomLevel
Overview
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- MERCATOR_OFFSET =
Total map width in pixels
268435456.0
- MERCATOR_RADIUS =
Map radius in pixels
MERCATOR_OFFSET / PI
Class Method Summary collapse
-
.included(base) ⇒ Object
Include class methods.
Instance Method Summary collapse
-
#set_center_coordinates(center_coordinate, zoom_level, animated = false) ⇒ Object
Set the views center coordinates with a given zoom level.
-
#set_map_lat_lon(latitude, longitude, zoom_level, animated = false) ⇒ Object
Set the views latitude and longitude with a given zoom level.
-
#set_zoom_level(zoom_level, animated = false) ⇒ Object
Set the current zoom level.
-
#zoom_level ⇒ Object
Get the current zoom level.
Class Method Details
.included(base) ⇒ Object
Include class methods
200 201 202 |
# File 'lib/map-kit-wrapper/zoom_level.rb', line 200 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#set_center_coordinates(center_coordinate, zoom_level, animated = false) ⇒ Object
Set the views center coordinates with a given zoom level
-
Args :
-
center_coordinate
-> A MKMapPoint -
zoom_level
-> Zoom level as Int -
animated
-> bool
-
212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/map-kit-wrapper/zoom_level.rb', line 212 def set_center_coordinates(center_coordinate, zoom_level, animated = false) # clamp large numbers to 18 zoom_level = [zoom_level, 18].min # use the zoom level to compute the region span = self.class.coordinate_span_with_map_view(self, center_coordinate, zoom_level) region = MKCoordinateRegionMake(center_coordinate, span) # set the region like normal self.setRegion(region, animated: animated) end |
#set_map_lat_lon(latitude, longitude, zoom_level, animated = false) ⇒ Object
Set the views latitude and longitude with a given zoom level
-
Args :
-
latitude
-> Float -
longitude
-> Float -
zoom_level
-> Zoom level as Int -
animated
-> bool
-
233 234 235 236 |
# File 'lib/map-kit-wrapper/zoom_level.rb', line 233 def set_map_lat_lon(latitude, longitude, zoom_level, animated = false) coordinates = CLLocationCoordinate2DMake(latitude, longitude) set_center_coordinates(coordinates, zoom_level, animated) end |
#set_zoom_level(zoom_level, animated = false) ⇒ Object
Set the current zoom level
-
Args :
-
zoom_level
-> Int or Float -
animated
-> Bool
-
264 265 266 |
# File 'lib/map-kit-wrapper/zoom_level.rb', line 264 def set_zoom_level(zoom_level, animated = false) set_center_coordinates(self.region.api.center, zoom_level, animated) end |
#zoom_level ⇒ Object
Get the current zoom level
-
Returns :
-
Zoom level as a Float
-
244 245 246 247 248 249 250 251 252 253 254 255 |
# File 'lib/map-kit-wrapper/zoom_level.rb', line 244 def zoom_level region = self.region.api center_pixel_x = self.class.longitude_to_pixel_space_x(region.center.longitude) top_left_pixel_x = self.class.longitude_to_pixel_space_x(region.center.longitude - region.span.longitudeDelta / 2) scaled_map_width = (center_pixel_x - top_left_pixel_x) * 2 map_size_in_pixels = self.bounds.size zoom_scale = scaled_map_width / map_size_in_pixels.width zoom_exponent = log(zoom_scale) / log(2) zoom_level = 20 - zoom_exponent zoom_level end |