jquery-geolocateMap-rails 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.markdown +35 -0
- data/Rakefile +1 -0
- data/app/.DS_Store +0 -0
- data/app/assets/.DS_Store +0 -0
- data/app/assets/javascripts/jquery.geolocateMap.js +200 -0
- data/jquery-geolocatemap-rails.gemspec +21 -0
- data/lib/jquery-geolocatemap-rails.rb +10 -0
- data/lib/jquery-geolocatemap-rails/version.rb +7 -0
- metadata +78 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Adrian Gonzalez
|
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.markdown
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# jquery-geolocateMap-rails
|
2
|
+
|
3
|
+
jquery-geolocateMap-rails integrates geolocateMap jquery plugin to Rails 3.1 Asset Pipeline (Rails 3.2 supported)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'jquery-geolocateMap-rails'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install jquery-geolocateMap-rails
|
18
|
+
|
19
|
+
## Add jquery-geolocateMap-rails js assets
|
20
|
+
add to your app/assets/javascripts/application.js
|
21
|
+
|
22
|
+
```javascript
|
23
|
+
//= require jquery-geolocateMap-rails
|
24
|
+
```
|
25
|
+
|
26
|
+
## Author
|
27
|
+
* [Adrián González](http://github.com/Adrian2112)
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
1. Fork it
|
32
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
33
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
34
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
35
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/app/.DS_Store
ADDED
Binary file
|
Binary file
|
@@ -0,0 +1,200 @@
|
|
1
|
+
// Generated by CoffeeScript 1.4.0
|
2
|
+
(function() {
|
3
|
+
var GeolocateMap, Marker, version,
|
4
|
+
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
|
5
|
+
|
6
|
+
GeolocateMap = (function() {
|
7
|
+
|
8
|
+
function GeolocateMap($element, settings) {
|
9
|
+
var markers_options,
|
10
|
+
_this = this;
|
11
|
+
this.map = new google.maps.Map($element[0], settings['google_maps']);
|
12
|
+
this.markers = Marker.markers_from_objects(this.map, settings['markers'], settings['markers_settings']);
|
13
|
+
markers_options = settings['markers_settings'];
|
14
|
+
if (markers_options['fit_bounds']) {
|
15
|
+
if (this.markers.length > 2) {
|
16
|
+
this.map.fitBounds(Marker.bounds_for_markers(this.markers));
|
17
|
+
} else if (this.markers.length === 1) {
|
18
|
+
this.map.setCenter(this.markers[0].get_position());
|
19
|
+
}
|
20
|
+
}
|
21
|
+
if (settings['locate_me'] && navigator.geolocation) {
|
22
|
+
navigator.geolocation.getCurrentPosition((function(position) {
|
23
|
+
_this.marker_me = new Marker(_this.map, {
|
24
|
+
lat: position.coords.latitude,
|
25
|
+
lng: position.coords.longitude
|
26
|
+
}, settings['locate_me_marker']);
|
27
|
+
return _this.map.setCenter(_this.marker_me.get_position());
|
28
|
+
}), (function(msg) {
|
29
|
+
return console.log("geolocation error: " + (JSON.stringify(msg)));
|
30
|
+
}));
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
34
|
+
return GeolocateMap;
|
35
|
+
|
36
|
+
})();
|
37
|
+
|
38
|
+
(function($) {
|
39
|
+
var defaults, methods;
|
40
|
+
defaults = {
|
41
|
+
google_maps: {
|
42
|
+
zoom: 0,
|
43
|
+
center: new google.maps.LatLng(0.0, 0.0),
|
44
|
+
mapTypeId: google.maps.MapTypeId.ROADMAP,
|
45
|
+
scaleControl: true
|
46
|
+
},
|
47
|
+
markers: [],
|
48
|
+
markers_settings: {
|
49
|
+
fit_bounds: true,
|
50
|
+
draggable: true
|
51
|
+
},
|
52
|
+
locate_me: false,
|
53
|
+
locate_me_marker: {
|
54
|
+
draggable: false
|
55
|
+
}
|
56
|
+
};
|
57
|
+
methods = {
|
58
|
+
init: function(args) {
|
59
|
+
var settings;
|
60
|
+
settings = $.extend(true, {}, defaults, args);
|
61
|
+
return this.data("geolocate_map", new GeolocateMap(this, settings));
|
62
|
+
}
|
63
|
+
};
|
64
|
+
return $.fn.geolocateMap = function(method) {
|
65
|
+
if (methods[method]) {
|
66
|
+
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
|
67
|
+
} else if (typeof method === 'object' || !method) {
|
68
|
+
return methods.init.apply(this, arguments);
|
69
|
+
} else {
|
70
|
+
return $.error("Method " + method + " does not exist on jQuery.geolocateMap");
|
71
|
+
}
|
72
|
+
};
|
73
|
+
})(jQuery);
|
74
|
+
|
75
|
+
Marker = (function() {
|
76
|
+
|
77
|
+
function Marker(map, data, settings) {
|
78
|
+
this.sync_inputs = __bind(this.sync_inputs, this);
|
79
|
+
|
80
|
+
var latitude, longitude, marker_position, pos;
|
81
|
+
latitude = data['lat'];
|
82
|
+
longitude = data['lng'];
|
83
|
+
pos = new google.maps.LatLng(latitude, longitude);
|
84
|
+
marker_position = {
|
85
|
+
'position': pos,
|
86
|
+
'map': map
|
87
|
+
};
|
88
|
+
settings = $.extend({}, settings, data, marker_position);
|
89
|
+
this.gmark = new google.maps.Marker(settings);
|
90
|
+
this.sync_inputs(settings);
|
91
|
+
}
|
92
|
+
|
93
|
+
Marker.prototype.get_position = function() {
|
94
|
+
return this.gmark.getPosition();
|
95
|
+
};
|
96
|
+
|
97
|
+
Marker.prototype.set_position = function(latLng) {
|
98
|
+
return this.gmark.setPosition(latLng);
|
99
|
+
};
|
100
|
+
|
101
|
+
Marker.markers_from_objects = function(map, markers, settings) {
|
102
|
+
return $(markers).map(function(i, e) {
|
103
|
+
return new Marker(map, e, settings);
|
104
|
+
});
|
105
|
+
};
|
106
|
+
|
107
|
+
Marker.bounds_for_markers = function(markers) {
|
108
|
+
var bounds;
|
109
|
+
bounds = new google.maps.LatLngBounds();
|
110
|
+
markers.each(function(i, marker) {
|
111
|
+
var latlng;
|
112
|
+
if (marker instanceof Marker) {
|
113
|
+
latlng = marker.gmark.getPosition();
|
114
|
+
return bounds.extend(latlng);
|
115
|
+
}
|
116
|
+
});
|
117
|
+
return bounds;
|
118
|
+
};
|
119
|
+
|
120
|
+
Marker.prototype.sync_inputs = function(settings) {
|
121
|
+
var $address, $lat, $lng,
|
122
|
+
_this = this;
|
123
|
+
if (settings['sync_inputs']) {
|
124
|
+
$lat = $(settings['sync_inputs']['lat']);
|
125
|
+
$lng = $(settings['sync_inputs']['lng']);
|
126
|
+
$address = $(settings['sync_inputs']['address']);
|
127
|
+
if ($lat) {
|
128
|
+
$lat.val(this.get_position().lat());
|
129
|
+
$lat.on('change', function() {
|
130
|
+
return _this.set_position(new google.maps.LatLng($lat.val(), _this.get_position().lng()));
|
131
|
+
});
|
132
|
+
}
|
133
|
+
if ($lng) {
|
134
|
+
$lng.val(this.get_position().lng());
|
135
|
+
$lng.on('change', function() {
|
136
|
+
return _this.set_position(new google.maps.LatLng(_this.get_position().lat(), $lng.val()));
|
137
|
+
});
|
138
|
+
}
|
139
|
+
if ($address) {
|
140
|
+
this.set_address_to_input($address);
|
141
|
+
$address.on('change', function() {
|
142
|
+
var geocoder;
|
143
|
+
geocoder = new google.maps.Geocoder();
|
144
|
+
return geocoder.geocode({
|
145
|
+
address: $address.val()
|
146
|
+
}, function(result, status) {
|
147
|
+
var map, position;
|
148
|
+
position = result[0].geometry.location;
|
149
|
+
map = this.getMap();
|
150
|
+
map.setCenter(position);
|
151
|
+
map.setZoom(15);
|
152
|
+
return this.set_position(position);
|
153
|
+
});
|
154
|
+
});
|
155
|
+
}
|
156
|
+
return google.maps.event.addListener(this.gmark, 'dragend', function() {
|
157
|
+
var map, position;
|
158
|
+
map = _this.map;
|
159
|
+
position = _this.get_position();
|
160
|
+
if ($lat) {
|
161
|
+
$lat.val(position.lat());
|
162
|
+
}
|
163
|
+
if ($lng) {
|
164
|
+
$lng.val(position.lng());
|
165
|
+
}
|
166
|
+
if ($address) {
|
167
|
+
return _this.set_address_to_input($address);
|
168
|
+
}
|
169
|
+
});
|
170
|
+
}
|
171
|
+
};
|
172
|
+
|
173
|
+
Marker.prototype.set_address_to_input = function($address) {
|
174
|
+
var geocoder, latLng;
|
175
|
+
geocoder = new google.maps.Geocoder();
|
176
|
+
latLng = this.get_position();
|
177
|
+
return geocoder.geocode({
|
178
|
+
'latLng': latLng
|
179
|
+
}, function(results, status) {
|
180
|
+
if (status === google.maps.GeocoderStatus.OK) {
|
181
|
+
if (results[0]) {
|
182
|
+
return $address.val(results[0].formatted_address);
|
183
|
+
} else {
|
184
|
+
console.log("geocoder not found");
|
185
|
+
return $address.val("");
|
186
|
+
}
|
187
|
+
} else {
|
188
|
+
console.log("geocoder fail: " + status);
|
189
|
+
return $address.val("");
|
190
|
+
}
|
191
|
+
});
|
192
|
+
};
|
193
|
+
|
194
|
+
return Marker;
|
195
|
+
|
196
|
+
})();
|
197
|
+
|
198
|
+
version = 0.1;
|
199
|
+
|
200
|
+
}).call(this);
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'jquery-geolocatemap-rails/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "jquery-geolocateMap-rails"
|
8
|
+
gem.version = Jquery::Geolocatemap::Rails::VERSION
|
9
|
+
gem.authors = ["Adrian Gonzalez"]
|
10
|
+
gem.email = ["adrian@icalialabs.com"]
|
11
|
+
gem.description = %q{jquery.geolocateMap integration with rails 3.1 Asset pipeline}
|
12
|
+
gem.summary = %q{jquery.geolocateMap integration with rails 3.1 Asset pipeline}
|
13
|
+
gem.homepage = "https://github.com/IcaliaLabs/jquery.geolocateMap-rails"
|
14
|
+
|
15
|
+
gem.rubyforge_project = "jquery-geolocateMap-rails"
|
16
|
+
|
17
|
+
gem.files = `git ls-files`.split($/)
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_dependency "railties", "~> 3.1"
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jquery-geolocateMap-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.2'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Adrian Gonzalez
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-22 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: railties
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3.1'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.1'
|
30
|
+
description: jquery.geolocateMap integration with rails 3.1 Asset pipeline
|
31
|
+
email:
|
32
|
+
- adrian@icalialabs.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- Gemfile
|
39
|
+
- LICENSE.txt
|
40
|
+
- README.markdown
|
41
|
+
- Rakefile
|
42
|
+
- app/.DS_Store
|
43
|
+
- app/assets/.DS_Store
|
44
|
+
- app/assets/javascripts/jquery.geolocateMap.js
|
45
|
+
- jquery-geolocatemap-rails.gemspec
|
46
|
+
- lib/jquery-geolocatemap-rails.rb
|
47
|
+
- lib/jquery-geolocatemap-rails/version.rb
|
48
|
+
homepage: https://github.com/IcaliaLabs/jquery.geolocateMap-rails
|
49
|
+
licenses: []
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options: []
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ! '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
hash: 3019174655847759856
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
hash: 3019174655847759856
|
72
|
+
requirements: []
|
73
|
+
rubyforge_project: jquery-geolocateMap-rails
|
74
|
+
rubygems_version: 1.8.24
|
75
|
+
signing_key:
|
76
|
+
specification_version: 3
|
77
|
+
summary: jquery.geolocateMap integration with rails 3.1 Asset pipeline
|
78
|
+
test_files: []
|