Class: SimpleMappr

Inherits:
Object
  • Object
show all
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.0.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'
]
SHAPES =
[
  'plus',
  'cross',
  'asterisk',
  'circle',
  'square',
  'triangle',
  'inversetriangle',
  'star',
  'hexagon',
  'opencircle',
  'opensquare',
  'opentriangle',
  'inverseopentriangle',
  'openstar',
  'openhexagon'
]
LAYERS =
[
  'countries',
  'countrynames',
  'relief',
  '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

Instance Method Summary collapse

Constructor Details

#initializeSimpleMappr

Returns a new instance of SimpleMappr.



8
9
10
# File 'lib/simple-mappr.rb', line 8

def initialize
  @parameters = {}
end

Class Method Details

.api_urlObject



60
61
62
# File 'lib/simple-mappr/constants.rb', line 60

def self.api_url
  API_URL
end

.layersObject



72
73
74
# File 'lib/simple-mappr/constants.rb', line 72

def self.layers
  LAYERS
end

.outputsObject



76
77
78
# File 'lib/simple-mappr/constants.rb', line 76

def self.outputs
  OUTPUTS
end

.projectionsObject



68
69
70
# File 'lib/simple-mappr/constants.rb', line 68

def self.projections
  PROJECTIONS
end

.shapesObject



64
65
66
# File 'lib/simple-mappr/constants.rb', line 64

def self.shapes
  SHAPES
end

.versionObject



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

Returns:

  • (Boolean)


22
23
24
25
# File 'lib/simple-mappr.rb', line 22

def alive?
  response = Transporter.ping
  response[:status] == "ok"
end

#bboxObject



55
56
57
# File 'lib/simple-mappr.rb', line 55

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"


50
51
52
53
# File 'lib/simple-mappr.rb', line 50

def bbox=(bbox)
  Validator.validate_bbox(bbox)
  @parameters[:bbox] = bbox
end

#colorObject



71
72
73
# File 'lib/simple-mappr.rb', line 71

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"]


66
67
68
69
# File 'lib/simple-mappr.rb', line 66

def color=(color)
  Validator.validate_colors(color)
  @parameters[:color] = color
end

#createObject

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.local/579273e6_1dd1_2.png",
   expiry: "2016-07-22T21:28:38-04:00"
}


39
40
41
# File 'lib/simple-mappr.rb', line 39

def create
  Transporter.send_data @parameters
end

#file_pathObject



87
88
89
# File 'lib/simple-mappr.rb', line 87

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 = "/Users/SimpleMappr/demo.txt"


82
83
84
85
# File 'lib/simple-mappr.rb', line 82

def file_path=(file_path)
  Validator.validate_type(file_path, 'File')
  @parameters[:file] = File.new(file_path, "r")
end

#graticulesObject



103
104
105
# File 'lib/simple-mappr.rb', line 103

def graticules
  @parameters[:graticules] || nil
end

#graticules=(graticules) ⇒ Object

Turn on or off the graticules (grid)

Example

instance.graticules = true


98
99
100
101
# File 'lib/simple-mappr.rb', line 98

def graticules=(graticules)
  Validator.validate_type(graticules, 'Boolean')
  @parameters[:graticules] = graticules
end

#heightObject



120
121
122
# File 'lib/simple-mappr.rb', line 120

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


115
116
117
118
# File 'lib/simple-mappr.rb', line 115

def height=(height)
  Validator.validate_dimension(height)
  @parameters[:height] = height
end

#layersObject



138
139
140
# File 'lib/simple-mappr.rb', line 138

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'


133
134
135
136
# File 'lib/simple-mappr.rb', line 133

def layers=(layers)
  Validator.validate_layers(layers)
  @parameters[:layers] = layers
end

#legendObject



155
156
157
# File 'lib/simple-mappr.rb', line 155

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.layers = ['My First Legend','My Second Legend']


150
151
152
153
# File 'lib/simple-mappr.rb', line 150

def legend=(legend)
  Validator.validate_type(legend, 'Array')
  @parameters[:legend] = legend
end

#originObject



171
172
173
# File 'lib/simple-mappr.rb', line 171

def origin
  @parameters[:origin] || nil
