Skip to content

Commit

Permalink
Fix #980
Browse files Browse the repository at this point in the history
  • Loading branch information
prushforth committed Sep 13, 2024
1 parent a94847a commit 7e351d1
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 16 deletions.
15 changes: 15 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,21 @@
<map-link rel="tile" tref="https://tile.openstreetmap.org/{z}/{x}/{y}.png"></map-link>
</map-extent>
</layer->
<layer- label="Restaurants" checked="">
<map-meta name="extent" content="top-left-easting=-8433179, top-left-northing=5689316, bottom-right-easting=-8420968, bottom-right-northing=5683139"></map-meta>
<map-extent units="OSMTILE" checked="">
<map-select id="restaurants" name="cusine">
<map-option value="restaurants" selected="selected">All cuisines</map-option>
<map-option value="african">African</map-option>
<map-option value="asian">Asian</map-option>
<map-option value="cajun">Cajun</map-option>
<map-option value="indian">Indian</map-option>
<map-option value="italian">Italian</map-option>
<map-option value="mexican">Mexican</map-option>
</map-select>
<map-link tref="https://maps4html.org/experiments/shared/restaurants/{cusine}.mapml" rel="features"></map-link>
</map-extent>
</layer->
</mapml-viewer>
</body>
</html>
21 changes: 13 additions & 8 deletions src/mapml-viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class MapViewer extends HTMLElement {
this.setAttribute('projection', val);
})
.catch(() => {
throw new Error('Undefined projection:' + val);
throw new Error('Undefined projection: ' + val);
});
}
}
Expand Down Expand Up @@ -405,13 +405,18 @@ export class MapViewer extends HTMLElement {
this._map.options.projection !== newValue
) {
const connect = reconnectLayers.bind(this);
connect().then(() => {
if (this._map && this._map.options.projection !== oldValue) {
// this doesn't completely work either
this._resetHistory();
}
if (this._debug) for (let i = 0; i < 2; i++) this.toggleDebug();
});
this.whenProjectionDefined(newValue)
.then(() => connect())
.then(() => {
if (this._map && this._map.options.projection !== oldValue) {
// this doesn't completely work either
this._resetHistory();
}
if (this._debug) for (let i = 0; i < 2; i++) this.toggleDebug();
})
.catch(() => {
throw new Error('Undefined projection: ' + newValue);
});
}
break;
}
Expand Down
21 changes: 13 additions & 8 deletions src/web-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class WebMap extends HTMLMapElement {
this.setAttribute('projection', val);
})
.catch(() => {
throw new Error('Undefined projection:' + val);
throw new Error('Undefined projection: ' + val);
});
}
}
Expand Down Expand Up @@ -460,13 +460,18 @@ export class WebMap extends HTMLMapElement {
this._map.options.projection !== newValue
) {
const connect = reconnectLayers.bind(this);
connect().then(() => {
if (this._map && this._map.options.projection !== oldValue) {
// this doesn't completely work either
this._resetHistory();
}
if (this._debug) for (let i = 0; i < 2; i++) this.toggleDebug();
});
this.whenProjectionDefined(newValue)
.then(() => connect())
.then(() => {
if (this._map && this._map.options.projection !== oldValue) {
// this doesn't completely work either
this._resetHistory();
}
if (this._debug) for (let i = 0; i < 2; i++) this.toggleDebug();
})
.catch(() => {
throw new Error('Undefined projection: ' + newValue);
});
}
break;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!DOCTYPE html>
<html lang="en">

<head>
<title>Basic Mapml-Viewer</title>
<meta charset="UTF-8">
<script type="module" src="mapml-viewer.js"></script>
<style>
html {
height: 100%
}

body {
height: inherit
}

* {
margin: 0;
padding: 0;
}
</style>
</head>

<body>
<mapml-viewer data-testid="testviewer" style="height: 600px;width:500px;" projection="CBMTILE" zoom="0" lat="47" lon="-92" controls>
<layer- data-testid="testlayer" label="CBMT - INLINE" checked>
<map-meta name="zoom" content="min=0,max=25"></map-meta>
<map-extent units="CBMTILE" checked hidden>
<map-input name="zoomLevel" type="zoom" value="3" min="0" max="3" ></map-input>
<map-input name="row" type="location" axis="row" units="tilematrix" min="14" max="21" ></map-input>
<map-input name="col" type="location" axis="column" units="tilematrix" min="14" max="19" ></map-input>
<map-link rel='tile' tref='/data/cbmt/{zoomLevel}/c{col}_r{row}.png' ></map-link>
</map-extent>
</layer->
</mapml-viewer>
</body>

</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { test, expect, chromium } from '@playwright/test';

test.describe('Playwright mapml-viewer issue-980 test', () => {
let page;
let context;
test.beforeAll(async () => {
context = await chromium.launchPersistentContext('');
page =
context.pages().find((page) => page.url() === 'about:blank') ||
(await context.newPage());
await page.goto('mapml-viewer-unknown-projection.html');
await page.waitForTimeout(500);
});

test.afterAll(async function () {
await context.close();
});

test('mapml-viewer projection set to unknown prj errors to console', async () => {
let message;
page.on('pageerror', exception => message = exception.message);
const viewer = page.getByTestId('testviewer');
await viewer.evaluate((v) => (v.projection = 'unknown'));
// update the projection attribute on the viewer
await page.waitForTimeout(5000);
expect(message).toBe("Undefined projection: unknown");
});
});

0 comments on commit 7e351d1

Please sign in to comment.