X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/d2cf09f389b2b92aa2bc55f375573173a2bcf1a4..f412c80d3f3fbb496fcd0baa09c464fa179dd839:/lib/quad_tile.rb?ds=sidebyside diff --git a/lib/quad_tile.rb b/lib/quad_tile.rb index 70012597b..347e7a817 100644 --- a/lib/quad_tile.rb +++ b/lib/quad_tile.rb @@ -6,14 +6,14 @@ module QuadTile x = ((lon.to_f + 180) * 65535 / 360).round y = ((lat.to_f + 90) * 65535 / 180).round - return tile_for_xy(x, y) + tile_for_xy(x, y) end - def self.tiles_for_area(minlat, minlon, maxlat, maxlon) - minx = ((minlon + 180) * 65535 / 360).round - maxx = ((maxlon + 180) * 65535 / 360).round - miny = ((minlat + 90) * 65535 / 180).round - maxy = ((maxlat + 90) * 65535 / 180).round + def self.tiles_for_area(bbox) + minx = ((bbox.min_lon + 180) * 65535 / 360).round + maxx = ((bbox.max_lon + 180) * 65535 / 360).round + miny = ((bbox.min_lat + 90) * 65535 / 180).round + maxy = ((bbox.max_lat + 90) * 65535 / 180).round tiles = [] minx.upto(maxx) do |x| @@ -22,7 +22,7 @@ module QuadTile end end - return tiles + tiles end def self.tile_for_xy(x, y) @@ -30,18 +30,18 @@ module QuadTile 16.times do t = t << 1 - t = t | 1 unless (x & 0x8000).zero? + t |= 1 unless (x & 0x8000).zero? x <<= 1 t = t << 1 - t = t | 1 unless (y & 0x8000).zero? + t |= 1 unless (y & 0x8000).zero? y <<= 1 end - return t + t end - def self.iterate_tiles_for_area(minlat, minlon, maxlat, maxlon) - tiles = tiles_for_area(minlat, minlon, maxlat, maxlon) + def self.iterate_tiles_for_area(bbox) + tiles = tiles_for_area(bbox) first = last = nil tiles.sort.each do |tile| @@ -60,11 +60,11 @@ module QuadTile end end - def self.sql_for_area(minlat, minlon, maxlat, maxlon, prefix) - sql = Array.new - single = Array.new + def self.sql_for_area(bbox, prefix) + sql = [] + single = [] - iterate_tiles_for_area(minlat, minlon, maxlat, maxlon) do |first,last| + iterate_tiles_for_area(bbox) do |first, last| if first == last single.push(first) else @@ -72,9 +72,9 @@ module QuadTile end end - sql.push("#{prefix}tile IN (#{single.join(',')})") if single.size > 0 + sql.push("#{prefix}tile IN (#{single.join(',')})") unless single.empty? - return "( " + sql.join(" OR ") + " )" + "( " + sql.join(" OR ") + " )" end private_class_method :tile_for_xy, :iterate_tiles_for_area