Skip to content

Commit

Permalink
Modified popup maxHeight
Browse files Browse the repository at this point in the history
  • Loading branch information
yushan-mu committed Dec 5, 2024
1 parent 8955976 commit cb31538
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 10 deletions.
6 changes: 6 additions & 0 deletions src/mapml.css
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,11 @@ summary {
line-height: 44px;
}

.mapml-zoom-link {
display: block;
text-align: center;
}

.mapml-focus-buttons {
white-space: nowrap;
}
Expand All @@ -614,6 +619,7 @@ summary {
.leaflet-popup-content {
margin: 0;
min-width: min-content;
scrollbar-width: thin;
}
.mapml-popup-content {
padding-top: 44px;
Expand Down
3 changes: 2 additions & 1 deletion src/mapml/handlers/QueryHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ export var QueryHandler = Handler.extend({
popupOptions = {
autoClose: false,
autoPan: true,
maxHeight: map.getSize().y * 0.5 - 50
maxHeight: map.getSize().y * 0.5 - 50,
maxWidth: map.getSize().x * 0.7
},
tcrs2pcrs = function (c) {
return crs.transformation.untransform(c, crs.scale(zoom));
Expand Down
27 changes: 23 additions & 4 deletions src/mapml/layers/MapMLLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,20 @@ export var MapMLLayer = LayerGroup.extend({
_leafletLayer: layer,
mapEl: layer._layerEl.parentElement,
onEachFeature: function (properties, geometry) {
const map = layer._layerEl.parentElement._map;
const popupOptions = {
autoClose: false,
autoPan: true,
maxHeight: map.getSize().y * 0.5 - 50,
maxWidth: map.getSize().x * 0.7,
minWidth: 165
};
// need to parse as HTML to preserve semantics and styles
if (properties) {
var c = document.createElement('div');
c.classList.add('mapml-popup-content');
c.insertAdjacentHTML('afterbegin', properties.innerHTML);
geometry.bindPopup(c, { autoClose: false, minWidth: 165 });
geometry.bindPopup(c, popupOptions);
}
}
}).addTo(layer);
Expand Down Expand Up @@ -527,8 +535,8 @@ export var MapMLLayer = LayerGroup.extend({
let divider = DomUtil.create('hr', 'mapml-popup-divider');

popup._navigationBar = div;
popup._content.appendChild(divider);
popup._content.appendChild(div);
popup._content.parentElement.parentElement.appendChild(divider);
popup._content.parentElement.parentElement.appendChild(div);

content.focus();

Expand Down Expand Up @@ -631,31 +639,40 @@ export var MapMLLayer = LayerGroup.extend({

function attachZoomLink(e) {
// this === popup
let content = this._content,
let content = this._content.parentElement.parentElement,
featureEl = e ? e.currFeature : this._source._groupLayer._featureEl;
if (content.querySelector('a.mapml-zoom-link')) {
content.querySelector('a.mapml-zoom-link').remove();
}

// return early if feature doesn't have map-geometry
if (!featureEl.querySelector('map-geometry')) return;

// calculate zoom parameters
let tL = featureEl.extent.topLeft.gcrs,
bR = featureEl.extent.bottomRight.gcrs,
center = latLngBounds(
latLng(tL.horizontal, tL.vertical),
latLng(bR.horizontal, bR.vertical)
).getCenter(true);

// construct zoom link
let zoomLink = document.createElement('a');
zoomLink.href = `#${featureEl.getZoomToZoom()},${center.lng},${
center.lat
}`;
zoomLink.innerHTML = `${map.options.mapEl.locale.popupZoom}`;
zoomLink.className = 'mapml-zoom-link';

// handle zoom link interactions
zoomLink.onclick = zoomLink.onkeydown = function (e) {
if (!(e instanceof MouseEvent) && e.keyCode !== 13) return;
e.preventDefault();
featureEl.zoomTo();
map.closePopup();
map.getContainer().focus();
};

// we found that the popupopen event is fired as many times as there
// are layers on the map (<map-layer> elements / MapMLLayers that is).
// In each case the target layer is always this layer, so we can't
Expand All @@ -667,6 +684,8 @@ export var MapMLLayer = LayerGroup.extend({
// apart from this slightly non-optimal method. Revisit sometime!
let link = content.querySelector('.mapml-zoom-link');
if (link) link.remove();

// attach link to popup
content.insertBefore(
zoomLink,
content.querySelector('hr.mapml-popup-divider')
Expand Down
9 changes: 8 additions & 1 deletion src/mapml/layers/TemplatedFeaturesLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,18 @@ export var TemplatedFeaturesLayer = Layer.extend({
projection: map.options.projection,
mapEl: this._linkEl.getMapEl(),
onEachFeature: function (properties, geometry) {
const popupOptions = {
autoClose: false,
autoPan: true,
maxHeight: map.getSize().y * 0.5 - 50,
maxWidth: map.getSize().x * 0.7,
minWidth: 108
};
// need to parse as HTML to preserve semantics and styles
var c = document.createElement('div');
c.classList.add('mapml-popup-content');
c.insertAdjacentHTML('afterbegin', properties.innerHTML);
geometry.bindPopup(c, { autoClose: false, minWidth: 108 });
geometry.bindPopup(c, popupOptions);
}
});
extend(this._features.options, { _leafletLayer: this._features });
Expand Down
8 changes: 4 additions & 4 deletions test/e2e/layers/queryLink.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ test.describe('Playwright Query Link Tests', () => {
(iframe) => iframe.contentWindow.document.querySelector('h1').innerText
);
const href = await page.$eval(
'div > div.leaflet-pane.leaflet-map-pane > div.leaflet-pane.leaflet-popup-pane > div > div.leaflet-popup-content-wrapper > div > div > a.mapml-zoom-link',
'div > div.leaflet-pane.leaflet-map-pane > div.leaflet-pane.leaflet-popup-pane > div > div.leaflet-popup-content-wrapper > a.mapml-zoom-link',
(link) => link.getAttribute('href')
);

Expand Down Expand Up @@ -141,7 +141,7 @@ test.describe('Playwright Query Link Tests', () => {
(iframe) => iframe.contentWindow.document.querySelector('h1').innerText
);
const href = await page.$eval(
'div > div.leaflet-pane.leaflet-map-pane > div.leaflet-pane.leaflet-popup-pane > div > div.leaflet-popup-content-wrapper > div > div > a.mapml-zoom-link',
'div > div.leaflet-pane.leaflet-map-pane > div.leaflet-pane.leaflet-popup-pane > div > div.leaflet-popup-content-wrapper > a.mapml-zoom-link',
(link) => link.getAttribute('href')
);

Expand Down Expand Up @@ -176,7 +176,7 @@ test.describe('Playwright Query Link Tests', () => {
(iframe) => iframe.contentWindow.document.querySelector('h1').innerText
);
const href = await page.$eval(
'div > div.leaflet-pane.leaflet-map-pane > div.leaflet-pane.leaflet-popup-pane > div > div.leaflet-popup-content-wrapper > div > div > a.mapml-zoom-link',
'div > div.leaflet-pane.leaflet-map-pane > div.leaflet-pane.leaflet-popup-pane > div > div.leaflet-popup-content-wrapper > a.mapml-zoom-link',
(link) => link.getAttribute('href')
);

Expand Down Expand Up @@ -254,7 +254,7 @@ test.describe('Playwright Query Link Tests', () => {
(iframe) => iframe.contentWindow.document.querySelector('h1').innerText
);
const link = await page.$eval(
'div > div.leaflet-pane.leaflet-map-pane > div.leaflet-pane.leaflet-popup-pane > div > div.leaflet-popup-content-wrapper > div > div',
'div > div.leaflet-pane.leaflet-map-pane > div.leaflet-pane.leaflet-popup-pane > div > div.leaflet-popup-content-wrapper',
(popup) => popup.querySelector('a.mapml-zoom-link')
);

Expand Down

0 comments on commit cb31538

Please sign in to comment.