Skip to content

Commit 3472d16

Browse files
committed
Make execution of map-extent's map-projectionchange handler conditional
on the there being a parentLayer._layer property value. This specifically covers the case when this handler is invoked by the projection change event happening, in which the parent layer may be disabled due to a media condition and therefore there is no LayerGroup to add the extentLayer to.
1 parent 0589bf0 commit 3472d16

File tree

2 files changed

+20
-24
lines changed

2 files changed

+20
-24
lines changed

src/map-extent.js

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -430,27 +430,22 @@ export class HTMLExtentElement extends HTMLElement {
430430
}
431431

432432
_handleChange() {
433-
// parent layer can be disabled due to media query
434-
if (!this.parentLayer.disabled) {
435-
// add _extentLayer to map if map-extent is checked, otherwise remove it
436-
if (this.checked && !this.disabled) {
437-
// can be added to mapmllayer layerGroup no matter map-layer is checked or not
438-
this._extentLayer.addTo(this.parentLayer._layer);
439-
this._extentLayer.setZIndex(
440-
Array.from(
441-
this.parentLayer.src
442-
? this.parentLayer.shadowRoot.querySelectorAll(
443-
':host > map-extent'
444-
)
445-
: this.parentLayer.querySelectorAll(':scope > map-extent')
446-
).indexOf(this)
447-
);
448-
} else {
449-
this.parentLayer._layer?.removeLayer(this._extentLayer);
450-
}
451-
// change the checkbox in the layer control to match map-extent.checked
452-
// doesn't trigger the event handler because it's not user-caused AFAICT
433+
// add _extentLayer to map if map-extent is checked, otherwise remove it
434+
if (this.checked && !this.disabled && this.parentLayer._layer) {
435+
// can be added to mapmllayer layerGroup no matter map-layer is checked or not
436+
this._extentLayer.addTo(this.parentLayer._layer);
437+
this._extentLayer.setZIndex(
438+
Array.from(
439+
this.parentLayer.src
440+
? this.parentLayer.shadowRoot.querySelectorAll(':host > map-extent')
441+
: this.parentLayer.querySelectorAll(':scope > map-extent')
442+
).indexOf(this)
443+
);
444+
} else {
445+
this.parentLayer._layer?.removeLayer(this._extentLayer);
453446
}
447+
// change the checkbox in the layer control to match map-extent.checked
448+
// doesn't trigger the event handler because it's not user-caused AFAICT
454449
}
455450
_validateLayerControlContainerHidden() {
456451
let extentsFieldset = this.parentLayer._propertiesGroupAnatomy;

test/e2e/elements/map-link/map-link-disabled.test.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ test.describe('map-link disabled', () => {
1515
});
1616
test('rel=stylesheet disabled attribute', async () => {
1717
const viewer = page.getByTestId('viewer');
18-
// there's a problem when attempting to select this link by testid. The map-link
19-
// code copies all the attributes of the map-link element onto the generated
20-
// <link> element it uses to render the content, including the data-testid,
21-
// resulting in duplicate ids that mess up the getByTestId algorithm.
2218
const featuresLink = page.getByTestId('restaurants_templated_link');
2319
// test that a templated content link can be disabled by the HTML author at
2420
// page load, and the bounds of the extent do not include the disabled link
@@ -29,6 +25,11 @@ test.describe('map-link disabled', () => {
2925
maxDiffPixels: 20
3026
});
3127
await featuresLink.evaluate((fl) => (fl.disabled = false));
28+
// there's a problem when attempting to select this link by testid. The map-link
29+
// code copies all the attributes of the map-link element onto the generated
30+
// <link> element it uses to render the content, including the data-testid,
31+
// resulting in duplicate ids that mess up the getByTestId algorithm.
32+
//
3233
// selecting it this way seems unambiguous at least
3334
const stylesheetLink = page.locator(
3435
'map-link[rel=stylesheet][href="restaurants/restaurants.css"]'

0 commit comments

Comments
 (0)