@@ -1025,10 +1025,6 @@ export class Map extends maplibregl.Map {
1025
1025
const oldStyle = this . getStyle ( ) as StyleSpecificationWithMetaData ;
1026
1026
const newStyle = styleInfo . style as StyleSpecificationWithMetaData ;
1027
1027
1028
- // the type returned from getStyle is incorrect, it can be null
1029
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
1030
- const spaceAndHaloMustAwaitTerrain = oldStyle ?. terrain ?. source !== newStyle ?. terrain ?. source || oldStyle ?. terrain ?. exaggeration !== newStyle ?. terrain ?. exaggeration ;
1031
-
1032
1028
try {
1033
1029
super . setStyle ( styleInfo . style , options ) ;
1034
1030
} catch ( e ) {
@@ -1041,40 +1037,58 @@ export class Map extends maplibregl.Map {
1041
1037
return this ;
1042
1038
}
1043
1039
1044
- const setSpaceAndHalo = ( ) => {
1040
+ const setSpaceAndHaloFromStyle = ( ) => {
1045
1041
this . setSpaceFromStyle ( { style : styleInfo . style as StyleSpecificationWithMetaData } ) ;
1046
1042
this . setHaloFromStyle ( { style : styleInfo . style as StyleSpecificationWithMetaData } ) ;
1047
1043
} ;
1048
1044
1049
- if ( spaceAndHaloMustAwaitTerrain ) {
1050
- void this . once ( "terrain" , setSpaceAndHalo ) ;
1051
- } else {
1052
- setSpaceAndHalo ( ) ;
1045
+ const handleStyleLoad = ( ) => {
1046
+ const targetBeforeLayer = this . getLayersOrder ( ) [ 0 ] ;
1047
+ const styleSpec = styleInfo . style as StyleSpecificationWithMetaData ;
1048
+ if ( this . space ) {
1049
+ this . setSpaceFromStyle ( { style : styleSpec } ) ;
1050
+ } else {
1051
+ this . initSpace ( { before : targetBeforeLayer , spec : styleSpec . metadata ?. maptiler ?. space } ) ;
1052
+ }
1053
+
1054
+ if ( this . halo ) {
1055
+ this . setHaloFromStyle ( { style : styleSpec } ) ;
1056
+ } else {
1057
+ this . initHalo ( { before : targetBeforeLayer , spec : styleSpec . metadata ?. maptiler ?. halo } ) ;
1058
+ }
1059
+ } ;
1060
+
1061
+ if ( this . styleInProcess && ! this . spaceboxLoadingState . styleLoadCallbackSet ) {
1062
+ // this handles setting space and halo from style on load
1063
+ void this . once ( "style.load" , handleStyleLoad ) ;
1064
+ this . spaceboxLoadingState . styleLoadCallbackSet = true ;
1053
1065
return this ;
1054
1066
}
1055
1067
1056
- if ( this . styleInProcess ) {
1057
- // this handles setting space and halo from style on load
1058
- void this . once ( "style.load" , ( ) => {
1059
- const targetBeforeLayer = this . getLayersOrder ( ) [ 0 ] ;
1060
- const styleSpec = styleInfo . style as StyleSpecificationWithMetaData ;
1061
- if ( this . space ) {
1062
- this . setSpaceFromStyle ( { style : styleSpec } ) ;
1063
- } else {
1064
- this . initSpace ( { before : targetBeforeLayer , spec : styleSpec . metadata ?. maptiler ?. space } ) ;
1065
- }
1068
+ // the type returned from getStyle is incorrect, it can be null
1069
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
1070
+ const spaceAndHaloMustAwaitTerrain = oldStyle ?. terrain ?. source !== newStyle ?. terrain ?. source || oldStyle ?. terrain ?. exaggeration !== newStyle ?. terrain ?. exaggeration ;
1066
1071
1067
- if ( this . halo ) {
1068
- this . setHaloFromStyle ( { style : styleSpec } ) ;
1069
- } else {
1070
- this . initHalo ( { before : targetBeforeLayer , spec : styleSpec . metadata ?. maptiler ?. halo } ) ;
1071
- }
1072
- } ) ;
1072
+ if ( spaceAndHaloMustAwaitTerrain ) {
1073
+ void this . once ( "terrain" , setSpaceAndHaloFromStyle ) ;
1074
+ return this ;
1075
+ }
1076
+
1077
+ const projectionFieldDeleted = ! newStyle ?. projection ?. type ;
1078
+ if ( projectionFieldDeleted ) {
1079
+ this . styleInProcess = true ;
1080
+ return this ;
1073
1081
}
1074
1082
1083
+ handleStyleLoad ( ) ;
1084
+
1075
1085
return this ;
1076
1086
}
1077
1087
1088
+ private spaceboxLoadingState = {
1089
+ styleLoadCallbackSet : false ,
1090
+ } ;
1091
+
1078
1092
/**
1079
1093
* Adds a [MapLibre style layer](https://maplibre.org/maplibre-style-spec/layers)
1080
1094
* to the map's style.
0 commit comments