atlas_middleware 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +23 -2
- data/lib/{rest_proxy.rb → arcgis_server_rest_proxy.rb} +1 -1
- data/lib/cgns_search.rb +16 -6
- data/lib/export_map_services.rb +56 -0
- data/lib/map_server_legend_info.rb +26 -6
- data/lib/postal_code_lookup.rb +19 -12
- data/test/print_map/job_test.rb +139 -0
- data/test/print_map/worker_test.rb +47 -0
- data/test/print_map_service_test.rb +68 -0
- data/test/test_helper.rb +7 -0
- metadata +49 -19
- data/lib/arc_server_soap.rb +0 -47
- data/lib/esri/soap/map_server/classes.rb +0 -4328
- data/lib/esri/soap/map_server/client.rb +0 -326
- data/lib/esri/soap/map_server/map_server.rb +0 -39
- data/lib/esri/soap/map_server/mapping_registry.rb +0 -4300
- data/lib/pdf_template.rb +0 -206
data/lib/pdf_template.rb
DELETED
@@ -1,206 +0,0 @@
|
|
1
|
-
#! /usr/bin/ruby
|
2
|
-
|
3
|
-
$:.unshift File.join(File.dirname(__FILE__))
|
4
|
-
|
5
|
-
require 'rubygems'
|
6
|
-
require 'prawn'
|
7
|
-
require 'prawn/format'
|
8
|
-
require 'prawn/layout'
|
9
|
-
#require 'prawn/fast_png'
|
10
|
-
require 'open-uri'
|
11
|
-
require 'esri/soap/map_server/map_server'
|
12
|
-
require 'RMagick'
|
13
|
-
require 'perftools'
|
14
|
-
require 'base64'
|
15
|
-
|
16
|
-
module Prawn
|
17
|
-
module Images
|
18
|
-
class PNG
|
19
|
-
alias_method :prawn_fast_png_old_initialize, :initialize
|
20
|
-
|
21
|
-
def initialize(data) #:nodoc:
|
22
|
-
@prawn_fast_png_data = data
|
23
|
-
prawn_fast_png_old_initialize(data)
|
24
|
-
end
|
25
|
-
|
26
|
-
private
|
27
|
-
def unfilter_image_data
|
28
|
-
img = Magick::Image.from_blob(@prawn_fast_png_data).first
|
29
|
-
|
30
|
-
# get only one color value per pixel (Intensity) for grayscale+alpha images
|
31
|
-
format = color_type == 4 ? 'I' : 'RGB'
|
32
|
-
|
33
|
-
img_data = img.export_pixels_to_str(0, 0, width, height, format)
|
34
|
-
alpha_channel = img.export_pixels_to_str(0, 0, width, height, 'A')
|
35
|
-
|
36
|
-
img.destroy!
|
37
|
-
@prawn_fast_png_data = nil
|
38
|
-
|
39
|
-
@img_data = Zlib::Deflate.deflate(img_data)
|
40
|
-
@alpha_channel = Zlib::Deflate.deflate(alpha_channel)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
|
47
|
-
def collect_legend_images
|
48
|
-
images = []
|
49
|
-
service = 'http://sampleserver1.arcgisonline.com/ArcGIS/services/Portland/ESRI_LandBase_WebMercator/MapServer'
|
50
|
-
legend_infos = ESRI::Soap::MapServer.get_legend_info(service, :image_return_type => :data)
|
51
|
-
|
52
|
-
legend_infos.each do |legend_info|
|
53
|
-
if legend_info.legendGroups[0].legendClasses.length == 1
|
54
|
-
img_data = Base64.decode64(Base64.decode64(legend_info.legendGroups[0].legendClasses[0].symbolImage.imageData))
|
55
|
-
images << {
|
56
|
-
:label => legend_info.name,
|
57
|
-
:image => Magick::Image.from_blob(img_data).first
|
58
|
-
}
|
59
|
-
else
|
60
|
-
legend_info.legendGroups[0].legendClasses.each do |legend_class|
|
61
|
-
img_data = Base64.decode64(Base64.decode64(legend_class.symbolImage.imageData))
|
62
|
-
images << {
|
63
|
-
:label => legend_class.label,
|
64
|
-
:image => Magick::Image.from_blob(img_data).first
|
65
|
-
}
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
images
|
71
|
-
end
|
72
|
-
|
73
|
-
def create_legend(pdf, opts = {})
|
74
|
-
images = collect_legend_images
|
75
|
-
|
76
|
-
columns = opts[:columns] || 4
|
77
|
-
rows = opts[:rows] || 4
|
78
|
-
gutter = opts[:gutter] || 0
|
79
|
-
|
80
|
-
pdf.define_grid(:columns => columns, :rows => rows, :gutter => gutter)
|
81
|
-
|
82
|
-
pdf.grid.rows.times do |i|
|
83
|
-
pdf.grid.columns.times do |j|
|
84
|
-
cell = pdf.grid(i,j)
|
85
|
-
pdf.bounding_box cell.top_left, :width => cell.width, :height => cell.height do
|
86
|
-
return if images.empty?
|
87
|
-
image = images.shift
|
88
|
-
|
89
|
-
pdf.image StringIO.new(image[:image].to_blob), :at => [pdf.bounds.top_left], :fit => [16, 16]
|
90
|
-
pdf.text_box image[:label],
|
91
|
-
:width => cell.width,
|
92
|
-
:height => cell.height,
|
93
|
-
:overflow => :ellipses,
|
94
|
-
:at => [pdf.bounds.left + 20, pdf.bounds.top - 2]
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
def portrait_pdf
|
101
|
-
print 'creating portrait pdf...'
|
102
|
-
Prawn::Document.generate '/home/colin/portrait.pdf', :page_layout => :portrait do |pdf|
|
103
|
-
box = pdf.bounds
|
104
|
-
# html tag definitions
|
105
|
-
pdf.tags :h1 => { :font_size => '25', :font_style => :bold }
|
106
|
-
# html style definitions
|
107
|
-
pdf.styles :footer => { :color => "#999", :font_style => :italic }
|
108
|
-
|
109
|
-
# header
|
110
|
-
pdf.bounding_box [box.left, box.top], :width => box.right, :height => 30 do
|
111
|
-
pdf.text "<h1>Title</h1>"
|
112
|
-
end
|
113
|
-
|
114
|
-
# map
|
115
|
-
pdf.bounding_box [box.left, pdf.cursor], :width => box.right, :height => box.width do
|
116
|
-
pdf.stroke_bounds
|
117
|
-
pdf.image "/home/colin/export.png", :at => [box.left, pdf.cursor], :width => box.width, :height => box.width
|
118
|
-
end
|
119
|
-
|
120
|
-
pdf.move_down 10
|
121
|
-
# toc
|
122
|
-
pdf.bounding_box [box.left, pdf.cursor], :width => box.right, :height => 140 do
|
123
|
-
pdf.padded_box 5 do
|
124
|
-
create_legend(pdf, :columns => 4, :rows => 5)
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
# footer
|
129
|
-
pdf.canvas do
|
130
|
-
footer = {
|
131
|
-
:top_left => [box.absolute_left - 20, box.absolute_bottom - 15],
|
132
|
-
:width => box.right + 40,
|
133
|
-
:height => 15
|
134
|
-
}
|
135
|
-
|
136
|
-
pdf.bounding_box footer[:top_left], :width => footer[:width], :height => footer[:height] do
|
137
|
-
pdf.text '<span class="footer">NB Aquatic Bio-Web</span>'
|
138
|
-
end
|
139
|
-
|
140
|
-
pdf.bounding_box footer[:top_left], :width => footer[:width], :height => footer[:height] do
|
141
|
-
pdf.text "<span class=\"footer\">Generated on #{Time.now.strftime("%Y/%m/%d")}</span>", :align => :right
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
145
|
-
puts 'done'
|
146
|
-
end
|
147
|
-
|
148
|
-
def landscape_pdf
|
149
|
-
print 'creating landscape pdf...'
|
150
|
-
Prawn::Document.generate '/home/colin/landscape.pdf', :page_layout => :landscape do |pdf|
|
151
|
-
box = pdf.bounds
|
152
|
-
# html tag definitions
|
153
|
-
pdf.tags :h1 => { :font_size => '25', :font_style => :bold }
|
154
|
-
# html style definitions
|
155
|
-
pdf.styles :footer => { :color => "#999", :font_style => :italic }
|
156
|
-
|
157
|
-
# map
|
158
|
-
pdf.bounding_box [box.left, box.top], :width => box.height, :height => box.height do
|
159
|
-
pdf.stroke_bounds
|
160
|
-
pdf.image "/home/colin/export.png", :at => [box.left, box.top], :width => box.height, :height => box.height
|
161
|
-
end
|
162
|
-
|
163
|
-
pdf.bounding_box [box.height + 10, box.top], :width => box.right - box.height - 10, :height => box.height do
|
164
|
-
# header
|
165
|
-
pdf.text "<h1>Title</h1>"
|
166
|
-
pdf.move_down 10
|
167
|
-
|
168
|
-
# toc
|
169
|
-
pdf.bounding_box [pdf.bounds.left, pdf.cursor], :width => pdf.bounds.right, :height => pdf.cursor do
|
170
|
-
create_legend(pdf, :columns => 1, :rows => 20)
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
# footer
|
175
|
-
pdf.canvas do
|
176
|
-
footer = {
|
177
|
-
:top_left => [box.absolute_left - 20, box.absolute_bottom - 15],
|
178
|
-
:width => box.right + 40,
|
179
|
-
:height => 15
|
180
|
-
}
|
181
|
-
|
182
|
-
pdf.bounding_box footer[:top_left], :width => footer[:width], :height => footer[:height] do
|
183
|
-
pdf.text '<span class="footer">NB Aquatic Bio-Web</span>'
|
184
|
-
end
|
185
|
-
|
186
|
-
pdf.bounding_box footer[:top_left], :width => footer[:width], :height => footer[:height] do
|
187
|
-
pdf.text "<span class=\"footer\">Generated on #{Time.now.strftime("%Y/%m/%d")}</span>", :align => :right
|
188
|
-
end
|
189
|
-
end
|
190
|
-
end
|
191
|
-
puts 'done'
|
192
|
-
end
|
193
|
-
|
194
|
-
PerfTools::CpuProfiler.start("/home/colin/pdf_perf") do
|
195
|
-
start_time = Time.now
|
196
|
-
portrait_pdf
|
197
|
-
end_time = Time.now
|
198
|
-
puts end_time - start_time
|
199
|
-
end
|
200
|
-
|
201
|
-
#
|
202
|
-
#start_time = Time.now
|
203
|
-
#landscape_pdf
|
204
|
-
#end_time = Time.now
|
205
|
-
#puts end_time - start_time
|
206
|
-
#end
|