leaflet_helper 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -5
- data/leaflet_helper.gemspec +1 -1
- data/lib/leaflet_helper.rb +24 -32
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f0a6f20aeb1a990f29061044ced274fae566267
|
4
|
+
data.tar.gz: 538a63485b9c432f7d8d0374f3bd7250e25d199d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 400b40208c8f2219f6b921a93c4b9183bd6b8d5728c4b61f1dfee65efc50300677e5e02ae1657e42a97799d08c6ecc9a387921008fa8a35349ced75d3dffb4d9
|
7
|
+
data.tar.gz: 4ae029f4525beed6e476fe921131be854d6dfd8c72f3904d0faddf5ac2a6f47ce715124fad53ed5b1b56ddd9e6b342bf91a299b477bf0be11a5354226cbf427b
|
data/README.md
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
# LeafletHelper
|
2
2
|
|
3
|
-
I couldn't find any libraries that were ruby-centric geospatial map knowledgable that were
|
4
|
-
|
5
|
-
|
3
|
+
I couldn't find any libraries that were ruby-centric geospatial map knowledgable that were
|
4
|
+
framework agnostic.
|
5
|
+
|
6
|
+
Look at my experiments/maps repo to see how leafelet_helpers is used with a sinatra-based web app.
|
6
7
|
|
7
8
|
## Installation
|
8
9
|
|
@@ -22,7 +23,11 @@ Or install it yourself as:
|
|
22
23
|
|
23
24
|
## Usage
|
24
25
|
|
25
|
-
|
26
|
+
Look at https://github.com/MadBomber/experiments/tree/master/maps
|
27
|
+
|
28
|
+
The views/layout.haml and views/index.haml show how to use the leaflet_helper. Of course you
|
29
|
+
have to require the gem in the main app.rb file in order for it to be available in the views. This
|
30
|
+
sinatra app also shows how to use markers on top of the main map layers.
|
26
31
|
|
27
32
|
## Development
|
28
33
|
|
@@ -30,7 +35,7 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
30
35
|
|
31
36
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
37
|
|
33
|
-
Of if that doesn't work try something.
|
38
|
+
Of course if that doesn't work try something else. I'm not any good a javascript; if you are, send me some pull requests to improve my naive notions.
|
34
39
|
|
35
40
|
## Contributing
|
36
41
|
|
data/leaflet_helper.gemspec
CHANGED
data/lib/leaflet_helper.rb
CHANGED
@@ -3,25 +3,24 @@
|
|
3
3
|
module LeafletHelper
|
4
4
|
class L
|
5
5
|
VERSION = '0.7.3' # of leaflet.js
|
6
|
+
|
7
|
+
# TODO: Why are these desired?
|
6
8
|
@@map_ids = [] # the div ids of all of the maps
|
7
9
|
@@markers = Hash.new([]) # An array of markers for each map id
|
8
|
-
@@initialized = false
|
9
10
|
|
10
11
|
class << self
|
11
12
|
|
12
13
|
# intended for the the head section
|
13
14
|
def init(options={})
|
14
15
|
o = {
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
# raise RuntimeError, 'Already initialized' if initialized?
|
19
|
-
initialized!
|
16
|
+
author: "@madbomber"
|
17
|
+
}.merge(options)
|
20
18
|
|
21
19
|
leaflet_script = <<~EOS
|
22
20
|
<script type="text/javascript" src="//cdn.leafletjs.com/leaflet-#{VERSION}/leaflet.js"></script>
|
23
21
|
<link rel="stylesheet" href="//cdn.leafletjs.com/leaflet-#{VERSION}/leaflet.css">
|
24
22
|
|
23
|
+
// SMELL: I'm not sure this script section is needed.
|
25
24
|
<script>
|
26
25
|
|
27
26
|
// set up AJAX request
|
@@ -48,8 +47,10 @@ module LeafletHelper
|
|
48
47
|
|
49
48
|
|
50
49
|
# intended for the body of a web page
|
51
|
-
#
|
50
|
+
# can support multiple maps on a page; each
|
51
|
+
# map must have a unique id
|
52
52
|
def place_map_here(id='map', options={})
|
53
|
+
# SMELL: This may happen every time the page is refreshed
|
53
54
|
@@map_ids << id
|
54
55
|
o = {
|
55
56
|
style: "width: 800px; height: 400px"
|
@@ -61,7 +62,7 @@ module LeafletHelper
|
|
61
62
|
return <<~EOS
|
62
63
|
<div id="#{id}"#{div_options}></div>
|
63
64
|
EOS
|
64
|
-
end # def
|
65
|
+
end # def place_map_here(id='map')
|
65
66
|
|
66
67
|
|
67
68
|
# Intended for the body at the bottom
|
@@ -126,9 +127,9 @@ module LeafletHelper
|
|
126
127
|
end # def add_openstreetmap_layer(id="map", options={})
|
127
128
|
|
128
129
|
|
130
|
+
# Allows for the generation of markers on top of the map
|
129
131
|
def add_support_for_markers(id="map", options={})
|
130
132
|
o = {
|
131
|
-
markers: true,
|
132
133
|
route: "#{id}/markers"
|
133
134
|
}.merge(options)
|
134
135
|
|
@@ -143,26 +144,27 @@ module LeafletHelper
|
|
143
144
|
function on#{id}Move(e) { getMarkersFor#{id}(); }
|
144
145
|
|
145
146
|
|
146
|
-
|
147
|
-
// request the marker info with AJAX for the current bounds
|
147
|
+
// request the marker info for the current bounds
|
148
148
|
function getMarkersFor#{id}() { // was: askForPlots
|
149
149
|
|
150
|
+
// TODO: Currently the displayed map bounds is not being used
|
151
|
+
// to get the new set of markers. This could be ugly for
|
152
|
+
// lots of markers. Need a way to insert the bounds into the route.
|
150
153
|
var bounds = #{var_name}.getBounds();
|
151
154
|
var minll = bounds.getSouthWest();
|
152
155
|
var maxll = bounds.getNorthEast();
|
153
156
|
|
154
|
-
//
|
155
|
-
|
156
|
-
|
157
|
-
var msg = '#{o[:route]}';
|
157
|
+
// this is the place from which the markers JSON array is obtained
|
158
|
+
var route = '#{o[:route]}';
|
158
159
|
|
159
160
|
ajaxRequest.onreadystatechange = stateChangedFor#{id};
|
160
|
-
ajaxRequest.open('GET',
|
161
|
+
ajaxRequest.open('GET', route, true);
|
161
162
|
ajaxRequest.send(null);
|
162
163
|
}
|
163
164
|
|
164
165
|
|
165
|
-
|
166
|
+
// The map changed so get new markers
|
167
|
+
function stateChangedFor#{id}() {
|
166
168
|
|
167
169
|
// if AJAX returned a list of markers, add them to the map
|
168
170
|
if (ajaxRequest.readyState == 4) {
|
@@ -189,7 +191,8 @@ module LeafletHelper
|
|
189
191
|
} // function stateChangedFor#{id}()
|
190
192
|
|
191
193
|
|
192
|
-
|
194
|
+
// remove all of the markers from the map
|
195
|
+
function removeMarkersFrom#{id}() {
|
193
196
|
for (i=0; i<plotlayersFor#{id}.length; i++) {
|
194
197
|
#{var_name}.removeLayer(plotlayersFor#{id}[i]);
|
195
198
|
}
|
@@ -203,7 +206,8 @@ module LeafletHelper
|
|
203
206
|
end # def add_support_for_markers(map_id, map_options)
|
204
207
|
|
205
208
|
|
206
|
-
#
|
209
|
+
# Can't think of a way to use add_marker and delete_marker.
|
210
|
+
# They may not be necessary.
|
207
211
|
def add_marker(marker={}, map_id='map')
|
208
212
|
# TODO: add_marker
|
209
213
|
end
|
@@ -214,6 +218,7 @@ module LeafletHelper
|
|
214
218
|
end
|
215
219
|
|
216
220
|
|
221
|
+
# The "var name" is the Javascript container that has the map
|
217
222
|
def get_var_name(id="map")
|
218
223
|
return "lh_#{id}"
|
219
224
|
end
|
@@ -224,19 +229,6 @@ module LeafletHelper
|
|
224
229
|
end
|
225
230
|
|
226
231
|
|
227
|
-
private
|
228
|
-
|
229
|
-
def initialized!
|
230
|
-
@@initialized = true
|
231
|
-
end
|
232
|
-
|
233
|
-
|
234
|
-
def initialized?
|
235
|
-
@@initialized
|
236
|
-
end
|
237
|
-
|
238
|
-
|
239
|
-
|
240
232
|
end # class << self
|
241
233
|
end # class L
|
242
234
|
end # module LeafletHelper
|