soda-angular
Version:
Socrata SODA client for Angular
56 lines (55 loc) • 2.15 kB
JavaScript
import { Intersects } from '../../soql-query/clauses/where/functions/intersects';
import { WithinBox } from '../../soql-query/clauses/where/functions/within-box';
import { WithinCircle } from '../../soql-query/clauses/where/functions/within-circle';
import { WithinPolygon } from '../../soql-query/clauses/where/functions/within-polygon';
import { WhereValue } from '../../soql-query/clauses/where/where-value';
export class GeometryFilter {
constructor(query, column, ...prependOperators) {
this.query = query;
this.column = column;
if (!query) {
throw new Error("query must be provided");
}
if (!column) {
throw new Error("column must be provided");
}
this.prependOperators = prependOperators;
}
intersects(geometry) {
if (!geometry) {
throw new Error("Geometry must be provided");
}
const filter = new Intersects(this.column, new WhereValue(geometry));
return this.addFilter(filter);
}
withinCircle(point, radius) {
if (!location) {
throw new Error("Point must be provided");
}
if (!radius) {
throw new Error("Radius must be provided");
}
const filter = new WithinCircle(this.column, new WhereValue(point), radius);
return this.addFilter(filter);
}
withinBox(start, end) {
if (!start) {
throw new Error("Start point must be provided");
}
if (!end) {
throw new Error("End point must be provided");
}
const filter = new WithinBox(this.column, new WhereValue(start), new WhereValue(end));
return this.addFilter(filter);
}
withinPolygon(multiPolygon) {
if (!multiPolygon) {
throw new Error("MultiPolygon must be provided");
}
const filter = new WithinPolygon(this.column, new WhereValue(multiPolygon));
return this.addFilter(filter);
}
addFilter(filter) {
return this.query.addFilter(...this.prependOperators, filter);
}
}