3 require "quad_tile/quad_tile_so"
4 rescue MissingSourceFile
5 def self.tile_for_point(lat, lon)
6 x = ((lon + 180) * 65535 / 360).round
7 y = ((lat + 90) * 65535 / 180).round
9 return tile_for_xy(x, y)
12 def self.tiles_for_area(minlat, minlon, maxlat, maxlon)
13 minx = ((minlon + 180) * 65535 / 360).round
14 maxx = ((maxlon + 180) * 65535 / 360).round
15 miny = ((minlat + 90) * 65535 / 180).round
16 maxy = ((maxlat + 90) * 65535 / 180).round
19 minx.upto(maxx) do |x|
20 miny.upto(maxy) do |y|
21 tiles << tile_for_xy(x, y)
28 def self.tile_for_xy(x, y)
33 t = t | 1 unless (x & 0x8000).zero?
36 t = t | 1 unless (y & 0x8000).zero?
44 def self.sql_for_area(minlat, minlon, maxlat, maxlon)
48 iterate_tiles_for_area(minlat, minlon, maxlat, maxlon) do |first,last|
52 sql.push("tile BETWEEN #{first} AND #{last}")
56 sql.push("tile IN (#{single.join(',')})") if single.size > 0
58 return "( " + sql.join(" OR ") + " )"
61 def self.iterate_tiles_for_area(minlat, minlon, maxlat, maxlon)
62 tiles = tiles_for_area(minlat, minlon, maxlat, maxlon)
65 tiles.sort.each do |tile|
68 elsif tile == last + 1
77 yield first, last unless last.nil?
80 private_class_method :tile_for_xy, :iterate_tiles_for_area