Skip to content

Commit 2afa2ad

Browse files
authored
feat: Add query constraint wherePolygonContains to determine whether a point in within a polygon (#778)
1 parent 7f24fb2 commit 2afa2ad

File tree

5 files changed

+88
-2
lines changed

5 files changed

+88
-2
lines changed

packages/dart/CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## [3.1.11](https://github.com/parse-community/Parse-SDK-Flutter/compare/dart-3.1.10...dart-3.1.11) (2023-01-21)
2+
3+
### Features
4+
5+
* Add query constraint `wherePolygonContains` to determine whether a point in within a polygon ([#777](https://github.com/parse-community/Parse-SDK-Flutter/issues/777))
6+
17
## [3.1.10](https://github.com/parse-community/Parse-SDK-Flutter/compare/dart-3.1.9...dart-3.1.10) (2023-01-16)
28

39
### Bug Fixes

packages/dart/lib/src/base/parse_constants.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
part of flutter_parse_sdk;
22

33
// Library
4-
const String keySdkVersion = '3.1.10';
4+
const String keySdkVersion = '3.1.11';
55
const String keyLibraryName = 'Flutter Parse SDK';
66

77
// End Points

packages/dart/lib/src/network/parse_query.dart

+9
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,15 @@ class QueryBuilder<T extends ParseObject> {
314314
_singleQuery, '"$column":{"\$geoWithin":${jsonEncode(dictionary)}}'));
315315
}
316316

317+
/// Add a constraint to the query that requires a particular key's coordinates that contains a point
318+
void wherePolygonContains(String column, ParseGeoPoint point) {
319+
final double latitude = point.latitude;
320+
final double longitude = point.longitude;
321+
322+
queries.add(MapEntry<String, dynamic>(_singleQuery,
323+
'"$column":{"\$geoIntersects":{"\$point":{"__type":"GeoPoint","latitude":$latitude,"longitude":$longitude}}}'));
324+
}
325+
317326
/// Add a constraint to the query that requires a particular key's value match another QueryBuilder
318327
void whereMatchesQuery<E extends ParseObject>(
319328
String column, QueryBuilder<E> query) {

packages/dart/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: parse_server_sdk
22
description: Dart plugin for Parse Server, (https://parseplatform.org), (https://back4app.com)
3-
version: 3.1.10
3+
version: 3.1.11
44
homepage: https://github.com/parse-community/Parse-SDK-Flutter
55

66
environment:

packages/dart/test/parse_query_test.dart

+71
Original file line numberDiff line numberDiff line change
@@ -327,5 +327,76 @@ void main() {
327327

328328
expect(result.query, expectedQuery.query);
329329
});
330+
331+
test('wherePolygonContains', () async {
332+
// arrange
333+
final QueryBuilder<ParseObject> queryBuilder =
334+
QueryBuilder<ParseObject>(ParseObject('TEST_SCHEMA', client: client));
335+
double latitude = 84.17724609375;
336+
double longitude = -53.69670647530323;
337+
ParseGeoPoint point =
338+
ParseGeoPoint(latitude: latitude, longitude: longitude);
339+
queryBuilder.wherePolygonContains("geometry", point);
340+
341+
var desiredOutput = {
342+
"results": [
343+
{
344+
"objectId": "eT9muOxBTK",
345+
"createdAt": "2022-07-25T13:46:06.092Z",
346+
"updatedAt": "2022-07-25T13:46:23.586Z",
347+
"geometry": {
348+
"type": "Polygon",
349+
"coordinates": [
350+
[
351+
[84.17724609375, -53.69670647530323],
352+
[83.1884765625, -54.61025498157913],
353+
[84.814453125, -55.14120964449505],
354+
[85.67138671875, -54.40614309031968],
355+
[84.17724609375, -53.69670647530323]
356+
]
357+
]
358+
}
359+
}
360+
]
361+
};
362+
363+
when(client.get(
364+
any,
365+
options: anyNamed("options"),
366+
onReceiveProgress: anyNamed("onReceiveProgress"),
367+
)).thenAnswer((_) async => ParseNetworkResponse(
368+
statusCode: 200, data: jsonEncode(desiredOutput)));
369+
370+
// act
371+
ParseResponse response = await queryBuilder.query();
372+
ParseObject parseObject = response.results?.first;
373+
374+
final Uri result = Uri.parse(verify(client.get(
375+
captureAny,
376+
options: anyNamed("options"),
377+
onReceiveProgress: anyNamed("onReceiveProgress"),
378+
)).captured.single);
379+
380+
var queryDesiredOutput = {
381+
"geometry": {
382+
"\$geoIntersects": {
383+
"\$point": {
384+
"__type": "GeoPoint",
385+
"latitude": latitude,
386+
"longitude": longitude
387+
}
388+
}
389+
}
390+
};
391+
final Uri expectedQuery =
392+
Uri(query: 'where=' + jsonEncode(queryDesiredOutput));
393+
394+
// assert
395+
expect(response.results?.first, isA<ParseObject>());
396+
expect(parseObject.objectId, "eT9muOxBTK");
397+
expect(parseObject.containsKey("geometry"), true);
398+
expect(result.path, '/classes/TEST_SCHEMA');
399+
expect(result.query, expectedQuery.query);
400+
});
330401
});
331402
}

0 commit comments

Comments
 (0)