Skip to content

Commit

Permalink
Add distance expression support (#642)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
HarelM authored May 4, 2024
1 parent e7b5c2b commit 1a9a08b
Show file tree
Hide file tree
Showing 23 changed files with 1,463 additions and 249 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ dist
.DS_Store
*/**/*.g.ts
.cache
docs/*
coverage/
site/
docs/*
!docs/assets/extra.css
!docs/assets/logo.svg
!docs/README.md
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## main

### ✨ Features and improvements

- Support `distance` expression in web style spec - [#642](https://github.com/maplibre/maplibre-style-spec/pull/642)
- _...Add new stuff here..._

### 🐞 Bug fixes
Expand Down
1 change: 1 addition & 0 deletions build/generate-style-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ export type ExpressionSpecification =
...(ExpressionInputType | ExpressionInputType[] | ExpressionSpecification)[], // repeated as above
ExpressionInputType | ExpressionSpecification]
| ['within', unknown | ExpressionSpecification]
| ['distance', unknown | ExpressionSpecification]
// Ramps, scales, curves
| ['interpolate', InterpolationSpecification, number | ExpressionSpecification,
...(number | number[] | ColorSpecification | ExpressionSpecification)[]] // alternating number and number | number[] | ColorSpecification
Expand Down
14 changes: 13 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@
"@mapbox/unitbezier": "^0.0.1",
"json-stringify-pretty-compact": "^4.0.0",
"minimist": "^1.2.8",
"quickselect": "^2.0.0",
"rw": "^1.3.3",
"sort-object": "^3.0.3"
"sort-object": "^3.0.3",
"tinyqueue": "^2.0.3"
},
"sideEffects": false,
"devDependencies": {
Expand Down
7 changes: 6 additions & 1 deletion src/expression/compound_expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import Literal from './definitions/literal';
import Assertion from './definitions/assertion';
import Coercion from './definitions/coercion';
import Var from './definitions/var';
import Distance from './definitions/distance';

import type {Expression, ExpressionRegistry} from './expression';
import type {Value} from './values';

import type {Type} from './types';

import {typeOf, Color, validateRGBA, toString as valueToString} from './values';
Expand Down Expand Up @@ -664,6 +664,8 @@ function isExpressionConstant(expression: Expression) {
return false;
} else if (expression instanceof Within) {
return false;
} else if (expression instanceof Distance) {
return false;
}

const isTypeAnnotation = expression instanceof Coercion ||
Expand Down Expand Up @@ -715,6 +717,9 @@ function isFeatureConstant(e: Expression) {
if (e instanceof Within) {
return false;
}
if (e instanceof Distance) {
return false;
}

let result = true;
e.eachChild(arg => {
Expand Down
Loading

0 comments on commit 1a9a08b

Please sign in to comment.