gmap_plotter 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +59 -0
- data/Rakefile +2 -0
- data/bin/gmap_plotter +4 -0
- data/config.ru +3 -0
- data/examples/config.ru +3 -0
- data/gmap_plotter.gemspec +25 -0
- data/lib/gmap_plotter.rb +11 -0
- data/lib/gmap_plotter/public/app.js +175 -0
- data/lib/gmap_plotter/public/bower.json +19 -0
- data/lib/gmap_plotter/server.rb +46 -0
- data/lib/gmap_plotter/version.rb +3 -0
- data/lib/gmap_plotter/views/_file_upload.erb +63 -0
- data/lib/gmap_plotter/views/_modal.erb +46 -0
- data/lib/gmap_plotter/views/main.erb +24 -0
- data/lib/gmap_plotter/views/main_layout.erb +119 -0
- data/screenshot.png +0 -0
- data/spec/spec_helper.rb +2 -0
- metadata +757 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e036fd433409d68760c60258b45e95973dce1552
|
4
|
+
data.tar.gz: b5592808729ee2501ccdd17638b077f8c28beb02
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c9d20a725a645662beb03acf782de15deca30953d3a3f89830772101fee303a3e7271395dfa857009fbacfb1213cc84e6930af01b1d1d8de1f39e1bc2113804d
|
7
|
+
data.tar.gz: fd8836b2dbdc1645674830cf341bf0929d49c22a7209e53b70ee6afc3096a8103b95f932478fdc344a55e069d49f07d695fb50a48cd55e608cc166a4c5357dcb
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Alexander Rueedlinger
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# GmapPlotter
|
2
|
+
|
3
|
+
GmapPlotter is a little sinatra app for plotting gps points on a google map.
|
4
|
+
|
5
|
+
##Demo app
|
6
|
+
|
7
|
+
![Alt text](screenshot.png?raw=true "Screenshot")
|
8
|
+
|
9
|
+
A demo app runs on heroku:
|
10
|
+
[https://gmap-plotter.herokuapp.com/](https://gmap-plotter.herokuapp.com/)
|
11
|
+
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Add this line to your application's Gemfile:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem 'gmap_plotter'
|
19
|
+
```
|
20
|
+
|
21
|
+
And then execute:
|
22
|
+
|
23
|
+
$ bundle
|
24
|
+
|
25
|
+
Or install it yourself as:
|
26
|
+
|
27
|
+
$ gem install gmap_plotter
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
###Running
|
32
|
+
To run the app enter the command:
|
33
|
+
```
|
34
|
+
gmap_plotter
|
35
|
+
```
|
36
|
+
|
37
|
+
This command starts the app on ```http://localhost:3000```.
|
38
|
+
|
39
|
+
###Deployment
|
40
|
+
|
41
|
+
You can deploy you're own gmap plotter app by creating a ```config.ru``` rack config file.
|
42
|
+
|
43
|
+
Example ```config.ru``` file:
|
44
|
+
```
|
45
|
+
require 'gmap_plotter'
|
46
|
+
run GmapPlotter::Server
|
47
|
+
```
|
48
|
+
And run it via:
|
49
|
+
```
|
50
|
+
rackup config.ru -p 3000
|
51
|
+
```
|
52
|
+
|
53
|
+
## Contributing
|
54
|
+
|
55
|
+
1. Fork it ( https://github.com/[my-github-username]/gmap_plotter/fork )
|
56
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
57
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
58
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
59
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/gmap_plotter
ADDED
data/config.ru
ADDED
data/examples/config.ru
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'gmap_plotter/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "gmap_plotter"
|
8
|
+
spec.version = GmapPlotter::VERSION
|
9
|
+
spec.authors = ["Alexander Rueedlinger"]
|
10
|
+
spec.email = ["a.rueedlinger@gmail.com"]
|
11
|
+
spec.summary = %q{A little app for plotting gps points on a google map.}
|
12
|
+
spec.description = %q{Gmap Plotter is little app for plotting gps points on a google map.}
|
13
|
+
spec.homepage = "https://github.com/lexruee/gmap_plotter"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables << 'gmap_plotter'
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_runtime_dependency "sinatra", "~> 1.4"
|
24
|
+
spec.add_runtime_dependency "sinatra-contrib", "~> 1.4"
|
25
|
+
end
|
data/lib/gmap_plotter.rb
ADDED
@@ -0,0 +1,175 @@
|
|
1
|
+
function Gmap() {
|
2
|
+
this.map = null;
|
3
|
+
this.markers = [];
|
4
|
+
this.load();
|
5
|
+
};
|
6
|
+
|
7
|
+
Gmap.prototype.load = function (){
|
8
|
+
var that = this;
|
9
|
+
function initialize() {
|
10
|
+
var mapOptions = {
|
11
|
+
zoom: 13,
|
12
|
+
center: new google.maps.LatLng(46.946506, 7.444150) // default is Bundeshaus :-)
|
13
|
+
};
|
14
|
+
that.map = new google.maps.Map(document.getElementById('map-canvas'),
|
15
|
+
mapOptions);
|
16
|
+
}
|
17
|
+
google.maps.event.addDomListener(window, 'load', initialize);
|
18
|
+
};
|
19
|
+
|
20
|
+
Gmap.prototype.clear_map = function () {
|
21
|
+
var that = this;
|
22
|
+
$.each(this.markers, function(i, marker){
|
23
|
+
marker.setMap(null);
|
24
|
+
});
|
25
|
+
this.markers = [];
|
26
|
+
}
|
27
|
+
|
28
|
+
Gmap.prototype.set_center = function (point) {
|
29
|
+
var lat_lng = new google.maps.LatLng(point[0],point[1]);
|
30
|
+
this.map.setCenter(lat_lng);
|
31
|
+
};
|
32
|
+
|
33
|
+
Gmap.prototype.set_zoom = function (zoom) {
|
34
|
+
this.map.setZoom(parseInt(zoom));
|
35
|
+
};
|
36
|
+
|
37
|
+
Gmap.prototype.add_markers = function (points) {
|
38
|
+
var that = this;
|
39
|
+
$.each(points, function (i, point) {
|
40
|
+
var marker = new google.maps.Marker({
|
41
|
+
position: point,
|
42
|
+
map: that.map
|
43
|
+
});
|
44
|
+
that.markers.push(marker);
|
45
|
+
})
|
46
|
+
};
|
47
|
+
|
48
|
+
Gmap.prototype.add_path = function (points) {
|
49
|
+
var path = new google.maps.Polyline({
|
50
|
+
path: points,
|
51
|
+
geodesic: true,
|
52
|
+
strokeColor: '#FF0000',
|
53
|
+
strokeOpacity: 1.0,
|
54
|
+
strokeWeight: 2,
|
55
|
+
map: this.map
|
56
|
+
});
|
57
|
+
this.markers.push(path);
|
58
|
+
};
|
59
|
+
|
60
|
+
Gmap.prototype.helper_center_of_gravity = function (points) {
|
61
|
+
var acc = [0, 0];
|
62
|
+
$.each(points, function (i, ele) {
|
63
|
+
var n_lat = acc[0] + ele[0];
|
64
|
+
var n_lng = acc[1] + ele[1];
|
65
|
+
acc = [ n_lat, n_lng];
|
66
|
+
});
|
67
|
+
var len = points.length * 1.0;
|
68
|
+
return [ acc[0] / len, acc[1] / len]
|
69
|
+
};
|
70
|
+
|
71
|
+
Gmap.prototype.plot = function (points, options) {
|
72
|
+
|
73
|
+
if(points == null || points.length == 0)
|
74
|
+
return;
|
75
|
+
|
76
|
+
var that = this;
|
77
|
+
var center = this.helper_center_of_gravity(points);
|
78
|
+
this.set_center(center);
|
79
|
+
this.clear_map();
|
80
|
+
|
81
|
+
var new_points = $.map(points, function (ele, i) {
|
82
|
+
var lat = ele[0];
|
83
|
+
var lng = ele[1];
|
84
|
+
return new google.maps.LatLng(lat, lng);
|
85
|
+
});
|
86
|
+
|
87
|
+
if(options['type'] == 'markers'){
|
88
|
+
gmap.add_markers(new_points);
|
89
|
+
}else if(options['type'] == 'path'){
|
90
|
+
gmap.add_path(new_points);
|
91
|
+
}
|
92
|
+
|
93
|
+
};
|
94
|
+
|
95
|
+
Gmap.prototype.set_map_type = function (type) {
|
96
|
+
this.map.setMapTypeId(type);
|
97
|
+
};
|
98
|
+
|
99
|
+
var gmap = new Gmap();
|
100
|
+
|
101
|
+
|
102
|
+
// hooks
|
103
|
+
|
104
|
+
$('#set-satellite').click(function () {
|
105
|
+
gmap.set_map_type(google.maps.MapTypeId.SATELLITE);
|
106
|
+
});
|
107
|
+
|
108
|
+
|
109
|
+
$('#set-roadmap').click(function () {
|
110
|
+
gmap.set_map_type(google.maps.MapTypeId.ROADMAP);
|
111
|
+
});
|
112
|
+
|
113
|
+
|
114
|
+
$('#set-hybrid').click(function () {
|
115
|
+
gmap.set_map_type(google.maps.MapTypeId.HYBRID);
|
116
|
+
});
|
117
|
+
|
118
|
+
|
119
|
+
$('#set-terrain').click(function () {
|
120
|
+
gmap.set_map_type(google.maps.MapTypeId.TERRAIN);
|
121
|
+
});
|
122
|
+
|
123
|
+
|
124
|
+
$.each(['markers', 'path'],function(i, ele){
|
125
|
+
|
126
|
+
$('#plot-' + ele).click(function () {
|
127
|
+
$('#plot-' + ele + '-modal').modal('show');
|
128
|
+
});
|
129
|
+
|
130
|
+
$('.plot-' + ele + '-button').click(function () {
|
131
|
+
var data = $('#plot-data-' + ele).val();
|
132
|
+
var points = $.parseJSON( data );
|
133
|
+
gmap.plot(points, { type: ele });
|
134
|
+
});
|
135
|
+
|
136
|
+
});
|
137
|
+
|
138
|
+
$('#plot-file').click(function () {
|
139
|
+
$('#plot-file-modal').modal('show');
|
140
|
+
});
|
141
|
+
|
142
|
+
$('.plot-file-button').click(function () {
|
143
|
+
var data = $('#plot-data-file').val();
|
144
|
+
|
145
|
+
$('#file-upload').submit(function (e) {
|
146
|
+
var file = document.getElementById('plot-data-file').files[0];
|
147
|
+
var data = new FormData();
|
148
|
+
var type = $('input[name=plot-type]:checked').val();
|
149
|
+
data.append('file',file);
|
150
|
+
data.append('plot-type', type)
|
151
|
+
|
152
|
+
$.ajax({
|
153
|
+
type: 'POST',
|
154
|
+
url: '/upload',
|
155
|
+
data: data,
|
156
|
+
processData: false,
|
157
|
+
contentType: false,
|
158
|
+
success: function(data){
|
159
|
+
var hash = data;
|
160
|
+
var points = hash['points'];
|
161
|
+
var type = hash['plot-type'];
|
162
|
+
gmap.plot(points, { type: type });
|
163
|
+
return false;
|
164
|
+
}
|
165
|
+
});
|
166
|
+
e.preventDefault();
|
167
|
+
return false;
|
168
|
+
});
|
169
|
+
|
170
|
+
$('#file-upload').trigger('submit');
|
171
|
+
|
172
|
+
});
|
173
|
+
|
174
|
+
|
175
|
+
$('.ui.radio.checkbox').checkbox();
|
@@ -0,0 +1,19 @@
|
|
1
|
+
{
|
2
|
+
"name": "gmap-explorer",
|
3
|
+
"version": "0.0.0",
|
4
|
+
"authors": [
|
5
|
+
"Alexander Rueedlinger <a.rueedlinger@gmail.com>"
|
6
|
+
],
|
7
|
+
"license": "MIT",
|
8
|
+
"private": true,
|
9
|
+
"ignore": [
|
10
|
+
"**/.*",
|
11
|
+
"node_modules",
|
12
|
+
"bower_components",
|
13
|
+
"test",
|
14
|
+
"tests"
|
15
|
+
],
|
16
|
+
"dependencies": {
|
17
|
+
"semantic-ui": "~1.5.2"
|
18
|
+
}
|
19
|
+
}
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module GmapPlotter
|
2
|
+
|
3
|
+
class Server < Sinatra::Base
|
4
|
+
helpers Sinatra::ContentFor
|
5
|
+
|
6
|
+
# make defaults explicit
|
7
|
+
set :public_folder, File.dirname(__FILE__) + '/public'
|
8
|
+
set :views, settings.root + '/views'
|
9
|
+
|
10
|
+
get '/' do
|
11
|
+
erb :main_layout do
|
12
|
+
erb :main
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
post '/upload' do
|
17
|
+
content_type :json
|
18
|
+
begin
|
19
|
+
a_hash = if params['file']
|
20
|
+
tmp_file = params['file'][:tempfile]
|
21
|
+
content = tmp_file.read
|
22
|
+
points = JSON.parse(content)
|
23
|
+
{
|
24
|
+
:'plot-type' => params['plot-type'],
|
25
|
+
:points => points
|
26
|
+
}
|
27
|
+
else
|
28
|
+
{
|
29
|
+
:'plot-type' => 'path',
|
30
|
+
:points => []
|
31
|
+
}
|
32
|
+
end
|
33
|
+
json a_hash
|
34
|
+
rescue
|
35
|
+
a_hash = {
|
36
|
+
:'plot-type' => 'path',
|
37
|
+
:points => []
|
38
|
+
}
|
39
|
+
json a_hash
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
<div class="ui modal" id="plot-file-modal">
|
2
|
+
<i class="close icon"></i>
|
3
|
+
<div class="header">
|
4
|
+
File upload
|
5
|
+
</div>
|
6
|
+
<div class="content">
|
7
|
+
|
8
|
+
<div class="description">
|
9
|
+
|
10
|
+
<p>Please upload a file whose content follows the json format below:</p>
|
11
|
+
<p>
|
12
|
+
<pre>
|
13
|
+
[
|
14
|
+
[-34.397, 150.644],
|
15
|
+
[-34.397, 150.644],
|
16
|
+
[-34.397, 150.644],
|
17
|
+
[-34.397, 150.644],
|
18
|
+
...
|
19
|
+
]
|
20
|
+
</pre>
|
21
|
+
</p>
|
22
|
+
<p>
|
23
|
+
A point corresponds to:
|
24
|
+
<pre>
|
25
|
+
[ lat_value, lng_value ]
|
26
|
+
</pre>
|
27
|
+
</p>
|
28
|
+
<form method="post" enctype="multipart/form-data" id="file-upload">
|
29
|
+
<div class="ui form">
|
30
|
+
<div class="grouped fields">
|
31
|
+
<label>File</label>
|
32
|
+
<div class="field">
|
33
|
+
<input name="File" type="file" accept="text/json" id="plot-data-file">
|
34
|
+
</div>
|
35
|
+
<label for="plot-type">Plot type</label>
|
36
|
+
<div class="field">
|
37
|
+
<div class="ui radio checkbox checked">
|
38
|
+
<input type="radio" name="plot-type" checked="" class="plot-type" value="path">
|
39
|
+
<label>Path</label>
|
40
|
+
</div>
|
41
|
+
</div>
|
42
|
+
<div class="field">
|
43
|
+
<div class="ui radio checkbox">
|
44
|
+
<input type="radio" name="plot-type" class="plot-type" value="markers">
|
45
|
+
<label>Markers</label>
|
46
|
+
</div>
|
47
|
+
</div>
|
48
|
+
</div>
|
49
|
+
|
50
|
+
</div>
|
51
|
+
</form>
|
52
|
+
</div>
|
53
|
+
</div>
|
54
|
+
<div class="actions">
|
55
|
+
<div class="ui black button">
|
56
|
+
Cancel
|
57
|
+
</div>
|
58
|
+
<div class="ui positive right labeled icon button plot-file-button">
|
59
|
+
Plot
|
60
|
+
<i class="checkmark icon"></i>
|
61
|
+
</div>
|
62
|
+
</div>
|
63
|
+
</div>
|