Skip to content

Commit 7e351d1

Browse files
committed
Fix #980
1 parent a94847a commit 7e351d1

File tree

5 files changed

+107
-16
lines changed

5 files changed

+107
-16
lines changed

index.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,21 @@
8383
<map-link rel="tile" tref="https://tile.openstreetmap.org/{z}/{x}/{y}.png"></map-link>
8484
</map-extent>
8585
</layer->
86+
<layer- label="Restaurants" checked="">
87+
<map-meta name="extent" content="top-left-easting=-8433179, top-left-northing=5689316, bottom-right-easting=-8420968, bottom-right-northing=5683139"></map-meta>
88+
<map-extent units="OSMTILE" checked="">
89+
<map-select id="restaurants" name="cusine">
90+
<map-option value="restaurants" selected="selected">All cuisines</map-option>
91+
<map-option value="african">African</map-option>
92+
<map-option value="asian">Asian</map-option>
93+
<map-option value="cajun">Cajun</map-option>
94+
<map-option value="indian">Indian</map-option>
95+
<map-option value="italian">Italian</map-option>
96+
<map-option value="mexican">Mexican</map-option>
97+
</map-select>
98+
<map-link tref="https://maps4html.org/experiments/shared/restaurants/{cusine}.mapml" rel="features"></map-link>
99+
</map-extent>
100+
</layer->
86101
</mapml-viewer>
87102
</body>
88103
</html>

src/mapml-viewer.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export class MapViewer extends HTMLElement {
8888
this.setAttribute('projection', val);
8989
})
9090
.catch(() => {
91-
throw new Error('Undefined projection:' + val);
91+
throw new Error('Undefined projection: ' + val);
9292
});
9393
}
9494
}
@@ -405,13 +405,18 @@ export class MapViewer extends HTMLElement {
405405
this._map.options.projection !== newValue
406406
) {
407407
const connect = reconnectLayers.bind(this);
408-
connect().then(() => {
409-
if (this._map && this._map.options.projection !== oldValue) {
410-
// this doesn't completely work either
411-
this._resetHistory();
412-
}
413-
if (this._debug) for (let i = 0; i < 2; i++) this.toggleDebug();
414-
});
408+
this.whenProjectionDefined(newValue)
409+
.then(() => connect())
410+
.then(() => {
411+
if (this._map && this._map.options.projection !== oldValue) {
412+
// this doesn't completely work either
413+
this._resetHistory();
414+
}
415+
if (this._debug) for (let i = 0; i < 2; i++) this.toggleDebug();
416+
})
417+
.catch(() => {
418+
throw new Error('Undefined projection: ' + newValue);
419+
});
415420
}
416421
break;
417422
}

src/web-map.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export class WebMap extends HTMLMapElement {
8989
this.setAttribute('projection', val);
9090
})
9191
.catch(() => {
92-
throw new Error('Undefined projection:' + val);
92+
throw new Error('Undefined projection: ' + val);
9393
});
9494
}
9595
}
@@ -460,13 +460,18 @@ export class WebMap extends HTMLMapElement {
460460
this._map.options.projection !== newValue
461461
) {
462462
const connect = reconnectLayers.bind(this);
463-
connect().then(() => {
464-
if (this._map && this._map.options.projection !== oldValue) {
465-
// this doesn't completely work either
466-
this._resetHistory();
467-
}
468-
if (this._debug) for (let i = 0; i < 2; i++) this.toggleDebug();
469-
});
463+
this.whenProjectionDefined(newValue)
464+
.then(() => connect())
465+
.then(() => {
466+
if (this._map && this._map.options.projection !== oldValue) {
467+
// this doesn't completely work either
468+
this._resetHistory();
469+
}
470+
if (this._debug) for (let i = 0; i < 2; i++) this.toggleDebug();
471+
})
472+
.catch(() => {
473+
throw new Error('Undefined projection: ' + newValue);
474+
});
470475
}
471476
break;
472477
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<title>Basic Mapml-Viewer</title>
6+
<meta charset="UTF-8">
7+
<script type="module" src="mapml-viewer.js"></script>
8+
<style>
9+
html {
10+
height: 100%
11+
}
12+
13+
body {
14+
height: inherit
15+
}
16+
17+
* {
18+
margin: 0;
19+
padding: 0;
20+
}
21+
</style>
22+
</head>
23+
24+
<body>
25+
<mapml-viewer data-testid="testviewer" style="height: 600px;width:500px;" projection="CBMTILE" zoom="0" lat="47" lon="-92" controls>
26+
<layer- data-testid="testlayer" label="CBMT - INLINE" checked>
27+
<map-meta name="zoom" content="min=0,max=25"></map-meta>
28+
<map-extent units="CBMTILE" checked hidden>
29+
<map-input name="zoomLevel" type="zoom" value="3" min="0" max="3" ></map-input>
30+
<map-input name="row" type="location" axis="row" units="tilematrix" min="14" max="21" ></map-input>
31+
<map-input name="col" type="location" axis="column" units="tilematrix" min="14" max="19" ></map-input>
32+
<map-link rel='tile' tref='/data/cbmt/{zoomLevel}/c{col}_r{row}.png' ></map-link>
33+
</map-extent>
34+
</layer->
35+
</mapml-viewer>
36+
</body>
37+
38+
</html>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { test, expect, chromium } from '@playwright/test';
2+
3+
test.describe('Playwright mapml-viewer issue-980 test', () => {
4+
let page;
5+
let context;
6+
test.beforeAll(async () => {
7+
context = await chromium.launchPersistentContext('');
8+
page =
9+
context.pages().find((page) => page.url() === 'about:blank') ||
10+
(await context.newPage());
11+
await page.goto('mapml-viewer-unknown-projection.html');
12+
await page.waitForTimeout(500);
13+
});
14+
15+
test.afterAll(async function () {
16+
await context.close();
17+
});
18+
19+
test('mapml-viewer projection set to unknown prj errors to console', async () => {
20+
let message;
21+
page.on('pageerror', exception => message = exception.message);
22+
const viewer = page.getByTestId('testviewer');
23+
await viewer.evaluate((v) => (v.projection = 'unknown'));
24+
// update the projection attribute on the viewer
25+
await page.waitForTimeout(5000);
26+
expect(message).toBe("Undefined projection: unknown");
27+
});
28+
});

0 commit comments

Comments
 (0)