app/assets/javascripts/gmapsjs/gmapsjs.js in gmapsjs-0.4.12 vs app/assets/javascripts/gmapsjs/gmapsjs.js in gmapsjs-0.4.16
- old
+ new
@@ -9,11 +9,11 @@
root.GMaps = factory();
}(this, function() {
/*!
- * GMaps.js v0.4.12
+ * GMaps.js v0.4.16
* http://hpneo.github.com/gmaps/
*
* Copyright 2014, Gustavo Leon
* Released under the MIT License.
*/
@@ -102,16 +102,18 @@
var arrayToLatLng = function(coords, useGeoJSON) {
var i;
for (i = 0; i < coords.length; i++) {
- if (coords[i].length > 0 && typeof(coords[i][0]) == "object") {
- coords[i] = arrayToLatLng(coords[i], useGeoJSON);
+ if (!(coords[i] instanceof google.maps.LatLng)) {
+ if (coords[i].length > 0 && typeof(coords[i][0]) == "object") {
+ coords[i] = arrayToLatLng(coords[i], useGeoJSON);
+ }
+ else {
+ coords[i] = coordsToLatLngs(coords[i], useGeoJSON);
+ }
}
- else {
- coords[i] = coordsToLatLngs(coords[i], useGeoJSON);
- }
}
return coords;
};
@@ -372,10 +374,13 @@
self.hideContextMenu();
});
};
+ //google.maps.event.addListener(this.map, 'idle', this.hideContextMenu);
+ google.maps.event.addListener(this.map, 'zoom_changed', this.hideContextMenu);
+
for (var ev = 0; ev < events_that_hide_context_menu.length; ev++) {
var name = events_that_hide_context_menu[ev];
if (name in options) {
setupListener(this.map, name);
@@ -498,13 +503,22 @@
if (options.classes) {
control.className = options.classes;
}
if (options.content) {
- control.innerHTML = options.content;
+ if (typeof options.content === 'string') {
+ control.innerHTML = options.content;
+ }
+ else if (options.content instanceof HTMLElement) {
+ control.appendChild(options.content);
+ }
}
+ if (options.position) {
+ control.position = google.maps.ControlPosition[options.position.toUpperCase()];
+ }
+
for (var ev in options.events) {
(function(object, name) {
google.maps.event.addDomListener(object, name, function(){
options.events[name].apply(this, [this]);
});
@@ -515,22 +529,40 @@
return control;
};
GMaps.prototype.addControl = function(options) {
- var position = google.maps.ControlPosition[options.position.toUpperCase()];
-
- delete options.position;
-
var control = this.createControl(options);
this.controls.push(control);
-
- this.map.controls[position].push(control);
+ this.map.controls[control.position].push(control);
return control;
};
+GMaps.prototype.removeControl = function(control) {
+ var position = null;
+
+ for (var i = 0; i < this.controls.length; i++) {
+ if (this.controls[i] == control) {
+ position = this.controls[i].position;
+ this.controls.splice(i, 1);
+ }
+ }
+
+ if (position) {
+ for (i = 0; i < this.map.controls.length; i++) {
+ var controlsForPosition = this.map.controls[control.position]
+ if (controlsForPosition.getAt(i) == control) {
+ controlsForPosition.removeAt(i);
+ break;
+ }
+ }
+ }
+
+ return control;
+};
+
GMaps.prototype.createMarker = function(options) {
if (options.lat == undefined && options.lng == undefined && options.position == undefined) {
throw 'No latitude or longitude defined.';
}
@@ -699,25 +731,42 @@
GMaps.prototype.removeMarkers = function (collection) {
var new_markers = [];
if (typeof collection == 'undefined') {
for (var i = 0; i < this.markers.length; i++) {
- this.markers[i].setMap(null);
+ var marker = this.markers[i];
+ marker.setMap(null);
+
+ if(this.markerClusterer) {
+ this.markerClusterer.removeMarker(marker);
+ }
+
+ GMaps.fire('marker_removed', marker, this);
}
this.markers = new_markers;
}
else {
for (var i = 0; i < collection.length; i++) {
- if (this.markers.indexOf(collection[i]) > -1) {
- this.markers[i].setMap(null);
+ var index = this.markers.indexOf(collection[i]);
+
+ if (index > -1) {
+ var marker = this.markers[index];
+ marker.setMap(null);
+
+ if(this.markerClusterer) {
+ this.markerClusterer.removeMarker(marker);
+ }
+
+ GMaps.fire('marker_removed', marker, this);
}
}
for (var i = 0; i < this.markers.length; i++) {
- if (this.markers[i].getMap() != null) {
- new_markers.push(this.markers[i]);
+ var marker = this.markers[i];
+ if (marker.getMap() != null) {
+ new_markers.push(marker);
}
}
this.markers = new_markers;
}
@@ -767,10 +816,11 @@
});
})(el, stop_overlay_events[ev]);
}
if (options.click) {
+ panes.overlayMouseTarget.appendChild(overlay.el);
google.maps.event.addDomListener(overlay.el, 'click', function() {
options.click.apply(overlay, [overlay]);
});
}
@@ -1367,10 +1417,11 @@
this.getRoutes({
origin: options.origin,
destination: options.destination,
travelMode: options.travelMode,
waypoints : options.waypoints,
+ unitSystem: options.unitSystem,
error: options.error,
callback: function(e) {
//start callback
if (e.length > 0 && options.start) {
options.start(e[e.length - 1]);
@@ -1700,16 +1751,16 @@
/** Map Styles **/
if (styles) {
for (var i = 0; i < styles.length; i++) {
var styleRule = [];
- if (styles[i].featureType && styles[i].featureType != 'all' ) {
- styleRule.push('feature:' + styles[i].featureType);
+ if (styles[i].featureType){
+ styleRule.push('feature:' + styles[i].featureType.toLowerCase());
}
- if (styles[i].elementType && styles[i].elementType != 'all') {
- styleRule.push('element:' + styles[i].elementType);
+ if (styles[i].elementType) {
+ styleRule.push('element:' + styles[i].elementType.toLowerCase());
}
for (var j = 0; j < styles[i].stylers.length; j++) {
for (var p in styles[i].stylers[j]) {
var ruleArg = styles[i].stylers[j][p];
@@ -1884,10 +1935,11 @@
GMaps.custom_events = ['marker_added', 'marker_removed', 'polyline_added', 'polyline_removed', 'polygon_added', 'polygon_removed', 'geolocated', 'geolocation_failed'];
GMaps.on = function(event_name, object, handler) {
if (GMaps.custom_events.indexOf(event_name) == -1) {
+ if(object instanceof GMaps) object = object.map;
return google.maps.event.addListener(object, event_name, handler);
}
else {
var registered_event = {
handler : handler,
@@ -1901,10 +1953,11 @@
}
};
GMaps.off = function(event_name, object) {
if (GMaps.custom_events.indexOf(event_name) == -1) {
+ if(object instanceof GMaps) object = object.map;
google.maps.event.clearListeners(object, event_name);
}
else {
object.registered_events[event_name] = [];
}
@@ -2027,10 +2080,21 @@
return inPoly;
};
}
+if (!google.maps.Circle.prototype.containsLatLng) {
+ google.maps.Circle.prototype.containsLatLng = function(latLng) {
+ if (google.maps.geometry) {
+ return google.maps.geometry.spherical.computeDistanceBetween(this.getCenter(), latLng) <= this.getRadius();
+ }
+ else {
+ return true;
+ }
+ };
+}
+
google.maps.LatLngBounds.prototype.containsLatLng = function(latLng) {
return this.contains(latLng);
};
google.maps.Marker.prototype.setFences = function(fences) {
@@ -2080,6 +2144,6 @@
return -1;
}
}
return GMaps;
-}));
+}));
\ No newline at end of file