Skip to content

Commit 8ee4a04

Browse files
authored
Merge pull request #25 from hothsys/bug/3D-mode
Bug: Fix to flatten buildings when 3D toggle is off
2 parents 276e25d + 9f34b2d commit 8ee4a04

4 files changed

Lines changed: 35 additions & 8 deletions

File tree

js/map.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ function _patchStyleWater(styleObj) {
109109
// Colors pre-compensated for canvas filter brightness(1.8) contrast(0.9).
110110
if (_mapStyle === 'dark') {
111111
// Darker water for Dark Map
112-
const waterColor = '#131619';
112+
const waterColor = '#17212b';
113113
for (const layer of styleObj.layers) {
114114
if (!layer.paint) layer.paint = {};
115115
if (layer.type === 'fill' && /^water/.test(layer.id)) {
@@ -357,10 +357,17 @@ function applyExtraLayers() {
357357

358358
function apply3DBuildings() {
359359
if (!map.getSource || !map.getSource('openmaptiles')) return;
360-
const shouldShow = buildings3DVisible && !['satellite', 'satellite3d', 'terrain3d', 'globe'].includes(_mapStyle);
361-
if (shouldShow && !map.getLayer('matrix-buildings-3d')) {
362-
// Insert below the first symbol layer so road/POI labels render on top of buildings
363-
const firstSymbol = map.getStyle()?.layers?.find(l => l.type === 'symbol');
360+
const noBuildings = ['satellite', 'satellite3d', 'terrain3d', 'globe'];
361+
const shouldShow = buildings3DVisible && !noBuildings.includes(_mapStyle);
362+
// Toggle the style's native fill-extrusion layers (OpenFreeMap styles include 3D buildings)
363+
const styleLayers = map.getStyle()?.layers || [];
364+
const nativeExtrusions = styleLayers.filter(l => l.type === 'fill-extrusion' && l.id !== 'matrix-buildings-3d');
365+
if (nativeExtrusions.length) {
366+
const vis = shouldShow ? 'visible' : 'none';
367+
nativeExtrusions.forEach(l => map.setLayoutProperty(l.id, 'visibility', vis));
368+
} else if (shouldShow && !map.getLayer('matrix-buildings-3d')) {
369+
// Style lacks native 3D buildings — add custom layer (e.g. dark mode)
370+
const firstSymbol = styleLayers.find(l => l.type === 'symbol');
364371
map.addLayer({
365372
id: 'matrix-buildings-3d',
366373
type: 'fill-extrusion',

tests/helpers/test-setup.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ async function setupApp(page) {
2121
return !!document.querySelector('#map canvas') && typeof db !== 'undefined' && db !== null;
2222
} catch { return false; }
2323
},
24-
{ timeout: 20000 }
24+
{ timeout: 45000 }
2525
);
2626
}
2727

@@ -40,7 +40,7 @@ async function uploadTestPhotos(page, fileNames) {
4040
const toast = document.getElementById('toast');
4141
return toast && toast.classList.contains('show') && toast.textContent.includes('Added');
4242
},
43-
{ timeout: 20000 }
43+
{ timeout: 45000 }
4444
);
4545
// Expand all collapsed year groups so photo cards render in the DOM
4646
// (the app uses virtual scrolling and year groups start collapsed)

tests/playwright.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ module.exports = defineConfig({
1111
baseURL: 'http://localhost:8765',
1212
headless: true,
1313
viewport: { width: 1280, height: 800 },
14-
actionTimeout: 30000,
1514
serviceWorkers: 'block',
1615
},
1716
projects: [

tests/specs/settings-export-import.spec.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,25 @@ test.describe('Settings & Export/Import', () => {
9393
expect(imported).toBe(1);
9494
await expect(page.locator('#stat-photos')).toHaveText('1');
9595
});
96+
97+
test('empty map cache clears tiles and shows toast', async ({ page }) => {
98+
// Pre-create a fake tile file so there's something to delete
99+
await page.request.post(
100+
'/api/tiles/cache?url=https://tiles.openfreemap.org/planet/test/0/0/0.pbf',
101+
{ data: Buffer.from('fake tile'), headers: { 'Content-Type': 'application/octet-stream' } }
102+
);
103+
104+
await page.locator('.settings-btn').click();
105+
await expect(page.locator('#settings-dropdown')).toHaveClass(/open/);
106+
107+
// Override the beforeEach dismiss handler to accept the confirmation dialog
108+
page.removeAllListeners('dialog');
109+
page.on('dialog', d => d.accept());
110+
111+
await page.locator('.settings-item', { hasText: 'Empty Map Cache' }).click();
112+
113+
// Success toast confirms tiles were removed
114+
await expect(page.locator('#toast')).toContainText('Map cache cleared', { timeout: 5000 });
115+
await expect(page.locator('#toast')).toHaveClass(/success/);
116+
});
96117
});

0 commit comments

Comments
 (0)