Skip to content

Commit 01bbf96

Browse files
committed
trying optional arguments
1 parent adbba9b commit 01bbf96

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

lib/redmine_gtt_print/issue_to_json.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,15 @@ def call
3232
image_urls(@issue))
3333
}
3434

35+
scale = nil
36+
basemap_url = nil
37+
if !@other_attributes.nil?
38+
scale = @other_attributes[:scale]
39+
basemap_url = @other_attributes[:basemap_url]
40+
end
3541
if data = @issue.geodata_for_print
3642
json[:attributes][:map] = self.class.map_data(data[:center], [data[:geojson]],
37-
@other_attributes[:scale], @other_attributes[:basemap_url])
43+
scale, basemap_url)
3844
end
3945

4046
context = {
@@ -178,12 +184,12 @@ def self.map_data(center, features, scale, basemap_url)
178184
type: "geojson"
179185
},
180186
{
181-
baseURL: basemap_url.sub(/\/{z}\/{x}\/{y}.png/,''),
187+
baseURL: basemap_url.nil? ? "https://cyberjapandata.gsi.go.jp/xyz/std" : basemap_url.sub(/\/{z}\/{x}\/{y}.png/,''),
182188
imageExtension: "png",
183189
type: "osm"
184190
}
185191
],
186-
scale: scale,
192+
scale: scale.nil? ? 25000 : scale,
187193
projection: "EPSG:3857",
188194
dpi: 144
189195
}

lib/redmine_gtt_print/mapfish.rb

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def get_capabilities(print_config)
3131
end
3232
end
3333

34-
def print(job, referer, user_agent)
34+
def print(job, referer = nil, user_agent = nil)
3535
if ref = request_print(job.json, job.print_config, job.format, referer, user_agent)
3636
CreateJobResult.new success: true, ref: ref
3737
else
@@ -63,17 +63,22 @@ def get_print(ref)
6363

6464
private
6565

66-
def request_print(json, print_config, format, referer, user_agent)
66+
def request_print(json, print_config, format, referer = nil, user_agent = nil)
6767
str = URI.escape(print_config)
6868
url = "#{@host}/print/#{str}/report.#{format}"
6969
if Rails.env.development?
7070
(File.open(Rails.root.join("tmp/mapfish.json"), "wb") << json).close
7171
end
72-
r = HTTParty.post url, body: json, headers: {
73-
'Content-Type' => 'application/json',
74-
'Referer' => referer,
75-
'User-Agent' => user_agent
72+
headers = {
73+
'Content-Type' => 'application/json'
7674
}
75+
if !referer.nil?
76+
headers['Referer'] = referer
77+
end
78+
if !user_agent.nil?
79+
headers['User-Agent'] = user_agent
80+
end
81+
r = HTTParty.post url, body: json, headers: headers
7782
if r.success?
7883
json = JSON.parse r.body
7984
json['ref']

0 commit comments

Comments
 (0)