@@ -1393,6 +1393,33 @@ describe('Style.setGlobalState', () => {
1393
1393
expect ( style . sourceCaches [ 'fill-source-id' ] . reload ) . toHaveBeenCalled ( ) ;
1394
1394
} ) ;
1395
1395
1396
+ test ( 'reloads sources when state property is used in layout property' , async ( ) => {
1397
+ const style = new Style ( getStubMap ( ) ) ;
1398
+ style . loadJSON ( createStyleJSON ( {
1399
+ sources : {
1400
+ 'line-source-id' : createGeoJSONSource ( )
1401
+ } ,
1402
+ layers : [ {
1403
+ id : 'first-layer-id' ,
1404
+ type : 'line' ,
1405
+ source : 'line-source-id' ,
1406
+ layout : {
1407
+ 'line-join' : [ 'global-state' , 'lineJoin' ]
1408
+ }
1409
+ } ]
1410
+ } ) ) ;
1411
+
1412
+ await style . once ( 'style.load' ) ;
1413
+
1414
+ style . sourceCaches [ 'line-source-id' ] . resume = vi . fn ( ) ;
1415
+ style . sourceCaches [ 'line-source-id' ] . reload = vi . fn ( ) ;
1416
+
1417
+ style . setGlobalState ( { lineJoin : { default : 'bevel' } } ) ;
1418
+
1419
+ expect ( style . sourceCaches [ 'line-source-id' ] . resume ) . toHaveBeenCalled ( ) ;
1420
+ expect ( style . sourceCaches [ 'line-source-id' ] . reload ) . toHaveBeenCalled ( ) ;
1421
+ } ) ;
1422
+
1396
1423
test ( 'does not reload sources when state property is set to the same value as current one' , async ( ) => {
1397
1424
const style = new Style ( getStubMap ( ) ) ;
1398
1425
style . loadJSON ( createStyleJSON ( {
@@ -1451,6 +1478,36 @@ describe('Style.setGlobalState', () => {
1451
1478
expect ( style . sourceCaches [ 'circle-source-id' ] . resume ) . not . toHaveBeenCalled ( ) ;
1452
1479
expect ( style . sourceCaches [ 'circle-source-id' ] . reload ) . not . toHaveBeenCalled ( ) ;
1453
1480
} ) ;
1481
+
1482
+ test ( 'does not reload sources when new state property is used in paint property while state property used in layout is unchanged' , async ( ) => {
1483
+ const style = new Style ( getStubMap ( ) ) ;
1484
+ style . loadJSON ( createStyleJSON ( {
1485
+ sources : {
1486
+ 'line-source-id' : createGeoJSONSource ( )
1487
+ } ,
1488
+ layers : [ {
1489
+ id : 'first-layer-id' ,
1490
+ type : 'line' ,
1491
+ source : 'line-source-id' ,
1492
+ layout : {
1493
+ 'line-join' : [ 'global-state' , 'lineJoin' ]
1494
+ } ,
1495
+ paint : {
1496
+ 'line-color' : [ 'global-state' , 'lineColor' ]
1497
+ }
1498
+ } ]
1499
+ } ) ) ;
1500
+
1501
+ await style . once ( 'style.load' ) ;
1502
+
1503
+ style . sourceCaches [ 'line-source-id' ] . resume = vi . fn ( ) ;
1504
+ style . sourceCaches [ 'line-source-id' ] . reload = vi . fn ( ) ;
1505
+
1506
+ style . setGlobalState ( { lineColor : { default : 'red' } } ) ;
1507
+
1508
+ expect ( style . sourceCaches [ 'line-source-id' ] . resume ) . not . toHaveBeenCalled ( ) ;
1509
+ expect ( style . sourceCaches [ 'line-source-id' ] . reload ) . not . toHaveBeenCalled ( ) ;
1510
+ } ) ;
1454
1511
} ) ;
1455
1512
1456
1513
describe ( 'Style.setGlobalStateProperty' , ( ) => {
@@ -1541,6 +1598,63 @@ describe('Style.setGlobalStateProperty', () => {
1541
1598
expect ( style . sourceCaches [ 'fill-source-id' ] . reload ) . not . toHaveBeenCalled ( ) ;
1542
1599
} ) ;
1543
1600
1601
+ test ( 'reloads sources when state property is used in layout property' , async ( ) => {
1602
+ const style = new Style ( getStubMap ( ) ) ;
1603
+ style . loadJSON ( createStyleJSON ( {
1604
+ sources : {
1605
+ 'line-1-source-id' : createGeoJSONSource ( ) ,
1606
+ 'line-2-source-id' : createGeoJSONSource ( ) ,
1607
+ 'line-3-source-id' : createGeoJSONSource ( )
1608
+ } ,
1609
+ layers : [ {
1610
+ id : 'first-layer-id' ,
1611
+ type : 'line' ,
1612
+ source : 'line-1-source-id' ,
1613
+ layout : {
1614
+ 'line-join' : [ 'global-state' , 'lineJoin' ]
1615
+ }
1616
+ } , {
1617
+ id : 'second-layer-id' ,
1618
+ type : 'line' ,
1619
+ source : 'line-3-source-id'
1620
+ } , {
1621
+ id : 'third-layer-id' ,
1622
+ type : 'line' ,
1623
+ source : 'line-2-source-id' ,
1624
+ layout : {
1625
+ 'line-join' : [ 'global-state' , 'lineJoin' ]
1626
+ }
1627
+ } , {
1628
+ id : 'fourth-layer-id' ,
1629
+ type : 'line' ,
1630
+ source : 'line-3-source-id' ,
1631
+ layout : {
1632
+ 'line-cap' : [ 'global-state' , 'lineCap' ]
1633
+ }
1634
+ } ]
1635
+ } ) ) ;
1636
+
1637
+ await style . once ( 'style.load' ) ;
1638
+
1639
+ style . sourceCaches [ 'line-1-source-id' ] . resume = vi . fn ( ) ;
1640
+ style . sourceCaches [ 'line-1-source-id' ] . reload = vi . fn ( ) ;
1641
+ style . sourceCaches [ 'line-2-source-id' ] . resume = vi . fn ( ) ;
1642
+ style . sourceCaches [ 'line-2-source-id' ] . reload = vi . fn ( ) ;
1643
+ style . sourceCaches [ 'line-3-source-id' ] . resume = vi . fn ( ) ;
1644
+ style . sourceCaches [ 'line-3-source-id' ] . reload = vi . fn ( ) ;
1645
+
1646
+ style . setGlobalStateProperty ( 'lineJoin' , 'bevel' ) ;
1647
+
1648
+ // sources line-1 and line-2 should be reloaded
1649
+ expect ( style . sourceCaches [ 'line-1-source-id' ] . resume ) . toHaveBeenCalled ( ) ;
1650
+ expect ( style . sourceCaches [ 'line-1-source-id' ] . reload ) . toHaveBeenCalled ( ) ;
1651
+ expect ( style . sourceCaches [ 'line-2-source-id' ] . resume ) . toHaveBeenCalled ( ) ;
1652
+ expect ( style . sourceCaches [ 'line-2-source-id' ] . reload ) . toHaveBeenCalled ( ) ;
1653
+ // source line-3 should not be reloaded
1654
+ expect ( style . sourceCaches [ 'line-3-source-id' ] . resume ) . not . toHaveBeenCalled ( ) ;
1655
+ expect ( style . sourceCaches [ 'line-3-source-id' ] . reload ) . not . toHaveBeenCalled ( ) ;
1656
+ } ) ;
1657
+
1544
1658
test ( 'does not reload sources when state property is set to the same value as current one' , async ( ) => {
1545
1659
const style = new Style ( getStubMap ( ) ) ;
1546
1660
style . loadJSON ( createStyleJSON ( {
@@ -1599,6 +1713,36 @@ describe('Style.setGlobalStateProperty', () => {
1599
1713
expect ( style . sourceCaches [ 'circle-source-id' ] . resume ) . not . toHaveBeenCalled ( ) ;
1600
1714
expect ( style . sourceCaches [ 'circle-source-id' ] . reload ) . not . toHaveBeenCalled ( ) ;
1601
1715
} ) ;
1716
+
1717
+ test ( 'does not reload sources when state property is used in paint property while a different state property used in layout is unchanged' , async ( ) => {
1718
+ const style = new Style ( getStubMap ( ) ) ;
1719
+ style . loadJSON ( createStyleJSON ( {
1720
+ sources : {
1721
+ 'line-source-id' : createGeoJSONSource ( )
1722
+ } ,
1723
+ layers : [ {
1724
+ id : 'first-layer-id' ,
1725
+ type : 'line' ,
1726
+ source : 'line-source-id' ,
1727
+ layout : {
1728
+ 'line-join' : [ 'global-state' , 'lineJoin' ]
1729
+ } ,
1730
+ paint : {
1731
+ 'line-color' : [ 'global-state' , 'lineColor' ]
1732
+ }
1733
+ } ]
1734
+ } ) ) ;
1735
+
1736
+ await style . once ( 'style.load' ) ;
1737
+
1738
+ style . sourceCaches [ 'line-source-id' ] . resume = vi . fn ( ) ;
1739
+ style . sourceCaches [ 'line-source-id' ] . reload = vi . fn ( ) ;
1740
+
1741
+ style . setGlobalStateProperty ( 'lineColor' , 'red' ) ;
1742
+
1743
+ expect ( style . sourceCaches [ 'line-source-id' ] . resume ) . not . toHaveBeenCalled ( ) ;
1744
+ expect ( style . sourceCaches [ 'line-source-id' ] . reload ) . not . toHaveBeenCalled ( ) ;
1745
+ } ) ;
1602
1746
} ) ;
1603
1747
1604
1748
describe ( 'Style.addLayer' , ( ) => {
@@ -1660,7 +1804,7 @@ describe('Style.addLayer', () => {
1660
1804
style . loadJSON ( createStyleJSON ( ) ) ;
1661
1805
await style . once ( 'style.load' ) ;
1662
1806
const errorPromise = style . once ( 'error' ) ;
1663
-
1807
+
1664
1808
style . addLayer ( {
1665
1809
id : 'background' ,
1666
1810
type : 'background' ,
@@ -1887,9 +2031,9 @@ describe('Style.addLayer', () => {
1887
2031
} as LayerSpecification ;
1888
2032
1889
2033
await style . once ( 'style.load' ) ;
1890
- const errorPromise = style . once ( 'error' ) ;
2034
+ const errorPromise = style . once ( 'error' ) ;
1891
2035
style . addLayer ( layer ) ;
1892
-
2036
+
1893
2037
const { error} = await errorPromise ;
1894
2038
expect ( error . message ) . toMatch ( / d o e s n o t e x i s t o n s o u r c e / ) ;
1895
2039
} ) ;
@@ -2078,7 +2222,7 @@ describe('Style.setPaintProperty', () => {
2078
2222
2079
2223
await source . once ( 'data' ) ;
2080
2224
vi . spyOn ( sourceCache , 'reload' ) ;
2081
-
2225
+
2082
2226
source . setData ( { 'type' : 'FeatureCollection' , 'features' : [ ] } ) ;
2083
2227
style . setPaintProperty ( 'circle' , 'circle-color' , { type : 'identity' , property : 'foo' } ) ;
2084
2228
await waitForEvent ( source , 'data' , ( e ) => e . sourceDataType === 'content' ) ;
0 commit comments