gmaps4rails 0.8.6 → 0.8.7
Sign up to get free protection for your applications and to get access to all the features.
- data/app/views/gmaps4rails/_gmaps4rails.html.erb +4 -9
- data/lib/acts_as_gmappable/base.rb +1 -1
- data/public/javascripts/gmaps4rails.js +32 -12
- data/test/dummy/app/models/user.rb +4 -4
- metadata +4 -10
- data/lib/rails/generators/gmaps4rails/gmaps4rails_generator.rb +0 -75
- data/lib/rails/generators/gmaps4rails/templates/initializer.rb +0 -8
- data/lib/rails/generators/gmaps4rails/templates/migration.rb +0 -9
- data/lib/rails/generators/gmaps4rails/templates/schema.rb +0 -11
- data/lib/rails/railties/tasks.rake +0 -8
- data/lib/tasks/install.rake +0 -9
@@ -7,6 +7,8 @@ if enable_css == true %>
|
|
7
7
|
|
8
8
|
<% content_for :scripts do %>
|
9
9
|
<% if enable_js == true %>
|
10
|
+
<script type="text/javascript" src='http://maps.google.com/maps/api/js?sensor=false&libraries=geometry'></script>
|
11
|
+
<script type="text/javascript" src='http://google-maps-utility-library-v3.googlecode.com/svn/tags/infobox/1.1.5/src/infobox.js'></script>
|
10
12
|
<%=javascript_include_tag 'gmaps4rails' %>
|
11
13
|
<script type="text/javascript" src='http://google-maps-utility-library-v3.googlecode.com/svn/tags/markerclusterer/1.0/src/markerclusterer_compiled.js'></script>
|
12
14
|
<% end %>
|
@@ -15,15 +17,8 @@ function gmaps4rails_init() {
|
|
15
17
|
<% #true is passed here to trigger map initialization %>
|
16
18
|
<%=raw options.to_gmaps4rails(true) %>
|
17
19
|
}
|
18
|
-
|
19
|
-
|
20
|
-
var script = document.createElement("script");
|
21
|
-
script.type = "text/javascript";
|
22
|
-
script.src = "http://maps.google.com/maps/api/js?sensor=false&libraries=geometry&callback=gmaps4rails_init";
|
23
|
-
document.body.appendChild(script);
|
24
|
-
}
|
25
|
-
|
26
|
-
window.onload = gmaps4rails_loadScript;
|
20
|
+
|
21
|
+
window.onload = gmaps4rails_init;
|
27
22
|
|
28
23
|
</script>
|
29
24
|
<% end %>
|
@@ -140,7 +140,7 @@ module Gmaps4rails
|
|
140
140
|
return true if gmaps4rails_options[:check_process] == true && self.send(gmaps4rails_options[:checker]) == true
|
141
141
|
begin
|
142
142
|
coordinates = Gmaps4rails.geocode(self.send(gmaps4rails_options[:address]))
|
143
|
-
rescue GeocodeStatus #address was invalid, add error to base.
|
143
|
+
rescue GeocodeStatus, GeocodeInvalidQuery #address was invalid, add error to base.
|
144
144
|
errors[gmaps4rails_options[:address]] << gmaps4rails_options[:msg] if gmaps4rails_options[:validation]
|
145
145
|
rescue GeocodeNetStatus => e #connection error, No need to prevent save.
|
146
146
|
logger.warn(e)
|
@@ -31,6 +31,7 @@ var Gmaps4Rails = {
|
|
31
31
|
picture : "",
|
32
32
|
width: 22,
|
33
33
|
length: 32,
|
34
|
+
draggable: false, // how to modify: <%= gmaps( "markers" => { "data" => @object.to_gmaps4rails, "options" => { "draggable" => true }}) %>
|
34
35
|
anchor: null, // centeranchor position of the marker image. Default is null <=> center, you can set options: top_left, top_center, top_right, center_left, center, center_right, bottom_right, bottom_center, bottom_left
|
35
36
|
//clustering config
|
36
37
|
do_clustering: true, // do clustering if set to true
|
@@ -39,7 +40,8 @@ var Gmaps4Rails = {
|
|
39
40
|
randomize: false, // Google maps can't display two markers which have the same coordinates. This randomizer enables to prevent this situation from happening.
|
40
41
|
max_random_distance: 100, // in meters. Each marker coordinate could be altered by this distance in a random direction
|
41
42
|
list_container: null, // id of the ul that will host links to all markers
|
42
|
-
custom_cluster_pictures: null
|
43
|
+
custom_cluster_pictures: null,
|
44
|
+
custom_infowindow_class: null,
|
43
45
|
},
|
44
46
|
|
45
47
|
//Stored variables
|
@@ -116,17 +118,22 @@ var Gmaps4Rails = {
|
|
116
118
|
|
117
119
|
findUserLocation: function() {
|
118
120
|
if(navigator.geolocation) {
|
121
|
+
//try to retrieve user's position
|
119
122
|
navigator.geolocation.getCurrentPosition(function(position) {
|
123
|
+
//saves the position in the userLocation variable
|
120
124
|
Gmaps4Rails.userLocation = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
|
121
|
-
//change map's center to focus on user's geoloc
|
125
|
+
//change map's center to focus on user's geoloc if asked
|
122
126
|
if(Gmaps4Rails.map_options.center_on_user === true) {
|
123
127
|
Gmaps4Rails.map.setCenter(Gmaps4Rails.userLocation);
|
124
128
|
}
|
125
129
|
},
|
126
130
|
function() {
|
131
|
+
//if failure, triggers the function if defined
|
127
132
|
if(this.fnSet("gmaps4rails_geolocation_failure")) { gmaps4rails_geolocation_failure(true); }
|
128
|
-
|
129
|
-
}
|
133
|
+
});
|
134
|
+
}
|
135
|
+
else {
|
136
|
+
//if failure, triggers the function if defined
|
130
137
|
if(this.fnSet("gmaps4rails_geolocation_failure")) { gmaps4rails_geolocation_failure(false); }
|
131
138
|
}
|
132
139
|
},
|
@@ -364,12 +371,13 @@ var Gmaps4Rails = {
|
|
364
371
|
var marker_height = this.exists(this.markers[i].height) ? this.markers[i].height : this.markers_conf.length;
|
365
372
|
var marker_anchor = this.exists(this.markers[i].anchor) ? this.markers[i].anchor : this.markers_conf.anchor;
|
366
373
|
var marker_title = this.exists(this.markers[i].title) ? this.markers[i].title : null;
|
374
|
+
var marker_draggable = this.exists(this.markers[i].draggable) ? this.markers[i].draggable : this.markers_conf.draggable;
|
367
375
|
var Lat = this.markers[i].latitude;
|
368
376
|
var Lng = this.markers[i].longitude;
|
369
377
|
var imageAnchorPosition = null;
|
370
378
|
// calculate MarkerImage anchor location
|
371
379
|
if (this.exists(this.markers[i].width) && this.exists(this.markers[i].height) && marker_anchor !== null) {
|
372
|
-
imageAnchorPosition = getImageAnchorPosition(marker_width, marker_height, marker_anchor);
|
380
|
+
imageAnchorPosition = this.getImageAnchorPosition(marker_width, marker_height, marker_anchor);
|
373
381
|
}
|
374
382
|
|
375
383
|
//alter coordinates if randomize is true
|
@@ -383,10 +391,10 @@ var Gmaps4Rails = {
|
|
383
391
|
var thisMarker;
|
384
392
|
// Marker sizes are expressed as a Size of X,Y
|
385
393
|
if (marker_picture === "") {
|
386
|
-
thisMarker = new google.maps.Marker({position: markerLatLng, map: this.map, title: marker_title});
|
394
|
+
thisMarker = new google.maps.Marker({position: markerLatLng, map: this.map, title: marker_title, draggable: marker_draggable});
|
387
395
|
} else {
|
388
396
|
var image = new google.maps.MarkerImage(marker_picture, new google.maps.Size(marker_width, marker_height), null, imageAnchorPosition, null );
|
389
|
-
thisMarker = new google.maps.Marker({position: markerLatLng, map: this.map, icon: image, title: marker_title});
|
397
|
+
thisMarker = new google.maps.Marker({position: markerLatLng, map: this.map, icon: image, title: marker_title, draggable: marker_draggable});
|
390
398
|
}
|
391
399
|
//save object
|
392
400
|
this.markers[i].google_object = thisMarker;
|
@@ -395,10 +403,11 @@ var Gmaps4Rails = {
|
|
395
403
|
//create sidebar if enabled
|
396
404
|
this.create_sidebar(this.markers[i]);
|
397
405
|
}
|
398
|
-
|
406
|
+
}
|
407
|
+
},
|
399
408
|
|
400
409
|
// calculate anchor point for MarkerImage
|
401
|
-
|
410
|
+
getImageAnchorPosition: function(markerWidth, markerHeight, anchorLocation) {
|
402
411
|
var x;
|
403
412
|
var y;
|
404
413
|
switch (anchorLocation) {
|
@@ -439,8 +448,7 @@ var Gmaps4Rails = {
|
|
439
448
|
y = markerHeight;
|
440
449
|
break;
|
441
450
|
}
|
442
|
-
|
443
|
-
}
|
451
|
+
return new google.maps.Point(x,y);
|
444
452
|
},
|
445
453
|
|
446
454
|
// clear markers
|
@@ -526,10 +534,22 @@ var Gmaps4Rails = {
|
|
526
534
|
|
527
535
|
// creates infowindows
|
528
536
|
create_info_window: function(marker_container){
|
537
|
+
var info_window;
|
538
|
+
if (this.markers_conf.custom_infowindow_class === null) {
|
529
539
|
//create the infowindow
|
530
|
-
|
540
|
+
info_window = new google.maps.InfoWindow({content: marker_container.description });
|
531
541
|
//add the listener associated
|
532
542
|
google.maps.event.addListener(marker_container.google_object, 'click', this.openInfoWindow(info_window, marker_container.google_object));
|
543
|
+
}
|
544
|
+
else { //creating custom infowindow
|
545
|
+
if (this.exists(marker_container.description)) {
|
546
|
+
var boxText = document.createElement("div");
|
547
|
+
boxText.setAttribute("class", this.markers_conf.custom_infowindow_class); //to customize
|
548
|
+
boxText.innerHTML = marker_container.description;
|
549
|
+
info_window = new InfoBox(gmaps4rails_infobox(boxText));
|
550
|
+
google.maps.event.addListener(marker_container.google_object, 'click', this.openInfoWindow(info_window, marker_container.google_object));
|
551
|
+
}
|
552
|
+
}
|
533
553
|
},
|
534
554
|
|
535
555
|
openInfoWindow: function(infoWindow, marker) {
|
@@ -7,10 +7,10 @@ class User < ActiveRecord::Base
|
|
7
7
|
end
|
8
8
|
|
9
9
|
#
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
def gmaps4rails_infowindow
|
11
|
+
"My Beautiful Name: #{name}"
|
12
|
+
end
|
13
|
+
|
14
14
|
# def gmaps4rails_marker_picture
|
15
15
|
# {
|
16
16
|
# "picture" => "http://www.blankdots.com/img/github-32x32.png",
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gmaps4rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 49
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 8
|
9
|
-
-
|
10
|
-
version: 0.8.
|
9
|
+
- 7
|
10
|
+
version: 0.8.7
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Benjamin Roth
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-05-
|
19
|
+
date: 2011-05-28 00:00:00 +02:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -53,12 +53,6 @@ files:
|
|
53
53
|
- lib/gmaps4rails.rb
|
54
54
|
- lib/gmaps4rails_helper.rb
|
55
55
|
- lib/hash.rb
|
56
|
-
- lib/rails/generators/gmaps4rails/gmaps4rails_generator.rb
|
57
|
-
- lib/rails/generators/gmaps4rails/templates/initializer.rb
|
58
|
-
- lib/rails/generators/gmaps4rails/templates/migration.rb
|
59
|
-
- lib/rails/generators/gmaps4rails/templates/schema.rb
|
60
|
-
- lib/rails/railties/tasks.rake
|
61
|
-
- lib/tasks/install.rake
|
62
56
|
- public/images/marker.png
|
63
57
|
- public/javascripts/gmaps4rails.js
|
64
58
|
- public/stylesheets/gmaps4rails.css
|
@@ -1,75 +0,0 @@
|
|
1
|
-
require 'rails/generators'
|
2
|
-
require 'rails/generators/migration'
|
3
|
-
|
4
|
-
class Gmaps4railsGenerator < Rails::Generators::Base
|
5
|
-
include Rails::Generators::Migration
|
6
|
-
|
7
|
-
def self.source_root
|
8
|
-
File.join(File.dirname(__FILE__), 'templates')
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.next_migration_number(dirname) #:nodoc:
|
12
|
-
if ActiveRecord::Base.timestamped_migrations
|
13
|
-
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
14
|
-
else
|
15
|
-
"%.3d" % (current_migration_number(dirname) + 1)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
|
20
|
-
# Every method that is declared below will be automatically executed when the generator is run
|
21
|
-
|
22
|
-
def create_migration_file
|
23
|
-
f = File.open File.join(File.dirname(__FILE__), 'templates', 'schema.rb')
|
24
|
-
schema = f.read; f.close
|
25
|
-
|
26
|
-
schema.gsub!(/ActiveRecord::Schema.*\n/, '')
|
27
|
-
schema.gsub!(/^end\n*$/, '')
|
28
|
-
|
29
|
-
f = File.open File.join(File.dirname(__FILE__), 'templates', 'migration.rb')
|
30
|
-
migration = f.read; f.close
|
31
|
-
migration.gsub!(/SCHEMA_AUTO_INSERTED_HERE/, schema)
|
32
|
-
|
33
|
-
tmp = File.open "tmp/~migration_ready.rb", "w"
|
34
|
-
tmp.write migration
|
35
|
-
tmp.close
|
36
|
-
|
37
|
-
migration_template '../../../tmp/~migration_ready.rb',
|
38
|
-
'db/migrate/create_gmaps4rails_tables.rb'
|
39
|
-
remove_file 'tmp/~migration_ready.rb'
|
40
|
-
end
|
41
|
-
|
42
|
-
def copy_initializer_file
|
43
|
-
copy_file 'initializer.rb', 'config/initializers/gmaps4rails.rb'
|
44
|
-
end
|
45
|
-
|
46
|
-
def update_application_template
|
47
|
-
f = File.open "app/views/layouts/application.html.erb"
|
48
|
-
layout = f.read; f.close
|
49
|
-
|
50
|
-
if layout =~ /<%=[ ]+yield[ ]+%>/
|
51
|
-
print " \e[1m\e[34mquestion\e[0m Your layouts/application.html.erb layout currently has the line <%= yield %>. This gem needs to change this line to <%= content_for?(:content) ? yield(:content) : yield %> to support its nested layouts. This change should not affect any of your existing layouts or views. Is this okay? [y/n] "
|
52
|
-
begin
|
53
|
-
answer = gets.chomp
|
54
|
-
end while not answer =~ /[yn]/i
|
55
|
-
|
56
|
-
if answer =~ /y/i
|
57
|
-
|
58
|
-
layout.gsub!(/<%=[ ]+yield[ ]+%>/, '<%= content_for?(:content) ? yield(:content) : yield %>')
|
59
|
-
|
60
|
-
tmp = File.open "tmp/~application.html.erb", "w"
|
61
|
-
tmp.write layout; tmp.close
|
62
|
-
|
63
|
-
remove_file 'app/views/layouts/application.html.erb'
|
64
|
-
copy_file '../../../tmp/~application.html.erb',
|
65
|
-
'app/views/layouts/application.html.erb'
|
66
|
-
remove_file 'tmp/~application.html.erb'
|
67
|
-
end
|
68
|
-
elsif layout =~ /<%=[ ]+content_for\?\(:content\) \? yield\(:content\) : yield[ ]+%>/
|
69
|
-
puts " \e[1m\e[33mskipping\e[0m layouts/application.html.erb modification is already done."
|
70
|
-
else
|
71
|
-
puts " \e[1m\e[31mconflict\e[0m The gem is confused by your layouts/application.html.erb. It does not contain the default line <%= yield %>, you may need to make manual changes to get this gem's nested layouts working. Visit ###### for details."
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
end
|
data/lib/tasks/install.rake
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
namespace :gmaps4rails do
|
2
|
-
desc "Copies all migrations and assets (NOTE: This will be obsolete with Rails 3.1)"
|
3
|
-
task :install do
|
4
|
-
source = File.join(File.dirname(__FILE__), '..', '..', 'public')
|
5
|
-
destination = File.join(Rails.root, 'public')
|
6
|
-
puts "INFO: Mirroring assets from #{source} to #{destination}"
|
7
|
-
Spree::FileUtilz.mirror_files(source, destination)
|
8
|
-
end
|
9
|
-
end
|