Skip to content

Commit

Permalink
omit a warning if maxzoom <= clusterMaxZoom for geojson sources (#4604)
Browse files Browse the repository at this point in the history
* omit a warning if maxzoom <= clusterMaxZoom for geojson sources

* fix lint issues

* CHANGELOG entry
  • Loading branch information
andrewharvey authored Aug 27, 2024
1 parent 6799ead commit 2200020
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
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
- Support multiple layers in `map.on`, `map.once` and `map.off` methods ([#4279](https://github.com/maplibre/maplibre-gl-js/pull/4401))
- Ensure GeoJSON cluster sources emit a console warning if `maxzoom` is less than or equal to `clusterMaxZoom` since in this case you may see unexpected results. ([#4604](https://github.com/maplibre/maplibre-gl-js/pull/4604))
- _...Add new stuff here..._

### 🐞 Bug fixes
Expand Down
19 changes: 19 additions & 0 deletions src/source/geojson_source.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,25 @@ const hawkHill = {
}]
} as GeoJSON.GeoJSON;

describe('GeoJSONSource#constructor', () => {
const mapStub = {
_requestManager: {
transformRequest: (url) => { return {url}; }
}
} as any;
test('warn if maxzoom <= clusterMaxZoom', () => {
const warn = jest.spyOn(console, 'warn').mockImplementation(() => {});

const source = new GeoJSONSource('id', {data: hawkHill, maxzoom: 4, clusterMaxZoom: 4} as GeoJSONSourceOptions, mockDispatcher, undefined);
source.map = mapStub;
source.load();

expect(warn).toHaveBeenCalledWith('The maxzoom value "4" is expected to be greater than the clusterMaxZoom value "4".');

warn.mockRestore();
});
});

describe('GeoJSONSource#setData', () => {
function createSource(opts?) {
opts = opts || {};
Expand Down
6 changes: 5 additions & 1 deletion src/source/geojson_source.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Event, ErrorEvent, Evented} from '../util/evented';

import {extend} from '../util/util';
import {extend, warnOnce} from '../util/util';
import {EXTENT} from '../data/extent';
import {ResourceType} from '../util/request_manager';
import {browser} from '../util/browser';
Expand Down Expand Up @@ -158,6 +158,10 @@ export class GeoJSONSource extends Evented implements Source {

const scale = EXTENT / this.tileSize;

if (options.clusterMaxZoom !== undefined && this.maxzoom <= options.clusterMaxZoom) {
warnOnce(`The maxzoom value "${this.maxzoom}" is expected to be greater than the clusterMaxZoom value "${options.clusterMaxZoom}".`);
}

// sent to the worker, along with `url: ...` or `data: literal geojson`,
// so that it can load/parse/index the geojson data
// extending with `options.workerOptions` helps to make it easy for
Expand Down

0 comments on commit 2200020

Please sign in to comment.