leaflet_helper 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8c6c2bfb061ed25ac3ffdf96fef9e873cac10ff3
4
- data.tar.gz: d23001011f855ba51e1b97ae012ea53e2cc57c25
3
+ metadata.gz: 83b213676f1fe561a3231121f948a1701a2f525e
4
+ data.tar.gz: d25a23c9184dd00302b9ae6113f67840d40b3523
5
5
  SHA512:
6
- metadata.gz: eb415d972d817fb45f1238c9364dc573b6673516b81982719bb01e6815645b2221c11dc8eb4240b966be9dc9b7e943a744b490b058db3d30ac062245488c28dd
7
- data.tar.gz: d90dcb14eb057a44ebe7b6c6ccf276f4f13d48cf44e881e694c0c4c52c94563b8e0f42fbc102de094a0406f092969b2e0f70c5532bb7e51f89626a5714bf9476
6
+ metadata.gz: d0e9e1cf5313422f3c291826c825dadabe7ecf0c7fc3797932f9a95431c8df465ace04659c28519b6efb6d5adf8534004c729b51cc3f19e8afb24ebf5149c810
7
+ data.tar.gz: 84818a516214faa0bfdab9a793667b47784ca3e16d48bfef002b2d876214c4509696ca3bc1af70b846d0bfd80a3c8bdaf46f50a5ebbe8df43f68ffba57316a27
data/README.md CHANGED
@@ -1,9 +1,15 @@
1
1
  # LeafletHelper
2
2
 
3
- I couldn't find any libraries that were ruby-centric geospatial map knowledgable that were
4
- framework agnostic.
3
+ For those of us who don't want to get our hands dirty writing JavaScript (shutter) this library is
4
+ for you. Actually, its for me, but you can use it if you like. Once you have installed the gem
5
+ do this:
5
6
 
6
- Look at my experiments/maps repo to see how leafelet_helpers is used with a sinatra-based web app.
7
+ ```bash
8
+ gem which leaflet_helper
9
+ ```
10
+
11
+ The `cd` to the root directory of the gem. There you will find a subdirectory named `example` in
12
+ which there is a simple Sinatra-based web application that makes use of the LeafletHelper.
7
13
 
8
14
  ## Installation
9
15
 
@@ -23,7 +29,7 @@ Or install it yourself as:
23
29
 
24
30
  ## Usage
25
31
 
