Skip to content
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

Auto issue query on moveend, add test #569

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/mapml/layers/Crosshair.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export var Crosshair = L.Layer.extend({

map.on("layerchange layeradd layerremove overlayremove", this._toggleEvents, this);
map.on("popupopen", this._isMapFocused, this);
map.on("moveend", this._moveEndQuery, this);
L.DomEvent.on(map._container, "keydown keyup mousedown", this._isMapFocused, this);

this._addOrRemoveCrosshair();
Expand All @@ -43,6 +44,7 @@ export var Crosshair = L.Layer.extend({
onRemove: function (map) {
map.off("layerchange layeradd layerremove overlayremove", this._toggleEvents);
map.off("popupopen", this._isMapFocused);
map.off("moveend", this._moveEndQuery);
L.DomEvent.off(map._container, "keydown keyup mousedown", this._isMapFocused);
},

Expand All @@ -55,6 +57,16 @@ export var Crosshair = L.Layer.extend({
this._addOrRemoveCrosshair();
},

_moveEndQuery: function (e) {
if (this._hasQueryableLayer() && this._map.isFocused) {
this._map.fire('click', {
latlng: this._map.getCenter(),
layerPoint: this._map.latLngToLayerPoint(this._map.getCenter()),
containerPoint: this._map.latLngToContainerPoint(this._map.getCenter())
});
}
},

_addOrRemoveCrosshair: function (e) {
if (this._hasQueryableLayer()) {
this._container.style.visibility = null;
Expand Down
13 changes: 0 additions & 13 deletions test/e2e/core/keyboardInteraction.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,6 @@ jest.setTimeout(50000);
expect(afterTab).toEqual("");
});

test("[" + browserType + "]" + " Crosshair remains on map move with arrow keys", async () => {
await page.keyboard.press("ArrowUp");
await page.waitForTimeout(1000);
await page.keyboard.press("ArrowDown");
await page.waitForTimeout(1000);
await page.keyboard.press("ArrowLeft");
await page.waitForTimeout(1000);
await page.keyboard.press("ArrowRight");
await page.waitForTimeout(1000);
const afterMove = await page.$eval("div > div.mapml-crosshair", (div) => div.style.visibility);
expect(afterMove).toEqual("");
});

test("[" + browserType + "]" + " Crosshair shows on esc but hidden on tab out", async () => {
await page.keyboard.press("Escape");
const afterEsc = await page.$eval("div > div.mapml-crosshair", (div) => div.style.visibility);
Expand Down
18 changes: 18 additions & 0 deletions test/e2e/layers/queryLink.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,24 @@ jest.setTimeout(50000);
expect(popupNumLeft).toEqual(0);
expect(popupNumTop).toEqual(0);
});
test("[" + browserType + "]" + " Auto query on moveend", async () => {
await page.reload()
await page.click("div");

await page.keyboard.press("Escape");
await page.waitForTimeout(500);
await page.keyboard.press("ArrowUp");
await page.waitForSelector("div > div.leaflet-pane.leaflet-map-pane > div.leaflet-pane.leaflet-popup-pane > div");
const popupNum = await page.$eval("div > div.leaflet-pane.leaflet-map-pane > div.leaflet-pane.leaflet-popup-pane", (div) => div.childElementCount);
expect(popupNum).toEqual(1);

await page.keyboard.press("Escape");
await page.waitForTimeout(1000);
await page.keyboard.press("ArrowDown");
await page.waitForSelector("div > div.leaflet-pane.leaflet-map-pane > div.leaflet-pane.leaflet-popup-pane > div");
const popupNumTwo = await page.$eval("div > div.leaflet-pane.leaflet-map-pane > div.leaflet-pane.leaflet-popup-pane", (div) => div.childElementCount);
expect(popupNumTwo).toEqual(1);
});
});
describe("Queried Feature Tests in " + browserType, () => {
test("[" + browserType + "]" + " First feature added + popup content updated ", async () => {
Expand Down