@@ -15,6 +15,8 @@ import {newStubStyle} from './utils';
1515import browser from '../../../src/util/browser' ;
1616import EvaluationParameters from '../../../src/style/evaluation_parameters' ;
1717
18+ import type { StyleSpecification } from 'mapbox-gl' ;
19+
1820function createStyleJSON ( properties ) {
1921 return { version : 8 ,
2022 sources : { } ,
@@ -3851,3 +3853,40 @@ test('Style#getFragmentStyle', async () => {
38513853 // Fragment should return itself when fragmentId is `undefined`
38523854 expect ( basemapFragment2 . getFragmentStyle ( ) ) . toBe ( basemapFragment2 ) ;
38533855} ) ;
3856+
3857+ describe ( 'feature-state with imported layer targets' , ( ) => {
3858+ async function loadCollidingRootAndImport ( ) {
3859+ const { style} = newStubStyle ( ) ;
3860+ const fragment = createStyleJSON ( {
3861+ sources : { shared : { type : 'geojson' , data : { type : 'FeatureCollection' , features : [ ] } } } ,
3862+ layers : [ { id : 'fragment-layer' , type : 'circle' , source : 'shared' } ]
3863+ } ) as StyleSpecification ;
3864+ const root = createStyleJSON ( {
3865+ sources : { shared : { type : 'geojson' , data : { type : 'FeatureCollection' , features : [ ] } } } ,
3866+ layers : [ { id : 'root-layer' , type : 'circle' , source : 'shared' } ] ,
3867+ imports : [ { id : 'fragment' , url : '' , data : fragment } ]
3868+ } ) as StyleSpecification ;
3869+ style . loadJSON ( root ) ;
3870+ await waitFor ( style , 'style.load' ) ;
3871+ return { style, fragmentStyle : style . getFragmentStyle ( 'fragment' ) } ;
3872+ }
3873+
3874+ test ( 'imported-layer setFeatureState writes to the fragment source, not the colliding root source' , async ( ) => {
3875+ const { style, fragmentStyle} = await loadCollidingRootAndImport ( ) ;
3876+ const importedLayerId = makeFQID ( 'fragment-layer' , 'fragment' ) ;
3877+
3878+ style . setFeatureState ( { id : 1 , target : { layerId : importedLayerId } } , { hover : true } ) ;
3879+
3880+ expect ( fragmentStyle . getFeatureState ( { source : 'shared' , id : 1 } ) ) . toEqual ( { hover : true } ) ;
3881+ expect ( style . getFeatureState ( { source : 'shared' , id : 1 } ) ) . toEqual ( { } ) ;
3882+ } ) ;
3883+
3884+ test ( 'root-layer setFeatureState still writes to the root source' , async ( ) => {
3885+ const { style, fragmentStyle} = await loadCollidingRootAndImport ( ) ;
3886+
3887+ style . setFeatureState ( { id : 2 , target : { layerId : 'root-layer' } } , { hover : true } ) ;
3888+
3889+ expect ( style . getFeatureState ( { source : 'shared' , id : 2 } ) ) . toEqual ( { hover : true } ) ;
3890+ expect ( fragmentStyle . getFeatureState ( { source : 'shared' , id : 2 } ) ) . toEqual ( { } ) ;
3891+ } ) ;
3892+ } ) ;
0 commit comments