Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ang-google-services

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ang-google-services - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

demos/assets/js/demo4.module.js

2

bower.json
{
"name": "ang-google-services",
"version": "1.0.2",
"version": "1.0.3",
"description": "Consuming google's APIs services",

@@ -5,0 +5,0 @@ "main": "./src/module.js",

{
"name": "ang-google-services",
"version": "1.0.2",
"version": "1.0.3",
"description": "Consuming google's APIs services",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -7,7 +7,9 @@ (function($A, $G) {

.factory('$Geocode', ['$q', function($q) { return Geocode($q); }])
.factory('$Distance', ['$q', function($q) { return Distance($q); }])
.factory('$Marker', ['$q', function($q) { return Marker($q); }])
.factory('$Places', ['$q', function($q) { return Places($q); }]);
.factory('$Places', ['$q', function($q) { return Places($q); }])
.factory('$Polyline', ['$q', function($q) { return Polyline($q); }]);
function Geocode($q) {
var $Self = this,

@@ -27,6 +29,27 @@ $GeocodeService = new $G.maps.Geocoder;

};
};
/**
* The factory of Ditance service.
*
* @param Object $q.
*/
function Distance($q) {
var $Self = this,
$GeocodeService = new $G.maps.Geocoder,
$DistanceMatrixService = new $G.maps.DistanceMatrixService;
return {
getDistance: function(options) {
return getDistance.call($Self, $GeocodeService, $DistanceMatrixService, $q, options);
}
};
}
/**
* The factory of Marker

@@ -43,2 +66,5 @@ */

return addMarkers.call($Self, options);
},
removeMarker: function(options) {
return removeMarker.call($Self, options);
}

@@ -49,3 +75,3 @@

}
/**

@@ -70,2 +96,61 @@ * The factory of Places

/**
* The factory of Polyline.
*/
function Polyline($q) {
var $Self = this;
return {
add: function(options) {
return addPolyline.call($Self, options, $q);
},
remove: function(options) {
return removePolyline.call($Self, options, $q);
}
};
}
/**
* Adds the polyline into the map
*
* @return Object $PathPolyline Polyline's object.
*/
function addPolyline(options, $q) {
var $Options = options || {},
$Paths = options['coords'] || [],
$Map = options['map'] || undefined;
if (!$Map) return new Error("Should pass map object");
var $PathPolyline = new $G.maps.Polyline({
path: $Paths,
geodesic: options['geodesic'] || true,
strokeColor: options['strokeColor'] || '#4285f4',
strokeOpacity: options['strokeOpacity'] || 0.4,
strokeWeight: options['strokeWeight'] || 2,
map: $Map
});
return $PathPolyline;
}
/**
* Removes the polyline from the map
*
*/
function removePolyline(polylineObj) {
var $PolylineObj = polylineObj || undefined;
if ($PolylineObj) if (typeof $PolylineObj['setMap'] == 'function') $PolylineObj['setMap'](null);
}
/**
* Shapes the request object for places' searching process

@@ -145,3 +230,3 @@ *

*
* @param {Object} options
* @param {Object} options { markers: [], map: mapObject }
*/

@@ -152,3 +237,4 @@ function addMarkers(options) {

$Markers = options['markers'] || [],
$Map = $Options['map'];
$Map = $Options['map'],
$Bounds = new $G.maps.LatLngBounds() || {};

@@ -167,5 +253,7 @@ if(!$Map) return 0;

$Map.panTo($Position);
$Bounds.extend(new google.maps.LatLng($Position['lat'], $Position['lng']));
}
if(typeof $Map.fitBounds == 'function') $Map.fitBounds($Bounds);

@@ -175,2 +263,19 @@ }

/**
*
* Removes the marker from the map.
*
* @param Object options.
*/
function removeMarker(options) {
var $Options = options || {},
$Marker = $Options['marker'];
if (!$Marker) return;
if (typeof $Marker.setMap == 'function') $Marker.setMap(null)
}
/**
* Gets the names of location from coordinates

@@ -189,3 +294,3 @@ *

} else {
$Defer.resolve({error: { message: 'Failed to get the result' }});
$Defer.reject({error: status, message: 'Failed to get the result ' + status});
}

@@ -213,3 +318,6 @@

} else {
$Defer.resolve(undefined);
$Defer.reject({
error: status,
message: "There something wrong due to " + status
});
}

@@ -222,3 +330,95 @@

}
function formPropObject(objName, $SeperatedField) {
var $SeperatedField = $SeperatedField || [],
$ObjStr = '';
for (var index = 0, length = $SeperatedField.length; index < length; index++) {
$ObjStr += '["' + $SeperatedField[index] + '"]';
}
return objName + $ObjStr;
}
function mapReduceDistance($Data, $Field, callback) {
var $Data = $Data || [],
$Field = $Field || '',
$SeperatedField = $Field.split('.'),
$Summary = {},
$Result = {};
for (var index = 0, length = $Data.length; index < length; index++) {
//console.log($Data[index]);
var $ChunkData = $Data[index],
$PrevData = (index < 1) ? $Data[index] : $Data[index-1],
value = eval(formPropObject("$ChunkData", $SeperatedField)),
prevValue = eval(formPropObject("$PrevData", $SeperatedField));
$Result = callback(prevValue, value, $Summary) || $Summary;
}
return $Result || undefined;
}
/**
* Gets the ditance from different origins and destinations.
*
* @param Object options { origins: Array, destinations: Array, etc ... }
* @return Object Promise.
*/
function getDistance($GeocodeService, $DistanceMatrixService, $q, options) {
var $Defer = $q.defer(),
options = options || {};
$DistanceMatrixService.getDistanceMatrix ({
origins: options['origins'] || [],
destinations: options['destinations'] || [],
travelMode: options['travelMode'] || google.maps.TravelMode.DRIVING,
unitSystem: options['travelMode'] || google.maps.UnitSystem.METRIC,
avoidHighways: options['avoidHighways'] || false,
avoidTolls: options['avoidTolls'] || false
}, function(response, status) {
if (status == $G.maps.DistanceMatrixStatus.OK) {
var $Summary = mapReduceDistance(response.rows[0].elements || undefined, "distance.value", function(prevValue, value, $Summary) {
if (prevValue <= value) {
$Summary.shortest = prevValue;
} else {
$Summary.shortest = value;
}
if (prevValue > value) {
$Summary.longest = prevValue;
} else {
$Summary.longest = value;
}
return $Summary;
});
$Defer.resolve({
response: response,
$Summary: $Summary
});
} else {
$Defer.reject(undefined);
}
});
return $Defer.promise;
}
}(angular, google));
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc