Skip to content

Commit d764aa8

Browse files
author
Les Moffat
committed
RD-1001 Changes options so that presets are respected
1 parent 99d6df4 commit d764aa8

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

src/Map.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,11 @@ export class Map extends maplibregl.Map {
263263
}
264264

265265
private initSpace({ options = this.options, before }: { options?: MapOptions; before: string }) {
266-
if (this.space && this.getLayer(this.space.id)) {
266+
if (this.space) {
267+
if (!this.getLayer(this.space.id)) {
268+
// If the space layer is already initialized but not added to the map, we add it now
269+
this.addLayer(this.space, before);
270+
}
267271
return;
268272
}
269273

@@ -993,10 +997,9 @@ export class Map extends maplibregl.Map {
993997
});
994998

995999
try {
996-
console.log("[Map.setStyle]: Setting style:", styleInfo.style);
9971000
super.setStyle(styleInfo.style, options);
9981001
} catch (e) {
999-
this.styleInProcess = false;
1002+
// this.styleInProcess = false;
10001003
console.error("[Map.setStyle]: Error while setting style:", e);
10011004
}
10021005

src/custom-layers/CubemapLayer/CubemapLayer.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ function configureOptions(inputOptions: CubemapLayerConstructorOptions | true, d
7070

7171
// path / faces will not be defined at this point
7272
// so we don't need to delete them
73-
return outputOptions as CubemapLayerConstructorOptions;
73+
return {
74+
...outputOptions,
75+
color: outputOptions.color ?? cubemapPresets[presetName].color ?? "hsl(233,100%,92%)",
76+
} as CubemapLayerConstructorOptions;
7477
}
7578

7679
class CubemapLayer implements CustomLayerInterface {
@@ -346,6 +349,7 @@ class CubemapLayer implements CustomLayerInterface {
346349
}
347350
this.imageIsAnimating = false;
348351
this.imageFadeInDelta = 0.0;
352+
return;
349353
};
350354

351355
requestAnimationFrame(animateIn);
@@ -362,7 +366,7 @@ class CubemapLayer implements CustomLayerInterface {
362366
return Promise.resolve(); // If already animating, just resolve
363367
}
364368
return new Promise((resolve) => {
365-
const animateIn = () => {
369+
const animateOut = () => {
366370
this.imageFadeInDelta = Math.min(this.imageFadeInDelta + 0.05, 1.0);
367371
this.currentFadeOpacity = lerp(1.0, 0.0, this.imageFadeInDelta);
368372
this.map.triggerRepaint();
@@ -373,10 +377,10 @@ class CubemapLayer implements CustomLayerInterface {
373377
resolve();
374378
return;
375379
}
376-
requestAnimationFrame(animateIn);
380+
requestAnimationFrame(animateOut);
377381
};
378382

379-
requestAnimationFrame(animateIn);
383+
requestAnimationFrame(animateOut);
380384
});
381385
}
382386

@@ -500,17 +504,20 @@ class CubemapLayer implements CustomLayerInterface {
500504
* Finally, it calls `updateCubemap` to apply the changes and trigger a repaint of the map.
501505
*/
502506
public async setCubemap(cubemap: CubemapDefinition): Promise<void> {
503-
const color = parseColorStringToVec4(cubemap.color);
504-
if (cubemap.color && this.targetBgColor.toString() !== color.toString()) {
505-
this.setBgColor(color);
506-
}
507-
508507
const facesKey = JSON.stringify(cubemap.faces ?? cubemap.preset ?? cubemap.path);
509508

510509
if (facesKey && this.currentFacesDefinitionKey !== facesKey) {
511510
await this.setCubemapFaces(cubemap);
512511
}
513512

513+
const color = parseColorStringToVec4(cubemap.color);
514+
if (cubemap.color && this.targetBgColor.toString() !== color.toString()) {
515+
this.setBgColor(color);
516+
} else if (cubemap.preset && cubemap.preset in cubemapPresets) {
517+
const preset = cubemapPresets[cubemap.preset];
518+
this.setBgColor(parseColorStringToVec4(preset.color));
519+
}
520+
514521
this.updateCubemap();
515522
}
516523

src/custom-layers/CubemapLayer/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export type CubemapLayerConstructorOptions = CubemapDefinition & {};
1010

1111
export const cubemapPresets: Record<string, CubemapDefinition> = {
1212
stars: {
13-
color: "white",
13+
color: "hsl(233,100%,92%)",
1414
preset: "stars",
1515
},
1616
space: {

0 commit comments

Comments
 (0)