end

#origin=(origin) ⇒ Object

Specify the origin of natural longitude

Example

instance.origin = -100


166
167
168
169
# File 'lib/simple-mappr.rb', line 166

def origin=(origin)
  Validator.validate_origin(origin)
  @parameters[:origin] = origin
end

#outlinecolorObject



187
188
189
# File 'lib/simple-mappr.rb', line 187

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"


182
183
184
185
# File 'lib/simple-mappr.rb', line 182

def outlinecolor=(outlinecolor)
  Validator.validate_color(outlinecolor)
  @parameters[:outlinecolor] = outlinecolor
end

#outputObject



204
205
206
# File 'lib/simple-mappr.rb', line 204

def output
  @parameters[:output] || nil
end

#output=(output) ⇒ Object

Specify the output file format Options are svg, png, or jpg

Example

instance.output = "png"


199
200
201
202
# File 'lib/simple-mappr.rb', line 199

def output=(output)
  Validator.validate_output(output)
  @parameters[:output] = output
end

#paramsObject

View the built parameters



15
16
17
# File 'lib/simple-mappr.rb', line 15

def params
  @parameters
end

#pointsObject



222
223
224
# File 'lib/simple-mappr.rb', line 222

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"]


217
218
219
220
# File 'lib/simple-mappr.rb', line 217

def points=(points)
  Validator.validate_points(points)
  @parameters[:points] = points
end

#projectionObject



239
240
241
# File 'lib/simple-mappr.rb', line 239

def projection
  @parameters[:projection] || nil
end

#projection=(projection) ⇒ Object

Specify the projection See simple-mappr/constants.rb

Example

instance.projection = "epsg:4326"


234
235
236
237
# File 'lib/simple-mappr.rb', line 234

def projection=(projection)
  Validator.validate_projection(projection)
  @parameters[:projection] = projection
end

#scalebarObject



255
256
257
# File 'lib/simple-mappr.rb', line 255

def scalebar
  @parameters[:scalebar] || nil
end

#scalebar=(scalebar) ⇒ Object

Include an embedded scalebar

Example

instance.scalebar = true


250
251
252
253
# File 'lib/simple-mappr.rb', line 250

def scalebar=(scalebar)
  Validator.validate_type(scalebar, 'Boolean')
  @parameters[:scalebar] = scalebar
end

#shadeObject



272
273
274
# File 'lib/simple-mappr.rb', line 272

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]"}


267
268
269
270
# File 'lib/simple-mappr.rb', line 267

def shade=(shade)
  Validator.validate_shade(shade)
  @parameters[:shade] = shade
end

#shapeObject



289
290
291
# File 'lib/simple-mappr.rb', line 289

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']


284
285
286
287
# File 'lib/simple-mappr.rb', line 284

def shape=(shape)
  Validator.validate_shapes(shape)
  @parameters[:shape] = shape
end

#sizeObject



306
307
308
# File 'lib/simple-mappr.rb', line 306

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]


301
302
303
304
# File 'lib/simple-mappr.rb', line 301

def size=(size)
  Validator.validate_sizes(size)
  @parameters[:size] = size
end

#spacingObject



323
324
325
# File 'lib/simple-mappr.rb', line 323

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


318
319
320
321
# File 'lib/simple-mappr.rb', line 318

def spacing=(spacing)
  Validator.validate_spacing(spacing)
  @parameters[:spacing] = spacing
end

#urlObject



340
341
342
# File 'lib/simple-mappr.rb', line 340

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"


335
336
337
338
# File 'lib/simple-mappr.rb', line 335

def url=(url)
  Validator.validate_url(url)
  @parameters[:url] = url
end

#widthObject



357
358
359
# File 'lib/simple-mappr.rb', line 357

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


352
353
354
355
# File 'lib/simple-mappr.rb', line 352

def width=(width)
  Validator.validate_dimension(width)
  @parameters[:width] = width
end

#zoomObject



374
375
376
# File 'lib/simple-mappr.rb', line 374

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


369
370
371
372
# File 'lib/simple-mappr.rb', line 369

def zoom=(zoom)
  Validator.validate_zoom(zoom)
  @parameters[:zoom] = zoom
end