Skip to content
Merged
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
5 changes: 5 additions & 0 deletions src/mapml/features/feature.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,11 @@ export var Feature = L.Path.extend({
this._outline = [];
for (let coords of this._markup.querySelectorAll('map-coordinates')) {
let nodes = coords.childNodes, cur = 0, tempDiv = document.createElement('div'), nodeLength = nodes.length;
for(let i = 0; i < nodes.length; i++){
if(nodes[i].textContent.trim().length === 0){
nodes[i].remove();
}
}
Comment on lines +243 to +247
Copy link
Member

@ahmadayubi ahmadayubi Nov 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need to loop through all to childNodes or could you get away with checking just the first and last? I'm not 100% sure how whitespace and textNodes work so you may have to loop through all of them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that I only need to check the last one

for (let n of nodes) {
let line = [];
if (!n.tagName) { //no tagName means it's text content
Expand Down
53 changes: 53 additions & 0 deletions test/e2e/core/mapSpan.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@

path.fclass { stroke: blue; }

g[data-fid="fclass.73"] > path { stroke: blue; fill: #DDA0DD;}


/* Those parts which are wrapped in a span also inherit the class
values of the span element, which in this case are taken to be noline and
aren"t therefore drawn at all (they are there only to represent tile boundaries)*/
path.noline { display: none}

*, ::before, ::after {
box-sizing: border-box;
}

html,
body {
height: 100%;
}

body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji';
margin: 0;
line-height: 1.5;
}


/*
* map viewers
*/
mapml-viewer:defined,
[is="web-map"]:defined {
height: 100%;
max-width: 100%;
width: 100%;
vertical-align: middle;
}

/* Pre-style to avoid FOUC of inline layer- and fallback content. */
mapml-viewer:not(:defined) > * {
display: none;
}
[is="web-map"]:not(:defined) + img[usemap],
[is="web-map"]:not(:defined) > :not(area):not(.mapml-web-map) {
display: none;
}
/* Ensure inline layer content is hidden if custom/built-in elements isn't
supported, or if javascript is disabled. This needs to be defined separately
from the above, because the `:not(:defined)` selector invalidates the entire
declaration in browsers that do not support it. */
layer- {
display: none;
}
49 changes: 49 additions & 0 deletions test/e2e/core/mapSpan.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>MapML Vector Tiles</title>
<script type="module" src="mapml-viewer.js"></script>
<link rel="stylesheet" href="mapSpan.css">
<style>
mapml-viewer:defined {
height: 50%;
border: 0;
vertical-align: middle;
}

mapml-viewer:defined ~ mapml-viewer:defined {
border-top: 1px inset;
}
</style>
</head>
<body>
<mapml-viewer projection="WGS84" zoom="0" lat="0" lon="0" controls>
<layer- label="Countries - WorldCRS84Quad" checked>
<map-link rel="stylesheet" href="mapSpan.css" >
<map-extent units="WGS84">
<map-input name="zoomLevel" type="zoom" min="0" max="2" value="0"></map-input>

<map-input name="row" type="location" axis="row" units="tilematrix" min="0" max="5"></map-input>
<map-input name="col" type="location" axis="column" units="tilematrix" min="0" max="5"></map-input>

<map-link rel='tile' type='text/mapml' title='Tiles for ne_10m_admin_0_countries (as MapML)' tref='data/wgs84/{zoomLevel}/r{row}_c{col}.mapml'/>
</map-extent>
</layer->
</mapml-viewer>

<mapml-viewer projection="OSMTILE" zoom="2" lat="0" lon="0" controls>
<layer- label="Countries - WebMercatorQuad" checked>
<map-link rel="stylesheet" href="mapSpan.css" >
<map-extent units="OSMTILE">
<map-input name="zoomLevel" type="zoom" min="0" max="2" value="0"></map-input>
<map-input name="row" type="location" axis="row" units="tilematrix" min="0" max="1"></map-input>
<map-input name="col" type="location" axis="column" units="tilematrix" min="0" max="1"></map-input>
<map-link rel='tile' type='text/mapml' tref='data/osmtile/{zoomLevel}/{row}_{col}.mapml' ></map-link>
</map-extent>
</layer->
</mapml-viewer>

</body>
</html>
62 changes: 62 additions & 0 deletions test/e2e/core/mapSpan.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
const playwright = require("playwright");
jest.setTimeout(50000);
(async () => {
for (const browserType of BROWSER) {
describe(
"<map-span> test " + browserType,
()=> {
beforeAll(async () => {
browser = await playwright[browserType].launch({
headless: ISHEADLESS,
slowMo: 100,
});
context = await browser.newContext();
page = await context.newPage();
if (browserType === "firefox") {
await page.waitForNavigation();
}
await page.goto(PATH + "mapSpan.html");
});
afterAll(async function () {
await browser.close();
});

test("[" + browserType + "]" + " <map-span> hides tile boundaries", async ()=>{
const total = await page.$eval(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the variable named "total" ? What is it the total of?

'body > mapml-viewer:nth-child(1) div > div.leaflet-pane.leaflet-map-pane > div.leaflet-pane.leaflet-overlay-pane > div > div.leaflet-layer.mapml-templatedlayer-container > div > div > div:nth-child(1) > svg > g > g:nth-child(1) > path:nth-child(2)',
(path) => path.getAttribute("style")
);

const featureOutline = await page.$(
'body > mapml-viewer:nth-child(1) div > div.leaflet-pane.leaflet-map-pane > div.leaflet-pane.leaflet-overlay-pane > div > div.leaflet-layer.mapml-templatedlayer-container > div > div > div:nth-child(1) > svg > g > g:nth-child(1) > path.fclass._2.mapml-feature-outline'
);

const hidden = await page.$eval(
'body > mapml-viewer:nth-child(1) div > div.leaflet-pane.leaflet-map-pane > div.leaflet-pane.leaflet-overlay-pane > div > div.leaflet-layer.mapml-templatedlayer-container > div > div > div:nth-child(1) > svg > g > g:nth-child(1) > path.noline.fclass._2',
(path) => path.getAttribute("d")
);
expect(featureOutline).not.toBe(null);

const d = await featureOutline.getAttribute("d");
const spliced = await hidden.slice(3, hidden.length);
//Makes sure that the part that should be hidden is not part of the feature outline
let index = d.indexOf(spliced);

expect(total).toEqual("stroke: none;");
expect(index).toEqual(-1);
});

//https://github.com/Maps4HTML/Web-Map-Custom-Element/issues/559#issuecomment-959805896
test("[" + browserType + "]" + " White space parsing for map-coordinates", async ()=>{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Title of the test could be easier to understand, e.g. "Ensure white space in map-coordinates is ignored" or something like that.

await page.waitForTimeout(1000);
const feature = await page.$eval(
'body > mapml-viewer:nth-child(2) div > div.leaflet-pane.leaflet-map-pane > div.leaflet-pane.leaflet-overlay-pane > div > div.leaflet-layer.mapml-templatedlayer-container > div > div > div:nth-child(1) > svg > g > g > path.fclass.mapml-feature-outline',
(path) => path.getAttribute("d")
);

expect(feature).toEqual("M0 217L0 217L0 217L2 217L4 218L6 218L6 218L6 216L2 214L0 216L0 216");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

});
}
);
}
})();
21 changes: 21 additions & 0 deletions test/e2e/data/tiles/osmtile/2/1_1.mapml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<mapml- xmlns="http://www.w3.org/1999/xhtml">
<map-head>
<map-title>ne_10m_admin_0_countries</map-title>
<map-meta charset="utf-8"/>
<map-meta content="text/mapml" http-equiv="Content-Type"/>
<map-meta name="projection" content="OSMTILE"></map-meta>
<map-meta name="cs" content="pcrs"></map-meta>
</map-head>
<map-body>
<map-feature id="fclass.73" class="fclass">
<map-geometry>
<map-polygon>
<map-coordinates>
Copy link
Member

@prushforth prushforth Nov 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could put an xml comment here that says e.g. <!-- leading and trailing whitespace should not affect parsing of map-coordinates -->

-10019154.93269 1538354.08306 -10018754.17139 1538179.92761 -9953778.73157 1518203.74208 -9871068.81875 1482220.46653 -9790805.04014 1478766.01397 -9768484.06551 1498870.65375 -9796003.07532 1547622.63538 -9951944.13091 1647924.2825 -10018754.17139 1569038.46245
<map-span class="noline">-10019154.93269 1569012.97177 -10019154.93269 1538354.08306</map-span>
</map-coordinates>
</map-polygon>
</map-geometry>
</map-feature>
</map-body>
</mapml->
5 changes: 5 additions & 0 deletions test/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ app.get('/data/query/us_map_query', (req, res, next) => {

app.use("/data", express.static(path.join(__dirname, "e2e/data/tiles/cbmt")));
app.use("/data", express.static(path.join(__dirname, "e2e/data/tiles/wgs84")));
app.use("/data", express.static(path.join(__dirname, "e2e/data/tiles/osmtile")));
app.use(
"/data/cbmt/0",
express.static(path.join(__dirname, "e2e/data/tiles/cbmt/0"))
Expand All @@ -40,6 +41,10 @@ app.use(
"/data/wgs84/1",
express.static(path.join(__dirname, "e2e/data/tiles/wgs84/1"))
);
app.use(
"/data/osmtile/2",
express.static(path.join(__dirname, "e2e/data/tiles/osmtile/2"))
);

console.log("Running on localhost:" + port);

Expand Down