Skip to content

Commit 1f71be2

Browse files
prushforprushforth
authored andcommitted
Static tile layer changes - move code from onAdd to initialize
Change (back) what StaticTileLayer.option._leafletLayer points to update broken playwright tests by removing the dom order dependency of the g elements + updating other methods of testing
1 parent 4307b43 commit 1f71be2

File tree

9 files changed

+31
-38
lines changed

9 files changed

+31
-38
lines changed

src/mapml/layers/MapMLLayer.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -161,18 +161,7 @@ export var MapMLLayer = L.Layer.extend({
161161
// content will be maintained
162162

163163
//only add the layer if there are tiles to be rendered
164-
if (
165-
(!this._staticTileLayer || this._staticTileLayer._container === null) &&
166-
this._mapmlTileContainer.getElementsByTagName('map-tiles').length > 0
167-
) {
168-
this._staticTileLayer = M.staticTileLayer({
169-
pane: this._container,
170-
_leafletLayer: this,
171-
className: 'mapml-static-tile-layer',
172-
tileContainer: this._mapmlTileContainer,
173-
maxZoomBound: map.options.crs.options.resolutions.length - 1,
174-
tileSize: map.options.crs.options.crs.tile.bounds.max.x
175-
});
164+
if (this._staticTileLayer) {
176165
map.addLayer(this._staticTileLayer);
177166
}
178167

@@ -868,7 +857,8 @@ export var MapMLLayer = L.Layer.extend({
868857
setLayerTitle();
869858
parseLicenseAndLegend();
870859
setZoomInOrOutLinks();
871-
processTiles();
860+
// crs is only set if the layer has the same projection as the map
861+
if (layer._properties.crs) processTiles();
872862
processFeatures();
873863
M._parseStylesheetAsHTML(mapml, base, layer._container);
874864
layer._validateExtent();
@@ -1537,6 +1527,14 @@ export var MapMLLayer = L.Layer.extend({
15371527
tiles.appendChild(document.importNode(newTiles[nt], true));
15381528
}
15391529
layer._mapmlTileContainer.appendChild(tiles);
1530+
layer._staticTileLayer = M.staticTileLayer({
1531+
pane: layer._container,
1532+
projection: layer._properties.projection,
1533+
className: 'mapml-static-tile-layer',
1534+
tileContainer: layer._mapmlTileContainer,
1535+
maxZoomBound: layer._properties.crs.options.resolutions.length - 1,
1536+
tileSize: layer._properties.crs.options.crs.tile.bounds.max.x
1537+
});
15401538
}
15411539
}
15421540
function getAlternateStyles() {

src/mapml/layers/StaticTileLayer.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,21 @@ export var StaticTileLayer = L.GridLayer.extend({
55
options.maxZoomBound
66
);
77
L.extend(options, this.zoomBounds);
8+
L.extend(options, { _leafletLayer: this });
89
L.setOptions(this, options);
910
this._groups = this._groupTiles(
1011
this.options.tileContainer.getElementsByTagName('map-tile')
1112
);
12-
},
13-
14-
onAdd: function () {
15-
this._bounds = this._getLayerBounds(
16-
this._groups,
17-
this._map.options.projection
18-
); //stores meter values of bounds
13+
this._bounds = this._getLayerBounds(this._groups, this.options.projection); //stores meter values of bounds
1914
this.layerBounds = this._bounds[Object.keys(this._bounds)[0]];
2015
for (let key of Object.keys(this._bounds)) {
2116
this.layerBounds.extend(this._bounds[key].min);
2217
this.layerBounds.extend(this._bounds[key].max);
2318
}
19+
},
20+
21+
onAdd: function (map) {
22+
this._map = map;
2423
L.GridLayer.prototype.onAdd.call(this, this._map);
2524
this._handleMoveEnd();
2625
},
@@ -116,7 +115,6 @@ export var StaticTileLayer = L.GridLayer.extend({
116115
projection
117116
);
118117
}
119-
120118
return layerBounds;
121119
},
122120

test/e2e/core/debugMode.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ test.describe('Playwright Map Element Tests', () => {
4040

4141
test('Reasonable debug layer extent created', async () => {
4242
const feature = await page.$eval(
43-
'xpath=//html/body/mapml-viewer >> css=div > div.leaflet-pane.leaflet-map-pane > div.leaflet-pane.leaflet-overlay-pane > svg > g > path:nth-child(2)',
43+
'xpath=//html/body/mapml-viewer >> css=div > div.leaflet-pane.leaflet-map-pane > div.leaflet-pane.leaflet-overlay-pane > svg > g > path[stroke="#8DFF33"]',
4444
(tile) => tile.getAttribute('d')
4545
);
4646
expect(feature).toEqual(
@@ -50,15 +50,15 @@ test.describe('Playwright Map Element Tests', () => {
5050

5151
test('Large debug layer extent created', async () => {
5252
const feature = await page.$eval(
53-
'xpath=//html/body/mapml-viewer >> css=div > div.leaflet-pane.leaflet-map-pane > div.leaflet-pane.leaflet-overlay-pane > svg > g > path:nth-child(4)',
53+
'xpath=//html/body/mapml-viewer >> css=div > div.leaflet-pane.leaflet-map-pane > div.leaflet-pane.leaflet-overlay-pane > svg > g > path[stroke="#E433FF"]',
5454
(tile) => tile.getAttribute('d')
5555
);
5656
expect(feature).toEqual('M-659 500L365 500L365 -780L-659 -780z');
5757
});
5858

5959
test('Debug layer extent beyond ((0,0), (5,5)) created', async () => {
6060
const feature = await page.$eval(
61-
'xpath=//html/body/mapml-viewer >> css=div > div.leaflet-pane.leaflet-map-pane > div.leaflet-pane.leaflet-overlay-pane > svg > g > path:nth-child(6)',
61+
'xpath=//html/body/mapml-viewer >> css=div > div.leaflet-pane.leaflet-map-pane > div.leaflet-pane.leaflet-overlay-pane > svg > g > path[d="M-1683 1268L1133 1268L1133 -1292L-1683 -1292z"]',
6262
(tile) => tile.getAttribute('d')
6363
);
6464
expect(feature).toEqual('M-1683 1268L1133 1268L1133 -1292L-1683 -1292z');

test/e2e/core/mapFeature.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ test.describe('Playwright MapFeature Custom Element Tests', () => {
176176

177177
test('Default click method test', async () => {
178178
await page.pause();
179-
179+
180180
// click method test
181181
// <map-feature> with role="button" should have popup opened after click
182182
const popup = await page.$eval('body > map', (map) => {

test/e2e/mapml-viewer/locateButton.test.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,10 @@ test.describe('Geolocation control tests', () => {
2222

2323
test('Using geolocation control to control map', async () => {
2424
await page.click('body > mapml-viewer');
25-
await page.keyboard.press('Tab');
26-
await page.keyboard.press('Tab');
27-
await page.keyboard.press('Tab');
28-
await page.keyboard.press('Tab');
29-
await page.keyboard.press('Tab');
30-
await page.keyboard.press('Tab');
31-
await page.keyboard.press('Tab');
25+
for (let i = 0; i < 7; i++) {
26+
await page.keyboard.press('Tab');
27+
await page.waitForTimeout(50);
28+
}
3229
await page.keyboard.press('Enter');
3330

3431
let locateButton_lat = await page.$eval(

test/e2e/mapml-viewer/mapml-viewer.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
</head>
2828

2929
<body>
30-
<mapml-viewer data-testid="testviewer" style="height: 600px;width:500px;" projection="CBMTILE" zoom="0" lat="47" lon="-92" controls>
30+
<mapml-viewer style="height: 600px;width:500px;" projection="CBMTILE" zoom="0" lat="47" lon="-92" controls>
3131
<layer- data-testid="testlayer" label="CBMT - INLINE" checked>
3232
<map-extent units="CBMTILE">
3333
<map-input name="zoomLevel" type="zoom" value="3" min="0" max="3" ></map-input>

test/e2e/mapml-viewer/mapml-viewer.test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,9 @@ test.describe('Playwright mapml-viewer Element Tests', () => {
184184

185185
await page.click('body > mapml-viewer');
186186
await page.keyboard.press('Control+v');
187-
const viewer = await page.getByTestId('testviewer');
188-
await viewer.evaluate((viewer) => viewer.whenLayersReady());
187+
await page.$eval('body > mapml-viewer', (viewer) =>
188+
viewer.whenLayersReady()
189+
);
189190
const layerCount = await page.$eval(
190191
'body > mapml-viewer',
191192
(map) => map.layers.length

test/e2e/web-map/map.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
</head>
2828

2929
<body>
30-
<map data-testid="testviewer" is="web-map" style="width: 500px;height: 500px;" projection="CBMTILE" zoom="2" lat="45.5052040" lon="-75.2202344"
30+
<map is="web-map" style="width: 500px;height: 500px;" projection="CBMTILE" zoom="2" lat="45.5052040" lon="-75.2202344"
3131
controls>
3232
<layer- label="CBMT - INLINE" checked>
3333
<map-extent units="CBMTILE">

test/e2e/web-map/map.test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ test.describe('Playwright web-map Element Tests', () => {
6666

6767
await page.click('body > map');
6868
await page.keyboard.press('Control+v');
69-
const viewer = await page.getByTestId('testviewer');
70-
await viewer.evaluate((viewer) => viewer.whenLayersReady());
69+
await page.$eval('body > map', (viewer) => viewer.whenLayersReady());
7170
const layerCount = await page.$eval(
7271
'body > map',
7372
(map) => map.layers.length

0 commit comments

Comments
 (0)