Class: Tairu::Store::Esri

Inherits:
Object
  • Object
show all
Defined in:
lib/tairu/store/esri.rb

Instance Method Summary collapse

Constructor Details

#initialize(layer) ⇒ Esri

Returns a new instance of Esri.



4
5
6
# File 'lib/tairu/store/esri.rb', line 4

def initialize(layer)
  @tileset = File.join(File.expand_path(Tairu.layers[layer]['location']), Tairu.layers[layer]['tileset'])
end

Instance Method Details

#decode_hex(hex_value) ⇒ Object



27
28
29
# File 'lib/tairu/store/esri.rb', line 27

def decode_hex(hex_value)
  Integer("0x#{hex_value}")
end

#encode_hex(int_value, length = 8) ⇒ Object



31
32
33
34
# File 'lib/tairu/store/esri.rb', line 31

def encode_hex(int_value, length=8)
  length = "%02i" % length
  "%#{length}x" % int_value
end

#get(coord, format = 'png') ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/tairu/store/esri.rb', line 8

def get(coord, format='png')
  path = File.join(@tileset, 'Layers', '_alllayers', "L#{'%02i' % coord.zoom}", "R#{encode_hex(coord.row)}", "C#{encode_hex(coord.column)}.#{format}")

  return nil unless File.exists?(path)

  data = File.open(path, 'r') do |f|
    begin
      f.flock(File::LOCK_SH)
      f.read
    ensure
      f.flock(File::LOCK_UN)
    end
  end

  mime_type = "image/#{format}"
  tile = data.nil? ? nil : Tairu::Tile.new(data, mime_type)
  tile
end