MCPcopy Create free account
hub / github.com/CloudBoost/cloudboost / geoWithin

Method geoWithin

sdk/src/CloudQuery.js:704–740  ·  view source on GitHub ↗
(columnName, geoPoint, radius)

Source from the content-addressed store, hash-verified

702
703 //GeoPoint geoWithin query
704 geoWithin(columnName, geoPoint, radius) {
705
706 if (!radius) {
707 var coordinates = [];
708 //extracting coordinates from each CloudGeoPoint Object
709 if (Object.prototype.toString.call(geoPoint) === '[object Array]') {
710 for (var i = 0; i < geoPoint.length; i++) {
711 if (geoPoint[i]['document'].hasOwnProperty('coordinates')) {
712 coordinates[i] = geoPoint[i]['document']['coordinates'];
713 }
714 }
715 } else {
716 throw 'Invalid Parameter, coordinates should be an array of CloudGeoPoint Object';
717 }
718 //2dSphere needs first and last coordinates to be same for polygon type
719 //eg. for Triangle four coordinates need to pass, three points of triangle and fourth one should be same as first one
720 coordinates[coordinates.length] = coordinates[0];
721 var type = 'Polygon';
722 if (!this.query[columnName]) {
723 this.query[columnName] = {};
724 this.query[columnName]['$geoWithin'] = {};
725 this.query[columnName]['$geoWithin']['$geometry'] = {
726 'type': type,
727 'coordinates': [coordinates]
728 };
729 }
730 } else {
731 if (!this.query[columnName]) {
732 this.query[columnName] = {};
733 this.query[columnName]['$geoWithin'] = {
734 '$centerSphere': [
735 geoPoint['document']['coordinates'], radius / 3963.2
736 ]
737 };
738 }
739 }
740 };
741
742 count(callback) {
743 if (!CB.appId) {

Callers 2

test.jsFile · 0.80
CloudGeoPoint.jsFile · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected