class MapPrint::Core
Constants
- PROVIDERS
Attributes
images[RW]
legend[RW]
map[RW]
output_path[RW]
pdf_options[RW]
png_options[RW]
scalebar[RW]
texts[RW]
Public Class Methods
new(args)
click to toggle source
# File lib/map_print/core.rb, line 24 def initialize(args) @format = args[:format] @pdf_options = args[:pdf_options] @png_options = args[:png_options] @map = args[:map] @images = args[:images] @texts = args[:texts] @legend = args[:legend] @scalebar = 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
Public Instance Methods
print(output_path)
click to toggle source
# 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)
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# File lib/map_print/core.rb, line 77 def print_legend if @legend LegendHandler.new(@legend).process end end
print_scalebar()
click to toggle source
# File lib/map_print/core.rb, line 71 def print_scalebar if @scalebar ScalebarHandler.new(@scalebar, @map[:zoom]).process end end