Skip to content

Commit 1a9a08b

Browse files
authored
Add distance expression support (#642)
* Initial commit to distance calculations * Add changelog item * Added polygon tests * Fix lint * Fix algorithm, imporve tests readablility * Add classify rings tests from the maplibre repo * Add wrap type * Make the threshold symetrical. * Allow using classify rings with a mapbox point type, remove circular dependencies.
1 parent e7b5c2b commit 1a9a08b

File tree

23 files changed

+1463
-249
lines changed

23 files changed

+1463
-249
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ dist
55
.DS_Store
66
*/**/*.g.ts
77
.cache
8-
docs/*
8+
coverage/
99
site/
10+
docs/*
1011
!docs/assets/extra.css
1112
!docs/assets/logo.svg
1213
!docs/README.md

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
## main
22

33
### ✨ Features and improvements
4+
5+
- Support `distance` expression in web style spec - [#642](https://github.com/maplibre/maplibre-style-spec/pull/642)
46
- _...Add new stuff here..._
57

68
### 🐞 Bug fixes

build/generate-style-spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ export type ExpressionSpecification =
199199
...(ExpressionInputType | ExpressionInputType[] | ExpressionSpecification)[], // repeated as above
200200
ExpressionInputType | ExpressionSpecification]
201201
| ['within', unknown | ExpressionSpecification]
202+
| ['distance', unknown | ExpressionSpecification]
202203
// Ramps, scales, curves
203204
| ['interpolate', InterpolationSpecification, number | ExpressionSpecification,
204205
...(number | number[] | ColorSpecification | ExpressionSpecification)[]] // alternating number and number | number[] | ColorSpecification

package-lock.json

Lines changed: 13 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@
5252
"@mapbox/unitbezier": "^0.0.1",
5353
"json-stringify-pretty-compact": "^4.0.0",
5454
"minimist": "^1.2.8",
55+
"quickselect": "^2.0.0",
5556
"rw": "^1.3.3",
56-
"sort-object": "^3.0.3"
57+
"sort-object": "^3.0.3",
58+
"tinyqueue": "^2.0.3"
5759
},
5860
"sideEffects": false,
5961
"devDependencies": {

src/expression/compound_expression.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ import Literal from './definitions/literal';
2121
import Assertion from './definitions/assertion';
2222
import Coercion from './definitions/coercion';
2323
import Var from './definitions/var';
24+
import Distance from './definitions/distance';
2425

2526
import type {Expression, ExpressionRegistry} from './expression';
2627
import type {Value} from './values';
27-
2828
import type {Type} from './types';
2929

3030
import {typeOf, Color, validateRGBA, toString as valueToString} from './values';
@@ -664,6 +664,8 @@ function isExpressionConstant(expression: Expression) {
664664
return false;
665665
} else if (expression instanceof Within) {
666666
return false;
667+
} else if (expression instanceof Distance) {
668+
return false;
667669
}
668670

669671
const isTypeAnnotation = expression instanceof Coercion ||
@@ -715,6 +717,9 @@ function isFeatureConstant(e: Expression) {
715717
if (e instanceof Within) {
716718
return false;
717719
}
720+
if (e instanceof Distance) {
721+
return false;
722+
}
718723

719724
let result = true;
720725
e.eachChild(arg => {

0 commit comments

Comments
 (0)