Created
November 10, 2024 22:08
-
-
Save ydrea/169b14e932ef07ea0a87020ce7cb29d6 to your computer and use it in GitHub Desktop.
BetterWMS + HTML popups
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//https://gist.github.com/rclark/6908938?permalink_comment_id=4749563#gistcomment-4749563 | |
// with thumbs | |
showGetFeatureInfo: function ( | |
err, | |
latlng, | |
content | |
// signaturaFromUrl | |
) { | |
if (err) { | |
console.log(err); | |
return; | |
} | |
var tempDiv = document.createElement('div'); | |
tempDiv.innerHTML = content; | |
var rows = tempDiv.querySelectorAll('tr'); | |
// var shouldFlyTo = false; // Initialize the flag | |
for (var i = 0; i < rows.length; i++) { | |
var row = rows[i]; | |
var cells = row.querySelectorAll('th, td'); | |
// console.log(header); | |
if (cells.length >= 2) { | |
var header = cells[0].textContent.trim(); | |
var value = cells[1].textContent.trim(); | |
if (header === 'signatura') { | |
console.log('Header:', header); | |
console.log('Value:', value); | |
} | |
if (header === 'foto_url') { | |
var imgUrl = value.replace(/["']/g, ''); | |
var thumbUrl; | |
var publicIndex = imgUrl.indexOf('/public/'); | |
if (publicIndex !== -1) { | |
thumbUrl = | |
imgUrl.slice(0, publicIndex + '/public/'.length) + | |
'thumbs/' + | |
imgUrl.slice(publicIndex + '/public/'.length); | |
} | |
console.log(imgUrl, thumbUrl); | |
var newRow = document.createElement('tr'); | |
newRow.style.width = '100%'; | |
var newCell = document.createElement('td'); | |
newCell.colSpan = 2; | |
var image = document.createElement('img'); | |
image.src = thumbUrl; | |
image.alt = 'thumb'; | |
image.style.minWidth = '300px'; | |
image.style.width = '100%'; | |
image.style.marginTop = '8px'; | |
newCell.appendChild(image); | |
newRow.appendChild(newCell); | |
// | |
row.parentNode.replaceChild(newRow, row); | |
} else { | |
if (value === 'NULL' || value === '') { | |
row.parentNode.removeChild(row); | |
} | |
} | |
} | |
} | |
var filteredContent = tempDiv.innerHTML; | |
// console.log(filteredContent); | |
L.popup({ minWidth: '500px', width: '100%' }) | |
.setLatLng(latlng) | |
.setContent(filteredContent) | |
.openOn(this._map); | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment