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

@@ -344,6 +344,25 @@ const buildWhereClause = ({ schema, query, index }) => {
index += 2;
}
if (fieldValue.$geoWithin && fieldValue.$geoWithin.$polygon) {
const polygon = fieldValue.$geoWithin.$polygon;
if (!(polygon instanceof Array)) {
throw new Parse.Error(Parse.Error.INVALID_JSON, 'bad $geoWithin value');
}
const points = polygon.map((point) => {
if (typeof point !== 'object' || point.__type !== 'GeoPoint') {
throw new Parse.Error(Parse.Error.INVALID_JSON, 'bad $geoWithin value');
} else {
Parse.GeoPoint._validate(point.latitude, point.longitude);
}
return `(${point.longitude}, ${point.latitude})`;
}).join(', ');
patterns.push(`$${index}:name::point <@ $${index + 1}::polygon`);
values.push(fieldName, `(${points})`);
index += 2;
}
if (fieldValue.$regex) {
let regex = fieldValue.$regex;
let operator = '~';