Class: SimpleMapnik::Map

Inherits:
Object
  • Object
show all
Includes:
FFI
Defined in:
lib/simple_mapnik/map.rb

Constant Summary

Constants included from FFI

FFI::MAPNIK_FUNCTIONS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from FFI

attach_functions, find_lib, mapnik_c_api_path

Constructor Details

#initialize(width, height) ⇒ Map

Returns a new instance of Map.



7
8
9
10
11
12
13
# File 'lib/simple_mapnik/map.rb', line 7

def initialize(width, height)
  @width = width
  @height = height
  ptr = mapnik_map width, height
  @ptr = ::FFI::AutoPointer.new ptr, self.class.method(:release)
  @ptr.autorelease = false
end

Instance Attribute Details

#heightObject

Returns the value of attribute height.



5
6
7
# File 'lib/simple_mapnik/map.rb', line 5

def height
  @height
end

#ptrObject

Returns the value of attribute ptr.



5
6
7
# File 'lib/simple_mapnik/map.rb', line 5

def ptr
  @ptr
end

#widthObject

Returns the value of attribute width.



5
6
7
# File 'lib/simple_mapnik/map.rb', line 5

def width
  @width
end

Class Method Details

.releaseObject



15
# File 'lib/simple_mapnik/map.rb', line 15

def self.release; end

Instance Method Details

#freeObject



17
18
19
# File 'lib/simple_mapnik/map.rb', line 17

def free
  mapnik_map_free @ptr
end

#load(style) ⇒ Object



21
22
23
24
# File 'lib/simple_mapnik/map.rb', line 21

def load(style)
  style = File.expand_path style
  mapnik_map_load @ptr, style
end

#load_string(style) ⇒ Object



26
27
28
# File 'lib/simple_mapnik/map.rb', line 26

def load_string(style)
  mapnik_map_load_string @ptr, style
end

#to_file(file) ⇒ Object



46
47
48
49
# File 'lib/simple_mapnik/map.rb', line 46

def to_file(file)
  file = File.expand_path file
  mapnik_map_render_to_file @ptr, file
end

#to_imageObject



38
39
40
# File 'lib/simple_mapnik/map.rb', line 38

def to_image
  mapnik_map_render_to_image @ptr
end

#to_pngObject



42
43
44
# File 'lib/simple_mapnik/map.rb', line 42

def to_png
  mapnik_image_to_png_blob to_image
end

#zoom_allObject



30
31
32
# File 'lib/simple_mapnik/map.rb', line 30

def zoom_all
  mapnik_map_zoom_all @ptr
end

#zoom_to(bounds) ⇒ Object



34
35
36
# File 'lib/simple_mapnik/map.rb', line 34

def zoom_to(bounds)
  mapnik_map_zoom_to_box @ptr, bounds.ptr
end