-
Notifications
You must be signed in to change notification settings - Fork 16
Added map-change event for extents #1005
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ae58ad3
added map-change event for extents, added test cases for map-change e…
yushan-mu 015b188
Added timeout
yushan-mu c736d38
Changed to headed mode, added different methods of changing checking/…
yushan-mu ef6f283
Cleaned up some parts
yushan-mu 34aedbd
Modified logic so that map-change is only called when layer/extent is…
yushan-mu 3a6437b
Edited comments, removed timeout
yushan-mu 602f031
Added test for checking/unchecking with keyboard
yushan-mu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="utf-8"> | ||
<title>map-change event</title> | ||
<!-- the layer in this map should continue to be visible when you change | ||
the viewer projection from OSMTILE to CBMTILE. --> | ||
<script type="module" src="/mapml.js"></script> | ||
<style> | ||
mapml-viewer { | ||
width: 100%; | ||
height: 100vh | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<mapml-viewer projection="OSMTILE" zoom="14" lat="45.406314" lon="-75.6883335" controls="" | ||
controlslist="geolocation"> | ||
<map-layer label="OpenStreetMap" checked=""> | ||
<map-link rel="license" title="© OpenStreetMap contributors CC BY-SA" | ||
href="https://www.openstreetmap.org/copyright"></map-link> | ||
<map-extent units="OSMTILE" checked="checked"> | ||
<map-input name="z" type="zoom" value="18" min="0" max="18"></map-input> | ||
<map-input name="x" type="location" units="tilematrix" axis="column" min="0" max="262144"></map-input> | ||
<map-input name="y" type="location" units="tilematrix" axis="row" min="0" max="262144"></map-input> | ||
<map-link rel="tile" tref="https://tile.openstreetmap.org/{z}/{x}/{y}.png"></map-link> | ||
</map-extent> | ||
</map-layer> | ||
</mapml-viewer> | ||
</body> | ||
|
||
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
import { test, expect, chromium } from '@playwright/test'; | ||
|
||
test.describe('Map-change event are only fired when layers/extents are checked or unchecked in the layer menu ', () => { | ||
let page; | ||
let context; | ||
test.beforeAll(async () => { | ||
context = await chromium.launchPersistentContext('', { | ||
headless: false, | ||
slowMo: 250 | ||
}); | ||
page = | ||
context.pages().find((page) => page.url() === 'about:blank') || | ||
(await context.newPage()); | ||
await page.goto('events/map-change-event.html'); | ||
}); | ||
|
||
test.afterAll(async function () { | ||
await context.close(); | ||
}); | ||
|
||
test('Map-change event for layers work', async () => { | ||
let layerClicked = 0; | ||
page.on('console', (msg) => { | ||
if (msg.text() === 'Layer clicked') { | ||
layerClicked++; | ||
} | ||
}); | ||
|
||
// check and uncheck layers in the DOM shouldn't call map-change | ||
await page.evaluate(() => { | ||
const layer = document.querySelector('map-layer'); | ||
layer.addEventListener('map-change', () => { | ||
console.log('Layer clicked'); | ||
}); | ||
layer.checked = false; | ||
layer.checked = true; | ||
}); | ||
expect(layerClicked).toBe(0); | ||
|
||
// check and uncheck layers using removeAttribute and setAttribute | ||
// shouldn't call map-change | ||
await page.evaluate(() => { | ||
const layer = document.querySelector('map-layer'); | ||
layer.removeAttribute('checked'); | ||
layer.setAttribute('checked', ''); | ||
}); | ||
expect(layerClicked).toBe(0); | ||
|
||
// check and uncheck layers in the layer menu should call map-change | ||
await page.hover('.leaflet-top.leaflet-right'); | ||
const button = await page.locator('.leaflet-control-layers-selector'); | ||
await button.click(); | ||
await button.click(); | ||
|
||
expect(layerClicked).toBe(2); | ||
|
||
// using keyboard to check and uncheck layers in the layer menu should | ||
// call map-change | ||
await page.locator('mapml-viewer').click(); | ||
await page.keyboard.press('Tab'); | ||
await page.keyboard.press('Tab'); | ||
await page.keyboard.press('Tab'); | ||
await page.keyboard.press('Tab'); | ||
await page.keyboard.press('Tab'); | ||
await page.keyboard.press('Enter'); | ||
await page.keyboard.press('Space'); | ||
await page.keyboard.press('Space'); | ||
|
||
expect(layerClicked).toBe(4); | ||
}); | ||
|
||
test('Map-change event for sub-layers work', async () => { | ||
let extentClicked = 0; | ||
page.on('console', (msg) => { | ||
if (msg.text() === 'Sub-layer clicked') { | ||
extentClicked++; | ||
} | ||
}); | ||
|
||
// check and uncheck extents in the DOM shouldn't call map-change | ||
await page.evaluate(() => { | ||
const extent = document.querySelector('map-extent'); | ||
extent.addEventListener('map-change', () => { | ||
console.log('Sub-layer clicked'); | ||
}); | ||
extent.checked = false; | ||
extent.checked = true; | ||
AliyanH marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
expect(extentClicked).toBe(0); | ||
|
||
// check and uncheck extents using removeAttribute and setAttribute | ||
// shouldn't call map-change | ||
await page.evaluate(() => { | ||
const extent = document.querySelector('map-extent'); | ||
extent.removeAttribute('checked'); | ||
extent.setAttribute('checked', ''); | ||
}); | ||
expect(extentClicked).toBe(0); | ||
|
||
// check and uncheck extents in the layer menu should call map-change | ||
const layerSettings = await page.locator( | ||
'.mapml-layer-item-settings-control' | ||
); | ||
await page.hover('.leaflet-top.leaflet-right'); | ||
await layerSettings.first().click(); | ||
const extentControls = await page.locator('.mapml-layer-extent'); | ||
const button = await extentControls.locator('.mapml-layer-item-toggle'); | ||
await button.click(); | ||
await button.click(); | ||
|
||
expect(extentClicked).toBe(2); | ||
|
||
// using keyboard to check and uncheck extents in the layer menu should | ||
// call map-change | ||
await page.locator('mapml-viewer').click(); | ||
await page.keyboard.press('Tab'); | ||
await page.keyboard.press('Tab'); | ||
await page.keyboard.press('Tab'); | ||
await page.keyboard.press('Tab'); | ||
await page.keyboard.press('Tab'); | ||
await page.keyboard.press('Enter'); | ||
await page.keyboard.press('Tab'); | ||
await page.keyboard.press('Tab'); | ||
await page.keyboard.press('Tab'); | ||
await page.keyboard.press('Tab'); | ||
await page.keyboard.press('Space'); | ||
await page.keyboard.press('Space'); | ||
|
||
expect(extentClicked).toBe(4); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.