call method
Tests whether a location (lon
, lat
) matches the locationSet
rules.
First checks for exclude
rules, so excluding a country but including
a city in it won't work. Empty rules satisfy any location.
Implementation
bool call(double lon, double lat, LocationSet locationSet) {
if (locationSet.isEmpty) return true;
bool anyIncludes = false;
// First check circular areas, since it's the fastest.
if (locationSet.excludeCircular.any((area) => area.contains(lon, lat)))
return false;
anyIncludes |=
locationSet.includeCircular.any((area) => area.contains(lon, lat));
// Now check additional polygons.
final List<String> includeGeojson = locationSet.include
.where((element) => element.endsWith('.geojson'))
.toList();
final List<String> excludeGeojson = locationSet.exclude
.where((element) => element.endsWith('.geojson'))
.toList();
if (includeGeojson.isNotEmpty || excludeGeojson.isNotEmpty) {
final List<String> geojsonIds = additionalPolygons
.all(lon, lat)
.map((e) => e['id'] as String)
.toList();
if (excludeGeojson.any((id) => geojsonIds.contains(id))) return false;
anyIncludes |= includeGeojson.any((id) => geojsonIds.contains(id));
}
// And finally employ CountryCoder for the remaining ids.
if (locationSet.exclude
.where((element) => !element.endsWith('.geojson'))
.any((id) => countryCoder.isIn(lon: lon, lat: lat, inside: id)))
return false;
// If the list is empty, consider it including everything.
if (locationSet.include.isEmpty) return true;
anyIncludes |= locationSet.include
.where((element) => !element.endsWith('.geojson'))
.any((id) => countryCoder.isIn(lon: lon, lat: lat, inside: id));
return anyIncludes;
}