Class: SimpleMappr
- Inherits:
-
Object
- Object
- SimpleMappr
- Defined in:
- lib/simple-mappr.rb,
lib/simple-mappr/version.rb,
lib/simple-mappr/constants.rb,
lib/simple-mappr/validator.rb,
lib/simple-mappr/exceptions.rb,
lib/simple-mappr/transporter.rb
Defined Under Namespace
Classes: InvalidParameterValue, Transporter, Validator
Constant Summary collapse
- VERSION =
"0.1.2"- API_URL =
"http://www.simplemappr.net/api/"- PROJECTIONS =
[ 'epsg:4326', 'esri:102009', 'esri:102015', 'esri:102014', 'esri:102012', 'esri:102024', 'epsg:3112', 'epsg:102017', 'epsg:102019', 'epsg:54030' ]
- SHAPES =
[ 'plus', 'cross', 'asterisk', 'circle', 'square', 'triangle', 'inversetriangle', 'star', 'hexagon', 'opencircle', 'opensquare', 'opentriangle', 'inverseopentriangle', 'openstar', 'openhexagon' ]
- LAYERS =
[ 'countries', 'countrynames', 'relief', 'reliefalt', 'reliefgrey', 'stateprovinces', 'stateprovnames', 'lakes', 'lakesOutline', 'lakenames', 'rivers', 'rivernames', 'oceans', 'marineLabels', 'placenames', 'physicalLabels', 'ecoregions', 'ecoregionLabels', 'conservation', 'hotspotLabels', 'blueMarble' ]
- OUTPUTS =
['svg', 'png', 'jpg']
Class Method Summary collapse
- .api_url ⇒ Object
- .layers ⇒ Object
- .outputs ⇒ Object
- .projections ⇒ Object
- .shapes ⇒ Object
- .version ⇒ Object
Instance Method Summary collapse
-
#alive? ⇒ Boolean
Check if the RESTful API is alive and well.
- #bbox ⇒ Object
-
#bbox=(bbox) ⇒ Object
Set a bounding box in decimal degrees as minx,miny,maxx,maxy.
- #color ⇒ Object
-
#color=(color) ⇒ Object
Set the colors in rgb corresponding to the points.
-
#create ⇒ Object
Send the SimpleMappr object to the RESTful API and receive a Hash in return containing a URL to the image and its expected expiry.
-
#download(file_title = nil) ⇒ Object
Send the SimpleMappr object to the RESTful API and a file title without extension and download the resulting image Returns the file path for the downloaded file.
- #file_path ⇒ Object
-
#file_path=(file_path) ⇒ Object
Set a file path for a csv or tab-separated text file.
- #graticules ⇒ Object
-
#graticules=(graticules) ⇒ Object
Turn on or off the graticules (grid).
- #height ⇒ Object
-
#height=(height) ⇒ Object
Specify the height of the image in pixels Maximum value is 4500.
-
#initialize ⇒ SimpleMappr
constructor
A new instance of SimpleMappr.
- #layers ⇒ Object
-
#layers=(layers) ⇒ Object
Specify the layers to include in the image Expressed as a comma-separated String without spaces See SimpleMappr.layers.
- #legend ⇒ Object
-
#legend=(legend) ⇒ Object
Specify the legend title(s) Expressed as an array of Strings corresponding to the points.
- #origin ⇒ Object
-
#origin=(origin) ⇒ Object
Specify the origin of natural longitude.
- #outlinecolor ⇒ Object
-
#outlinecolor=(outlinecolor) ⇒ Object
Specify the color in rgb for the outline around all points.
- #output ⇒ Object
-
#output=(output) ⇒ Object
Specify the output file format Options are svg, png, or jpg.
-
#params ⇒ Object
View the built parameters.
- #points ⇒ Object
-
#points=(points) ⇒ Object
An array of geographic coordinates, each as latitude,longitude Group coordinates in array elements, each of which can also be separated by linebreaks, n.
- #projection ⇒ Object
-
#projection=(projection) ⇒ Object
Specify the projection See simple-mappr/constants.rb.
- #scalebar ⇒ Object
-
#scalebar=(scalebar) ⇒ Object
Include an embedded scalebar.
- #shade ⇒ Object
-
#shade=(shade) ⇒ Object
Include shaded regions as a Hash Specify color, title, and places as keys.
- #shape ⇒ Object
-
#shape=(shape) ⇒ Object
Describe the shape to use corresponding to the points See simple-mappr/constants.rb.
- #size ⇒ Object
-
#size=(size) ⇒ Object
Specify the size of the corresponding points Options are Integer less than or equal to 14.
- #spacing ⇒ Object
-
#spacing=(spacing) ⇒ Object
Specify the spacing between graticule (grid) lines in degrees Must be an Integer less than or equal to 10.
- #url ⇒ Object
-
#url=(url) ⇒ Object
Specify a remote URL Source must be a csv, a tab-delimited file, or a GeoRSS.
- #width ⇒ Object
-
#width=(width) ⇒ Object
Specify the width of the output in pixels Must be less than or eqaual to 4500.
- #wkt ⇒ Object
-
#wkt=(wkt) ⇒ Object
Include wkt regions as an Array of Hashes Specify color, title, and data as keys for each element.
- #zoom ⇒ Object
-
#zoom=(zoom) ⇒ Object
Specify a zoom level, centred on the geographic center of all points Must be less than or eqaual to 10.
Constructor Details
#initialize ⇒ SimpleMappr
Returns a new instance of SimpleMappr.
9 10 11 |
# File 'lib/simple-mappr.rb', line 9 def initialize @parameters = {} end |
Class Method Details
.api_url ⇒ Object
62 63 64 |
# File 'lib/simple-mappr/constants.rb', line 62 def self.api_url API_URL end |
.layers ⇒ Object
74 75 76 |
# File 'lib/simple-mappr/constants.rb', line 74 def self.layers LAYERS end |
.outputs ⇒ Object
78 79 80 |
# File 'lib/simple-mappr/constants.rb', line 78 def self.outputs OUTPUTS end |
.projections ⇒ Object
70 71 72 |
# File 'lib/simple-mappr/constants.rb', line 70 def self.projections PROJECTIONS end |
.shapes ⇒ Object
66 67 68 |
# File 'lib/simple-mappr/constants.rb', line 66 def self.shapes SHAPES end |
.version ⇒ Object
4 5 6 |
# File 'lib/simple-mappr/version.rb', line 4 def self.version VERSION end |
Instance Method Details
#alive? ⇒ Boolean
Check if the RESTful API is alive and well
23 24 25 26 |
# File 'lib/simple-mappr.rb', line 23 def alive? response = Transporter.ping response[:status] == "ok" end |
#bbox ⇒ Object
80 81 82 |
# File 'lib/simple-mappr.rb', line 80 def bbox @parameters[:bbox] || nil end |
#bbox=(bbox) ⇒ Object
Set a bounding box in decimal degrees as minx,miny,maxx,maxy
Example
instance.bbox = "-120,45,-100,52"
75 76 77 78 |
# File 'lib/simple-mappr.rb', line 75 def bbox=(bbox) Validator.validate_bbox(bbox) @parameters[:bbox] = bbox end |
#color ⇒ Object
96 97 98 |
# File 'lib/simple-mappr.rb', line 96 def color @parameters[:color] || nil end |
#color=(color) ⇒ Object
Set the colors in rgb corresponding to the points
Example
instance.color = ["255,0,0","0,255,0"]
91 92 93 94 |
# File 'lib/simple-mappr.rb', line 91 def color=(color) Validator.validate_colors(color) @parameters[:color] = color end |
#create ⇒ Object
Send the SimpleMappr object to the RESTful API and receive a Hash in return containing a URL to the image and its expected expiry
Example Output
{
imageURL: "http://img.simplemappr.net/579273e6_1dd1_2.png",
expiry: "2016-07-22T21:28:38-04:00",
bad_points: [],
bad_drawings: []
}
42 43 44 |
# File 'lib/simple-mappr.rb', line 42 def create Transporter.send_data @parameters end |
#download(file_title = nil) ⇒ Object
Send the SimpleMappr object to the RESTful API and a file title without extension and download the resulting image Returns the file path for the downloaded file
Example
instance.download("/tmp/my_map")
Returns
/tmp/my_map.png
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/simple-mappr.rb', line 57 def download(file_title = nil) if !file_title raise InvalidParameterValue, "File path is required" end file = [file_title,output].join(".") File.open(file, 'wb') do |fo| fo.write(Transporter.send_data(@parameters, true)) end file end |
#file_path ⇒ Object
112 113 114 |
# File 'lib/simple-mappr.rb', line 112 def file_path @parameters[:file].path rescue nil end |
#file_path=(file_path) ⇒ Object
Set a file path for a csv or tab-separated text file
Example
instance.file_path = "/Users/SimpleMappr/demo.txt"
107 108 109 110 |
# File 'lib/simple-mappr.rb', line 107 def file_path=(file_path) Validator.validate_type(file_path, 'File') @parameters[:file] = File.new(file_path, "r") end |
#graticules ⇒ Object
128 129 130 |
# File 'lib/simple-mappr.rb', line 128 def graticules @parameters[:graticules] || nil end |
#graticules=(graticules) ⇒ Object
Turn on or off the graticules (grid)
Example
instance.graticules = true
123 124 125 126 |
# File 'lib/simple-mappr.rb', line 123 def graticules=(graticules) Validator.validate_type(graticules, 'Boolean') @parameters[:graticules] = graticules end |
#height ⇒ Object
145 146 147 |
# File 'lib/simple-mappr.rb', line 145 def height @parameters[:height] || nil end |
#height=(height) ⇒ Object
Specify the height of the image in pixels Maximum value is 4500
Example
instance.height = 1_000
140 141 142 143 |
# File 'lib/simple-mappr.rb', line 140 def height=(height) Validator.validate_dimension(height) @parameters[:height] = height end |
#layers ⇒ Object
163 164 165 |
# File 'lib/simple-mappr.rb', line 163 def layers @parameters[:layers] || nil end |
#layers=(layers) ⇒ Object
Specify the layers to include in the image Expressed as a comma-separated String without spaces See SimpleMappr.layers
Example
instance.layers = 'oceans,lakes,rivers'
158 159 160 161 |
# File 'lib/simple-mappr.rb', line 158 def layers=(layers) Validator.validate_layers(layers) @parameters[:layers] = layers end |
#legend ⇒ Object
180 181 182 |
# File 'lib/simple-mappr.rb', line 180 def legend @parameters[:legend] || nil end |
#legend=(legend) ⇒ Object
Specify the legend title(s) Expressed as an array of Strings corresponding to the points
Example
instance.legend = ['My First Legend','My Second Legend']
175 176 177 178 |
# File 'lib/simple-mappr.rb', line 175 def legend=(legend) Validator.validate_type(legend, 'Array') @parameters[:legend] = legend end |
#origin ⇒ Object
196 197 198 |
# File 'lib/simple-mappr.rb', line 196 def origin @parameters[:origin] || nil end |
#origin=(origin) ⇒ Object
Specify the origin of natural longitude
Example
instance.origin = -100
191 192 193 194 |
# File 'lib/simple-mappr.rb', line 191 def origin=(origin) Validator.validate_origin(origin) @parameters[:origin] = origin end |
#outlinecolor ⇒ Object
212 213 214 |
# File 'lib/simple-mappr.rb', line 212 def outlinecolor @parameters[:outlinecolor] || nil end |
#outlinecolor=(outlinecolor) ⇒ Object
Specify the color in rgb for the outline around all points
Example
instance.outlinecolor = "10,10,10"
207 208 209 210 |
# File 'lib/simple-mappr.rb', line 207 def outlinecolor=(outlinecolor) Validator.validate_color(outlinecolor) @parameters[:outlinecolor] = outlinecolor end |
#output ⇒ Object
229 230 231 |
# File 'lib/simple-mappr.rb', line 229 def output @parameters[:output] || "png" end |
#output=(output) ⇒ Object
Specify the output file format Options are svg, png, or jpg
Example
instance.output = "png"
224 225 226 227 |
# File 'lib/simple-mappr.rb', line 224 def output=(output) Validator.validate_output(output) @parameters[:output] = output end |
#params ⇒ Object
View the built parameters
16 17 18 |
# File 'lib/simple-mappr.rb', line 16 def params @parameters end |
#points ⇒ Object
247 248 249 |
# File 'lib/simple-mappr.rb', line 247 def points @parameters[:points] || nil end |
#points=(points) ⇒ Object
An array of geographic coordinates, each as latitude,longitude Group coordinates in array elements, each of which can also be separated by linebreaks, n
Example
instance.points = ["45,-120\n45.4,-110","52,-120"]
242 243 244 245 |
# File 'lib/simple-mappr.rb', line 242 def points=(points) Validator.validate_points(points) @parameters[:points] = points end |
#projection ⇒ Object
264 265 266 |
# File 'lib/simple-mappr.rb', line 264 def projection @parameters[:projection] || nil end |
#projection=(projection) ⇒ Object
Specify the projection See simple-mappr/constants.rb
Example
instance.projection = "epsg:4326"
259 260 261 262 |
# File 'lib/simple-mappr.rb', line 259 def projection=(projection) Validator.validate_projection(projection) @parameters[:projection] = projection end |
#scalebar ⇒ Object
280 281 282 |
# File 'lib/simple-mappr.rb', line 280 def @parameters[:scalebar] || nil end |
#scalebar=(scalebar) ⇒ Object
Include an embedded scalebar
Example
instance. = true
275 276 277 278 |
# File 'lib/simple-mappr.rb', line 275 def () Validator.validate_type(, 'Boolean') @parameters[:scalebar] = end |
#shade ⇒ Object
297 298 299 |
# File 'lib/simple-mappr.rb', line 297 def shade @parameters[:shade] || nil end |
#shade=(shade) ⇒ Object
Include shaded regions as a Hash Specify color, title, and places as keys
Example
instance.shade = { color: "200,200,200", title: "My Regions", places: "Canada,US[WY|WA]"}
292 293 294 295 |
# File 'lib/simple-mappr.rb', line 292 def shade=(shade) Validator.validate_shade(shade) @parameters[:shade] = shade end |
#shape ⇒ Object
314 315 316 |
# File 'lib/simple-mappr.rb', line 314 def shape @parameters[:shape] || nil end |
#shape=(shape) ⇒ Object
Describe the shape to use corresponding to the points See simple-mappr/constants.rb
Example
instance.shape = ['circle','square']
309 310 311 312 |
# File 'lib/simple-mappr.rb', line 309 def shape=(shape) Validator.validate_shapes(shape) @parameters[:shape] = shape end |
#size ⇒ Object
331 332 333 |
# File 'lib/simple-mappr.rb', line 331 def size @parameters[:size] || nil end |
#size=(size) ⇒ Object
Specify the size of the corresponding points Options are Integer less than or equal to 14
Example
instance.size = [8,14]
326 327 328 329 |
# File 'lib/simple-mappr.rb', line 326 def size=(size) Validator.validate_sizes(size) @parameters[:size] = size end |
#spacing ⇒ Object
348 349 350 |
# File 'lib/simple-mappr.rb', line 348 def spacing @parameters[:spacing] || nil end |
#spacing=(spacing) ⇒ Object
Specify the spacing between graticule (grid) lines in degrees Must be an Integer less than or equal to 10
Example
instance.spacing = 5
343 344 345 346 |
# File 'lib/simple-mappr.rb', line 343 def spacing=(spacing) Validator.validate_spacing(spacing) @parameters[:spacing] = spacing end |
#url ⇒ Object
365 366 367 |
# File 'lib/simple-mappr.rb', line 365 def url @parameters[:url] || nil end |
#url=(url) ⇒ Object
Specify a remote URL Source must be a csv, a tab-delimited file, or a GeoRSS
Example
instance.url = "http://www.simplemappr.net/public/files/demo.csv"
360 361 362 363 |
# File 'lib/simple-mappr.rb', line 360 def url=(url) Validator.validate_url(url) @parameters[:url] = url end |
#width ⇒ Object
382 383 384 |
# File 'lib/simple-mappr.rb', line 382 def width @parameters[:width] || nil end |
#width=(width) ⇒ Object
Specify the width of the output in pixels Must be less than or eqaual to 4500
Example
instance.width = 1_000
377 378 379 380 |
# File 'lib/simple-mappr.rb', line 377 def width=(width) Validator.validate_dimension(width) @parameters[:width] = width end |
#wkt ⇒ Object
399 400 401 |
# File 'lib/simple-mappr.rb', line 399 def wkt @parameters[:wkt] || nil end |
#wkt=(wkt) ⇒ Object
Include wkt regions as an Array of Hashes Specify color, title, and data as keys for each element
Example
instance.wkt = [{ color: "200,200,200", title: "My Regions", data: "POLYGON((-70 63,-70 48,-106 48,-106 63,-70 63))" }]
394 395 396 397 |
# File 'lib/simple-mappr.rb', line 394 def wkt=(wkt) Validator.validate_wkt(wkt) @parameters[:wkt] = wkt end |
#zoom ⇒ Object
416 417 418 |
# File 'lib/simple-mappr.rb', line 416 def zoom @parameters[:zoom] || nil end |
#zoom=(zoom) ⇒ Object
Specify a zoom level, centred on the geographic center of all points Must be less than or eqaual to 10
Example
instance.zoom = 3
411 412 413 414 |
# File 'lib/simple-mappr.rb', line 411 def zoom=(zoom) Validator.validate_zoom(zoom) @parameters[:zoom] = zoom end |