gmaps4rails 1.1.1 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/app/assets/javascripts/gmaps4rails/gmaps4rails.base.js.coffee +8 -3
- data/app/assets/javascripts/gmaps4rails/gmaps4rails.googlemaps.js.coffee +20 -15
- data/lib/gmaps4rails/base.rb +11 -7
- data/public/javascripts/gmaps4rails/gmaps4rails.base.js +9 -3
- data/public/javascripts/gmaps4rails/gmaps4rails.googlemaps.js +27 -20
- metadata +3 -3
@@ -36,6 +36,7 @@ class @Gmaps4Rails
|
|
36
36
|
auto_adjust : true # adjust the map to the markers if set to true
|
37
37
|
auto_zoom: true # zoom given by auto-adjust
|
38
38
|
bounds: [] # adjust map to these limits. Should be [{"lat": , "lng": }]
|
39
|
+
raw: {} # raw json to pass additional options
|
39
40
|
|
40
41
|
@default_markers_conf =
|
41
42
|
#Marker config
|
@@ -51,7 +52,8 @@ class @Gmaps4Rails
|
|
51
52
|
max_random_distance: 100 # in meters. Each marker coordinate could be altered by this distance in a random direction
|
52
53
|
list_container: null # id of the ul that will host links to all markers
|
53
54
|
offset: 0 # used when adding_markers to an existing map. Because new markers are concated with previous one, offset is here to prevent the existing from being re-created.
|
54
|
-
|
55
|
+
raw: {} # raw json to pass additional options
|
56
|
+
|
55
57
|
#Stored variables
|
56
58
|
@markers = [] # contains all markers. A marker contains the following: {"description": , "longitude": , "title":, "latitude":, "picture": "", "width": "", "length": "", "sidebar": "", "serviceObject": google_marker}
|
57
59
|
@boundsObject = null # contains current bounds from markers, polylines etc...
|
@@ -68,7 +70,7 @@ class @Gmaps4Rails
|
|
68
70
|
@findUserLocation(this)
|
69
71
|
#resets sidebar if needed
|
70
72
|
@resetSidebarContent()
|
71
|
-
|
73
|
+
|
72
74
|
findUserLocation : (map_object) ->
|
73
75
|
if (navigator.geolocation)
|
74
76
|
#try to retrieve user's position
|
@@ -450,7 +452,10 @@ class @Gmaps4Rails
|
|
450
452
|
return [Lat, Lng]
|
451
453
|
|
452
454
|
mergeObjectWithDefault : (object1, object2) ->
|
453
|
-
copy_object1 =
|
455
|
+
copy_object1 = {}
|
456
|
+
for key, value of object1
|
457
|
+
copy_object1[key] = value
|
458
|
+
|
454
459
|
for key, value of object2
|
455
460
|
unless copy_object1[key]?
|
456
461
|
copy_object1[key] = value
|
@@ -79,7 +79,7 @@ class @Gmaps4RailsGoogle extends Gmaps4Rails
|
|
79
79
|
return new google.maps.LatLngBounds()
|
80
80
|
|
81
81
|
createMap : ->
|
82
|
-
|
82
|
+
defaultOptions =
|
83
83
|
maxZoom: @map_options.maxZoom
|
84
84
|
minZoom: @map_options.minZoom
|
85
85
|
zoom: @map_options.zoom
|
@@ -89,7 +89,10 @@ class @Gmaps4RailsGoogle extends Gmaps4Rails
|
|
89
89
|
disableDefaultUI: @map_options.disableDefaultUI
|
90
90
|
disableDoubleClickZoom: @map_options.disableDoubleClickZoom
|
91
91
|
draggable: @map_options.draggable
|
92
|
-
|
92
|
+
|
93
|
+
mergedOptions = @mergeObjectWithDefault @map_options.raw, defaultOptions
|
94
|
+
|
95
|
+
return new google.maps.Map document.getElementById(@map_options.id), mergedOptions
|
93
96
|
|
94
97
|
|
95
98
|
createMarkerImage : (markerPicture, markerSize, origin, anchor, scaledSize) ->
|
@@ -104,12 +107,13 @@ class @Gmaps4RailsGoogle extends Gmaps4Rails
|
|
104
107
|
|
105
108
|
createMarker : (args) ->
|
106
109
|
markerLatLng = @createLatLng(args.Lat, args.Lng)
|
107
|
-
|
108
110
|
#Marker sizes are expressed as a Size of X,Y
|
109
|
-
if args.marker_picture and args.rich_marker == null
|
110
|
-
|
111
|
+
if args.marker_picture == "" and args.rich_marker == null
|
112
|
+
defaultOptions = {position: markerLatLng, map: @map, title: args.marker_title, draggable: args.marker_draggable}
|
113
|
+
mergedOptions = @mergeObjectWithDefault @markers_conf.raw, defaultOptions
|
114
|
+
return new google.maps.Marker mergedOptions
|
111
115
|
|
112
|
-
|
116
|
+
if (args.rich_marker != null)
|
113
117
|
return new RichMarker({
|
114
118
|
position: markerLatLng
|
115
119
|
map: @map
|
@@ -119,15 +123,16 @@ class @Gmaps4RailsGoogle extends Gmaps4Rails
|
|
119
123
|
anchor: if args.marker_anchor == null then 0 else args.marker_anchor[0]
|
120
124
|
})
|
121
125
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
126
|
+
#default behavior
|
127
|
+
#calculate MarkerImage anchor location
|
128
|
+
imageAnchorPosition = @createImageAnchorPosition args.marker_anchor
|
129
|
+
shadowAnchorPosition = @createImageAnchorPosition args.shadow_anchor
|
130
|
+
#create or retrieve existing MarkerImages
|
131
|
+
markerImage = @createOrRetrieveImage(args.marker_picture, args.marker_width, args.marker_height, imageAnchorPosition)
|
132
|
+
shadowImage = @createOrRetrieveImage(args.shadow_picture, args.shadow_width, args.shadow_height, shadowAnchorPosition)
|
133
|
+
defaultOptions = {position: markerLatLng, map: @map, icon: markerImage, title: args.marker_title, draggable: args.marker_draggable, shadow: shadowImage}
|
134
|
+
mergedOptions = @mergeObjectWithDefault @markers_conf.raw, defaultOptions
|
135
|
+
return new google.maps.Marker mergedOptions
|
131
136
|
|
132
137
|
#checks if obj is included in arr Array and returns the position or false
|
133
138
|
includeMarkerImage : (arr, obj) ->
|
data/lib/gmaps4rails/base.rb
CHANGED
@@ -212,16 +212,17 @@ module Gmaps4rails
|
|
212
212
|
unless hash[:map_options].nil?
|
213
213
|
hash[:map_options].each do |option_k, option_v|
|
214
214
|
case option_k.to_sym
|
215
|
-
when :bounds #particular case
|
215
|
+
when :bounds #particular case, render the content unescaped
|
216
216
|
result << "#{map_id}.map_options.#{option_k} = #{option_v};"
|
217
|
-
when :
|
218
|
-
|
217
|
+
when :raw #particular case, render the content unescaped
|
218
|
+
result << "#{map_id}.map_options.#{option_k} = #{option_v};"
|
219
|
+
when :class #do nothing
|
220
|
+
when :container_class #do nothing
|
219
221
|
else
|
220
222
|
result << "#{map_id}.map_options.#{option_k} = #{Gmaps4rails.filter option_v};"
|
221
223
|
end
|
222
224
|
end
|
223
225
|
end
|
224
|
-
|
225
226
|
result << "#{map_id}.initialize();"
|
226
227
|
end
|
227
228
|
|
@@ -234,7 +235,7 @@ module Gmaps4rails
|
|
234
235
|
|
235
236
|
content[:options] ||= Array.new
|
236
237
|
content[:options].each do |option_k, option_v|
|
237
|
-
if option_k ==
|
238
|
+
if option_k.to_sym == :waypoints
|
238
239
|
waypoints = Array.new
|
239
240
|
option_v.each do |waypoint|
|
240
241
|
waypoints << { "location" => waypoint, "stopover" => true }.to_json
|
@@ -249,7 +250,11 @@ module Gmaps4rails
|
|
249
250
|
result << "#{map_id}.#{category} = #{content[:data]};"
|
250
251
|
content[:options] ||= Array.new
|
251
252
|
content[:options].each do |option_k, option_v|
|
252
|
-
|
253
|
+
if option_k.to_sym == :raw
|
254
|
+
result << "#{map_id}.#{category}_conf.#{option_k} = #{option_v};"
|
255
|
+
else
|
256
|
+
result << "#{map_id}.#{category}_conf.#{option_k} = #{Gmaps4rails.filter option_v};"
|
257
|
+
end
|
253
258
|
end
|
254
259
|
result << "#{map_id}.create_#{category}();"
|
255
260
|
end
|
@@ -261,7 +266,6 @@ module Gmaps4rails
|
|
261
266
|
result << "};"
|
262
267
|
if hash[:last_map].nil? || hash[:last_map] == true
|
263
268
|
result << "window.onload = function() { Gmaps.loadMaps(); };"
|
264
|
-
#result << "window.onload = load_map;"
|
265
269
|
end
|
266
270
|
end
|
267
271
|
|
@@ -40,7 +40,8 @@
|
|
40
40
|
minZoom: null,
|
41
41
|
auto_adjust: true,
|
42
42
|
auto_zoom: true,
|
43
|
-
bounds: []
|
43
|
+
bounds: [],
|
44
|
+
raw: {}
|
44
45
|
};
|
45
46
|
this.default_markers_conf = {
|
46
47
|
title: "",
|
@@ -52,7 +53,8 @@
|
|
52
53
|
randomize: false,
|
53
54
|
max_random_distance: 100,
|
54
55
|
list_container: null,
|
55
|
-
offset: 0
|
56
|
+
offset: 0,
|
57
|
+
raw: {}
|
56
58
|
};
|
57
59
|
this.markers = [];
|
58
60
|
this.boundsObject = null;
|
@@ -438,7 +440,11 @@
|
|
438
440
|
};
|
439
441
|
Gmaps4Rails.prototype.mergeObjectWithDefault = function(object1, object2) {
|
440
442
|
var copy_object1, key, value;
|
441
|
-
copy_object1 =
|
443
|
+
copy_object1 = {};
|
444
|
+
for (key in object1) {
|
445
|
+
value = object1[key];
|
446
|
+
copy_object1[key] = value;
|
447
|
+
}
|
442
448
|
for (key in object2) {
|
443
449
|
value = object2[key];
|
444
450
|
if (copy_object1[key] == null) {
|
@@ -74,7 +74,8 @@
|
|
74
74
|
return new google.maps.LatLngBounds();
|
75
75
|
};
|
76
76
|
Gmaps4RailsGoogle.prototype.createMap = function() {
|
77
|
-
|
77
|
+
var defaultOptions, mergedOptions;
|
78
|
+
defaultOptions = {
|
78
79
|
maxZoom: this.map_options.maxZoom,
|
79
80
|
minZoom: this.map_options.minZoom,
|
80
81
|
zoom: this.map_options.zoom,
|
@@ -84,7 +85,9 @@
|
|
84
85
|
disableDefaultUI: this.map_options.disableDefaultUI,
|
85
86
|
disableDoubleClickZoom: this.map_options.disableDoubleClickZoom,
|
86
87
|
draggable: this.map_options.draggable
|
87
|
-
}
|
88
|
+
};
|
89
|
+
mergedOptions = this.mergeObjectWithDefault(this.map_options.raw, defaultOptions);
|
90
|
+
return new google.maps.Map(document.getElementById(this.map_options.id), mergedOptions);
|
88
91
|
};
|
89
92
|
Gmaps4RailsGoogle.prototype.createMarkerImage = function(markerPicture, markerSize, origin, anchor, scaledSize) {
|
90
93
|
return new google.maps.MarkerImage(markerPicture, markerSize, origin, anchor, scaledSize);
|
@@ -93,16 +96,19 @@
|
|
93
96
|
return new google.maps.Size(width, height);
|
94
97
|
};
|
95
98
|
Gmaps4RailsGoogle.prototype.createMarker = function(args) {
|
96
|
-
var imageAnchorPosition, markerImage, markerLatLng, shadowAnchorPosition, shadowImage;
|
99
|
+
var defaultOptions, imageAnchorPosition, markerImage, markerLatLng, mergedOptions, shadowAnchorPosition, shadowImage;
|
97
100
|
markerLatLng = this.createLatLng(args.Lat, args.Lng);
|
98
|
-
if (args.marker_picture && args.rich_marker === null) {
|
99
|
-
|
101
|
+
if (args.marker_picture === "" && args.rich_marker === null) {
|
102
|
+
defaultOptions = {
|
100
103
|
position: markerLatLng,
|
101
104
|
map: this.map,
|
102
105
|
title: args.marker_title,
|
103
106
|
draggable: args.marker_draggable
|
104
|
-
}
|
105
|
-
|
107
|
+
};
|
108
|
+
mergedOptions = this.mergeObjectWithDefault(this.markers_conf.raw, defaultOptions);
|
109
|
+
return new google.maps.Marker(mergedOptions);
|
110
|
+
}
|
111
|
+
if (args.rich_marker !== null) {
|
106
112
|
return new RichMarker({
|
107
113
|
position: markerLatLng,
|
108
114
|
map: this.map,
|
@@ -111,20 +117,21 @@
|
|
111
117
|
flat: args.marker_anchor === null ? false : args.marker_anchor[1],
|
112
118
|
anchor: args.marker_anchor === null ? 0 : args.marker_anchor[0]
|
113
119
|
});
|
114
|
-
} else {
|
115
|
-
imageAnchorPosition = this.createImageAnchorPosition(args.marker_anchor);
|
116
|
-
shadowAnchorPosition = this.createImageAnchorPosition(args.shadow_anchor);
|
117
|
-
markerImage = this.createOrRetrieveImage(args.marker_picture, args.marker_width, args.marker_height, imageAnchorPosition);
|
118
|
-
shadowImage = this.createOrRetrieveImage(args.shadow_picture, args.shadow_width, args.shadow_height, shadowAnchorPosition);
|
119
|
-
return new google.maps.Marker({
|
120
|
-
position: markerLatLng,
|
121
|
-
map: this.map,
|
122
|
-
icon: markerImage,
|
123
|
-
title: args.marker_title,
|
124
|
-
draggable: args.marker_draggable,
|
125
|
-
shadow: shadowImage
|
126
|
-
});
|
127
120
|
}
|
121
|
+
imageAnchorPosition = this.createImageAnchorPosition(args.marker_anchor);
|
122
|
+
shadowAnchorPosition = this.createImageAnchorPosition(args.shadow_anchor);
|
123
|
+
markerImage = this.createOrRetrieveImage(args.marker_picture, args.marker_width, args.marker_height, imageAnchorPosition);
|
124
|
+
shadowImage = this.createOrRetrieveImage(args.shadow_picture, args.shadow_width, args.shadow_height, shadowAnchorPosition);
|
125
|
+
defaultOptions = {
|
126
|
+
position: markerLatLng,
|
127
|
+
map: this.map,
|
128
|
+
icon: markerImage,
|
129
|
+
title: args.marker_title,
|
130
|
+
draggable: args.marker_draggable,
|
131
|
+
shadow: shadowImage
|
132
|
+
};
|
133
|
+
mergedOptions = this.mergeObjectWithDefault(this.markers_conf.raw, defaultOptions);
|
134
|
+
return new google.maps.Marker(mergedOptions);
|
128
135
|
};
|
129
136
|
Gmaps4RailsGoogle.prototype.includeMarkerImage = function(arr, obj) {
|
130
137
|
var index, object, _len;
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gmaps4rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -14,7 +14,7 @@ date: 2011-09-07 00:00:00.000000000Z
|
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: crack
|
17
|
-
requirement: &
|
17
|
+
requirement: &2152391800 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,7 +22,7 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *2152391800
|
26
26
|
description: ! 'Enables easy display of items (taken from a Rails 3 model) on a Google
|
27
27
|
Maps (JS API V3), OpenLayers, Mapquest and Bing. Geocoding + Directions included.
|
28
28
|
Provides much options: markers customization, infowindows, auto-adjusted zoom, polylines,
|