vendor/assets/javascripts/map.js in quantum-0.0.7 vs vendor/assets/javascripts/map.js in quantum-0.0.8

- old
+ new

@@ -1,7 +1,7 @@ /*! - * GMaps.js v0.4.5 + * GMaps.js v0.4.6 * http://hpneo.github.com/gmaps/ * * Copyright 2013, Gustavo Leon * Released under the MIT License. */ @@ -134,10 +134,12 @@ "use strict"; var doc = document; var GMaps = function(options) { + if (!this) return new GMaps(options); + options.zoom = options.zoom || 15; options.mapType = options.mapType || 'roadmap'; var self = this, i, @@ -247,11 +249,11 @@ } if (!getElementById('gmaps_context_menu')) return; var context_menu_element = getElementById('gmaps_context_menu'); - + context_menu_element.innerHTML = html; var context_menu_items = context_menu_element.getElementsByTagName('a'), context_menu_items_count = context_menu_items.length i; @@ -284,15 +286,15 @@ if (control === 'marker') { e.pixel = {}; var overlay = new google.maps.OverlayView(); overlay.setMap(self.map); - + overlay.draw = function() { var projection = overlay.getProjection(), position = e.marker.getPosition(); - + e.pixel = projection.fromLatLngToContainerPixel(position); buildContextMenuHTML(control, e); }; } @@ -502,11 +504,11 @@ delete options.position; var control = this.createControl(options); this.controls.push(control); - + this.map.controls[position].push(control); return control; }; @@ -569,11 +571,11 @@ if (options[name]) { google.maps.event.addListener(object, name, function(me){ if(!me.pixel){ me.pixel = map.getProjection().fromLatLngToPoint(me.latLng) } - + options[name].apply(this, [me]); }); } })(this.map, marker, marker_events_with_mouse[ev]); } @@ -715,11 +717,11 @@ overlay.el = el; if (!options.layer) { options.layer = 'overlayLayer'; } - + var panes = this.getPanes(), overlayLayer = panes[options.layer], stop_overlay_events = ['contextmenu', 'DOMMouseScroll', 'dblclick', 'mousedown']; overlayLayer.appendChild(el); @@ -1304,11 +1306,11 @@ path: e[e.length - 1].overview_path, strokeColor: options.strokeColor, strokeOpacity: options.strokeOpacity, strokeWeight: options.strokeWeight }); - + if (options.callback) { options.callback(e[e.length - 1]); } } } @@ -1358,11 +1360,11 @@ } }; GMaps.prototype.drawSteppedRoute = function(options) { var self = this; - + if (options.origin && options.destination) { this.getRoutes({ origin: options.origin, destination: options.destination, travelMode: options.travelMode, @@ -1501,22 +1503,22 @@ static_map_options['lat'] = this.getCenter().lat(); static_map_options['lng'] = this.getCenter().lng(); if (this.markers.length > 0) { static_map_options['markers'] = []; - + for (var i = 0; i < this.markers.length; i++) { static_map_options['markers'].push({ lat: this.markers[i].getPosition().lat(), lng: this.markers[i].getPosition().lng() }); } } if (this.polylines.length > 0) { var polyline = this.polylines[0]; - + static_map_options['polyline'] = {}; static_map_options['polyline']['path'] = google.maps.geometry.encoding.encodePath(polyline.getPath()); static_map_options['polyline']['strokeColor'] = polyline.strokeColor static_map_options['polyline']['strokeOpacity'] = polyline.strokeOpacity static_map_options['polyline']['strokeWeight'] = polyline.strokeWeight @@ -1536,18 +1538,22 @@ } static_root += '?'; var markers = options.markers; - + delete options.markers; if (!markers && options.marker) { markers = [options.marker]; delete options.marker; } + var styles = options.styles; + + delete options.styles; + var polyline = options.polyline; delete options.polyline; /** Map options **/ if (options.center) { @@ -1578,11 +1584,11 @@ else { size = '630x300'; } parameters.push('size=' + size); - if (!options.zoom) { + if (!options.zoom && options.zoom !== false) { options.zoom = 15; } var sensor = options.hasOwnProperty('sensor') ? !!options.sensor : true; delete options.sensor; @@ -1601,25 +1607,38 @@ for (var i=0; data=markers[i]; i++) { marker = []; if (data.size && data.size !== 'normal') { marker.push('size:' + data.size); + delete data.size; } else if (data.icon) { marker.push('icon:' + encodeURI(data.icon)); + delete data.icon; } if (data.color) { marker.push('color:' + data.color.replace('#', '0x')); + delete data.color; } if (data.label) { marker.push('label:' + data.label[0].toUpperCase()); + delete data.label; } loc = (data.address ? data.address : data.lat + ',' + data.lng); + delete data.address; + delete data.lat; + delete data.lng; + for(var param in data){ + if (data.hasOwnProperty(param)) { + marker.push(param + ':' + data[param]); + } + } + if (marker.length || i === 0) { marker.push(loc); marker = marker.join('|'); parameters.push('markers=' + encodeURI(marker)); } @@ -1629,10 +1648,39 @@ parameters.push(marker); } } } + /** 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].elementType && styles[i].elementType != 'all') { + styleRule.push('element:' + styles[i].elementType); + } + + 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]; + if (p == 'hue' || p == 'color') { + ruleArg = '0x' + ruleArg.substring(1); + } + styleRule.push(p + ':' + ruleArg); + } + } + + var rule = styleRule.join('|'); + if (rule != '') { + parameters.push('style=' + rule); + } + } + } + /** Polylines **/ function parseColor(color, opacity) { if (color[0] === '#'){ color = color.replace('#', '0x'); @@ -1718,11 +1766,11 @@ GMaps.prototype.removeOverlayMapType = function(overlayMapTypeIndex) { this.map.overlayMapTypes.removeAt(overlayMapTypeIndex); }; GMaps.prototype.addStyle = function(options) { - var styledMapType = new google.maps.StyledMapType(options.styles, options.styledMapName); + var styledMapType = new google.maps.StyledMapType(options.styles, { name: options.styledMapName }); this.map.mapTypes.set(options.mapTypeId, styledMapType); }; GMaps.prototype.setStyle = function(mapTypeId) { @@ -1862,10 +1910,10 @@ } delete options.lat; delete options.lng; delete options.callback; - + this.geocoder.geocode(options, function(results, status) { callback(results, status); }); }; \ No newline at end of file