vendor/assets/javascripts/map.js in active_frontend-9.1.1 vs vendor/assets/javascripts/map.js in active_frontend-10.0.0
- old
+ new
@@ -2,14 +2,16 @@
(function(root, factory) {
if(typeof exports === 'object') {
module.exports = factory();
}
else if(typeof define === 'function' && define.amd) {
- define('GMaps', [], factory);
+ define(['jquery', 'googlemaps!'], factory);
}
+ else {
+ root.GMaps = factory();
+ }
- root.GMaps = factory();
}(this, function() {
if (!(typeof window.google === 'object' && window.google.maps)) {
throw 'Google Maps API is required. Please register the following JavaScript library http://maps.google.com/maps/api/js?sensor=true.'
@@ -161,10 +163,14 @@
if (!this) return new GMaps(options);
options.zoom = options.zoom || 15;
options.mapType = options.mapType || 'roadmap';
+ var valueOrDefault = function(value, defaultValue) {
+ return value === undefined ? defaultValue : value;
+ };
+
var self = this,
i,
events_that_hide_context_menu = [
'bounds_changed', 'center_changed', 'click', 'dblclick', 'drag',
'dragend', 'dragstart', 'idle', 'maptypeid_changed', 'projection_changed',
@@ -174,22 +180,22 @@
options_to_be_deleted = ['el', 'lat', 'lng', 'mapType', 'width', 'height', 'markerClusterer', 'enableNewStyle'],
identifier = options.el || options.div,
markerClustererFunction = options.markerClusterer,
mapType = google.maps.MapTypeId[options.mapType.toUpperCase()],
map_center = new google.maps.LatLng(options.lat, options.lng),
- zoomControl = options.zoomControl || true,
+ zoomControl = valueOrDefault(options.zoomControl, true),
zoomControlOpt = options.zoomControlOpt || {
style: 'DEFAULT',
position: 'TOP_LEFT'
},
zoomControlStyle = zoomControlOpt.style || 'DEFAULT',
zoomControlPosition = zoomControlOpt.position || 'TOP_LEFT',
- panControl = options.panControl || true,
- mapTypeControl = options.mapTypeControl || true,
- scaleControl = options.scaleControl || true,
- streetViewControl = options.streetViewControl || true,
- overviewMapControl = overviewMapControl || true,
+ panControl = valueOrDefault(options.panControl, true),
+ mapTypeControl = valueOrDefault(options.mapTypeControl, true),
+ scaleControl = valueOrDefault(options.scaleControl, true),
+ streetViewControl = valueOrDefault(options.streetViewControl, true),
+ overviewMapControl = valueOrDefault(overviewMapControl, true),
map_options = {},
map_base_options = {
zoom: this.zoom,
center: map_center,
mapTypeId: mapType
@@ -309,11 +315,11 @@
top = position[1] + e.pixel.y- 15;
context_menu_element.style.left = left + "px";
context_menu_element.style.top = top + "px";
- context_menu_element.style.display = 'block';
+ // context_menu_element.style.display = 'block';
};
this.buildContextMenu = function(control, e) {
if (control === 'marker') {
e.pixel = {};
@@ -331,10 +337,16 @@
};
}
else {
buildContextMenuHTML(control, e);
}
+
+ var context_menu_element = getElementById('gmaps_context_menu');
+
+ setTimeout(function() {
+ context_menu_element.style.display = 'block';
+ }, 0);
};
this.setContextMenu = function(options) {
window.context_menu[self.el.id][options.control] = {};
@@ -359,13 +371,15 @@
ul.style.background = 'white';
ul.style.listStyle = 'none';
ul.style.padding = '8px';
ul.style.boxShadow = '2px 2px 6px #ccc';
- doc.body.appendChild(ul);
+ if (!getElementById('gmaps_context_menu')) {
+ doc.body.appendChild(ul);
+ }
- var context_menu_element = getElementById('gmaps_context_menu')
+ var context_menu_element = getElementById('gmaps_context_menu');
google.maps.event.addDomListener(context_menu_element, 'mouseout', function(ev) {
if (!ev.relatedTarget || !this.contains(ev.relatedTarget)) {
window.setTimeout(function(){
context_menu_element.style.display = 'none';
@@ -515,9 +529,13 @@
control.style[option] = options.style[option];
}
if (options.id) {
control.id = options.id;
+ }
+
+ if (options.title) {
+ control.title = options.title;
}
if (options.classes) {
control.className = options.classes;
}
\ No newline at end of file