gmapsjs-rails 0.2.30.1
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.
- checksums.yaml +7 -0
- data/LICENSE +22 -0
- data/README.md +28 -0
- data/Rakefile +2 -0
- data/app/assets/javascripts/gmaps.controls.js +49 -0
- data/app/assets/javascripts/gmaps.core.js +457 -0
- data/app/assets/javascripts/gmaps.events.js +52 -0
- data/app/assets/javascripts/gmaps.geofences.js +14 -0
- data/app/assets/javascripts/gmaps.geometry.js +205 -0
- data/app/assets/javascripts/gmaps.js +2065 -0
- data/app/assets/javascripts/gmaps.layers.js +154 -0
- data/app/assets/javascripts/gmaps.map_types.js +29 -0
- data/app/assets/javascripts/gmaps.markers.js +189 -0
- data/app/assets/javascripts/gmaps.native_extensions.js +110 -0
- data/app/assets/javascripts/gmaps.overlays.js +127 -0
- data/app/assets/javascripts/gmaps.routes.js +305 -0
- data/app/assets/javascripts/gmaps.static.js +245 -0
- data/app/assets/javascripts/gmaps.streetview.js +44 -0
- data/app/assets/javascripts/gmaps.styles.js +9 -0
- data/app/assets/javascripts/gmaps.utils.js +42 -0
- data/lib/gmapsjs-rails/engine.rb +6 -0
- data/lib/gmapsjs-rails/version.rb +5 -0
- data/lib/gmapsjs-rails.rb +2 -0
- metadata +86 -0
@@ -0,0 +1,154 @@
|
|
1
|
+
GMaps.prototype.getFromFusionTables = function(options) {
|
2
|
+
var events = options.events;
|
3
|
+
|
4
|
+
delete options.events;
|
5
|
+
|
6
|
+
var fusion_tables_options = options,
|
7
|
+
layer = new google.maps.FusionTablesLayer(fusion_tables_options);
|
8
|
+
|
9
|
+
for (var ev in events) {
|
10
|
+
(function(object, name) {
|
11
|
+
google.maps.event.addListener(object, name, function(e) {
|
12
|
+
events[name].apply(this, [e]);
|
13
|
+
});
|
14
|
+
})(layer, ev);
|
15
|
+
}
|
16
|
+
|
17
|
+
this.layers.push(layer);
|
18
|
+
|
19
|
+
return layer;
|
20
|
+
};
|
21
|
+
|
22
|
+
GMaps.prototype.loadFromFusionTables = function(options) {
|
23
|
+
var layer = this.getFromFusionTables(options);
|
24
|
+
layer.setMap(this.map);
|
25
|
+
|
26
|
+
return layer;
|
27
|
+
};
|
28
|
+
|
29
|
+
GMaps.prototype.getFromKML = function(options) {
|
30
|
+
var url = options.url,
|
31
|
+
events = options.events;
|
32
|
+
|
33
|
+
delete options.url;
|
34
|
+
delete options.events;
|
35
|
+
|
36
|
+
var kml_options = options,
|
37
|
+
layer = new google.maps.KmlLayer(url, kml_options);
|
38
|
+
|
39
|
+
for (var ev in events) {
|
40
|
+
(function(object, name) {
|
41
|
+
google.maps.event.addListener(object, name, function(e) {
|
42
|
+
events[name].apply(this, [e]);
|
43
|
+
});
|
44
|
+
})(layer, ev);
|
45
|
+
}
|
46
|
+
|
47
|
+
this.layers.push(layer);
|
48
|
+
|
49
|
+
return layer;
|
50
|
+
};
|
51
|
+
|
52
|
+
GMaps.prototype.loadFromKML = function(options) {
|
53
|
+
var layer = this.getFromKML(options);
|
54
|
+
layer.setMap(this.map);
|
55
|
+
|
56
|
+
return layer;
|
57
|
+
};
|
58
|
+
|
59
|
+
GMaps.prototype.addLayer = function(layerName, options) {
|
60
|
+
//var default_layers = ['weather', 'clouds', 'traffic', 'transit', 'bicycling', 'panoramio', 'places'];
|
61
|
+
options = options || {};
|
62
|
+
var layer;
|
63
|
+
|
64
|
+
switch(layerName) {
|
65
|
+
case 'weather': this.singleLayers.weather = layer = new google.maps.weather.WeatherLayer();
|
66
|
+
break;
|
67
|
+
case 'clouds': this.singleLayers.clouds = layer = new google.maps.weather.CloudLayer();
|
68
|
+
break;
|
69
|
+
case 'traffic': this.singleLayers.traffic = layer = new google.maps.TrafficLayer();
|
70
|
+
break;
|
71
|
+
case 'transit': this.singleLayers.transit = layer = new google.maps.TransitLayer();
|
72
|
+
break;
|
73
|
+
case 'bicycling': this.singleLayers.bicycling = layer = new google.maps.BicyclingLayer();
|
74
|
+
break;
|
75
|
+
case 'panoramio':
|
76
|
+
this.singleLayers.panoramio = layer = new google.maps.panoramio.PanoramioLayer();
|
77
|
+
layer.setTag(options.filter);
|
78
|
+
delete options.filter;
|
79
|
+
|
80
|
+
//click event
|
81
|
+
if (options.click) {
|
82
|
+
google.maps.event.addListener(layer, 'click', function(event) {
|
83
|
+
options.click(event);
|
84
|
+
delete options.click;
|
85
|
+
});
|
86
|
+
}
|
87
|
+
break;
|
88
|
+
case 'places':
|
89
|
+
this.singleLayers.places = layer = new google.maps.places.PlacesService(this.map);
|
90
|
+
|
91
|
+
//search and nearbySearch callback, Both are the same
|
92
|
+
if (options.search || options.nearbySearch) {
|
93
|
+
var placeSearchRequest = {
|
94
|
+
bounds : options.bounds || null,
|
95
|
+
keyword : options.keyword || null,
|
96
|
+
location : options.location || null,
|
97
|
+
name : options.name || null,
|
98
|
+
radius : options.radius || null,
|
99
|
+
rankBy : options.rankBy || null,
|
100
|
+
types : options.types || null
|
101
|
+
};
|
102
|
+
|
103
|
+
if (options.search) {
|
104
|
+
layer.search(placeSearchRequest, options.search);
|
105
|
+
}
|
106
|
+
|
107
|
+
if (options.nearbySearch) {
|
108
|
+
layer.nearbySearch(placeSearchRequest, options.nearbySearch);
|
109
|
+
}
|
110
|
+
}
|
111
|
+
|
112
|
+
//textSearch callback
|
113
|
+
if (options.textSearch) {
|
114
|
+
var textSearchRequest = {
|
115
|
+
bounds : options.bounds || null,
|
116
|
+
location : options.location || null,
|
117
|
+
query : options.query || null,
|
118
|
+
radius : options.radius || null
|
119
|
+
};
|
120
|
+
|
121
|
+
layer.textSearch(textSearchRequest, options.textSearch);
|
122
|
+
}
|
123
|
+
break;
|
124
|
+
}
|
125
|
+
|
126
|
+
if (layer !== undefined) {
|
127
|
+
if (typeof layer.setOptions == 'function') {
|
128
|
+
layer.setOptions(options);
|
129
|
+
}
|
130
|
+
if (typeof layer.setMap == 'function') {
|
131
|
+
layer.setMap(this.map);
|
132
|
+
}
|
133
|
+
|
134
|
+
return layer;
|
135
|
+
}
|
136
|
+
};
|
137
|
+
|
138
|
+
GMaps.prototype.removeLayer = function(layer) {
|
139
|
+
if (typeof(layer) == "string" && this.singleLayers[layer] !== undefined) {
|
140
|
+
this.singleLayers[layer].setMap(null);
|
141
|
+
|
142
|
+
delete this.singleLayers[layer];
|
143
|
+
}
|
144
|
+
else {
|
145
|
+
for (var i = 0; i < this.layers.length; i++) {
|
146
|
+
if (this.layers[i] === layer) {
|
147
|
+
this.layers[i].setMap(null);
|
148
|
+
this.layers.splice(i, 1);
|
149
|
+
|
150
|
+
break;
|
151
|
+
}
|
152
|
+
}
|
153
|
+
}
|
154
|
+
};
|
@@ -0,0 +1,29 @@
|
|
1
|
+
GMaps.prototype.addMapType = function(mapTypeId, options) {
|
2
|
+
if (options.hasOwnProperty("getTileUrl") && typeof(options["getTileUrl"]) == "function") {
|
3
|
+
options.tileSize = options.tileSize || new google.maps.Size(256, 256);
|
4
|
+
|
5
|
+
var mapType = new google.maps.ImageMapType(options);
|
6
|
+
|
7
|
+
this.map.mapTypes.set(mapTypeId, mapType);
|
8
|
+
}
|
9
|
+
else {
|
10
|
+
throw "'getTileUrl' function required.";
|
11
|
+
}
|
12
|
+
};
|
13
|
+
|
14
|
+
GMaps.prototype.addOverlayMapType = function(options) {
|
15
|
+
if (options.hasOwnProperty("getTile") && typeof(options["getTile"]) == "function") {
|
16
|
+
var overlayMapTypeIndex = options.index;
|
17
|
+
|
18
|
+
delete options.index;
|
19
|
+
|
20
|
+
this.map.overlayMapTypes.insertAt(overlayMapTypeIndex, options);
|
21
|
+
}
|
22
|
+
else {
|
23
|
+
throw "'getTile' function required.";
|
24
|
+
}
|
25
|
+
};
|
26
|
+
|
27
|
+
GMaps.prototype.removeOverlayMapType = function(overlayMapTypeIndex) {
|
28
|
+
this.map.overlayMapTypes.removeAt(overlayMapTypeIndex);
|
29
|
+
};
|
@@ -0,0 +1,189 @@
|
|
1
|
+
GMaps.prototype.createMarker = function(options) {
|
2
|
+
if (options.lat == undefined && options.lng == undefined && options.position == undefined) {
|
3
|
+
throw 'No latitude or longitude defined.';
|
4
|
+
}
|
5
|
+
|
6
|
+
var self = this,
|
7
|
+
details = options.details,
|
8
|
+
fences = options.fences,
|
9
|
+
outside = options.outside,
|
10
|
+
base_options = {
|
11
|
+
position: new google.maps.LatLng(options.lat, options.lng),
|
12
|
+
map: null
|
13
|
+
};
|
14
|
+
|
15
|
+
delete options.lat;
|
16
|
+
delete options.lng;
|
17
|
+
delete options.fences;
|
18
|
+
delete options.outside;
|
19
|
+
|
20
|
+
var marker_options = extend_object(base_options, options),
|
21
|
+
marker = new google.maps.Marker(marker_options);
|
22
|
+
|
23
|
+
marker.fences = fences;
|
24
|
+
|
25
|
+
if (options.infoWindow) {
|
26
|
+
marker.infoWindow = new google.maps.InfoWindow(options.infoWindow);
|
27
|
+
|
28
|
+
var info_window_events = ['closeclick', 'content_changed', 'domready', 'position_changed', 'zindex_changed'];
|
29
|
+
|
30
|
+
for (var ev = 0; ev < info_window_events.length; ev++) {
|
31
|
+
(function(object, name) {
|
32
|
+
if (options.infoWindow[name]) {
|
33
|
+
google.maps.event.addListener(object, name, function(e){
|
34
|
+
options.infoWindow[name].apply(this, [e]);
|
35
|
+
});
|
36
|
+
}
|
37
|
+
})(marker.infoWindow, info_window_events[ev]);
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
var marker_events = ['animation_changed', 'clickable_changed', 'cursor_changed', 'draggable_changed', 'flat_changed', 'icon_changed', 'position_changed', 'shadow_changed', 'shape_changed', 'title_changed', 'visible_changed', 'zindex_changed'];
|
42
|
+
|
43
|
+
var marker_events_with_mouse = ['dblclick', 'drag', 'dragend', 'dragstart', 'mousedown', 'mouseout', 'mouseover', 'mouseup'];
|
44
|
+
|
45
|
+
for (var ev = 0; ev < marker_events.length; ev++) {
|
46
|
+
(function(object, name) {
|
47
|
+
if (options[name]) {
|
48
|
+
google.maps.event.addListener(object, name, function(){
|
49
|
+
options[name].apply(this, [this]);
|
50
|
+
});
|
51
|
+
}
|
52
|
+
})(marker, marker_events[ev]);
|
53
|
+
}
|
54
|
+
|
55
|
+
for (var ev = 0; ev < marker_events_with_mouse.length; ev++) {
|
56
|
+
(function(map, object, name) {
|
57
|
+
if (options[name]) {
|
58
|
+
google.maps.event.addListener(object, name, function(me){
|
59
|
+
if(!me.pixel){
|
60
|
+
me.pixel = map.getProjection().fromLatLngToPoint(me.latLng)
|
61
|
+
}
|
62
|
+
|
63
|
+
options[name].apply(this, [me]);
|
64
|
+
});
|
65
|
+
}
|
66
|
+
})(this.map, marker, marker_events_with_mouse[ev]);
|
67
|
+
}
|
68
|
+
|
69
|
+
google.maps.event.addListener(marker, 'click', function() {
|
70
|
+
this.details = details;
|
71
|
+
|
72
|
+
if (options.click) {
|
73
|
+
options.click.apply(this, [this]);
|
74
|
+
}
|
75
|
+
|
76
|
+
if (marker.infoWindow) {
|
77
|
+
self.hideInfoWindows();
|
78
|
+
marker.infoWindow.open(self.map, marker);
|
79
|
+
}
|
80
|
+
});
|
81
|
+
|
82
|
+
google.maps.event.addListener(marker, 'rightclick', function(e) {
|
83
|
+
e.marker = this;
|
84
|
+
|
85
|
+
if (options.rightclick) {
|
86
|
+
options.rightclick.apply(this, [e]);
|
87
|
+
}
|
88
|
+
|
89
|
+
if (window.context_menu[self.el.id]['marker'] != undefined) {
|
90
|
+
self.buildContextMenu('marker', e);
|
91
|
+
}
|
92
|
+
});
|
93
|
+
|
94
|
+
if (marker.fences) {
|
95
|
+
google.maps.event.addListener(marker, 'dragend', function() {
|
96
|
+
self.checkMarkerGeofence(marker, function(m, f) {
|
97
|
+
outside(m, f);
|
98
|
+
});
|
99
|
+
});
|
100
|
+
}
|
101
|
+
|
102
|
+
return marker;
|
103
|
+
};
|
104
|
+
|
105
|
+
GMaps.prototype.addMarker = function(options) {
|
106
|
+
var marker;
|
107
|
+
if(options.hasOwnProperty('gm_accessors_')) {
|
108
|
+
// Native google.maps.Marker object
|
109
|
+
marker = options;
|
110
|
+
}
|
111
|
+
else {
|
112
|
+
if ((options.hasOwnProperty('lat') && options.hasOwnProperty('lng')) || options.position) {
|
113
|
+
marker = this.createMarker(options);
|
114
|
+
}
|
115
|
+
else {
|
116
|
+
throw 'No latitude or longitude defined.';
|
117
|
+
}
|
118
|
+
}
|
119
|
+
|
120
|
+
marker.setMap(this.map);
|
121
|
+
|
122
|
+
if(this.markerClusterer) {
|
123
|
+
this.markerClusterer.addMarker(marker);
|
124
|
+
}
|
125
|
+
|
126
|
+
this.markers.push(marker);
|
127
|
+
|
128
|
+
GMaps.fire('marker_added', marker, this);
|
129
|
+
|
130
|
+
return marker;
|
131
|
+
};
|
132
|
+
|
133
|
+
GMaps.prototype.addMarkers = function(array) {
|
134
|
+
for (var i = 0, marker; marker=array[i]; i++) {
|
135
|
+
this.addMarker(marker);
|
136
|
+
}
|
137
|
+
|
138
|
+
return this.markers;
|
139
|
+
};
|
140
|
+
|
141
|
+
GMaps.prototype.hideInfoWindows = function() {
|
142
|
+
for (var i = 0, marker; marker = this.markers[i]; i++){
|
143
|
+
if (marker.infoWindow){
|
144
|
+
marker.infoWindow.close();
|
145
|
+
}
|
146
|
+
}
|
147
|
+
};
|
148
|
+
|
149
|
+
GMaps.prototype.removeMarker = function(marker) {
|
150
|
+
for (var i = 0; i < this.markers.length; i++) {
|
151
|
+
if (this.markers[i] === marker) {
|
152
|
+
this.markers[i].setMap(null);
|
153
|
+
this.markers.splice(i, 1);
|
154
|
+
|
155
|
+
if(this.markerClusterer) {
|
156
|
+
this.markerClusterer.removeMarker(marker);
|
157
|
+
}
|
158
|
+
|
159
|
+
GMaps.fire('marker_removed', marker, this);
|
160
|
+
|
161
|
+
break;
|
162
|
+
}
|
163
|
+
}
|
164
|
+
|
165
|
+
return marker;
|
166
|
+
};
|
167
|
+
|
168
|
+
GMaps.prototype.removeMarkers = function (collection) {
|
169
|
+
if(typeof collection == 'undefined') {
|
170
|
+
for(var i = 0; i < this.markers.length; i++) {
|
171
|
+
this.markers[i].setMap(null);
|
172
|
+
}
|
173
|
+
var new_markers = [];
|
174
|
+
this.markers = new_markers;
|
175
|
+
} else {
|
176
|
+
for(var i = 0; i < this.markers.length; i++) {
|
177
|
+
if(this.markers[i] === collection[i]) {
|
178
|
+
this.markers[i].setMap(null);
|
179
|
+
}
|
180
|
+
}
|
181
|
+
var new_markers = [];
|
182
|
+
for(var i = 0; i < this.markers.length; i++) {
|
183
|
+
if(this.markers[i].getMap() != null) {
|
184
|
+
new_markers.push(this.markers[i]);
|
185
|
+
}
|
186
|
+
}
|
187
|
+
this.markers = new_markers;
|
188
|
+
}
|
189
|
+
};
|
@@ -0,0 +1,110 @@
|
|
1
|
+
//==========================
|
2
|
+
// Polygon containsLatLng
|
3
|
+
// https://github.com/tparkin/Google-Maps-Point-in-Polygon
|
4
|
+
// Poygon getBounds extension - google-maps-extensions
|
5
|
+
// http://code.google.com/p/google-maps-extensions/source/browse/google.maps.Polygon.getBounds.js
|
6
|
+
if (!google.maps.Polygon.prototype.getBounds) {
|
7
|
+
google.maps.Polygon.prototype.getBounds = function(latLng) {
|
8
|
+
var bounds = new google.maps.LatLngBounds();
|
9
|
+
var paths = this.getPaths();
|
10
|
+
var path;
|
11
|
+
|
12
|
+
for (var p = 0; p < paths.getLength(); p++) {
|
13
|
+
path = paths.getAt(p);
|
14
|
+
for (var i = 0; i < path.getLength(); i++) {
|
15
|
+
bounds.extend(path.getAt(i));
|
16
|
+
}
|
17
|
+
}
|
18
|
+
|
19
|
+
return bounds;
|
20
|
+
};
|
21
|
+
}
|
22
|
+
|
23
|
+
if (!google.maps.Polygon.prototype.containsLatLng) {
|
24
|
+
// Polygon containsLatLng - method to determine if a latLng is within a polygon
|
25
|
+
google.maps.Polygon.prototype.containsLatLng = function(latLng) {
|
26
|
+
// Exclude points outside of bounds as there is no way they are in the poly
|
27
|
+
var bounds = this.getBounds();
|
28
|
+
|
29
|
+
if (bounds !== null && !bounds.contains(latLng)) {
|
30
|
+
return false;
|
31
|
+
}
|
32
|
+
|
33
|
+
// Raycast point in polygon method
|
34
|
+
var inPoly = false;
|
35
|
+
|
36
|
+
var numPaths = this.getPaths().getLength();
|
37
|
+
for (var p = 0; p < numPaths; p++) {
|
38
|
+
var path = this.getPaths().getAt(p);
|
39
|
+
var numPoints = path.getLength();
|
40
|
+
var j = numPoints - 1;
|
41
|
+
|
42
|
+
for (var i = 0; i < numPoints; i++) {
|
43
|
+
var vertex1 = path.getAt(i);
|
44
|
+
var vertex2 = path.getAt(j);
|
45
|
+
|
46
|
+
if (vertex1.lng() < latLng.lng() && vertex2.lng() >= latLng.lng() || vertex2.lng() < latLng.lng() && vertex1.lng() >= latLng.lng()) {
|
47
|
+
if (vertex1.lat() + (latLng.lng() - vertex1.lng()) / (vertex2.lng() - vertex1.lng()) * (vertex2.lat() - vertex1.lat()) < latLng.lat()) {
|
48
|
+
inPoly = !inPoly;
|
49
|
+
}
|
50
|
+
}
|
51
|
+
|
52
|
+
j = i;
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
return inPoly;
|
57
|
+
};
|
58
|
+
}
|
59
|
+
|
60
|
+
google.maps.LatLngBounds.prototype.containsLatLng = function(latLng) {
|
61
|
+
return this.contains(latLng);
|
62
|
+
};
|
63
|
+
|
64
|
+
google.maps.Marker.prototype.setFences = function(fences) {
|
65
|
+
this.fences = fences;
|
66
|
+
};
|
67
|
+
|
68
|
+
google.maps.Marker.prototype.addFence = function(fence) {
|
69
|
+
this.fences.push(fence);
|
70
|
+
};
|
71
|
+
|
72
|
+
google.maps.Marker.prototype.getId = function() {
|
73
|
+
return this['__gm_id'];
|
74
|
+
};
|
75
|
+
|
76
|
+
//==========================
|
77
|
+
// Array indexOf
|
78
|
+
// https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/indexOf
|
79
|
+
if (!Array.prototype.indexOf) {
|
80
|
+
Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
|
81
|
+
"use strict";
|
82
|
+
if (this == null) {
|
83
|
+
throw new TypeError();
|
84
|
+
}
|
85
|
+
var t = Object(this);
|
86
|
+
var len = t.length >>> 0;
|
87
|
+
if (len === 0) {
|
88
|
+
return -1;
|
89
|
+
}
|
90
|
+
var n = 0;
|
91
|
+
if (arguments.length > 1) {
|
92
|
+
n = Number(arguments[1]);
|
93
|
+
if (n != n) { // shortcut for verifying if it's NaN
|
94
|
+
n = 0;
|
95
|
+
} else if (n != 0 && n != Infinity && n != -Infinity) {
|
96
|
+
n = (n > 0 || -1) * Math.floor(Math.abs(n));
|
97
|
+
}
|
98
|
+
}
|
99
|
+
if (n >= len) {
|
100
|
+
return -1;
|
101
|
+
}
|
102
|
+
var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
|
103
|
+
for (; k < len; k++) {
|
104
|
+
if (k in t && t[k] === searchElement) {
|
105
|
+
return k;
|
106
|
+
}
|
107
|
+
}
|
108
|
+
return -1;
|
109
|
+
}
|
110
|
+
}
|
@@ -0,0 +1,127 @@
|
|
1
|
+
GMaps.prototype.drawOverlay = function(options) {
|
2
|
+
var overlay = new google.maps.OverlayView(),
|
3
|
+
auto_show = true;
|
4
|
+
|
5
|
+
overlay.setMap(this.map);
|
6
|
+
|
7
|
+
if (options.auto_show != null) {
|
8
|
+
auto_show = options.auto_show;
|
9
|
+
}
|
10
|
+
|
11
|
+
overlay.onAdd = function() {
|
12
|
+
var el = document.createElement('div');
|
13
|
+
|
14
|
+
el.style.borderStyle = "none";
|
15
|
+
el.style.borderWidth = "0px";
|
16
|
+
el.style.position = "absolute";
|
17
|
+
el.style.zIndex = 100;
|
18
|
+
el.innerHTML = options.content;
|
19
|
+
|
20
|
+
overlay.el = el;
|
21
|
+
|
22
|
+
if (!options.layer) {
|
23
|
+
options.layer = 'overlayLayer';
|
24
|
+
}
|
25
|
+
|
26
|
+
var panes = this.getPanes(),
|
27
|
+
overlayLayer = panes[options.layer],
|
28
|
+
stop_overlay_events = ['contextmenu', 'DOMMouseScroll', 'dblclick', 'mousedown'];
|
29
|
+
|
30
|
+
overlayLayer.appendChild(el);
|
31
|
+
|
32
|
+
for (var ev = 0; ev < stop_overlay_events.length; ev++) {
|
33
|
+
(function(object, name) {
|
34
|
+
google.maps.event.addDomListener(object, name, function(e){
|
35
|
+
if (navigator.userAgent.toLowerCase().indexOf('msie') != -1 && document.all) {
|
36
|
+
e.cancelBubble = true;
|
37
|
+
e.returnValue = false;
|
38
|
+
}
|
39
|
+
else {
|
40
|
+
e.stopPropagation();
|
41
|
+
}
|
42
|
+
});
|
43
|
+
})(el, stop_overlay_events[ev]);
|
44
|
+
}
|
45
|
+
|
46
|
+
google.maps.event.trigger(this, 'ready');
|
47
|
+
};
|
48
|
+
|
49
|
+
overlay.draw = function() {
|
50
|
+
var projection = this.getProjection(),
|
51
|
+
pixel = projection.fromLatLngToDivPixel(new google.maps.LatLng(options.lat, options.lng));
|
52
|
+
|
53
|
+
options.horizontalOffset = options.horizontalOffset || 0;
|
54
|
+
options.verticalOffset = options.verticalOffset || 0;
|
55
|
+
|
56
|
+
var el = overlay.el,
|
57
|
+
content = el.children[0],
|
58
|
+
content_height = content.clientHeight,
|
59
|
+
content_width = content.clientWidth;
|
60
|
+
|
61
|
+
switch (options.verticalAlign) {
|
62
|
+
case 'top':
|
63
|
+
el.style.top = (pixel.y - content_height + options.verticalOffset) + 'px';
|
64
|
+
break;
|
65
|
+
default:
|
66
|
+
case 'middle':
|
67
|
+
el.style.top = (pixel.y - (content_height / 2) + options.verticalOffset) + 'px';
|
68
|
+
break;
|
69
|
+
case 'bottom':
|
70
|
+
el.style.top = (pixel.y + options.verticalOffset) + 'px';
|
71
|
+
break;
|
72
|
+
}
|
73
|
+
|
74
|
+
switch (options.horizontalAlign) {
|
75
|
+
case 'left':
|
76
|
+
el.style.left = (pixel.x - content_width + options.horizontalOffset) + 'px';
|
77
|
+
break;
|
78
|
+
default:
|
79
|
+
case 'center':
|
80
|
+
el.style.left = (pixel.x - (content_width / 2) + options.horizontalOffset) + 'px';
|
81
|
+
break;
|
82
|
+
case 'right':
|
83
|
+
el.style.left = (pixel.x + options.horizontalOffset) + 'px';
|
84
|
+
break;
|
85
|
+
}
|
86
|
+
|
87
|
+
el.style.display = auto_show ? 'block' : 'none';
|
88
|
+
|
89
|
+
if (!auto_show) {
|
90
|
+
options.show.apply(this, [el]);
|
91
|
+
}
|
92
|
+
};
|
93
|
+
|
94
|
+
overlay.onRemove = function() {
|
95
|
+
var el = overlay.el;
|
96
|
+
|
97
|
+
if (options.remove) {
|
98
|
+
options.remove.apply(this, [el]);
|
99
|
+
}
|
100
|
+
else {
|
101
|
+
overlay.el.parentNode.removeChild(overlay.el);
|
102
|
+
overlay.el = null;
|
103
|
+
}
|
104
|
+
};
|
105
|
+
|
106
|
+
this.overlays.push(overlay);
|
107
|
+
return overlay;
|
108
|
+
};
|
109
|
+
|
110
|
+
GMaps.prototype.removeOverlay = function(overlay) {
|
111
|
+
for (var i = 0; i < this.overlays.length; i++) {
|
112
|
+
if (this.overlays[i] === overlay) {
|
113
|
+
this.overlays[i].setMap(null);
|
114
|
+
this.overlays.splice(i, 1);
|
115
|
+
|
116
|
+
break;
|
117
|
+
}
|
118
|
+
}
|
119
|
+
};
|
120
|
+
|
121
|
+
GMaps.prototype.removeOverlays = function() {
|
122
|
+
for (var i = 0, item; item = this.overlays[i]; i++) {
|
123
|
+
item.setMap(null);
|
124
|
+
}
|
125
|
+
|
126
|
+
this.overlays = [];
|
127
|
+
};
|