Class: Mormon::Tile::Name

Inherits:
Object
  • Object
show all
Defined in:
lib/mormon/tile_name.rb

Constant Summary collapse

LAYERS_URL =
{
  tah:    "http://a.tile.openstreetmap.org/",
  oam:    "http://oam1.hypercube.telascience.org/tiles/1.0.0/openaerialmap-900913/",
  mapnik: "http://tile.openstreetmap.org/mapnik/"
}

Instance Method Summary collapse

Instance Method Details

#edges(x, y, z) ⇒ Object



15
16
17
18
19
# File 'lib/mormon/tile_name.rb', line 15

def edges(x, y, z)
  lat1, lat2 = lat_edges(y, z)
  lon1, lon2 = lon_edges(x, z)
  [lat2, lon1, lat1, lon2] # S,W,N,E
end

#layer_base(layer) ⇒ Object



29
30
31
# File 'lib/mormon/tile_name.rb', line 29

def layer_base(layer)
  LAYERS_URL[layer]
end

#layer_ext(layer) ⇒ Object



25
26
27
# File 'lib/mormon/tile_name.rb', line 25

def layer_ext(layer)
  layer == 'oam' ? 'jpg' : 'png'
end

#px_sizeObject



21
22
23
# File 'lib/mormon/tile_name.rb', line 21

def px_size
  256
end

#url(x, y, z, layer = :mapnik) ⇒ Object



33
34
35
# File 'lib/mormon/tile_name.rb', line 33

def url(x, y, z, layer = :mapnik)
  "%s%d/%d/%d.%s" % [layer_base(layer), z, x, y, layer_ext(layer)]
end

#xy(lat, lon, z) ⇒ Object



37
38
39
40
# File 'lib/mormon/tile_name.rb', line 37

def xy(lat, lon, z)
  x, y = latlon_2_xy(lat, lon, z)
  [x.to_i, y.to_i]
end

#xy_2_latlon(x, y, z) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/mormon/tile_name.rb', line 42

def xy_2_latlon(x, y, z)
  n = num_tiles(z)
  rel_y = y / n
  lat = mercator_to_lat(Math::PI * (1 - 2 * rel_y))
  lon = -180.0 + 360.0 * x / n
  [lat, lon]
end