Skip to content

Commit 0785c2b

Browse files
committed
added map-change event for extents, added test cases for map-change events
1 parent 56a8791 commit 0785c2b

File tree

3 files changed

+92
-0
lines changed

3 files changed

+92
-0
lines changed

src/map-extent.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ export class HTMLExtentElement extends HTMLElement {
158158
this._handleChange();
159159
this._calculateBounds();
160160
this._layerControlCheckbox.checked = newValue !== null;
161+
this.dispatchEvent(new CustomEvent('map-change'));
161162
})
162163
.catch((error) => {
163164
console.log(
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<!doctype html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="utf-8">
6+
<title>map-projectionchange event</title>
7+
<!-- the layer in this map should continue to be visible when you change
8+
the viewer projection from OSMTILE to CBMTILE. -->
9+
<script type="module" src="/mapml.js"></script>
10+
<style>
11+
mapml-viewer {
12+
width: 100%;
13+
height: 100vh
14+
}
15+
</style>
16+
</head>
17+
18+
<body>
19+
<mapml-viewer projection="OSMTILE" zoom="14" lat="45.406314" lon="-75.6883335" controls=""
20+
controlslist="geolocation">
21+
<map-layer data-testid="layer" label="OpenStreetMap" checked="">
22+
<map-link rel="license" title="© OpenStreetMap contributors CC BY-SA"
23+
href="https://www.openstreetmap.org/copyright"></map-link>
24+
<map-extent data-testid="extent" units="OSMTILE" checked="checked">
25+
<map-input name="z" type="zoom" value="18" min="0" max="18"></map-input>
26+
<map-input name="x" type="location" units="tilematrix" axis="column" min="0" max="262144"></map-input>
27+
<map-input name="y" type="location" units="tilematrix" axis="row" min="0" max="262144"></map-input>
28+
<map-link rel="tile" tref="https://tile.openstreetmap.org/{z}/{x}/{y}.png"></map-link>
29+
</map-extent>
30+
</map-layer>
31+
</mapml-viewer>
32+
</body>
33+
34+
</html>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { test, expect, chromium } from '@playwright/test';
2+
3+
test.describe('map change event 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('events/map-change-event.html');
12+
});
13+
14+
test.afterAll(async function () {
15+
await context.close();
16+
});
17+
18+
test('Map change event for layers work', async () => {
19+
let layerClicked = 0;
20+
page.on('console', (msg) => {
21+
if (msg.text() === 'Layer clicked') {
22+
layerClicked++;
23+
}
24+
});
25+
26+
await page.evaluate(() => {
27+
const layer = document.querySelector('map-layer');
28+
layer.addEventListener('map-change', () => {
29+
console.log('Layer clicked');
30+
});
31+
layer.checked = false;
32+
layer.checked = true;
33+
});
34+
35+
expect(layerClicked).toBe(2);
36+
});
37+
38+
test('Map change event for sub-layers work', async () => {
39+
let extentClicked = 0;
40+
page.on('console', (msg) => {
41+
if (msg.text() === 'Sub-layer clicked') {
42+
extentClicked++;
43+
}
44+
});
45+
46+
await page.evaluate(() => {
47+
const extent = document.querySelector('map-extent');
48+
extent.addEventListener('map-change', () => {
49+
console.log('Sub-layer clicked');
50+
});
51+
extent.checked = false;
52+
extent.checked = true;
53+
});
54+
55+
expect(extentClicked).toBe(2);
56+
});
57+
});

0 commit comments

Comments
 (0)