Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions integration/test/ParseLocalDatastoreTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2735,6 +2735,26 @@ function runTest(controller) {
assert.equal(objects.length, 1);
});

it(`${controller.name} supports withinKilometers`, async () => {
const object = new TestObject();
const firstPoint = new Parse.GeoPoint({ latitude: 40.0, longitude: -30.0 });
object.set({ location: firstPoint });
await object.save();
await object.pin();

const sorted = false;
const query = new Parse.Query(TestObject);
query.withinKilometers(
'location',
new Parse.GeoPoint({ latitude: 40.0, longitude: -30.0 }),
2,
sorted
);
query.fromLocalDatastore();
const results = await query.find();
assert.equal(results.length, 1);
});

it(`${controller.name} supports withinPolygon`, async () => {
const sacramento = new TestObject();
sacramento.set('location', new Parse.GeoPoint(38.52, -121.5));
Expand Down
20 changes: 17 additions & 3 deletions src/OfflineQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -513,9 +513,23 @@ function matchesKeyConstraints(className, object, objects, key, constraints) {
return true;
}
case '$geoWithin': {
const points = compareTo.$polygon.map(geoPoint => [geoPoint.latitude, geoPoint.longitude]);
const polygon = new ParsePolygon(points);
return polygon.containsPoint(object[key]);
if (compareTo.$polygon) {
const points = compareTo.$polygon.map(geoPoint => [
geoPoint.latitude,
geoPoint.longitude,
]);
const polygon = new ParsePolygon(points);
return polygon.containsPoint(object[key]);
}
// $centerSphere
const [WGS84Point, maxDistance] = compareTo.$centerSphere;
const centerPoint = new ParseGeoPoint({
latitude: WGS84Point[1],
longitude: WGS84Point[0],
});
const point = new ParseGeoPoint(object[key]);
const distance = point.radiansTo(centerPoint);
return distance <= maxDistance;
}
case '$geoIntersects': {
const polygon = new ParsePolygon(object[key].coordinates);
Expand Down
9 changes: 9 additions & 0 deletions src/__tests__/OfflineQuery-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,15 @@ describe('OfflineQuery', () => {
expect(matchesQuery(q.className, pt, [], q)).toBe(true);
});

it('matches $centerSphere queries', () => {
const pt = new ParseObject('Checkin');
pt.set('location', new ParseGeoPoint(40, 40));

const q = new ParseQuery('Checkin');
q.withinRadians('location', new ParseGeoPoint(30, 30), 0.3, false);
expect(matchesQuery(q.className, pt, [], q)).toBe(true);
});

it('matches $within queries', () => {
const caltrainStation = new ParseObject('Checkin');
caltrainStation
Expand Down