26
- Look at [https://github.com/MadBomber/experiments/tree/master/maps]
32
+ Here is another example of how to use LeafletHelper with multiple maps on a webpage [https://github.com/MadBomber/experiments/tree/master/maps]
27
33
 
28
34
  The views/layout.haml and views/index.haml show how to use the leaflet_helper. Of course you
29
35
  have to require the gem in the main app.rb file in order for it to be available in the views. This
data/example/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ # Gemfile
2
+
3
+ source "https://rubygems.org"
4
+
5
+ ruby "2.3.1"
6
+
7
+ # Special Libraries
8
+ gem 'leaflet_helper' # A Ruby-wrapper around leaflet.js
9
+
10
+ # Web-app framework
11
+ gem 'sinatra', require: 'sinatra/base' # Classy web-development dressed in a DSL
12
+ gem 'sinatra-partial' # A sinatra extension for render partials.
13
+ gem 'haml' # An elegant, structured (X)HTML/XML templating engine.
14
+ gem 'puma' # Puma is a simple, fast, threaded, and highly concurrent HTTP 1.1 server for Ruby/Rack application
15
+
@@ -0,0 +1,33 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ haml (4.0.7)
5
+ tilt
6
+ leaflet_helper (0.0.6)
7
+ puma (3.4.0)
8
+ rack (1.6.4)
9
+ rack-protection (1.5.3)
10
+ rack
11
+ sinatra (1.4.7)
12
+ rack (~> 1.5)
13
+ rack-protection (~> 1.4)
14
+ tilt (>= 1.3, < 3)
15
+ sinatra-partial (1.0.0)
16
+ sinatra (~> 1.4)
17
+ tilt (2.0.5)
18
+
19
+ PLATFORMS
20
+ ruby
21
+
22
+ DEPENDENCIES
23
+ haml
24
+ leaflet_helper
25
+ puma
26
+ sinatra
27
+ sinatra-partial
28
+
29
+ RUBY VERSION
30
+ ruby 2.3.1p112
31
+
32
+ BUNDLED WITH
33
+ 1.12.5
data/example/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # __application_name__ #
2
+
3
+ ## Description
4
+
5
+ __description__
6
+
7
+ Remainder of this file is TBD ...
8
+
9
+ ## Details
10
+
11
+ ### What is this application? ###
12
+
13
+ * Quick summary
14
+ * Version
15
+
16
+ ### How do I get set up? ###
17
+
18
+ * Summary of set up
19
+ * Configuration
20
+ * Dependencies
21
+ * Database configuration
22
+ * How to run tests
23
+ * Deployment instructions
24
+
25
+ ### Contribution guidelines ###
26
+
27
+ * Writing tests
28
+ * Code review
29
+ * Other guidelines
30
+
31
+ ### Who do I talk to? ###
32
+
33
+ * Repo owner or admin
34
+ * Other community or team contact
data/example/app.rb ADDED
@@ -0,0 +1,139 @@
1
+ #!/usr/bin/env ruby
2
+ #########################################################
3
+ ###
4
+ ## File: app.rb
5
+ ## Desc: An example Sinatra app using LeafletHelper
6
+ #
7
+
8
+ require 'leaflet_helper'
9
+
10
+ $markers = Hash.new(LeafletHelper::ManageMarkers.new)
11
+
12
+ module TestData
13
+
14
+ AREA51_LOCATION = [37.242, -115.8191] # Lat, Long
15
+ DELTA = [15, 15] # NOTE: expresed as integer of real delta +/- 1.5 in lat, long
16
+ # in order to use rand() method
17
+
18
+ CODE_WORDS = [
19
+ "Magic Carpet",
20
+ "Desert Storm",
21
+ "Bayonet Lightning",
22
+ "Valiant Guardian",
23
+ "Urgent Fury",
24
+ "Eagle Claw",
25
+ "Crescent Wind",
26
+ "Spartan Scorpion",
27
+ "Overlord",
28
+ "Rolling Thunder"
29
+ ]
30
+
31
+ class << self
32
+
33
+ def get_random_codeword
34
+ CODE_WORDS.sample
35
+ end
36
+
37
+
38
+ def get_random_location( fixed_point=AREA51_LOCATION, delta=DELTA )
39
+ offset = []
40
+ dir = rand(2) == 0 ? -1.0 : 1.0
41
+ offset << dir * rand(delta.first).to_f / 10.0
42
+ dir = rand(2) == 0 ? -1.0 : 1.0
43
+ offset << dir * rand(delta.last).to_f / 10.0
44
+ point = fixed_point.each_with_index.map {|v, x| v + offset[x]}
45
+
46
+ return { 'lat' => point.first, 'lon' => point.last }
47
+
48
+ end # def get_random_location( fixed_point=AREA51_LOCATION, delta=DELTA )
49
+ end # class < self
50
+
51
+ end # module TestData
52
+
53
+
54
+
55
+ require 'pathname'
56
+
57
+ ROOT = Pathname.new(__FILE__).realpath.parent
58
+
59
+ class MissingSystemEnvironmentVariable < RuntimeError; end
60
+
61
+ unless defined?(APP_BIND)
62
+ raise APP_BIND, "APP_BIND is undefined" if ENV['APP_BIND'].nil?
63
+ APP_BIND = ENV['APP_BIND']
64
+ end
65
+
66
+ unless defined?(APP_PORT)
67
+ raise MissingSystemEnvironmentVariable, "APP_PORT is undefined" if ENV['APP_PORT'].nil?
68
+ APP_PORT = ENV['APP_PORT']
69
+ end
70
+
71
+ require 'json'
72
+
73
+
74
+ require 'sinatra/base'
75
+ require 'sinatra/partial'
76
+
77
+
78
+ module APP
79
+
80
+ class DemoError < RuntimeError; end
81
+
82
+ class App < Sinatra::Base
83
+ register Sinatra::Partial
84
+
85
+ set :bind, APP_BIND
86
+ set :port, APP_PORT
87
+ set :server, :puma
88
+
89
+ set :haml, :format => :html5
90
+ set :views, settings.root + '/views'
91
+
92
+ set :partial_template_engine, :haml
93
+
94
+ configure do
95
+ mime_type :html, 'text/html'
96
+ end
97
+
98
+
99
+ before do
100
+ content_type :html
101
+ end
102
+
103
+
104
+ # A marketting landing page
105
+ get '/' do
106
+ haml :index
107
+ end
108
+
109
+
110
+ # Provide some JSON markers
111
+ # Since everything is randomized, every time the map is
112
+ # changed a new set of markers is generated.
113
+ get '/:map_id/markers' do |map_id|
114
+ content_type :json
115
+ $markers[map_id].clear
116
+ (rand(10)+1).times do |x|
117
+ code_word = TestData.get_random_codeword
118
+ location = TestData.get_random_location
119
+ $markers[map_id].add id: code_word,
120
+ lat: location['lat'],
121
+ lon: location['lon'],
122
+ html: <<~EOS
123
+ <h3>Crash ##{x}</h3>
124
+ <p>During #{code_word} rehearsals, programmer error resulted in an unexpected hard landing at this location</p>
125
+ EOS
126
+ end
127
+ $markers[map_id].to_json
128
+ end
129
+
130
+
131
+
132
+ ############################################################
133
+
134
+ end # class App < Sinatra::Base
135
+ end # module APP
136
+
137
+
138
+ # APP::App.run!
139
+
data/example/config.ru ADDED
@@ -0,0 +1,2 @@
1
+ require './app'
2
+ run APP::App
data/example/start ADDED
@@ -0,0 +1,7 @@
1
+ # start
2
+
3
+ export APP_BIND='0.0.0.0'
4
+ export APP_PORT=4567
5
+
6
+ rackup --port $APP_PORT --host $APP_BIND --server puma
7
+
File without changes
@@ -0,0 +1,3 @@
1
+ -# footer.haml
2
+
3
+ %p Copyright &copy; 2016 - MadBomber Software - All Rights Reserved
@@ -0,0 +1,5 @@
1
+ -# index.haml
2
+
3
+ %h2 Checkout the Map
4
+
5
+ = LeafletHelper::L.place_map_here('my_wonderful_map')
@@ -0,0 +1,25 @@
1
+ -# layout.haml
2
+ !!!
3
+ %html
4
+ %head
5
+ %title Application by VanHoozer
6
+ = LeafletHelper::L.init
7
+ %body
8
+
9
+ #logo_header
10
+
11
+ %h1
12
+ Application by VanHoozer
13
+
14
+ #main
15
+
16
+ = yield
17
+
18
+ #footer
19
+ = partial :footer
20
+
21
+ - map_id = 'my_wonderful_map'
22
+ - map_options = { latitude: 37.235, longitude: -115.811111, min_zoom: 2, max_zoom: 18}
23
+ = LeafletHelper::L.show_map(map_id, map_options)
24
+ = LeafletHelper::L.add_openstreetmap_layer(map_id, map_options)
25
+ = LeafletHelper::L.add_support_for_markers(map_id, route: "#{map_id}/markers")
@@ -1,11 +1,10 @@
1
1
  # coding: utf-8
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'leaflet_helper/version'
5
4
 
6
5
  Gem::Specification.new do |spec|
7
6
  spec.name = "leaflet_helper"
8
- spec.version = '0.0.5'
7
+ spec.version = '0.0.6'
9
8
  spec.authors = ["Dewayne VanHoozer"]
10
9
  spec.email = ["dvanhoozer@gmail.com"]
11
10
 
@@ -23,11 +22,10 @@ Gem::Specification.new do |spec|
23
22
  # end
24
23
 
25
24
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
- spec.bindir = "exe"
27
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
25
  spec.require_paths = ["lib"]
29
26
 
30
27
  spec.add_development_dependency "bundler", "~> 1.12"
31
28
  spec.add_development_dependency "rake", "~> 10.0"
32
29
  spec.add_development_dependency "minitest", "~> 5.0"
30
+
33
31
  end
@@ -0,0 +1,102 @@
1
+ # manage_markers.rb
2
+
3
+ require 'json'
4
+
5
+ module LeafletHelper
6
+
7
+ # Marker encapsulates an Array of Hashes where each Hash
8
+ # is a marker structure which can be used to add content to
9
+ # a LeafletJS-managed map image.
10
+ class ManageMarkers
11
+
12
+ # Manage an Array of Hashes
13
+ def initialize()
14
+ @markers = Array.new
15
+ end # def initialize
16
+
17
+
18
+ # a marker consists of an identification (not unique),
19
+ # a location expressed as decimal latitude longitude and
20
+ # an html component.
21
+ def add(id:, lat:, lon:, html: 'Marker')
22
+ @markers << {
23
+ id: id,
24
+ lat: lat,
25
+ lon: lon,
26
+ html: html
27
+ }
28
+ end
29
+ alias :insert :add
30
+ alias :<< :add
31
+ alias :push :add
32
+
33
+
34
+ # Remove all marker entries that have the given id
35
+ def remove(id)
36
+ return() if @markers.empty?
37
+ @markers.each_index do |x|
38
+ @markersp[x] = nil if id == @markers[x][:id]
39
+ end
40
+ @markers.compact!
41
+ end
42
+ alias :delete :remove
43
+ alias :rm :remove
44
+ alias :pull :remove
45
+
46
+
47
+ # Clear out the array so we can start over
48
+ def clear
49
+ @markers = Array.new
50
+ end
51
+ alias :clean :clear
52
+
53
+
54
+ # Turn the array of markers into a JSON structure
55
+ def to_json
56
+ @markers.to_json
57
+ end
58
+
59
+ end # class ManageMarkers
60
+ end # module LeafletHelper
61
+
62
+
63
+
64
+ __END__
65
+
66
+ Example: One Map
67
+
68
+ my_map = LeafletHelper::ManageMarkers.new
69
+
70
+ my_map.add id: 'Secret Place',
71
+ lat: AREA51.latitude,
72
+ lon: AREA51.longitude,
73
+ html: <<~EOS
74
+ <h3>Area 51</h3>
75
+ <img src='ufo.png'>
76
+ <p>For Sale <em>Low Mileage</em>, owner is medicated. Must see to appriciate! Come by after sunset; beware of guards!</p>
77
+ EOS
78
+
79
+ puts my_map.to_json #=> [{"id":"Secret Place","lat":37.235,"lon":-115.811111,"html":"<h3>Area 51</h3>\n<img src='ufo.png'>\n<p>For Sale <em>Low Mileage</em>, owner is modicated. Must see to appriciate! Come by after sunset; beware of guards</p>\n"}]
80
+
81
+
82
+ Example: Multiple Maps
83
+
84
+ markers = Hash.new(LeafletHelper::ManageMarkers.new)
85
+
86
+ markers['map'].add id: 'Secret Place',
87
+ lat: AREA51.latitude,
88
+ lon: AREA51.longitude,
89
+ html: <<~EOS
90
+ <h3>Area 51</h3>
91
+ <img src='ufo.png'>
92
+ <p>For Sale <em>Low Mileage</em>, owner is modivated. Must see to appriciate! Come by after sunset; beware of guards!</p>
93
+ EOS
94
+
95
+ markers['map2'].add id: 'Secret Place',
96
+ lat: AREA51.latitude,
97
+ lon: AREA51.longitude,
98
+ html: <<~EOS
99
+ <h3>Area 51</h3>
100
+ <img src='ufo.png'>
101
+ <p>For Sale <em>Low Mileage</em>, owner is modivated. Must see to appriciate! Come by after sunset; beware of guards!</p>
102
+ EOS
@@ -21,6 +21,9 @@ AREA51 = Struct.new('Location', :latitude, :longitude).new
21
21
  AREA51.latitude = 37.235
22
22
  AREA51.longitude = -115.811111
23
23
 
24
+ require 'leaflet_helper/manage_markers'
25
+
26
+
24
27
  module LeafletHelper
25
28
  class L
26
29
  VERSION = '0.7.7' # of leaflet.js
@@ -29,7 +32,6 @@ module LeafletHelper
29
32
 
30
33
  # TODO: Why are these desired?
31
34
  @@map_ids = [] # the div ids of all of the maps
32
- @@markers = Hash.new([]) # An array of markers for each map id
33
35
 
34
36
  class << self
35
37
 
@@ -131,7 +133,7 @@ module LeafletHelper
131
133
 
132
134
 
133
135
  # Intended for the body at the bottom
134
- # SMELL: why the bottom? Because that's they way we did it in the old days
136
+ # SMELL: why the bottom? Because that's the way we did it in the old days
135
137
  # so that the entire web page would have been loaded by then.
136
138
  def add_openstreetmap_layer(id="map", options={})
137
139
  o = {
@@ -265,7 +267,7 @@ module LeafletHelper
265
267
  plotmark.data = plotlist[i];
266
268
 
267
269
  #{var_name}.addLayer(plotmark);
268
- plotmark.bindPopup("<h3>" + plotlist[i].name + "</h3>" + plotlist[i].details);
270
+ plotmark.bindPopup(plotlist[i].html);
269
271
  plotlayersFor#{id}.push(plotmark);
270
272
  } // for
271
273
 
@@ -301,43 +303,6 @@ module LeafletHelper
301
303
  return "<!-- #{a_string} -->"
302
304
  end
303
305
 
304
-
305
- # TODO: Marker management is something that could be abstracted into
306
- # its own class.
307
-
308
- # Can't think of a way to use add_marker and delete_marker.
309
- # They may not be necessary.
310
- def add_marker(marker={}, map_id='map')
311
- # TODO: add_marker
312
- end
313
-
314
-
315
- # delete/remove a specific marker from a given map id
316
- def delete_marker(marker={}, map_id='map')
317
- # TODO: delete_marker
318
- end
319
-
320
-
321
- # clear/remove all markers for a given map id
322
- def clear_markers(map_id='map')
323
- @@markers[map_id] = []
324
- end
325
-
326
306
  end # class << self
327
307
  end # class L
328
308
  end # module LeafletHelper
329
-
330
-
331
- __END__
332
-
333
- A JSON marker array with one entry looks like this:
334
-
335
- [
336
- {
337
- "name":"Tunbridge Wells, Langton Road, Burnt Cottage",
338
- "lon":"0.213102", // SMELL: a string? really?
339
- "lat":"51.1429", // SMELL: ditto
340
- "details":"A Grade II listed five bedroom wing in need of renovation."
341
- }
342
- ]
343
-
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: leaflet_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dewayne VanHoozer
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2016-06-10 00:00:00.000000000 Z
12
12
  dependencies:
@@ -65,11 +65,19 @@ files:
65
65
  - LICENSE.txt
66
66
  - README.md
67
67
  - Rakefile
68
- - bin/console
69
- - bin/setup
68
+ - example/Gemfile
69
+ - example/Gemfile.lock
70
+ - example/README.md
71
+ - example/app.rb
72
+ - example/config.ru
73
+ - example/start
74
+ - example/views/.keep
75
+ - example/views/footer.haml
76
+ - example/views/index.haml
77
+ - example/views/layout.haml
70
78
  - leaflet_helper.gemspec
71
79
  - lib/leaflet_helper.rb
72
- - lib/leaflet_helper/version.rb
80
+ - lib/leaflet_helper/manage_markers.rb
73
81
  homepage: http://github.com/MadBomber/leaflet_helper
74
82
  licenses:
75
83
  - You want it? Its yours!
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "leaflet_helper"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
@@ -1,3 +0,0 @@
1
- module LeafletHelper
2
- VERSION = "0.1.0"
3
- end