Compare commits

...
Author SHA1 Message Date
bence d5d3563ddc Merged in feature/MAPG-169-make-map-boxes-height-identical (pull request #138)
Feature/MAPG-169 make map boxes height identical
2020-06-23 21:44:58 +00:00
bence 19aa4098e5 MAPG-169 set mapContainer's inners' height dynamically to be identical in a row 2020-06-23 23:36:19 +02:00
bence 394c8b8830 MAPG-169 make static map background instead of img 2020-06-23 23:36:19 +02:00
2 changed files with 69 additions and 11 deletions

No files matched your search

+5 -6
View File
@@ -29,17 +29,16 @@ div.mapItem>div.title>p.title {
div.mapItem>div.imgContainer {
width: 100%;
padding-top: 50%;
background: #cccccc;
}
div.mapItem>div.imgContainer>img {
width: 100%;
margin-top: -50%
background-color: #cccccc;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
div.mapItem>div.inner {
background-color: #eeeeee;
padding: 10px 8px;
box-sizing: border-box;
}
div.mapItem>div.inner>div.info {
+64 -5
View File
@@ -63,21 +63,80 @@ $cssFiles = [
(function () {
const GOOGLE_MAPS_JS_API_KEY = '<?= $_ENV['GOOGLE_MAPS_JS_API_KEY'] ?>';
var Maps = {
innerDivs: null,
addStaticMaps: function () {
var imgContainers = document.getElementById('mapContainer').getElementsByClassName('imgContainer');
for (var i = 0; i < imgContainers.length; i++) {
var imgContainer = imgContainers[i];
var img = document.createElement('img');
img.src = 'https://maps.googleapis.com/maps/api/staticmap?size=350x175&' +
var imgSrc = 'https://maps.googleapis.com/maps/api/staticmap?size=350x175&' +
'scale=' + (window.devicePixelRatio >= 2 ? 2 : 1) + '&' +
'visible=' + imgContainer.dataset.boundSouthLat + ',' + imgContainer.dataset.boundWestLng + '|' +
imgContainer.dataset.boundNorthLat + ',' + imgContainer.dataset.boundEastLng +
'&key=' + GOOGLE_MAPS_JS_API_KEY;
img.alt = 'Map area';
imgContainer.appendChild(img);
imgContainer.style.backgroundImage = 'url("' + imgSrc + '")';
}
},
initializeInnerDivs: function () {
Maps.innerDivs = document.getElementById('mapContainer').getElementsByClassName('inner');
for (var i = 0; i < Maps.innerDivs.length; i++) {
var inner = Maps.innerDivs[i];
var boundingClientRect = inner.getBoundingClientRect();
inner.defaultHeight = boundingClientRect.height;
}
},
calculateInnerDivHeights: function () {
var currentY;
var rows = [];
for (var i = 0; i < Maps.innerDivs.length; i++) {
var inner = Maps.innerDivs[i];
var boundingClientRect = inner.getBoundingClientRect();
if (currentY !== boundingClientRect.y) {
rows.push([]);
}
rows[rows.length - 1].push(inner);
currentY = boundingClientRect.y;
}
for (var i = 0; i < rows.length; i++) {
var row = rows[i];
var maxHeight = 0;
for (var j = 0; j < row.length; j++) {
var inner = row[j];
if (inner.defaultHeight > maxHeight) {
maxHeight = inner.defaultHeight;
}
}
for (var j = 0; j < row.length; j++) {
var inner = row[j];
inner.style.height = maxHeight + 'px';
}
}
}
};
Maps.addStaticMaps();
Maps.initializeInnerDivs();
Maps.calculateInnerDivHeights();
window.onresize = function () {
Maps.calculateInnerDivHeights();
};
})();
</script>
<?php if ($isAdmin): ?>