gmaps4rails 0.9.1 → 0.10.0.pre1
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 +23 -11
- data/app/views/gmaps4rails/_gmaps4rails.html.erb +35 -8
- data/lib/{gmaps4rails/generators → generators}/gmaps4rails/install_generator.rb +0 -0
- data/lib/{gmaps4rails/generators → generators}/templates/README +0 -0
- data/lib/gmaps4rails.rb +2 -2
- data/lib/gmaps4rails/acts_as_gmappable.rb +2 -2
- data/lib/gmaps4rails/base.rb +8 -4
- data/lib/gmaps4rails/extensions/array.rb +2 -2
- data/lib/gmaps4rails/extensions/hash.rb +19 -19
- data/public/javascripts/gmaps4rails.bing.js +195 -0
- data/public/javascripts/gmaps4rails.googlemaps.js +263 -0
- data/public/javascripts/gmaps4rails.js +444 -675
- data/public/javascripts/gmaps4rails.mapquest.js +172 -0
- data/public/javascripts/gmaps4rails.openlayers.js +259 -0
- data/public/stylesheets/gmaps4rails.css +9 -0
- data/test/dummy/app/controllers/users_controller.rb +1 -2
- data/test/dummy/app/helpers/application_helper.rb +0 -1
- data/test/dummy/app/models/user.rb +11 -6
- data/test/dummy/spec/base/base_spec.rb +3 -3
- data/test/dummy/spec/models/user_spec.rb +19 -5
- metadata +21 -14
@@ -0,0 +1,172 @@
|
|
1
|
+
// http://www.mapquestapi.com/sdk/js/v6.0.0/poi.html
|
2
|
+
|
3
|
+
//Map settings
|
4
|
+
Gmaps4Rails.map_options.type = "map"; // //map type (map, sat, hyb)
|
5
|
+
|
6
|
+
|
7
|
+
////////////////////////////////////////////////////
|
8
|
+
/////////////// Basic Objects //////////////
|
9
|
+
////////////////////////////////////////////////////
|
10
|
+
|
11
|
+
Gmaps4Rails.createPoint = function(lat, lng){
|
12
|
+
return new MQA.Poi({lat: lat, lng: lng});
|
13
|
+
};
|
14
|
+
|
15
|
+
Gmaps4Rails.createLatLng = function(lat, lng){
|
16
|
+
return {lat: lat, lng: lng};
|
17
|
+
};
|
18
|
+
|
19
|
+
Gmaps4Rails.createLatLngBounds = function(){
|
20
|
+
};
|
21
|
+
|
22
|
+
|
23
|
+
Gmaps4Rails.createMap = function(){
|
24
|
+
var map = new MQA.TileMap( // Constructs an instance of MQA.TileMap
|
25
|
+
document.getElementById("mapQuest"), //the id of the element on the page you want the map to be added into
|
26
|
+
Gmaps4Rails.map_options.zoom, //intial zoom level of the map
|
27
|
+
{lat: Gmaps4Rails.map_options.center_latitude, //the lat/lng of the map to center on
|
28
|
+
lng: Gmaps4Rails.map_options.center_longitude},
|
29
|
+
Gmaps4Rails.map_options.type); //map type (map, sat, hyb)
|
30
|
+
MQA.withModule('zoomcontrol3', function() {
|
31
|
+
|
32
|
+
map.addControl(
|
33
|
+
new MQA.LargeZoomControl3(),
|
34
|
+
new MQA.MapCornerPlacement(MQA.MapCorner.TOP_LEFT)
|
35
|
+
);
|
36
|
+
|
37
|
+
});
|
38
|
+
return map;
|
39
|
+
};
|
40
|
+
|
41
|
+
Gmaps4Rails.createMarkerImage = function(markerPicture, markerSize, origin, anchor, scaledSize) {
|
42
|
+
|
43
|
+
};
|
44
|
+
|
45
|
+
|
46
|
+
////////////////////////////////////////////////////
|
47
|
+
////////////////////// Markers /////////////////////
|
48
|
+
////////////////////////////////////////////////////
|
49
|
+
|
50
|
+
Gmaps4Rails.createMarker = function(args){
|
51
|
+
|
52
|
+
var marker = new MQA.Poi( {lat: args.Lat, lng: args.Lng} );
|
53
|
+
|
54
|
+
if (args.marker_picture !== "" ) {
|
55
|
+
var icon = new MQA.Icon(args.marker_picture, args.marker_height, args.marker_width);
|
56
|
+
marker.setIcon(icon);
|
57
|
+
if(args.marker_anchor !== null) {
|
58
|
+
marker.setBias({x: args.marker_anchor[0], y: args.marker_anchor[1]});
|
59
|
+
}
|
60
|
+
}
|
61
|
+
|
62
|
+
if (args.shadow_picture !== "" ) {
|
63
|
+
var icon = new MQA.Icon(args.shadow_picture, args.shadow_height, args.shadow_width);
|
64
|
+
marker.setShadow(icon);
|
65
|
+
|
66
|
+
if(args.shadow_anchor !== null) {
|
67
|
+
marker.setShadowOffset({x: args.shadow_anchor[0], y: args.shadow_anchor[1]});
|
68
|
+
}
|
69
|
+
}
|
70
|
+
|
71
|
+
Gmaps4Rails.addToMap(marker);
|
72
|
+
return marker;
|
73
|
+
};
|
74
|
+
|
75
|
+
|
76
|
+
// clear markers
|
77
|
+
Gmaps4Rails.clearMarkers = function() {
|
78
|
+
for (var i = 0; i < this.markers.length; ++i) {
|
79
|
+
this.clearMarker(this.markers[i]);
|
80
|
+
}
|
81
|
+
};
|
82
|
+
|
83
|
+
//show and hide markers
|
84
|
+
Gmaps4Rails.showMarkers = function() {
|
85
|
+
for (var i = 0; i < this.markers.length; ++i) {
|
86
|
+
this.showMarker(this.markers[i]);
|
87
|
+
}
|
88
|
+
};
|
89
|
+
|
90
|
+
Gmaps4Rails.hideMarkers = function() {
|
91
|
+
for (var i = 0; i < this.markers.length; ++i) {
|
92
|
+
this.hideMarker(this.markers[i]);
|
93
|
+
}
|
94
|
+
};
|
95
|
+
|
96
|
+
Gmaps4Rails.clearMarker = function(marker) {
|
97
|
+
this.removeFromMap(marker.serviceObject);
|
98
|
+
};
|
99
|
+
|
100
|
+
Gmaps4Rails.showMarker = function(marker) {
|
101
|
+
// marker.serviceObject
|
102
|
+
};
|
103
|
+
|
104
|
+
Gmaps4Rails.hideMarker = function(marker) {
|
105
|
+
// marker.serviceObject
|
106
|
+
};
|
107
|
+
|
108
|
+
Gmaps4Rails.extendBoundsWithMarkers = function(){
|
109
|
+
|
110
|
+
if (Gmaps4Rails.markers.length >=2) {
|
111
|
+
Gmaps4Rails.boundsObject = new MQA.RectLL(Gmaps4Rails.markers[0].serviceObject.latLng, Gmaps4Rails.markers[1].serviceObject.latLng);
|
112
|
+
|
113
|
+
for (var i = 2; i < Gmaps4Rails.markers.length; ++i) {
|
114
|
+
Gmaps4Rails.boundsObject.extend(Gmaps4Rails.markers[i].serviceObject.latLng);
|
115
|
+
}
|
116
|
+
}
|
117
|
+
|
118
|
+
};
|
119
|
+
|
120
|
+
////////////////////////////////////////////////////
|
121
|
+
/////////////////// Clusterer //////////////////////
|
122
|
+
////////////////////////////////////////////////////
|
123
|
+
|
124
|
+
Gmaps4Rails.createClusterer = function(markers_array){
|
125
|
+
|
126
|
+
};
|
127
|
+
|
128
|
+
Gmaps4Rails.clearClusterer = function() {
|
129
|
+
|
130
|
+
};
|
131
|
+
|
132
|
+
//creates clusters
|
133
|
+
Gmaps4Rails.clusterize = function()
|
134
|
+
{
|
135
|
+
|
136
|
+
};
|
137
|
+
|
138
|
+
////////////////////////////////////////////////////
|
139
|
+
/////////////////// INFO WINDOW ////////////////////
|
140
|
+
////////////////////////////////////////////////////
|
141
|
+
|
142
|
+
// creates infowindows
|
143
|
+
Gmaps4Rails.createInfoWindow = function(marker_container){
|
144
|
+
marker_container.serviceObject.setInfoTitleHTML(marker_container.description);
|
145
|
+
//TODO: how to disable the mouseover display when using setInfoContentHTML?
|
146
|
+
//marker_container.serviceObject.setInfoContentHTML(marker_container.description);
|
147
|
+
};
|
148
|
+
|
149
|
+
////////////////////////////////////////////////////
|
150
|
+
/////////////////// Other methods //////////////////
|
151
|
+
////////////////////////////////////////////////////
|
152
|
+
|
153
|
+
Gmaps4Rails.fitBounds = function(){
|
154
|
+
if (Gmaps4Rails.markers.length >=2) {
|
155
|
+
Gmaps4Rails.map.zoomToRect(Gmaps4Rails.boundsObject);
|
156
|
+
}
|
157
|
+
if (Gmaps4Rails.markers.length ==1 ) {
|
158
|
+
Gmaps4Rails.map.setCenter(Gmaps4Rails.markers[0].serviceObject.latLng);
|
159
|
+
}
|
160
|
+
};
|
161
|
+
|
162
|
+
Gmaps4Rails.centerMapOnUser = function(){
|
163
|
+
Gmaps4Rails.map.setCenter(Gmaps4Rails.userLocation);
|
164
|
+
};
|
165
|
+
|
166
|
+
Gmaps4Rails.addToMap = function(object){
|
167
|
+
Gmaps4Rails.map.addShape(object);
|
168
|
+
};
|
169
|
+
|
170
|
+
Gmaps4Rails.removeFromMap = function(object){
|
171
|
+
Gmaps4Rails.map.removeShape(object);
|
172
|
+
}
|
@@ -0,0 +1,259 @@
|
|
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
|
8
|
+
|
9
|
+
Gmaps4Rails.openMarkers = null;
|
10
|
+
Gmaps4Rails.markersLayer = null;
|
11
|
+
Gmaps4Rails.markersControl = null;
|
12
|
+
|
13
|
+
////////////////////////////////////////////////////
|
14
|
+
/////////////// Basic Objects ////////////////////
|
15
|
+
////////////////////////////////////////////////////
|
16
|
+
|
17
|
+
Gmaps4Rails.createPoint = function(lat, lng){
|
18
|
+
//return new Microsoft.Maps.Point(lat, lng);
|
19
|
+
};
|
20
|
+
|
21
|
+
Gmaps4Rails.createLatLng = function(lat, lng){
|
22
|
+
return new OpenLayers.LonLat(lng, lat)
|
23
|
+
.transform(
|
24
|
+
new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
|
25
|
+
new OpenLayers.Projection("EPSG:900913") // to Spherical Mercator Projection
|
26
|
+
);
|
27
|
+
};
|
28
|
+
|
29
|
+
Gmaps4Rails.createAnchor = function(offset){
|
30
|
+
if (offset === null)
|
31
|
+
{ return null; }
|
32
|
+
else {
|
33
|
+
return new OpenLayers.Pixel(offset[0], offset[1]);
|
34
|
+
}
|
35
|
+
};
|
36
|
+
|
37
|
+
Gmaps4Rails.createSize = function(width, height){
|
38
|
+
return new OpenLayers.Size(width, height);
|
39
|
+
};
|
40
|
+
|
41
|
+
Gmaps4Rails.createLatLngBounds = function(){
|
42
|
+
return new OpenLayers.Bounds();
|
43
|
+
};
|
44
|
+
|
45
|
+
Gmaps4Rails.createMap = function(){
|
46
|
+
//todo add customization: kind of map and other map options
|
47
|
+
var map = new OpenLayers.Map(Gmaps4Rails.map_options.id);
|
48
|
+
map.addLayer(new OpenLayers.Layer.OSM());
|
49
|
+
map.setCenter(Gmaps4Rails.createLatLng(Gmaps4Rails.map_options.center_latitude, Gmaps4Rails.map_options.center_longitude), // Center of the map
|
50
|
+
Gmaps4Rails.map_options.zoom // Zoom level
|
51
|
+
);
|
52
|
+
return map;
|
53
|
+
};
|
54
|
+
|
55
|
+
////////////////////////////////////////////////////
|
56
|
+
////////////////////// Markers /////////////////////
|
57
|
+
////////////////////////////////////////////////////
|
58
|
+
//http://openlayers.org/dev/examples/marker-shadow.html
|
59
|
+
Gmaps4Rails.createMarker = function(args){
|
60
|
+
|
61
|
+
var style_mark = OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style['default']);
|
62
|
+
style_mark.fillOpacity = 1;
|
63
|
+
|
64
|
+
//creating markers' dedicated layer
|
65
|
+
if (Gmaps4Rails.markersLayer === null) {
|
66
|
+
Gmaps4Rails.markersLayer = new OpenLayers.Layer.Vector("Markers", null);
|
67
|
+
Gmaps4Rails.map.addLayer(Gmaps4Rails.markersLayer);
|
68
|
+
//TODO move?
|
69
|
+
Gmaps4Rails.markersLayer.events.register("featureselected", Gmaps4Rails.markersLayer, Gmaps4Rails.onFeatureSelect);
|
70
|
+
Gmaps4Rails.markersLayer.events.register("featureunselected", Gmaps4Rails.markersLayer, Gmaps4Rails.onFeatureUnselect);
|
71
|
+
|
72
|
+
Gmaps4Rails.markersControl = new OpenLayers.Control.SelectFeature(Gmaps4Rails.markersLayer);
|
73
|
+
Gmaps4Rails.map.addControl(Gmaps4Rails.markersControl);
|
74
|
+
Gmaps4Rails.markersControl.activate();
|
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];
|
91
|
+
}
|
92
|
+
//adding shadow if any
|
93
|
+
if (args.shadow_picture !== ""){
|
94
|
+
style_mark.backgroundGraphic = args.shadow_picture;
|
95
|
+
style_mark.backgroundWidth = args.shadow_width;
|
96
|
+
style_mark.backgroundHeight = args.shadow_height;
|
97
|
+
//adding shadow's anchor if any
|
98
|
+
if(args.shadow_anchor !== null) {
|
99
|
+
style_mark.backgroundXOffset = args.shadow_anchor[0];
|
100
|
+
style_mark.backgroundYOffset = args.shadow_anchor[1];
|
101
|
+
}
|
102
|
+
}
|
103
|
+
}
|
104
|
+
|
105
|
+
style_mark.graphicTitle = args.title;
|
106
|
+
|
107
|
+
var marker = new OpenLayers.Feature.Vector(
|
108
|
+
new OpenLayers.Geometry.Point(args.Lng, args.Lat),
|
109
|
+
null,
|
110
|
+
style_mark
|
111
|
+
);
|
112
|
+
//changing coordinates so that it actually appears on the map!
|
113
|
+
marker.geometry.transform(new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:900913"));
|
114
|
+
//adding layer to the map
|
115
|
+
Gmaps4Rails.markersLayer.addFeatures([marker]);
|
116
|
+
|
117
|
+
return marker;
|
118
|
+
};
|
119
|
+
|
120
|
+
// clear markers
|
121
|
+
Gmaps4Rails.clearMarkers = function() {
|
122
|
+
Gmaps4Rails.clearMarkersLayerIfExists();
|
123
|
+
Gmaps4Rails.markersLayer = null;
|
124
|
+
Gmaps4Rails.boundsObject = new OpenLayers.Bounds();
|
125
|
+
};
|
126
|
+
|
127
|
+
Gmaps4Rails.clearMarkersLayerIfExists = function() {
|
128
|
+
if (Gmaps4Rails.markersLayer !== null) {
|
129
|
+
if (Gmaps4Rails.map.getLayer(Gmaps4Rails.markersLayer.id) !== null) {
|
130
|
+
Gmaps4Rails.map.removeLayer(Gmaps4Rails.markersLayer);
|
131
|
+
}
|
132
|
+
}
|
133
|
+
};
|
134
|
+
|
135
|
+
Gmaps4Rails.extendBoundsWithMarkers = function(){
|
136
|
+
for (var i = 0; i < this.markers.length; ++i) {
|
137
|
+
Gmaps4Rails.boundsObject.extend(Gmaps4Rails.createLatLng(Gmaps4Rails.markers[i].lat,Gmaps4Rails.markers[i].lng));
|
138
|
+
}
|
139
|
+
};
|
140
|
+
////////////////////////////////////////////////////
|
141
|
+
/////////////////// Clusterer //////////////////////
|
142
|
+
////////////////////////////////////////////////////
|
143
|
+
//too ugly to be considered valid :(
|
144
|
+
|
145
|
+
Gmaps4Rails.createClusterer = function(markers_array){
|
146
|
+
|
147
|
+
var style = new OpenLayers.Style({
|
148
|
+
pointRadius: "${radius}",
|
149
|
+
fillColor: "#ffcc66",
|
150
|
+
fillOpacity: 0.8,
|
151
|
+
strokeColor: "#cc6633",
|
152
|
+
strokeWidth: "${width}",
|
153
|
+
strokeOpacity: 0.8
|
154
|
+
}, {
|
155
|
+
context: {
|
156
|
+
width: function(feature) {
|
157
|
+
return (feature.cluster) ? 2 : 1;
|
158
|
+
},
|
159
|
+
radius: function(feature) {
|
160
|
+
var pix = 2;
|
161
|
+
if(feature.cluster) {
|
162
|
+
pix = Math.min(feature.attributes.count, 7) + 2;
|
163
|
+
}
|
164
|
+
return pix;
|
165
|
+
}
|
166
|
+
}
|
167
|
+
});
|
168
|
+
|
169
|
+
var strategy = new OpenLayers.Strategy.Cluster();
|
170
|
+
|
171
|
+
var clusters = new OpenLayers.Layer.Vector("Clusters", {
|
172
|
+
strategies: [strategy],
|
173
|
+
styleMap: new OpenLayers.StyleMap({
|
174
|
+
"default": style,
|
175
|
+
"select": {
|
176
|
+
fillColor: "#8aeeef",
|
177
|
+
strokeColor: "#32a8a9"
|
178
|
+
}
|
179
|
+
})
|
180
|
+
});
|
181
|
+
Gmaps4Rails.clearMarkersLayerIfExists();
|
182
|
+
Gmaps4Rails.map.addLayer(clusters);
|
183
|
+
clusters.addFeatures(markers_array);
|
184
|
+
return clusters;
|
185
|
+
};
|
186
|
+
|
187
|
+
Gmaps4Rails.clusterize = function() {
|
188
|
+
|
189
|
+
if (this.markers_conf.do_clustering === true)
|
190
|
+
{
|
191
|
+
//first clear the existing clusterer if any
|
192
|
+
if (this.markerClusterer !== null) {
|
193
|
+
this.clearClusterer();
|
194
|
+
}
|
195
|
+
|
196
|
+
var markers_array = new Array;
|
197
|
+
for (var i = 0; i < this.markers.length; ++i) {
|
198
|
+
markers_array.push(this.markers[i].serviceObject);
|
199
|
+
}
|
200
|
+
|
201
|
+
this.markerClusterer = Gmaps4Rails.createClusterer(markers_array);
|
202
|
+
}
|
203
|
+
|
204
|
+
};
|
205
|
+
|
206
|
+
Gmaps4Rails.clearClusterer = function() {
|
207
|
+
Gmaps4Rails.map.removeLayer(Gmaps4Rails.markerClusterer);
|
208
|
+
};
|
209
|
+
|
210
|
+
////////////////////////////////////////////////////
|
211
|
+
/////////////////// INFO WINDOW ////////////////////
|
212
|
+
////////////////////////////////////////////////////
|
213
|
+
|
214
|
+
// creates infowindows
|
215
|
+
Gmaps4Rails.createInfoWindow = function(marker_container){
|
216
|
+
var info_window;
|
217
|
+
if (Gmaps4Rails.exists(marker_container.description)) {
|
218
|
+
marker_container.serviceObject.infoWindow = marker_container.description;
|
219
|
+
}
|
220
|
+
};
|
221
|
+
|
222
|
+
Gmaps4Rails.onPopupClose = function(evt) {
|
223
|
+
// 'this' is the popup.
|
224
|
+
Gmaps4Rails.markersControl.unselect(this.feature);
|
225
|
+
};
|
226
|
+
|
227
|
+
Gmaps4Rails.onFeatureSelect = function(evt) {
|
228
|
+
var feature = evt.feature;
|
229
|
+
var popup = new OpenLayers.Popup.FramedCloud("featurePopup",
|
230
|
+
feature.geometry.getBounds().getCenterLonLat(),
|
231
|
+
new OpenLayers.Size(300,200),
|
232
|
+
feature.infoWindow,
|
233
|
+
null, true, Gmaps4Rails.onPopupClose);
|
234
|
+
feature.popup = popup;
|
235
|
+
popup.feature = feature;
|
236
|
+
Gmaps4Rails.map.addPopup(popup);
|
237
|
+
};
|
238
|
+
|
239
|
+
Gmaps4Rails.onFeatureUnselect = function(evt) {
|
240
|
+
var feature = evt.feature;
|
241
|
+
if (feature.popup) {
|
242
|
+
//popup.feature = null;
|
243
|
+
Gmaps4Rails.map.removePopup(feature.popup);
|
244
|
+
feature.popup.destroy();
|
245
|
+
feature.popup = null;
|
246
|
+
}
|
247
|
+
};
|
248
|
+
|
249
|
+
////////////////////////////////////////////////////
|
250
|
+
/////////////////// Other methods //////////////////
|
251
|
+
////////////////////////////////////////////////////
|
252
|
+
|
253
|
+
Gmaps4Rails.fitBounds = function(){
|
254
|
+
Gmaps4Rails.map.zoomToExtent(Gmaps4Rails.boundsObject, true);
|
255
|
+
};
|
256
|
+
|
257
|
+
Gmaps4Rails.centerMapOnUser = function(){
|
258
|
+
Gmaps4Rails.map.setCenter(Gmaps4Rails.userLocation);
|
259
|
+
};
|