natour 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,6 +4,7 @@ require 'fileutils'
4
4
  require 'pathname'
5
5
  require 'uri'
6
6
  require 'webrick'
7
+ require 'webrick/https'
7
8
 
8
9
  module Natour
9
10
  class MapGeoAdmin
@@ -11,21 +12,29 @@ module Natour
11
12
  @doc_root = Pathname(Dir.mktmpdir)
12
13
  FileUtils.cp_r("#{__dir__}/data/js", @doc_root)
13
14
  event = Concurrent::Event.new
14
- @server = WEBrick::HTTPServer.new(
15
- StartCallback: -> { event.set },
16
- Logger: WEBrick::Log.new(File.open(File::NULL, 'w')),
17
- AccessLog: [],
18
- DocumentRoot: @doc_root,
19
- BindAddress: 'localhost',
20
- Port: port
21
- )
15
+ @server = StdoutUtils.suppress_output do
16
+ WEBrick::HTTPServer.new(
17
+ StartCallback: -> { event.set },
18
+ Logger: WEBrick::Log.new(File.open(File::NULL, 'w')),
19
+ AccessLog: [],
20
+ DocumentRoot: @doc_root,
21
+ BindAddress: 'localhost',
22
+ Port: port,
23
+ SSLEnable: true,
24
+ SSLCertName: [%w[CN localhost]]
25
+ )
26
+ end
22
27
  @server.mount('/map', MapServlet)
23
28
  @thread = Thread.new { @server.start }
24
29
  event.wait
25
30
  @browser = Ferrum::Browser.new(
26
31
  slowmo: 2.0,
32
+ timout: 30,
27
33
  window_size: [5000, 5000],
28
- browser_options: { 'no-sandbox': nil }
34
+ browser_options: {
35
+ 'no-sandbox': nil,
36
+ 'ignore-certificate-errors': nil
37
+ }
29
38
  )
30
39
  end
31
40
 
@@ -36,11 +45,12 @@ module Natour
36
45
  FileUtils.remove_entry(@doc_root)
37
46
  end
38
47
 
39
- def save_image(filename, overwrite: false, gps_files: [], map_layers: [], image_size: [1200, 900])
48
+ def save_image(filename, overwrite: false, gps_files: [], gps_colors: [], map_layers: [], image_size: [1200, 900])
40
49
  FileUtils.cp(gps_files, @doc_root)
41
- uri = URI("http://#{@server[:BindAddress]}:#{@server[:Port]}/map")
50
+ uri = URI("https://#{@server[:BindAddress]}:#{@server[:Port]}/map")
42
51
  uri.query = URI.encode_www_form(
43
52
  'gps-files': gps_files.map { |gps_file| Pathname(gps_file).basename }.join(','),
53
+ 'gps-colors': gps_colors.join(','),
44
54
  'map-layers': map_layers.join(','),
45
55
  'map-size': image_size.map { |dim| dim.is_a?(String) ? dim : "#{dim}px" }.join(',')
46
56
  )
@@ -73,8 +83,10 @@ module Natour
73
83
  raise WEBrick::HTTPStatus::NotFound unless request.path == '/map'
74
84
 
75
85
  files = request.query.fetch('gps-files', '').split(',')
76
- layers = request.query.fetch('map-layers', '').split(',')
77
- layers.unshift('ch.swisstopo.pixelkarte-farbe')
86
+ colors = request.query.fetch('gps-colors', '').split(',')
87
+ (files.size - colors.size).times { colors << (colors.last || 'blueviolet') }
88
+ layers = ['ch.swisstopo.pixelkarte-farbe']
89
+ layers |= request.query.fetch('map-layers', '').split(',')
78
90
 
79
91
  width, height = request.query.fetch('map-size', '').split(',')
80
92
  raise WEBrick::HTTPStatus::BadRequest unless width && height
@@ -87,54 +99,57 @@ module Natour
87
99
  doc << '<script src="js/loader.js"></script>'
88
100
  doc << '<script type="text/javascript">'
89
101
  doc << ' $(function() {'
90
- doc << ' var map = new ga.Map({'
102
+ doc << ' let map = new ga.Map({'
91
103
  doc << ' controls: [],'
92
104
  doc << ' target: "map",'
93
105
  doc << ' view: new ol.View()'
94
106
  doc << ' })'
95
- doc << " var layers = [#{layers.map { |layer| "\"#{layer}\"" }.join(', ')}]"
107
+ doc << " let layers = [#{layers.map { |layer| "\"#{layer}\"" }.join(', ')}]"
96
108
  doc << ' layers.forEach(function(layer) {'
97
109
  doc << ' map.addLayer(ga.layer.create(layer))'
98
110
  doc << ' })'
