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

Added geoJSON source getBounds method #5403

Open
wants to merge 43 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
427b8b8
added geoJSON source getBounds method
AbelVM Jan 24, 2025
4447079
Bump dependabot/fetch-metadata from 2.2.0 to 2.3.0 (#141)
dependabot[bot] Jan 27, 2025
424ab5c
Bump stylelint from 16.13.2 to 16.14.0 (#142)
dependabot[bot] Jan 27, 2025
4790824
Bump @vitest/ui from 3.0.3 to 3.0.4 (#143)
dependabot[bot] Jan 27, 2025
ad8cf0a
geoJSON source getBounds method, tweaks 1
AbelVM Jan 27, 2025
15c6d00
Merge branch 'maplibre:main' into main
AbelVM Jan 27, 2025
e53ead9
Merge remote-tracking branch 'refs/remotes/origin/main'
AbelVM Jan 27, 2025
7a6e82f
geoJSON source getBounds method, change from promise to raw bounds
AbelVM Jan 27, 2025
3016268
Merge branch 'main' into main
HarelM Jan 27, 2025
a9640a4
geoJSON source getBounds method, fixed vitest version
AbelVM Jan 27, 2025
038fc08
geoJSON source getBounds method, overwrite packaje.json files from so…
AbelVM Jan 27, 2025
0a161f1
geoJSON source getBounds method, change back function type to promise
AbelVM Jan 27, 2025
6ce70fb
geoJSON source getBounds method, typing enforcement
AbelVM Jan 27, 2025
d8ac930
geoJSON source getBounds method, support single features
AbelVM Jan 27, 2025
f805489
geoJSON source getBounds method, cover any GeoJSON case
AbelVM Jan 27, 2025
ac7afa1
geoJSON source getBounds method, async test
AbelVM Jan 27, 2025
c112544
geoJSON source getBounds method, fixed tests and removed async stuff
AbelVM Jan 27, 2025
6c3e0cd
Bump vitest from 3.0.3 to 3.0.4 (#144)
dependabot[bot] Jan 28, 2025
7455aff
Bump pbf from 3.3.0 to 4.0.1 (#146)
dependabot[bot] Jan 28, 2025
91a8193
Bump @vitest/coverage-v8 from 3.0.3 to 3.0.4 (#147)
dependabot[bot] Jan 28, 2025
944c5d9
Bump @typescript-eslint/eslint-plugin from 8.21.0 to 8.22.0 (#148)
dependabot[bot] Jan 28, 2025
873b344
Bump @types/node from 22.10.10 to 22.12.0 (#149)
dependabot[bot] Jan 28, 2025
a471b2c
Bump @typescript-eslint/parser from 8.21.0 to 8.22.0 (#145)
dependabot[bot] Jan 28, 2025
2c493a1
geoJSON source getBounds method, back to async, still errors
AbelVM Jan 28, 2025
3a2e5c7
geoJSON source getBounds method, added missing unit tests
AbelVM Jan 28, 2025
8c60411
geoJSON source getBounds method, move tests from unit to integration
AbelVM Jan 28, 2025
0c49eda
geoJSON source getBounds method, move tests from unit to integration,…
AbelVM Jan 28, 2025
fffd20d
geoJSON source getBounds method, move tests from unit to integration,…
AbelVM Jan 28, 2025
c629dee
Merge branch 'main' into main
AbelVM Jan 28, 2025
059b744
geoJSON source getBounds method, move tests from unit to integration,…
AbelVM Jan 28, 2025
f33c64a
geoJSON source getBounds method, move tests from unit to integration,…
AbelVM Jan 28, 2025
6fd45ca
geoJSON source getBounds method, scoping tests
AbelVM Jan 28, 2025
d2642b7
geoJSON source getBounds method, scoping tests
AbelVM Jan 28, 2025
3cce7b8
geoJSON source getBounds method, added all tests as browser tests
AbelVM Jan 28, 2025
bbe2976
geoJSON source getBounds method, added all tests as browser tests
AbelVM Jan 28, 2025
cde489c
geoJSON source getBounds method, expectedBytes += 4
AbelVM Jan 28, 2025
9b5274c
geoJSON source getBounds method, trunked coordinates and other minor…
AbelVM Jan 28, 2025
6db2340
geoJSON source getBounds method, once => on
AbelVM Jan 28, 2025
97ed09c
geoJSON source getBounds method, once => on
AbelVM Jan 28, 2025
7f41246
geoJSON source getBounds method, back to old load event managing
AbelVM Jan 28, 2025
47c0856
Merge branch 'main' into main
AbelVM Jan 30, 2025
d323876
geoJSON source getBounds method, remove commented lines
AbelVM Jan 30, 2025
99a7b9e
Merge remote-tracking branch 'refs/remotes/origin/main'
AbelVM Jan 30, 2025
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
2 changes: 1 addition & 1 deletion .github/workflows/auto-merge-dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
steps:
- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v2.2.0
uses: dependabot/fetch-metadata@v2.3.0
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
- name: Approve Dependabot PRs
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### ✨ Features and improvements

- Added `getBounds()` method to `GeoJSONSource` ([#5403](https://github.com/maplibre/maplibre-gl-js/pull/5403))
- _...Add new stuff here..._

### 🐞 Bug fixes
Expand Down
55 changes: 42 additions & 13 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"@typescript-eslint/eslint-plugin": "^8.21.0",
"@typescript-eslint/parser": "^8.21.0",
"@vitest/coverage-v8": "3.0.3",
"@vitest/ui": "3.0.3",
"@vitest/ui": "3.0.4",
"address": "^2.0.3",
"autoprefixer": "^10.4.20",
"benchmark": "^2.1.4",
Expand Down Expand Up @@ -126,7 +126,7 @@
"shuffle-seed": "^1.1.6",
"source-map-explorer": "^2.5.3",
"st": "^3.0.1",
"stylelint": "^16.13.2",
"stylelint": "^16.14.0",
"stylelint-config-standard": "^37.0.0",
"ts-node": "^10.9.2",
"tslib": "^2.8.1",
Expand Down
9 changes: 9 additions & 0 deletions src/source/geojson_source.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {SubdivisionGranularitySetting} from '../render/subdivision_granularity_s
import {type ActorMessage, MessageType} from '../util/actor_messages';
import {type Actor} from '../util/actor';
import {MercatorTransform} from '../geo/projection/mercator_transform';
import {LngLatBounds} from '../geo/lng_lat_bounds';

const wrapDispatcher = (dispatcher) => {
return {
Expand Down Expand Up @@ -506,3 +507,11 @@ describe('GeoJSONSource#serialize', () => {
});
});
});

describe('GeoJSONSource#getBounds', () => {
test('returns bounds', () => {
const source = new GeoJSONSource('id', {data: hawkHill} as GeoJSONSourceOptions, mockDispatcher, undefined);
const bounds = new LngLatBounds([-122.493782, 37.82880237, -122.4833965, 37.83381888]);
expect(source.getBounds()).toBe(bounds);
});
});
19 changes: 19 additions & 0 deletions src/source/geojson_source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type {GeoJSONSourceDiff} from './geojson_source_diff';
import type {GeoJSONWorkerOptions, LoadGeoJSONParameters} from './geojson_worker_source';
import {type WorkerTileParameters} from './worker_source';
import {MessageType} from '../util/actor_messages';
import {LngLatBounds} from '../geo/lng_lat_bounds';

/**
* Options object for GeoJSONSource.
Expand Down Expand Up @@ -249,6 +250,24 @@ export class GeoJSONSource extends Evented implements Source {
return this.actor.sendAsync({type: MessageType.getData, data: options});
}

/**
* Allows to get the source's actual boundaries.
*
* @returns a promise which resolves to the source's actual boundaries
*/

async getBounds(): LngLatBounds {
const bounds = new LngLatBounds();
const data = await this.getData();
const coordinates = data.features
.map(f => f.geometry.coordinates.flat(Infinity))
.reduce((acc, cur) => [...acc, ...cur],[]);
for(let i = 0; i < coordinates.length - 1; i += 2){
bounds.extend([coordinates[i], coordinates[i+1]]);
}
return bounds;
}

/**
* To disable/enable clustering on the source options
* @param options - The options to set
Expand Down
Loading