Class: MapPrint::GeoJSONHandler
- Inherits:
-
Object
- Object
- MapPrint::GeoJSONHandler
- Defined in:
- lib/map_print/geo_json_handler.rb
Instance Method Summary collapse
-
#initialize(geojson, sw, ne, width, height) ⇒ GeoJSONHandler
constructor
A new instance of GeoJSONHandler.
- #process ⇒ Object
Constructor Details
#initialize(geojson, sw, ne, width, height) ⇒ GeoJSONHandler
Returns a new instance of GeoJSONHandler.
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/map_print/geo_json_handler.rb', line 5 def initialize(geojson, sw, ne, width, height) @top_lat = ne[:lat] @total_lat = (ne[:lat] - sw[:lat]) @left_lng = sw[:lng] @total_lng = (ne[:lng] - sw[:lng]) @height = height @width = width @geojson = JSON[geojson] rescue JSON::GeneratorError, JSON::ParserError raise InvalidGeoJSON.new("Invalid GeoJSON: #{geojson.inspect}") end |
Instance Method Details
#process ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/map_print/geo_json_handler.rb', line 17 def process tempfile = Tempfile.new ['geojson', '.png'] `convert -density 300 -size #{@width}x#{@height} xc:transparent #{tempfile.path}` @image = MiniMagick::Image.new tempfile.path draw_geojson @image.write(tempfile.path) MiniMagick::Image.open(tempfile.path) ensure tempfile.close end |