Skip to content

Commit

Permalink
Modified logic so that map-change is only called when layer/extent is…
Browse files Browse the repository at this point in the history
… checked/unchecked on the layer menu
  • Loading branch information
yushan-mu committed Oct 31, 2024
1 parent a39cba4 commit c3a55bd
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
1 change: 0 additions & 1 deletion src/layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ export class BaseLayerElement extends HTMLElement {
this.parentElement._map.removeLayer(this._layer);
}
this._layerControlCheckbox.checked = this.checked;
this.dispatchEvent(new CustomEvent('map-change'));
break;
case 'hidden':
if (typeof newValue === 'string') {
Expand Down
1 change: 0 additions & 1 deletion src/map-extent.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ export class HTMLExtentElement extends HTMLElement {
this._handleChange();
this._calculateBounds();
this._layerControlCheckbox.checked = newValue !== null;
this.dispatchEvent(new CustomEvent('map-change'));
})
.catch((error) => {
console.log(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export var createLayerControlExtentHTML = function () {
extentItemNameSpan.innerHTML = this.label;
const changeCheck = function () {
this.checked = !this.checked;
this.dispatchEvent(new CustomEvent('map-change'));
};
// save for later access by API
this._layerControlCheckbox = input;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export var createLayerControlHTML = async function () {
layerItemName.layer = this._layer;
const changeCheck = function () {
this.checked = !this.checked;
this.dispatchEvent(new CustomEvent('map-change'));
};
input.addEventListener('change', changeCheck.bind(this));
if (this._layer._legendUrl) {
Expand Down
18 changes: 10 additions & 8 deletions test/e2e/api/events/map-change-event.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test, expect, chromium } from '@playwright/test';

test.describe('Map change event are fired when layers/extents are checked or unchecked ', () => {
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 () => {
Expand Down Expand Up @@ -34,7 +34,7 @@ test.describe('Map change event are fired when layers/extents are checked or unc
layer.checked = true;
});
await page.waitForTimeout(500);
expect(layerClicked).toBe(2);
expect(layerClicked).toBe(0);

// check and uncheck layers using removeAttribute and setAttribute
await page.evaluate(() => {
Expand All @@ -43,7 +43,7 @@ test.describe('Map change event are fired when layers/extents are checked or unc
layer.setAttribute('checked', '');
});
await page.waitForTimeout(500);
expect(layerClicked).toBe(4);
expect(layerClicked).toBe(0);

// check and uncheck layers in the layer menu
await page.hover('.leaflet-top.leaflet-right');
Expand All @@ -52,7 +52,7 @@ test.describe('Map change event are fired when layers/extents are checked or unc
await button.click();

await page.waitForTimeout(500);
expect(layerClicked).toBe(6);
expect(layerClicked).toBe(2);
});

test('Map change event for sub-layers work', async () => {
Expand All @@ -73,7 +73,7 @@ test.describe('Map change event are fired when layers/extents are checked or unc
extent.checked = true;
});
await page.waitForTimeout(500);
expect(extentClicked).toBe(2);
expect(extentClicked).toBe(0);

// check and uncheck extents using removeAttribute and setAttribute
await page.evaluate(() => {
Expand All @@ -82,10 +82,12 @@ test.describe('Map change event are fired when layers/extents are checked or unc
extent.setAttribute('checked', '');
});
await page.waitForTimeout(500);
expect(extentClicked).toBe(4);
expect(extentClicked).toBe(0);

// check and uncheck extents in the layer menu
const layerSettings = await page.locator('.mapml-layer-item-settings-control');
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');
Expand All @@ -94,6 +96,6 @@ test.describe('Map change event are fired when layers/extents are checked or unc
await button.click();

await page.waitForTimeout(500);
expect(extentClicked).toBe(6);
expect(extentClicked).toBe(2);
});
});

0 comments on commit c3a55bd

Please sign in to comment.