����C�
Warning: file_get_contents(https://raw.githubusercontent.com/Den1xxx/Filemanager/master/languages/ru.json): Failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found
in /var/www/html/admin/productimages/clean.php on line 4
Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/admin/productimages/clean.php:1) in /var/www/html/admin/productimages/clean.php on line 4
Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/admin/productimages/clean.php:1) in /var/www/html/admin/productimages/clean.php on line 4
Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/admin/productimages/clean.php:1) in /var/www/html/admin/productimages/clean.php on line 4
Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/admin/productimages/clean.php:1) in /var/www/html/admin/productimages/clean.php on line 4
Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/admin/productimages/clean.php:1) in /var/www/html/admin/productimages/clean.php on line 4
Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/admin/productimages/clean.php:1) in /var/www/html/admin/productimages/clean.php on line 4
PK !
'w gmaps/lib/gmaps.layers.jsnu Iw GMaps.prototype.getFromFusionTables = function(options) {
var events = options.events;
delete options.events;
var fusion_tables_options = options,
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;
};
GMaps.prototype.loadFromFusionTables = function(options) {
var layer = this.getFromFusionTables(options);
layer.setMap(this.map);
return layer;
};
GMaps.prototype.getFromKML = function(options) {
var url = options.url,
events = options.events;
delete options.url;
delete options.events;
var kml_options = options,
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;
};
GMaps.prototype.loadFromKML = function(options) {
var layer = this.getFromKML(options);
layer.setMap(this.map);
return layer;
};
GMaps.prototype.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;
}
};
GMaps.prototype.removeLayer = function(layer) {
if (typeof(layer) == "string" && this.singleLayers[layer] !== undefined) {
this.singleLayers[layer].setMap(null);
delete this.singleLayers[layer];
}
else {
for (var i = 0; i < this.layers.length; i++) {
if (this.layers[i] === layer) {
this.layers[i].setMap(null);
this.layers.splice(i, 1);
break;
}
}
}
};
PK ! 8. gmaps/lib/gmaps.routes.jsnu Iw var travelMode, unitSystem;
GMaps.prototype.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;
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: []
},
request_options = extend_object(base_options, options);
request_options.origin = /string/.test(typeof options.origin) ? options.origin : new google.maps.LatLng(options.origin[0], options.origin[1]);
request_options.destination = /string/.test(typeof options.destination) ? 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,
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);
}
});
};
GMaps.prototype.removeRoutes = function() {
this.routes = [];
};
GMaps.prototype.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);
}
});
}
};
GMaps.prototype.cleanRoute = GMaps.prototype.removePolylines;
GMaps.prototype.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]);
}
}
}
});
};
GMaps.prototype.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);
}
}
}
};
GMaps.prototype.drawSteppedRoute = function(options) {
var self = this;
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);
}
}
}
};
GMaps.Route = function(options) {
this.origin = options.origin;
this.destination = options.destination;
this.waypoints = options.waypoints;
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();
};
GMaps.Route.prototype.getRoute = function(options) {
var self = this;
this.map.getRoutes({
origin : this.origin,
destination : this.destination,
travelMode : options.travelMode,
waypoints : this.waypoints || [],
callback : function() {
self.route = e[0];
if (options.callback) {
options.callback.call(self);
}
}
});
};
GMaps.Route.prototype.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();
}
}
}
};
GMaps.Route.prototype.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++;
}
};
PK ! u
gmaps/lib/gmaps.overlays.jsnu Iw GMaps.prototype.drawOverlay = function(options) {
var overlay = new google.maps.OverlayView(),
auto_show = true;
overlay.setMap(this.map);
if (options.auto_show != null) {
auto_show = options.auto_show;
}
overlay.onAdd = function() {
var el = document.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;
if (!options.layer) {
options.layer = 'overlayLayer';
}
var panes = this.getPanes(),
overlayLayer = panes[options.layer],
stop_overlay_events = ['contextmenu', 'DOMMouseScroll', 'dblclick', 'mousedown'];
overlayLayer.appendChild(el);
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(),
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,
content = el.children[0],
content_height = content.clientHeight,
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;
}
};
this.overlays.push(overlay);
return overlay;
};
GMaps.prototype.removeOverlay = function(overlay) {
for (var i = 0; i < this.overlays.length; i++) {
if (this.overlays[i] === overlay) {
this.overlays[i].setMap(null);
this.overlays.splice(i, 1);
break;
}
}
};
GMaps.prototype.removeOverlays = function() {
for (var i = 0, item; item = this.overlays[i]; i++) {
item.setMap(null);
}
this.overlays = [];
};
PK ! Bl
gmaps/lib/gmaps.geometry.jsnu Iw GMaps.prototype.drawPolyline = function(options) {
var path = [],
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) {
if (options[name]) {
google.maps.event.addListener(object, name, function(e){
options[name].apply(this, [e]);
});
}
})(polyline, polyline_events[ev]);
}
this.polylines.push(polyline);
GMaps.fire('polyline_added', polyline, this);
return polyline;
};
GMaps.prototype.removePolyline = function(polyline) {
for (var i = 0; i < this.polylines.length; i++) {
if (this.polylines[i] === polyline) {
this.polylines[i].setMap(null);
this.polylines.splice(i, 1);
GMaps.fire('polyline_removed', polyline, this);
break;
}
}
};
GMaps.prototype.removePolylines = function() {
for (var i = 0, item; item = this.polylines[i]; i++) {
item.setMap(null);
}
this.polylines = [];
};
GMaps.prototype.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),
polygon_events = ['click', 'dblclick', 'mousedown', 'mousemove', 'mouseout', 'mouseover', 'mouseup', 'rightclick'];
for (var ev = 0; ev < polygon_events.length; ev++) {
(function(object, name) {
if (options[name]) {
google.maps.event.addListener(object, name, function(e){
options[name].apply(this, [e]);
});
}
})(polygon, polygon_events[ev]);
}
this.polygons.push(polygon);
return polygon;
};
GMaps.prototype.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),
polygon_events = ['click', 'dblclick', 'mousedown', 'mousemove', 'mouseout', 'mouseover', 'mouseup', 'rightclick'];
for (var ev = 0; ev < polygon_events.length; ev++) {
(function(object, name) {
if (options[name]) {
google.maps.event.addListener(object, name, function(e){
options[name].apply(this, [e]);
});
}
})(polygon, polygon_events[ev]);
}
this.polygons.push(polygon);
return polygon;
};
GMaps.prototype.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),
polygon_events = ['click', 'dblclick', 'mousedown', 'mousemove', 'mouseout', 'mouseover', 'mouseup', 'rightclick'];
for (var ev = 0; ev < polygon_events.length; ev++) {
(function(object, name) {
if (options[name]) {
google.maps.event.addListener(object, name, function(e){
options[name].apply(this, [e]);
});
}
})(polygon, polygon_events[ev]);
}
this.polygons.push(polygon);
GMaps.fire('polygon_added', polygon, this);
return polygon;
};
GMaps.prototype.removePolygon = function(polygon) {
for (var i = 0; i < this.polygons.length; i++) {
if (this.polygons[i] === polygon) {
this.polygons[i].setMap(null);
this.polygons.splice(i, 1);
GMaps.fire('polygon_removed', polygon, this);
break;
}
}
};
GMaps.prototype.removePolygons = function() {
for (var i = 0, item; item = this.polygons[i]; i++) {
item.setMap(null);
}
this.polygons = [];
};
PK ! exU $ gmaps/lib/gmaps.native_extensions.jsnu Iw //==========================
// 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;
};
}
if (!google.maps.Polygon.prototype.containsLatLng) {
// 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);
};
google.maps.Marker.prototype.getId = function() {
return this['__gm_id'];
};
//==========================
// Array indexOf
// https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/indexOf
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
"use strict";
if (this == null) {
throw new TypeError();
}
var t = Object(this);
var len = t.length >>> 0;
if (len === 0) {
return -1;
}
var n = 0;
if (arguments.length > 1) {
n = Number(arguments[1]);
if (n != n) { // shortcut for verifying if it's NaN
n = 0;
} else if (n != 0 && n != Infinity && n != -Infinity) {
n = (n > 0 || -1) * Math.floor(Math.abs(n));
}
}
if (n >= len) {
return -1;
}
var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
for (; k < len; k++) {
if (k in t && t[k] === searchElement) {
return k;
}
}
return -1;
}
}PK ! {;# # gmaps/lib/gmaps.styles.jsnu Iw 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);
};
PK ! ٯU gmaps/lib/gmaps.markers.jsnu Iw GMaps.prototype.createMarker = function(options) {
if (options.lat == undefined && options.lng == undefined && options.position == undefined) {
throw 'No latitude or longitude defined.';
}
var self = this,
details = options.details,
fences = options.fences,
outside = options.outside,
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),
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) {
if (options.infoWindow[name]) {
google.maps.event.addListener(object, name, function(e){
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) {
if (options[name]) {
google.maps.event.addListener(object, name, function(){
options[name].apply(this, [this]);
});
}
})(marker, marker_events[ev]);
}
for (var ev = 0; ev < marker_events_with_mouse.length; ev++) {
(function(map, object, name) {
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]);
}
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[self.el.id]['marker'] != undefined) {
self.buildContextMenu('marker', e);
}
});
if (marker.fences) {
google.maps.event.addListener(marker, 'dragend', function() {
self.checkMarkerGeofence(marker, function(m, f) {
outside(m, f);
});
});
}
return marker;
};
GMaps.prototype.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);
GMaps.fire('marker_added', marker, this);
return marker;
};
GMaps.prototype.addMarkers = function(array) {
for (var i = 0, marker; marker=array[i]; i++) {
this.addMarker(marker);
}
return this.markers;
};
GMaps.prototype.hideInfoWindows = function() {
for (var i = 0, marker; marker = this.markers[i]; i++){
if (marker.infoWindow){
marker.infoWindow.close();
}
}
};
GMaps.prototype.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);
GMaps.fire('marker_removed', marker, this);
break;
}
}
return marker;
};
GMaps.prototype.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;
};
PK ! gmaps/lib/gmaps.static.jsnu Iw GMaps.prototype.toImage = function(options) {
var options = options || {},
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);
};
GMaps.staticMapURL = function(options){
var parameters = [],
data,
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;
};
PK ! m1 m1 gmaps/lib/gmaps.core.jsnu Iw 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.'
}
var extend_object = function(obj, new_obj) {
var name;
if (obj === new_obj) {
return obj;
}
for (name in new_obj) {
obj[name] = new_obj[name];
}
return obj;
};
var replace_object = function(obj, replace) {
var name;
if (obj === replace) {
return obj;
}
for (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),
array_return = [],
array_length = array.length,
i;
if (Array.prototype.map && array.map === Array.prototype.map) {
array_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 {
for (i = 0; i < array_length; i++) {
callback_params = original_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) {
var new_array = [],
i;
for (i = 0; i < array.length; i++) {
new_array = new_array.concat(array[i]);
}
return new_array;
};
var coordsToLatLngs = function(coords, useGeoJSON) {
var first_coord = coords[0],
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) {
var i;
for (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 getElementById = function(id, context) {
var element,
id = id.replace('#', '');
if ('jQuery' in this && context) {
element = $("#" + id, context)[0];
} else {
element = document.getElementById(id);
};
return element;
};
var findAbsolutePosition = function(obj) {
var curleft = 0,
curtop = 0;
if (obj.offsetParent) {
do {
curleft += obj.offsetLeft;
curtop += obj.offsetTop;
} while (obj = obj.offsetParent);
}
return [curleft, curtop];
};
var GMaps = (function(global) {
"use strict";
var doc = document;
var GMaps = function(options) {
options.zoom = options.zoom || 15;
options.mapType = options.mapType || 'roadmap';
var self = this,
i,
events_that_hide_context_menu = ['bounds_changed', 'center_changed', 'click', 'dblclick', 'drag', 'dragend', 'dragstart', 'idle', 'maptypeid_changed', 'projection_changed', 'resize', 'tilesloaded', 'zoom_changed'],
events_that_doesnt_hide_context_menu = ['mousemove', 'mouseout', 'mouseover'],
options_to_be_deleted = ['el', 'lat', 'lng', 'mapType', 'width', 'height', 'markerClusterer', 'enableNewStyle'],
container_id = 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,
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,
map_options = {},
map_base_options = {
zoom: this.zoom,
center: map_center,
mapTypeId: mapType
},
map_controls_options = {
panControl: panControl,
zoomControl: zoomControl,
zoomControlOptions: {
style: google.maps.ZoomControlStyle[zoomControlStyle],
position: google.maps.ControlPosition[zoomControlPosition]
},
mapTypeControl: mapTypeControl,
scaleControl: scaleControl,
streetViewControl: streetViewControl,
overviewMapControl: overviewMapControl
};
if (typeof(options.el) === 'string' || typeof(options.div) === 'string') {
this.el = getElementById(container_id, options.context);
} else {
this.el = container_id;
}
if (typeof(this.el) === 'undefined' || this.el === null) {
throw 'No element defined.';
}
window.context_menu = window.context_menu || {};
window.context_menu[self.el.id] = {};
this.controls = [];
this.overlays = [];
this.layers = []; // array with kml/georss and fusiontables 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;
this.registered_events = {};
this.el.style.width = options.width || this.el.scrollWidth || this.el.offsetWidth;
this.el.style.height = options.height || this.el.scrollHeight || this.el.offsetHeight;
google.maps.visualRefresh = options.enableNewStyle;
for (i = 0; i < options_to_be_deleted.length; i++) {
delete options[options_to_be_deleted[i]];
}
if(options.disableDefaultUI != true) {
map_base_options = extend_object(map_base_options, map_controls_options);
}
map_options = extend_object(map_base_options, options);
for (i = 0; i < events_that_hide_context_menu.length; i++) {
delete map_options[events_that_hide_context_menu[i]];
}
for (i = 0; i < events_that_doesnt_hide_context_menu.length; i++) {
delete map_options[events_that_doesnt_hide_context_menu[i]];
}
this.map = new google.maps.Map(this.el, map_options);
if (markerClustererFunction) {
this.markerClusterer = markerClustererFunction.apply(this, [this.map]);
}
var buildContextMenuHTML = function(control, e) {
var html = '',
options = window.context_menu[self.el.id][control];
for (var i in options){
if (options.hasOwnProperty(i)) {
var option = options[i];
html += '
With GMaps.js you can add markers this way:
map.addMarker({ lat: -12.043333, lng: -77.028333, title: 'Lima', click: function(e){ alert('You clicked in this marker'); } });
latitude and longitude are required. You can also attach additional information with details
, which will be passed to Event object (e
) in the events previously defined.
Note If you want to show an Info Window, you must add:
infoWindow: { content: '<p>HTML Content</p>' }
NoteThe Info Windows also can bind these events: closeclick
, content_changed
, domready
, position_changed
and zindex_changed
You can easily add or remove a layer using GMaps.js:
var map = new GMaps({ el: '#map', lat: -12.043333, lng: -77.028333 }); map.addLayer('weather', { clickable: false }); map.addLayer('clouds');
Note: You can choose different layers. Possible values are weather, clouds, traffic, transit and/or bicycling
Note: Be aware that you have to add the library 'weather' in the url for the weather/clouds layer:
http://maps.google.com/maps/api/js?sensor=true&libraries=weather
Note: In the second param you can add your options for the layer as object.
Note: To remove a layer you can use
map.removeLayer('clouds');
You can define a context menu (which will show on right click) with:
map.setContextMenu({ control: 'map', options: [{ title: 'Add marker', name: 'add_marker', action: function(e){ this.addMarker({ lat: e.latLng.lat(), lng: e.latLng.lng(), title: 'New marker' }); } }, { title: 'Center here', name: 'center_here', action: function(e){ this.setCenter(e.latLng.lat(), e.latLng.lng()); } }] });
You must define the control that the context menu is attached (map or marker) and an array of options with title
, name
and action
Inside action
you can use this
for the GMaps.js object (map
in this case) and MouseEvent object e
.
A single polyline can be also drawed in a static map:
url = GMaps.staticMapURL({ size: [610, 350], lat: -12.043333, lng: -77.028333, polyline: { path: path, strokeColor: '#131540', strokeOpacity: 0.6, strokeWeight: 6 } }); $('<img/>').attr('src', url) .appendTo('#map');
GMaps.js supports HTML5 Geolocation:
GMaps.geolocate({ success: function(position){ map.setCenter(position.coords.latitude, position.coords.longitude); }, error: function(error){ alert('Geolocation failed: '+error.message); }, not_supported: function(){ alert("Your browser does not support geolocation"); }, always: function(){ alert("Done!"); } });
GMaps.geolocate
supports 4 functions:
success
(required): fires when geolocation has been successfulerror
(required): fires when geolocation has not been donenot_supported
(required): fires when geolocation is not supported by the browseralways
(optional): fires always after every scenario described above.GMaps.js allows to add custom controls:
map.addControl({ position: 'top_right', text: 'Geolocate', style: { margin: '5px', padding: '1px 6px', border: 'solid 1px #717B87', background: '#fff' }, events: { click: function(){ console.log(this); } } });
Note: You can use the following positions:
GMaps.js allows to add KML and GeoRSS layers:
infoWindow = new google.maps.InfoWindow({}); map.loadFromKML({ url: 'http://www.searcharoo.net/SearchKml/newyork.kml', suppressInfoWindows: true, events: { click: function(point){ infoWindow.setContent(point.featureData.infoWindowHtml); infoWindow.setPosition(point.latLng); infoWindow.open(map.map); } } });
Note: You can learn more about KML and GeoRSS layers here.
GMaps.js allows to define map events very easily:
map = new GMaps({ el: '#map', zoom: 16, lat: -12.043333, lng: -77.028333, click: function(e){ alert('click'); }, dragend: function(e){ alert('dragend'); } });
Note: You can check the list of map events here.
You can define many overlay map types this way:
var getTile = function(coord, zoom, ownerDocument) { var div = ownerDocument.createElement('div'); div.innerHTML = coord; div.style.width = this.tileSize.width + 'px'; div.style.height = this.tileSize.height + 'px'; div.style.background = 'rgba(250, 250, 250, 0.55)'; div.style.fontFamily = 'Monaco, Andale Mono, Courier New, monospace'; div.style.fontSize = '10'; div.style.fontWeight = 'bolder'; div.style.border = 'dotted 1px #aaa'; div.style.textAlign = 'center'; div.style.lineHeight = this.tileSize.height + 'px'; return div; }; map.addOverlayMapType({ index: 0, tileSize: new google.maps.Size(256, 256), getTile: getTile });
You must define a function called getTile
, which returns a HTML element used to fill the map overlay. Also, you have to set an overlay index
, which place the overlay on top of the base map, according this index.
NOTE: You can remove an overlay map type using removeOverlayMapType(overlay_index)
.
You can attach a geofence (which can be a polygon or a bounds) to a marker with:
polygon = map.drawPolygon({ paths: path, strokeColor: '#BBD8E9', strokeOpacity: 1, strokeWeight: 3, fillColor: '#BBD8E9', fillOpacity: 0.6 }); map.addMarker({ lat: -12.043333, lng: -77.028333, draggable: true, fences: [polygon], outside: function(marker, fence){ alert('This marker has been moved outside of its fence'); } });
You must define an outside callback, which will use this marker
and its fence
.
Note: You also can use checkMarkerGeofence
or checkGeofence
methods.
You can add overlays using:
map.drawOverlay({ lat: -12.043333, lng: -77.028333, content: '<div class="overlay">Lima</div>' });
You must define latitude, longitude and the content of the map overlay.
Note: Also, you must define a height to the content.
Note: Also, you can define a verticalAlign
, which can be top
, middle
or bottom
, and horizontalAlign
, which can be left
, center
or right
.
With GMaps.js you can add elevation this way:
map.getElevations({ locations : [[-12.040397656836609,-77.03373871559225], [-12.050047116528843,-77.02448169303511], [-12.044804866577001,-77.02154422636042]], callback : function (result, status){ if (status == google.maps.ElevationStatus.OK) { console.log(result, status); } } });
With GMaps.js, a static map with markers is made this way:
url = GMaps.staticMapURL({ size: [610, 350], lat: -12.043333, lng: -77.028333, markers: [ {lat: -12.043333, lng: -77.028333}, {lat: -12.045333, lng: -77.034, size: 'small'}, {lat: -12.045633, lng: -77.022, color: 'blue'} ] }); $('<img/>').attr('src', url) .appendTo('#map');
If no style attribute (like color, size or icon) is defined for a marker, the last one (or the default) will be used.
You can draw geometry overlays (which can be a polygon or a rectangle or a circle):
polygon = map.drawRectangle({ bounds: bounds, strokeColor: '#BBD8E9', strokeOpacity: 1, strokeWeight: 3, fillColor: '#BBD8E9', fillOpacity: 0.6 }); polygon = map.drawPolygon({ paths: paths, strokeColor: '#25D359', strokeOpacity: 1, strokeWeight: 3, fillColor: '#25D359', fillOpacity: 0.6 }); circle = map.drawCircle({ lat: lat, lng: lng, radius: 350, //350 meters strokeColor: '#432070', strokeOpacity: 1, strokeWeight: 3, fillColor: '#432070', fillOpacity: 0.6 });
Be careful with the settings as they are not the same for each overlay.
Using GMaps.js is as easy as:
new GMaps({ el: '#map', lat: -12.043333, lng: -77.028333 });
You must define container ID, latitude and longitude of the map's center.
Note: You also can define zoom, width and height. By default, zoom is 15. Width and height in a CSS class will replace these values.
GMaps.js allows to add Fusion Table layers:
infoWindow = new google.maps.InfoWindow({}); map.loadFromFusionTables({ query: { select: '\'Geocodable address\'', from: '1mZ53Z70NsChnBMm-qEYmSDOvLXgrreLTkQUvvg' }, suppressInfoWindows: true, events: { click: function(point){ infoWindow.setContent('You clicked here!'); infoWindow.setPosition(point.latLng); infoWindow.open(map.map); } } });
Note: You can learn more about Fusion Table layers here.
You can geocoding this way:
GMaps.geocode({ address: $('#address').val(), callback: function(results, status){ if(status=='OK'){ var latlng = results[0].geometry.location; map.setCenter(latlng.lat(), latlng.lng()); map.addMarker({ lat: latlng.lat(), lng: latlng.lng() }); } } });
You can define either address
or lat
and lng
. Also, you must define callback
, which will use results
of geocoding and status
.
You can easily make a static map using GMaps.js:
url = GMaps.staticMapURL({ size: [610, 350], lat: -12.043333, lng: -77.028333 }); $('<img/>').attr('src', url) .appendTo('#map');
You must define a size and the latitude and longitude of the map's center.
Note: You also can define zoom (by default is 15).
You can easily add or remove a layer using GMaps.js:
map.addLayer('places', { location : new google.maps.LatLng(-33.8665433,151.1956316), radius : 500, types : ['store'], search: function (results, status) { //do something with the result } });
Note: There are 3 types of function to use: search(), textSearch() and nearbySearch(). On the Google Places page you can see the options to use per search function.
With GMaps.js you can draw a route between two points this way:
map.drawRoute({ origin: [-12.044012922866312, -77.02470665341184], destination: [-12.090814532191756, -77.02271108990476], travelMode: 'driving', strokeColor: '#131540', strokeOpacity: 0.6, strokeWeight: 6 });
You must define two points (origin and destination) and color, opacity and weight of the route in the map.
Also, you can define a travelMode
: driving
, bicycling
or walking
. Default is walking
You can add polylines in GMaps.js this way:
path = [[-12.044012922866312, -77.02470665341184], [-12.05449279282314, -77.03024273281858], [-12.055122327623378, -77.03039293652341], [-12.075917129727586, -77.02764635449216], [-12.07635776902266, -77.02792530422971], [-12.076819390363665, -77.02893381481931], [-12.088527520066453, -77.0241058385925], [-12.090814532191756, -77.02271108990476]]; map.drawPolyline({ path: path, strokeColor: '#131540', strokeOpacity: 0.6, strokeWeight: 6 });
The path of the polyline is defined by an array of array of two (latitude and longitude).
You can add polygons in GMaps.js this way:
path = [[-12.040397656836609,-77.03373871559225], [-12.040248585302038,-77.03993927003302], [-12.050047116528843,-77.02448169303511], [-12.044804866577001,-77.02154422636042]]; map.drawPolygon({ paths: path, strokeColor: '#131540', strokeOpacity: 0.6, strokeWeight: 6 });
The path of the polygon is defined by an array of array of two (latitude and longitude).
NOTE: Also, you can add a GeoJSON Polygon or MultiPolygon path using useGeoJSON: true
.
With GMaps.js you can calculate the elevation for a route like this:
map.getElevations({ locations : [[-12.040397656836609,-77.03373871559225], [-12.040248585302038,-77.03993927003302], [-12.050047116528843,-77.02448169303511], [-12.044804866577001,-77.02154422636042]], path: true, callback : function (result, status){ if (status == google.maps.ElevationStatus.OK) { console.log(result, status); } } });
With GMaps.js you can use a marker clusterer to group large amount of markers:
map = new GMaps({ div: '#map', lat: -12.043333, lng: -77.028333, markerClusterer: function(map) { return new MarkerClusterer(map); } });
You can use MarkerClusterer or MarkerClustererPlus. If you want to use a custom marker clustering library, you have to define a addMarker
method.
Note: Read more about MarkerClusterer and MarkerClustererPlus here.
You can easily manage a map style using GMaps.js:
var styles = [ { featureType: "road", elementType: "geometry", stylers: [ { lightness: 100 }, { visibility: "simplified" } ] }, { ... } ]; map.addStyle({ styledMapName:"Styled Map", styles: styles, mapTypeId: "map_style" }); map.setStyle("map_style");
Note: You can choose different styles and associate the styled map with the MapTypeId and set it to display.
You can travel a route, step by step, this way:
map.travelRoute({ origin: [-12.044012922866312, -77.02470665341184], destination: [-12.090814532191756, -77.02271108990476], travelMode: 'driving', step: function(e){ $('#instructions').append('<li>'+e.instructions+'</li>'); $('#instructions li:eq('+e.step_number+')').delay(450*e.step_number).fadeIn(200, function(){ map.drawPolyline({ path: e.path, strokeColor: '#131540', strokeOpacity: 0.6, strokeWeight: 6 }); }); } });
Same as drawRoute
, you must define an origin, destination and travelMode
. Also, you must define the function that GMaps will call every step in the route.
You can define many map types from external map services, like OpenStreetMap:
map.addMapType("osm", { getTileUrl: function(coord, zoom) { return "http://tile.openstreetmap.org/" + zoom + "/" + coord.x + "/" + coord.y + ".png"; }, tileSize: new google.maps.Size(256, 256), name: "OpenStreetMap", maxZoom: 18 });
You must define a function called getTileUrl
, which returns a tile URL according the coordenates in the map.
jasmine.undefined
instead of undefined
, since undefined
is just
* a plain old variable and may be redefined by somebody else.
*
* @private
*/
jasmine.undefined = jasmine.___undefined___;
/**
* Show diagnostic messages in the console if set to true
*
*/
jasmine.VERBOSE = false;
/**
* Default interval in milliseconds for event loop yields (e.g. to allow network activity or to refresh the screen with the HTML-based runner). Small values here may result in slow test running. Zero means no updates until all tests have completed.
*
*/
jasmine.DEFAULT_UPDATE_INTERVAL = 250;
/**
* Maximum levels of nesting that will be included when an object is pretty-printed
*/
jasmine.MAX_PRETTY_PRINT_DEPTH = 40;
/**
* Default timeout interval in milliseconds for waitsFor() blocks.
*/
jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000;
/**
* By default exceptions thrown in the context of a test are caught by jasmine so that it can run the remaining tests in the suite.
* Set to false to let the exception bubble up in the browser.
*
*/
jasmine.CATCH_EXCEPTIONS = true;
jasmine.getGlobal = function() {
function getGlobal() {
return this;
}
return getGlobal();
};
/**
* Allows for bound functions to be compared. Internal use only.
*
* @ignore
* @private
* @param base {Object} bound 'this' for the function
* @param name {Function} function to find
*/
jasmine.bindOriginal_ = function(base, name) {
var original = base[name];
if (original.apply) {
return function() {
return original.apply(base, arguments);
};
} else {
// IE support
return jasmine.getGlobal()[name];
}
};
jasmine.setTimeout = jasmine.bindOriginal_(jasmine.getGlobal(), 'setTimeout');
jasmine.clearTimeout = jasmine.bindOriginal_(jasmine.getGlobal(), 'clearTimeout');
jasmine.setInterval = jasmine.bindOriginal_(jasmine.getGlobal(), 'setInterval');
jasmine.clearInterval = jasmine.bindOriginal_(jasmine.getGlobal(), 'clearInterval');
jasmine.MessageResult = function(values) {
this.type = 'log';
this.values = values;
this.trace = new Error(); // todo: test better
};
jasmine.MessageResult.prototype.toString = function() {
var text = "";
for (var i = 0; i < this.values.length; i++) {
if (i > 0) text += " ";
if (jasmine.isString_(this.values[i])) {
text += this.values[i];
} else {
text += jasmine.pp(this.values[i]);
}
}
return text;
};
jasmine.ExpectationResult = function(params) {
this.type = 'expect';
this.matcherName = params.matcherName;
this.passed_ = params.passed;
this.expected = params.expected;
this.actual = params.actual;
this.message = this.passed_ ? 'Passed.' : params.message;
var trace = (params.trace || new Error(this.message));
this.trace = this.passed_ ? '' : trace;
};
jasmine.ExpectationResult.prototype.toString = function () {
return this.message;
};
jasmine.ExpectationResult.prototype.passed = function () {
return this.passed_;
};
/**
* Getter for the Jasmine environment. Ensures one gets created
*/
jasmine.getEnv = function() {
var env = jasmine.currentEnv_ = jasmine.currentEnv_ || new jasmine.Env();
return env;
};
/**
* @ignore
* @private
* @param value
* @returns {Boolean}
*/
jasmine.isArray_ = function(value) {
return jasmine.isA_("Array", value);
};
/**
* @ignore
* @private
* @param value
* @returns {Boolean}
*/
jasmine.isString_ = function(value) {
return jasmine.isA_("String", value);
};
/**
* @ignore
* @private
* @param value
* @returns {Boolean}
*/
jasmine.isNumber_ = function(value) {
return jasmine.isA_("Number", value);
};
/**
* @ignore
* @private
* @param {String} typeName
* @param value
* @returns {Boolean}
*/
jasmine.isA_ = function(typeName, value) {
return Object.prototype.toString.apply(value) === '[object ' + typeName + ']';
};
/**
* Pretty printer for expecations. Takes any object and turns it into a human-readable string.
*
* @param value {Object} an object to be outputted
* @returns {String}
*/
jasmine.pp = function(value) {
var stringPrettyPrinter = new jasmine.StringPrettyPrinter();
stringPrettyPrinter.format(value);
return stringPrettyPrinter.string;
};
/**
* Returns true if the object is a DOM Node.
*
* @param {Object} obj object to check
* @returns {Boolean}
*/
jasmine.isDomNode = function(obj) {
return obj.nodeType > 0;
};
/**
* Returns a matchable 'generic' object of the class type. For use in expecations of type when values don't matter.
*
* @example
* // don't care about which function is passed in, as long as it's a function
* expect(mySpy).toHaveBeenCalledWith(jasmine.any(Function));
*
* @param {Class} clazz
* @returns matchable object of the type clazz
*/
jasmine.any = function(clazz) {
return new jasmine.Matchers.Any(clazz);
};
/**
* Returns a matchable subset of a JSON object. For use in expectations when you don't care about all of the
* attributes on the object.
*
* @example
* // don't care about any other attributes than foo.
* expect(mySpy).toHaveBeenCalledWith(jasmine.objectContaining({foo: "bar"});
*
* @param sample {Object} sample
* @returns matchable object for the sample
*/
jasmine.objectContaining = function (sample) {
return new jasmine.Matchers.ObjectContaining(sample);
};
/**
* Jasmine Spies are test doubles that can act as stubs, spies, fakes or when used in an expecation, mocks.
*
* Spies should be created in test setup, before expectations. They can then be checked, using the standard Jasmine
* expectation syntax. Spies can be checked if they were called or not and what the calling params were.
*
* A Spy has the following fields: wasCalled, callCount, mostRecentCall, and argsForCall (see docs).
*
* Spies are torn down at the end of every spec.
*
* Note: Do not call new jasmine.Spy() directly - a spy must be created using spyOn, jasmine.createSpy or jasmine.createSpyObj.
*
* @example
* // a stub
* var myStub = jasmine.createSpy('myStub'); // can be used anywhere
*
* // spy example
* var foo = {
* not: function(bool) { return !bool; }
* }
*
* // actual foo.not will not be called, execution stops
* spyOn(foo, 'not');
// foo.not spied upon, execution will continue to implementation
* spyOn(foo, 'not').andCallThrough();
*
* // fake example
* var foo = {
* not: function(bool) { return !bool; }
* }
*
* // foo.not(val) will return val
* spyOn(foo, 'not').andCallFake(function(value) {return value;});
*
* // mock example
* foo.not(7 == 7);
* expect(foo.not).toHaveBeenCalled();
* expect(foo.not).toHaveBeenCalledWith(true);
*
* @constructor
* @see spyOn, jasmine.createSpy, jasmine.createSpyObj
* @param {String} name
*/
jasmine.Spy = function(name) {
/**
* The name of the spy, if provided.
*/
this.identity = name || 'unknown';
/**
* Is this Object a spy?
*/
this.isSpy = true;
/**
* The actual function this spy stubs.
*/
this.plan = function() {
};
/**
* Tracking of the most recent call to the spy.
* @example
* var mySpy = jasmine.createSpy('foo');
* mySpy(1, 2);
* mySpy.mostRecentCall.args = [1, 2];
*/
this.mostRecentCall = {};
/**
* Holds arguments for each call to the spy, indexed by call count
* @example
* var mySpy = jasmine.createSpy('foo');
* mySpy(1, 2);
* mySpy(7, 8);
* mySpy.mostRecentCall.args = [7, 8];
* mySpy.argsForCall[0] = [1, 2];
* mySpy.argsForCall[1] = [7, 8];
*/
this.argsForCall = [];
this.calls = [];
};
/**
* Tells a spy to call through to the actual implemenatation.
*
* @example
* var foo = {
* bar: function() { // do some stuff }
* }
*
* // defining a spy on an existing property: foo.bar
* spyOn(foo, 'bar').andCallThrough();
*/
jasmine.Spy.prototype.andCallThrough = function() {
this.plan = this.originalValue;
return this;
};
/**
* For setting the return value of a spy.
*
* @example
* // defining a spy from scratch: foo() returns 'baz'
* var foo = jasmine.createSpy('spy on foo').andReturn('baz');
*
* // defining a spy on an existing property: foo.bar() returns 'baz'
* spyOn(foo, 'bar').andReturn('baz');
*
* @param {Object} value
*/
jasmine.Spy.prototype.andReturn = function(value) {
this.plan = function() {
return value;
};
return this;
};
/**
* For throwing an exception when a spy is called.
*
* @example
* // defining a spy from scratch: foo() throws an exception w/ message 'ouch'
* var foo = jasmine.createSpy('spy on foo').andThrow('baz');
*
* // defining a spy on an existing property: foo.bar() throws an exception w/ message 'ouch'
* spyOn(foo, 'bar').andThrow('baz');
*
* @param {String} exceptionMsg
*/
jasmine.Spy.prototype.andThrow = function(exceptionMsg) {
this.plan = function() {
throw exceptionMsg;
};
return this;
};
/**
* Calls an alternate implementation when a spy is called.
*
* @example
* var baz = function() {
* // do some stuff, return something
* }
* // defining a spy from scratch: foo() calls the function baz
* var foo = jasmine.createSpy('spy on foo').andCall(baz);
*
* // defining a spy on an existing property: foo.bar() calls an anonymnous function
* spyOn(foo, 'bar').andCall(function() { return 'baz';} );
*
* @param {Function} fakeFunc
*/
jasmine.Spy.prototype.andCallFake = function(fakeFunc) {
this.plan = fakeFunc;
return this;
};
/**
* Resets all of a spy's the tracking variables so that it can be used again.
*
* @example
* spyOn(foo, 'bar');
*
* foo.bar();
*
* expect(foo.bar.callCount).toEqual(1);
*
* foo.bar.reset();
*
* expect(foo.bar.callCount).toEqual(0);
*/
jasmine.Spy.prototype.reset = function() {
this.wasCalled = false;
this.callCount = 0;
this.argsForCall = [];
this.calls = [];
this.mostRecentCall = {};
};
jasmine.createSpy = function(name) {
var spyObj = function() {
spyObj.wasCalled = true;
spyObj.callCount++;
var args = jasmine.util.argsToArray(arguments);
spyObj.mostRecentCall.object = this;
spyObj.mostRecentCall.args = args;
spyObj.argsForCall.push(args);
spyObj.calls.push({object: this, args: args});
return spyObj.plan.apply(this, arguments);
};
var spy = new jasmine.Spy(name);
for (var prop in spy) {
spyObj[prop] = spy[prop];
}
spyObj.reset();
return spyObj;
};
/**
* Determines whether an object is a spy.
*
* @param {jasmine.Spy|Object} putativeSpy
* @returns {Boolean}
*/
jasmine.isSpy = function(putativeSpy) {
return putativeSpy && putativeSpy.isSpy;
};
/**
* Creates a more complicated spy: an Object that has every property a function that is a spy. Used for stubbing something
* large in one call.
*
* @param {String} baseName name of spy class
* @param {Array} methodNames array of names of methods to make spies
*/
jasmine.createSpyObj = function(baseName, methodNames) {
if (!jasmine.isArray_(methodNames) || methodNames.length === 0) {
throw new Error('createSpyObj requires a non-empty array of method names to create spies for');
}
var obj = {};
for (var i = 0; i < methodNames.length; i++) {
obj[methodNames[i]] = jasmine.createSpy(baseName + '.' + methodNames[i]);
}
return obj;
};
/**
* All parameters are pretty-printed and concatenated together, then written to the current spec's output.
*
* Be careful not to leave calls to jasmine.log
in production code.
*/
jasmine.log = function() {
var spec = jasmine.getEnv().currentSpec;
spec.log.apply(spec, arguments);
};
/**
* Function that installs a spy on an existing object's method name. Used within a Spec to create a spy.
*
* @example
* // spy example
* var foo = {
* not: function(bool) { return !bool; }
* }
* spyOn(foo, 'not'); // actual foo.not will not be called, execution stops
*
* @see jasmine.createSpy
* @param obj
* @param methodName
* @return {jasmine.Spy} a Jasmine spy that can be chained with all spy methods
*/
var spyOn = function(obj, methodName) {
return jasmine.getEnv().currentSpec.spyOn(obj, methodName);
};
if (isCommonJS) exports.spyOn = spyOn;
/**
* Creates a Jasmine spec that will be added to the current suite.
*
* // TODO: pending tests
*
* @example
* it('should be true', function() {
* expect(true).toEqual(true);
* });
*
* @param {String} desc description of this specification
* @param {Function} func defines the preconditions and expectations of the spec
*/
var it = function(desc, func) {
return jasmine.getEnv().it(desc, func);
};
if (isCommonJS) exports.it = it;
/**
* Creates a disabled Jasmine spec.
*
* A convenience method that allows existing specs to be disabled temporarily during development.
*
* @param {String} desc description of this specification
* @param {Function} func defines the preconditions and expectations of the spec
*/
var xit = function(desc, func) {
return jasmine.getEnv().xit(desc, func);
};
if (isCommonJS) exports.xit = xit;
/**
* Starts a chain for a Jasmine expectation.
*
* It is passed an Object that is the actual value and should chain to one of the many
* jasmine.Matchers functions.
*
* @param {Object} actual Actual value to test against and expected value
* @return {jasmine.Matchers}
*/
var expect = function(actual) {
return jasmine.getEnv().currentSpec.expect(actual);
};
if (isCommonJS) exports.expect = expect;
/**
* Defines part of a jasmine spec. Used in cominbination with waits or waitsFor in asynchrnous specs.
*
* @param {Function} func Function that defines part of a jasmine spec.
*/
var runs = function(func) {
jasmine.getEnv().currentSpec.runs(func);
};
if (isCommonJS) exports.runs = runs;
/**
* Waits a fixed time period before moving to the next block.
*
* @deprecated Use waitsFor() instead
* @param {Number} timeout milliseconds to wait
*/
var waits = function(timeout) {
jasmine.getEnv().currentSpec.waits(timeout);
};
if (isCommonJS) exports.waits = waits;
/**
* Waits for the latchFunction to return true before proceeding to the next block.
*
* @param {Function} latchFunction
* @param {String} optional_timeoutMessage
* @param {Number} optional_timeout
*/
var waitsFor = function(latchFunction, optional_timeoutMessage, optional_timeout) {
jasmine.getEnv().currentSpec.waitsFor.apply(jasmine.getEnv().currentSpec, arguments);
};
if (isCommonJS) exports.waitsFor = waitsFor;
/**
* A function that is called before each spec in a suite.
*
* Used for spec setup, including validating assumptions.
*
* @param {Function} beforeEachFunction
*/
var beforeEach = function(beforeEachFunction) {
jasmine.getEnv().beforeEach(beforeEachFunction);
};
if (isCommonJS) exports.beforeEach = beforeEach;
/**
* A function that is called after each spec in a suite.
*
* Used for restoring any state that is hijacked during spec execution.
*
* @param {Function} afterEachFunction
*/
var afterEach = function(afterEachFunction) {
jasmine.getEnv().afterEach(afterEachFunction);
};
if (isCommonJS) exports.afterEach = afterEach;
/**
* Defines a suite of specifications.
*
* Stores the description and all defined specs in the Jasmine environment as one suite of specs. Variables declared
* are accessible by calls to beforeEach, it, and afterEach. Describe blocks can be nested, allowing for specialization
* of setup in some tests.
*
* @example
* // TODO: a simple suite
*
* // TODO: a simple suite with a nested describe block
*
* @param {String} description A string, usually the class under test.
* @param {Function} specDefinitions function that defines several specs.
*/
var describe = function(description, specDefinitions) {
return jasmine.getEnv().describe(description, specDefinitions);
};
if (isCommonJS) exports.describe = describe;
/**
* Disables a suite of specifications. Used to disable some suites in a file, or files, temporarily during development.
*
* @param {String} description A string, usually the class under test.
* @param {Function} specDefinitions function that defines several specs.
*/
var xdescribe = function(description, specDefinitions) {
return jasmine.getEnv().xdescribe(description, specDefinitions);
};
if (isCommonJS) exports.xdescribe = xdescribe;
// Provide the XMLHttpRequest class for IE 5.x-6.x:
jasmine.XmlHttpRequest = (typeof XMLHttpRequest == "undefined") ? function() {
function tryIt(f) {
try {
return f();
} catch(e) {
}
return null;
}
var xhr = tryIt(function() {
return new ActiveXObject("Msxml2.XMLHTTP.6.0");
}) ||
tryIt(function() {
return new ActiveXObject("Msxml2.XMLHTTP.3.0");
}) ||
tryIt(function() {
return new ActiveXObject("Msxml2.XMLHTTP");
}) ||
tryIt(function() {
return new ActiveXObject("Microsoft.XMLHTTP");
});
if (!xhr) throw new Error("This browser does not support XMLHttpRequest.");
return xhr;
} : XMLHttpRequest;
/**
* @namespace
*/
jasmine.util = {};
/**
* Declare that a child class inherit it's prototype from the parent class.
*
* @private
* @param {Function} childClass
* @param {Function} parentClass
*/
jasmine.util.inherit = function(childClass, parentClass) {
/**
* @private
*/
var subclass = function() {
};
subclass.prototype = parentClass.prototype;
childClass.prototype = new subclass();
};
jasmine.util.formatException = function(e) {
var lineNumber;
if (e.line) {
lineNumber = e.line;
}
else if (e.lineNumber) {
lineNumber = e.lineNumber;
}
var file;
if (e.sourceURL) {
file = e.sourceURL;
}
else if (e.fileName) {
file = e.fileName;
}
var message = (e.name && e.message) ? (e.name + ': ' + e.message) : e.toString();
if (file && lineNumber) {
message += ' in ' + file + ' (line ' + lineNumber + ')';
}
return message;
};
jasmine.util.htmlEscape = function(str) {
if (!str) return str;
return str.replace(/&/g, '&')
.replace(//g, '>');
};
jasmine.util.argsToArray = function(args) {
var arrayOfArgs = [];
for (var i = 0; i < args.length; i++) arrayOfArgs.push(args[i]);
return arrayOfArgs;
};
jasmine.util.extend = function(destination, source) {
for (var property in source) destination[property] = source[property];
return destination;
};
/**
* Environment for Jasmine
*
* @constructor
*/
jasmine.Env = function() {
this.currentSpec = null;
this.currentSuite = null;
this.currentRunner_ = new jasmine.Runner(this);
this.reporter = new jasmine.MultiReporter();
this.updateInterval = jasmine.DEFAULT_UPDATE_INTERVAL;
this.defaultTimeoutInterval = jasmine.DEFAULT_TIMEOUT_INTERVAL;
this.lastUpdate = 0;
this.specFilter = function() {
return true;
};
this.nextSpecId_ = 0;
this.nextSuiteId_ = 0;
this.equalityTesters_ = [];
// wrap matchers
this.matchersClass = function() {
jasmine.Matchers.apply(this, arguments);
};
jasmine.util.inherit(this.matchersClass, jasmine.Matchers);
jasmine.Matchers.wrapInto_(jasmine.Matchers.prototype, this.matchersClass);
};
jasmine.Env.prototype.setTimeout = jasmine.setTimeout;
jasmine.Env.prototype.clearTimeout = jasmine.clearTimeout;
jasmine.Env.prototype.setInterval = jasmine.setInterval;
jasmine.Env.prototype.clearInterval = jasmine.clearInterval;
/**
* @returns an object containing jasmine version build info, if set.
*/
jasmine.Env.prototype.version = function () {
if (jasmine.version_) {
return jasmine.version_;
} else {
throw new Error('Version not set');
}
};
/**
* @returns string containing jasmine version build info, if set.
*/
jasmine.Env.prototype.versionString = function() {
if (!jasmine.version_) {
return "version unknown";
}
var version = this.version();
var versionString = version.major + "." + version.minor + "." + version.build;
if (version.release_candidate) {
versionString += ".rc" + version.release_candidate;
}
versionString += " revision " + version.revision;
return versionString;
};
/**
* @returns a sequential integer starting at 0
*/
jasmine.Env.prototype.nextSpecId = function () {
return this.nextSpecId_++;
};
/**
* @returns a sequential integer starting at 0
*/
jasmine.Env.prototype.nextSuiteId = function () {
return this.nextSuiteId_++;
};
/**
* Register a reporter to receive status updates from Jasmine.
* @param {jasmine.Reporter} reporter An object which will receive status updates.
*/
jasmine.Env.prototype.addReporter = function(reporter) {
this.reporter.addReporter(reporter);
};
jasmine.Env.prototype.execute = function() {
this.currentRunner_.execute();
};
jasmine.Env.prototype.describe = function(description, specDefinitions) {
var suite = new jasmine.Suite(this, description, specDefinitions, this.currentSuite);
var parentSuite = this.currentSuite;
if (parentSuite) {
parentSuite.add(suite);
} else {
this.currentRunner_.add(suite);
}
this.currentSuite = suite;
var declarationError = null;
try {
specDefinitions.call(suite);
} catch(e) {
declarationError = e;
}
if (declarationError) {
this.it("encountered a declaration exception", function() {
throw declarationError;
});
}
this.currentSuite = parentSuite;
return suite;
};
jasmine.Env.prototype.beforeEach = function(beforeEachFunction) {
if (this.currentSuite) {
this.currentSuite.beforeEach(beforeEachFunction);
} else {
this.currentRunner_.beforeEach(beforeEachFunction);
}
};
jasmine.Env.prototype.currentRunner = function () {
return this.currentRunner_;
};
jasmine.Env.prototype.afterEach = function(afterEachFunction) {
if (this.currentSuite) {
this.currentSuite.afterEach(afterEachFunction);
} else {
this.currentRunner_.afterEach(afterEachFunction);
}
};
jasmine.Env.prototype.xdescribe = function(desc, specDefinitions) {
return {
execute: function() {
}
};
};
jasmine.Env.prototype.it = function(description, func) {
var spec = new jasmine.Spec(this, this.currentSuite, description);
this.currentSuite.add(spec);
this.currentSpec = spec;
if (func) {
spec.runs(func);
}
return spec;
};
jasmine.Env.prototype.xit = function(desc, func) {
return {
id: this.nextSpecId(),
runs: function() {
}
};
};
jasmine.Env.prototype.compareRegExps_ = function(a, b, mismatchKeys, mismatchValues) {
if (a.source != b.source)
mismatchValues.push("expected pattern /" + b.source + "/ is not equal to the pattern /" + a.source + "/");
if (a.ignoreCase != b.ignoreCase)
mismatchValues.push("expected modifier i was" + (b.ignoreCase ? " " : " not ") + "set and does not equal the origin modifier");
if (a.global != b.global)
mismatchValues.push("expected modifier g was" + (b.global ? " " : " not ") + "set and does not equal the origin modifier");
if (a.multiline != b.multiline)
mismatchValues.push("expected modifier m was" + (b.multiline ? " " : " not ") + "set and does not equal the origin modifier");
if (a.sticky != b.sticky)
mismatchValues.push("expected modifier y was" + (b.sticky ? " " : " not ") + "set and does not equal the origin modifier");
return (mismatchValues.length === 0);
};
jasmine.Env.prototype.compareObjects_ = function(a, b, mismatchKeys, mismatchValues) {
if (a.__Jasmine_been_here_before__ === b && b.__Jasmine_been_here_before__ === a) {
return true;
}
a.__Jasmine_been_here_before__ = b;
b.__Jasmine_been_here_before__ = a;
var hasKey = function(obj, keyName) {
return obj !== null && obj[keyName] !== jasmine.undefined;
};
for (var property in b) {
if (!hasKey(a, property) && hasKey(b, property)) {
mismatchKeys.push("expected has key '" + property + "', but missing from actual.");
}
}
for (property in a) {
if (!hasKey(b, property) && hasKey(a, property)) {
mismatchKeys.push("expected missing key '" + property + "', but present in actual.");
}
}
for (property in b) {
if (property == '__Jasmine_been_here_before__') continue;
if (!this.equals_(a[property], b[property], mismatchKeys, mismatchValues)) {
mismatchValues.push("'" + property + "' was '" + (b[property] ? jasmine.util.htmlEscape(b[property].toString()) : b[property]) + "' in expected, but was '" + (a[property] ? jasmine.util.htmlEscape(a[property].toString()) : a[property]) + "' in actual.");
}
}
if (jasmine.isArray_(a) && jasmine.isArray_(b) && a.length != b.length) {
mismatchValues.push("arrays were not the same length");
}
delete a.__Jasmine_been_here_before__;
delete b.__Jasmine_been_here_before__;
return (mismatchKeys.length === 0 && mismatchValues.length === 0);
};
jasmine.Env.prototype.equals_ = function(a, b, mismatchKeys, mismatchValues) {
mismatchKeys = mismatchKeys || [];
mismatchValues = mismatchValues || [];
for (var i = 0; i < this.equalityTesters_.length; i++) {
var equalityTester = this.equalityTesters_[i];
var result = equalityTester(a, b, this, mismatchKeys, mismatchValues);
if (result !== jasmine.undefined) return result;
}
if (a === b) return true;
if (a === jasmine.undefined || a === null || b === jasmine.undefined || b === null) {
return (a == jasmine.undefined && b == jasmine.undefined);
}
if (jasmine.isDomNode(a) && jasmine.isDomNode(b)) {
return a === b;
}
if (a instanceof Date && b instanceof Date) {
return a.getTime() == b.getTime();
}
if (a.jasmineMatches) {
return a.jasmineMatches(b);
}
if (b.jasmineMatches) {
return b.jasmineMatches(a);
}
if (a instanceof jasmine.Matchers.ObjectContaining) {
return a.matches(b);
}
if (b instanceof jasmine.Matchers.ObjectContaining) {
return b.matches(a);
}
if (jasmine.isString_(a) && jasmine.isString_(b)) {
return (a == b);
}
if (jasmine.isNumber_(a) && jasmine.isNumber_(b)) {
return (a == b);
}
if (a instanceof RegExp && b instanceof RegExp) {
return this.compareRegExps_(a, b, mismatchKeys, mismatchValues);
}
if (typeof a === "object" && typeof b === "object") {
return this.compareObjects_(a, b, mismatchKeys, mismatchValues);
}
//Straight check
return (a === b);
};
jasmine.Env.prototype.contains_ = function(haystack, needle) {
if (jasmine.isArray_(haystack)) {
for (var i = 0; i < haystack.length; i++) {
if (this.equals_(haystack[i], needle)) return true;
}
return false;
}
return haystack.indexOf(needle) >= 0;
};
jasmine.Env.prototype.addEqualityTester = function(equalityTester) {
this.equalityTesters_.push(equalityTester);
};
/** No-op base class for Jasmine reporters.
*
* @constructor
*/
jasmine.Reporter = function() {
};
//noinspection JSUnusedLocalSymbols
jasmine.Reporter.prototype.reportRunnerStarting = function(runner) {
};
//noinspection JSUnusedLocalSymbols
jasmine.Reporter.prototype.reportRunnerResults = function(runner) {
};
//noinspection JSUnusedLocalSymbols
jasmine.Reporter.prototype.reportSuiteResults = function(suite) {
};
//noinspection JSUnusedLocalSymbols
jasmine.Reporter.prototype.reportSpecStarting = function(spec) {
};
//noinspection JSUnusedLocalSymbols
jasmine.Reporter.prototype.reportSpecResults = function(spec) {
};
//noinspection JSUnusedLocalSymbols
jasmine.Reporter.prototype.log = function(str) {
};
/**
* Blocks are functions with executable code that make up a spec.
*
* @constructor
* @param {jasmine.Env} env
* @param {Function} func
* @param {jasmine.Spec} spec
*/
jasmine.Block = function(env, func, spec) {
this.env = env;
this.func = func;
this.spec = spec;
};
jasmine.Block.prototype.execute = function(onComplete) {
if (!jasmine.CATCH_EXCEPTIONS) {
this.func.apply(this.spec);
}
else {
try {
this.func.apply(this.spec);
} catch (e) {
this.spec.fail(e);
}
}
onComplete();
};
/** JavaScript API reporter.
*
* @constructor
*/
jasmine.JsApiReporter = function() {
this.started = false;
this.finished = false;
this.suites_ = [];
this.results_ = {};
};
jasmine.JsApiReporter.prototype.reportRunnerStarting = function(runner) {
this.started = true;
var suites = runner.topLevelSuites();
for (var i = 0; i < suites.length; i++) {
var suite = suites[i];
this.suites_.push(this.summarize_(suite));
}
};
jasmine.JsApiReporter.prototype.suites = function() {
return this.suites_;
};
jasmine.JsApiReporter.prototype.summarize_ = function(suiteOrSpec) {
var isSuite = suiteOrSpec instanceof jasmine.Suite;
var summary = {
id: suiteOrSpec.id,
name: suiteOrSpec.description,
type: isSuite ? 'suite' : 'spec',
children: []
};
if (isSuite) {
var children = suiteOrSpec.children();
for (var i = 0; i < children.length; i++) {
summary.children.push(this.summarize_(children[i]));
}
}
return summary;
};
jasmine.JsApiReporter.prototype.results = function() {
return this.results_;
};
jasmine.JsApiReporter.prototype.resultsForSpec = function(specId) {
return this.results_[specId];
};
//noinspection JSUnusedLocalSymbols
jasmine.JsApiReporter.prototype.reportRunnerResults = function(runner) {
this.finished = true;
};
//noinspection JSUnusedLocalSymbols
jasmine.JsApiReporter.prototype.reportSuiteResults = function(suite) {
};
//noinspection JSUnusedLocalSymbols
jasmine.JsApiReporter.prototype.reportSpecResults = function(spec) {
this.results_[spec.id] = {
messages: spec.results().getItems(),
result: spec.results().failedCount > 0 ? "failed" : "passed"
};
};
//noinspection JSUnusedLocalSymbols
jasmine.JsApiReporter.prototype.log = function(str) {
};
jasmine.JsApiReporter.prototype.resultsForSpecs = function(specIds){
var results = {};
for (var i = 0; i < specIds.length; i++) {
var specId = specIds[i];
results[specId] = this.summarizeResult_(this.results_[specId]);
}
return results;
};
jasmine.JsApiReporter.prototype.summarizeResult_ = function(result){
var summaryMessages = [];
var messagesLength = result.messages.length;
for (var messageIndex = 0; messageIndex < messagesLength; messageIndex++) {
var resultMessage = result.messages[messageIndex];
summaryMessages.push({
text: resultMessage.type == 'log' ? resultMessage.toString() : jasmine.undefined,
passed: resultMessage.passed ? resultMessage.passed() : true,
type: resultMessage.type,
message: resultMessage.message,
trace: {
stack: resultMessage.passed && !resultMessage.passed() ? resultMessage.trace.stack : jasmine.undefined
}
});
}
return {
result : result.result,
messages : summaryMessages
};
};
/**
* @constructor
* @param {jasmine.Env} env
* @param actual
* @param {jasmine.Spec} spec
*/
jasmine.Matchers = function(env, actual, spec, opt_isNot) {
this.env = env;
this.actual = actual;
this.spec = spec;
this.isNot = opt_isNot || false;
this.reportWasCalled_ = false;
};
// todo: @deprecated as of Jasmine 0.11, remove soon [xw]
jasmine.Matchers.pp = function(str) {
throw new Error("jasmine.Matchers.pp() is no longer supported, please use jasmine.pp() instead!");
};
// todo: @deprecated Deprecated as of Jasmine 0.10. Rewrite your custom matchers to return true or false. [xw]
jasmine.Matchers.prototype.report = function(result, failing_message, details) {
throw new Error("As of jasmine 0.11, custom matchers must be implemented differently -- please see jasmine docs");
};
jasmine.Matchers.wrapInto_ = function(prototype, matchersClass) {
for (var methodName in prototype) {
if (methodName == 'report') continue;
var orig = prototype[methodName];
matchersClass.prototype[methodName] = jasmine.Matchers.matcherFn_(methodName, orig);
}
};
jasmine.Matchers.matcherFn_ = function(matcherName, matcherFunction) {
return function() {
var matcherArgs = jasmine.util.argsToArray(arguments);
var result = matcherFunction.apply(this, arguments);
if (this.isNot) {
result = !result;
}
if (this.reportWasCalled_) return result;
var message;
if (!result) {
if (this.message) {
message = this.message.apply(this, arguments);
if (jasmine.isArray_(message)) {
message = message[this.isNot ? 1 : 0];
}
} else {
var englishyPredicate = matcherName.replace(/[A-Z]/g, function(s) { return ' ' + s.toLowerCase(); });
message = "Expected " + jasmine.pp(this.actual) + (this.isNot ? " not " : " ") + englishyPredicate;
if (matcherArgs.length > 0) {
for (var i = 0; i < matcherArgs.length; i++) {
if (i > 0) message += ",";
message += " " + jasmine.pp(matcherArgs[i]);
}
}
message += ".";
}
}
var expectationResult = new jasmine.ExpectationResult({
matcherName: matcherName,
passed: result,
expected: matcherArgs.length > 1 ? matcherArgs : matcherArgs[0],
actual: this.actual,
message: message
});
this.spec.addMatcherResult(expectationResult);
return jasmine.undefined;
};
};
/**
* toBe: compares the actual to the expected using ===
* @param expected
*/
jasmine.Matchers.prototype.toBe = function(expected) {
return this.actual === expected;
};
/**
* toNotBe: compares the actual to the expected using !==
* @param expected
* @deprecated as of 1.0. Use not.toBe() instead.
*/
jasmine.Matchers.prototype.toNotBe = function(expected) {
return this.actual !== expected;
};
/**
* toEqual: compares the actual to the expected using common sense equality. Handles Objects, Arrays, etc.
*
* @param expected
*/
jasmine.Matchers.prototype.toEqual = function(expected) {
return this.env.equals_(this.actual, expected);
};
/**
* toNotEqual: compares the actual to the expected using the ! of jasmine.Matchers.toEqual
* @param expected
* @deprecated as of 1.0. Use not.toEqual() instead.
*/
jasmine.Matchers.prototype.toNotEqual = function(expected) {
return !this.env.equals_(this.actual, expected);
};
/**
* Matcher that compares the actual to the expected using a regular expression. Constructs a RegExp, so takes
* a pattern or a String.
*
* @param expected
*/
jasmine.Matchers.prototype.toMatch = function(expected) {
return new RegExp(expected).test(this.actual);
};
/**
* Matcher that compares the actual to the expected using the boolean inverse of jasmine.Matchers.toMatch
* @param expected
* @deprecated as of 1.0. Use not.toMatch() instead.
*/
jasmine.Matchers.prototype.toNotMatch = function(expected) {
return !(new RegExp(expected).test(this.actual));
};
/**
* Matcher that compares the actual to jasmine.undefined.
*/
jasmine.Matchers.prototype.toBeDefined = function() {
return (this.actual !== jasmine.undefined);
};
/**
* Matcher that compares the actual to jasmine.undefined.
*/
jasmine.Matchers.prototype.toBeUndefined = function() {
return (this.actual === jasmine.undefined);
};
/**
* Matcher that compares the actual to null.
*/
jasmine.Matchers.prototype.toBeNull = function() {
return (this.actual === null);
};
/**
* Matcher that compares the actual to NaN.
*/
jasmine.Matchers.prototype.toBeNaN = function() {
this.message = function() {
return [ "Expected " + jasmine.pp(this.actual) + " to be NaN." ];
};
return (this.actual !== this.actual);
};
/**
* Matcher that boolean not-nots the actual.
*/
jasmine.Matchers.prototype.toBeTruthy = function() {
return !!this.actual;
};
/**
* Matcher that boolean nots the actual.
*/
jasmine.Matchers.prototype.toBeFalsy = function() {
return !this.actual;
};
/**
* Matcher that checks to see if the actual, a Jasmine spy, was called.
*/
jasmine.Matchers.prototype.toHaveBeenCalled = function() {
if (arguments.length > 0) {
throw new Error('toHaveBeenCalled does not take arguments, use toHaveBeenCalledWith');
}
if (!jasmine.isSpy(this.actual)) {
throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.');
}
this.message = function() {
return [
"Expected spy " + this.actual.identity + " to have been called.",
"Expected spy " + this.actual.identity + " not to have been called."
];
};
return this.actual.wasCalled;
};
/** @deprecated Use expect(xxx).toHaveBeenCalled() instead */
jasmine.Matchers.prototype.wasCalled = jasmine.Matchers.prototype.toHaveBeenCalled;
/**
* Matcher that checks to see if the actual, a Jasmine spy, was not called.
*
* @deprecated Use expect(xxx).not.toHaveBeenCalled() instead
*/
jasmine.Matchers.prototype.wasNotCalled = function() {
if (arguments.length > 0) {
throw new Error('wasNotCalled does not take arguments');
}
if (!jasmine.isSpy(this.actual)) {
throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.');
}
this.message = function() {
return [
"Expected spy " + this.actual.identity + " to not have been called.",
"Expected spy " + this.actual.identity + " to have been called."
];
};
return !this.actual.wasCalled;
};
/**
* Matcher that checks to see if the actual, a Jasmine spy, was called with a set of parameters.
*
* @example
*
*/
jasmine.Matchers.prototype.toHaveBeenCalledWith = function() {
var expectedArgs = jasmine.util.argsToArray(arguments);
if (!jasmine.isSpy(this.actual)) {
throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.');
}
this.message = function() {
var invertedMessage = "Expected spy " + this.actual.identity + " not to have been called with " + jasmine.pp(expectedArgs) + " but it was.";
var positiveMessage = "";
if (this.actual.callCount === 0) {
positiveMessage = "Expected spy " + this.actual.identity + " to have been called with " + jasmine.pp(expectedArgs) + " but it was never called.";
} else {
positiveMessage = "Expected spy " + this.actual.identity + " to have been called with " + jasmine.pp(expectedArgs) + " but actual calls were " + jasmine.pp(this.actual.argsForCall).replace(/^\[ | \]$/g, '')
}
return [positiveMessage, invertedMessage];
};
return this.env.contains_(this.actual.argsForCall, expectedArgs);
};
/** @deprecated Use expect(xxx).toHaveBeenCalledWith() instead */
jasmine.Matchers.prototype.wasCalledWith = jasmine.Matchers.prototype.toHaveBeenCalledWith;
/** @deprecated Use expect(xxx).not.toHaveBeenCalledWith() instead */
jasmine.Matchers.prototype.wasNotCalledWith = function() {
var expectedArgs = jasmine.util.argsToArray(arguments);
if (!jasmine.isSpy(this.actual)) {
throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.');
}
this.message = function() {
return [
"Expected spy not to have been called with " + jasmine.pp(expectedArgs) + " but it was",
"Expected spy to have been called with " + jasmine.pp(expectedArgs) + " but it was"
];
};
return !this.env.contains_(this.actual.argsForCall, expectedArgs);
};
/**
* Matcher that checks that the expected item is an element in the actual Array.
*
* @param {Object} expected
*/
jasmine.Matchers.prototype.toContain = function(expected) {
return this.env.contains_(this.actual, expected);
};
/**
* Matcher that checks that the expected item is NOT an element in the actual Array.
*
* @param {Object} expected
* @deprecated as of 1.0. Use not.toContain() instead.
*/
jasmine.Matchers.prototype.toNotContain = function(expected) {
return !this.env.contains_(this.actual, expected);
};
jasmine.Matchers.prototype.toBeLessThan = function(expected) {
return this.actual < expected;
};
jasmine.Matchers.prototype.toBeGreaterThan = function(expected) {
return this.actual > expected;
};
/**
* Matcher that checks that the expected item is equal to the actual item
* up to a given level of decimal precision (default 2).
*
* @param {Number} expected
* @param {Number} precision, as number of decimal places
*/
jasmine.Matchers.prototype.toBeCloseTo = function(expected, precision) {
if (!(precision === 0)) {
precision = precision || 2;
}
return Math.abs(expected - this.actual) < (Math.pow(10, -precision) / 2);
};
/**
* Matcher that checks that the expected exception was thrown by the actual.
*
* @param {String} [expected]
*/
jasmine.Matchers.prototype.toThrow = function(expected) {
var result = false;
var exception;
if (typeof this.actual != 'function') {
throw new Error('Actual is not a function');
}
try {
this.actual();
} catch (e) {
exception = e;
}
if (exception) {
result = (expected === jasmine.undefined || this.env.equals_(exception.message || exception, expected.message || expected));
}
var not = this.isNot ? "not " : "";
this.message = function() {
if (exception && (expected === jasmine.undefined || !this.env.equals_(exception.message || exception, expected.message || expected))) {
return ["Expected function " + not + "to throw", expected ? expected.message || expected : "an exception", ", but it threw", exception.message || exception].join(' ');
} else {
return "Expected function to throw an exception.";
}
};
return result;
};
jasmine.Matchers.Any = function(expectedClass) {
this.expectedClass = expectedClass;
};
jasmine.Matchers.Any.prototype.jasmineMatches = function(other) {
if (this.expectedClass == String) {
return typeof other == 'string' || other instanceof String;
}
if (this.expectedClass == Number) {
return typeof other == 'number' || other instanceof Number;
}
if (this.expectedClass == Function) {
return typeof other == 'function' || other instanceof Function;
}
if (this.expectedClass == Object) {
return typeof other == 'object';
}
return other instanceof this.expectedClass;
};
jasmine.Matchers.Any.prototype.jasmineToString = function() {
return 'jasmine.log
in production code.
*/
jasmine.Spec.prototype.log = function() {
return this.results_.log(arguments);
};
jasmine.Spec.prototype.runs = function (func) {
var block = new jasmine.Block(this.env, func, this);
this.addToQueue(block);
return this;
};
jasmine.Spec.prototype.addToQueue = function (block) {
if (this.queue.isRunning()) {
this.queue.insertNext(block);
} else {
this.queue.add(block);
}
};
/**
* @param {jasmine.ExpectationResult} result
*/
jasmine.Spec.prototype.addMatcherResult = function(result) {
this.results_.addResult(result);
};
jasmine.Spec.prototype.expect = function(actual) {
var positive = new (this.getMatchersClass_())(this.env, actual, this);
positive.not = new (this.getMatchersClass_())(this.env, actual, this, true);
return positive;
};
/**
* Waits a fixed time period before moving to the next block.
*
* @deprecated Use waitsFor() instead
* @param {Number} timeout milliseconds to wait
*/
jasmine.Spec.prototype.waits = function(timeout) {
var waitsFunc = new jasmine.WaitsBlock(this.env, timeout, this);
this.addToQueue(waitsFunc);
return this;
};
/**
* Waits for the latchFunction to return true before proceeding to the next block.
*
* @param {Function} latchFunction
* @param {String} optional_timeoutMessage
* @param {Number} optional_timeout
*/
jasmine.Spec.prototype.waitsFor = function(latchFunction, optional_timeoutMessage, optional_timeout) {
var latchFunction_ = null;
var optional_timeoutMessage_ = null;
var optional_timeout_ = null;
for (var i = 0; i < arguments.length; i++) {
var arg = arguments[i];
switch (typeof arg) {
case 'function':
latchFunction_ = arg;
break;
case 'string':
optional_timeoutMessage_ = arg;
break;
case 'number':
optional_timeout_ = arg;
break;
}
}
var waitsForFunc = new jasmine.WaitsForBlock(this.env, optional_timeout_, latchFunction_, optional_timeoutMessage_, this);
this.addToQueue(waitsForFunc);
return this;
};
jasmine.Spec.prototype.fail = function (e) {
var expectationResult = new jasmine.ExpectationResult({
passed: false,
message: e ? jasmine.util.formatException(e) : 'Exception',
trace: { stack: e.stack }
});
this.results_.addResult(expectationResult);
};
jasmine.Spec.prototype.getMatchersClass_ = function() {
return this.matchersClass || this.env.matchersClass;
};
jasmine.Spec.prototype.addMatchers = function(matchersPrototype) {
var parent = this.getMatchersClass_();
var newMatchersClass = function() {
parent.apply(this, arguments);
};
jasmine.util.inherit(newMatchersClass, parent);
jasmine.Matchers.wrapInto_(matchersPrototype, newMatchersClass);
this.matchersClass = newMatchersClass;
};
jasmine.Spec.prototype.finishCallback = function() {
this.env.reporter.reportSpecResults(this);
};
jasmine.Spec.prototype.finish = function(onComplete) {
this.removeAllSpies();
this.finishCallback();
if (onComplete) {
onComplete();
}
};
jasmine.Spec.prototype.after = function(doAfter) {
if (this.queue.isRunning()) {
this.queue.add(new jasmine.Block(this.env, doAfter, this), true);
} else {
this.afterCallbacks.unshift(doAfter);
}
};
jasmine.Spec.prototype.execute = function(onComplete) {
var spec = this;
if (!spec.env.specFilter(spec)) {
spec.results_.skipped = true;
spec.finish(onComplete);
return;
}
this.env.reporter.reportSpecStarting(this);
spec.env.currentSpec = spec;
spec.addBeforesAndAftersToQueue();
spec.queue.start(function () {
spec.finish(onComplete);
});
};
jasmine.Spec.prototype.addBeforesAndAftersToQueue = function() {
var runner = this.env.currentRunner();
var i;
for (var suite = this.suite; suite; suite = suite.parentSuite) {
for (i = 0; i < suite.before_.length; i++) {
this.queue.addBefore(new jasmine.Block(this.env, suite.before_[i], this));
}
}
for (i = 0; i < runner.before_.length; i++) {
this.queue.addBefore(new jasmine.Block(this.env, runner.before_[i], this));
}
for (i = 0; i < this.afterCallbacks.length; i++) {
this.queue.add(new jasmine.Block(this.env, this.afterCallbacks[i], this), true);
}
for (suite = this.suite; suite; suite = suite.parentSuite) {
for (i = 0; i < suite.after_.length; i++) {
this.queue.add(new jasmine.Block(this.env, suite.after_[i], this), true);
}
}
for (i = 0; i < runner.after_.length; i++) {
this.queue.add(new jasmine.Block(this.env, runner.after_[i], this), true);
}
};
jasmine.Spec.prototype.explodes = function() {
throw 'explodes function should not have been called';
};
jasmine.Spec.prototype.spyOn = function(obj, methodName, ignoreMethodDoesntExist) {
if (obj == jasmine.undefined) {
throw "spyOn could not find an object to spy upon for " + methodName + "()";
}
if (!ignoreMethodDoesntExist && obj[methodName] === jasmine.undefined) {
throw methodName + '() method does not exist';
}
if (!ignoreMethodDoesntExist && obj[methodName] && obj[methodName].isSpy) {
throw new Error(methodName + ' has already been spied upon');
}
var spyObj = jasmine.createSpy(methodName);
this.spies_.push(spyObj);
spyObj.baseObj = obj;
spyObj.methodName = methodName;
spyObj.originalValue = obj[methodName];
obj[methodName] = spyObj;
return spyObj;
};
jasmine.Spec.prototype.removeAllSpies = function() {
for (var i = 0; i < this.spies_.length; i++) {
var spy = this.spies_[i];
spy.baseObj[spy.methodName] = spy.originalValue;
}
this.spies_ = [];
};
/**
* Internal representation of a Jasmine suite.
*
* @constructor
* @param {jasmine.Env} env
* @param {String} description
* @param {Function} specDefinitions
* @param {jasmine.Suite} parentSuite
*/
jasmine.Suite = function(env, description, specDefinitions, parentSuite) {
var self = this;
self.id = env.nextSuiteId ? env.nextSuiteId() : null;
self.description = description;
self.queue = new jasmine.Queue(env);
self.parentSuite = parentSuite;
self.env = env;
self.before_ = [];
self.after_ = [];
self.children_ = [];
self.suites_ = [];
self.specs_ = [];
};
jasmine.Suite.prototype.getFullName = function() {
var fullName = this.description;
for (var parentSuite = this.parentSuite; parentSuite; parentSuite = parentSuite.parentSuite) {
fullName = parentSuite.description + ' ' + fullName;
}
return fullName;
};
jasmine.Suite.prototype.finish = function(onComplete) {
this.env.reporter.reportSuiteResults(this);
this.finished = true;
if (typeof(onComplete) == 'function') {
onComplete();
}
};
jasmine.Suite.prototype.beforeEach = function(beforeEachFunction) {
beforeEachFunction.typeName = 'beforeEach';
this.before_.unshift(beforeEachFunction);
};
jasmine.Suite.prototype.afterEach = function(afterEachFunction) {
afterEachFunction.typeName = 'afterEach';
this.after_.unshift(afterEachFunction);
};
jasmine.Suite.prototype.results = function() {
return this.queue.results();
};
jasmine.Suite.prototype.add = function(suiteOrSpec) {
this.children_.push(suiteOrSpec);
if (suiteOrSpec instanceof jasmine.Suite) {
this.suites_.push(suiteOrSpec);
this.env.currentRunner().addSuite(suiteOrSpec);
} else {
this.specs_.push(suiteOrSpec);
}
this.queue.add(suiteOrSpec);
};
jasmine.Suite.prototype.specs = function() {
return this.specs_;
};
jasmine.Suite.prototype.suites = function() {
return this.suites_;
};
jasmine.Suite.prototype.children = function() {
return this.children_;
};
jasmine.Suite.prototype.execute = function(onComplete) {
var self = this;
this.queue.start(function () {
self.finish(onComplete);
});
};
jasmine.WaitsBlock = function(env, timeout, spec) {
this.timeout = timeout;
jasmine.Block.call(this, env, null, spec);
};
jasmine.util.inherit(jasmine.WaitsBlock, jasmine.Block);
jasmine.WaitsBlock.prototype.execute = function (onComplete) {
if (jasmine.VERBOSE) {
this.env.reporter.log('>> Jasmine waiting for ' + this.timeout + ' ms...');
}
this.env.setTimeout(function () {
onComplete();
}, this.timeout);
};
/**
* A block which waits for some condition to become true, with timeout.
*
* @constructor
* @extends jasmine.Block
* @param {jasmine.Env} env The Jasmine environment.
* @param {Number} timeout The maximum time in milliseconds to wait for the condition to become true.
* @param {Function} latchFunction A function which returns true when the desired condition has been met.
* @param {String} message The message to display if the desired condition hasn't been met within the given time period.
* @param {jasmine.Spec} spec The Jasmine spec.
*/
jasmine.WaitsForBlock = function(env, timeout, latchFunction, message, spec) {
this.timeout = timeout || env.defaultTimeoutInterval;
this.latchFunction = latchFunction;
this.message = message;
this.totalTimeSpentWaitingForLatch = 0;
jasmine.Block.call(this, env, null, spec);
};
jasmine.util.inherit(jasmine.WaitsForBlock, jasmine.Block);
jasmine.WaitsForBlock.TIMEOUT_INCREMENT = 10;
jasmine.WaitsForBlock.prototype.execute = function(onComplete) {
if (jasmine.VERBOSE) {
this.env.reporter.log('>> Jasmine waiting for ' + (this.message || 'something to happen'));
}
var latchFunctionResult;
try {
latchFunctionResult = this.latchFunction.apply(this.spec);
} catch (e) {
this.spec.fail(e);
onComplete();
return;
}
if (latchFunctionResult) {
onComplete();
} else if (this.totalTimeSpentWaitingForLatch >= this.timeout) {
var message = 'timed out after ' + this.timeout + ' msec waiting for ' + (this.message || 'something to happen');
this.spec.fail({
name: 'timeout',
message: message
});
this.abort = true;
onComplete();
} else {
this.totalTimeSpentWaitingForLatch += jasmine.WaitsForBlock.TIMEOUT_INCREMENT;
var self = this;
this.env.setTimeout(function() {
self.execute(onComplete);
}, jasmine.WaitsForBlock.TIMEOUT_INCREMENT);
}
};
jasmine.version_= {
"major": 1,
"minor": 3,
"build": 1,
"revision": 1354556913
};
PK ! gmaps/test/spec/RouteSpec.jsnu Iw var map_with_routes, route, routes;
describe("Drawing a route", function() {
beforeEach(function() {
map_with_routes = map_with_routes || new GMaps({
el : '#map-with-routes',
lat : -12.0433,
lng : -77.0283,
zoom : 12
});
});
it("should add a line in the current map", function() {
var route_flag;
runs(function() {
route_flag = false;
map_with_routes.drawRoute({
origin : [-12.044012922866312, -77.02470665341184],
destination : [-12.090814532191756, -77.02271108990476],
travelMode : 'driving',
strokeColor : '#131540',
strokeOpacity : 0.6,
strokeWeight : 6,
callback : function() {
route_flag = true;
}
});
});
waitsFor(function() {
return route_flag;
}, "The drawn route should create a line in the current map", 500);
runs(function() {
expect(map_with_routes.polylines.length).toEqual(1);
expect(map_with_routes.polylines[0].get('strokeColor')).toEqual('#131540');
expect(map_with_routes.polylines[0].get('strokeOpacity')).toEqual(0.6);
expect(map_with_routes.polylines[0].getMap()).toEqual(map_with_routes.map);
});
});
});
describe("Getting routes", function() {
beforeEach(function() {
map_with_routes = map_with_routes || new GMaps({
el : '#map-with-routes',
lat : -12.0433,
lng : -77.0283,
zoom : 12
});
});
it("should return an array of routes", function() {
var routes_flag;
runs(function() {
routes_flag = false;
map_with_routes.getRoutes({
origin : [-12.0440, -77.0247],
destination : [-12.0908, -77.0227],
callback : function(r) {
routes = r;
routes_flag = true;
}
});
});
waitsFor(function() {
return routes_flag;
}, "#getRoutes should return the found routes as an argument", 500);
runs(function() {
expect(routes).toBeDefined();
expect(map_with_routes.routes).toEqual(routes);
if (routes.length > 0) {
expect(routes[0].legs[0].distance).toBeDefined();
expect(routes[0].legs[0].duration).toBeDefined();
}
});
});
});PK ! p gmaps/test/spec/MapSpec.jsnu Iw describe("Creating a map", function() {
var basic_map, advanced_map, map_with_events, map_with_custom_controls;
it("should throw an error if element is not defined", function() {
expect(function() { new GMaps({}); }).toThrow(new Error('No element defined.'));
});
describe("With basic options", function() {
beforeEach(function() {
basic_map = basic_map || new GMaps({
el : '#basic-map',
lat: -12.0433,
lng: -77.0283,
zoom: 12
});
});
it("should create a GMaps object", function() {
expect(basic_map).toBeDefined();
});
it("should have centered the map at the initial coordinates", function() {
var lat = basic_map.getCenter().lat();
var lng = basic_map.getCenter().lng();
expect(lat).toEqual(-12.0433);
expect(lng).toEqual(-77.0283);
});
it("should have the correct zoom", function() {
expect(basic_map.getZoom()).toEqual(12);
});
});
describe("With advanced controls", function() {
beforeEach(function() {
advanced_map = advanced_map || new GMaps({
el : '#advanced-map',
lat: -12.0433,
lng: -77.0283,
zoomControl : true,
panControl : false,
streetViewControl : false,
mapTypeControl: false,
overviewMapControl: false
});
});
it("should show the defined controls", function() {
expect(advanced_map.map.zoomControl).toBeTruthy();
expect(advanced_map.map.panControl).toBeFalsy();
expect(advanced_map.map.streetViewControl).toBeFalsy();
expect(advanced_map.map.mapTypeControl).toBeFalsy();
expect(advanced_map.map.overviewMapControl).toBeFalsy();
});
});
describe("With events", function() {
var callbacks, current_zoom = 0, current_center = null;
beforeEach(function() {
callbacks = {
onclick : function(e) {
var lat = e.latLng.lat();
var lng = e.latLng.lng();
map_with_events.addMarker({
lat : lat,
lng : lng,
title : 'New Marker'
});
},
onzoomchanged : function() {
console.log('onzoomchanged');
current_zoom = this.getZoom();
},
oncenterchanged : function() {
console.log('oncenterchanged');
current_center = this.getCenter();
}
};
spyOn(callbacks, 'onclick').andCallThrough();
spyOn(callbacks, 'onzoomchanged').andCallThrough();
spyOn(callbacks, 'oncenterchanged').andCallThrough();
map_with_events = map_with_events || new GMaps({
el : '#map-with-events',
lat : -12.0433,
lng : -77.0283,
click : callbacks.onclick,
zoom_changed : callbacks.onzoomchanged,
center_changed : callbacks.oncenterchanged
});
});
it("should respond to zoom_changed event", function() {
map_with_events.map.setZoom(16);
expect(callbacks.onzoomchanged).toHaveBeenCalled();
expect(current_zoom).toEqual(16);
});
it("should respond to center_changed event", function() {
map_with_events.map.setCenter(new google.maps.LatLng(-12.0907, -77.0227));
// Fix for floating-point bug
var lat = parseFloat(current_center.lat().toFixed(4));
var lng = parseFloat(current_center.lng().toFixed(4));
expect(callbacks.oncenterchanged).toHaveBeenCalled();
expect(lat).toEqual(-12.0907);
expect(lng).toEqual(-77.0227);
});
it("should respond to click event", function() {
google.maps.event.trigger(map_with_events.map, 'click', {
latLng : new google.maps.LatLng(-12.0433, -77.0283)
});
expect(callbacks.onclick).toHaveBeenCalled();
expect(map_with_events.markers.length).toEqual(1);
});
afterEach(function() {
document.getElementById('map-with-events').innerHTML = '';
map_with_events = null;
});
});
describe("With custom controls", function() {
var callbacks, markers_in_map = 0;
beforeEach(function() {
callbacks = {
onclick : function() {
map_with_custom_controls.addMarker({
lat : map_with_custom_controls.getCenter().lat(),
lng : map_with_custom_controls.getCenter().lng()
});
}
}
spyOn(callbacks, 'onclick').andCallThrough();
map_with_custom_controls = new GMaps({
el : '#map-with-custom-controls',
lat : -12.0433,
lng : -77.0283
});
map_with_custom_controls.addControl({
position : 'top_right',
content : 'Add marker at the center',
style : {
margin: '5px',
padding: '1px 6px',
border: 'solid 1px #717B87',
background: '#fff'
},
events : {
click: callbacks.onclick
}
});
});
it("should add the control to the controls collection", function() {
expect(map_with_custom_controls.controls.length).toEqual(1);
});
it("should respond to click event attached to the custom control", function() {
google.maps.event.trigger(map_with_custom_controls.controls[0], 'click');
expect(callbacks.onclick).toHaveBeenCalled();
expect(map_with_custom_controls.markers.length).toEqual(1);
});
});
});
PK ! G< < ! gmaps/test/spec/StreetViewSpec.jsnu Iw describe("Create a Street View Panorama", function() {
var map_with_streetview, attached_panorama, standalone_panorama, panorama_with_events;
beforeEach(function() {
map_with_streetview = map_with_streetview || new GMaps({
el : '#map-with-streetview',
lat : 42.3455,
lng : -71.0983,
zoom : 12
});
});
describe("Standalone", function() {
beforeEach(function() {
standalone_panorama = standalone_panorama || GMaps.createPanorama({
el : '#streetview-standalone-panorama',
lat : 42.3455,
lng : -71.0983,
pov : {
heading : 60,
pitch : -10,
zoom : 1
}
});
});
it("should create a Street View panorama", function() {
expect(standalone_panorama).toBeDefined();
});
});
describe("Attached to the current map", function() {
beforeEach(function() {
attached_panorama = attached_panorama || map_with_streetview.createPanorama({
el : '#streetview-panorama',
pov : {
heading : 60,
pitch : -10,
zoom : 1
}
});
});
it("should be equal to the current map Street View panorama", function() {
expect(map_with_streetview.getStreetView()).toEqual(attached_panorama);
});
});
describe("With events", function() {
var callbacks;
beforeEach(function() {
callbacks = {
onpovchanged : function() {
console.log(this);
}
};
spyOn(callbacks, 'onpovchanged').andCallThrough();
panorama_with_events = panorama_with_events || GMaps.createPanorama({
el : '#streetview-with-events',
lat : 42.3455,
lng : -71.0983,
pov : {
heading : 60,
pitch : -10,
zoom : 1
},
pov_changed : callbacks.onpovchanged
});
});
it("should respond to pov_changed event", function() {
panorama_with_events.setPov({
heading : 80,
pitch : -10,
zoom : 1
});
expect(callbacks.onpovchanged).toHaveBeenCalled();
});
});
});PK ! fk gmaps/test/spec/StyleSpec.jsnu Iw describe("Adding Map Styles", function() {
var map_with_styles;
beforeEach(function() {
map_with_styles = map_with_styles || new GMaps({
el : '#map-with-styles',
lat : -12.0433,
lng : -77.0283,
zoom : 12
});
map_with_styles.addStyle({
styledMapName : {
name : 'Lighter'
},
mapTypeId : 'lighter',
styles : [
{
elementType : 'geometry',
stylers : [
{ lightness : 50 }
]
},
{
elementType : 'labels',
stylers : [
{ visibility : 'off' }
]
},
]
});
});
it("should add a MapType to the current map", function() {
expect(map_with_styles.map.mapTypes.get('lighter')).toBeDefined();
});
it("should update the styles in the current map", function() {
map_with_styles.setStyle('lighter');
expect(map_with_styles.getMapTypeId()).toEqual('lighter');
});
});PK ! *)g gmaps/test/spec/MarkerSpec.jsnu Iw describe("Creating a marker", function() {
var map, marker;
beforeEach(function() {
map = map || new GMaps({
el : '#map-with-markers',
lat : -12.0533,
lng: -77.0293,
zoom: 14
});
});
describe("With basic options", function() {
beforeEach(function() {
marker = map.addMarker({
lat : -12.0533,
lng: -77.0293,
title : 'New marker'
});
});
it("should add the marker to the markers collection", function() {
expect(map.markers.length).toEqual(1);
expect(map.markers[0]).toEqual(marker);
});
it("should create a marker with defined position", function() {
// Fix for floating-point bug
expect(parseFloat(marker.getPosition().lat().toFixed(4))).toEqual(-12.0533);
expect(parseFloat(marker.getPosition().lng().toFixed(4))).toEqual(-77.0293);
});
});
describe("With events", function() {
var callbacks;
beforeEach(function() {
callbacks = {
onclick : function() {
console.log(this.title);
}
};
spyOn(callbacks, 'onclick').andCallThrough();
marker = map.addMarker({
lat : -12.0533,
lng: -77.0193,
title : 'New marker',
click : callbacks.onclick
});
});
it("should respond to click event", function() {
google.maps.event.trigger(marker, 'click');
expect(callbacks.onclick).toHaveBeenCalled();
});
});
});PK ! ?g gmaps/test/spec/LayerSpec.jsnu Iw describe("Adding layers", function() {
var map_with_layers, single_layer, multiple_layers = [];
beforeEach(function() {
map_with_layers = map_with_layers || new GMaps({
el : '#map-with-layers',
lat: -12.0433,
lng: -77.0283,
zoom: 12
});
});
describe("Single layer", function() {
beforeEach(function() {
single_layer = single_layer || map_with_layers.addLayer('traffic');
})
it("should be added in the current map", function() {
expect(single_layer.getMap()).toEqual(map_with_layers.map);
});
it("should be removed from the current map", function() {
map_with_layers.removeLayer('traffic');
expect(single_layer.getMap()).toBeNull();
});
});
describe("Multiple layers", function() {
beforeEach(function() {
if (multiple_layers.length == 0) {
multiple_layers.push(map_with_layers.addLayer('transit'));
multiple_layers.push(map_with_layers.addLayer('bicycling'));
}
});
it("should be added in the current map", function() {
expect(multiple_layers[0].getMap()).toEqual(map_with_layers.map);
expect(multiple_layers[1].getMap()).toEqual(map_with_layers.map);
});
it("should be removed from the current map", function() {
map_with_layers.removeLayer('transit');
map_with_layers.removeLayer('bicycling');
expect(multiple_layers[0].getMap()).toBeNull();
expect(multiple_layers[1].getMap()).toBeNull();
});
});
});PK ! φ´V% V% gmaps/test/spec/EventSpec.jsnu Iw describe("Creating event listeners", function() {
var map_events, marker, line, polygon, callbacks_native, callbacks_gmaps;
var added_marker, added_line, added_polygon;
var marker_added_event, marker_removed_event,
polyline_added_event, polyline_removed_event,
polygon_added_event, polygon_removed_event;
beforeEach(function() {
map_events = map_events || new GMaps({
el : '#events',
lat : -12.0433,
lng : -77.0283,
zoom : 12
});
marker = marker || map_events.addMarker({
lat : -12.0433,
lng : -77.0283,
title : 'New marker'
});
line = line || map_events.drawPolyline({
path : [[-12.0440, -77.0247], [-12.0544, -77.0302], [-12.0551, -77.0303], [-12.0759, -77.0276], [-12.0763, -77.0279], [-12.0768, -77.0289], [-12.0885, -77.0241], [-12.0908, -77.0227]],
strokeColor : '#131540',
strokeOpacity : 0.6,
strokeWeight : 6
});
polygon = polygon || map_events.drawPolygon({
paths : [[-12.0403,-77.0337],[-12.0402,-77.0399],[-12.0500,-77.0244],[-12.0448,-77.0215]],
strokeColor : '#25D359',
strokeOpacity : 1,
strokeWeight : 3,
fillColor : '#25D359',
fillOpacity : 0.6
});
});
describe("for google.maps events", function() {
beforeEach(function() {
callbacks_native = callbacks_native || {
map : {
onclick : function() {
console.log('callbacks_native.map.onclick');
}
},
marker : {
onclick : function() {
console.log('callbacks_native.marker.onclick');
}
},
line : {
onclick : function() {
console.log('callbacks_native.line.onclick');
}
},
polygon : {
onclick : function() {
console.log('callbacks_native.polygon.onclick');
}
}
};
spyOn(callbacks_native.map, 'onclick').andCallThrough();
spyOn(callbacks_native.marker, 'onclick').andCallThrough();
spyOn(callbacks_native.line, 'onclick').andCallThrough();
spyOn(callbacks_native.polygon, 'onclick').andCallThrough();
});
describe("To a map", function() {
it("should add the listener to the listeners collection", function() {
var click_event = GMaps.on('click', map_events.map, callbacks_native.map.onclick);
expect(map_events.map['__e3_']['click'][click_event['id']]).toBeDefined();
expect(map_events.map['__e3_']['click'][click_event['id']]).toEqual(click_event);
});
});
describe("To a marker", function() {
it("should add the listener to the listeners collection", function() {
var click_event = GMaps.on('click', marker, callbacks_native.marker.onclick);
expect(marker['__e3_']['click'][click_event['id']]).toBeDefined();
expect(marker['__e3_']['click'][click_event['id']]).toEqual(click_event);
});
});
describe("To a line", function() {
it("should add the listener to the listeners collection", function() {
var click_event = GMaps.on('click', line, callbacks_native.line.onclick);
expect(line['__e3_']['click'][click_event['id']]).toBeDefined();
expect(line['__e3_']['click'][click_event['id']]).toEqual(click_event);
});
});
describe("To a polygon", function() {
it("should add the listener to the listeners collection", function() {
var click_event = GMaps.on('click', polygon, callbacks_native.polygon.onclick);
expect(polygon['__e3_']['click'][click_event['id']]).toBeDefined();
expect(polygon['__e3_']['click'][click_event['id']]).toEqual(click_event);
});
});
});
describe("for GMaps events", function() {
beforeEach(function() {
callbacks_gmaps = {
marker_added : function() {
console.log('callbacks_gmaps.marker_added called');
},
marker_removed : function() {
console.log('callbacks_gmaps.marker_removed called');
},
polyline_added : function() {
console.log('callbacks_gmaps.polyline_added called');
},
polyline_removed : function() {
console.log('callbacks_gmaps.polyline_removed called');
},
polygon_added : function() {
console.log('callbacks_gmaps.polygon_added called');
},
polygon_removed : function() {
console.log('callbacks_gmaps.polygon_removed called');
}
};
spyOn(callbacks_gmaps, 'marker_added').andCallThrough();
spyOn(callbacks_gmaps, 'marker_removed').andCallThrough();
spyOn(callbacks_gmaps, 'polyline_added').andCallThrough();
spyOn(callbacks_gmaps, 'polyline_removed').andCallThrough();
spyOn(callbacks_gmaps, 'polygon_added').andCallThrough();
spyOn(callbacks_gmaps, 'polygon_removed').andCallThrough();
});
describe("#marker_added", function() {
beforeEach(function() {
marker_added_event = GMaps.on('marker_added', map_events, callbacks_gmaps.marker_added);
});
it("should add the listener to the listeners collection", function() {
expect(map_events.registered_events['marker_added'][0]).toEqual(marker_added_event);
});
it("should trigger the listener created", function() {
added_marker = added_marker || map_events.addMarker({
lat : -12.0433,
lng : -77.0273,
title : 'New marker'
});
expect(callbacks_gmaps.marker_added).toHaveBeenCalled();
});
afterEach(function() {
GMaps.off('marker_added', map_events);
});
});
describe("#marker_removed", function() {
beforeEach(function() {
marker_removed_event = GMaps.on('marker_removed', map_events, callbacks_gmaps.marker_removed);
});
it("should add the listener to the listeners collection", function() {
expect(map_events.registered_events['marker_removed'][0]).toEqual(marker_removed_event);
});
it("should trigger the listener created", function() {
map_events.removeMarker(added_marker);
expect(callbacks_gmaps.marker_removed).toHaveBeenCalled();
});
afterEach(function() {
GMaps.off('marker_removed', map_events);
});
});
describe("#polyline_added", function() {
beforeEach(function() {
polyline_added_event = GMaps.on('polyline_added', map_events, callbacks_gmaps.polyline_added);
});
it("should add the listener to the listeners collection", function() {
expect(map_events.registered_events['polyline_added'][0]).toEqual(polyline_added_event);
});
it("should trigger the listener created", function() {
added_line = added_line || map_events.drawPolyline({
path : [[-12.0420, -77.0247], [-12.0544, -77.0102], [-12.0751, -77.0903], [-12.0759, -77.0276], [-12.0763, -77.0279], [-12.0768, -77.0289], [-12.0885, -77.0241], [-12.0908, -77.0227]],
strokeColor : '#271804',
strokeOpacity : 0.1,
strokeWeight : 1
});
expect(callbacks_gmaps.polyline_added).toHaveBeenCalled();
});
afterEach(function() {
GMaps.off('polyline_added', map_events);
});
});
describe("#polyline_removed", function() {
beforeEach(function() {
polyline_removed_event = GMaps.on('polyline_removed', map_events, callbacks_gmaps.polyline_removed);
});
it("should add the listener to the listeners collection", function() {
expect(map_events.registered_events['polyline_removed'][0]).toEqual(polyline_removed_event);
});
it("should trigger the listener created", function() {
map_events.removePolyline(added_line);
expect(callbacks_gmaps.polyline_removed).toHaveBeenCalled();
});
afterEach(function() {
GMaps.off('polyline_removed', map_events);
});
});
describe("#polygon_added", function() {
beforeEach(function() {
polygon_added_event = GMaps.on('polygon_added', map_events, callbacks_gmaps.polygon_added);
});
it("should add the listener to the listeners collection", function() {
expect(map_events.registered_events['polygon_added'][0]).toEqual(polygon_added_event);
});
it("should trigger the listener created", function() {
added_polygon = added_polygon || map_events.drawPolygon({
paths : [[-12.0203,-77.0137],[-12.0402,-77.0109],[-12.0500,-77.0144],[-12.0848,-77.0115]],
strokeColor : '#D32559',
strokeOpacity : 0.7,
strokeWeight : 8,
fillColor : '#D32559',
fillOpacity : 0.6
});
expect(callbacks_gmaps.polygon_added).toHaveBeenCalled();
});
afterEach(function() {
GMaps.off('polygon_added', map_events);
});
});
describe("#polygon_removed", function() {
beforeEach(function() {
polygon_removed_event = GMaps.on('polygon_removed', map_events, callbacks_gmaps.polygon_removed);
});
it("should add the listener to the listeners collection", function() {
expect(map_events.registered_events['polygon_removed'][0]).toEqual(polygon_removed_event);
});
it("should trigger the listener created", function() {
map_events.removePolygon(added_polygon);
expect(callbacks_gmaps.polygon_removed).toHaveBeenCalled();
});
afterEach(function() {
GMaps.off('polygon_removed', map_events);
});
});
});
});PK ! :. gmaps/test/spec/GeometrySpec.jsnu Iw describe("Drawing geometry overlays", function() {
var map_with_polygons, line, rectangle, circle, polygon;
beforeEach(function() {
map_with_polygons = map_with_polygons || new GMaps({
el : '#map-with-polygons',
lat : -12.0433,
lng : -77.0283,
zoom : 12
});
});
describe("A line", function() {
beforeEach(function() {
line = line || map_with_polygons.drawPolyline({
path : [[-12.0440, -77.0247], [-12.0544, -77.0302], [-12.0551, -77.0303], [-12.0759, -77.0276], [-12.0763, -77.0279], [-12.0768, -77.0289], [-12.0885, -77.0241], [-12.0908, -77.0227]],
strokeColor : '#131540',
strokeOpacity : 0.6,
strokeWeight : 6
});
});
it("should add the line to the polylines collection", function() {
expect(map_with_polygons.polylines.length).toEqual(1);
expect(map_with_polygons.polylines[0]).toEqual(line);
});
it("should be added in the current map", function() {
expect(line.getMap()).toEqual(map_with_polygons.map);
});
it("should return the defined path", function() {
var first_point = line.getPath().getAt(0);
expect(parseFloat(first_point.lat().toFixed(4))).toEqual(-12.0440);
expect(parseFloat(first_point.lng().toFixed(4))).toEqual(-77.0247);
});
});
describe("A rectangle", function() {
beforeEach(function() {
rectangle = rectangle || map_with_polygons.drawRectangle({
bounds : [[-12.0303,-77.0237],[-12.0348,-77.0115]],
strokeColor : '#BBD8E9',
strokeOpacity : 1,
strokeWeight : 3,
fillColor : '#BBD8E9',
fillOpacity : 0.6
});
});
it("should add the rectangle to the polygons collection", function() {
expect(map_with_polygons.polygons.length).toEqual(1);
expect(map_with_polygons.polygons[0]).toEqual(rectangle);
});
it("should be added in the current map", function() {
expect(rectangle.getMap()).toEqual(map_with_polygons.map);
});
it("should have the defined bounds", function() {
// Fix for floating-point bug
var SWLat = parseFloat(rectangle.getBounds().getSouthWest().lat().toFixed(4));
var SWLng = parseFloat(rectangle.getBounds().getSouthWest().lng().toFixed(4));
var NELat = parseFloat(rectangle.getBounds().getNorthEast().lat().toFixed(4));
var NELng = parseFloat(rectangle.getBounds().getNorthEast().lng().toFixed(4));
expect(SWLat).toEqual(-12.0303);
expect(SWLng).toEqual(-77.0237);
expect(NELat).toEqual(-12.0348);
expect(NELng).toEqual(-77.0115);
});
});
describe("A polygon", function() {
beforeEach(function() {
polygon = polygon || map_with_polygons.drawPolygon({
paths : [[-12.0403,-77.0337],[-12.0402,-77.0399],[-12.0500,-77.0244],[-12.0448,-77.0215]],
strokeColor : '#25D359',
strokeOpacity : 1,
strokeWeight : 3,
fillColor : '#25D359',
fillOpacity : 0.6
});
});
it("should add the polygon to the polygons collection", function() {
expect(map_with_polygons.polygons.length).toEqual(2);
expect(map_with_polygons.polygons[1]).toEqual(polygon);
});
it("should be added in the current map", function() {
expect(polygon.getMap()).toEqual(map_with_polygons.map);
});
it("should return the defined path", function() {
var first_point = polygon.getPath().getAt(0);
expect(parseFloat(first_point.lat().toFixed(4))).toEqual(-12.0403);
expect(parseFloat(first_point.lng().toFixed(4))).toEqual(-77.0337);
});
});
describe("A circle", function() {
beforeEach(function() {
circle = circle || map_with_polygons.drawCircle({
lat : -12.040504866577001,
lng : -77.02024422636042,
radius : 350,
strokeColor : '#432070',
strokeOpacity : 1,
strokeWeight : 3,
fillColor : '#432070',
fillOpacity : 0.6
});
});
it("should add the circle to the polygons collection", function() {
expect(map_with_polygons.polygons.length).toEqual(3);
expect(map_with_polygons.polygons[2]).toEqual(circle);
});
it("should be added in the current map", function() {
expect(circle.getMap()).toEqual(map_with_polygons.map);
});
it("should have the defined radius", function() {
expect(circle.getRadius()).toEqual(350);
});
});
});
describe("Removing geometry overlays", function() {
var map_with_polygons, line, rectangle, circle, polygon;
beforeEach(function() {
map_with_polygons = map_with_polygons || new GMaps({
el : '#map-with-polygons',
lat : -12.0433,
lng : -77.0283,
zoom : 12
});
});
describe("A line", function() {
beforeEach(function() {
line = map_with_polygons.drawPolyline({
path : [[-12.0440, -77.0247], [-12.0544, -77.0302], [-12.0551, -77.0303], [-12.0759, -77.0276], [-12.0763, -77.0279], [-12.0768, -77.0289], [-12.0885, -77.0241], [-12.0908, -77.0227]],
strokeColor : '#131540',
strokeOpacity : 0.6,
strokeWeight : 6
});
map_with_polygons.removePolyline(line);
});
it("should remove the line from the polylines collection", function() {
expect(map_with_polygons.polylines.length).toEqual(0);
expect(line.getMap()).toBeNull();
});
});
describe("A rectangle", function() {
beforeEach(function() {
rectangle = map_with_polygons.drawRectangle({
bounds : [[-12.0303,-77.0237],[-12.0348,-77.0115]],
strokeColor : '#BBD8E9',
strokeOpacity : 1,
strokeWeight : 3,
fillColor : '#BBD8E9',
fillOpacity : 0.6
});
map_with_polygons.removePolygon(rectangle);
});
it("should remove the rectangle from the polygons collection", function() {
expect(map_with_polygons.polygons.length).toEqual(0);
expect(rectangle.getMap()).toBeNull();
});
});
describe("A polygon", function() {
beforeEach(function() {
polygon = map_with_polygons.drawPolygon({
paths : [[-12.0403,-77.0337],[-12.0402,-77.0399],[-12.0500,-77.0244],[-12.0448,-77.0215]],
strokeColor : '#25D359',
strokeOpacity : 1,
strokeWeight : 3,
fillColor : '#25D359',
fillOpacity : 0.6
});
map_with_polygons.removePolygon(polygon);
});
it("should remove the polygon from the polygons collection", function() {
expect(map_with_polygons.polygons.length).toEqual(0);
expect(polygon.getMap()).toBeNull();
});
});
describe("A circle", function() {
beforeEach(function() {
circle = map_with_polygons.drawCircle({
lat : -12.040504866577001,
lng : -77.02024422636042,
radius : 350,
strokeColor : '#432070',
strokeOpacity : 1,
strokeWeight : 3,
fillColor : '#432070',
fillOpacity : 0.6
});
map_with_polygons.removePolygon(circle);
});
it("should remove the circle from the polygons collection", function() {
expect(map_with_polygons.polygons.length).toEqual(0);
expect(circle.getMap()).toBeNull();
});
});
});PK ! T gmaps/test/spec/OverlaySpec.jsnu Iw describe("Drawing HTML overlays", function() {
var map_with_overlays, overlay;
beforeEach(function() {
map_with_overlays = map_with_overlays || new GMaps({
el : '#map-with-overlays',
lat : -12.0433,
lng : -77.0283,
zoom : 12
});
overlay = overlay || map_with_overlays.drawOverlay({
lat: map_with_overlays.getCenter().lat(),
lng: map_with_overlays.getCenter().lng(),
layer: 'overlayLayer',
content: ' ',
verticalAlign: 'top',
horizontalAlign: 'center'
});
});
it("should add the overlay to the overlays collection", function() {
expect(map_with_overlays.overlays.length).toEqual(1);
expect(map_with_overlays.overlays[0]).toEqual(overlay);
});
it("should add the overlay in the current map", function() {
expect(overlay.getMap()).toEqual(map_with_overlays.map);
});
});PK ! Fh h gmaps/test/index.htmlnu Iw