Class: GMS::Engine

Inherits:
Object
  • Object
show all
Defined in:
lib/google-map-stitch/engine.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Engine

Returns a new instance of Engine.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/google-map-stitch/engine.rb', line 6

def initialize(config)

  @zoomLevel = config[:zoomLevel]||2

  # two is the minimum zoom level
  @zoomLevel = 2 if config[:zoomLevel] < 2

  # if all starting and ending coords are not defined, then
  # assume we want the whole map
  if ![:startX,:endX,:startY,:endY].all? { |key| config.has_key?(key) }
    @startX = 0
    @endX = 2**config[:zoomLevel]-1
    @startY = 0
    @endY = 2**config[:zoomLevel]-1
  else
    @startX = config[:startX]
    @endX = config[:endX]
    @startY = config[:startY]
    @endY = config[:endY]
  end

  # allow the downloaded layer to be customized
  @layer = config[:layerID] || "m@195000000"

  status
end

Instance Attribute Details

#endXObject

Returns the value of attribute endX.



4
5
6
# File 'lib/google-map-stitch/engine.rb', line 4

def endX
  @endX
end

#endYObject

Returns the value of attribute endY.



4
5
6
# File 'lib/google-map-stitch/engine.rb', line 4

def endY
  @endY
end

#layerObject

Returns the value of attribute layer.



4
5
6
# File 'lib/google-map-stitch/engine.rb', line 4

def layer
  @layer
end

#startXObject

Returns the value of attribute startX.



4
5
6
# File 'lib/google-map-stitch/engine.rb', line 4

def startX
  @startX
end

#startYObject

Returns the value of attribute startY.



4
5
6
# File 'lib/google-map-stitch/engine.rb', line 4

def startY
  @startY
end

#zoomLevelObject

Returns the value of attribute zoomLevel.



4
5
6
# File 'lib/google-map-stitch/engine.rb', line 4

def zoomLevel
  @zoomLevel
end

Instance Method Details

#heightObject

total height in tiles



39
40
41
# File 'lib/google-map-stitch/engine.rb', line 39

def height
  @endY-@startY
end

#imageURL(x, y, z, layer = @layer) ⇒ Object

build a url for a google image



69
70
71
# File 'lib/google-map-stitch/engine.rb', line 69

def imageURL(x, y, z, layer=@layer)
  "http://mt1.google.com/vt/lyrs=#{layer}&hl=en&x=#{x}&s=&y=#{y}&z=#{z.to_s}"
end

#pixelHeightObject

total height in pixels



49
50
51
# File 'lib/google-map-stitch/engine.rb', line 49

def pixelHeight
  height*256
end

#pixelWidthObject

total width in pixels



44
45
46
# File 'lib/google-map-stitch/engine.rb', line 44

def pixelWidth
  width*256
end

#printHeight(dpi = 300) ⇒ Object

total height printed @ 300 dpi (in inches)



59
60
61
# File 'lib/google-map-stitch/engine.rb', line 59

def printHeight(dpi=300)
  (pixelHeight.to_f/dpi).round(2)
end

#printWidth(dpi = 300) ⇒ Object

total width printed @ 300 dpi (in inches)



54
55
56
# File 'lib/google-map-stitch/engine.rb', line 54

def printWidth(dpi=300)
  (pixelWidth.to_f/dpi).round(2)
end

#statusObject



73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/google-map-stitch/engine.rb', line 73

def status
  puts "\Google Map Stitch Configuration"
  puts "======================================================="
  puts "Starting Coord: #{@startX},#{@endX}"
  puts "Ending Coord: #{@startY},#{@endY}"
  puts "Zoom Level: #{@zoomLevel}"
  puts "Total Tiles to Download: #{tileCount.to_s.reverse.gsub(/...(?=.)/,'\&,').reverse}"
  puts "Final Image Size @ 72DPI #{pixelWidth}x#{pixelHeight}"
  puts "Final Print Size @ 300DPI (Inches): #{printWidth}\"x#{printHeight}\""
  puts "Final Print Size @ 300DPI (Feet): #{(printWidth/12).round(2)}'x#{(printHeight/12).round(2)}'"
  puts "=======================================================\n\n"
end

#tileCountObject

total number of tiles to download



64
65
66
# File 'lib/google-map-stitch/engine.rb', line 64

def tileCount
  width*height
end

#tilesObject

list all tiles



87
88
89
90
91
92
93
94
95
96
97
# File 'lib/google-map-stitch/engine.rb', line 87

def tiles
  @startY.upto(@endY).map.with_index do |y, c|
    @startX.upto(@endX).map.with_index do |x, r|
      {
        :url => imageURL(x,y,@zoomLevel,@layer),
        :dir => "r#{"%06d" % r}",
        :file => "c#{"%06d" % c}.png"
      }
    end
  end.flatten
end

#widthObject

total width in tiles



34
35
36
# File 'lib/google-map-stitch/engine.rb', line 34

def width
  @endX-@startX
end