Class: GeoWeb::Map
- Inherits:
-
Object
- Object
- GeoWeb::Map
- Defined in:
- lib/geoweb/map.rb
Instance Attribute Summary collapse
-
#boundaries ⇒ Object
Returns the value of attribute boundaries.
-
#projection ⇒ Object
, :transformation.
-
#tile_height ⇒ Object
Returns the value of attribute tile_height.
-
#tile_width ⇒ Object
Returns the value of attribute tile_width.
-
#zoom ⇒ Object
, :transformation.
Class Method Summary collapse
-
.map_extent(zoom, tile_size = 256) ⇒ Object
Calculates the map-size (width or height) given a tile size and specific zoom.
Instance Method Summary collapse
- #absolute_point(offset) ⇒ Object
-
#coordinates_to_point(location) ⇒ Object
Faster, but is accurate only to zoom levels lesser than 17.
- #height ⇒ Object
-
#initialize(options = {}) ⇒ Map
constructor
A new instance of Map.
-
#location_point(location) ⇒ Object
Return an x, y point on the map image for a given geographical location.
-
#point_location(point) ⇒ Object
Return a geographical location on the map image for a given x, y point.
- #relative_point(point) ⇒ Object
-
#width ⇒ Object
SAME AS DIMENSIONS, retirar isso.
Constructor Details
#initialize(options = {}) ⇒ Map
Returns a new instance of Map.
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/geoweb/map.rb', line 13 def initialize(={}) @tile_width = [:tile_width] || 256 @tile_height = [:tile_height] || 256 @zoom = [:zoom] || 1 @boundaries = [:boundaries] || {} @origin_tile = [:origin_tile] || Coordinate.new(0, 0, @zoom) @origin_pixel = [:origin_pixel] || Point.new(0, 0, @zoom) # @dimensions = Point.new(map_extent(@zoom, @tile_width), map_extent(@zoom, @tile_height)) # @transformation = options[:transformation] || default_transformation @projection = [:projection] || default_mercator_projection([:transformation]) end |
Instance Attribute Details
#boundaries ⇒ Object
Returns the value of attribute boundaries.
5 6 7 |
# File 'lib/geoweb/map.rb', line 5 def boundaries @boundaries end |
#projection ⇒ Object
, :transformation
4 5 6 |
# File 'lib/geoweb/map.rb', line 4 def projection @projection end |
#tile_height ⇒ Object
Returns the value of attribute tile_height.
6 7 8 |
# File 'lib/geoweb/map.rb', line 6 def tile_height @tile_height end |
#tile_width ⇒ Object
Returns the value of attribute tile_width.
6 7 8 |
# File 'lib/geoweb/map.rb', line 6 def tile_width @tile_width end |
#zoom ⇒ Object
, :transformation
4 5 6 |
# File 'lib/geoweb/map.rb', line 4 def zoom @zoom end |
Class Method Details
.map_extent(zoom, tile_size = 256) ⇒ Object
Calculates the map-size (width or height) given a tile size and specific zoom
9 10 11 |
# File 'lib/geoweb/map.rb', line 9 def self.map_extent(zoom, tile_size=256) 2 ** (zoom + Math::log(tile_size)/Math::log(2)) end |
Instance Method Details
#absolute_point(offset) ⇒ Object
35 36 37 |
# File 'lib/geoweb/map.rb', line 35 def absolute_point(offset) (@origin_pixel + offset) end |
#coordinates_to_point(location) ⇒ Object
Faster, but is accurate only to zoom levels lesser than 17
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/geoweb/map.rb', line 47 def coordinates_to_point(location) lat, lon = location.lat, location.lon #Parece que ele faz isso pra representar como uma fração (sem sinal) de 2Pi #http://en.wikipedia.org/wiki/Longitude#Noting_and_calculating_longitude long_deg = (-180.0 - lon).abs long_ppd = width.to_f / 360.0 long_ppdrad = width.to_f / (2.0 * Math::PI) px_x = long_deg * long_ppd e = Math::sin( lat * (1.0/180.0 * Math::PI) ) e = 0.9999 if e > 0.9999 e = -0.9999 if e < -0.9999 px_y = (height / 2.0) + 0.5 * Math::log((1+e)/(1-e)) * (-long_ppdrad) return absolute_point(Point.new(px_x, px_y, zoom)) end |
#height ⇒ Object
29 |
# File 'lib/geoweb/map.rb', line 29 def height; @height ||= GeoWeb::Map.map_extent(zoom, tile_height); end |
#location_point(location) ⇒ Object
Return an x, y point on the map image for a given geographical location.
40 41 42 43 44 |
# File 'lib/geoweb/map.rb', line 40 def location_point(location) coord = projection.location_coordinate(location).zoom_to(zoom) point = (coord - @origin_tile) * [@tile_width, @tile_height] return absolute_point(point) end |
#point_location(point) ⇒ Object
Return a geographical location on the map image for a given x, y point.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/geoweb/map.rb', line 66 def point_location(point) # origin tile at maximum zoom hizoom_origin_tile = @origin_tile.zoom_to(Coordinate::MAX_ZOOM) # distance in tile widths from reference tile to point tiles_distance = relative_point(point) / [@tile_width, @tile_height] # distance in rows & columns at maximum zoom distance = Coordinate.new(tiles_distance.x, tiles_distance.y, zoom).zoom_to(Coordinate::MAX_ZOOM) distance.z = 0 # absolute tile at maximum zoom tile = (hizoom_origin_tile + distance).round! tile = tile.zoom_to(zoom) location = projection.coordinate_location(tile) return location end |
#relative_point(point) ⇒ Object
31 32 33 |
# File 'lib/geoweb/map.rb', line 31 def relative_point(point) (point - @origin_pixel) end |
#width ⇒ Object
SAME AS DIMENSIONS, retirar isso
28 |
# File 'lib/geoweb/map.rb', line 28 def width; @width ||= GeoWeb::Map.map_extent(zoom, tile_width); end |