Skip to main content

Map Controller

Map Controller provides an API for manipulate a map.


enableInspector

Enable MapGrab inspector

test("foo test", async ({ mapController }) => {
await mapController('mainMap').enableInspector();
...
});

disableInspector

Disable MapGrab inspector

test("foo test", async ({ mapController }) => {
await mapController('mainMap').disableInspector();
...
});

setView

Set map view based on lng/lat

Usage

test("foo test", async ({ mapController }) => {
await mapController('mainMap').setView({ center: [11, 12] })
...
});

setViewAbsolute

Set map view based on screen x/y

Usage

test("foo test", async ({ mapController }) => {
await mapController('mainMap').setViewAbsolute({ center: [240, 321] });
...
});

fitMapToBounds

Fit map to specified bounds by lng/lat

Usage

test("foo test", async ({ mapController }) => {
await mapController('mainMap').fitMapToBounds([11, 11, 14, 14], { duration: 11 });
...
});

fitMapToBoundingBox

Fit map to specified bounds by screen x/y

Usage

test("foo test", async ({ mapController, mapLocator }) => {
const controller = mapController('mainMap');
const city = mapLocator('layer[id=cities]').first();
const bbox = await locator.boundingBox();

await controller.fitMapToBoundingBox(bbox, { padding: 5 });
...
});

exposeLayers

Hides all layers on the map except the passed

Usage

test("foo test", async ({ mapController, mapLocator }) => {
const controller = mapController('mainMap');

await controller.exposeLayers(['cities-label']);

await expect(await page.screenshot()).toMatchSnapshot('page-with-show-city-label.png');
...
});

revertExposeLayers

Restores the previous state of layer visibility

Usage

test("foo test", async ({ mapController, mapLocator }) => {
const controller = mapController('mainMap');

const exposeState = await controller.exposeLayers(['cities-label']);

await expect(await page.screenshot()).toMatchSnapshot('page-with-show-city-label.png');

await controller.revertExposeLayers(exposeState);
...
});

projectLngLatToScreenPoint

Return converted geographic coordinates to screen coordinates

Usage

test("foo test", async ({ mapController, mapLocator, page }) => {
const controller = mapController('mainMap');

const { x, y } = await controller.projectLngLatToScreenPoint({ lng: 12, lat: 11 });

await page.mouse.click(x, y);
...
});

unprojectLngLatToScreenPoint

Return converted screen coordinates to geographic coordinates

Usage

test("foo test", async ({ mapController, mapLocator, page }) => {
const controller = mapController('mainMap');

const { lng, lat } = await controller.unprojectLngLatToScreenPoint({ x: 200, y: 200 });

await expect(lng).toBe(22);
...
});

waitToMapLoaded

Waits until the map is loaded

Usage

test("foo test", async ({ mapController, mapLocator, page }) => {
await mapController('mainMap').waitToMapLoaded();
...
});

waitToMapStable

Waiting for the map to stop painting or moving

Usage

test("foo test", async ({ mapController, mapLocator, page }) => {
await mapController('mainMap').waitToMapStable();
await expect(await page.screenshot()).toMatchSnapshot('map-loaded.png');
...
});

waitToMapRepaint

Waiting for the map to repaint

Usage

test("foo test", async ({ mapController, mapLocator, page }) => {
await Promise.all([
page.locator('.show-cities').click(),
mapController('mainMap').waitToMapRepaint()
]);
...
});

getMapInstance

Get map handle its Mapbox GL JS or Maplibre GL JS instance

Usage

test("foo test", async ({ mapController, mapLocator, page }) => {
const map = await mapController('mainMap').getMapInstance();

await map.evaluate((map) => map.jumpTo(...));
...
});