Class: Map::Gdal::TilesService

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/map/gdal/tiles_service.rb

Constant Summary collapse

DEFAULT_ZOOM_MAX =
15

Instance Attribute Summary

Attributes included from Base

#files_to_clean

Instance Method Summary collapse

Methods included from Base

#add_to_clean, #clean, #gdal_running?, #get_file_name_with_path, #get_layer_name, #get_path_to_temp_file, #options_to_command_line, #run_command, #store_kml, #tmp_file

Constructor Details

#initialize(file) ⇒ TilesService

Returns a new instance of TilesService.



8
9
10
# File 'lib/map/gdal/tiles_service.rb', line 8

def initialize(file)
  @file = file
end

Instance Method Details

#call(options = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/map/gdal/tiles_service.rb', line 12

def call(options = {})
  tiles_folder = options[:output] || File.join(Dir.tmpdir, "tiles-#{(Time.current.to_i * rand).to_i}")

  run_command("gdal2tiles.py --profile=mercator -z #{options[:zoom_min].to_i}-#{options[:zoom_max] || DEFAULT_ZOOM_MAX} #{@file} #{tiles_folder}")

  add_to_clean(tiles_folder)

  tiles_folder
end