diff --git a/src/style/style.js b/src/style/style.js index deff109dd11..45417adefce 100644 --- a/src/style/style.js +++ b/src/style/style.js @@ -878,12 +878,12 @@ class Style extends Evented { return; } - if (target.id && isNaN(featureId) || featureId < 0) { + if (target.id !== undefined && isNaN(featureId) || featureId < 0) { this.fire(new ErrorEvent(new Error(`The feature id parameter must be non-negative.`))); return; } - if (key && !target.id) { + if (key && (typeof target.id !== 'string' && typeof target.id !== 'number')) { this.fire(new ErrorEvent(new Error(`A feature id is requred to remove its specific state property.`))); return; } diff --git a/test/unit/ui/map.test.js b/test/unit/ui/map.test.js index 2c95c36c98b..8cd3605fb49 100755 --- a/test/unit/ui/map.test.js +++ b/test/unit/ui/map.test.js @@ -1524,6 +1524,27 @@ test('Map', (t) => { t.end(); }); }); + t.test('remove properties for zero-based feature IDs.', (t) => { + const map = createMap(t, { + style: { + "version": 8, + "sources": { + "geojson": createStyleSource() + }, + "layers": [] + } + }); + map.on('load', () => { + map.setFeatureState({ source: 'geojson', id: 0}, {'hover': true, 'foo': true}); + map.removeFeatureState({ source: 'geojson', id: 0}); + + const fState = map.getFeatureState({ source: 'geojson', id: 0}); + t.equal(fState.hover, undefined); + t.equal(fState.foo, undefined); + + t.end(); + }); + }); t.test('other properties persist when removing specific property', (t) => { const map = createMap(t, { style: {