Class: MapPrint::Core
- Inherits:
-
Object
- Object
- MapPrint::Core
- Defined in:
- lib/map_print/core.rb
Constant Summary collapse
- PROVIDERS =
{ 'bing' => MapPrint::Providers::Bing, 'osm' => MapPrint::Providers::OpenStreetMap }
Instance Attribute Summary collapse
-
#images ⇒ Object
Returns the value of attribute images.
-
#legend ⇒ Object
Returns the value of attribute legend.
-
#map ⇒ Object
Returns the value of attribute map.
-
#output_path ⇒ Object
Returns the value of attribute output_path.
-
#pdf_options ⇒ Object
Returns the value of attribute pdf_options.
-
#png_options ⇒ Object
Returns the value of attribute png_options.
-
#scalebar ⇒ Object
Returns the value of attribute scalebar.
-
#texts ⇒ Object
Returns the value of attribute texts.
Instance Method Summary collapse
-
#initialize(args) ⇒ Core
constructor
A new instance of Core.
- #print(output_path) ⇒ Object
- #print_geojson(map_image) ⇒ Object
- #print_layers ⇒ Object
- #print_legend ⇒ Object
- #print_scalebar ⇒ Object
Constructor Details
#initialize(args) ⇒ Core
Returns a new instance of Core.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/map_print/core.rb', line 24 def initialize(args) @format = args[:format] = args[:pdf_options] = args[:png_options] @map = args[:map] @images = args[:images] @texts = args[:texts] @legend = args[:legend] = args[:scalebar] raise ParameterError.new("Please indicate the southwest point for the map ({map: {sw: {lat: -35.026862, lng: -58.425003}}})") unless @map && @map[:sw] && @map[:sw][:lat] && @map[:sw][:lng] raise ParameterError.new("Please indicate the northeast point for the map ({map: {ne: {lat: -29.980172, lng: -52.959305}}})") unless @map[:ne] && @map[:ne][:lat] && @map[:ne][:lng] raise ParameterError.new("Please indicate the zoom level for the map ({map: {zoom: 9})") unless @map[:zoom] raise ParameterError.new("Please indicate layers to be printed for the map ({map: {layers: [{type: 'osm'}]})") unless @map[:layers].is_a?(Array) Logger.warn 'Found geojson property defined outside map, it must be inside the map property' if @map[:geojson].nil? && args[:geojson] end |
Instance Attribute Details
#images ⇒ Object
Returns the value of attribute images.
17 18 19 |
# File 'lib/map_print/core.rb', line 17 def images @images end |
#legend ⇒ Object
Returns the value of attribute legend.
17 18 19 |
# File 'lib/map_print/core.rb', line 17 def legend @legend end |
#map ⇒ Object
Returns the value of attribute map.
17 18 19 |
# File 'lib/map_print/core.rb', line 17 def map @map end |
#output_path ⇒ Object
Returns the value of attribute output_path.
17 18 19 |
# File 'lib/map_print/core.rb', line 17 def output_path @output_path end |
#pdf_options ⇒ Object
Returns the value of attribute pdf_options.
17 18 19 |
# File 'lib/map_print/core.rb', line 17 def end |
#png_options ⇒ Object
Returns the value of attribute png_options.
17 18 19 |
# File 'lib/map_print/core.rb', line 17 def end |
#scalebar ⇒ Object
Returns the value of attribute scalebar.
17 18 19 |
# File 'lib/map_print/core.rb', line 17 def end |
#texts ⇒ Object
Returns the value of attribute texts.
17 18 19 |
# File 'lib/map_print/core.rb', line 17 def texts @texts end |
Instance Method Details
#print(output_path) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/map_print/core.rb', line 40 def print(output_path) @output_path = output_path if @format == 'pdf' handler = PdfHandler.new(self) else Logger.warn 'Did not specify format, defaulting to png' handler = PngHandler.new(self) end handler.print @output_path end |
#print_geojson(map_image) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/map_print/core.rb', line 58 def print_geojson(map_image) if @map[:geojson] geojson_image = GeoJSONHandler.new(@map[:geojson], @map[:sw], @map[:ne], map_image.width, map_image.height).process result = MiniMagick::Image.open(map_image.path).composite(geojson_image) do |c| c.density 300 c.compose "atop" end result.write map_image.path end map_image end |
#print_layers ⇒ Object
54 55 56 |
# File 'lib/map_print/core.rb', line 54 def print_layers LayerHandler.new(@map[:layers], @map[:sw], @map[:ne], @map[:zoom]).process end |
#print_legend ⇒ Object
77 78 79 80 81 |
# File 'lib/map_print/core.rb', line 77 def print_legend if @legend LegendHandler.new(@legend).process end end |
#print_scalebar ⇒ Object
71 72 73 74 75 |
# File 'lib/map_print/core.rb', line 71 def if .new(, @map[:zoom]).process end end |