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,206 +1,191 @@
1
- var Gmaps4RailsBing = function() {
2
-
3
- this.map_options = {
4
- type: "road" // aerial, auto, birdseye, collinsBart, mercator, ordnanceSurvey, road
5
- };
6
- this.markers_conf = {
7
- infobox: "description" // description or htmlContent
8
- };
9
-
10
- this.mergeWithDefault("map_options");
11
- this.mergeWithDefault("markers_conf");
12
-
13
- ////////////////////////////////////////////////////
14
- /////////////// Basic Objects //////////////
15
- ////////////////////////////////////////////////////
16
-
17
- this.getMapType = function(){
18
- switch(this.map_options.type)
19
- {
20
- case "road":
21
- return Microsoft.Maps.MapTypeId.road;
22
- case "aerial":
23
- return Microsoft.Maps.MapTypeId.aerial;
24
- case "auto":
25
- return Microsoft.Maps.MapTypeId.auto;
26
- case "birdseye":
27
- return Microsoft.Maps.MapTypeId.birdseye;
28
- case "collinsBart":
29
- return Microsoft.Maps.MapTypeId.collinsBart;
30
- case "mercator":
31
- return Microsoft.Maps.MapTypeId.mercator;
32
- case "ordnanceSurvey":
33
- return Microsoft.Maps.MapTypeId.ordnanceSurvey;
34
- default:
35
- return Microsoft.Maps.MapTypeId.auto;
36
- }
37
- };
38
-
39
- this.createPoint = function(lat, lng){
40
- return new Microsoft.Maps.Point(lat, lng);
41
- };
42
-
43
- this.createLatLng = function(lat, lng){
44
- return new Microsoft.Maps.Location(lat, lng);
45
- };
46
-
47
- this.createLatLngBounds = function(){
48
-
49
- };
50
-
51
- this.createMap = function(){
52
- return new Microsoft.Maps.Map(document.getElementById(this.map_options.id), {
53
- credentials: this.map_options.provider_key,
54
- mapTypeId: this.getMapType(),
55
- center: this.createLatLng(this.map_options.center_latitude, this.map_options.center_longitude),
56
- zoom: this.map_options.zoom
57
- });
58
- };
59
-
60
- this.createSize = function(width, height){
61
- return new google.maps.Size(width, height);
62
- };
63
-
64
- ////////////////////////////////////////////////////
65
- ////////////////////// Markers /////////////////////
66
- ////////////////////////////////////////////////////
67
-
68
- this.createMarker = function(args){
69
- var markerLatLng = this.createLatLng(args.Lat, args.Lng);
70
- var marker;
71
- // Marker sizes are expressed as a Size of X,Y
72
- if (args.marker_picture === "" ) {
73
- marker = new Microsoft.Maps.Pushpin(this.createLatLng(args.Lat, args.Lng), {
74
- draggable: args.marker_draggable,
75
- anchor: this.createImageAnchorPosition(args.Lat, args.Lng),
76
- text: args.marker_title
77
- }
78
- );
79
- } else {
80
- marker = new Microsoft.Maps.Pushpin(this.createLatLng(args.Lat, args.Lng), {
81
- draggable: args.marker_draggable,
82
- anchor: this.createImageAnchorPosition(args.Lat, args.Lng),
83
- icon: args.marker_picture,
84
- height: args.marker_height,
85
- text: args.marker_title,
86
- width: args.marker_width
87
- }
88
- );
89
- }
90
- this.addToMap(marker);
91
- return marker;
92
- };
93
-
94
- // clear markers
95
- this.clearMarkers = function() {
96
- for (var i = 0; i < this.markers.length; ++i) {
97
- this.clearMarker(this.markers[i]);
98
- }
99
- };
100
-
101
- this.clearMarker = function(marker) {
102
- this.removeFromMap(marker.serviceObject);
103
- };
104
-
105
- //show and hide markers
106
- this.showMarkers = function() {
107
- for (var i = 0; i < this.markers.length; ++i) {
108
- this.showMarker(this.markers[i]);
109
- }
110
- };
111
-
112
- this.showMarker = function(marker) {
113
- marker.serviceObject.setOptions({ visible: true });
114
- };
115
-
116
- this.hideMarkers = function() {
117
- for (var i = 0; i < this.markers.length; ++i) {
118
- this.hideMarker(this.markers[i]);
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.Gmaps4RailsBing = (function() {
11
+ __extends(Gmaps4RailsBing, Gmaps4Rails);
12
+ function Gmaps4RailsBing() {
13
+ Gmaps4RailsBing.__super__.constructor.apply(this, arguments);
14
+ this.map_options = {
15
+ type: "road"
16
+ };
17
+ this.markers_conf = {
18
+ infobox: "description"
19
+ };
20
+ this.mergeWithDefault("map_options");
21
+ this.mergeWithDefault("markers_conf");
119
22
  }
120
- };
121
-
122
- this.hideMarker = function(marker) {
123
- marker.serviceObject.setOptions({ visible: false });
124
- };
125
-
126
- this.extendBoundsWithMarkers = function(){
127
- var locationsArray = [];
128
- for (var i = 0; i < this.markers.length; ++i) {
129
- locationsArray.push(this.markers[i].serviceObject.getLocation());
130
- }
131
- this.boundsObject = Microsoft.Maps.LocationRect.fromLocations(locationsArray);
132
- };
133
-
134
-
135
- ////////////////////////////////////////////////////
136
- /////////////////// Clusterer //////////////////////
137
- ////////////////////////////////////////////////////
138
-
139
- this.createClusterer = function(markers_array){
140
-
141
- };
142
-
143
- this.clearClusterer = function() {
144
- };
145
-
146
- //creates clusters
147
- this.clusterize = function()
148
- {
149
-
150
- };
151
-
152
- ////////////////////////////////////////////////////
153
- /////////////////// INFO WINDOW ////////////////////
154
- ////////////////////////////////////////////////////
155
-
156
- // creates infowindows
157
- this.createInfoWindow = function(marker_container){
158
- var info_window;
159
- if (this.exists(marker_container.description)) {
160
- //create the infowindow
161
- if (this.markers_conf.infobox === "description") {
162
- marker_container.info_window = new Microsoft.Maps.Infobox(marker_container.serviceObject.getLocation(), { description: marker_container.description, visible: false, showCloseButton: true});
23
+ Gmaps4RailsBing.prototype.getMapType = function() {
24
+ switch (this.map_options.type) {
25
+ case "road":
26
+ return Microsoft.Maps.MapTypeId.road;
27
+ case "aerial":
28
+ return Microsoft.Maps.MapTypeId.aerial;
29
+ case "auto":
30
+ return Microsoft.Maps.MapTypeId.auto;
31
+ case "birdseye":
32
+ return Microsoft.Maps.MapTypeId.birdseye;
33
+ case "collinsBart":
34
+ return Microsoft.Maps.MapTypeId.collinsBart;
35
+ case "mercator":
36
+ return Microsoft.Maps.MapTypeId.mercator;
37
+ case "ordnanceSurvey":
38
+ return Microsoft.Maps.MapTypeId.ordnanceSurvey;
39
+ default:
40
+ return Microsoft.Maps.MapTypeId.auto;
163
41
  }
164
- else {
165
- marker_container.info_window = new Microsoft.Maps.Infobox(marker_container.serviceObject.getLocation(), { htmlContent: marker_container.description, visible: false});
42
+ };
43
+ Gmaps4RailsBing.prototype.createPoint = function(lat, lng) {
44
+ return new Microsoft.Maps.Point(lat, lng);
45
+ };
46
+ Gmaps4RailsBing.prototype.createLatLng = function(lat, lng) {
47
+ return new Microsoft.Maps.Location(lat, lng);
48
+ };
49
+ Gmaps4RailsBing.prototype.createLatLngBounds = function() {};
50
+ Gmaps4RailsBing.prototype.createMap = function() {
51
+ return new Microsoft.Maps.Map(document.getElementById(this.map_options.id), {
52
+ credentials: this.map_options.provider_key,
53
+ mapTypeId: this.getMapType(),
54
+ center: this.createLatLng(this.map_options.center_latitude, this.map_options.center_longitude),
55
+ zoom: this.map_options.zoom
56
+ });
57
+ };
58
+ Gmaps4RailsBing.prototype.createSize = function(width, height) {
59
+ return new google.maps.Size(width, height);
60
+ };
61
+ Gmaps4RailsBing.prototype.createMarker = function(args) {
62
+ var marker, markerLatLng;
63
+ markerLatLng = this.createLatLng(args.Lat, args.Lng);
64
+ marker;
65
+ if (args.marker_picture === "") {
66
+ marker = new Microsoft.Maps.Pushpin(this.createLatLng(args.Lat, args.Lng), {
67
+ draggable: args.marker_draggable,
68
+ anchor: this.createImageAnchorPosition(args.Lat, args.Lng),
69
+ text: args.marker_title
70
+ });
71
+ } else {
72
+ marker = new Microsoft.Maps.Pushpin(this.createLatLng(args.Lat, args.Lng), {
73
+ draggable: args.marker_draggable,
74
+ anchor: this.createImageAnchorPosition(args.Lat, args.Lng),
75
+ icon: args.marker_picture,
76
+ height: args.marker_height,
77
+ text: args.marker_title,
78
+ width: args.marker_width
79
+ });
166
80
  }
167
-
168
- //add the listener associated
169
- Microsoft.Maps.Events.addHandler(marker_container.serviceObject, 'click', this.openInfoWindow(marker_container.info_window));
170
- this.addToMap(marker_container.info_window);
171
- }
172
- };
173
-
174
- this.openInfoWindow = function(infoWindow) {
175
- return function() {
176
- // Close the latest selected marker before opening the current one.
177
- if (this.visibleInfoWindow) {
178
- this.visibleInfoWindow.setOptions({ visible: false });
81
+ this.addToMap(marker);
82
+ return marker;
83
+ };
84
+ Gmaps4RailsBing.prototype.clearMarkers = function() {
85
+ var marker, _i, _len, _ref, _results;
86
+ _ref = this.markers;
87
+ _results = [];
88
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
89
+ marker = _ref[_i];
90
+ _results.push(this.clearMarker(marker));
91
+ }
92
+ return _results;
93
+ };
94
+ Gmaps4RailsBing.prototype.clearMarker = function(marker) {
95
+ return this.removeFromMap(marker.serviceObject);
96
+ };
97
+ Gmaps4RailsBing.prototype.showMarkers = function() {
98
+ var marker, _i, _len, _ref, _results;
99
+ _ref = this.markers;
100
+ _results = [];
101
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
102
+ marker = _ref[_i];
103
+ _results.push(this.showMarker(marker));
104
+ }
105
+ return _results;
106
+ };
107
+ Gmaps4RailsBing.prototype.showMarker = function(marker) {
108
+ return marker.serviceObject.setOptions({
109
+ visible: true
110
+ });
111
+ };
112
+ Gmaps4RailsBing.prototype.hideMarkers = function() {
113
+ var marker, _i, _len, _ref, _results;
114
+ _ref = this.markers;
115
+ _results = [];
116
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
117
+ marker = _ref[_i];
118
+ _results.push(this.hideMarker(marker));
119
+ }
120
+ return _results;
121
+ };
122
+ Gmaps4RailsBing.prototype.hideMarker = function(marker) {
123
+ return marker.serviceObject.setOptions({
124
+ visible: false
125
+ });
126
+ };
127
+ Gmaps4RailsBing.prototype.extendBoundsWithMarkers = function() {
128
+ var locationsArray, marker, _i, _len, _ref;
129
+ locationsArray = [];
130
+ _ref = this.markers;
131
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
132
+ marker = _ref[_i];
133
+ locationsArray.push(marker.serviceObject.getLocation());
134
+ }
135
+ return this.boundsObject = Microsoft.Maps.LocationRect.fromLocations(locationsArray);
136
+ };
137
+ Gmaps4RailsBing.prototype.createClusterer = function(markers_array) {};
138
+ Gmaps4RailsBing.prototype.clearClusterer = function() {};
139
+ Gmaps4RailsBing.prototype.clusterize = function() {};
140
+ Gmaps4RailsBing.prototype.createInfoWindow = function(marker_container) {
141
+ var currentMap;
142
+ if (marker_container.description != null) {
143
+ if (this.markers_conf.infobox === "description") {
144
+ marker_container.info_window = new Microsoft.Maps.Infobox(marker_container.serviceObject.getLocation(), {
145
+ description: marker_container.description,
146
+ visible: false,
147
+ showCloseButton: true
148
+ });
149
+ } else {
150
+ marker_container.info_window = new Microsoft.Maps.Infobox(marker_container.serviceObject.getLocation(), {
151
+ htmlContent: marker_container.description,
152
+ visible: false
153
+ });
179
154
  }
180
- infoWindow.setOptions({ visible:true });
181
- this.visibleInfoWindow = infoWindow;
155
+ currentMap = this;
156
+ Microsoft.Maps.Events.addHandler(marker_container.serviceObject, 'click', this.openInfoWindow(currentMap, marker_container.info_window));
157
+ return this.addToMap(marker_container.info_window);
158
+ }
159
+ };
160
+ Gmaps4RailsBing.prototype.openInfoWindow = function(currentMap, infoWindow) {
161
+ return function() {
162
+ if (currentMap.visibleInfoWindow) {
163
+ currentMap.visibleInfoWindow.setOptions({
164
+ visible: false
165
+ });
166
+ }
167
+ infoWindow.setOptions({
168
+ visible: true
169
+ });
170
+ return currentMap.visibleInfoWindow = infoWindow;
182
171
  };
183
- };
184
-
185
- ////////////////////////////////////////////////////
186
- /////////////////// Other methods //////////////////
187
- ////////////////////////////////////////////////////
188
-
189
- this.fitBounds = function(){
190
- this.map.setView({bounds: this.boundsObject});
191
- };
192
-
193
- this.addToMap = function(object){
194
- this.map.entities.push(object);
195
- };
196
-
197
- this.removeFromMap = function(object){
198
- this.map.entities.remove(object);
199
- };
200
-
201
- this.centerMapOnUser = function(){
202
- this.map.setView({ center: this.userLocation});
203
- };
204
- };
205
-
206
- Gmaps4RailsBing.prototype = new Gmaps4Rails();
172
+ };
173
+ Gmaps4RailsBing.prototype.fitBounds = function() {
174
+ return this.map.setView({
175
+ bounds: this.boundsObject
176
+ });
177
+ };
178
+ Gmaps4RailsBing.prototype.addToMap = function(object) {
179
+ return this.map.entities.push(object);
180
+ };
181
+ Gmaps4RailsBing.prototype.removeFromMap = function(object) {
182
+ return this.map.entities.remove(object);
183
+ };
184
+ Gmaps4RailsBing.prototype.centerMapOnUser = function() {
185
+ return this.map.setView({
186
+ center: this.userLocation
187
+ });
188
+ };
189
+ return Gmaps4RailsBing;
190
+ })();
191
+ }).call(this);
@@ -1,306 +1,276 @@
1
- var Gmaps4RailsGoogle = function() {
2
-
3
- //Map settings
4
- this.map_options = {
5
- disableDefaultUI: false,
6
- disableDoubleClickZoom: false,
7
- type: "ROADMAP" // HYBRID, ROADMAP, SATELLITE, TERRAIN
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;
8
9
  };
9
-
10
- this.mergeWithDefault("map_options");
11
-
12
- //markers + info styling
13
- this.markers_conf = {
14
- clusterer_gridSize: 50,
15
- clusterer_maxZoom: 5,
16
- custom_cluster_pictures: null,
17
- custom_infowindow_class: null
18
- };
19
-
20
- this.mergeWithDefault("markers_conf");
21
-
22
- this.kml_options = {
23
- clickable: true,
24
- preserveViewport: false,
25
- suppressInfoWindows: false
26
- };
27
-
28
- //Polygon Styling
29
- this.polygons_conf = { // default style for polygons
30
- strokeColor: "#FFAA00",
31
- strokeOpacity: 0.8,
32
- strokeWeight: 2,
33
- fillColor: "#000000",
34
- fillOpacity: 0.35
35
- };
36
-
37
- //Polyline Styling
38
- this.polylines_conf = { //default style for polylines
39
- strokeColor: "#FF0000",
40
- strokeOpacity: 1,
41
- strokeWeight: 2
42
- };
43
-
44
- //Circle Styling
45
- this.circles_conf = { //default style for circles
46
- fillColor: "#00AAFF",
47
- fillOpacity: 0.35,
48
- strokeColor: "#FFAA00",
49
- strokeOpacity: 0.8,
50
- strokeWeight: 2,
51
- clickable: false,
52
- zIndex: null
53
- };
54
-
55
- //Direction Settings
56
- this.direction_conf = {
57
- panel_id: null,
58
- display_panel: false,
59
- origin: null,
60
- destination: null,
61
- waypoints: [], //[{location: "toulouse,fr", stopover: true}, {location: "Clermont-Ferrand, fr", stopover: true}]
62
- optimizeWaypoints: false,
63
- unitSystem: "METRIC", //IMPERIAL
64
- avoidHighways: false,
65
- avoidTolls: false,
66
- region: null,
67
- travelMode: "DRIVING" //WALKING, BICYCLING
68
- };
69
-
70
- ////////////////////////////////////////////////////
71
- /////////////// Basic Objects //////////////
72
- ////////////////////////////////////////////////////
73
-
74
- this.createPoint = function(lat, lng){
75
- return new google.maps.Point(lat, lng);
76
- };
77
-
78
- this.createLatLng = function(lat, lng){
79
- return new google.maps.LatLng(lat, lng);
80
- };
81
-
82
- this.createLatLngBounds = function(){
83
- return new google.maps.LatLngBounds();
84
- };
85
-
86
- this.createMap = function(){
87
- return new google.maps.Map(document.getElementById(this.map_options.id), {
88
- maxZoom: this.map_options.maxZoom,
89
- minZoom: this.map_options.minZoom,
90
- zoom: this.map_options.zoom,
91
- center: this.createLatLng(this.map_options.center_latitude, this.map_options.center_longitude),
92
- mapTypeId: google.maps.MapTypeId[this.map_options.type],
93
- mapTypeControl: this.map_options.mapTypeControl,
94
- disableDefaultUI: this.map_options.disableDefaultUI,
95
- disableDoubleClickZoom: this.map_options.disableDoubleClickZoom,
96
- draggable: this.map_options.draggable
97
- });
98
- };
99
-
100
- this.createMarkerImage = function(markerPicture, markerSize, origin, anchor, scaledSize) {
101
- return new google.maps.MarkerImage(markerPicture, markerSize, origin, anchor, scaledSize);
102
- };
103
-
104
-
105
- this.createSize = function(width, height){
106
- return new google.maps.Size(width, height);
107
- };
108
-
109
- ////////////////////////////////////////////////////
110
- ////////////////////// Markers /////////////////////
111
- ////////////////////////////////////////////////////
112
-
113
- this.createMarker = function(args){
114
- var markerLatLng = this.createLatLng(args.Lat, args.Lng);
115
-
116
- // Marker sizes are expressed as a Size of X,Y
117
- if (args.marker_picture === "" && args.rich_marker === null) {
118
- return new google.maps.Marker({position: markerLatLng, map: this.map, title: args.marker_title, draggable: args.marker_draggable});
119
- }
120
- else if (args.rich_marker !== null){
121
- return new RichMarker({position: markerLatLng,
122
- map: this.map,
123
- draggable: args.marker_draggable,
124
- content: args.rich_marker,
125
- flat: args.marker_anchor === null ? false : args.marker_anchor[1],
126
- anchor: args.marker_anchor === null ? 0 : args.marker_anchor[0]
127
- });
128
- }
129
- else {
130
- // calculate MarkerImage anchor location
131
- var imageAnchorPosition = this.createImageAnchorPosition(args.marker_anchor);
132
- var shadowAnchorPosition = this.createImageAnchorPosition(args.shadow_anchor);
133
-
134
- //create or retrieve existing MarkerImages
135
- var markerImage = this.createOrRetrieveImage(args.marker_picture, args.marker_width, args.marker_height, imageAnchorPosition);
136
- var shadowImage = this.createOrRetrieveImage(args.shadow_picture, args.shadow_width, args.shadow_height, shadowAnchorPosition);
137
- return new google.maps.Marker({position: markerLatLng, map: this.map, icon: markerImage, title: args.marker_title, draggable: args.marker_draggable, shadow: shadowImage});
138
- }
139
- };
140
-
141
- //checks if obj is included in arr Array and returns the position or false
142
- this.includeMarkerImage = function(arr, obj) {
143
- for(var i=0; i<arr.length; i++) {
144
- if (arr[i].url == obj) {return i;}
145
- }
146
- return false;
147
- };
148
-
149
- // checks if MarkerImage exists before creating a new one
150
- // returns a MarkerImage or false if ever something wrong is passed as argument
151
- this.createOrRetrieveImage = function(currentMarkerPicture, markerWidth, markerHeight, imageAnchorPosition){
152
- if (currentMarkerPicture === "" || currentMarkerPicture === null )
153
- { return null;}
154
-
155
- var test_image_index = this.includeMarkerImage(this.markerImages, currentMarkerPicture);
156
- switch (test_image_index)
157
- {
158
- case false:
159
- var markerImage = this.createMarkerImage(currentMarkerPicture, this.createSize(markerWidth, markerHeight), null, imageAnchorPosition, null );
160
- this.markerImages.push(markerImage);
161
- return markerImage;
162
- break;
163
- default:
164
- if (typeof test_image_index == 'number') { return this.markerImages[test_image_index]; }
165
- else { return false; }
166
- break;
167
- }
168
- };
169
-
170
- // clear markers
171
- this.clearMarkers = function() {
172
- for (var i = 0; i < this.markers.length; ++i) {
173
- this.clearMarker(this.markers[i]);
10
+ this.Gmaps4RailsGoogle = (function() {
11
+ __extends(Gmaps4RailsGoogle, Gmaps4Rails);
12
+ function Gmaps4RailsGoogle() {
13
+ Gmaps4RailsGoogle.__super__.constructor.apply(this, arguments);
14
+ this.map_options = {
15
+ disableDefaultUI: false,
16
+ disableDoubleClickZoom: false,
17
+ type: "ROADMAP"
18
+ };
19
+ this.markers_conf = {
20
+ clusterer_gridSize: 50,
21
+ clusterer_maxZoom: 5,
22
+ custom_cluster_pictures: null,
23
+ custom_infowindow_class: null
24
+ };
25
+ this.mergeWithDefault("map_options");
26
+ this.mergeWithDefault("markers_conf");
27
+ this.kml_options = {
28
+ clickable: true,
29
+ preserveViewport: false,
30
+ suppressInfoWindows: false
31
+ };
32
+ this.polygons_conf = {
33
+ strokeColor: "#FFAA00",
34
+ strokeOpacity: 0.8,
35
+ strokeWeight: 2,
36
+ fillColor: "#000000",
37
+ fillOpacity: 0.35
38
+ };
39
+ this.polylines_conf = {
40
+ strokeColor: "#FF0000",
41
+ strokeOpacity: 1,
42
+ strokeWeight: 2
43
+ };
44
+ this.circles_conf = {
45
+ fillColor: "#00AAFF",
46
+ fillOpacity: 0.35,
47
+ strokeColor: "#FFAA00",
48
+ strokeOpacity: 0.8,
49
+ strokeWeight: 2,
50
+ clickable: false,
51
+ zIndex: null
52
+ };
53
+ this.direction_conf = {
54
+ panel_id: null,
55
+ display_panel: false,
56
+ origin: null,
57
+ destination: null,
58
+ waypoints: [],
59
+ optimizeWaypoints: false,
60
+ unitSystem: "METRIC",
61
+ avoidHighways: false,
62
+ avoidTolls: false,
63
+ region: null,
64
+ travelMode: "DRIVING"
65
+ };
174
66
  }
175
- };
176
-
177
- //show and hide markers
178
- this.showMarkers = function() {
179
- for (var i = 0; i < this.markers.length; ++i) {
180
- this.showMarker(this.markers[i]);
181
- }
182
- };
183
-
184
- this.hideMarkers = function() {
185
- for (var i = 0; i < this.markers.length; ++i) {
186
- this.hideMarker(this.markers[i]);
187
- }
188
- };
189
-
190
- this.clearMarker = function(marker) {
191
- marker.serviceObject.setMap(null);
192
- };
193
-
194
- this.showMarker = function(marker) {
195
- marker.serviceObject.setVisible(true);
196
- };
197
-
198
- this.hideMarker = function(marker) {
199
- marker.serviceObject.setVisible(false);
200
- };
201
-
202
- this.extendBoundsWithMarkers = function(){
203
- for (var i = 0; i < this.markers.length; ++i) {
204
- this.boundsObject.extend(this.markers[i].serviceObject.position);
205
- }
206
- };
207
-
208
- ////////////////////////////////////////////////////
209
- /////////////////// Clusterer //////////////////////
210
- ////////////////////////////////////////////////////
211
-
212
- this.createClusterer = function(markers_array){
213
- return new MarkerClusterer( this.map,
214
- markers_array,
215
- { maxZoom: this.markers_conf.clusterer_maxZoom, gridSize: this.markers_conf.clusterer_gridSize, styles: this.customClusterer() }
216
- );
217
- };
218
-
219
- this.clearClusterer = function() {
220
- this.markerClusterer.clearMarkers();
221
- };
222
-
223
- //creates clusters
224
- this.clusterize = function()
225
- {
226
- if (this.markers_conf.do_clustering === true)
227
- {
228
- //first clear the existing clusterer if any
229
- if (this.markerClusterer !== null) {
230
- this.clearClusterer();
67
+ Gmaps4RailsGoogle.prototype.createPoint = function(lat, lng) {
68
+ return new google.maps.Point(lat, lng);
69
+ };
70
+ Gmaps4RailsGoogle.prototype.createLatLng = function(lat, lng) {
71
+ return new google.maps.LatLng(lat, lng);
72
+ };
73
+ Gmaps4RailsGoogle.prototype.createLatLngBounds = function() {
74
+ return new google.maps.LatLngBounds();
75
+ };
76
+ Gmaps4RailsGoogle.prototype.createMap = function() {
77
+ return new google.maps.Map(document.getElementById(this.map_options.id), {
78
+ maxZoom: this.map_options.maxZoom,
79
+ minZoom: this.map_options.minZoom,
80
+ zoom: this.map_options.zoom,
81
+ center: this.createLatLng(this.map_options.center_latitude, this.map_options.center_longitude),
82
+ mapTypeId: google.maps.MapTypeId[this.map_options.type],
83
+ mapTypeControl: this.map_options.mapTypeControl,
84
+ disableDefaultUI: this.map_options.disableDefaultUI,
85
+ disableDoubleClickZoom: this.map_options.disableDoubleClickZoom,
86
+ draggable: this.map_options.draggable
87
+ });
88
+ };
89
+ Gmaps4RailsGoogle.prototype.createMarkerImage = function(markerPicture, markerSize, origin, anchor, scaledSize) {
90
+ return new google.maps.MarkerImage(markerPicture, markerSize, origin, anchor, scaledSize);
91
+ };
92
+ Gmaps4RailsGoogle.prototype.createSize = function(width, height) {
93
+ return new google.maps.Size(width, height);
94
+ };
95
+ Gmaps4RailsGoogle.prototype.createMarker = function(args) {
96
+ var imageAnchorPosition, markerImage, markerLatLng, shadowAnchorPosition, shadowImage;
97
+ markerLatLng = this.createLatLng(args.Lat, args.Lng);
98
+ if (args.marker_picture && args.rich_marker === null) {
99
+ return new google.maps.Marker({
100
+ position: markerLatLng,
101
+ map: this.map,
102
+ title: args.marker_title,
103
+ draggable: args.marker_draggable
104
+ });
105
+ } else if (args.rich_marker !== null) {
106
+ return new RichMarker({
107
+ position: markerLatLng,
108
+ map: this["this"].map,
109
+ draggable: args.marker_draggable,
110
+ content: args.rich_marker,
111
+ flat: args.marker_anchor === null ? false : args.marker_anchor[1],
112
+ anchor: args.marker_anchor === null ? 0 : args.marker_anchor[0]
113
+ });
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
+ });
231
127
  }
232
-
233
- var markers_array = new Array;
234
- for (var i = 0; i < this.markers.length; ++i) {
235
- markers_array.push(this.markers[i].serviceObject);
128
+ };
129
+ Gmaps4RailsGoogle.prototype.includeMarkerImage = function(arr, obj) {
130
+ var index, object, _len;
131
+ for (index = 0, _len = arr.length; index < _len; index++) {
132
+ object = arr[index];
133
+ if (object.url === obj) {
134
+ return index;
135
+ }
236
136
  }
237
-
238
- this.markerClusterer = this.createClusterer(markers_array);
239
- }
240
- };
241
-
242
- ////////////////////////////////////////////////////
243
- /////////////////// INFO WINDOW ////////////////////
244
- ////////////////////////////////////////////////////
245
-
246
- // creates infowindows
247
- this.createInfoWindow = function(marker_container){
248
- var info_window;
249
- if (this.markers_conf.custom_infowindow_class === null && this.exists(marker_container.description)) {
250
- //create the infowindow
251
- info_window = new google.maps.InfoWindow({content: marker_container.description });
252
- //add the listener associated
253
- google.maps.event.addListener(marker_container.serviceObject, 'click', this.openInfoWindow(info_window, marker_container.serviceObject));
254
- }
255
- else { //creating custom infowindow
256
- if (this.exists(marker_container.description)) {
257
- var boxText = document.createElement("div");
258
- boxText.setAttribute("class", this.markers_conf.custom_infowindow_class); //to customize
259
- boxText.innerHTML = marker_container.description;
260
- info_window = new InfoBox(this.infobox(boxText));
261
- google.maps.event.addListener(marker_container.serviceObject, 'click', this.openInfoWindow(info_window, marker_container.serviceObject));
137
+ return false;
138
+ };
139
+ Gmaps4RailsGoogle.prototype.createOrRetrieveImage = function(currentMarkerPicture, markerWidth, markerHeight, imageAnchorPosition) {
140
+ var markerImage, test_image_index;
141
+ if (currentMarkerPicture === "" || currentMarkerPicture === null) {
142
+ return null;
262
143
  }
263
- }
264
- };
265
-
266
- this.openInfoWindow = function(infoWindow, marker) {
267
- return function() {
268
- // Close the latest selected marker before opening the current one.
269
- if (this.visibleInfoWindow) {
270
- this.visibleInfoWindow.close();
144
+ test_image_index = this.includeMarkerImage(this.markerImages, currentMarkerPicture);
145
+ switch (test_image_index) {
146
+ case false:
147
+ markerImage = this.createMarkerImage(currentMarkerPicture, this.createSize(markerWidth, markerHeight), null, imageAnchorPosition, null);
148
+ this.markerImages.push(markerImage);
149
+ return markerImage;
150
+ break;
151
+ default:
152
+ if (typeof test_image_index === 'number') {
153
+ return this.markerImages[test_image_index];
154
+ }
155
+ return false;
271
156
  }
272
-
273
- infoWindow.open(this.map, marker);
274
- this.visibleInfoWindow = infoWindow;
275
157
  };
276
- };
277
-
278
- ////////////////////////////////////////////////////
279
- ///////////////// KML //////////////////
280
- ////////////////////////////////////////////////////
281
-
282
- this.createKmlLayer = function(kml){
283
- var kml_options = kml.options || {};
284
- kml_options = this.mergeObjectWithDefault(kml_options, this.kml_options);
285
- var kml = new google.maps.KmlLayer( kml.url,
286
- kml_options
287
- );
288
- kml.setMap(this.map);
289
- return kml;
290
- };
291
-
292
-
293
- ////////////////////////////////////////////////////
294
- /////////////////// Other methods //////////////////
295
- ////////////////////////////////////////////////////
296
-
297
- this.fitBounds = function(){
298
- this.map.fitBounds(this.boundsObject);
299
- };
300
-
301
- this.centerMapOnUser = function(){
302
- this.map.setCenter(this.userLocation);
303
- };
304
- };
305
-
306
- Gmaps4RailsGoogle.prototype = new Gmaps4Rails();
158
+ Gmaps4RailsGoogle.prototype.clearMarkers = function() {
159
+ var marker, _i, _len, _ref, _results;
160
+ _ref = this.markers;
161
+ _results = [];
162
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
163
+ marker = _ref[_i];
164
+ _results.push(this.clearMarker(marker));
165
+ }
166
+ return _results;
167
+ };
168
+ Gmaps4RailsGoogle.prototype.showMarkers = function() {
169
+ var marker, _i, _len, _ref, _results;
170
+ _ref = this.markers;
171
+ _results = [];
172
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
173
+ marker = _ref[_i];
174
+ _results.push(this.showMarker(marker));
175
+ }
176
+ return _results;
177
+ };
178
+ Gmaps4RailsGoogle.prototype.hideMarkers = function() {
179
+ var marker, _i, _len, _ref, _results;
180
+ _ref = this.markers;
181
+ _results = [];
182
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
183
+ marker = _ref[_i];
184
+ _results.push(this.hideMarker(marker));
185
+ }
186
+ return _results;
187
+ };
188
+ Gmaps4RailsGoogle.prototype.clearMarker = function(marker) {
189
+ return marker.serviceObject.setMap(null);
190
+ };
191
+ Gmaps4RailsGoogle.prototype.showMarker = function(marker) {
192
+ return marker.serviceObject.setVisible(true);
193
+ };
194
+ Gmaps4RailsGoogle.prototype.hideMarker = function(marker) {
195
+ return marker.serviceObject.setVisible(false);
196
+ };
197
+ Gmaps4RailsGoogle.prototype.extendBoundsWithMarkers = function() {
198
+ var marker, _i, _len, _ref, _results;
199
+ _ref = this.markers;
200
+ _results = [];
201
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
202
+ marker = _ref[_i];
203
+ _results.push(this.boundsObject.extend(marker.serviceObject.position));
204
+ }
205
+ return _results;
206
+ };
207
+ Gmaps4RailsGoogle.prototype.createClusterer = function(markers_array) {
208
+ return new MarkerClusterer(this.map, markers_array, {
209
+ maxZoom: this.markers_conf.clusterer_maxZoom,
210
+ gridSize: this.markers_conf.clusterer_gridSize,
211
+ styles: this.customClusterer()
212
+ });
213
+ };
214
+ Gmaps4RailsGoogle.prototype.clearClusterer = function() {
215
+ return this.markerClusterer.clearMarkers();
216
+ };
217
+ Gmaps4RailsGoogle.prototype.clusterize = function() {
218
+ var marker, markers_array, _i, _len, _ref;
219
+ if (this.markers_conf.do_clustering === true) {
220
+ if (this.markerClusterer !== null) {
221
+ this.clearClusterer();
222
+ }
223
+ markers_array = new Array;
224
+ _ref = this.markers;
225
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
226
+ marker = _ref[_i];
227
+ markers_array.push(marker.serviceObject);
228
+ }
229
+ return this.markerClusterer = this.createClusterer(markers_array);
230
+ }
231
+ };
232
+ Gmaps4RailsGoogle.prototype.createInfoWindow = function(marker_container) {
233
+ var boxText, currentMap, info_window;
234
+ if (this.markers_conf.custom_infowindow_class === null && (marker_container.description != null)) {
235
+ info_window = new google.maps.InfoWindow({
236
+ content: marker_container.description
237
+ });
238
+ currentMap = this;
239
+ return google.maps.event.addListener(marker_container.serviceObject, 'click', this.openInfoWindow(currentMap, info_window, marker_container.serviceObject));
240
+ } else {
241
+ if (marker_container.description != null) {
242
+ boxText = document.createElement("div");
243
+ boxText.setAttribute("class", this.markers_conf.custom_infowindow_class);
244
+ boxText.innerHTML = marker_container.description;
245
+ info_window = new InfoBox(this.infobox(boxText));
246
+ currentMap = this;
247
+ return google.maps.event.addListener(marker_container.serviceObject, 'click', this.openInfoWindow(currentMap, info_window, marker_container.serviceObject));
248
+ }
249
+ }
250
+ };
251
+ Gmaps4RailsGoogle.prototype.openInfoWindow = function(currentMap, infoWindow, marker) {
252
+ return function() {
253
+ if (currentMap.visibleInfoWindow !== null) {
254
+ currentMap.visibleInfoWindow.close();
255
+ }
256
+ infoWindow.open(currentMap.map, marker);
257
+ return currentMap.visibleInfoWindow = infoWindow;
258
+ };
259
+ };
260
+ Gmaps4RailsGoogle.prototype.createKmlLayer = function(kml) {
261
+ var kml_options;
262
+ kml_options = kml.options || {};
263
+ kml_options = this.mergeObjectWithDefault(kml_options, this.kml_options);
264
+ kml = new google.maps.KmlLayer(kml.url, kml_options);
265
+ kml.setMap(this.map);
266
+ return kml;
267
+ };
268
+ Gmaps4RailsGoogle.prototype.fitBounds = function() {
269
+ return this.map.fitBounds(this.boundsObject);
270
+ };
271
+ Gmaps4RailsGoogle.prototype.centerMapOnUser = function() {
272
+ return this.map.setCenter(this.userLocation);
273
+ };
274
+ return Gmaps4RailsGoogle;
275
+ })();
276
+ }).call(this);