X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/cfbdd3f7e1c688e2c875ded9fd847fcc1c3a4caf..82eedbf6511faf136293fce5ffc394ee0bf3511a:/lib/quad_tile.rb diff --git a/lib/quad_tile.rb b/lib/quad_tile.rb index 6e4fb6d22..70012597b 100644 --- a/lib/quad_tile.rb +++ b/lib/quad_tile.rb @@ -3,8 +3,8 @@ module QuadTile require "quad_tile/quad_tile_so" rescue MissingSourceFile def self.tile_for_point(lat, lon) - x = ((lon + 180) * 65535 / 360).round - y = ((lat + 90) * 65535 / 180).round + x = ((lon.to_f + 180) * 65535 / 360).round + y = ((lat.to_f + 90) * 65535 / 180).round return tile_for_xy(x, y) end @@ -39,6 +39,25 @@ module QuadTile return t end + + def self.iterate_tiles_for_area(minlat, minlon, maxlat, maxlon) + tiles = tiles_for_area(minlat, minlon, maxlat, maxlon) + first = last = nil + + tiles.sort.each do |tile| + if last.nil? + first = last = tile + elsif tile == last + 1 + last = tile + else + yield first, last + + first = last = tile + end + end + + yield first, last unless last.nil? + end end def self.sql_for_area(minlat, minlon, maxlat, maxlon, prefix) @@ -58,24 +77,5 @@ module QuadTile return "( " + sql.join(" OR ") + " )" end - def self.iterate_tiles_for_area(minlat, minlon, maxlat, maxlon) - tiles = tiles_for_area(minlat, minlon, maxlat, maxlon) - first = last = nil - - tiles.sort.each do |tile| - if last.nil? - first = last = tile - elsif tile == last + 1 - last = tile - else - yield first, last - - first = last = tile - end - end - - yield first, last unless last.nil? - end - private_class_method :tile_for_xy, :iterate_tiles_for_area end