Skip to content

Commit 74aeab4

Browse files
committed
Fix client hangs when hovering over a <map-a> that is too long issue. (Maps4HTML#972)
Closes Maps4HTML#971
1 parent 8486c47 commit 74aeab4

File tree

7 files changed

+32
-15
lines changed

7 files changed

+32
-15
lines changed

src/mapml.css

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,12 +683,16 @@ svg.leaflet-image-layer.leaflet-interactive g {
683683
bottom: 0;
684684
background-color: rgb(222,225,230);
685685
border-radius: 0 5px 0 0 ;
686-
z-index: 1050;
686+
z-index: 1050;
687+
max-width: 60%;
687688
}
688689

689690
.mapml-link-preview > p {
690691
margin: 3px 5px 2px 3px;
691692
color: rgb(60,64,67);
693+
text-overflow: ellipsis;
694+
overflow-x: hidden;
695+
white-space: nowrap;
692696
}
693697

694698
/**

src/mapml/features/path.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,20 +116,15 @@ export var Path = L.Path.extend({
116116
(e) => {
117117
if (e.target !== e.currentTarget) return;
118118
hovered = true;
119-
let resolver = document.createElement('a'),
120-
mapWidth = this._map.getContainer().clientWidth;
119+
let resolver = document.createElement('a');
121120
resolver.href = link.url;
122121
p.innerHTML = resolver.href;
123122

124123
this._map.getContainer().appendChild(container);
125124

126-
while (p.clientWidth > mapWidth / 2) {
127-
p.innerHTML =
128-
p.innerHTML.substring(0, p.innerHTML.length - 5) + '...';
129-
}
130-
setTimeout(() => {
131-
if (hovered) p.innerHTML = resolver.href;
132-
}, 1000);
125+
// setTimeout(() => {
126+
// if (hovered) p.innerHTML = resolver.href;
127+
// }, 1000);
133128
},
134129
this
135130
);

src/mapml/layers/FeatureLayer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ export var FeatureLayer = L.FeatureGroup.extend({
411411
);
412412
}
413413
let cs =
414-
feature.getElementsByTagName('map-geometry')[0]?.getAttribute('cs') ||
414+
feature.getElementsByTagName('map-geometry')[0]?.getAttribute('cs') ??
415415
fallbackCS;
416416
// options.layerBounds and options.zoomBounds are set by TemplatedTileLayer._createFeatures
417417
// each geometry needs bounds so that it can be a good community member of this._layers

src/mapml/layers/TemplatedFeaturesLayer.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export var TemplatedFeaturesLayer = L.Layer.extend({
6666
}
6767
});
6868
L.extend(this._features.options, { _leafletLayer: this._features });
69+
this._features._layerEl = this._linkEl.getLayerEl();
6970
} else {
7071
this._features.eachLayer((layer) => layer.addTo(map));
7172
}

test/e2e/elements/map-a/map-a-inline-or-remote-templated-issue-968.test.js renamed to test/e2e/elements/map-a/map-a-inline-or-remote-templated.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,16 @@ test.describe('map-a loaded inline or remote, directly or via templated map-link
7272
);
7373
});
7474
}
75+
test('Long map-a href is actionable, does not cause client to hang', async () => {
76+
const longUrl = "http://localhost:8080/geoserver/tiger/wms?service=WMS&version=1.1.0&request=GetMap&layers=tiger%3Atiger_roads&bbox=-74.02722%2C40.684221%2C-73.907005%2C40.878178&width=476&height=768&srs=EPSG%3A4326&styles=&format=text%2Fmapml";
77+
// remove the top three layers (the bottom layer has a long href)
78+
await page.getByTestId('remote-templated').evaluate(layer => layer.remove());
79+
await page.getByTestId('inline-templated').evaluate(layer => layer.remove());
80+
await page.getByTestId('remote-features').evaluate(layer => layer.remove());
81+
const aWithLongHref = page.getByRole('link', { name: 'Long href' });
82+
await aWithLongHref.hover();
83+
const toast = await page.locator('.mapml-link-preview > p').evaluate((p) => p.innerText );
84+
expect(toast).toEqual(longUrl);
85+
86+
});
7587
});

test/e2e/elements/map-a/map-a.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@
4949
</table>
5050
</map-properties>
5151
</map-feature>
52-
<map-feature id="poi.1" class="poi-r1-s1 poi-r1-s2">
52+
<map-feature data-testid="poi-1" id="poi.1" class="poi-r1-s1 poi-r1-s2">
53+
<map-featurecaption>Long href</map-featurecaption>
5354
<map-geometry>
54-
<map-a href="https://example.org/" target="_top">
55+
<map-a type="text/mapml" target="_blank" href="http://localhost:8080/geoserver/tiger/wms?service=WMS&version=1.1.0&request=GetMap&layers=tiger%3Atiger_roads&bbox=-74.02722%2C40.684221%2C-73.907005%2C40.878178&width=476&height=768&srs=EPSG%3A4326&styles=&format=text%2Fmapml">
5556
<map-point>
5657
<map-coordinates>-8238806.8429565085 4969306.111096254</map-coordinates>
5758
</map-point>

test/e2e/layers/multipleExtents.test.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,11 @@ test.describe('Multiple Extents Bounds Tests', () => {
261261
await expect(
262262
page.locator('.mapml-debug-vectors.projection-centre ')
263263
).toHaveCount(1);
264+
// templated features formerly did not keep track of their layer- element,
265+
// which prevented them from being added to the debug layer. That is fixed.
264266
await expect(
265267
page.locator('.mapml-debug-vectors.multiple-extents')
266-
).toHaveCount(2);
268+
).toHaveCount(6);
267269
await expect(
268270
page.locator('.mapml-debug-vectors.single-extent')
269271
).toHaveCount(1);
@@ -312,9 +314,11 @@ test.describe('Multiple Extents Bounds Tests', () => {
312314
await expect(
313315
page.locator('.mapml-debug-vectors.projection-centre ')
314316
).toHaveCount(1);
317+
// templated features formerly did not keep track of their layer- element,
318+
// which prevented them from being added to the debug layer. That is fixed.
315319
await expect(
316320
page.locator('.mapml-debug-vectors.multiple-extents')
317-
).toHaveCount(2);
321+
).toHaveCount(6);
318322
await expect(
319323
page.locator('.mapml-debug-vectors.single-extent')
320324
).toHaveCount(1);

0 commit comments

Comments
 (0)