diff --git a/ajax/libs/gmaps.js/0.2.27/gmaps.js b/ajax/libs/gmaps.js/0.2.27/gmaps.js new file mode 100644 index 000000000..e0230de59 --- /dev/null +++ b/ajax/libs/gmaps.js/0.2.27/gmaps.js @@ -0,0 +1,1698 @@ +/*! + * GMaps.js v0.2.27 + * http://hpneo.github.com/gmaps/ + * + * Copyright 2012, Gustavo Leon + * Released under the MIT License. + */ + +if(window.google && window.google.maps){ + + var GMaps = (function(global) { + "use strict"; + + var doc = document; + var getElementById = function(id, context) { + var ele + if('jQuery' in global && context){ + ele = $("#"+id.replace('#', ''), context)[0] + }else{ + ele = doc.getElementById(id.replace('#', '')); + }; + return ele; + }; + + var GMaps = function(options) { + var self = this; + window.context_menu = {}; + + if (typeof(options.el) === 'string' || typeof(options.div) === 'string') { + this.el = getElementById(options.el || options.div, options.context); + } else { + this.el = options.el || options.div; + }; + this.el.style.width = options.width || this.el.scrollWidth || this.el.offsetWidth; + this.el.style.height = options.height || this.el.scrollHeight || this.el.offsetHeight; + + this.controls = []; + this.overlays = []; + this.layers = []; // array with kml and ft layers, can be as many + this.singleLayers = {}; // object with the other layers, only one per layer + this.markers = []; + this.polylines = []; + this.routes = []; + this.polygons = []; + this.infoWindow = null; + this.overlay_el = null; + this.zoom = options.zoom || 15; + + var markerClusterer = options.markerClusterer; + + //'Hybrid', 'Roadmap', 'Satellite' or 'Terrain' + var mapType; + + if (options.mapType) { + mapType = google.maps.MapTypeId[options.mapType.toUpperCase()]; + } + else { + mapType = google.maps.MapTypeId.ROADMAP; + } + + var map_center = new google.maps.LatLng(options.lat, options.lng); + + delete options.el; + delete options.lat; + delete options.lng; + delete options.mapType; + delete options.width; + delete options.height; + delete options.markerClusterer; + + var zoomControlOpt = options.zoomControlOpt || { + style: 'DEFAULT', + position: 'TOP_LEFT' + }; + + var zoomControl = options.zoomControl || true, + 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; + + var map_options = {}; + + var map_base_options = { + zoom: this.zoom, + center: map_center, + mapTypeId: mapType + }; + + var map_controls_options = { + panControl: panControl, + zoomControl: zoomControl, + zoomControlOptions: { + style: google.maps.ZoomControlStyle[zoomControlStyle], // DEFAULT LARGE SMALL + position: google.maps.ControlPosition[zoomControlPosition] + }, + mapTypeControl: mapTypeControl, + scaleControl: scaleControl, + streetViewControl: streetViewControl, + overviewMapControl: overviewMapControl + } + + if(options.disableDefaultUI != true) + map_base_options = extend_object(map_base_options, map_controls_options); + + map_options = extend_object(map_base_options, options); + + this.map = new google.maps.Map(this.el, map_options); + + if(markerClusterer) + this.markerClusterer = markerClusterer.apply(this, [this.map]); + + // Context menus + var buildContextMenuHTML = function(control, e) { + var html = ''; + var options = window.context_menu[control]; + for (var i in options){ + if (options.hasOwnProperty(i)){ + var option = options[i]; + html += '
  • ' + + option.title + '
  • '; + } + } + + 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'); + + var context_menu_items_count = context_menu_items.length; + + for(var i = 0; i < context_menu_items_count; i++){ + var context_menu_item = context_menu_items[i]; + + var assign_menu_item_action = function(ev){ + ev.preventDefault(); + + options[this.id.replace(control + '_', '')].action.apply(self, [e]); + self.hideContextMenu(); + }; + + google.maps.event.clearListeners(context_menu_item, 'click'); + google.maps.event.addDomListenerOnce(context_menu_item, 'click', assign_menu_item_action, false); + } + + var left = self.el.offsetLeft + e.pixel.x - 15; + var top = self.el.offsetTop + e.pixel.y - 15; + + context_menu_element.style.left = left + "px"; + context_menu_element.style.top = top + "px"; + + context_menu_element.style.display = 'block'; + }; + + var buildContextMenu = function(control, e) { + if (control === 'marker') { + e.pixel = {}; + var overlay = new google.maps.OverlayView(); + overlay.setMap(self.map); + overlay.draw = function() { + var projection = overlay.getProjection(); + var position = e.marker.getPosition(); + e.pixel = projection.fromLatLngToContainerPixel(position); + + buildContextMenuHTML(control, e); + }; + } + else { + buildContextMenuHTML(control, e); + } + }; + + this.setContextMenu = function(options) { + window.context_menu[options.control] = {}; + for (var i in options.options){ + if (options.options.hasOwnProperty(i)){ + var option = options.options[i]; + window.context_menu[options.control][option.name] = { + title: option.title, + action: option.action + }; + } + } + var ul = doc.createElement('ul'); + ul.id = 'gmaps_context_menu'; + ul.style.display = 'none'; + ul.style.position = 'absolute'; + ul.style.minWidth = '100px'; + ul.style.background = 'white'; + ul.style.listStyle = 'none'; + ul.style.padding = '8px'; + ul.style.boxShadow = '2px 2px 6px #ccc'; + + doc.body.appendChild(ul); + + 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'; + }, 400); + } + }, false); + }; + + this.hideContextMenu = function() { + var context_menu_element = getElementById('gmaps_context_menu'); + if(context_menu_element) + context_menu_element.style.display = 'none'; + }; + + //Events + + var events_that_hide_context_menu = ['bounds_changed', 'center_changed', 'click', 'dblclick', 'drag', 'dragend', 'dragstart', 'idle', 'maptypeid_changed', 'projection_changed', 'resize', 'tilesloaded', 'zoom_changed']; + var events_that_doesnt_hide_context_menu = ['mousemove', 'mouseout', 'mouseover']; + + for (var ev = 0; ev < events_that_hide_context_menu.length; ev++) { + (function(object, name) { + google.maps.event.addListener(object, name, function(e){ + if(e == undefined) + e = this; + + if (options[name]) + options[name].apply(this, [e]); + + self.hideContextMenu(); + }); + })(this.map, events_that_hide_context_menu[ev]); + } + + for (var ev = 0; ev < events_that_doesnt_hide_context_menu.length; ev++) { + (function(object, name) { + google.maps.event.addListener(object, name, function(e){ + if(e == undefined) + e = this; + + if (options[name]) + options[name].apply(this, [e]); + }); + })(this.map, events_that_doesnt_hide_context_menu[ev]); + } + + google.maps.event.addListener(this.map, 'rightclick', function(e) { + if (options.rightclick) { + options.rightclick.apply(this, [e]); + } + + if(window.context_menu['map'] != undefined) { + buildContextMenu('map', e); + } + }); + + this.refresh = function() { + google.maps.event.trigger(this.map, 'resize'); + }; + + this.fitZoom = function() { + var latLngs = []; + var markers_length = this.markers.length; + + for(var i=0; i < markers_length; i++) { + latLngs.push(this.markers[i].getPosition()); + } + + this.fitLatLngBounds(latLngs); + }; + + this.fitLatLngBounds = function(latLngs) { + var total = latLngs.length; + var bounds = new google.maps.LatLngBounds(); + + for(var i=0; i < total; i++) { + bounds.extend(latLngs[i]); + } + + this.map.fitBounds(bounds); + }; + + // Map methods + this.setCenter = function(lat, lng, callback) { + this.map.panTo(new google.maps.LatLng(lat, lng)); + if (callback) { + callback(); + } + }; + + this.getElement = function() { + return this.el; + }; + + this.zoomIn = function(value) { + this.zoom = this.map.getZoom() + value; + this.map.setZoom(this.zoom); + }; + + this.zoomOut = function(value) { + this.zoom = this.map.getZoom() - value; + this.map.setZoom(this.zoom); + }; + + var native_methods = []; + + for(var method in this.map){ + if(typeof(this.map[method]) == 'function' && !this[method]){ + native_methods.push(method); + } + } + + for(var i=0; i < native_methods.length; i++){ + (function(gmaps, scope, method_name) { + gmaps[method_name] = function(){ + return scope[method_name].apply(scope, arguments); + }; + })(this, this.map, native_methods[i]); + } + + this.createControl = function(options) { + var control = doc.createElement('div'); + + control.style.cursor = 'pointer'; + control.style.fontFamily = 'Arial, sans-serif'; + control.style.fontSize = '13px'; + control.style.boxShadow = 'rgba(0, 0, 0, 0.398438) 0px 2px 4px'; + + for(var option in options.style) + control.style[option] = options.style[option]; + + if(options.id) { + control.id = options.id; + } + + if(options.classes) { + control.className = options.classes; + } + + if(options.content) { + control.innerHTML = options.content; + } + + for (var ev in options.events) { + (function(object, name) { + google.maps.event.addDomListener(object, name, function(){ + options.events[name].apply(this, [this]); + }); + })(control, ev); + } + + control.index = 1; + + return control; + }; + + this.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); + + return control; + }; + + // Markers + this.createMarker = function(options) { + if ((options.hasOwnProperty('lat') && options.hasOwnProperty('lng')) || options.position) { + var self = this; + var details = options.details; + var fences = options.fences; + var outside = options.outside; + + var base_options = { + position: new google.maps.LatLng(options.lat, options.lng), + map: null + }; + + delete options.lat; + delete options.lng; + delete options.fences; + delete options.outside; + + var marker_options = extend_object(base_options, options); + + var marker = new google.maps.Marker(marker_options); + + marker.fences = fences; + + if (options.infoWindow) { + marker.infoWindow = new google.maps.InfoWindow(options.infoWindow); + + var info_window_events = ['closeclick', 'content_changed', 'domready', 'position_changed', 'zindex_changed']; + + for (var ev = 0; ev < info_window_events.length; ev++) { + (function(object, name) { + google.maps.event.addListener(object, name, function(e){ + if (options.infoWindow[name]) + options.infoWindow[name].apply(this, [e]); + }); + })(marker.infoWindow, info_window_events[ev]); + } + } + + 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']; + + var marker_events_with_mouse = ['dblclick', 'drag', 'dragend', 'dragstart', 'mousedown', 'mouseout', 'mouseover', 'mouseup']; + + for (var ev = 0; ev < marker_events.length; ev++) { + (function(object, name) { + google.maps.event.addListener(object, name, function(){ + if (options[name]) + options[name].apply(this, [this]); + }); + })(marker, marker_events[ev]); + } + + for (var ev = 0; ev < marker_events_with_mouse.length; ev++) { + (function(map, object, name) { + google.maps.event.addListener(object, name, function(me){ + if(!me.pixel){ + me.pixel = map.getProjection().fromLatLngToPoint(me.latLng) + } + if (options[name]) + options[name].apply(this, [me]); + }); + })(this.map, marker, marker_events_with_mouse[ev]); + } + + google.maps.event.addListener(marker, 'click', function() { + this.details = details; + + if (options.click) { + options.click.apply(this, [this]); + } + + if (marker.infoWindow) { + self.hideInfoWindows(); + marker.infoWindow.open(self.map, marker); + } + }); + + google.maps.event.addListener(marker, 'rightclick', function(e) { + e.marker = this; + + if (options.rightclick) { + options.rightclick.apply(this, [e]); + } + + if (window.context_menu['marker'] != undefined) { + buildContextMenu('marker', e); + } + }); + + if (options.dragend || marker.fences) { + google.maps.event.addListener(marker, 'dragend', function() { + if (marker.fences) { + self.checkMarkerGeofence(marker, function(m, f) { + outside(m, f); + }); + } + }); + } + + return marker; + } + else { + throw 'No latitude or longitude defined'; + } + }; + + this.addMarker = function(options) { + var marker; + if(options.hasOwnProperty('gm_accessors_')) { + // Native google.maps.Marker object + marker = options; + } + else { + if ((options.hasOwnProperty('lat') && options.hasOwnProperty('lng')) || options.position) { + marker = this.createMarker(options); + } + else { + throw 'No latitude or longitude defined'; + } + } + + marker.setMap(this.map); + + if(this.markerClusterer) + this.markerClusterer.addMarker(marker); + + this.markers.push(marker); + + return marker; + }; + + this.addMarkers = function(array) { + for (var i=0, marker; marker=array[i]; i++) { + this.addMarker(marker); + } + return this.markers; + }; + + this.hideInfoWindows = function() { + for (var i=0, marker; marker=this.markers[i]; i++){ + if (marker.infoWindow){ + marker.infoWindow.close(); + } + } + }; + + this.removeMarker = function(marker) { + for(var i=0; i < this.markers.length; i++) { + if(this.markers[i] === marker) { + this.markers[i].setMap(null); + this.markers.splice(i, 1); + break; + } + } + + return marker; + }; + + this.removeMarkers = function(collection) { + var collection = (collection || this.markers); + + for(var i=0;i < this.markers.length; i++){ + if(this.markers[i] === collection[i]) + this.markers[i].setMap(null); + } + + var new_markers = []; + + for(var i=0;i < this.markers.length; i++){ + if(this.markers[i].getMap() != null) + new_markers.push(this.markers[i]); + } + + this.markers = new_markers; + }; + + // Overlays + this.drawOverlay = function(options) { + var overlay = new google.maps.OverlayView(); + overlay.setMap(self.map); + + var auto_show = true; + + if(options.auto_show != null) + auto_show = options.auto_show; + + overlay.onAdd = function() { + var el = doc.createElement('div'); + el.style.borderStyle = "none"; + el.style.borderWidth = "0px"; + el.style.position = "absolute"; + el.style.zIndex = 100; + el.innerHTML = options.content; + + overlay.el = el; + + var panes = this.getPanes(); + if (!options.layer) { + options.layer = 'overlayLayer'; + } + var overlayLayer = panes[options.layer]; + overlayLayer.appendChild(el); + + var stop_overlay_events = ['contextmenu', 'DOMMouseScroll', 'dblclick', 'mousedown']; + + for (var ev = 0; ev < stop_overlay_events.length; ev++) { + (function(object, name) { + google.maps.event.addDomListener(object, name, function(e){ + if(navigator.userAgent.toLowerCase().indexOf('msie') != -1 && document.all) { + e.cancelBubble = true; + e.returnValue = false; + } + else { + e.stopPropagation(); + } + }); + })(el, stop_overlay_events[ev]); + } + + google.maps.event.trigger(this, 'ready'); + }; + + overlay.draw = function() { + var projection = this.getProjection(); + var pixel = projection.fromLatLngToDivPixel(new google.maps.LatLng(options.lat, options.lng)); + + options.horizontalOffset = options.horizontalOffset || 0; + options.verticalOffset = options.verticalOffset || 0; + + var el = overlay.el; + var content = el.children[0]; + + var content_height = content.clientHeight; + var content_width = content.clientWidth; + + switch (options.verticalAlign) { + case 'top': + el.style.top = (pixel.y - content_height + options.verticalOffset) + 'px'; + break; + default: + case 'middle': + el.style.top = (pixel.y - (content_height / 2) + options.verticalOffset) + 'px'; + break; + case 'bottom': + el.style.top = (pixel.y + options.verticalOffset) + 'px'; + break; + } + + switch (options.horizontalAlign) { + case 'left': + el.style.left = (pixel.x - content_width + options.horizontalOffset) + 'px'; + break; + default: + case 'center': + el.style.left = (pixel.x - (content_width / 2) + options.horizontalOffset) + 'px'; + break; + case 'right': + el.style.left = (pixel.x + options.horizontalOffset) + 'px'; + break; + } + + el.style.display = auto_show ? 'block' : 'none'; + + if(!auto_show){ + options.show.apply(this, [el]); + } + }; + + overlay.onRemove = function() { + var el = overlay.el; + + if(options.remove){ + options.remove.apply(this, [el]); + } + else{ + overlay.el.parentNode.removeChild(overlay.el); + overlay.el = null; + } + }; + + self.overlays.push(overlay); + return overlay; + }; + + this.removeOverlay = function(overlay) { + overlay.setMap(null); + }; + + this.removeOverlays = function() { + for (var i=0, item; item=self.overlays[i]; i++){ + item.setMap(null); + } + self.overlays = []; + }; + + this.removePolylines = function() { + for (var i=0, item; item=self.polylines[i]; i++){ + item.setMap(null); + } + self.polylines = []; + }; + + this.drawPolyline = function(options) { + var path = []; + var points = options.path; + + if (points.length){ + if (points[0][0] === undefined){ + path = points; + } + else { + for (var i=0, latlng; latlng=points[i]; i++){ + path.push(new google.maps.LatLng(latlng[0], latlng[1])); + } + } + } + + var polyline_options = { + map: this.map, + path: path, + strokeColor: options.strokeColor, + strokeOpacity: options.strokeOpacity, + strokeWeight: options.strokeWeight, + geodesic: options.geodesic, + clickable: true, + editable: false, + visible: true + }; + + if(options.hasOwnProperty("clickable")) + polyline_options.clickable = options.clickable; + + if(options.hasOwnProperty("editable")) + polyline_options.editable = options.editable; + + if(options.hasOwnProperty("icons")) + polyline_options.icons = options.icons; + + if(options.hasOwnProperty("zIndex")) + polyline_options.zIndex = options.zIndex; + + var polyline = new google.maps.Polyline(polyline_options); + + var polyline_events = ['click', 'dblclick', 'mousedown', 'mousemove', 'mouseout', 'mouseover', 'mouseup', 'rightclick']; + + for (var ev = 0; ev < polyline_events.length; ev++) { + (function(object, name) { + google.maps.event.addListener(object, name, function(e){ + if (options[name]) + options[name].apply(this, [e]); + }); + })(polyline, polyline_events[ev]); + } + + this.polylines.push(polyline); + + return polyline; + }; + + this.drawCircle = function(options) { + options = extend_object({ + map: this.map, + center: new google.maps.LatLng(options.lat, options.lng) + }, options); + + delete options.lat; + delete options.lng; + var polygon = new google.maps.Circle(options); + + var polygon_events = ['click', 'dblclick', 'mousedown', 'mousemove', 'mouseout', 'mouseover', 'mouseup', 'rightclick']; + + for (var ev = 0; ev < polygon_events.length; ev++) { + (function(object, name) { + google.maps.event.addListener(object, name, function(e){ + if (options[name]) + options[name].apply(this, [e]); + }); + })(polygon, polygon_events[ev]); + } + + this.polygons.push(polygon); + + return polygon; + }; + + this.drawRectangle = function(options) { + options = extend_object({ + map: this.map + }, options); + + var latLngBounds = new google.maps.LatLngBounds( + new google.maps.LatLng(options.bounds[0][0], options.bounds[0][1]), + new google.maps.LatLng(options.bounds[1][0], options.bounds[1][1]) + ); + + options.bounds = latLngBounds; + + var polygon = new google.maps.Rectangle(options); + + var polygon_events = ['click', 'dblclick', 'mousedown', 'mousemove', 'mouseout', 'mouseover', 'mouseup', 'rightclick']; + + for (var ev = 0; ev < polygon_events.length; ev++) { + (function(object, name) { + google.maps.event.addListener(object, name, function(e){ + if (options[name]) + options[name].apply(this, [e]); + }); + })(polygon, polygon_events[ev]); + } + + this.polygons.push(polygon); + + return polygon; + }; + + this.drawPolygon = function(options) { + var useGeoJSON = false; + if(options.hasOwnProperty("useGeoJSON")) + useGeoJSON = options.useGeoJSON; + + delete options.useGeoJSON; + + options = extend_object({ + map: this.map + }, options); + + if(useGeoJSON == false) + options.paths = [options.paths.slice(0)]; + + if(options.paths.length > 0) { + if(options.paths[0].length > 0) { + options.paths = array_flat(array_map(options.paths, arrayToLatLng, useGeoJSON)); + } + } + + var polygon = new google.maps.Polygon(options); + + var polygon_events = ['click', 'dblclick', 'mousedown', 'mousemove', 'mouseout', 'mouseover', 'mouseup', 'rightclick']; + + for (var ev = 0; ev < polygon_events.length; ev++) { + (function(object, name) { + google.maps.event.addListener(object, name, function(e){ + if (options[name]) + options[name].apply(this, [e]); + }); + })(polygon, polygon_events[ev]); + } + + this.polygons.push(polygon); + + return polygon; + }; + + this.removePolygon = this.removeOverlay; + + this.removePolygons = function() { + for (var i=0, item; item=self.polygons[i]; i++){ + item.setMap(null); + } + self.polygons = []; + }; + + this.getFromFusionTables = function(options) { + var events = options.events; + + delete options.events; + + var fusion_tables_options = options; + + var layer = new google.maps.FusionTablesLayer(fusion_tables_options); + + for (var ev in events) { + (function(object, name) { + google.maps.event.addListener(object, name, function(e){ + events[name].apply(this, [e]); + }); + })(layer, ev); + } + + this.layers.push(layer); + + return layer; + }; + + this.loadFromFusionTables = function(options) { + var layer = this.getFromFusionTables(options); + layer.setMap(this.map); + + return layer; + }; + + this.getFromKML = function(options) { + var url = options.url; + var events = options.events; + + delete options.url; + delete options.events; + + var kml_options = options; + + var layer = new google.maps.KmlLayer(url, kml_options); + + for (var ev in events) { + (function(object, name) { + google.maps.event.addListener(object, name, function(e){ + events[name].apply(this, [e]); + }); + })(layer, ev); + } + + this.layers.push(layer); + + return layer; + }; + + this.loadFromKML = function(options) { + var layer = this.getFromKML(options); + layer.setMap(this.map); + + return layer; + }; + + // Services + var travelMode, unitSystem; + this.getRoutes = function(options) { + switch (options.travelMode) { + case 'bicycling': + travelMode = google.maps.TravelMode.BICYCLING; + break; + case 'transit': + travelMode = google.maps.TravelMode.TRANSIT; + break; + case 'driving': + travelMode = google.maps.TravelMode.DRIVING; + break; + // case 'walking': + default: + travelMode = google.maps.TravelMode.WALKING; + break; + } + + if (options.unitSystem === 'imperial') { + unitSystem = google.maps.UnitSystem.IMPERIAL; + } + else { + unitSystem = google.maps.UnitSystem.METRIC; + } + + var base_options = { + avoidHighways: false, + avoidTolls: false, + optimizeWaypoints: false, + waypoints: [] + }; + + var request_options = extend_object(base_options, options); + + request_options.origin = new google.maps.LatLng(options.origin[0], options.origin[1]); + request_options.destination = new google.maps.LatLng(options.destination[0], options.destination[1]); + request_options.travelMode = travelMode; + request_options.unitSystem = unitSystem; + + delete request_options.callback; + + var self = this; + var service = new google.maps.DirectionsService(); + + service.route(request_options, function(result, status) { + if (status === google.maps.DirectionsStatus.OK) { + for (var r in result.routes) { + if (result.routes.hasOwnProperty(r)) { + self.routes.push(result.routes[r]); + } + } + } + if (options.callback) { + options.callback(self.routes); + } + }); + }; + + this.removeRoutes = function() { + this.routes = []; + }; + + this.getElevations = function(options) { + options = extend_object({ + locations: [], + path : false, + samples : 256 + }, options); + + if(options.locations.length > 0) { + if(options.locations[0].length > 0) { + options.locations = array_flat(array_map([options.locations], arrayToLatLng, false)); + } + } + + var callback = options.callback; + delete options.callback; + + var service = new google.maps.ElevationService(); + + //location request + if (!options.path) { + delete options.path; + delete options.samples; + service.getElevationForLocations(options, function(result, status){ + if (callback && typeof(callback) === "function") { + callback(result, status); + } + }); + //path request + } else { + var pathRequest = { + path : options.locations, + samples : options.samples + }; + + service.getElevationAlongPath(pathRequest, function(result, status){ + if (callback && typeof(callback) === "function") { + callback(result, status); + } + }); + } + }; + + // Alias for the method "drawRoute" + this.cleanRoute = this.removePolylines; + + this.drawRoute = function(options) { + var self = this; + this.getRoutes({ + origin: options.origin, + destination: options.destination, + travelMode: options.travelMode, + waypoints: options.waypoints, + unitSystem: options.unitSystem, + callback: function(e) { + if (e.length > 0) { + self.drawPolyline({ + 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]); + } + } + } + }); + }; + + this.travelRoute = function(options) { + if (options.origin && options.destination) { + this.getRoutes({ + origin: options.origin, + destination: options.destination, + travelMode: options.travelMode, + waypoints : options.waypoints, + callback: function(e) { + //start callback + if (e.length > 0 && options.start) { + options.start(e[e.length - 1]); + } + + //step callback + if (e.length > 0 && options.step) { + var route = e[e.length - 1]; + if (route.legs.length > 0) { + var steps = route.legs[0].steps; + for (var i=0, step; step=steps[i]; i++) { + step.step_number = i; + options.step(step, (route.legs[0].steps.length - 1)); + } + } + } + + //end callback + if (e.length > 0 && options.end) { + options.end(e[e.length - 1]); + } + } + }); + } + else if (options.route) { + if (options.route.legs.length > 0) { + var steps = options.route.legs[0].steps; + for (var i=0, step; step=steps[i]; i++) { + step.step_number = i; + options.step(step); + } + } + } + }; + + this.drawSteppedRoute = function(options) { + if (options.origin && options.destination) { + this.getRoutes({ + origin: options.origin, + destination: options.destination, + travelMode: options.travelMode, + waypoints : options.waypoints, + callback: function(e) { + //start callback + if (e.length > 0 && options.start) { + options.start(e[e.length - 1]); + } + + //step callback + if (e.length > 0 && options.step) { + var route = e[e.length - 1]; + if (route.legs.length > 0) { + var steps = route.legs[0].steps; + for (var i=0, step; step=steps[i]; i++) { + step.step_number = i; + self.drawPolyline({ + path: step.path, + strokeColor: options.strokeColor, + strokeOpacity: options.strokeOpacity, + strokeWeight: options.strokeWeight + }); + options.step(step, (route.legs[0].steps.length - 1)); + } + } + } + + //end callback + if (e.length > 0 && options.end) { + options.end(e[e.length - 1]); + } + } + }); + } + else if (options.route) { + if (options.route.legs.length > 0) { + var steps = options.route.legs[0].steps; + for (var i=0, step; step=steps[i]; i++) { + step.step_number = i; + self.drawPolyline({ + path: step.path, + strokeColor: options.strokeColor, + strokeOpacity: options.strokeOpacity, + strokeWeight: options.strokeWeight + }); + options.step(step); + } + } + } + }; + + // Geofence + this.checkGeofence = function(lat, lng, fence) { + return fence.containsLatLng(new google.maps.LatLng(lat, lng)); + }; + + this.checkMarkerGeofence = function(marker, outside_callback) { + if (marker.fences) { + for (var i=0, fence; fence=marker.fences[i]; i++) { + var pos = marker.getPosition(); + if (!self.checkGeofence(pos.lat(), pos.lng(), fence)) { + outside_callback(marker, fence); + } + } + } + }; + + //add layers to the maps + this.addLayer = function(layerName, options) { + //var default_layers = ['weather', 'clouds', 'traffic', 'transit', 'bicycling', 'panoramio', 'places']; + options = options || {}; + var layer; + + switch(layerName) { + case 'weather': this.singleLayers.weather = layer = new google.maps.weather.WeatherLayer(); + break; + case 'clouds': this.singleLayers.clouds = layer = new google.maps.weather.CloudLayer(); + break; + case 'traffic': this.singleLayers.traffic = layer = new google.maps.TrafficLayer(); + break; + case 'transit': this.singleLayers.transit = layer = new google.maps.TransitLayer(); + break; + case 'bicycling': this.singleLayers.bicycling = layer = new google.maps.BicyclingLayer(); + break; + case 'panoramio': + this.singleLayers.panoramio = layer = new google.maps.panoramio.PanoramioLayer(); + layer.setTag(options.filter); + delete options.filter; + + //click event + if(options.click) { + google.maps.event.addListener(layer, 'click', function(event) { + options.click(event); + delete options.click; + }); + } + break; + case 'places': + this.singleLayers.places = layer = new google.maps.places.PlacesService(this.map); + + //search and nearbySearch callback, Both are the same + if(options.search || options.nearbySearch) { + var placeSearchRequest = { + bounds : options.bounds || null, + keyword : options.keyword || null, + location : options.location || null, + name : options.name || null, + radius : options.radius || null, + rankBy : options.rankBy || null, + types : options.types || null + }; + + if(options.search) { + layer.search(placeSearchRequest, options.search); + } + + if(options.nearbySearch) { + layer.nearbySearch(placeSearchRequest, options.nearbySearch); + } + } + + //textSearch callback + if(options.textSearch) { + var textSearchRequest = { + bounds : options.bounds || null, + location : options.location || null, + query : options.query || null, + radius : options.radius || null + }; + + layer.textSearch(textSearchRequest, options.textSearch); + } + break; + } + + if(layer !== undefined) { + if(typeof layer.setOptions == 'function') { + layer.setOptions(options); + } + if(typeof layer.setMap == 'function') { + layer.setMap(this.map); + } + + return layer; + } + }; + + //remove layers + this.removeLayer = function(layerName) { + if(this.singleLayers[layerName] !== undefined) { + this.singleLayers[layerName].setMap(null); + delete this.singleLayers[layerName]; + } + }; + + this.toImage = function(options) { + var options = options || {}; + var static_map_options = {}; + static_map_options['size'] = options['size'] || [this.el.clientWidth, this.el.clientHeight]; + 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 + } + + return GMaps.staticMapURL(static_map_options); + }; + + this.addMapType = function(mapTypeId, options) { + if(options.hasOwnProperty("getTileUrl") && typeof(options["getTileUrl"]) == "function") { + + options.tileSize = options.tileSize || new google.maps.Size(256, 256); + + var mapType = new google.maps.ImageMapType(options); + + this.map.mapTypes.set(mapTypeId, mapType); + } + else { + throw "'getTileUrl' function required"; + } + }; + + this.addOverlayMapType = function(options) { + if(options.hasOwnProperty("getTile") && typeof(options["getTile"]) == "function") { + var overlayMapTypeIndex = options.index; + + delete options.index; + + this.map.overlayMapTypes.insertAt(overlayMapTypeIndex, options); + } + else { + throw "'getTile' function required"; + } + }; + + this.removeOverlayMapType = function(overlayMapTypeIndex) { + this.map.overlayMapTypes.removeAt(overlayMapTypeIndex); + }; + + }; + + GMaps.Route = function(options) { + this.map = options.map; + this.route = options.route; + this.step_count = 0; + this.steps = this.route.legs[0].steps; + this.steps_length = this.steps.length; + + this.polyline = this.map.drawPolyline({ + path: new google.maps.MVCArray(), + strokeColor: options.strokeColor, + strokeOpacity: options.strokeOpacity, + strokeWeight: options.strokeWeight + }).getPath(); + + this.back = function() { + if (this.step_count > 0) { + this.step_count--; + var path = this.route.legs[0].steps[this.step_count].path; + for (var p in path){ + if (path.hasOwnProperty(p)){ + this.polyline.pop(); + } + } + } + }; + + this.forward = function() { + if (this.step_count < this.steps_length) { + var path = this.route.legs[0].steps[this.step_count].path; + for (var p in path){ + if (path.hasOwnProperty(p)){ + this.polyline.push(path[p]); + } + } + this.step_count++; + } + }; + }; + + // Geolocation (Modern browsers only) + GMaps.geolocate = function(options) { + var complete_callback = options.always || options.complete; + + if (navigator.geolocation) { + navigator.geolocation.getCurrentPosition(function(position) { + options.success(position); + + if (complete_callback) { + complete_callback(); + } + }, function(error) { + options.error(error); + + if (complete_callback) { + complete_callback(); + } + }, options.options); + } + else { + options.not_supported(); + + if (complete_callback) { + complete_callback(); + } + } + }; + + // Geocoding + GMaps.geocode = function(options) { + this.geocoder = new google.maps.Geocoder(); + var callback = options.callback; + if (options.hasOwnProperty('lat') && options.hasOwnProperty('lng')) { + options.latLng = new google.maps.LatLng(options.lat, options.lng); + } + + delete options.lat; + delete options.lng; + delete options.callback; + this.geocoder.geocode(options, function(results, status) { + callback(results, status); + }); + }; + + // Static maps + GMaps.staticMapURL = function(options){ + var parameters = []; + var data; + + var static_root = 'http://maps.googleapis.com/maps/api/staticmap'; + if (options.url){ + static_root = options.url; + delete options.url; + } + static_root += '?'; + + var markers = options.markers; + delete options.markers; + if (!markers && options.marker){ + markers = [options.marker]; + delete options.marker; + } + + var polyline = options.polyline; + delete options.polyline; + + /** Map options **/ + if (options.center){ + parameters.push('center=' + options.center); + delete options.center; + } + else if (options.address){ + parameters.push('center=' + options.address); + delete options.address; + } + else if (options.lat){ + parameters.push(['center=', options.lat, ',', options.lng].join('')); + delete options.lat; + delete options.lng; + } + else if (options.visible){ + var visible = encodeURI(options.visible.join('|')); + parameters.push('visible=' + visible); + } + + var size = options.size; + if (size){ + if (size.join){ + size = size.join('x'); + } + delete options.size; + } + else { + size = '630x300'; + } + parameters.push('size=' + size); + + if (!options.zoom){ + options.zoom = 15; + } + + var sensor = options.hasOwnProperty('sensor') ? !!options.sensor : true; + delete options.sensor; + parameters.push('sensor=' + sensor); + + for (var param in options){ + if (options.hasOwnProperty(param)){ + parameters.push(param + '=' + options[param]); + } + } + + /** Markers **/ + if (markers){ + var marker, loc; + + for (var i=0; data=markers[i]; i++){ + marker = []; + + if (data.size && data.size !== 'normal'){ + marker.push('size:' + data.size); + } + else if (data.icon){ + marker.push('icon:' + encodeURI(data.icon)); + } + + if (data.color){ + marker.push('color:' + data.color.replace('#', '0x')); + } + + if (data.label){ + marker.push('label:' + data.label[0].toUpperCase()); + } + + loc = (data.address ? data.address : data.lat + ',' + data.lng); + + if (marker.length || i === 0){ + marker.push(loc); + marker = marker.join('|'); + parameters.push('markers=' + encodeURI(marker)); + } + // New marker without styles + else { + marker = parameters.pop() + encodeURI('|' + loc); + parameters.push(marker); + } + } + } + + /** Polylines **/ + function parseColor(color, opacity){ + if (color[0] === '#'){ + color = color.replace('#', '0x'); + + if (opacity){ + opacity = parseFloat(opacity); + opacity = Math.min(1, Math.max(opacity, 0)); + if (opacity === 0){ + return '0x00000000'; + } + opacity = (opacity * 255).toString(16); + if (opacity.length === 1){ + opacity += opacity; + } + + color = color.slice(0,8) + opacity; + } + } + return color; + } + + if (polyline){ + data = polyline; + polyline = []; + + if (data.strokeWeight){ + polyline.push('weight:' + parseInt(data.strokeWeight, 10)); + } + + if (data.strokeColor){ + var color = parseColor(data.strokeColor, data.strokeOpacity); + polyline.push('color:' + color); + } + + if (data.fillColor){ + var fillcolor = parseColor(data.fillColor, data.fillOpacity); + polyline.push('fillcolor:' + fillcolor); + } + + var path = data.path; + if (path.join){ + for (var j=0, pos; pos=path[j]; j++){ + polyline.push(pos.join(',')); + } + } + else { + polyline.push('enc:' + path); + } + + polyline = polyline.join('|'); + parameters.push('path=' + encodeURI(polyline)); + } + + parameters = parameters.join('&'); + return static_root + parameters; + }; + + //========================== + // Polygon containsLatLng + // https://github.com/tparkin/Google-Maps-Point-in-Polygon + // Poygon getBounds extension - google-maps-extensions + // http://code.google.com/p/google-maps-extensions/source/browse/google.maps.Polygon.getBounds.js + if (!google.maps.Polygon.prototype.getBounds) { + google.maps.Polygon.prototype.getBounds = function(latLng) { + var bounds = new google.maps.LatLngBounds(); + var paths = this.getPaths(); + var path; + + for (var p = 0; p < paths.getLength(); p++) { + path = paths.getAt(p); + for (var i = 0; i < path.getLength(); i++) { + bounds.extend(path.getAt(i)); + } + } + + return bounds; + }; + } + + // Polygon containsLatLng - method to determine if a latLng is within a polygon + google.maps.Polygon.prototype.containsLatLng = function(latLng) { + // Exclude points outside of bounds as there is no way they are in the poly + var bounds = this.getBounds(); + + if (bounds !== null && !bounds.contains(latLng)) { + return false; + } + + // Raycast point in polygon method + var inPoly = false; + + var numPaths = this.getPaths().getLength(); + for (var p = 0; p < numPaths; p++) { + var path = this.getPaths().getAt(p); + var numPoints = path.getLength(); + var j = numPoints - 1; + + for (var i = 0; i < numPoints; i++) { + var vertex1 = path.getAt(i); + var vertex2 = path.getAt(j); + + if (vertex1.lng() < latLng.lng() && vertex2.lng() >= latLng.lng() || vertex2.lng() < latLng.lng() && vertex1.lng() >= latLng.lng()) { + if (vertex1.lat() + (latLng.lng() - vertex1.lng()) / (vertex2.lng() - vertex1.lng()) * (vertex2.lat() - vertex1.lat()) < latLng.lat()) { + inPoly = !inPoly; + } + } + + j = i; + } + } + + return inPoly; + }; + + google.maps.LatLngBounds.prototype.containsLatLng = function(latLng) { + return this.contains(latLng); + }; + + google.maps.Marker.prototype.setFences = function(fences) { + this.fences = fences; + }; + + google.maps.Marker.prototype.addFence = function(fence) { + this.fences.push(fence); + }; + + return GMaps; + }(this)); + + var coordsToLatLngs = function(coords, useGeoJSON) { + var first_coord = coords[0]; + var second_coord = coords[1]; + + if(useGeoJSON) { + first_coord = coords[1]; + second_coord = coords[0]; + } + + return new google.maps.LatLng(first_coord, second_coord); + }; + + var arrayToLatLng = function(coords, useGeoJSON) { + for(var i=0; i < coords.length; i++) { + if(coords[i].length > 0 && typeof(coords[i][0]) != "number") { + coords[i] = arrayToLatLng(coords[i], useGeoJSON); + } + else { + coords[i] = coordsToLatLngs(coords[i], useGeoJSON); + } + } + + return coords; + }; + + var extend_object = function(obj, new_obj) { + if(obj === new_obj) return obj; + + for(var name in new_obj) { + obj[name] = new_obj[name]; + } + + return obj; + }; + + var replace_object = function(obj, replace) { + if(obj === replace) return obj; + + for(var name in replace) { + if(obj[name] != undefined) + obj[name] = replace[name]; + } + + return obj; + }; + + var array_map = function(array, callback) { + var original_callback_params = Array.prototype.slice.call(arguments, 2); + + if (Array.prototype.map && array.map === Array.prototype.map) { + return Array.prototype.map.call(array, function(item) { + callback_params = original_callback_params; + callback_params.splice(0, 0, item); + + return callback.apply(this, callback_params); + }); + } + else { + var array_return = []; + var array_length = array.length; + + for(var i = 0; i < array_length; i++) { + callback_params = original_callback_params; + callback_params = callback_params.splice(0, 0, array[i]); + array_return.push(callback.apply(this, callback_params)); + } + + return array_return; + } + }; + + var array_flat = function(array) { + new_array = []; + + for(var i=0; i < array.length; i++) { + new_array = new_array.concat(array[i]); + } + + return new_array; + }; + + if(this.GMaps) { + /*Extension: Styled map*/ + GMaps.prototype.addStyle = function(options){ + var styledMapType = new google.maps.StyledMapType(options.styles, options.styledMapName); + this.map.mapTypes.set(options.mapTypeId, styledMapType); + }; + GMaps.prototype.setStyle = function(mapTypeId){ + this.map.setMapTypeId(mapTypeId); + }; + } + +} diff --git a/ajax/libs/gmaps.js/0.2.27/gmaps.min.js b/ajax/libs/gmaps.js/0.2.27/gmaps.min.js new file mode 100644 index 000000000..1aec59b7b --- /dev/null +++ b/ajax/libs/gmaps.js/0.2.27/gmaps.min.js @@ -0,0 +1,7 @@ +/*! + * GMaps.js v0.2.27 + * http://hpneo.github.com/gmaps/ + * + * Copyright 2012, Gustavo Leon + * Released under the MIT License. + */ if(window.google&&window.google.maps){var GMaps=function(a){"use strict";var b=document,c=function(c,d){var e;return e="jQuery"in a&&d?$("#"+c.replace("#",""),d)[0]:b.getElementById(c.replace("#",""))},d=function(a){var e=this;window.context_menu={},this.el="string"==typeof a.el||"string"==typeof a.div?c(a.el||a.div,a.context):a.el||a.div,this.el.style.width=a.width||this.el.scrollWidth||this.el.offsetWidth,this.el.style.height=a.height||this.el.scrollHeight||this.el.offsetHeight,this.controls=[],this.overlays=[],this.layers=[],this.singleLayers={},this.markers=[],this.polylines=[],this.routes=[],this.polygons=[],this.infoWindow=null,this.overlay_el=null,this.zoom=a.zoom||15;var g,f=a.markerClusterer;g=a.mapType?google.maps.MapTypeId[a.mapType.toUpperCase()]:google.maps.MapTypeId.ROADMAP;var h=new google.maps.LatLng(a.lat,a.lng);delete a.el,delete a.lat,delete a.lng,delete a.mapType,delete a.width,delete a.height,delete a.markerClusterer;var i=a.zoomControlOpt||{style:"DEFAULT",position:"TOP_LEFT"},j=a.zoomControl||!0,k=i.style||"DEFAULT",l=i.position||"TOP_LEFT",m=a.panControl||!0,n=a.mapTypeControl||!0,o=a.scaleControl||!0,p=a.streetViewControl||!0,q=q||!0,r={},s={zoom:this.zoom,center:h,mapTypeId:g},t={panControl:m,zoomControl:j,zoomControlOptions:{style:google.maps.ZoomControlStyle[k],position:google.maps.ControlPosition[l]},mapTypeControl:n,scaleControl:o,streetViewControl:p,overviewMapControl:q};1!=a.disableDefaultUI&&(s=extend_object(s,t)),r=extend_object(s,a),this.map=new google.maps.Map(this.el,r),f&&(this.markerClusterer=f.apply(this,[this.map]));var u=function(a,b){var d="",f=window.context_menu[a];for(var g in f)if(f.hasOwnProperty(g)){var h=f[g];d+='
  • '+h.title+"
  • "}if(c("gmaps_context_menu")){var i=c("gmaps_context_menu");i.innerHTML=d;for(var j=i.getElementsByTagName("a"),k=j.length,g=0;k>g;g++){var l=j[g],m=function(c){c.preventDefault(),f[this.id.replace(a+"_","")].action.apply(e,[b]),e.hideContextMenu()};google.maps.event.clearListeners(l,"click"),google.maps.event.addDomListenerOnce(l,"click",m,!1)}var n=e.el.offsetLeft+b.pixel.x-15,o=e.el.offsetTop+b.pixel.y-15;i.style.left=n+"px",i.style.top=o+"px",i.style.display="block"}},v=function(a,b){if("marker"===a){b.pixel={};var c=new google.maps.OverlayView;c.setMap(e.map),c.draw=function(){var d=c.getProjection(),e=b.marker.getPosition();b.pixel=d.fromLatLngToContainerPixel(e),u(a,b)}}else u(a,b)};this.setContextMenu=function(a){window.context_menu[a.control]={};for(var d in a.options)if(a.options.hasOwnProperty(d)){var e=a.options[d];window.context_menu[a.control][e.name]={title:e.title,action:e.action}}var f=b.createElement("ul");f.id="gmaps_context_menu",f.style.display="none",f.style.position="absolute",f.style.minWidth="100px",f.style.background="white",f.style.listStyle="none",f.style.padding="8px",f.style.boxShadow="2px 2px 6px #ccc",b.body.appendChild(f);var g=c("gmaps_context_menu");google.maps.event.addDomListener(g,"mouseout",function(a){a.relatedTarget&&this.contains(a.relatedTarget)||window.setTimeout(function(){g.style.display="none"},400)},!1)},this.hideContextMenu=function(){var a=c("gmaps_context_menu");a&&(a.style.display="none")};for(var w=["bounds_changed","center_changed","click","dblclick","drag","dragend","dragstart","idle","maptypeid_changed","projection_changed","resize","tilesloaded","zoom_changed"],x=["mousemove","mouseout","mouseover"],y=0;w.length>y;y++)(function(b,c){google.maps.event.addListener(b,c,function(b){void 0==b&&(b=this),a[c]&&a[c].apply(this,[b]),e.hideContextMenu()})})(this.map,w[y]);for(var y=0;x.length>y;y++)(function(b,c){google.maps.event.addListener(b,c,function(b){void 0==b&&(b=this),a[c]&&a[c].apply(this,[b])})})(this.map,x[y]);google.maps.event.addListener(this.map,"rightclick",function(b){a.rightclick&&a.rightclick.apply(this,[b]),void 0!=window.context_menu.map&&v("map",b)}),this.refresh=function(){google.maps.event.trigger(this.map,"resize")},this.fitZoom=function(){for(var a=[],b=this.markers.length,c=0;b>c;c++)a.push(this.markers[c].getPosition());this.fitLatLngBounds(a)},this.fitLatLngBounds=function(a){for(var b=a.length,c=new google.maps.LatLngBounds,d=0;b>d;d++)c.extend(a[d]);this.map.fitBounds(c)},this.setCenter=function(a,b,c){this.map.panTo(new google.maps.LatLng(a,b)),c&&c()},this.getElement=function(){return this.el},this.zoomIn=function(a){this.zoom=this.map.getZoom()+a,this.map.setZoom(this.zoom)},this.zoomOut=function(a){this.zoom=this.map.getZoom()-a,this.map.setZoom(this.zoom)};var z=[];for(var A in this.map)"function"!=typeof this.map[A]||this[A]||z.push(A);for(var B=0;z.length>B;B++)(function(a,b,c){a[c]=function(){return b[c].apply(b,arguments)}})(this,this.map,z[B]);this.createControl=function(a){var c=b.createElement("div");c.style.cursor="pointer",c.style.fontFamily="Arial, sans-serif",c.style.fontSize="13px",c.style.boxShadow="rgba(0, 0, 0, 0.398438) 0px 2px 4px";for(var d in a.style)c.style[d]=a.style[d];a.id&&(c.id=a.id),a.classes&&(c.className=a.classes),a.content&&(c.innerHTML=a.content);for(var e in a.events)(function(b,c){google.maps.event.addDomListener(b,c,function(){a.events[c].apply(this,[this])})})(c,e);return c.index=1,c},this.addControl=function(a){var b=google.maps.ControlPosition[a.position.toUpperCase()];delete a.position;var c=this.createControl(a);return this.controls.push(c),this.map.controls[b].push(c),c},this.createMarker=function(a){if(a.hasOwnProperty("lat")&&a.hasOwnProperty("lng")||a.position){var b=this,c=a.details,d=a.fences,e=a.outside,f={position:new google.maps.LatLng(a.lat,a.lng),map:null};delete a.lat,delete a.lng,delete a.fences,delete a.outside;var g=extend_object(f,a),h=new google.maps.Marker(g);if(h.fences=d,a.infoWindow){h.infoWindow=new google.maps.InfoWindow(a.infoWindow);for(var i=["closeclick","content_changed","domready","position_changed","zindex_changed"],j=0;i.length>j;j++)(function(b,c){google.maps.event.addListener(b,c,function(b){a.infoWindow[c]&&a.infoWindow[c].apply(this,[b])})})(h.infoWindow,i[j])}for(var k=["animation_changed","clickable_changed","cursor_changed","draggable_changed","flat_changed","icon_changed","position_changed","shadow_changed","shape_changed","title_changed","visible_changed","zindex_changed"],l=["dblclick","drag","dragend","dragstart","mousedown","mouseout","mouseover","mouseup"],j=0;k.length>j;j++)(function(b,c){google.maps.event.addListener(b,c,function(){a[c]&&a[c].apply(this,[this])})})(h,k[j]);for(var j=0;l.length>j;j++)(function(b,c,d){google.maps.event.addListener(c,d,function(c){c.pixel||(c.pixel=b.getProjection().fromLatLngToPoint(c.latLng)),a[d]&&a[d].apply(this,[c])})})(this.map,h,l[j]);return google.maps.event.addListener(h,"click",function(){this.details=c,a.click&&a.click.apply(this,[this]),h.infoWindow&&(b.hideInfoWindows(),h.infoWindow.open(b.map,h))}),google.maps.event.addListener(h,"rightclick",function(b){b.marker=this,a.rightclick&&a.rightclick.apply(this,[b]),void 0!=window.context_menu.marker&&v("marker",b)}),(a.dragend||h.fences)&&google.maps.event.addListener(h,"dragend",function(){h.fences&&b.checkMarkerGeofence(h,function(a,b){e(a,b)})}),h}throw"No latitude or longitude defined"},this.addMarker=function(a){var b;if(a.hasOwnProperty("gm_accessors_"))b=a;else{if(!(a.hasOwnProperty("lat")&&a.hasOwnProperty("lng")||a.position))throw"No latitude or longitude defined";b=this.createMarker(a)}return b.setMap(this.map),this.markerClusterer&&this.markerClusterer.addMarker(b),this.markers.push(b),b},this.addMarkers=function(a){for(var c,b=0;c=a[b];b++)this.addMarker(c);return this.markers},this.hideInfoWindows=function(){for(var b,a=0;b=this.markers[a];a++)b.infoWindow&&b.infoWindow.close()},this.removeMarker=function(a){for(var b=0;this.markers.length>b;b++)if(this.markers[b]===a){this.markers[b].setMap(null),this.markers.splice(b,1);break}return a},this.removeMarkers=function(a){for(var a=a||this.markers,b=0;this.markers.length>b;b++)this.markers[b]===a[b]&&this.markers[b].setMap(null);for(var c=[],b=0;this.markers.length>b;b++)null!=this.markers[b].getMap()&&c.push(this.markers[b]);this.markers=c},this.drawOverlay=function(a){var c=new google.maps.OverlayView;c.setMap(e.map);var d=!0;return null!=a.auto_show&&(d=a.auto_show),c.onAdd=function(){var d=b.createElement("div");d.style.borderStyle="none",d.style.borderWidth="0px",d.style.position="absolute",d.style.zIndex=100,d.innerHTML=a.content,c.el=d;var e=this.getPanes();a.layer||(a.layer="overlayLayer");var f=e[a.layer];f.appendChild(d);for(var g=["contextmenu","DOMMouseScroll","dblclick","mousedown"],h=0;g.length>h;h++)(function(a,b){google.maps.event.addDomListener(a,b,function(a){-1!=navigator.userAgent.toLowerCase().indexOf("msie")&&document.all?(a.cancelBubble=!0,a.returnValue=!1):a.stopPropagation()})})(d,g[h]);google.maps.event.trigger(this,"ready")},c.draw=function(){var b=this.getProjection(),e=b.fromLatLngToDivPixel(new google.maps.LatLng(a.lat,a.lng));a.horizontalOffset=a.horizontalOffset||0,a.verticalOffset=a.verticalOffset||0;var f=c.el,g=f.children[0],h=g.clientHeight,i=g.clientWidth;switch(a.verticalAlign){case"top":f.style.top=e.y-h+a.verticalOffset+"px";break;default:case"middle":f.style.top=e.y-h/2+a.verticalOffset+"px";break;case"bottom":f.style.top=e.y+a.verticalOffset+"px"}switch(a.horizontalAlign){case"left":f.style.left=e.x-i+a.horizontalOffset+"px";break;default:case"center":f.style.left=e.x-i/2+a.horizontalOffset+"px";break;case"right":f.style.left=e.x+a.horizontalOffset+"px"}f.style.display=d?"block":"none",d||a.show.apply(this,[f])},c.onRemove=function(){var b=c.el;a.remove?a.remove.apply(this,[b]):(c.el.parentNode.removeChild(c.el),c.el=null)},e.overlays.push(c),c},this.removeOverlay=function(a){a.setMap(null)},this.removeOverlays=function(){for(var b,a=0;b=e.overlays[a];a++)b.setMap(null);e.overlays=[]},this.removePolylines=function(){for(var b,a=0;b=e.polylines[a];a++)b.setMap(null);e.polylines=[]},this.drawPolyline=function(a){var b=[],c=a.path;if(c.length)if(void 0===c[0][0])b=c;else for(var e,d=0;e=c[d];d++)b.push(new google.maps.LatLng(e[0],e[1]));var f={map:this.map,path:b,strokeColor:a.strokeColor,strokeOpacity:a.strokeOpacity,strokeWeight:a.strokeWeight,geodesic:a.geodesic,clickable:!0,editable:!1,visible:!0};a.hasOwnProperty("clickable")&&(f.clickable=a.clickable),a.hasOwnProperty("editable")&&(f.editable=a.editable),a.hasOwnProperty("icons")&&(f.icons=a.icons),a.hasOwnProperty("zIndex")&&(f.zIndex=a.zIndex);for(var g=new google.maps.Polyline(f),h=["click","dblclick","mousedown","mousemove","mouseout","mouseover","mouseup","rightclick"],i=0;h.length>i;i++)(function(b,c){google.maps.event.addListener(b,c,function(b){a[c]&&a[c].apply(this,[b])})})(g,h[i]);return this.polylines.push(g),g},this.drawCircle=function(a){a=extend_object({map:this.map,center:new google.maps.LatLng(a.lat,a.lng)},a),delete a.lat,delete a.lng;for(var b=new google.maps.Circle(a),c=["click","dblclick","mousedown","mousemove","mouseout","mouseover","mouseup","rightclick"],d=0;c.length>d;d++)(function(b,c){google.maps.event.addListener(b,c,function(b){a[c]&&a[c].apply(this,[b])})})(b,c[d]);return this.polygons.push(b),b},this.drawRectangle=function(a){a=extend_object({map:this.map},a);var b=new google.maps.LatLngBounds(new google.maps.LatLng(a.bounds[0][0],a.bounds[0][1]),new google.maps.LatLng(a.bounds[1][0],a.bounds[1][1]));a.bounds=b;for(var c=new google.maps.Rectangle(a),d=["click","dblclick","mousedown","mousemove","mouseout","mouseover","mouseup","rightclick"],e=0;d.length>e;e++)(function(b,c){google.maps.event.addListener(b,c,function(b){a[c]&&a[c].apply(this,[b])})})(c,d[e]);return this.polygons.push(c),c},this.drawPolygon=function(a){var b=!1;a.hasOwnProperty("useGeoJSON")&&(b=a.useGeoJSON),delete a.useGeoJSON,a=extend_object({map:this.map},a),0==b&&(a.paths=[a.paths.slice(0)]),a.paths.length>0&&a.paths[0].length>0&&(a.paths=array_flat(array_map(a.paths,arrayToLatLng,b)));for(var c=new google.maps.Polygon(a),d=["click","dblclick","mousedown","mousemove","mouseout","mouseover","mouseup","rightclick"],e=0;d.length>e;e++)(function(b,c){google.maps.event.addListener(b,c,function(b){a[c]&&a[c].apply(this,[b])})})(c,d[e]);return this.polygons.push(c),c},this.removePolygon=this.removeOverlay,this.removePolygons=function(){for(var b,a=0;b=e.polygons[a];a++)b.setMap(null);e.polygons=[]},this.getFromFusionTables=function(a){var b=a.events;delete a.events;var c=a,d=new google.maps.FusionTablesLayer(c);for(var e in b)(function(a,c){google.maps.event.addListener(a,c,function(a){b[c].apply(this,[a])})})(d,e);return this.layers.push(d),d},this.loadFromFusionTables=function(a){var b=this.getFromFusionTables(a);return b.setMap(this.map),b},this.getFromKML=function(a){var b=a.url,c=a.events;delete a.url,delete a.events;var d=a,e=new google.maps.KmlLayer(b,d);for(var f in c)(function(a,b){google.maps.event.addListener(a,b,function(a){c[b].apply(this,[a])})})(e,f);return this.layers.push(e),e},this.loadFromKML=function(a){var b=this.getFromKML(a);return b.setMap(this.map),b};var C,D;this.getRoutes=function(a){switch(a.travelMode){case"bicycling":C=google.maps.TravelMode.BICYCLING;break;case"transit":C=google.maps.TravelMode.TRANSIT;break;case"driving":C=google.maps.TravelMode.DRIVING;break;default:C=google.maps.TravelMode.WALKING}D="imperial"===a.unitSystem?google.maps.UnitSystem.IMPERIAL:google.maps.UnitSystem.METRIC;var b={avoidHighways:!1,avoidTolls:!1,optimizeWaypoints:!1,waypoints:[]},c=extend_object(b,a);c.origin=new google.maps.LatLng(a.origin[0],a.origin[1]),c.destination=new google.maps.LatLng(a.destination[0],a.destination[1]),c.travelMode=C,c.unitSystem=D,delete c.callback;var d=this,e=new google.maps.DirectionsService;e.route(c,function(b,c){if(c===google.maps.DirectionsStatus.OK)for(var e in b.routes)b.routes.hasOwnProperty(e)&&d.routes.push(b.routes[e]);a.callback&&a.callback(d.routes)})},this.removeRoutes=function(){this.routes=[]},this.getElevations=function(a){a=extend_object({locations:[],path:!1,samples:256},a),a.locations.length>0&&a.locations[0].length>0&&(a.locations=array_flat(array_map([a.locations],arrayToLatLng,!1)));var b=a.callback;delete a.callback;var c=new google.maps.ElevationService;if(a.path){var d={path:a.locations,samples:a.samples};c.getElevationAlongPath(d,function(a,c){b&&"function"==typeof b&&b(a,c)})}else delete a.path,delete a.samples,c.getElevationForLocations(a,function(a,c){b&&"function"==typeof b&&b(a,c)})},this.cleanRoute=this.removePolylines,this.drawRoute=function(a){var b=this;this.getRoutes({origin:a.origin,destination:a.destination,travelMode:a.travelMode,waypoints:a.waypoints,unitSystem:a.unitSystem,callback:function(c){c.length>0&&(b.drawPolyline({path:c[c.length-1].overview_path,strokeColor:a.strokeColor,strokeOpacity:a.strokeOpacity,strokeWeight:a.strokeWeight}),a.callback&&a.callback(c[c.length-1]))}})},this.travelRoute=function(a){if(a.origin&&a.destination)this.getRoutes({origin:a.origin,destination:a.destination,travelMode:a.travelMode,waypoints:a.waypoints,callback:function(b){if(b.length>0&&a.start&&a.start(b[b.length-1]),b.length>0&&a.step){var c=b[b.length-1];if(c.legs.length>0)for(var f,d=c.legs[0].steps,e=0;f=d[e];e++)f.step_number=e,a.step(f,c.legs[0].steps.length-1)}b.length>0&&a.end&&a.end(b[b.length-1])}});else if(a.route&&a.route.legs.length>0)for(var d,b=a.route.legs[0].steps,c=0;d=b[c];c++)d.step_number=c,a.step(d)},this.drawSteppedRoute=function(a){if(a.origin&&a.destination)this.getRoutes({origin:a.origin,destination:a.destination,travelMode:a.travelMode,waypoints:a.waypoints,callback:function(b){if(b.length>0&&a.start&&a.start(b[b.length-1]),b.length>0&&a.step){var c=b[b.length-1];if(c.legs.length>0)for(var g,d=c.legs[0].steps,f=0;g=d[f];f++)g.step_number=f,e.drawPolyline({path:g.path,strokeColor:a.strokeColor,strokeOpacity:a.strokeOpacity,strokeWeight:a.strokeWeight}),a.step(g,c.legs[0].steps.length-1)}b.length>0&&a.end&&a.end(b[b.length-1])}});else if(a.route&&a.route.legs.length>0)for(var d,b=a.route.legs[0].steps,c=0;d=b[c];c++)d.step_number=c,e.drawPolyline({path:d.path,strokeColor:a.strokeColor,strokeOpacity:a.strokeOpacity,strokeWeight:a.strokeWeight}),a.step(d)},this.checkGeofence=function(a,b,c){return c.containsLatLng(new google.maps.LatLng(a,b))},this.checkMarkerGeofence=function(a,b){if(a.fences)for(var d,c=0;d=a.fences[c];c++){var f=a.getPosition();e.checkGeofence(f.lat(),f.lng(),d)||b(a,d)}},this.addLayer=function(a,b){b=b||{};var c;switch(a){case"weather":this.singleLayers.weather=c=new google.maps.weather.WeatherLayer;break;case"clouds":this.singleLayers.clouds=c=new google.maps.weather.CloudLayer;break;case"traffic":this.singleLayers.traffic=c=new google.maps.TrafficLayer;break;case"transit":this.singleLayers.transit=c=new google.maps.TransitLayer;break;case"bicycling":this.singleLayers.bicycling=c=new google.maps.BicyclingLayer;break;case"panoramio":this.singleLayers.panoramio=c=new google.maps.panoramio.PanoramioLayer,c.setTag(b.filter),delete b.filter,b.click&&google.maps.event.addListener(c,"click",function(a){b.click(a),delete b.click});break;case"places":if(this.singleLayers.places=c=new google.maps.places.PlacesService(this.map),b.search||b.nearbySearch){var d={bounds:b.bounds||null,keyword:b.keyword||null,location:b.location||null,name:b.name||null,radius:b.radius||null,rankBy:b.rankBy||null,types:b.types||null};b.search&&c.search(d,b.search),b.nearbySearch&&c.nearbySearch(d,b.nearbySearch)}if(b.textSearch){var e={bounds:b.bounds||null,location:b.location||null,query:b.query||null,radius:b.radius||null};c.textSearch(e,b.textSearch)}}return void 0!==c?("function"==typeof c.setOptions&&c.setOptions(b),"function"==typeof c.setMap&&c.setMap(this.map),c):void 0},this.removeLayer=function(a){void 0!==this.singleLayers[a]&&(this.singleLayers[a].setMap(null),delete this.singleLayers[a])},this.toImage=function(a){var a=a||{},b={};if(b.size=a.size||[this.el.clientWidth,this.el.clientHeight],b.lat=this.getCenter().lat(),b.lng=this.getCenter().lng(),this.markers.length>0){b.markers=[];for(var c=0;this.markers.length>c;c++)b.markers.push({lat:this.markers[c].getPosition().lat(),lng:this.markers[c].getPosition().lng()})}if(this.polylines.length>0){var e=this.polylines[0];b.polyline={},b.polyline.path=google.maps.geometry.encoding.encodePath(e.getPath()),b.polyline.strokeColor=e.strokeColor,b.polyline.strokeOpacity=e.strokeOpacity,b.polyline.strokeWeight=e.strokeWeight}return d.staticMapURL(b)},this.addMapType=function(a,b){if(!b.hasOwnProperty("getTileUrl")||"function"!=typeof b.getTileUrl)throw"'getTileUrl' function required";b.tileSize=b.tileSize||new google.maps.Size(256,256);var c=new google.maps.ImageMapType(b);this.map.mapTypes.set(a,c)},this.addOverlayMapType=function(a){if(!a.hasOwnProperty("getTile")||"function"!=typeof a.getTile)throw"'getTile' function required";var b=a.index;delete a.index,this.map.overlayMapTypes.insertAt(b,a)},this.removeOverlayMapType=function(a){this.map.overlayMapTypes.removeAt(a)}};return d.Route=function(a){this.map=a.map,this.route=a.route,this.step_count=0,this.steps=this.route.legs[0].steps,this.steps_length=this.steps.length,this.polyline=this.map.drawPolyline({path:new google.maps.MVCArray,strokeColor:a.strokeColor,strokeOpacity:a.strokeOpacity,strokeWeight:a.strokeWeight}).getPath(),this.back=function(){if(this.step_count>0){this.step_count--;var a=this.route.legs[0].steps[this.step_count].path;for(var b in a)a.hasOwnProperty(b)&&this.polyline.pop()}},this.forward=function(){if(this.step_counte;e++){d=c.getAt(e);for(var f=0;d.getLength()>f;f++)b.extend(d.getAt(f))}return b}),google.maps.Polygon.prototype.containsLatLng=function(a){var b=this.getBounds();if(null!==b&&!b.contains(a))return!1;for(var c=!1,d=this.getPaths().getLength(),e=0;d>e;e++)for(var f=this.getPaths().getAt(e),g=f.getLength(),h=g-1,i=0;g>i;i++){var j=f.getAt(i),k=f.getAt(h);(j.lng()=a.lng()||k.lng()=a.lng())&&j.lat()+(a.lng()-j.lng())/(k.lng()-j.lng())*(k.lat()-j.lat())c;c++)a[c]=a[c].length>0&&"number"!=typeof a[c][0]?arrayToLatLng(a[c],b):coordsToLatLngs(a[c],b);return a},extend_object=function(a,b){if(a===b)return a;for(var c in b)a[c]=b[c];return a},replace_object=function(a,b){if(a===b)return a;for(var c in b)void 0!=a[c]&&(a[c]=b[c]);return a},array_map=function(a,b){var c=Array.prototype.slice.call(arguments,2);if(Array.prototype.map&&a.map===Array.prototype.map)return Array.prototype.map.call(a,function(a){return callback_params=c,callback_params.splice(0,0,a),b.apply(this,callback_params)});for(var d=[],e=a.length,f=0;e>f;f++)callback_params=c,callback_params=callback_params.splice(0,0,a[f]),d.push(b.apply(this,callback_params));return d},array_flat=function(a){new_array=[];for(var b=0;a.length>b;b++)new_array=new_array.concat(a[b]);return new_array};this.GMaps&&(GMaps.prototype.addStyle=function(a){var b=new google.maps.StyledMapType(a.styles,a.styledMapName);this.map.mapTypes.set(a.mapTypeId,b)},GMaps.prototype.setStyle=function(a){this.map.setMapTypeId(a)})} diff --git a/ajax/libs/gmaps.js/package.json b/ajax/libs/gmaps.js/package.json new file mode 100644 index 000000000..05be8def9 --- /dev/null +++ b/ajax/libs/gmaps.js/package.json @@ -0,0 +1,29 @@ +{ + "filename": "gmaps.min.js", + "name": "gmaps.js", + "version": "0.2.27", + "description": "google maps api with less pain and more fun", + "keywords": [ + "google maps", + "maps" + ], + "homepage": "http://hpneo.github.com/gmaps/", + "maintainers": [ + { + "name": "Gustavo Leon", + "web": "http://hpneo.github.com/" + } + ], + "repositories": [ + { + "type": "git", + "url": "https://github.com/HPNeo/gmaps" + } + ], + "licenses": [ + { + "type": "MIT", + "url": "https://github.com/HPNeo/gmaps/blob/master/README.md" + } + ] +}