In my Leaflet Map, I would like to have a popup binded to a layer that has thumbnail images.
When a user clicks on the thumbnail, a lightbox will appear with a larger version of that image.
I have chosen to use the dialog box in Jquery UI to do this.
JS Fiddle of What I have so far
/// I am using a leaflet JS Fiddle Template was provided by SO User Asad here:
/// http://stackoverflow.com/a/13699060/3679978
/// I THINK I understand the concept he explained about dynamically generating Javascript.
// Load Map stuff.
var map = L.map('map_canvas').setView([51.505, -0.09], 13);
L.tileLayer('http://{s}.tiles.mapbox.com/v3/mapbox.mapbox-light/{z}/{x}/{y}.png', {
attribution: 'Imagery from <a href="http://mapbox.com/about/maps/">MapBox</a> — © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>',
maxZoom: 18,
}).addTo(map);
var marker = L.marker([51.5, -0.09]).addTo(map);
// Create an element to hold all your text and markup
var container = $('<div />');
// Create var to hold html string for thumbnail
// Originally Based off this: http://stackoverflow.com/a/4452494/3679978
var tempimg = '<a class="preview" href="#" /><div class="myImage"><img src="http://www.w3schools.com/images/pulpit.jpg" alt="myimage" width="120" height="90"/></div>';
// Delegate all event handling for the container itself and its contents to the container
container.on('click', '#button_pdf', function() {
alert("test");
});
// same as above but for class myImage on line 20
container.on('click', '.myImage', function() {
$('div.myImage').dialog();
});
// Insert whatever you want into the container, using whichever approach you prefer
container.html("This is a link: <input id='button_pdf' type='button' value='Click to test' />."+ tempimg);
// container.append($('<span class="bold">').text(" :)"))
// Insert the container into the popup
marker.bindPopup(container[0]);
I think the issues are clear:
- The Jquery UI dialog box behaves wierdly when opened
- The Thumbnail disappears when the Dialog box is closed.
Still new at Javascript,JQuery and Leaflet. Please advise.
Note: If there is a better solution to my image in popup problem I'm open to hear it.
Thanks!