Skip to content

Commit 229a6e2

Browse files
lesbaaLes Moffat
andauthored
Rd 1105 projection in style does not change space (#221)
* RD-1105 Fix bug where spacebox breaks when style.json changed * 3.6.1 --------- Co-authored-by: Les Moffat <[email protected]>
1 parent c27df50 commit 229a6e2

File tree

7 files changed

+64
-31
lines changed

7 files changed

+64
-31
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# MapTiler SDK Changelog
22

3+
## 3.6.1
4+
5+
### ✨ Features and improvements
6+
- None
7+
8+
### 🐛 Bug fixes
9+
- Fixes a bug that breaks spacebox when projection is changed in style.json
10+
11+
### Others
12+
- None
13+
314
## 3.6.0
415

516
### ✨ Features and improvements

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@maptiler/sdk",
3-
"version": "3.6.0",
3+
"version": "3.6.1",
44
"description": "The Javascript & TypeScript map SDK tailored for MapTiler Cloud",
55
"author": "MapTiler",
66
"module": "dist/maptiler-sdk.mjs",

src/Map.ts

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,10 +1025,6 @@ export class Map extends maplibregl.Map {
10251025
const oldStyle = this.getStyle() as StyleSpecificationWithMetaData;
10261026
const newStyle = styleInfo.style as StyleSpecificationWithMetaData;
10271027

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-
10321028
try {
10331029
super.setStyle(styleInfo.style, options);
10341030
} catch (e) {
@@ -1041,40 +1037,58 @@ export class Map extends maplibregl.Map {
10411037
return this;
10421038
}
10431039

1044-
const setSpaceAndHalo = () => {
1040+
const setSpaceAndHaloFromStyle = () => {
10451041
this.setSpaceFromStyle({ style: styleInfo.style as StyleSpecificationWithMetaData });
10461042
this.setHaloFromStyle({ style: styleInfo.style as StyleSpecificationWithMetaData });
10471043
};
10481044

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;
10531065
return this;
10541066
}
10551067

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;
10661071

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;
10731081
}
10741082

1083+
handleStyleLoad();
1084+
10751085
return this;
10761086
}
10771087

1088+
private spaceboxLoadingState = {
1089+
styleLoadCallbackSet: false,
1090+
};
1091+
10781092
/**
10791093
* Adds a [MapLibre style layer](https://maplibre.org/maplibre-style-spec/layers)
10801094
* to the map's style.

src/custom-layers/CubemapLayer/CubemapLayer.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,10 @@ class CubemapLayer implements CustomLayerInterface {
410410
* @throws Error if the map, cubemap, or texture is undefined.
411411
*/
412412
public render(gl: WebGLRenderingContext | WebGL2RenderingContext, _options: CustomRenderMethodInput): void {
413+
if (!this.map.isGlobeProjection()) {
414+
return;
415+
}
416+
413417
if (this.map === undefined) {
414418
throw new Error("[CubemapLayer]: Map is undefined");
415419
}

src/custom-layers/RadialGradientLayer/RadialGradientLayer.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,10 @@ export class RadialGradientLayer implements CustomLayerInterface {
233233
throw new Error("[RadialGradientLayer]: Map is undefined");
234234
}
235235

236+
if (!this.map.isGlobeProjection()) {
237+
return;
238+
}
239+
236240
if (this.plane === undefined) {
237241
throw new Error("[RadialGradientLayer]: Plane is undefined");
238242
}

src/utils/webgl-utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export function loadShader({ gl, type, source }: { gl: WebGLContext; type: GLenu
3737
*
3838
* @returns WebGL program
3939
*/
40-
export function createShadersSetProgram({ gl, vertexShaderSource, fragmentShaderSource }: { gl: WebGLContext; vertexShaderSource: string; fragmentShaderSource: string }) {
40+
export function createShaderProgram({ gl, vertexShaderSource, fragmentShaderSource }: { gl: WebGLContext; vertexShaderSource: string; fragmentShaderSource: string }) {
4141
const vertexShader = loadShader({
4242
gl,
4343
type: gl.VERTEX_SHADER,
@@ -101,7 +101,7 @@ export function createObject3D<Attribute extends string, Uniform extends string>
101101
vertices: Array<number>;
102102
indices?: Array<number>;
103103
}): Object3D<Attribute, Uniform> {
104-
const shaderProgram = createShadersSetProgram({ gl, vertexShaderSource, fragmentShaderSource });
104+
const shaderProgram = createShaderProgram({ gl, vertexShaderSource, fragmentShaderSource });
105105

106106
const attributesLocations = attributesKeys.reduce<Record<string, number>>((acc, key) => {
107107
acc[key] = gl.getAttribLocation(shaderProgram, `a_${key}`);

0 commit comments

Comments
 (0)