Class: Gpx2png::Base

Inherits:
Object
  • Object
show all
Extended by:
Calculations::BaseClassMethods
Includes:
Calculations::BaseInstanceMethods
Defined in:
lib/gpx2png/base.rb

Direct Known Subclasses

OsmBase

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Calculations::BaseClassMethods

deg2rad, rad2deg

Methods included from Calculations::BaseInstanceMethods

#calculate_minmax_latlon, #enlarge_border_coords

Constructor Details

#initializeBase

Returns a new instance of Base.



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/gpx2png/base.rb', line 12

def initialize
  @layers = Array.new
  _layer = Layer.new
  _layer.parent = self
  @layers << _layer
  @single_layer = true

  @zoom = 9

  self.class.logger.debug("Init, default zoom #{@zoom.to_s.green}")
end

Instance Attribute Details

#layersObject

Returns the value of attribute layers.



97
98
99
# File 'lib/gpx2png/base.rb', line 97

def layers
  @layers
end

#simulate_downloadObject

Simulate download of tiles



100
101
102
# File 'lib/gpx2png/base.rb', line 100

def simulate_download
  @simulate_download
end

Class Method Details

.loggerObject



120
121
122
123
# File 'lib/gpx2png/base.rb', line 120

def self.logger
  @@logger = Logger.new(STDOUT) unless defined? @@logger
  return @@logger
end

.logger=(_logger) ⇒ Object



116
117
118
# File 'lib/gpx2png/base.rb', line 116

def self.logger=(_logger)
  @@logger = _logger
end

.simulate_download=(b) ⇒ Object



102
103
104
105
# File 'lib/gpx2png/base.rb', line 102

def self.simulate_download=(b)
  logger.debug("Simulate tiles download for class #{self.to_s.blue}") if b
  @@simulate_download = b
end

Instance Method Details

#add(lat, lon) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/gpx2png/base.rb', line 44

def add(lat, lon)
  if @single_layer
    # add coord to first layer
    _layer = @layers.first
    _layer.add(lat, lon)
  else
    # I'm afraid Dave I can't do that
    self.class.logger.fatal("After you've added first layer you can use coords only from layers")
    raise StandardError
  end
end

#add_layer(_layer_options) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/gpx2png/base.rb', line 24

def add_layer(_layer_options)
  if @single_layer
    self.class.logger.debug("Created #{"first".to_s.red} layer")
    # turn off single layer version
    @single_layer = false
    # set layer options for first layer and return it
    _layer = @layers.first
    _layer.options = _layer_options
    return _layer
  else
    # create new layer with options, add to list and return
    _layer = Layer.new
    _layer.parent = self
    _layer.options = _layer_options
    @layers << _layer
    self.class.logger.debug("Created layer, count: #{@layers.size.to_s.red}")
    return _layer
  end
end

#color(_color) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
# File 'lib/gpx2png/base.rb', line 68

def color(_color)
  if @single_layer
    # add coord to first layer
    _layer = @layers.first
    _layer.color = _color
  else
    # I'm afraid Dave I can't do that
    self.class.fatal("After you've added first layer you have to use layers")
    raise StandardError
  end
end

#coords=(_coords) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/gpx2png/base.rb', line 56

def coords=(_coords)
  if @single_layer
    # add coord to first layer
    _layer = @layers.first
    _layer.coords = _coords
  else
    # I'm afraid Dave I can't do that
    self.class.fatal("After you've added first layer you can use coords only from layers")
    raise StandardError
  end
end

#destroyObject



111
112
113
114
# File 'lib/gpx2png/base.rb', line 111

def destroy
  @r.destroy
  self.class.logger.debug "Image destroyed"
end

#fixed_size(_width, _height) ⇒ Object

Create image with fixed size



81
82
83
84
85
86
# File 'lib/gpx2png/base.rb', line 81

def fixed_size(_width, _height)
  @fixed_width = _width
  @fixed_height = _height
  self.class.logger.debug("Map image fixed dimension set #{@fixed_width.to_s.red} x #{@fixed_height.to_s.red}")
  true
end

#simulate_download?Boolean

Returns:

  • (Boolean)


107
108
109
# File 'lib/gpx2png/base.rb', line 107

def simulate_download?
  return true if true == self.simulate_download or (defined? @@simulate_download and true == @@simulate_download)
end

#zoomObject



93
94
95
# File 'lib/gpx2png/base.rb', line 93

def zoom
  @zoom
end

#zoom=(_zoom) ⇒ Object



88
89
90
91
# File 'lib/gpx2png/base.rb', line 88

def zoom=(_zoom)
  self.class.logger.debug("Map zoom set #{_zoom.to_s.red}")
  @zoom = _zoom
end