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.2.0"
- API_URL =
"https://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', 'epsg:3395' ]
- SHAPES =
[ 'plus', 'cross', 'asterisk', 'circle', 'square', 'triangle', 'inversetriangle', 'star', 'hexagon', 'opencircle', 'opensquare', 'opentriangle', 'inverseopentriangle', 'openstar', 'openhexagon' ]
- LAYERS =
[ 'countries', 'countrynames', 'relief', 'reliefalt', 'reliefgrey', 'stateprovinces', 'stateprovnames', 'us_counties', '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.
- #hide_gridlabel ⇒ Object
-
#hide_gridlabel=(label) ⇒ Object
Show/hide graticule labels.
-
#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.
- #shadow ⇒ Object
-
#shadow=(shadow) ⇒ Object
Specify if shadow should be drawn under corresponding points Must be boolean.
- #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.
- #watermark ⇒ Object
-
#watermark=(mark) ⇒ Object
Specify if watermark is shown Must be boolean.
- #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, data, and border 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
64 65 66 |
# File 'lib/simple-mappr/constants.rb', line 64 def self.api_url API_URL end |
.layers ⇒ Object
76 77 78 |
# File 'lib/simple-mappr/constants.rb', line 76 def self.layers LAYERS end |
.outputs ⇒ Object
80 81 82 |
# File 'lib/simple-mappr/constants.rb', line 80 def self.outputs OUTPUTS end |
.projections ⇒ Object
72 73 74 |
# File 'lib/simple-mappr/constants.rb', line 72 def self.projections PROJECTIONS end |
.shapes ⇒ Object
68 69 70 |
# File 'lib/simple-mappr/constants.rb', line 68 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
78 79 80 |
# File 'lib/simple-mappr.rb', line 78 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"
73 74 75 76 |
# File 'lib/simple-mappr.rb', line 73 def bbox=(bbox) Validator.validate_bbox(bbox) @parameters[:bbox] = bbox end |
#color ⇒ Object
94 95 96 |
# File 'lib/simple-mappr.rb', line 94 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"]
89 90 91 92 |
# File 'lib/simple-mappr.rb', line 89 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 |
# File 'lib/simple-mappr.rb', line 57 def download(file_title = nil) if !file_title raise InvalidParameterValue, "File path is required" end file_name = [file_title,output].join(".") IO.copy_stream(open(create[:imageURL]), file_name) file_name end |
#file_path ⇒ Object
110 111 112 |
# File 'lib/simple-mappr.rb', line 110 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"
105 106 107 108 |
# File 'lib/simple-mappr.rb', line 105 def file_path=(file_path) Validator.validate_type(file_path, 'File') @parameters[:file] = File.new(file_path, "r") end |
#graticules ⇒ Object
126 127 128 |
# File 'lib/simple-mappr.rb', line 126 def graticules @parameters[:graticules] || nil end |
#graticules=(graticules) ⇒ Object
Turn on or off the graticules (grid)
Example
instance.graticules = true
121 122 123 124 |
# File 'lib/simple-mappr.rb', line 121 def graticules=(graticules) Validator.validate_type(graticules, 'Boolean') @parameters[:graticules] = graticules end |
#height ⇒ Object
143 144 145 |
# File 'lib/simple-mappr.rb', line 143 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
138 139 140 141 |
# File 'lib/simple-mappr.rb', line 138 def height=(height) Validator.validate_dimension(height) @parameters[:height] = height end |
#hide_gridlabel ⇒ Object
159 160 161 |
# File 'lib/simple-mappr.rb', line 159 def hide_gridlabel @parameters[:hide_gridlabel] || nil end |
#hide_gridlabel=(label) ⇒ Object
Show/hide graticule labels
Example
instance.hide_gridlabel = true
154 155 156 157 |
# File 'lib/simple-mappr.rb', line 154 def hide_gridlabel=(label) Validator.validate_type(label, 'Boolean') @parameters[:hide_gridlabel] = label end |
#layers ⇒ Object
177 178 179 |
# File 'lib/simple-mappr.rb', line 177 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'
172 173 174 175 |
# File 'lib/simple-mappr.rb', line 172 def layers=(layers) Validator.validate_layers(layers) @parameters[:layers] = layers end |
#legend ⇒ Object
194 195 196 |
# File 'lib/simple-mappr.rb', line 194 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']
189 190 191 192 |
# File 'lib/simple-mappr.rb', line 189 def legend=(legend) Validator.validate_type(legend, 'Array') @parameters[:legend] = legend end |
#origin ⇒ Object
210 211 212 |
# File 'lib/simple-mappr.rb', line 210 def origin @parameters[:origin] || nil end |
#origin=(origin) ⇒ Object
Specify the origin of natural longitude
Example
instance.origin = -100
205 206 207 208 |
# File 'lib/simple-mappr.rb', line 205 def origin=(origin) Validator.validate_origin(origin) @parameters[:origin] = origin end |
#outlinecolor ⇒ Object
226 227 228 |
# File 'lib/simple-mappr.rb', line 226 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"
221 222 223 224 |
# File 'lib/simple-mappr.rb', line 221 def outlinecolor=(outlinecolor) Validator.validate_color(outlinecolor) @parameters[:outlinecolor] = outlinecolor end |
#output ⇒ Object
243 244 245 |
# File 'lib/simple-mappr.rb', line 243 def output @parameters[:output] || "png" end |
#output=(output) ⇒ Object
Specify the output file format Options are svg, png, or jpg
Example
instance.output = "png"
238 239 240 241 |
# File 'lib/simple-mappr.rb', line 238 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
261 262 263 |
# File 'lib/simple-mappr.rb', line 261 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"]
256 257 258 259 |
# File 'lib/simple-mappr.rb', line 256 def points=(points) Validator.validate_points(points) @parameters[:points] = points end |
#projection ⇒ Object
278 279 280 |
# File 'lib/simple-mappr.rb', line 278 def projection @parameters[:projection] || nil end |
#projection=(projection) ⇒ Object
Specify the projection See simple-mappr/constants.rb
Example
instance.projection = "epsg:4326"
273 274 275 276 |
# File 'lib/simple-mappr.rb', line 273 def projection=(projection) Validator.validate_projection(projection) @parameters[:projection] = projection end |
#scalebar ⇒ Object
294 295 296 |
# File 'lib/simple-mappr.rb', line 294 def @parameters[:scalebar] || nil end |
#scalebar=(scalebar) ⇒ Object
Include an embedded scalebar
Example
instance. = true
289 290 291 292 |
# File 'lib/simple-mappr.rb', line 289 def () Validator.validate_type(, 'Boolean') @parameters[:scalebar] = end |
#shade ⇒ Object
311 312 313 |
# File 'lib/simple-mappr.rb', line 311 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]"}
306 307 308 309 |
# File 'lib/simple-mappr.rb', line 306 def shade=(shade) Validator.validate_shade(shade) @parameters[:shade] = shade end |
#shadow ⇒ Object
362 363 364 |
# File 'lib/simple-mappr.rb', line 362 def shadow @parameters[:shadow] || nil end |
#shadow=(shadow) ⇒ Object
Specify if shadow should be drawn under corresponding points Must be boolean
Example
instance.shadow = [true,false]
357 358 359 360 |
# File 'lib/simple-mappr.rb', line 357 def shadow=(shadow) Validator.validate_shadows(shadow) @parameters[:shadow] = shadow end |
#shape ⇒ Object
328 329 330 |
# File 'lib/simple-mappr.rb', line 328 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']
323 324 325 326 |
# File 'lib/simple-mappr.rb', line 323 def shape=(shape) Validator.validate_shapes(shape) @parameters[:shape] = shape end |
#size ⇒ Object
345 346 347 |
# File 'lib/simple-mappr.rb', line 345 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]
340 341 342 343 |
# File 'lib/simple-mappr.rb', line 340 def size=(size) Validator.validate_sizes(size) @parameters[:size] = size end |
#spacing ⇒ Object
379 380 381 |
# File 'lib/simple-mappr.rb', line 379 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
374 375 376 377 |
# File 'lib/simple-mappr.rb', line 374 def spacing=(spacing) Validator.validate_spacing(spacing) @parameters[:spacing] = spacing end |
#url ⇒ Object
396 397 398 |
# File 'lib/simple-mappr.rb', line 396 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"
391 392 393 394 |
# File 'lib/simple-mappr.rb', line 391 def url=(url) Validator.validate_url(url) @parameters[:url] = url end |
#watermark ⇒ Object
413 414 415 |
# File 'lib/simple-mappr.rb', line 413 def watermark @parameters[:watermark] || nil end |
#watermark=(mark) ⇒ Object
Specify if watermark is shown Must be boolean
Example
instance.watermark = [true,false]
408 409 410 411 |
# File 'lib/simple-mappr.rb', line 408 def watermark=(mark) Validator.validate_watermark(mark) @parameters[:watermark] = mark end |
#width ⇒ Object
430 431 432 |
# File 'lib/simple-mappr.rb', line 430 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
425 426 427 428 |
# File 'lib/simple-mappr.rb', line 425 def width=(width) Validator.validate_dimension(width) @parameters[:width] = width end |
#wkt ⇒ Object
447 448 449 |
# File 'lib/simple-mappr.rb', line 447 def wkt @parameters[:wkt] || nil end |
#wkt=(wkt) ⇒ Object
Include wkt regions as an Array of Hashes Specify color, title, data, and border 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))" }]
442 443 444 445 |
# File 'lib/simple-mappr.rb', line 442 def wkt=(wkt) Validator.validate_wkt(wkt) @parameters[:wkt] = wkt end |
#zoom ⇒ Object
464 465 466 |
# File 'lib/simple-mappr.rb', line 464 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
459 460 461 462 |
# File 'lib/simple-mappr.rb', line 459 def zoom=(zoom) Validator.validate_zoom(zoom) @parameters[:zoom] = zoom end |