Skip to content
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
ce82b04
"geometry-type" to identify Milti- features
zstadler Feb 2, 2024
3d55f64
Fix and extend tests
zstadler Feb 8, 2024
334103f
Lint fixes, incomplete
zstadler Feb 8, 2024
4675c8b
Linting, continued
zstadler Feb 8, 2024
e3b7448
Linting, var -> let, const
zstadler Feb 9, 2024
a05f9ea
Linting, completed
zstadler Feb 9, 2024
80eb2d8
Merge branch 'main' into geometry-type
zstadler Oct 16, 2024
feb0451
Merge commit '4e9e832' into geometry-type-merge
zstadler Oct 16, 2024
031dd80
Merge commit 'b3d112a' into geometry-type-merge
zstadler Oct 16, 2024
ae718af
Merge commit '9db6f8f' into geometry-type-merge
zstadler Oct 16, 2024
f66ee52
Merge commit '8e10188' into geometry-type-merge
zstadler Oct 16, 2024
25dc3d4
Merge remote-tracking branch 'upstream/main' into geometry-type-merge
zstadler Oct 16, 2024
7fc93c4
Merge remote-tracking branch 'upstream/main' into geometry-type
zstadler Oct 16, 2024
a7d7621
Move lost code changes to their new location
zstadler Oct 16, 2024
cbdd941
Reuse `calculateSignedArea`
zstadler Oct 16, 2024
253108a
Simplify `geometryType()` code
zstadler Oct 19, 2024
ebe3bc4
Split test
zstadler Oct 19, 2024
66741c3
Use variables for sample geometries.
zstadler Oct 19, 2024
5262c3d
Extract code into `hasMultipleOuterRings()`
zstadler Oct 19, 2024
3c27179
Update src/util/classify_rings.ts
zstadler Oct 19, 2024
2ed3000
Updated `Changelog.md`
zstadler Oct 19, 2024
28930b3
Add `["geomerty-type"]` tests
zstadler Oct 19, 2024
e182527
Rename test.json to test.json
HarelM Oct 22, 2024
3f114b4
Rename test.json to test.json
HarelM Oct 22, 2024
b72e2b8
Rename test.json to test.json
HarelM Oct 22, 2024
3f4d870
Rename test.json to test.json
HarelM Oct 22, 2024
bbe4b5e
Rename test.json to test.json
HarelM Oct 22, 2024
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
4 changes: 2 additions & 2 deletions src/expression/compound_expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ CompoundExpression.register(expressions, {
'filter-type-==': [
BooleanType,
[StringType],
(ctx, [v]) => ctx.geometryType() === (v as any).value
(ctx, [v]) => ctx.geometryDollarType() === (v as any).value
],
'filter-<': [
BooleanType,
Expand Down Expand Up @@ -548,7 +548,7 @@ CompoundExpression.register(expressions, {
'filter-type-in': [
BooleanType,
[array(StringType)],
(ctx, [v]) => (v as any).value.indexOf(ctx.geometryType()) >= 0
(ctx, [v]) => (v as any).value.indexOf(ctx.geometryDollarType()) >= 0
],
'filter-id-in': [
BooleanType,
Expand Down
4 changes: 2 additions & 2 deletions src/expression/definitions/within.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,9 @@ class Within implements Expression {

evaluate(ctx: EvaluationContext) {
if (ctx.geometry() != null && ctx.canonicalID() != null) {
if (ctx.geometryType() === 'Point') {
if (ctx.geometryDollarType() === 'Point') {
return pointsWithinPolygons(ctx, this.geometries);
} else if (ctx.geometryType() === 'LineString') {
} else if (ctx.geometryDollarType() === 'LineString') {
return linesWithinPolygons(ctx, this.geometries);
}
}
Expand Down
46 changes: 45 additions & 1 deletion src/expression/evaluation_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,18 @@ import {Color} from './values';
import type {FormattedSection} from './types/formatted';
import type {GlobalProperties, Feature, FeatureState} from './index';
import {ICanonicalTileID} from '../tiles_and_coordinates';
import {calculateSignedArea} from '../util/classify_rings';

const geometryTypes = ['Unknown', 'Point', 'LineString', 'Polygon'];
const simpleGeometryType = {
'Unknown': 'Unknown',
'Point': 'Point',
'MultiPoint': 'Point',
'LineString': 'LineString',
'MultiLineString': 'LineString',
'Polygon': 'Polygon',
'MultiPolygon': 'Polygon'
};

class EvaluationContext {
globals: GlobalProperties;
Expand All @@ -14,6 +24,7 @@ class EvaluationContext {
canonical: ICanonicalTileID;

_parseColorCache: {[_: string]: Color};
_geometryType: string;

constructor() {
this.globals = null;
Expand All @@ -29,8 +40,41 @@ class EvaluationContext {
return this.feature && 'id' in this.feature ? this.feature.id : null;
}

geometryDollarType() {
return this.feature ?
typeof this.feature.type === 'number' ? geometryTypes[this.feature.type] : simpleGeometryType[this.feature.type] :
null;
}

geometryType() {
return this.feature ? typeof this.feature.type === 'number' ? geometryTypes[this.feature.type] : this.feature.type : null;
let geometryType = this.feature.type;
if (typeof geometryType !== 'number') {
return geometryType;
}
geometryType = geometryTypes[this.feature.type];
if (geometryType === 'Unknown') {
return geometryType;
}
const geom = this.geometry();
const len = geom.length;
if (len === 1) {
return geometryType;
}
if (geometryType !== 'Polygon') {
return `Multi${geometryType}`;
}
// Following https://github.com/mapbox/vector-tile-js/blob/77851380b63b07fd0af3d5a3f144cc86fb39fdd1/lib/vectortilefeature.js#L197
for (let i = 0, ccw; i < len; i++) {
const area = calculateSignedArea(geom[i]);
if (area === 0) continue;
if (ccw === undefined) {
ccw = area < 0;
} else if (ccw === area < 0) {
// Same direction as the first ring -> a second outer ring
return 'MultiPolygon';
}
}
return geometryType;
}

geometry() {
Expand Down
6 changes: 5 additions & 1 deletion src/feature_filter/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ function runtimeTypeChecks(expectedTypes: ExpectedTypes): ExpressionFilterSpecif
function convertComparisonOp(property: string, value: any, op: string, expectedTypes?: ExpectedTypes | null): ExpressionFilterSpecification {
let get;
if (property === '$type') {
return [op, ['geometry-type'], value] as ExpressionFilterSpecification;
return convertInOp('$type', [value], op === '!=');
} else if (property === '$id') {
get = ['id'];
} else {
Expand Down Expand Up @@ -162,6 +162,10 @@ function convertInOp(property: string, values: Array<any>, negate = false): Expr

let get: ExpressionSpecification;
if (property === '$type') {
const len = values.length;
for (let i = 0; i < len; i++) {
values.push(`Multi${values[i]}`);
}
get = ['geometry-type'];
} else if (property === '$id') {
get = ['id'];
Expand Down
Loading