gmaps4rails 0.11.1 → 1.0.0
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/README.rdoc +6 -2
- data/app/views/gmaps4rails/_gmaps4rails.html.erb +18 -20
- data/lib/gmaps4rails/base.rb +95 -0
- data/lib/gmaps4rails/extensions/hash.rb +3 -67
- data/lib/gmaps4rails/helper/gmaps4rails_helper.rb +13 -2
- data/public/javascripts/gmaps4rails/all_apis.js +5 -0
- data/public/javascripts/gmaps4rails/gmaps4rails.base.js +147 -112
- data/public/javascripts/gmaps4rails/gmaps4rails.bing.js +182 -171
- data/public/javascripts/gmaps4rails/gmaps4rails.googlemaps.js +269 -235
- data/public/javascripts/gmaps4rails/gmaps4rails.mapquest.js +135 -125
- data/public/javascripts/gmaps4rails/gmaps4rails.openlayers.js +227 -218
- data/public/stylesheets/gmaps4rails.css +2 -2
- metadata +9 -111
- data/test/dummy/app/controllers/application_controller.rb +0 -3
- data/test/dummy/app/controllers/users_controller.rb +0 -60
- data/test/dummy/app/helpers/application_helper.rb +0 -2
- data/test/dummy/app/helpers/users_helper.rb +0 -3
- data/test/dummy/app/models/user.rb +0 -38
- data/test/dummy/config/application.rb +0 -41
- data/test/dummy/config/boot.rb +0 -6
- data/test/dummy/config/environment.rb +0 -5
- data/test/dummy/config/environments/development.rb +0 -26
- data/test/dummy/config/environments/production.rb +0 -49
- data/test/dummy/config/environments/test.rb +0 -35
- data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/test/dummy/config/initializers/inflections.rb +0 -10
- data/test/dummy/config/initializers/mime_types.rb +0 -5
- data/test/dummy/config/initializers/secret_token.rb +0 -7
- data/test/dummy/config/initializers/session_store.rb +0 -8
- data/test/dummy/config/routes.rb +0 -7
- data/test/dummy/db/migrate/20110306182914_create_users.rb +0 -21
- data/test/dummy/db/migrate/20110430081624_add_addresses_to_users.rb +0 -11
- data/test/dummy/db/migrate/20110430083824_remove_address_from_users.rb +0 -9
- data/test/dummy/db/schema.rb +0 -35
- data/test/dummy/db/seeds.rb +0 -7
- data/test/dummy/spec/base/base_spec.rb +0 -127
- data/test/dummy/spec/helpers/gmaps4rails_helper_spec.rb +0 -13
- data/test/dummy/spec/javascripts/support/jasmine_config.rb +0 -23
- data/test/dummy/spec/javascripts/support/jasmine_runner.rb +0 -20
- data/test/dummy/spec/models/user_spec.rb +0 -284
- data/test/dummy/spec/requests/users_spec.rb +0 -22
- data/test/dummy/spec/spec_helper.rb +0 -41
- data/test/dummy/spec/support/factories.rb +0 -20
- data/test/dummy/spec/support/matchers.rb +0 -7
- data/test/dummy31/app/controllers/application_controller.rb +0 -3
- data/test/dummy31/app/controllers/users_controller.rb +0 -83
- data/test/dummy31/app/helpers/application_helper.rb +0 -2
- data/test/dummy31/app/helpers/users_helper.rb +0 -2
- data/test/dummy31/app/models/user.rb +0 -7
- data/test/dummy31/config/application.rb +0 -43
- data/test/dummy31/config/boot.rb +0 -6
- data/test/dummy31/config/environment.rb +0 -5
- data/test/dummy31/config/environments/development.rb +0 -27
- data/test/dummy31/config/environments/production.rb +0 -51
- data/test/dummy31/config/environments/test.rb +0 -39
- data/test/dummy31/config/initializers/backtrace_silencers.rb +0 -7
- data/test/dummy31/config/initializers/inflections.rb +0 -10
- data/test/dummy31/config/initializers/mime_types.rb +0 -5
- data/test/dummy31/config/initializers/secret_token.rb +0 -7
- data/test/dummy31/config/initializers/session_store.rb +0 -8
- data/test/dummy31/config/initializers/wrap_parameters.rb +0 -12
- data/test/dummy31/config/routes.rb +0 -61
- data/test/dummy31/db/migrate/20110809134019_create_users.rb +0 -13
- data/test/dummy31/db/schema.rb +0 -25
- data/test/dummy31/db/seeds.rb +0 -7
@@ -1,259 +1,268 @@
|
|
1
|
-
|
2
|
-
/////////////// Abstracting API calls //////////////
|
3
|
-
//(for maybe an extension to another map provider)//
|
4
|
-
//////////////////mocks created/////////////////////
|
5
|
-
// http://wiki.openstreetmap.org/wiki/OpenLayers
|
6
|
-
// http://openlayers.org/dev/examples
|
7
|
-
//http://docs.openlayers.org/contents.html
|
1
|
+
var Gmaps4RailsOpenlayers = function() {
|
8
2
|
|
9
|
-
|
10
|
-
|
11
|
-
|
3
|
+
////////////////////////////////////////////////////
|
4
|
+
/////////////// Abstracting API calls //////////////
|
5
|
+
//(for maybe an extension to another map provider)//
|
6
|
+
//////////////////mocks created/////////////////////
|
7
|
+
// http://wiki.openstreetmap.org/wiki/OpenLayers
|
8
|
+
// http://openlayers.org/dev/examples
|
9
|
+
//http://docs.openlayers.org/contents.html
|
10
|
+
this.map_options = {};
|
11
|
+
this.mergeWithDefault("map_options");
|
12
|
+
this.markers_conf = {};
|
13
|
+
this.mergeWithDefault("markers_conf");
|
14
|
+
|
15
|
+
this.openMarkers = null;
|
16
|
+
this.markersLayer = null;
|
17
|
+
this.markersControl = null;
|
12
18
|
|
13
|
-
////////////////////////////////////////////////////
|
14
|
-
/////////////// Basic Objects ////////////////////
|
15
|
-
////////////////////////////////////////////////////
|
19
|
+
////////////////////////////////////////////////////
|
20
|
+
/////////////// Basic Objects ////////////////////
|
21
|
+
////////////////////////////////////////////////////
|
16
22
|
|
17
|
-
|
18
|
-
|
19
|
-
};
|
23
|
+
this.createPoint = function(lat, lng){
|
24
|
+
//return new Microsoft.Maps.Point(lat, lng);
|
25
|
+
};
|
20
26
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
};
|
27
|
+
this.createLatLng = function(lat, lng){
|
28
|
+
return new OpenLayers.LonLat(lng, lat)
|
29
|
+
.transform(
|
30
|
+
new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
|
31
|
+
new OpenLayers.Projection("EPSG:900913") // to Spherical Mercator Projection
|
32
|
+
);
|
33
|
+
};
|
28
34
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
};
|
35
|
+
this.createAnchor = function(offset){
|
36
|
+
if (offset === null)
|
37
|
+
{ return null; }
|
38
|
+
else {
|
39
|
+
return new OpenLayers.Pixel(offset[0], offset[1]);
|
40
|
+
}
|
41
|
+
};
|
36
42
|
|
37
|
-
|
38
|
-
|
39
|
-
};
|
43
|
+
this.createSize = function(width, height){
|
44
|
+
return new OpenLayers.Size(width, height);
|
45
|
+
};
|
40
46
|
|
41
|
-
|
42
|
-
|
43
|
-
};
|
47
|
+
this.createLatLngBounds = function(){
|
48
|
+
return new OpenLayers.Bounds();
|
49
|
+
};
|
44
50
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
};
|
51
|
+
this.createMap = function(){
|
52
|
+
//todo add customization: kind of map and other map options
|
53
|
+
var map = new OpenLayers.Map(this.map_options.id);
|
54
|
+
map.addLayer(new OpenLayers.Layer.OSM());
|
55
|
+
map.setCenter(this.createLatLng(this.map_options.center_latitude, this.map_options.center_longitude), // Center of the map
|
56
|
+
this.map_options.zoom // Zoom level
|
57
|
+
);
|
58
|
+
return map;
|
59
|
+
};
|
54
60
|
|
55
|
-
////////////////////////////////////////////////////
|
56
|
-
////////////////////// Markers /////////////////////
|
57
|
-
////////////////////////////////////////////////////
|
58
|
-
//http://openlayers.org/dev/examples/marker-shadow.html
|
59
|
-
|
61
|
+
////////////////////////////////////////////////////
|
62
|
+
////////////////////// Markers /////////////////////
|
63
|
+
////////////////////////////////////////////////////
|
64
|
+
//http://openlayers.org/dev/examples/marker-shadow.html
|
65
|
+
this.createMarker = function(args){
|
60
66
|
|
61
|
-
|
62
|
-
|
67
|
+
var style_mark = OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style['default']);
|
68
|
+
style_mark.fillOpacity = 1;
|
63
69
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
70
|
+
//creating markers' dedicated layer
|
71
|
+
if (this.markersLayer === null) {
|
72
|
+
this.markersLayer = new OpenLayers.Layer.Vector("Markers", null);
|
73
|
+
this.map.addLayer(this.markersLayer);
|
74
|
+
//TODO move?
|
75
|
+
this.markersLayer.events.register("featureselected", this.markersLayer, this.onFeatureSelect);
|
76
|
+
this.markersLayer.events.register("featureunselected", this.markersLayer, this.onFeatureUnselect);
|
71
77
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
}
|
76
|
-
//showing default pic if none available
|
77
|
-
if (args.marker_picture === "" ) {
|
78
|
-
//style_mark.graphicWidth = 24;
|
79
|
-
style_mark.graphicHeight = 30;
|
80
|
-
style_mark.externalGraphic = "http://openlayers.org/dev/img/marker-blue.png";
|
81
|
-
}
|
82
|
-
//creating custom pic
|
83
|
-
else {
|
84
|
-
style_mark.graphicWidth = args.marker_width;
|
85
|
-
style_mark.graphicHeight = args.marker_height;
|
86
|
-
style_mark.externalGraphic = args.marker_picture;
|
87
|
-
//adding anchor if any
|
88
|
-
if (args.marker_anchor !== null ){
|
89
|
-
style_mark.graphicXOffset = args.marker_anchor[0];
|
90
|
-
style_mark.graphicYOffset = args.marker_anchor[1];
|
78
|
+
this.markersControl = new OpenLayers.Control.SelectFeature(this.markersLayer);
|
79
|
+
this.map.addControl(this.markersControl);
|
80
|
+
this.markersControl.activate();
|
91
81
|
}
|
92
|
-
//
|
93
|
-
if (args.
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
82
|
+
//showing default pic if none available
|
83
|
+
if (args.marker_picture === "" ) {
|
84
|
+
//style_mark.graphicWidth = 24;
|
85
|
+
style_mark.graphicHeight = 30;
|
86
|
+
style_mark.externalGraphic = "http://openlayers.org/dev/img/marker-blue.png";
|
87
|
+
}
|
88
|
+
//creating custom pic
|
89
|
+
else {
|
90
|
+
style_mark.graphicWidth = args.marker_width;
|
91
|
+
style_mark.graphicHeight = args.marker_height;
|
92
|
+
style_mark.externalGraphic = args.marker_picture;
|
93
|
+
//adding anchor if any
|
94
|
+
if (args.marker_anchor !== null ){
|
95
|
+
style_mark.graphicXOffset = args.marker_anchor[0];
|
96
|
+
style_mark.graphicYOffset = args.marker_anchor[1];
|
97
|
+
}
|
98
|
+
//adding shadow if any
|
99
|
+
if (args.shadow_picture !== ""){
|
100
|
+
style_mark.backgroundGraphic = args.shadow_picture;
|
101
|
+
style_mark.backgroundWidth = args.shadow_width;
|
102
|
+
style_mark.backgroundHeight = args.shadow_height;
|
103
|
+
//adding shadow's anchor if any
|
104
|
+
if(args.shadow_anchor !== null) {
|
105
|
+
style_mark.backgroundXOffset = args.shadow_anchor[0];
|
106
|
+
style_mark.backgroundYOffset = args.shadow_anchor[1];
|
107
|
+
}
|
101
108
|
}
|
102
109
|
}
|
103
|
-
}
|
104
110
|
|
105
|
-
|
111
|
+
style_mark.graphicTitle = args.title;
|
106
112
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
113
|
+
var marker = new OpenLayers.Feature.Vector(
|
114
|
+
new OpenLayers.Geometry.Point(args.Lng, args.Lat),
|
115
|
+
null,
|
116
|
+
style_mark
|
117
|
+
);
|
118
|
+
//changing coordinates so that it actually appears on the map!
|
119
|
+
marker.geometry.transform(new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:900913"));
|
120
|
+
//adding layer to the map
|
121
|
+
this.markersLayer.addFeatures([marker]);
|
116
122
|
|
117
|
-
|
118
|
-
};
|
123
|
+
return marker;
|
124
|
+
};
|
119
125
|
|
120
|
-
// clear markers
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
};
|
126
|
+
// clear markers
|
127
|
+
this.clearMarkers = function() {
|
128
|
+
this.clearMarkersLayerIfExists();
|
129
|
+
this.markersLayer = null;
|
130
|
+
this.boundsObject = new OpenLayers.Bounds();
|
131
|
+
};
|
126
132
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
133
|
+
this.clearMarkersLayerIfExists = function() {
|
134
|
+
if (this.markersLayer !== null) {
|
135
|
+
if (this.map.getLayer(this.markersLayer.id) !== null) {
|
136
|
+
this.map.removeLayer(this.markersLayer);
|
137
|
+
}
|
131
138
|
}
|
132
|
-
}
|
133
|
-
};
|
139
|
+
};
|
134
140
|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
};
|
140
|
-
////////////////////////////////////////////////////
|
141
|
-
/////////////////// Clusterer //////////////////////
|
142
|
-
////////////////////////////////////////////////////
|
143
|
-
//too ugly to be considered valid :(
|
141
|
+
this.extendBoundsWithMarkers = function(){
|
142
|
+
for (var i = 0; i < this.markers.length; ++i) {
|
143
|
+
this.boundsObject.extend(this.createLatLng(this.markers[i].lat,this.markers[i].lng));
|
144
|
+
}
|
145
|
+
};
|
146
|
+
////////////////////////////////////////////////////
|
147
|
+
/////////////////// Clusterer //////////////////////
|
148
|
+
////////////////////////////////////////////////////
|
149
|
+
//too ugly to be considered valid :(
|
144
150
|
|
145
|
-
|
151
|
+
this.createClusterer = function(markers_array){
|
146
152
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
153
|
+
var style = new OpenLayers.Style({
|
154
|
+
pointRadius: "${radius}",
|
155
|
+
fillColor: "#ffcc66",
|
156
|
+
fillOpacity: 0.8,
|
157
|
+
strokeColor: "#cc6633",
|
158
|
+
strokeWidth: "${width}",
|
159
|
+
strokeOpacity: 0.8
|
160
|
+
}, {
|
161
|
+
context: {
|
162
|
+
width: function(feature) {
|
163
|
+
return (feature.cluster) ? 2 : 1;
|
164
|
+
},
|
165
|
+
radius: function(feature) {
|
166
|
+
var pix = 2;
|
167
|
+
if(feature.cluster) {
|
168
|
+
pix = Math.min(feature.attributes.count, 7) + 2;
|
169
|
+
}
|
170
|
+
return pix;
|
171
|
+
}
|
172
|
+
}
|
173
|
+
});
|
168
174
|
|
169
|
-
|
175
|
+
var strategy = new OpenLayers.Strategy.Cluster();
|
170
176
|
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
};
|
177
|
+
var clusters = new OpenLayers.Layer.Vector("Clusters", {
|
178
|
+
strategies: [strategy],
|
179
|
+
styleMap: new OpenLayers.StyleMap({
|
180
|
+
"default": style,
|
181
|
+
"select": {
|
182
|
+
fillColor: "#8aeeef",
|
183
|
+
strokeColor: "#32a8a9"
|
184
|
+
}
|
185
|
+
})
|
186
|
+
});
|
187
|
+
this.clearMarkersLayerIfExists();
|
188
|
+
this.map.addLayer(clusters);
|
189
|
+
clusters.addFeatures(markers_array);
|
190
|
+
return clusters;
|
191
|
+
};
|
186
192
|
|
187
|
-
|
193
|
+
this.clusterize = function() {
|
188
194
|
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
+
if (this.markers_conf.do_clustering === true)
|
196
|
+
{
|
197
|
+
//first clear the existing clusterer if any
|
198
|
+
if (this.markerClusterer !== null) {
|
199
|
+
this.clearClusterer();
|
200
|
+
}
|
195
201
|
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
202
|
+
var markers_array = new Array;
|
203
|
+
for (var i = 0; i < this.markers.length; ++i) {
|
204
|
+
markers_array.push(this.markers[i].serviceObject);
|
205
|
+
}
|
200
206
|
|
201
|
-
|
202
|
-
|
207
|
+
this.markerClusterer = this.createClusterer(markers_array);
|
208
|
+
}
|
203
209
|
|
204
|
-
};
|
210
|
+
};
|
205
211
|
|
206
|
-
|
207
|
-
|
208
|
-
};
|
212
|
+
this.clearClusterer = function() {
|
213
|
+
this.map.removeLayer(this.markerClusterer);
|
214
|
+
};
|
209
215
|
|
210
|
-
////////////////////////////////////////////////////
|
211
|
-
/////////////////// INFO WINDOW ////////////////////
|
212
|
-
////////////////////////////////////////////////////
|
216
|
+
////////////////////////////////////////////////////
|
217
|
+
/////////////////// INFO WINDOW ////////////////////
|
218
|
+
////////////////////////////////////////////////////
|
213
219
|
|
214
|
-
// creates infowindows
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
};
|
220
|
+
// creates infowindows
|
221
|
+
this.createInfoWindow = function(marker_container){
|
222
|
+
var info_window;
|
223
|
+
if (this.exists(marker_container.description)) {
|
224
|
+
marker_container.serviceObject.infoWindow = marker_container.description;
|
225
|
+
}
|
226
|
+
};
|
221
227
|
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
};
|
228
|
+
this.onPopupClose = function(evt) {
|
229
|
+
// 'this' is the popup.
|
230
|
+
this.markersControl.unselect(this.feature);
|
231
|
+
};
|
226
232
|
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
};
|
233
|
+
this.onFeatureSelect = function(evt) {
|
234
|
+
var feature = evt.feature;
|
235
|
+
var popup = new OpenLayers.Popup.FramedCloud("featurePopup",
|
236
|
+
feature.geometry.getBounds().getCenterLonLat(),
|
237
|
+
new OpenLayers.Size(300,200),
|
238
|
+
feature.infoWindow,
|
239
|
+
null, true, this.onPopupClose);
|
240
|
+
feature.popup = popup;
|
241
|
+
popup.feature = feature;
|
242
|
+
this.map.addPopup(popup);
|
243
|
+
};
|
238
244
|
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
};
|
245
|
+
this.onFeatureUnselect = function(evt) {
|
246
|
+
var feature = evt.feature;
|
247
|
+
if (feature.popup) {
|
248
|
+
//popup.feature = null;
|
249
|
+
this.map.removePopup(feature.popup);
|
250
|
+
feature.popup.destroy();
|
251
|
+
feature.popup = null;
|
252
|
+
}
|
253
|
+
};
|
254
|
+
|
255
|
+
////////////////////////////////////////////////////
|
256
|
+
/////////////////// Other methods //////////////////
|
257
|
+
////////////////////////////////////////////////////
|
248
258
|
|
249
|
-
|
250
|
-
|
251
|
-
|
259
|
+
this.fitBounds = function(){
|
260
|
+
this.map.zoomToExtent(this.boundsObject, true);
|
261
|
+
};
|
252
262
|
|
253
|
-
|
254
|
-
|
263
|
+
this.centerMapOnUser = function(){
|
264
|
+
this.map.setCenter(this.userLocation);
|
265
|
+
};
|
255
266
|
};
|
256
267
|
|
257
|
-
|
258
|
-
Gmaps4Rails.map.setCenter(Gmaps4Rails.userLocation);
|
259
|
-
};
|
268
|
+
Gmaps4RailsOpenlayers.prototype = new Gmaps4Rails();
|