99
- doc << ' var styles = {'
100
- doc << ' "Point": new ol.style.Style({'
101
- doc << ' image: new ol.style.Circle({'
102
- doc << ' fill: new ol.style.Fill({'
103
- doc << ' color: function() {'
104
- doc << ' var color = "blueviolet"'
105
- doc << ' var alpha = 0.3'
106
- doc << ' var [r, g, b] = ol.color.asArray(color)'
107
- doc << ' return ol.color.asString([r, g, b, alpha])'
108
- doc << ' }()'
109
- doc << ' }),'
110
- doc << ' radius: 6,'
111
+ doc << ' let getStyles = function(color) {'
112
+ doc << ' return {'
113
+ doc << ' "Point": new ol.style.Style({'
114
+ doc << ' image: new ol.style.Circle({'
115
+ doc << ' fill: new ol.style.Fill({'
116
+ doc << ' color: function() {'
117
+ doc << ' let [r, g, b, a] = ol.color.asArray(color)'
118
+ doc << ' a = 0.3'
119
+ doc << ' return ol.color.asString([r, g, b, a])'
120
+ doc << ' }()'
121
+ doc << ' }),'
122
+ doc << ' radius: 6,'
123
+ doc << ' stroke: new ol.style.Stroke({'
124
+ doc << ' color: color,'
125
+ doc << ' width: 1.5'
126
+ doc << ' })'
127
+ doc << ' })'
128
+ doc << ' }),'
129
+ doc << ' "LineString": new ol.style.Style({'
111
130
  doc << ' stroke: new ol.style.Stroke({'
112
- doc << ' color: "blueviolet",'
113
- doc << ' width: 1.5'
131
+ doc << ' color: color,'
132
+ doc << ' width: 3'
133
+ doc << ' })'
134
+ doc << ' }),'
135
+ doc << ' "MultiLineString": new ol.style.Style({'
136
+ doc << ' stroke: new ol.style.Stroke({'
137
+ doc << ' color: color,'
138
+ doc << ' width: 3'
114
139
  doc << ' })'
115
140
  doc << ' })'
116
- doc << ' }),'
117
- doc << ' "LineString": new ol.style.Style({'
118
- doc << ' stroke: new ol.style.Stroke({'
119
- doc << ' color: "blueviolet",'
120
- doc << ' width: 3'
121
- doc << ' })'
122
- doc << ' }),'
123
- doc << ' "MultiLineString": new ol.style.Style({'
124
- doc << ' stroke: new ol.style.Stroke({'
125
- doc << ' color: "blueviolet",'
126
- doc << ' width: 3'
127
- doc << ' })'
128
- doc << ' })'
141
+ doc << ' }'
129
142
  doc << ' }'
130
- doc << " var files = [#{files.map { |file| "\"#{file}\"" }.join(', ')}]"
131
- doc << ' var vectors = files.map(function(file) {'
143
+ doc << " let sources = [#{files.zip(colors)
144
+ .map { |file, color| "{ file: \"#{file}\", color: \"#{color}\" }" }
145
+ .join(', ')}]"
146
+ doc << ' let vectors = sources.map(function(source) {'
132
147
  doc << ' return new ol.layer.Vector({'
133
148
  doc << ' source: new ol.source.Vector({'
134
149
  doc << ' format: function() {'
135
- doc << ' if (file.endsWith(".gpx")) {'
150
+ doc << ' if (source.file.endsWith(".gpx")) {'
136
151
  doc << ' return new ol.format.GPX()'
137
- doc << ' } else if (file.endsWith(".kml")) {'
152
+ doc << ' } else if (source.file.endsWith(".kml")) {'
138
153
  doc << ' return new ol.format.KML({'
139
154
  doc << ' extractStyles: false'
140
155
  doc << ' })'
@@ -142,17 +157,17 @@ module Natour
142
157
  doc << ' return null'
143
158
  doc << ' }'
144
159
  doc << ' }(),'
145
- doc << ' url: file'
160
+ doc << ' url: source.file'
146
161
  doc << ' }),'
147
162
  doc << ' style: function(feature) {'
148
- doc << ' return styles[feature.getGeometry().getType()]'
163
+ doc << ' return getStyles(source.color)[feature.getGeometry().getType()]'
149
164
  doc << ' }'
150
165
  doc << ' })'
151
166
  doc << ' })'
152
167
  doc << ' vectors.forEach(function(vector) {'
153
168
  doc << ' map.addLayer(vector)'
154
169
  doc << ' vector.getSource().on("change", function(evt) {'
155
- doc << ' var extent = ol.extent.createEmpty()'
170
+ doc << ' let extent = ol.extent.createEmpty()'
156
171
  doc << ' vectors.forEach(function(vector) {'
157
172
  doc << ' ol.extent.extend(extent, vector.getSource().getExtent())'
158
173
  doc << ' })'
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Natour
4
- VERSION = '0.8.0'
4
+ VERSION = '0.9.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: natour
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Gysi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-22 00:00:00.000000000 Z
11
+ date: 2022-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor