I'm trying to display a map using OpenLayers 3 and the SimpleModal plugin for jQuery. When I click my link, the modal opens but the map isn't showing. What am I missing?
I've reproduced my problem on JSBin, http://jsbin.com/hunexepeti/2/edit?html,js,output
This is the HTML relevant part,
<a id="open-map" href="#">Open map</a>
<div id="map"></div>
and this is my JS,
function initMap(lat, lon) {
var container = document.getElementById('map');
var map = new ol.Map({
layers: [
new ol.layer.Tile({
source: new ol.source.Stamen({
layer: 'toner'
})
})
],
renderer: 'canvas',
target: container,
view: new ol.View({
center: [lat, lon],
zoom: 2
})
});
}
$(document).on('click', 'a#open-map', function(e) {
e.preventDefault();
var pos = {
lat: 0,
lon: 0
};
$("#map").modal({
onOpen: function (dialog) {
dialog.overlay.fadeIn('fast', function () {
dialog.data.hide();
dialog.container.fadeIn('fast', function () {
dialog.data.slideDown('fast');
});
});
initMap(pos.lat, pos.lon);
},
onClose: function (dialog) {
dialog.data.fadeOut('fast', function () {
dialog.container.hide('fast', function () {
dialog.overlay.slideUp('fast', function () {
$.modal.close();
});
});
});
},
overlayClose: true
});
});
EDIT: It is fixed, thanks to @ekuusela answer. However I have several location links, so I need to open different locations into the modal.
- Should I reuse the same map and change its View?
- or could I create a new one with a new View because the older is overwritten? I'm curious about performance.