feat(ParseQuery): Added 'withinPolygon' support for GeoPoints (#3866)

* Added 'withinPolygon' to query

* Unit test for withinPolygon

* More Unit Test

* withinPolygon fix for Postgres

* Fix nit

nit?
This commit is contained in:
Diamond Lewis
2017-05-28 11:42:16 -05:00
committed by Florent Vilmart
parent a380fcf2c7
commit c99fdea6fb
3 changed files with 192 additions and 0 deletions

View File

@@ -618,6 +618,24 @@ function transformConstraint(constraint, inArray) {
};
break;
case '$geoWithin': {
const polygon = constraint[key]['$polygon'];
if (!(polygon instanceof Array)) {
throw new Parse.Error(Parse.Error.INVALID_JSON, 'bad $geoWithin value');
}
const points = polygon.map((point) => {
if (!GeoPointCoder.isValidJSON(point)) {
throw new Parse.Error(Parse.Error.INVALID_JSON, 'bad $geoWithin value');
} else {
Parse.GeoPoint._validate(point.latitude, point.longitude);
}
return [point.longitude, point.latitude];
});
answer[key] = {
'$polygon': points
};
break;
}
default:
if (key.match(/^\$+/)) {
throw new Parse.Error(