Skip to content

Commit 2c5e5cd

Browse files
hyperknotlouwersHarelM
authored
Revert geometry-type implementation changes, bring spec in line with historic behavior (#966)
* revert geometry-type changes * Revert "Fixes geometry type filter (#924)" This reverts commit 2ed393e. * update description * Update changelog, scratch out previous change. * Use backticks in v8.json * Update CHANGELOG.md --------- Co-authored-by: Bart Louwers <[email protected]> Co-authored-by: Harel M <[email protected]>
1 parent 1a8b7a5 commit 2c5e5cd

File tree

14 files changed

+33
-444
lines changed

14 files changed

+33
-444
lines changed

CHANGELOG.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
## main
22

33
### ✨ Features and improvements
4-
- _...Add new stuff here..._
4+
5+
- Adjust `geometry-type` expression specification and MapLibre GL JS implementation to the historic behavior of only returning `Point`, `LineString` or `Polygon`, not the `Multi...` variants of these. This reverts a recent change to the implementation, which was causing issues in a [large number of styles](https://github.com/maplibre/maplibre-style-spec/issues/965).
56

67
### 🐞 Bug fixes
78
- _...Add new stuff here..._
@@ -10,7 +11,7 @@
1011

1112
### 🐞 Bug fixes
1213

13-
- Fix issue with `geomtry-type` filter ([#924](https://github.com/maplibre/maplibre-style-spec/pull/924))
14+
- ~~Fix issue with `geomtry-type` filter ([#924](https://github.com/maplibre/maplibre-style-spec/pull/924))~~ This was reverted in 23.0.0 due to causing issues in [a large number of styles](https://github.com/maplibre/maplibre-style-spec/issues/965).
1415

1516
## 22.0.0
1617

@@ -33,7 +34,7 @@
3334

3435
### ✨ Features and improvements
3536

36-
- Aligned the implementation of `["geometry-type"]` with [its spec](https://maplibre.org/maplibre-style-spec/expressions/#geometry-type). Now, when applicable, `["geometry-type"]` returns values not available while using `"$type"`: `"MultiPoint"`, `"MultiLineString"`, and `"MultiPolygon"`. The behaviour of `"$type"` has not changed. ([#519](https://github.com/maplibre/maplibre-style-spec/pull/519))
37+
- ~~Aligned the implementation of `["geometry-type"]` with [its spec](https://maplibre.org/maplibre-style-spec/expressions/#geometry-type). Now, when applicable, `["geometry-type"]` returns values not available while using `"$type"`: `"MultiPoint"`, `"MultiLineString"`, and `"MultiPolygon"`. The behaviour of `"$type"` has not changed. ([#519](https://github.com/maplibre/maplibre-style-spec/pull/519))~~ This was reverted in 23.0.0 due to causing issues in [a large number of styles](https://github.com/maplibre/maplibre-style-spec/issues/965).
3738

3839
## 20.4.0
3940

src/expression/compound_expression.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ CompoundExpression.register(expressions, {
461461
'filter-type-==': [
462462
BooleanType,
463463
[StringType],
464-
(ctx, [v]) => ctx.geometryDollarType() === (v as any).value
464+
(ctx, [v]) => ctx.geometryType() === (v as any).value
465465
],
466466
'filter-<': [
467467
BooleanType,
@@ -548,7 +548,7 @@ CompoundExpression.register(expressions, {
548548
'filter-type-in': [
549549
BooleanType,
550550
[array(StringType)],
551-
(ctx, [v]) => (v as any).value.indexOf(ctx.geometryDollarType()) >= 0
551+
(ctx, [v]) => (v as any).value.indexOf(ctx.geometryType()) >= 0
552552
],
553553
'filter-id-in': [
554554
BooleanType,

src/expression/definitions/within.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,9 @@ export class Within implements Expression {
192192

193193
evaluate(ctx: EvaluationContext) {
194194
if (ctx.geometry() != null && ctx.canonicalID() != null) {
195-
if (ctx.geometryDollarType() === 'Point') {
195+
if (ctx.geometryType() === 'Point') {
196196
return pointsWithinPolygons(ctx, this.geometries);
197-
} else if (ctx.geometryDollarType() === 'LineString') {
197+
} else if (ctx.geometryType() === 'LineString') {
198198
return linesWithinPolygons(ctx, this.geometries);
199199
}
200200
}
Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,9 @@
11
import type {FormattedSection} from './types/formatted';
22
import type {GlobalProperties, Feature, FeatureState} from './index';
33
import {ICanonicalTileID} from '../tiles_and_coordinates';
4-
import {hasMultipleOuterRings} from '../util/classify_rings';
54
import {Color} from './types/color';
65

76
const geometryTypes = ['Unknown', 'Point', 'LineString', 'Polygon'];
8-
const simpleGeometryType = {
9-
'Unknown': 'Unknown',
10-
'Point': 'Point',
11-
'MultiPoint': 'Point',
12-
'LineString': 'LineString',
13-
'MultiLineString': 'LineString',
14-
'Polygon': 'Polygon',
15-
'MultiPolygon': 'Polygon'
16-
};
177

188
export class EvaluationContext {
199
globals: GlobalProperties;
@@ -24,7 +14,6 @@ export class EvaluationContext {
2414
canonical: ICanonicalTileID;
2515

2616
_parseColorCache: {[_: string]: Color};
27-
_geometryType: string;
2817

2918
constructor() {
3019
this.globals = null;
@@ -40,33 +29,8 @@ export class EvaluationContext {
4029
return this.feature && 'id' in this.feature ? this.feature.id : null;
4130
}
4231

43-
geometryDollarType() {
44-
return this.feature ?
45-
typeof this.feature.type === 'number' ? geometryTypes[this.feature.type] : simpleGeometryType[this.feature.type] :
46-
null;
47-
}
48-
4932
geometryType() {
50-
let geometryType = this.feature.type;
51-
if (typeof geometryType !== 'number') {
52-
return geometryType;
53-
}
54-
geometryType = geometryTypes[this.feature.type];
55-
if (geometryType === 'Unknown') {
56-
return geometryType;
57-
}
58-
const geom = this.geometry();
59-
const len = geom.length;
60-
if (len === 1) {
61-
return geometryType;
62-
}
63-
if (geometryType !== 'Polygon') {
64-
return `Multi${geometryType}`;
65-
}
66-
if (hasMultipleOuterRings(geom)) {
67-
return 'MultiPolygon';
68-
}
69-
return 'Polygon';
33+
return this.feature ? typeof this.feature.type === 'number' ? geometryTypes[this.feature.type] : this.feature.type : null;
7034
}
7135

7236
geometry() {
@@ -89,3 +53,4 @@ export class EvaluationContext {
8953
return cached;
9054
}
9155
}
56+

src/feature_filter/convert.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ function runtimeTypeChecks(expectedTypes: ExpectedTypes): ExpressionFilterSpecif
128128
function convertComparisonOp(property: string, value: any, op: string, expectedTypes?: ExpectedTypes | null): ExpressionFilterSpecification {
129129
let get;
130130
if (property === '$type') {
131-
return convertInOp('$type', [value], op === '!=');
131+
return [op, ['geometry-type'], value] as ExpressionFilterSpecification;
132132
} else if (property === '$id') {
133133
get = ['id'];
134134
} else {
@@ -162,10 +162,6 @@ function convertInOp(property: string, values: Array<any>, negate = false): Expr
162162

163163
let get: ExpressionSpecification;
164164
if (property === '$type') {
165-
const len = values.length;
166-
for (let i = 0; i < len; i++) {
167-
values.push(`Multi${values[i]}`);
168-
}
169165
get = ['geometry-type'];
170166
} else if (property === '$id') {
171167
get = ['id'];

0 commit comments

Comments
 (0)