Skip to content

Commit 03f0186

Browse files
committed
set featureLayer._staticFeature for static features, fix failing tests
1 parent c13be79 commit 03f0186

File tree

9 files changed

+32
-28
lines changed

9 files changed

+32
-28
lines changed

src/map-feature.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export class MapFeature extends HTMLElement {
7979
this._removeInFeatureList(oldValue);
8080
let native = this._getNativeZoomAndCS(layer._content);
8181
mapmlvectors.zoomBounds = M.getZoomBounds(
82-
layerEl.shadowRoot || layerEl,
82+
layer._content,
8383
native.zoom
8484
);
8585
}
@@ -160,7 +160,7 @@ export class MapFeature extends HTMLElement {
160160
let container = this._layer.shadowRoot || this._layer._layerEl;
161161
// update zoom bounds of vector layer
162162
mapmlvectors.zoomBounds = M.getZoomBounds(
163-
container,
163+
this._layer._content,
164164
this._getNativeZoomAndCS(this._layer._content).zoom
165165
);
166166
}
@@ -216,18 +216,20 @@ export class MapFeature extends HTMLElement {
216216
// if the <layer- > is not removed, then regenerate featureGroup and update the mapmlvectors accordingly
217217
let native = this._getNativeZoomAndCS(this._layer._content);
218218
this._featureGroup = mapmlvectors.addData(this, native.cs, native.zoom);
219-
this._layer._setLayerElExtent();
220219
mapmlvectors._layers[this._featureGroup._leaflet_id] = this._featureGroup;
221220
this._groupEl = this._featureGroup.options.group;
222221
if (mapmlvectors._staticFeature) {
223222
let container = this._layer.shadowRoot || this._layer._layerEl;
224223
// update zoom bounds of vector layer
225224
mapmlvectors.zoomBounds = M.getZoomBounds(
226-
container,
225+
this._layer._content,
227226
this._getNativeZoomAndCS(this._layer._content).zoom
228227
);
228+
// update layer bounds of vector layer
229+
mapmlvectors.layerBounds = M.getBounds(this._layer._content);
229230
// add feature layers to map
230231
mapmlvectors._resetFeatures();
232+
this._layer._setLayerElExtent();
231233
// update map's zoom limit
232234
this._map._addZoomLimit(mapmlvectors);
233235
L.extend(mapmlvectors.options, mapmlvectors.zoomBounds);

src/mapml/layers/FeatureLayer.js

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -40,28 +40,23 @@ export var FeatureLayer = L.FeatureGroup.extend({
4040
let native = M.getNativeVariables(mapml);
4141
this.options.nativeZoom = native.zoom;
4242
this.options.nativeCS = native.cs;
43-
} else if (mapml) {
44-
let native = M.getNativeVariables(mapml);
45-
//needed to check if the feature is static or not, since this method is used by templated also
46-
if (
47-
!mapml.querySelector('map-extent') &&
48-
mapml.querySelector('map-feature') &&
49-
this.options.static
50-
) {
51-
this._features = {};
52-
this._staticFeature = true;
53-
this.isVisible = true; //placeholder for when this actually gets updated in the future
54-
this.zoomBounds = M.getZoomBounds(mapml, native.zoom);
55-
this.layerBounds = M.getBounds(mapml);
56-
L.extend(this.options, this.zoomBounds);
43+
} else {
44+
if (mapml) {
45+
let native = M.getNativeVariables(mapml);
46+
this.addData(mapml, native.cs, native.zoom);
47+
} else if (!mapml) {
48+
this.isVisible = false;
49+
// use this.options._leafletLayer to distinguish the featureLayer constructed for initialization and for templated features / tiles
50+
if (this.options._leafletLayer) {
51+
// this._staticFeature should be set to true to make sure the _getEvents works properly
52+
this._features = {};
53+
this._staticFeature = true;
54+
}
55+
this.layerBounds = this.options.layerBounds
56+
? this.options.layerBounds
57+
: null;
58+
this.zoomBounds = this.options.zoomBounds;
5759
}
58-
this.addData(mapml, native.cs, native.zoom);
59-
} else if (!mapml) {
60-
this.isVisible = false;
61-
this.layerBounds = this.options.layerBounds
62-
? this.options.layerBounds
63-
: null;
64-
this.zoomBounds = this.options.zoomBounds;
6560
}
6661
},
6762

src/mapml/layers/TemplatedFeaturesLayer.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export var TemplatedFeaturesLayer = L.Layer.extend({
3737
pane: container,
3838
// the bounds will be static, fixed, constant for the lifetime of the layer
3939
layerBounds: this.extentBounds,
40+
zoomBounds: this.zoomBounds,
4041
opacity: opacity,
4142
projection: map.options.projection,
4243
static: true,

src/mapml/layers/TemplatedTileLayer.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,11 @@ export var TemplatedTileLayer = L.TileLayer.extend({
163163
xOffset = coords.x * tileSize,
164164
yOffset = coords.y * tileSize;
165165

166-
let tileFeatures = M.featureLayer(null, {
166+
let tileFeatures = M.featureLayer(markup, {
167167
projection: this._map.options.projection,
168168
static: false,
169169
layerBounds: this.extentBounds,
170+
zoomBounds: this.zoomBounds,
170171
interactive: false
171172
});
172173

test/e2e/core/mapContextMenu.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,7 @@ test.describe('Playwright Map Context Menu Tests', () => {
581581
await page.click('body > map');
582582
await page.keyboard.press('Shift+F10');
583583
await page.keyboard.press('p');
584+
await page.waitForTimeout(500);
584585
const layerLabel = await page.$eval(
585586
'body > map',
586587
(map) => map.layers[2].outerHTML

test/e2e/core/projectionChange.test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ test.describe('Playwright Projection Change Tests', () => {
5656

5757
test('Debug components update with projection changes', async () => {
5858
await page.reload();
59+
await page.waitForTimeout(500);
5960
await page.$eval('body > map:nth-child(1)', (map) => map.toggleDebug());
6061

6162
const colBefore = await page.$eval(
@@ -81,7 +82,8 @@ test.describe('Playwright Projection Change Tests', () => {
8182
await page.waitForTimeout(200);
8283
}
8384
await page.keyboard.press('Enter');
84-
await page.waitForTimeout(2000);
85+
// enter on the wrong thing
86+
await page.waitForTimeout(1000);
8587

8688
const colAfter = await page.$eval(
8789
'xpath=//html/body/map[1] >> css=div > div.leaflet-pane.leaflet-map-pane > div.leaflet-layer.mapml-debug-grid > div > div:nth-child(1)',

test/e2e/geojson/geojson2mapml.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ test.describe('GeoJSON API - geojson2mapml', () => {
99
context.pages().find((page) => page.url() === 'about:blank') ||
1010
(await context.newPage());
1111
await page.goto('geojson2mapml.html');
12-
//await page.waitForTimeout(10000);
12+
await page.waitForTimeout(200);
1313
});
1414

1515
test.afterAll(async function () {

test/e2e/layers/featureLayer.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ test.describe('Playwright featureLayer (Static Features) Layer Tests', () => {
4444
});
4545

4646
test('Loading in retrieved features', async () => {
47+
await page.waitForTimeout(200);
4748
const features = await page.$eval(
4849
'layer-#US',
4950
(layer) =>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ test.describe('Playwright Custom TCRS Tests', () => {
1717
});
1818

1919
test('Simple Custom TCRS, tiles load, mismatched layer disabled', async () => {
20+
await page.waitForTimeout(100);
2021
const misMatchedLayerDisabled = await page.$eval(
2122
'body > mapml-viewer:nth-child(1)',
2223
(map) => map.querySelectorAll('layer-')[0].hasAttribute('disabled')

0 commit comments

Comments
 (0)