gmaps4rails 1.4.8 → 1.5.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +11 -0
- data/.travis.yml +10 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +175 -0
- data/Guardfile +38 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +26 -37
- data/Rakefile +4 -0
- data/app/assets/javascripts/gmaps4rails/gmaps4rails.base.js.coffee +40 -34
- data/app/assets/javascripts/gmaps4rails/gmaps4rails.googlemaps.js.coffee +4 -2
- data/app/views/gmaps4rails/_gmaps4rails.html.erb +13 -12
- data/gmaps4rails.gemspec +38 -0
- data/lib/gmaps4rails.rb +0 -8
- data/lib/gmaps4rails/acts_as_gmappable.rb +55 -33
- data/lib/gmaps4rails/base.rb +7 -12
- data/lib/gmaps4rails/helper/gmaps4rails_helper.rb +16 -42
- data/lib/gmaps4rails/js_builder.rb +121 -0
- data/lib/gmaps4rails/json_builder.rb +127 -0
- data/lib/gmaps4rails/version.rb +3 -0
- data/lib/gmaps4rails/view_helper.rb +171 -0
- data/lib/tasks/gmaps4rails_tasks.rake +4 -0
- data/lib/tasks/jasmine.rake +8 -0
- data/public/javascripts/gmaps4rails/gmaps4rails.base.js +81 -30
- data/public/javascripts/gmaps4rails/gmaps4rails.bing.js +34 -11
- data/public/javascripts/gmaps4rails/gmaps4rails.googlemaps.js +45 -21
- data/public/javascripts/gmaps4rails/gmaps4rails.mapquest.js +33 -14
- data/public/javascripts/gmaps4rails/gmaps4rails.openlayers.js +33 -20
- data/spec/base/base_spec.rb +185 -0
- data/spec/base/geocoding_spec.rb +17 -0
- data/spec/dummy/.gitignore +2 -0
- data/spec/dummy/.rspec +1 -0
- data/spec/dummy/README.rdoc +261 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +15 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/assets/stylesheets/gmaps4rails.css +24 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/controllers/users_controller.rb +96 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.gitkeep +0 -0
- data/spec/dummy/app/models/.gitkeep +0 -0
- data/spec/dummy/app/models/user.rb +9 -0
- data/spec/dummy/app/views/layouts/application.html.erb +16 -0
- data/spec/dummy/app/views/users/_form.html.erb +37 -0
- data/spec/dummy/app/views/users/_my_template.html.erb +2 -0
- data/spec/dummy/app/views/users/_my_template2.html.erb +1 -0
- data/spec/dummy/app/views/users/ajax_data.js.erb +2 -0
- data/spec/dummy/app/views/users/ajax_test.html.erb +22 -0
- data/spec/dummy/app/views/users/edit.html.erb +6 -0
- data/spec/dummy/app/views/users/index.html.erb +238 -0
- data/spec/dummy/app/views/users/new.html.erb +5 -0
- data/spec/dummy/app/views/users/show.html.erb +30 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +62 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/production.rb +67 -0
- data/spec/dummy/config/environments/test.rb +37 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +15 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +60 -0
- data/spec/dummy/db/migrate/20120408170155_create_users.rb +16 -0
- data/spec/dummy/db/schema.rb +29 -0
- data/spec/dummy/lib/assets/.gitkeep +0 -0
- data/spec/dummy/log/.gitkeep +0 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +25 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/javascripts/Player.js +22 -0
- data/spec/dummy/public/javascripts/Song.js +7 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/factories/user_factory.rb +23 -0
- data/spec/javascripts/basic_methods_spec.js +103 -0
- data/spec/javascripts/helpers/.gitkeep +0 -0
- data/spec/javascripts/helpers/SpecHelper.js +87 -0
- data/spec/javascripts/map_spec.js +49 -0
- data/spec/javascripts/markers_methods_spec.js +368 -0
- data/spec/javascripts/mocks_spec.js +27 -0
- data/spec/javascripts/support/jasmine.yml +76 -0
- data/spec/javascripts/support/jasmine_config.rb +23 -0
- data/spec/javascripts/support/jasmine_runner.rb +20 -0
- data/spec/launchers/all_but_requests.rb +0 -0
- data/spec/launchers/all_specs.rb +0 -0
- data/spec/launchers/requests.rb +0 -0
- data/spec/models/user_spec.rb +447 -0
- data/spec/spec_helper.rb +44 -0
- data/spec/support/geocoding.rb +14 -0
- data/spec/support/matchers.rb +43 -0
- metadata +364 -31
- data/LICENSE.txt +0 -21
- data/app/assets/javascripts/gmaps4rails/all_apis.js +0 -5
- data/app/assets/javascripts/gmaps4rails/bing.js +0 -2
- data/app/assets/javascripts/gmaps4rails/googlemaps.js +0 -2
- data/app/assets/javascripts/gmaps4rails/mapquest.js +0 -2
- data/app/assets/javascripts/gmaps4rails/openlayers.js +0 -2
- data/app/views/gmaps4rails/_html.html.erb +0 -12
- data/app/views/gmaps4rails/_scripts.html.erb +0 -37
- data/lib/gmaps4rails/js_handler.rb +0 -112
- data/lib/gmaps4rails/json_handler.rb +0 -116
- data/public/images/marker.png +0 -0
@@ -0,0 +1,127 @@
|
|
1
|
+
module Gmaps4rails
|
2
|
+
|
3
|
+
def Gmaps4rails.create_json(object, &block)
|
4
|
+
json_handler = ::Gmaps4rails::JsonBuilder.new(object, &block)
|
5
|
+
json_handler.process(&block)
|
6
|
+
end
|
7
|
+
|
8
|
+
# the to_gmaps4rails method accepts a block to customize:
|
9
|
+
# - infowindow
|
10
|
+
# - picture
|
11
|
+
# - title
|
12
|
+
# - sidebar
|
13
|
+
# - json
|
14
|
+
#
|
15
|
+
# This works this way:
|
16
|
+
# @json = User.all.to_gmaps4rails do |user, marker|
|
17
|
+
# marker.infowindow render_to_string(:partial => "/users/my_template", :locals => { :object => user}).gsub(/\n/, '').gsub(/"/, '\"')
|
18
|
+
# marker.picture({
|
19
|
+
# :picture => "http://www.blankdots.com/img/github-32x32.png",
|
20
|
+
# :width => "32",
|
21
|
+
# :height => "32"
|
22
|
+
# })
|
23
|
+
# marker.title "i'm the title"
|
24
|
+
# marker.sidebar "i'm the sidebar"
|
25
|
+
# marker.json({ :id => user.id })
|
26
|
+
# end
|
27
|
+
#
|
28
|
+
# For backward compability, a mere string could be passed:
|
29
|
+
# @json = User.all.to_gmaps4rails do |user, marker|
|
30
|
+
# "\"id\": #{user.id}"
|
31
|
+
# end
|
32
|
+
#
|
33
|
+
class JsonBuilder
|
34
|
+
|
35
|
+
def initialize(object)
|
36
|
+
@object, @json_hash, @custom_json = object, Hash.new, nil
|
37
|
+
end
|
38
|
+
|
39
|
+
def process(&block)
|
40
|
+
if compliant?
|
41
|
+
handle_block(&block) if block_given?
|
42
|
+
handle_model_methods
|
43
|
+
return_json
|
44
|
+
else
|
45
|
+
nil
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def infowindow(string)
|
50
|
+
@json_hash[:description] = string
|
51
|
+
true
|
52
|
+
end
|
53
|
+
|
54
|
+
def title(string)
|
55
|
+
@json_hash[:title] = string
|
56
|
+
true
|
57
|
+
end
|
58
|
+
|
59
|
+
def sidebar(string)
|
60
|
+
@json_hash[:sidebar] = string
|
61
|
+
true
|
62
|
+
end
|
63
|
+
|
64
|
+
def json(json)
|
65
|
+
return @json_hash.merge! json if json.is_a? Hash
|
66
|
+
true
|
67
|
+
end
|
68
|
+
|
69
|
+
def picture(hash)
|
70
|
+
@json_hash.merge! hash
|
71
|
+
true
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def model_attributes
|
77
|
+
{
|
78
|
+
:description => :gmaps4rails_infowindow,
|
79
|
+
:title => :gmaps4rails_title,
|
80
|
+
:sidebar => :gmaps4rails_sidebar,
|
81
|
+
:marker_picture => :gmaps4rails_marker_picture,
|
82
|
+
:lat => @object.gmaps4rails_options[:lat_column],
|
83
|
+
:lng => @object.gmaps4rails_options[:lng_column]
|
84
|
+
}
|
85
|
+
end
|
86
|
+
|
87
|
+
def handle_model_methods
|
88
|
+
model_attributes.each do |json_name, method_name|
|
89
|
+
if @object.respond_to? method_name
|
90
|
+
if json_name == :marker_picture
|
91
|
+
@json_hash.merge!(@object.send(method_name))
|
92
|
+
else
|
93
|
+
@json_hash[json_name] = @object.send(method_name) unless @json_hash.has_key? json_name
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
# returns the proper json
|
100
|
+
# three cases here:
|
101
|
+
# - no custom json provided
|
102
|
+
# - custom json provided as a hash (marker.json { :id => user.id }) => merge hashes then create json
|
103
|
+
# - custom json provided as string (marker.json {"\"id\": #{user.id}" } => create json from hash then insert string inside
|
104
|
+
def return_json
|
105
|
+
return @json_hash.to_json if @custom_json.nil?
|
106
|
+
case @custom_json
|
107
|
+
when Hash
|
108
|
+
@json_hash.merge! @custom_json
|
109
|
+
return @json_hash.to_json
|
110
|
+
when String
|
111
|
+
output = @json_hash.to_json
|
112
|
+
return output.insert(1, @custom_json + ",")
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def compliant?
|
117
|
+
!(@object.send(@object.gmaps4rails_options[:lat_column]).blank? && @object.send(@object.gmaps4rails_options[:lng_column]).blank?)
|
118
|
+
end
|
119
|
+
|
120
|
+
def handle_block(&block)
|
121
|
+
block_result = yield(@object, self)
|
122
|
+
@custom_json = block_result unless block_result == true
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
@@ -0,0 +1,171 @@
|
|
1
|
+
module Gmaps4rails
|
2
|
+
|
3
|
+
class ViewHelper
|
4
|
+
|
5
|
+
OPENLAYERS = "http://www.openlayers.org/api/OpenLayers.js"
|
6
|
+
MAPQUEST = "http://mapquestapi.com/sdk/js/v6.0.0/mqa.toolkit.js"
|
7
|
+
BING = "http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"
|
8
|
+
GOOGLE = "//maps.google.com/maps/api/js?v=3.8"
|
9
|
+
GOOGLE_EXT = "//google-maps-utility-library-v3.googlecode.com/svn/"
|
10
|
+
|
11
|
+
# options is the hash passed to the 'gmaps' helper
|
12
|
+
# looks like:
|
13
|
+
#{
|
14
|
+
# :map_options => hash,
|
15
|
+
# :markers => { :data => json, :options => hash },
|
16
|
+
# :polylines => { :data => json, :options => hash },
|
17
|
+
# :polygons => { :data => json, :options => hash },
|
18
|
+
# :circles => { :data => json, :options => hash },
|
19
|
+
# :direction => { :data => hash, :options => hash },
|
20
|
+
# :kml => { :data => json, :options => hash }
|
21
|
+
#}
|
22
|
+
# should be with only symbol keys or with indifferent access
|
23
|
+
def initialize(options = {})
|
24
|
+
@options = options
|
25
|
+
@js_array = Array.new
|
26
|
+
end
|
27
|
+
|
28
|
+
# outputs an array containing the path to all required js files
|
29
|
+
# this list is deduced from the options passed
|
30
|
+
def js_dependencies_array
|
31
|
+
if scripts != :none
|
32
|
+
get_vendor_scripts
|
33
|
+
get_gem_scripts
|
34
|
+
end
|
35
|
+
@js_array
|
36
|
+
end
|
37
|
+
|
38
|
+
# outputs an object containing the basic information to fill the map's dom attributes
|
39
|
+
def dom_attributes
|
40
|
+
OpenStruct.new({
|
41
|
+
:map_id => map_id,
|
42
|
+
:map_class => map_class,
|
43
|
+
:container_class => container_class,
|
44
|
+
:provider => map_provider
|
45
|
+
})
|
46
|
+
end
|
47
|
+
|
48
|
+
# gem's script aren't taken into account when asset pipeline is enabled:
|
49
|
+
# I assume they'll be within
|
50
|
+
def get_gem_scripts
|
51
|
+
unless gmaps4rails_pipeline_enabled?
|
52
|
+
@js_array << '/gmaps4rails/gmaps4rails.base.js' unless scripts == :api
|
53
|
+
@js_array << case map_provider
|
54
|
+
when "openlayers" then '/gmaps4rails/gmaps4rails.openlayers.js'
|
55
|
+
when "mapquest" then '/gmaps4rails/gmaps4rails.mapquest.js'
|
56
|
+
when "bing" then '/gmaps4rails/gmaps4rails.bing.js'
|
57
|
+
else '/gmaps4rails/gmaps4rails.googlemaps.js'
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# vendor_scripts are the js libraries from the map providers
|
63
|
+
def get_vendor_scripts
|
64
|
+
case map_provider
|
65
|
+
when "openlayers" then @js_array << OPENLAYERS
|
66
|
+
when "mapquest" then @js_array << "#{MAPQUEST}?key=#{provider_key}"
|
67
|
+
when "bing" then @js_array << BING
|
68
|
+
else #case googlemaps which is the default
|
69
|
+
@js_array << "#{GOOGLE}&sensor=false&key=#{provider_key}&libraries=geometry#{google_libraries}&#{google_map_i18n}"
|
70
|
+
@js_array << "#{GOOGLE_EXT}tags/infobox/1.1.9/src/infobox_packed.js" if custom_infowindow_class
|
71
|
+
@js_array << "#{GOOGLE_EXT}tags/markerclustererplus/2.0.5/src/markerclusterer_packed.js" if do_clustering
|
72
|
+
@js_array << "#{GOOGLE_EXT}trunk/richmarker/src/richmarker-compiled.js" if rich_marker
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
# checks whether or not the app has pipeline enabled
|
79
|
+
# works for Rails 3.0.x and above
|
80
|
+
# @return [Boolean]
|
81
|
+
def gmaps4rails_pipeline_enabled?
|
82
|
+
Rails.configuration.respond_to?('assets') && Rails.configuration.assets.enabled
|
83
|
+
end
|
84
|
+
|
85
|
+
def map_options
|
86
|
+
@map_options ||= @options[:map_options]
|
87
|
+
end
|
88
|
+
|
89
|
+
def marker_options
|
90
|
+
@marker_options ||= @options[:markers].try(:[],:options)
|
91
|
+
end
|
92
|
+
|
93
|
+
#
|
94
|
+
def map_provider
|
95
|
+
@map_provider ||= map_options.try(:[], :provider)
|
96
|
+
end
|
97
|
+
|
98
|
+
# the scripts option can have the following values
|
99
|
+
# - :api => only the js related to the map api is inserted
|
100
|
+
# - :none => no javascript inserted
|
101
|
+
# - anything else => base javascript + map api javascript inserted
|
102
|
+
def scripts
|
103
|
+
@scripts ||= @options[:scripts].try(:to_sym)
|
104
|
+
end
|
105
|
+
|
106
|
+
# could be one of the following:
|
107
|
+
# - "openlayers"
|
108
|
+
# - "mapquest"
|
109
|
+
# - "bing"
|
110
|
+
# - anything else which would default to googlemaps
|
111
|
+
def provider_key
|
112
|
+
map_options.try(:[], :provider_key)
|
113
|
+
end
|
114
|
+
|
115
|
+
# when custom_infowindow_class is added in the marker_options,
|
116
|
+
#it means user wants to use the InfoBox googlemap's plugin
|
117
|
+
def custom_infowindow_class
|
118
|
+
marker_options.try(:[], :custom_infowindow_class)
|
119
|
+
end
|
120
|
+
|
121
|
+
# do_clustering tells whether or not the js marker clustering library should be loaded
|
122
|
+
def do_clustering
|
123
|
+
marker_options.try(:[], :do_clustering)
|
124
|
+
end
|
125
|
+
|
126
|
+
# libraries should be an array of string containing the additional js library the user
|
127
|
+
# wants from google.
|
128
|
+
# Ex: [ "places" ]
|
129
|
+
def google_libraries
|
130
|
+
libraries_array = map_options.try(:[], :libraries)
|
131
|
+
return "" if libraries_array.nil?
|
132
|
+
"," + libraries_array.join(",")
|
133
|
+
end
|
134
|
+
|
135
|
+
# google maps could be "i18n"ed
|
136
|
+
def google_map_i18n
|
137
|
+
"language=#{language}&hl=#{hl}®ion=#{region}"
|
138
|
+
end
|
139
|
+
|
140
|
+
def language
|
141
|
+
map_options.try(:[], :language)
|
142
|
+
end
|
143
|
+
|
144
|
+
def hl
|
145
|
+
map_options.try(:[], :hl)
|
146
|
+
end
|
147
|
+
|
148
|
+
def region
|
149
|
+
map_options.try(:[], :region)
|
150
|
+
end
|
151
|
+
|
152
|
+
def rich_marker
|
153
|
+
marker_options.try(:[], :rich_marker)
|
154
|
+
end
|
155
|
+
|
156
|
+
def map_id
|
157
|
+
map_options.try(:[], :id) || Gmaps4rails::JsBuilder::DEFAULT_MAP_ID
|
158
|
+
end
|
159
|
+
|
160
|
+
def map_class
|
161
|
+
default_class = map_options.try(:[], :provider) == "bing" ? "bing_map" : "gmaps4rails_map"
|
162
|
+
map_options.try(:[], :class) || default_class
|
163
|
+
end
|
164
|
+
|
165
|
+
def container_class
|
166
|
+
map_options.try(:[], :container_class) || "map_container"
|
167
|
+
end
|
168
|
+
|
169
|
+
end
|
170
|
+
|
171
|
+
end
|
@@ -1,18 +1,32 @@
|
|
1
1
|
(function() {
|
2
2
|
var Gmaps;
|
3
|
+
|
3
4
|
Gmaps = {};
|
5
|
+
|
6
|
+
Gmaps.triggerOldOnload = function() {
|
7
|
+
if (typeof Gmaps.oldOnload === 'function') return Gmaps.oldOnload();
|
8
|
+
};
|
9
|
+
|
4
10
|
Gmaps.loadMaps = function() {
|
5
11
|
var key, load_function_name, searchLoadIncluded, value, _results;
|
6
12
|
_results = [];
|
7
13
|
for (key in Gmaps) {
|
8
14
|
value = Gmaps[key];
|
9
15
|
searchLoadIncluded = key.search(/load/);
|
10
|
-
|
16
|
+
if (searchLoadIncluded === -1) {
|
17
|
+
load_function_name = "load_" + key;
|
18
|
+
_results.push(Gmaps[load_function_name]());
|
19
|
+
} else {
|
20
|
+
_results.push(void 0);
|
21
|
+
}
|
11
22
|
}
|
12
23
|
return _results;
|
13
24
|
};
|
25
|
+
|
14
26
|
window.Gmaps = Gmaps;
|
27
|
+
|
15
28
|
this.Gmaps4Rails = (function() {
|
29
|
+
|
16
30
|
function Gmaps4Rails() {
|
17
31
|
this.map = null;
|
18
32
|
this.visibleInfoWindow = null;
|
@@ -66,6 +80,7 @@
|
|
66
80
|
this.markerClusterer = null;
|
67
81
|
this.markerImages = [];
|
68
82
|
}
|
83
|
+
|
69
84
|
Gmaps4Rails.prototype.initialize = function() {
|
70
85
|
this.map = this.createMap();
|
71
86
|
if (this.map_options.detect_location === true || this.map_options.center_on_user === true) {
|
@@ -73,6 +88,7 @@
|
|
73
88
|
}
|
74
89
|
return this.resetSidebarContent();
|
75
90
|
};
|
91
|
+
|
76
92
|
Gmaps4Rails.prototype.findUserLocation = function(map_object) {
|
77
93
|
var positionFailure, positionSuccessful;
|
78
94
|
if (navigator.geolocation) {
|
@@ -90,6 +106,7 @@
|
|
90
106
|
return map_object.geolocationFailure(false);
|
91
107
|
}
|
92
108
|
};
|
109
|
+
|
93
110
|
Gmaps4Rails.prototype.create_direction = function() {
|
94
111
|
var directionsDisplay, directionsService, request;
|
95
112
|
directionsDisplay = new google.maps.DirectionsRenderer();
|
@@ -121,6 +138,7 @@
|
|
121
138
|
}
|
122
139
|
});
|
123
140
|
};
|
141
|
+
|
124
142
|
Gmaps4Rails.prototype.create_circles = function() {
|
125
143
|
var circle, _i, _len, _ref, _results;
|
126
144
|
_ref = this.circles;
|
@@ -131,6 +149,7 @@
|
|
131
149
|
}
|
132
150
|
return _results;
|
133
151
|
};
|
152
|
+
|
134
153
|
Gmaps4Rails.prototype.create_circle = function(circle) {
|
135
154
|
var newCircle;
|
136
155
|
if (circle === this.circles[0]) {
|
@@ -166,6 +185,7 @@
|
|
166
185
|
return newCircle.setMap(this.map);
|
167
186
|
}
|
168
187
|
};
|
188
|
+
|
169
189
|
Gmaps4Rails.prototype.clear_circles = function() {
|
170
190
|
var circle, _i, _len, _ref, _results;
|
171
191
|
_ref = this.circles;
|
@@ -176,9 +196,11 @@
|
|
176
196
|
}
|
177
197
|
return _results;
|
178
198
|
};
|
199
|
+
|
179
200
|
Gmaps4Rails.prototype.clear_circle = function(circle) {
|
180
201
|
return circle.serviceObject.setMap(null);
|
181
202
|
};
|
203
|
+
|
182
204
|
Gmaps4Rails.prototype.hide_circles = function() {
|
183
205
|
var circle, _i, _len, _ref, _results;
|
184
206
|
_ref = this.circles;
|
@@ -189,9 +211,11 @@
|
|
189
211
|
}
|
190
212
|
return _results;
|
191
213
|
};
|
214
|
+
|
192
215
|
Gmaps4Rails.prototype.hide_circle = function(circle) {
|
193
216
|
return circle.serviceObject.setMap(null);
|
194
217
|
};
|
218
|
+
|
195
219
|
Gmaps4Rails.prototype.show_circles = function() {
|
196
220
|
var circle, _i, _len, _ref, _results;
|
197
221
|
_ref = this.circles;
|
@@ -202,9 +226,11 @@
|
|
202
226
|
}
|
203
227
|
return _results;
|
204
228
|
};
|
229
|
+
|
205
230
|
Gmaps4Rails.prototype.show_circle = function(circle) {
|
206
231
|
return circle.serviceObject.setMap(this.map);
|
207
232
|
};
|
233
|
+
|
208
234
|
Gmaps4Rails.prototype.create_polygons = function() {
|
209
235
|
var polygon, _i, _len, _ref, _results;
|
210
236
|
_ref = this.polygons;
|
@@ -215,8 +241,9 @@
|
|
215
241
|
}
|
216
242
|
return _results;
|
217
243
|
};
|
244
|
+
|
218
245
|
Gmaps4Rails.prototype.create_polygon = function(polygon) {
|
219
|
-
var fillColor, fillOpacity, latlng, new_poly, point, polygon_coordinates, strokeColor, strokeOpacity, strokeWeight, _i, _len;
|
246
|
+
var clickable, fillColor, fillOpacity, latlng, new_poly, point, polygon_coordinates, strokeColor, strokeOpacity, strokeWeight, _i, _len;
|
220
247
|
polygon_coordinates = [];
|
221
248
|
for (_i = 0, _len = polygon.length; _i < _len; _i++) {
|
222
249
|
point = polygon[_i];
|
@@ -228,6 +255,7 @@
|
|
228
255
|
strokeWeight = point.strokeWeight || this.polygons_conf.strokeWeight;
|
229
256
|
fillColor = point.fillColor || this.polygons_conf.fillColor;
|
230
257
|
fillOpacity = point.fillOpacity || this.polygons_conf.fillOpacity;
|
258
|
+
clickable = point.clickable || this.polygons_conf.clickable;
|
231
259
|
}
|
232
260
|
}
|
233
261
|
new_poly = new google.maps.Polygon({
|
@@ -237,17 +265,19 @@
|
|
237
265
|
strokeWeight: strokeWeight,
|
238
266
|
fillColor: fillColor,
|
239
267
|
fillOpacity: fillOpacity,
|
240
|
-
clickable:
|
268
|
+
clickable: clickable,
|
241
269
|
map: this.map
|
242
270
|
});
|
243
271
|
return polygon.serviceObject = new_poly;
|
244
272
|
};
|
273
|
+
|
245
274
|
Gmaps4Rails.prototype.replacePolylines = function(new_polylines) {
|
246
275
|
this.destroy_polylines();
|
247
276
|
this.polylines = new_polylines;
|
248
277
|
this.create_polylines();
|
249
278
|
return this.adjustMapToBounds();
|
250
279
|
};
|
280
|
+
|
251
281
|
Gmaps4Rails.prototype.destroy_polylines = function() {
|
252
282
|
var polyline, _i, _len, _ref;
|
253
283
|
_ref = this.polylines;
|
@@ -257,6 +287,7 @@
|
|
257
287
|
}
|
258
288
|
return this.polylines = [];
|
259
289
|
};
|
290
|
+
|
260
291
|
Gmaps4Rails.prototype.create_polylines = function() {
|
261
292
|
var polyline, _i, _len, _ref, _results;
|
262
293
|
_ref = this.polylines;
|
@@ -267,6 +298,7 @@
|
|
267
298
|
}
|
268
299
|
return _results;
|
269
300
|
};
|
301
|
+
|
270
302
|
Gmaps4Rails.prototype.create_polyline = function(polyline) {
|
271
303
|
var clickable, decoded_array, element, latlng, new_poly, point, polyline_coordinates, strokeColor, strokeOpacity, strokeWeight, zIndex, _i, _j, _len, _len2;
|
272
304
|
polyline_coordinates = [];
|
@@ -303,43 +335,49 @@
|
|
303
335
|
polyline.serviceObject = new_poly;
|
304
336
|
return new_poly.setMap(this.map);
|
305
337
|
};
|
338
|
+
|
306
339
|
Gmaps4Rails.prototype.create_markers = function() {
|
307
340
|
this.createServiceMarkersFromMarkers();
|
308
341
|
return this.clusterize();
|
309
342
|
};
|
343
|
+
|
310
344
|
Gmaps4Rails.prototype.createServiceMarkersFromMarkers = function() {
|
311
345
|
var Lat, LatLng, Lng, index, marker, _len, _ref;
|
312
346
|
_ref = this.markers;
|
313
347
|
for (index = 0, _len = _ref.length; index < _len; index++) {
|
314
348
|
marker = _ref[index];
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
349
|
+
if (!(this.markers[index].serviceObject != null)) {
|
350
|
+
Lat = this.markers[index].lat;
|
351
|
+
Lng = this.markers[index].lng;
|
352
|
+
if (this.markers_conf.randomize) {
|
353
|
+
LatLng = this.randomize(Lat, Lng);
|
354
|
+
Lat = LatLng[0];
|
355
|
+
Lng = LatLng[1];
|
356
|
+
}
|
357
|
+
this.markers[index].serviceObject = this.createMarker({
|
358
|
+
"marker_picture": this.markers[index].picture ? this.markers[index].picture : this.markers_conf.picture,
|
359
|
+
"marker_width": this.markers[index].width ? this.markers[index].width : this.markers_conf.width,
|
360
|
+
"marker_height": this.markers[index].height ? this.markers[index].height : this.markers_conf.length,
|
361
|
+
"marker_title": this.markers[index].title ? this.markers[index].title : null,
|
362
|
+
"marker_anchor": this.markers[index].marker_anchor ? this.markers[index].marker_anchor : null,
|
363
|
+
"shadow_anchor": this.markers[index].shadow_anchor ? this.markers[index].shadow_anchor : null,
|
364
|
+
"shadow_picture": this.markers[index].shadow_picture ? this.markers[index].shadow_picture : null,
|
365
|
+
"shadow_width": this.markers[index].shadow_width ? this.markers[index].shadow_width : null,
|
366
|
+
"shadow_height": this.markers[index].shadow_height ? this.markers[index].shadow_height : null,
|
367
|
+
"marker_draggable": this.markers[index].draggable ? this.markers[index].draggable : this.markers_conf.draggable,
|
368
|
+
"rich_marker": this.markers[index].rich_marker ? this.markers[index].rich_marker : null,
|
369
|
+
"zindex": this.markers[index].zindex ? this.markers[index].zindex : null,
|
370
|
+
"Lat": Lat,
|
371
|
+
"Lng": Lng,
|
372
|
+
"index": index
|
373
|
+
});
|
374
|
+
this.createInfoWindow(this.markers[index]);
|
375
|
+
this.createSidebar(this.markers[index]);
|
321
376
|
}
|
322
|
-
this.markers[index].serviceObject = this.createMarker({
|
323
|
-
"marker_picture": this.markers[index].picture ? this.markers[index].picture : this.markers_conf.picture,
|
324
|
-
"marker_width": this.markers[index].width ? this.markers[index].width : this.markers_conf.width,
|
325
|
-
"marker_height": this.markers[index].height ? this.markers[index].height : this.markers_conf.length,
|
326
|
-
"marker_title": this.markers[index].title ? this.markers[index].title : null,
|
327
|
-
"marker_anchor": this.markers[index].marker_anchor ? this.markers[index].marker_anchor : null,
|
328
|
-
"shadow_anchor": this.markers[index].shadow_anchor ? this.markers[index].shadow_anchor : null,
|
329
|
-
"shadow_picture": this.markers[index].shadow_picture ? this.markers[index].shadow_picture : null,
|
330
|
-
"shadow_width": this.markers[index].shadow_width ? this.markers[index].shadow_width : null,
|
331
|
-
"shadow_height": this.markers[index].shadow_height ? this.markers[index].shadow_height : null,
|
332
|
-
"marker_draggable": this.markers[index].draggable ? this.markers[index].draggable : this.markers_conf.draggable,
|
333
|
-
"rich_marker": this.markers[index].rich_marker ? this.markers[index].rich_marker : null,
|
334
|
-
"Lat": Lat,
|
335
|
-
"Lng": Lng,
|
336
|
-
"index": index
|
337
|
-
});
|
338
|
-
this.createInfoWindow(this.markers[index]);
|
339
|
-
this.createSidebar(this.markers[index]);
|
340
377
|
}
|
341
378
|
return this.markers_conf.offset = this.markers.length;
|
342
379
|
};
|
380
|
+
|
343
381
|
Gmaps4Rails.prototype.createImageAnchorPosition = function(anchorLocation) {
|
344
382
|
if (anchorLocation === null) {
|
345
383
|
return null;
|
@@ -347,6 +385,7 @@
|
|
347
385
|
return this.createPoint(anchorLocation[0], anchorLocation[1]);
|
348
386
|
}
|
349
387
|
};
|
388
|
+
|
350
389
|
Gmaps4Rails.prototype.replaceMarkers = function(new_markers) {
|
351
390
|
this.clearMarkers();
|
352
391
|
this.markers = new Array;
|
@@ -355,11 +394,13 @@
|
|
355
394
|
this.markers_conf.offset = 0;
|
356
395
|
return this.addMarkers(new_markers);
|
357
396
|
};
|
397
|
+
|
358
398
|
Gmaps4Rails.prototype.addMarkers = function(new_markers) {
|
359
399
|
this.markers = this.markers.concat(new_markers);
|
360
400
|
this.create_markers();
|
361
401
|
return this.adjustMapToBounds();
|
362
402
|
};
|
403
|
+
|
363
404
|
Gmaps4Rails.prototype.createSidebar = function(marker_container) {
|
364
405
|
var aSel, currentMap, html, li, ul;
|
365
406
|
if (this.markers_conf.list_container) {
|
@@ -375,12 +416,14 @@
|
|
375
416
|
return ul.appendChild(li);
|
376
417
|
}
|
377
418
|
};
|
419
|
+
|
378
420
|
Gmaps4Rails.prototype.sidebar_element_handler = function(currentMap, marker, eventType) {
|
379
421
|
return function() {
|
380
422
|
currentMap.map.panTo(marker.position);
|
381
423
|
return google.maps.event.trigger(marker, eventType);
|
382
424
|
};
|
383
425
|
};
|
426
|
+
|
384
427
|
Gmaps4Rails.prototype.resetSidebarContent = function() {
|
385
428
|
var ul;
|
386
429
|
if (this.markers_conf.list_container !== null) {
|
@@ -388,6 +431,7 @@
|
|
388
431
|
return ul.innerHTML = "";
|
389
432
|
}
|
390
433
|
};
|
434
|
+
|
391
435
|
Gmaps4Rails.prototype.adjustMapToBounds = function() {
|
392
436
|
var bound, circle, map_center, point, polygon, polygon_points, polyline, polyline_points, _i, _j, _k, _l, _len, _len2, _len3, _len4, _len5, _len6, _m, _n, _ref, _ref2, _ref3, _ref4;
|
393
437
|
if (this.map_options.auto_adjust || this.map_options.bounds !== null) {
|
@@ -437,6 +481,7 @@
|
|
437
481
|
}
|
438
482
|
}
|
439
483
|
};
|
484
|
+
|
440
485
|
Gmaps4Rails.prototype.create_kml = function() {
|
441
486
|
var kml, _i, _len, _ref, _results;
|
442
487
|
_ref = this.kml;
|
@@ -447,9 +492,11 @@
|
|
447
492
|
}
|
448
493
|
return _results;
|
449
494
|
};
|
495
|
+
|
450
496
|
Gmaps4Rails.prototype.exists = function(var_name) {
|
451
497
|
return var_name !== "" && typeof var_name !== "undefined";
|
452
498
|
};
|
499
|
+
|
453
500
|
Gmaps4Rails.prototype.randomize = function(Lat0, Lng0) {
|
454
501
|
var Lat, Lng, dx, dy;
|
455
502
|
dx = this.markers_conf.max_random_distance * this.random();
|
@@ -458,6 +505,7 @@
|
|
458
505
|
Lng = parseFloat(Lng0) + (90 / Math.PI) * (dx / 6378137) / Math.cos(Lat0);
|
459
506
|
return [Lat, Lng];
|
460
507
|
};
|
508
|
+
|
461
509
|
Gmaps4Rails.prototype.mergeObjectWithDefault = function(object1, object2) {
|
462
510
|
var copy_object1, key, value;
|
463
511
|
copy_object1 = {};
|
@@ -467,12 +515,11 @@
|
|
467
515
|
}
|
468
516
|
for (key in object2) {
|
469
517
|
value = object2[key];
|
470
|
-
if (copy_object1[key] == null)
|
471
|
-
copy_object1[key] = value;
|
472
|
-
}
|
518
|
+
if (copy_object1[key] == null) copy_object1[key] = value;
|
473
519
|
}
|
474
520
|
return copy_object1;
|
475
521
|
};
|
522
|
+
|
476
523
|
Gmaps4Rails.prototype.mergeWithDefault = function(objectName) {
|
477
524
|
var default_object, object;
|
478
525
|
default_object = this["default_" + objectName];
|
@@ -480,9 +527,13 @@
|
|
480
527
|
this[objectName] = this.mergeObjectWithDefault(object, default_object);
|
481
528
|
return true;
|
482
529
|
};
|
530
|
+
|
483
531
|
Gmaps4Rails.prototype.random = function() {
|
484
532
|
return Math.random() * 2 - 1;
|
485
533
|
};
|
534
|
+
|
486
535
|
return Gmaps4Rails;
|
536
|
+
|
487
537
|
})();
|
538
|
+
|
488
539
|
}).call(this);
|