gmaps4rails 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,182 +1,145 @@
1
- var Gmaps4RailsMapquest = function() {
2
-
3
- // http://www.mapquestapi.com/sdk/js/v6.0.0/poi.html
4
-
5
- //Map settings
6
- this.map_options = {
7
- type: "map" // //map type (map, sat, hyb)
8
- };
9
- this.markers_conf = {};
10
-
11
- this.mergeWithDefault("markers_conf");
12
- this.mergeWithDefault("map_options");
13
-
14
- ////////////////////////////////////////////////////
15
- /////////////// Basic Objects //////////////
16
- ////////////////////////////////////////////////////
17
-
18
- this.createPoint = function(lat, lng){
19
- return new MQA.Poi({lat: lat, lng: lng});
20
- };
21
-
22
- this.createLatLng = function(lat, lng){
23
- return {lat: lat, lng: lng};
24
- };
25
-
26
- this.createLatLngBounds = function(){
27
- };
28
-
29
-
30
- this.createMap = function(){
31
- var map = new MQA.TileMap( // Constructs an instance of MQA.TileMap
32
- document.getElementById(this.map_options.id), //the id of the element on the page you want the map to be added into
33
- this.map_options.zoom, //intial zoom level of the map
34
- {lat: this.map_options.center_latitude, //the lat/lng of the map to center on
35
- lng: this.map_options.center_longitude},
36
- this.map_options.type); //map type (map, sat, hyb)
37
- MQA.withModule('zoomcontrol3', function() {
38
-
39
- map.addControl(
40
- new MQA.LargeZoomControl3(),
41
- new MQA.MapCornerPlacement(MQA.MapCorner.TOP_LEFT)
42
- );
43
-
44
- });
45
- return map;
46
- };
47
-
48
- this.createMarkerImage = function(markerPicture, markerSize, origin, anchor, scaledSize) {
49
-
50
- };
51
-
52
-
53
- ////////////////////////////////////////////////////
54
- ////////////////////// Markers /////////////////////
55
- ////////////////////////////////////////////////////
56
-
57
- this.createMarker = function(args){
58
-
59
- var marker = new MQA.Poi( {lat: args.Lat, lng: args.Lng} );
60
-
61
- if (args.marker_picture !== "" ) {
62
- var icon = new MQA.Icon(args.marker_picture, args.marker_height, args.marker_width);
63
- marker.setIcon(icon);
64
- if(args.marker_anchor !== null) {
65
- marker.setBias({x: args.marker_anchor[0], y: args.marker_anchor[1]});
66
- }
1
+ (function() {
2
+ var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) {
3
+ for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }
4
+ function ctor() { this.constructor = child; }
5
+ ctor.prototype = parent.prototype;
6
+ child.prototype = new ctor;
7
+ child.__super__ = parent.prototype;
8
+ return child;
9
+ };
10
+ this.Gmaps4RailsMapquest = (function() {
11
+ __extends(Gmaps4RailsMapquest, Gmaps4Rails);
12
+ function Gmaps4RailsMapquest() {
13
+ Gmaps4RailsMapquest.__super__.constructor.apply(this, arguments);
14
+ this.map_options = {
15
+ type: "map"
16
+ };
17
+ this.markers_conf = {};
18
+ this.mergeWithDefault("markers_conf");
19
+ this.mergeWithDefault("map_options");
67
20
  }
68
-
69
- if (args.shadow_picture !== "" ) {
70
- var icon = new MQA.Icon(args.shadow_picture, args.shadow_height, args.shadow_width);
71
- marker.setShadow(icon);
72
-
73
- if(args.shadow_anchor !== null) {
74
- marker.setShadowOffset({x: args.shadow_anchor[0], y: args.shadow_anchor[1]});
21
+ Gmaps4RailsMapquest.prototype.createPoint = function(lat, lng) {
22
+ return new MQA.Poi({
23
+ lat: lat,
24
+ lng: lng
25
+ });
26
+ };
27
+ Gmaps4RailsMapquest.prototype.createLatLng = function(lat, lng) {
28
+ return {
29
+ lat: lat,
30
+ lng: lng
31
+ };
32
+ };
33
+ Gmaps4RailsMapquest.prototype.createLatLngBounds = function() {};
34
+ Gmaps4RailsMapquest.prototype.createMap = function() {
35
+ var map;
36
+ map = new MQA.TileMap(document.getElementById(this.map_options.id), this.map_options.zoom, {
37
+ lat: this.map_options.center_latitude,
38
+ lng: this.map_options.center_longitude
39
+ }, this.map_options.type);
40
+ MQA.withModule('zoomcontrol3', (function() {
41
+ return map.addControl(new MQA.LargeZoomControl3(), new MQA.MapCornerPlacement(MQA.MapCorner.TOP_LEFT));
42
+ }));
43
+ return map;
44
+ };
45
+ Gmaps4RailsMapquest.prototype.createMarkerImage = function(markerPicture, markerSize, origin, anchor, scaledSize) {};
46
+ Gmaps4RailsMapquest.prototype.createMarker = function(args) {
47
+ var icon, marker;
48
+ marker = new MQA.Poi({
49
+ lat: args.Lat,
50
+ lng: args.Lng
51
+ });
52
+ if (args.marker_picture !== "") {
53
+ icon = new MQA.Icon(args.marker_picture, args.marker_height, args.marker_width);
54
+ marker.setIcon(icon);
55
+ if (args.marker_anchor !== null) {
56
+ marker.setBias({
57
+ x: args.marker_anchor[0],
58
+ y: args.marker_anchor[1]
59
+ });
75
60
  }
76
- }
77
-
78
- this.addToMap(marker);
79
- return marker;
80
- };
81
-
82
-
83
- // clear markers
84
- this.clearMarkers = function() {
85
- for (var i = 0; i < this.markers.length; ++i) {
86
- this.clearMarker(this.markers[i]);
87
- }
88
- };
89
-
90
- //show and hide markers
91
- this.showMarkers = function() {
92
- for (var i = 0; i < this.markers.length; ++i) {
93
- this.showMarker(this.markers[i]);
94
- }
95
- };
96
-
97
- this.hideMarkers = function() {
98
- for (var i = 0; i < this.markers.length; ++i) {
99
- this.hideMarker(this.markers[i]);
100
- }
101
- };
102
-
103
- this.clearMarker = function(marker) {
104
- this.removeFromMap(marker.serviceObject);
105
- };
106
-
107
- this.showMarker = function(marker) {
108
- // marker.serviceObject
109
- };
110
-
111
- this.hideMarker = function(marker) {
112
- // marker.serviceObject
113
- };
114
-
115
- this.extendBoundsWithMarkers = function(){
116
-
117
- if (this.markers.length >=2) {
118
- this.boundsObject = new MQA.RectLL(this.markers[0].serviceObject.latLng, this.markers[1].serviceObject.latLng);
119
-
120
- for (var i = 2; i < this.markers.length; ++i) {
121
- this.boundsObject.extend(this.markers[i].serviceObject.latLng);
122
61
  }
123
- }
124
-
125
- };
126
-
127
- ////////////////////////////////////////////////////
128
- /////////////////// Clusterer //////////////////////
129
- ////////////////////////////////////////////////////
130
-
131
- this.createClusterer = function(markers_array){
132
-
133
- };
134
-
135
- this.clearClusterer = function() {
136
-
137
- };
138
-
139
- //creates clusters
140
- this.clusterize = function()
141
- {
142
-
143
- };
144
-
145
- ////////////////////////////////////////////////////
146
- /////////////////// INFO WINDOW ////////////////////
147
- ////////////////////////////////////////////////////
148
-
149
- // creates infowindows
150
- this.createInfoWindow = function(marker_container){
151
- marker_container.serviceObject.setInfoTitleHTML(marker_container.description);
152
- //TODO: how to disable the mouseover display when using setInfoContentHTML?
153
- //marker_container.serviceObject.setInfoContentHTML(marker_container.description);
154
- };
155
-
156
- ////////////////////////////////////////////////////
157
- /////////////////// Other methods //////////////////
158
- ////////////////////////////////////////////////////
159
-
160
- this.fitBounds = function(){
161
- if (this.markers.length >=2) {
162
- this.map.zoomToRect(this.boundsObject);
163
- }
164
- if (this.markers.length ==1 ) {
165
- this.map.setCenter(this.markers[0].serviceObject.latLng);
166
- }
167
- };
168
-
169
- this.centerMapOnUser = function(){
170
- this.map.setCenter(this.userLocation);
171
- };
172
-
173
- this.addToMap = function(object){
174
- this.map.addShape(object);
175
- };
176
-
177
- this.removeFromMap = function(object){
178
- this.map.removeShape(object);
179
- }
180
- }
181
-
182
- Gmaps4RailsMapquest.prototype = new Gmaps4Rails();
62
+ if (args.shadow_picture !== "") {
63
+ icon = new MQA.Icon(args.shadow_picture, args.shadow_height, args.shadow_width);
64
+ marker.setShadow(icon);
65
+ if (args.shadow_anchor !== null) {
66
+ marker.setShadowOffset({
67
+ x: args.shadow_anchor[0],
68
+ y: args.shadow_anchor[1]
69
+ });
70
+ }
71
+ }
72
+ this.addToMap(marker);
73
+ return marker;
74
+ };
75
+ Gmaps4RailsMapquest.prototype.clearMarkers = function() {
76
+ var marker, _i, _len, _results;
77
+ _results = [];
78
+ for (_i = 0, _len = markers.length; _i < _len; _i++) {
79
+ marker = markers[_i];
80
+ _results.push(this.clearMarker(marker));
81
+ }
82
+ return _results;
83
+ };
84
+ Gmaps4RailsMapquest.prototype.showMarkers = function() {
85
+ var marker, _i, _len, _results;
86
+ _results = [];
87
+ for (_i = 0, _len = markers.length; _i < _len; _i++) {
88
+ marker = markers[_i];
89
+ _results.push(this.showMarker(marker));
90
+ }
91
+ return _results;
92
+ };
93
+ Gmaps4RailsMapquest.prototype.hideMarkers = function() {
94
+ var marker, _i, _len, _results;
95
+ _results = [];
96
+ for (_i = 0, _len = markers.length; _i < _len; _i++) {
97
+ marker = markers[_i];
98
+ _results.push(this.hideMarker(marker));
99
+ }
100
+ return _results;
101
+ };
102
+ Gmaps4RailsMapquest.prototype.clearMarker = function(marker) {
103
+ return this.removeFromMap(marker.serviceObject);
104
+ };
105
+ Gmaps4RailsMapquest.prototype.showMarker = function(marker) {};
106
+ Gmaps4RailsMapquest.prototype.hideMarker = function(marker) {};
107
+ Gmaps4RailsMapquest.prototype.extendBoundsWithMarkers = function() {
108
+ var marker, _i, _len, _ref, _results;
109
+ if (this.markers.length >= 2) {
110
+ this.boundsObject = new MQA.RectLL(this.markers[0].serviceObject.latLng, this.markers[1].serviceObject.latLng);
111
+ _ref = this.markers;
112
+ _results = [];
113
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
114
+ marker = _ref[_i];
115
+ _results.push(this.boundsObject.extend(marker.serviceObject.latLng));
116
+ }
117
+ return _results;
118
+ }
119
+ };
120
+ Gmaps4RailsMapquest.prototype.createClusterer = function(markers_array) {};
121
+ Gmaps4RailsMapquest.prototype.clearClusterer = function() {};
122
+ Gmaps4RailsMapquest.prototype.clusterize = function() {};
123
+ Gmaps4RailsMapquest.prototype.createInfoWindow = function(marker_container) {
124
+ return marker_container.serviceObject.setInfoTitleHTML(marker_container.description);
125
+ };
126
+ Gmaps4RailsMapquest.prototype.fitBounds = function() {
127
+ if (this.markers.length >= 2) {
128
+ this.map.zoomToRect(this.boundsObject);
129
+ }
130
+ if (this.markers.length === 1) {
131
+ return this.map.setCenter(this.markers[0].serviceObject.latLng);
132
+ }
133
+ };
134
+ Gmaps4RailsMapquest.prototype.centerMapOnUser = function() {
135
+ return this.map.setCenter(this.userLocation);
136
+ };
137
+ Gmaps4RailsMapquest.prototype.addToMap = function(object) {
138
+ return this.map.addShape(object);
139
+ };
140
+ Gmaps4RailsMapquest.prototype.removeFromMap = function(object) {
141
+ return this.map.removeShape(object);
142
+ };
143
+ return Gmaps4RailsMapquest;
144
+ })();
145
+ }).call(this);
@@ -1,268 +1,202 @@
1
- var Gmaps4RailsOpenlayers = function() {
2
-
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;
18
-
19
- ////////////////////////////////////////////////////
20
- /////////////// Basic Objects ////////////////////
21
- ////////////////////////////////////////////////////
22
-
23
- this.createPoint = function(lat, lng){
24
- //return new Microsoft.Maps.Point(lat, lng);
25
- };
26
-
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
- };
34
-
35
- this.createAnchor = function(offset){
36
- if (offset === null)
37
- { return null; }
38
- else {
39
- return new OpenLayers.Pixel(offset[0], offset[1]);
1
+ (function() {
2
+ var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) {
3
+ for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }
4
+ function ctor() { this.constructor = child; }
5
+ ctor.prototype = parent.prototype;
6
+ child.prototype = new ctor;
7
+ child.__super__ = parent.prototype;
8
+ return child;
9
+ };
10
+ this.Gmaps4RailsOpenlayers = (function() {
11
+ __extends(Gmaps4RailsOpenlayers, Gmaps4Rails);
12
+ function Gmaps4RailsOpenlayers() {
13
+ Gmaps4RailsOpenlayers.__super__.constructor.apply(this, arguments);
14
+ this.map_options = {};
15
+ this.mergeWithDefault("map_options");
16
+ this.markers_conf = {};
17
+ this.mergeWithDefault("markers_conf");
18
+ this.openMarkers = null;
19
+ this.markersLayer = null;
20
+ this.markersControl = null;
40
21
  }
41
- };
42
-
43
- this.createSize = function(width, height){
44
- return new OpenLayers.Size(width, height);
45
- };
46
-
47
- this.createLatLngBounds = function(){
48
- return new OpenLayers.Bounds();
49
- };
50
-
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
- };
60
-
61
- ////////////////////////////////////////////////////
62
- ////////////////////// Markers /////////////////////
63
- ////////////////////////////////////////////////////
64
- //http://openlayers.org/dev/examples/marker-shadow.html
65
- this.createMarker = function(args){
66
-
67
- var style_mark = OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style['default']);
68
- style_mark.fillOpacity = 1;
69
-
70
- //creating markers' dedicated layer
71
- if (this.markersLayer === null) {
22
+ Gmaps4RailsOpenlayers.prototype.createPoint = function(lat, lng) {};
23
+ Gmaps4RailsOpenlayers.prototype.createLatLng = function(lat, lng) {
24
+ return new OpenLayers.LonLat(lng, lat).transform(new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:900913"));
25
+ };
26
+ Gmaps4RailsOpenlayers.prototype.createAnchor = function(offset) {
27
+ if (offset === null) {
28
+ return null;
29
+ }
30
+ return new OpenLayers.Pixel(offset[0], offset[1]);
31
+ };
32
+ Gmaps4RailsOpenlayers.prototype.createSize = function(width, height) {
33
+ return new OpenLayers.Size(width, height);
34
+ };
35
+ Gmaps4RailsOpenlayers.prototype.createLatLngBounds = function() {
36
+ return new OpenLayers.Bounds();
37
+ };
38
+ Gmaps4RailsOpenlayers.prototype.createMap = function() {
39
+ var map;
40
+ map = new OpenLayers.Map(this.map_options.id);
41
+ map.addLayer(new OpenLayers.Layer.OSM());
42
+ map.setCenter(this.createLatLng(this.map_options.center_latitude, this.map_options.center_longitude), this.map_options.zoom);
43
+ return map;
44
+ };
45
+ Gmaps4RailsOpenlayers.prototype.createMarker = function(args) {
46
+ var marker, style_mark;
47
+ style_mark = OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style['default']);
48
+ style_mark.fillOpacity = 1;
49
+ if (this.markersLayer === null) {
72
50
  this.markersLayer = new OpenLayers.Layer.Vector("Markers", null);
73
51
  this.map.addLayer(this.markersLayer);
74
- //TODO move?
75
52
  this.markersLayer.events.register("featureselected", this.markersLayer, this.onFeatureSelect);
76
53
  this.markersLayer.events.register("featureunselected", this.markersLayer, this.onFeatureUnselect);
77
-
78
54
  this.markersControl = new OpenLayers.Control.SelectFeature(this.markersLayer);
79
55
  this.map.addControl(this.markersControl);
80
56
  this.markersControl.activate();
81
57
  }
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;
58
+ if (args.marker_picture === "") {
59
+ style_mark.graphicHeight = 30;
60
+ style_mark.externalGraphic = "http://openlayers.org/dev/img/marker-blue.png";
61
+ } else {
62
+ style_mark.graphicWidth = args.marker_width;
91
63
  style_mark.graphicHeight = args.marker_height;
92
64
  style_mark.externalGraphic = args.marker_picture;
93
- //adding anchor if any
94
- if (args.marker_anchor !== null ){
65
+ if (args.marker_anchor !== null) {
95
66
  style_mark.graphicXOffset = args.marker_anchor[0];
96
67
  style_mark.graphicYOffset = args.marker_anchor[1];
97
68
  }
98
- //adding shadow if any
99
- if (args.shadow_picture !== ""){
69
+ if (args.shadow_picture !== "") {
100
70
  style_mark.backgroundGraphic = args.shadow_picture;
101
- style_mark.backgroundWidth = args.shadow_width;
71
+ style_mark.backgroundWidth = args.shadow_width;
102
72
  style_mark.backgroundHeight = args.shadow_height;
103
- //adding shadow's anchor if any
104
- if(args.shadow_anchor !== null) {
73
+ if (args.shadow_anchor !== null) {
105
74
  style_mark.backgroundXOffset = args.shadow_anchor[0];
106
75
  style_mark.backgroundYOffset = args.shadow_anchor[1];
107
76
  }
108
77
  }
109
78
  }
110
-
111
- style_mark.graphicTitle = args.title;
112
-
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]);
122
-
123
- return marker;
124
- };
125
-
126
- // clear markers
127
- this.clearMarkers = function() {
128
- this.clearMarkersLayerIfExists();
129
- this.markersLayer = null;
130
- this.boundsObject = new OpenLayers.Bounds();
131
- };
132
-
133
- this.clearMarkersLayerIfExists = function() {
134
- if (this.markersLayer !== null) {
135
- if (this.map.getLayer(this.markersLayer.id) !== null) {
136
- this.map.removeLayer(this.markersLayer);
79
+ style_mark.graphicTitle = args.title;
80
+ marker = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(args.Lng, args.Lat), null, style_mark);
81
+ marker.geometry.transform(new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:900913"));
82
+ this.markersLayer.addFeatures([marker]);
83
+ return marker;
84
+ };
85
+ Gmaps4RailsOpenlayers.prototype.clearMarkers = function() {
86
+ this.clearMarkersLayerIfExists();
87
+ this.markersLayer = null;
88
+ return this.boundsObject = new OpenLayers.Bounds();
89
+ };
90
+ Gmaps4RailsOpenlayers.prototype.clearMarkersLayerIfExists = function() {
91
+ if (this.markersLayer !== null && this.map.getLayer(this.markersLayer.id) !== null) {
92
+ return this.map.removeLayer(this.markersLayer);
137
93
  }
138
- }
139
- };
140
-
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 :(
150
-
151
- this.createClusterer = function(markers_array){
152
-
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
- });
174
-
175
- var strategy = new OpenLayers.Strategy.Cluster();
176
-
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
- };
192
-
193
- this.clusterize = function() {
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();
94
+ };
95
+ Gmaps4RailsOpenlayers.prototype.extendBoundsWithMarkers = function() {
96
+ var marker, _i, _len, _ref, _results;
97
+ _ref = this.markers;
98
+ _results = [];
99
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
100
+ marker = _ref[_i];
101
+ _results.push(this.boundsObject.extend(this.createLatLng(marker.lat, marker.lng)));
200
102
  }
201
-
202
- var markers_array = new Array;
203
- for (var i = 0; i < this.markers.length; ++i) {
204
- markers_array.push(this.markers[i].serviceObject);
103
+ return _results;
104
+ };
105
+ Gmaps4RailsOpenlayers.prototype.createClusterer = function(markers_array) {
106
+ var clusters, funcs, options, strategy, style;
107
+ options = {
108
+ pointRadius: "${radius}",
109
+ fillColor: "#ffcc66",
110
+ fillOpacity: 0.8,
111
+ strokeColor: "#cc6633",
112
+ strokeWidth: "${width}",
113
+ strokeOpacity: 0.8
114
+ };
115
+ funcs = {
116
+ context: {
117
+ width: function(feature) {
118
+ var _ref;
119
+ return (_ref = feature.cluster) != null ? _ref : {
120
+ 2: 1
121
+ };
122
+ },
123
+ radius: function(feature) {
124
+ var pix;
125
+ pix = 2;
126
+ if (feature.cluster) {
127
+ pix = Math.min(feature.attributes.count, 7) + 2;
128
+ }
129
+ return pix;
130
+ }
131
+ }
132
+ };
133
+ style = new OpenLayers.Style(options, funcs);
134
+ strategy = new OpenLayers.Strategy.Cluster();
135
+ clusters = new OpenLayers.Layer.Vector("Clusters", {
136
+ strategies: [strategy],
137
+ styleMap: new OpenLayers.StyleMap({
138
+ "default": style,
139
+ "select": {
140
+ fillColor: "#8aeeef",
141
+ strokeColor: "#32a8a9"
142
+ }
143
+ })
144
+ });
145
+ this.clearMarkersLayerIfExists();
146
+ this.map.addLayer(clusters);
147
+ clusters.addFeatures(markers_array);
148
+ return clusters;
149
+ };
150
+ Gmaps4RailsOpenlayers.prototype.clusterize = function() {
151
+ var marker, markers_array, _i, _len;
152
+ if (this.markers_conf.do_clustering === true) {
153
+ if (this.markerClusterer !== null) {
154
+ this.clearClusterer();
155
+ }
156
+ markers_array = new Array;
157
+ for (_i = 0, _len = markers.length; _i < _len; _i++) {
158
+ marker = markers[_i];
159
+ markers_array.push(marker.serviceObject);
160
+ }
161
+ return this.markerClusterer = this.createClusterer(markers_array);
205
162
  }
206
-
207
- this.markerClusterer = this.createClusterer(markers_array);
208
- }
209
-
210
- };
211
-
212
- this.clearClusterer = function() {
213
- this.map.removeLayer(this.markerClusterer);
214
- };
215
-
216
- ////////////////////////////////////////////////////
217
- /////////////////// INFO WINDOW ////////////////////
218
- ////////////////////////////////////////////////////
219
-
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
- };
227
-
228
- this.onPopupClose = function(evt) {
229
- // 'this' is the popup.
230
- this.markersControl.unselect(this.feature);
231
- };
232
-
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);
163
+ };
164
+ Gmaps4RailsOpenlayers.prototype.clearClusterer = function() {
165
+ return this.map.removeLayer(this.markerClusterer);
166
+ };
167
+ Gmaps4RailsOpenlayers.prototype.createInfoWindow = function() {
168
+ return function(marker_container) {
169
+ if (marker_container.description != null) {
170
+ return marker_container.serviceObject.infoWindow = marker_container.description;
171
+ }
172
+ };
173
+ };
174
+ Gmaps4RailsOpenlayers.prototype.onPopupClose = function(evt) {
175
+ return this.markersControl.unselect(this.feature);
176
+ };
177
+ Gmaps4RailsOpenlayers.prototype.onFeatureSelect = function(evt) {
178
+ var feature, popup;
179
+ feature = evt.feature;
180
+ popup = new OpenLayers.Popup.FramedCloud("featurePopup", feature.geometry.getBounds().getCenterLonLat(), new OpenLayers.Size(300, 200), feature.infoWindow, null, true, this.onPopupClose);
240
181
  feature.popup = popup;
241
182
  popup.feature = feature;
242
- this.map.addPopup(popup);
243
- };
244
-
245
- this.onFeatureUnselect = function(evt) {
246
- var feature = evt.feature;
183
+ return this.map.addPopup(popup);
184
+ };
185
+ Gmaps4RailsOpenlayers.prototype.onFeatureUnselect = function(evt) {
186
+ var feature;
187
+ feature = evt.feature;
247
188
  if (feature.popup) {
248
- //popup.feature = null;
249
- this.map.removePopup(feature.popup);
250
- feature.popup.destroy();
251
- feature.popup = null;
189
+ this.map.removePopup(feature.popup);
190
+ feature.popup.destroy();
191
+ return feature.popup = null;
252
192
  }
253
- };
254
-
255
- ////////////////////////////////////////////////////
256
- /////////////////// Other methods //////////////////
257
- ////////////////////////////////////////////////////
258
-
259
- this.fitBounds = function(){
260
- this.map.zoomToExtent(this.boundsObject, true);
261
- };
262
-
263
- this.centerMapOnUser = function(){
264
- this.map.setCenter(this.userLocation);
265
- };
266
- };
267
-
268
- Gmaps4RailsOpenlayers.prototype = new Gmaps4Rails();
193
+ };
194
+ Gmaps4RailsOpenlayers.prototype.fitBounds = function() {
195
+ return this.map.zoomToExtent(this.boundsObject, true);
196
+ };
197
+ Gmaps4RailsOpenlayers.prototype.centerMapOnUser = function() {
198
+ return this.map.setCenter(this.userLocation);
199
+ };
200
+ return Gmaps4RailsOpenlayers;
201
+ })();
202
+ }).call(this);