Class: SimplerTiles::Map
- Inherits:
-
Object
- Object
- SimplerTiles::Map
- Includes:
- PP
- Defined in:
- lib/simpler_tiles/map.rb,
ext/simpler_tiles/map.c
Overview
The Map object is the root of the style declaration for SimplerTiles. It wraps the methods in Simple Tiles and tracks projection, width, height and contains a list of Layer objects.
Instance Method Summary collapse
-
#ar_layer(&blk) ⇒ Object
A convienence method to use Active Record configuration and add a new layer.
-
#bgcolor ⇒ String
Return a copy of the background color of the map.
-
#bgcolor=(bgcolor) ⇒ nil
Set the background color of the map.
-
#bounds ⇒ Bounds
Return the bounds of this map.
-
#buffer ⇒ Number
Get the Map’s buffer.
-
#buffer=(buffer) ⇒ Number
Set the buffer on the Map.
-
#buffered_bounds ⇒ Bounds
Return the bounds of this map sized according to it’s buffer attribute.
-
#height ⇒ Number
Get the height of the map.
-
#height=(height) ⇒ Number
Set the height of the Map.
-
#initialize {|_self| ... } ⇒ Map
constructor
A new instance of Map.
-
#layer(source, &blk) ⇒ Object
Add a layer to the c list of layers and yield the new layer.
-
#raster_layer(source, &blk) ⇒ Object
Add a raster layer.
-
#save(path) ⇒ Boolean
Render the Map to the filesystem.
-
#set_bounds(maxx, maxy, minx, miny) ⇒ nil
Set the bounds on the map.
-
#set_size(width, height) ⇒ nil
Set the size in pixels of the final map.
-
#slippy(x, y, z) ⇒ nil
Set the map to be slippy via passed in parameters.
-
#srs ⇒ String
Return the projection for the map in string representation.
-
#srs=(srs) ⇒ String
Set the projection from an Proj.4 readable string.
-
#to_png {|data| ... } ⇒ Object
Render the data to a blob of png data.
-
#valid? ⇒ Boolean
Test to see if the Map has fulfilled the requirements for rendering.
-
#width ⇒ Number
Get the width of the map.
-
#width=(width) ⇒ Number
Set the width of the Map.
Methods included from PP
Constructor Details
#initialize {|_self| ... } ⇒ Map
Returns a new instance of Map.
8 9 10 |
# File 'lib/simpler_tiles/map.rb', line 8 def initialize yield self if block_given? end |
Instance Method Details
#ar_layer(&blk) ⇒ Object
A convienence method to use Active Record configuration and add a new layer.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/simpler_tiles/map.rb', line 26 def ar_layer(&blk) if !defined?(ActiveRecord) raise "ActiveRecord not available" end config = ActiveRecord::Base.connection.instance_variable_get("@config") params = { :dbname => config[:database], :user => config[:username], :host => config[:host], :port => config[:port], :password => config[:password] } conn = "PG:" + params.reject {|k,v| v.nil? }.map {|k,v| "#{k}=#{v}"}.join(' ') layer conn, &blk end |
#bgcolor ⇒ String
Return a copy of the background color of the map.
38 39 40 41 42 43 44 |
# File 'ext/simpler_tiles/map.c', line 38 static VALUE get_bgcolor(VALUE self){ simplet_map_t *map = get_map(self); char *color; simplet_map_get_bgcolor(map, &color); return rb_str_new2(color); } |
#bgcolor=(bgcolor) ⇒ nil
Set the background color of the map.
25 26 27 28 29 30 31 |
# File 'ext/simpler_tiles/map.c', line 25
static VALUE
set_bgcolor(VALUE self, VALUE bgcolor){
Check_Type(bgcolor, T_STRING);
simplet_map_t *map = get_map(self);
simplet_map_set_bgcolor(map, RSTRING_PTR(bgcolor));
return Qnil;
}
|
#bounds ⇒ Bounds
Return the bounds of this map.
101 102 103 104 105 |
# File 'ext/simpler_tiles/map.c', line 101
static VALUE
bounds(VALUE self){
simplet_map_t *map = get_map(self);
return new_bounds(map->bounds);
}
|
#buffer ⇒ Number
Get the Map’s buffer.
160 161 162 163 164 |
# File 'ext/simpler_tiles/map.c', line 160 static VALUE get_buffer(VALUE self){ simplet_map_t *map = get_map(self); return rb_float_new(simplet_map_get_buffer(map)); } |
#buffer=(buffer) ⇒ Number
Set the buffer on the Map.
148 149 150 151 152 153 |
# File 'ext/simpler_tiles/map.c', line 148
static VALUE
set_buffer(VALUE self, VALUE buffer){
simplet_map_t *map = get_map(self);
simplet_map_set_buffer(map, NUM2DBL(buffer));
return rb_float_new(map->buffer);
}
|
#buffered_bounds ⇒ Bounds
Return the bounds of this map sized according to it’s buffer attribute.
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'ext/simpler_tiles/map.c', line 111
static VALUE
buffered_bounds(VALUE self){
simplet_map_t *map = get_map(self);
cairo_matrix_t mat;
simplet_map_init_matrix(map, &mat);
cairo_matrix_invert(&mat);
double dx, dy;
dx = dy = simplet_map_get_buffer(map);
cairo_matrix_transform_distance(&mat, &dx, &dy);
simplet_bounds_t *bbounds = simplet_bounds_buffer(map->bounds, dx);
if(!bbounds)
rb_raise(rb_eRuntimeError, "Could not allocate space for a new SimplerTiles::Bounds in memory.");
return new_bounds(bbounds);
}
|
#height ⇒ Number
Get the height of the map.
183 184 185 186 187 |
# File 'ext/simpler_tiles/map.c', line 183 static VALUE get_height(VALUE self){ simplet_map_t *map = get_map(self); return INT2NUM(simplet_map_get_height(map)); } |
#height=(height) ⇒ Number
Set the height of the Map.
206 207 208 209 210 211 |
# File 'ext/simpler_tiles/map.c', line 206
static VALUE
set_height(VALUE self, VALUE height){
simplet_map_t *map = get_map(self);
simplet_map_set_height(map, NUM2INT(height));
return get_height(self);
}
|
#layer(source, &blk) ⇒ Object
Add a layer to the c list of layers and yield the new layer.
13 14 15 16 |
# File 'lib/simpler_tiles/map.rb', line 13 def layer(source, &blk) layer = SimplerTiles::VectorLayer.new(source, &blk) add_vector_layer layer end |
#raster_layer(source, &blk) ⇒ Object
Add a raster layer
19 20 21 22 |
# File 'lib/simpler_tiles/map.rb', line 19 def raster_layer(source, &blk) layer = SimplerTiles::RasterLayer.new(source, &blk) add_raster_layer layer end |
#save(path) ⇒ Boolean
Render the Map to the filesystem.
271 272 273 274 275 276 277 278 279 280 281 282 283 |
# File 'ext/simpler_tiles/map.c', line 271
static VALUE
save(VALUE self, VALUE path){
Check_Type(path, T_STRING);
if(!is_valid(self)) return Qfalse;
simplet_map_t *map = get_map(self);
simplet_map_render_to_png(map, RSTRING_PTR(path));
if(simplet_map_get_status(map) == SIMPLET_OK) {
return Qtrue;
} else {
rb_raise(rb_eRuntimeError, "%s", simplet_map_status_to_string(map));
return Qfalse;
}
}
|
#set_bounds(maxx, maxy, minx, miny) ⇒ nil
Set the bounds on the map.
79 80 81 82 83 84 |
# File 'ext/simpler_tiles/map.c', line 79
static VALUE
set_bounds(VALUE self, VALUE maxx, VALUE maxy, VALUE minx, VALUE miny){
simplet_map_t *map = get_map(self);
simplet_map_set_bounds(map, NUM2DBL(maxx), NUM2DBL(maxy), NUM2DBL(minx), NUM2DBL(miny));
return Qnil;
}
|
#set_size(width, height) ⇒ nil
Set the size in pixels of the final map.
135 136 137 138 139 140 |
# File 'ext/simpler_tiles/map.c', line 135
static VALUE
set_size(VALUE self, VALUE width, VALUE height){
simplet_map_t *map = get_map(self);
simplet_map_set_size(map, NUM2INT(width), NUM2INT(height));
return Qnil;
}
|
#slippy(x, y, z) ⇒ nil
Set the map to be slippy via passed in parameters.
317 318 319 320 321 322 323 |
# File 'ext/simpler_tiles/map.c', line 317
static VALUE
slippy(VALUE self, VALUE x, VALUE y, VALUE z){
simplet_map_t *map = get_map(self);
if(simplet_map_set_slippy(map, NUM2INT(x), NUM2INT(y), NUM2INT(z)) != SIMPLET_OK)
rb_raise(rb_eRuntimeError, "%s", simplet_map_status_to_string(map));
return Qnil;
}
|
#srs ⇒ String
Return the projection for the map in string representation.
65 66 67 68 69 70 71 |
# File 'ext/simpler_tiles/map.c', line 65 static VALUE get_srs(VALUE self){ simplet_map_t *map = get_map(self); char *srs; simplet_map_get_srs(map, &srs); return rb_str_new2(srs); } |
#srs=(srs) ⇒ String
Set the projection from an Proj.4 readable string.
52 53 54 55 56 57 58 |
# File 'ext/simpler_tiles/map.c', line 52
static VALUE
set_srs(VALUE self, VALUE srs){
Check_Type(srs, T_STRING);
simplet_map_t *map = get_map(self);
simplet_map_set_srs(map, RSTRING_PTR(srs));
return Qnil;
}
|
#to_png {|data| ... } ⇒ Object
Render the data to a blob of png data.
46 47 48 49 50 51 |
# File 'lib/simpler_tiles/map.rb', line 46 def to_png data = "" to_png_stream Proc.new { |chunk| data += chunk } yield data if block_given? data end |
#valid? ⇒ Boolean
Test to see if the Map has fulfilled the requirements for rendering
257 258 259 260 261 262 263 |
# File 'ext/simpler_tiles/map.c', line 257
static VALUE
is_valid(VALUE self){
simplet_map_t *map = get_map(self);
if(!simplet_map_is_valid(map))
return Qfalse;
return Qtrue;
}
|
#width ⇒ Number
Get the width of the map.
172 173 174 175 176 |
# File 'ext/simpler_tiles/map.c', line 172 static VALUE get_width(VALUE self){ simplet_map_t *map = get_map(self); return INT2NUM(simplet_map_get_width(map)); } |
#width=(width) ⇒ Number
Set the width of the Map.
194 195 196 197 198 199 |
# File 'ext/simpler_tiles/map.c', line 194
static VALUE
set_width(VALUE self, VALUE width){
simplet_map_t *map = get_map(self);
simplet_map_set_width(map, NUM2INT(width));
return get_width(self);
}
|