Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for distance style spec expression #4076

Merged
merged 4 commits into from
May 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
## main
- Update Popup methods `addClass` & `removeClass` to return instance of Popup ([#3975](https://github.com/maplibre/maplibre-gl-js/pull/3975))

### ✨ Features and improvements
- _...Add new stuff here..._

- Update `Popup`'s methods `addClass` and `removeClass` to return an instance of Popup ([#3975](https://github.com/maplibre/maplibre-gl-js/pull/3975))
- New map option to decide whether to cancel previous pending tiles while zooming in ([#4051](https://github.com/maplibre/maplibre-gl-js/pull/4051))
- Sprites include optional textFitHeight and textFitWidth values ([#4019](https://github.com/maplibre/maplibre-gl-js/pull/4019))
- Add support for `distance` expression ([#4076](https://github.com/maplibre/maplibre-gl-js/pull/4076))
- _...Add new stuff here..._

### 🐞 Bug fixes
- _...Add new stuff here..._
Expand Down
12 changes: 7 additions & 5 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@mapbox/unitbezier": "^0.0.1",
"@mapbox/vector-tile": "^1.3.1",
"@mapbox/whoots-js": "^3.1.0",
"@maplibre/maplibre-gl-style-spec": "^20.1.1",
"@maplibre/maplibre-gl-style-spec": "^20.2.0",
"@types/geojson": "^7946.0.14",
"@types/geojson-vt": "3.2.5",
"@types/junit-report-builder": "^3.0.2",
Expand Down
2 changes: 1 addition & 1 deletion src/data/bucket/fill_bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {SegmentVector} from '../segment';
import {ProgramConfigurationSet} from '../program_configuration';
import {LineIndexArray, TriangleIndexArray} from '../index_array_type';
import earcut from 'earcut';
import {classifyRings} from '../../util/classify_rings';
import {classifyRings} from '@maplibre/maplibre-gl-style-spec';
const EARCUT_MAX_RINGS = 500;
import {register} from '../../util/web_worker_transfer';
import {hasPattern, addPatternDependencies} from './pattern_bucket_features';
Expand Down
2 changes: 1 addition & 1 deletion src/data/bucket/fill_extrusion_bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {EXTENT} from '../extent';
import earcut from 'earcut';
import mvt from '@mapbox/vector-tile';
const vectorTileFeatureTypes = mvt.VectorTileFeature.types;
import {classifyRings} from '../../util/classify_rings';
import {classifyRings} from '@maplibre/maplibre-gl-style-spec';
const EARCUT_MAX_RINGS = 500;
import {register} from '../../util/web_worker_transfer';
import {hasPattern, addPatternDependencies} from './pattern_bucket_features';
Expand Down
3 changes: 1 addition & 2 deletions src/symbol/symbol_layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
allowsLetterSpacing
} from '../util/script_detection';
import {findPoleOfInaccessibility} from '../util/find_pole_of_inaccessibility';
import {classifyRings} from '../util/classify_rings';
import {EXTENT} from '../data/extent';
import {SymbolBucket} from '../data/bucket/symbol_bucket';
import {EvaluationParameters} from '../style/evaluation_parameters';
Expand All @@ -31,7 +30,7 @@ import type {PossiblyEvaluatedPropertyValue} from '../style/properties';
import Point from '@mapbox/point-geometry';
import murmur3 from 'murmurhash-js';
import {getIconPadding, SymbolPadding} from '../style/style_layer/symbol_style_layer';
import {VariableAnchorOffsetCollection} from '@maplibre/maplibre-gl-style-spec';
import {VariableAnchorOffsetCollection, classifyRings} from '@maplibre/maplibre-gl-style-spec';
import {getTextVariableAnchorOffset, evaluateVariableOffset, INVALID_TEXT_OFFSET, TextAnchor, TextAnchorEnum} from '../style/style_layer/variable_text_anchor';

// The symbol layout process needs `text-size` evaluated at up to five different zoom levels, and
Expand Down
147 changes: 0 additions & 147 deletions src/util/classify_rings.test.ts

This file was deleted.

50 changes: 0 additions & 50 deletions src/util/classify_rings.ts

This file was deleted.

26 changes: 1 addition & 25 deletions src/util/util.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Point from '@mapbox/point-geometry';
import {arraysIntersect, bezier, clamp, clone, deepEqual, easeCubicInOut, extend, filterObject, findLineIntersection, isClosedPolygon, isCounterClockwise, isPowerOfTwo, keysDifference, mapObject, nextPowerOfTwo, parseCacheControl, pick, readImageDataUsingOffscreenCanvas, readImageUsingVideoFrame, uniqueId, wrap} from './util';
import {arraysIntersect, bezier, clamp, clone, deepEqual, easeCubicInOut, extend, filterObject, findLineIntersection, isCounterClockwise, isPowerOfTwo, keysDifference, mapObject, nextPowerOfTwo, parseCacheControl, pick, readImageDataUsingOffscreenCanvas, readImageUsingVideoFrame, uniqueId, wrap} from './util';
import {Canvas} from 'canvas';

describe('util', () => {
Expand Down Expand Up @@ -197,30 +197,6 @@ describe('util isCounterClockwise', () => {
});
});

describe('util isClosedPolygon', () => {
test('not enough points', done => {
const polygon = [new Point(0, 0), new Point(1, 0), new Point(0, 1)];

expect(isClosedPolygon(polygon)).toBe(false);
done();
});

test('not equal first + last point', done => {
const polygon = [new Point(0, 0), new Point(1, 0), new Point(0, 1), new Point(1, 1)];

expect(isClosedPolygon(polygon)).toBe(false);
done();
});

test('closed polygon', done => {
const polygon = [new Point(0, 0), new Point(1, 0), new Point(1, 1), new Point(0, 1), new Point(0, 0)];

expect(isClosedPolygon(polygon)).toBe(true);
done();
});

});

describe('util parseCacheControl', () => {
test('max-age', done => {
expect(parseCacheControl('max-age=123456789')).toEqual({
Expand Down
41 changes: 0 additions & 41 deletions src/util/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,47 +291,6 @@ export function findLineIntersection(a1: Point, a2: Point, b1: Point, b2: Point)
return new Point(a1.x + (aInterpolation * aDeltaX), a1.y + (aInterpolation * aDeltaY));
}

/**
* Returns the signed area for the polygon ring. Positive areas are exterior rings and
* have a clockwise winding. Negative areas are interior rings and have a counter clockwise
* ordering.
*
* @param ring - Exterior or interior ring
*/
export function calculateSignedArea(ring: Array<Point>): number {
let sum = 0;
for (let i = 0, len = ring.length, j = len - 1, p1, p2; i < len; j = i++) {
p1 = ring[i];
p2 = ring[j];
sum += (p2.x - p1.x) * (p1.y + p2.y);
}
return sum;
}

/**
* Detects closed polygons, first + last point are equal
*
* @param points - array of points
* @returns `true` if the points are a closed polygon
*/
export function isClosedPolygon(points: Array<Point>): boolean {
// If it is 2 points that are the same then it is a point
// If it is 3 points with start and end the same then it is a line
if (points.length < 4)
return false;

const p1 = points[0];
const p2 = points[points.length - 1];

if (Math.abs(p1.x - p2.x) > 0 ||
Math.abs(p1.y - p2.y) > 0) {
return false;
}

// polygon simplification can produce polygons with zero area and more than 3 points
return Math.abs(calculateSignedArea(points)) > 0.01;
}

/**
* Converts spherical coordinates to cartesian coordinates.
*
Expand Down
2 changes: 1 addition & 1 deletion test/build/min.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('test min build', () => {
const decreaseQuota = 4096;

// feel free to update this value after you've checked that it has changed on purpose :-)
const expectedBytes = 776381;
const expectedBytes = 787777;

expect(actualBytes - expectedBytes).toBeLessThan(increaseQuota);
expect(expectedBytes - actualBytes).toBeLessThan(decreaseQuota);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading