I’m encountering an issue after upgrading from OpenLayers 5 to OpenLayers 9. Specifically, I’m unable to initialize the map view when the map container is hidden inside a jQuery modal. The problem seems to manifest because the modal is not in the current viewport when I try to set the zoom level and center coordinates (lon/lat).
Steps to Reproduce:
- Create an OpenLayers map within a container that is inside a jQuery modal.
- Attempt to initialize the map view with specific zoom and center coordinates while the modal is still hidden.
- Open the modal to reveal the map.
$(document).ready(function() {
// Initialize jQuery modal (hidden by default)
$('#myModal').modal('hide');
// OpenLayers map initialization
var map = new ol.Map({
target: 'map', // The map div inside the modal
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
})
],
view: new ol.View({
center: ol.proj.fromLonLat([0, 0]), // Example coordinates
zoom: 2
})
});
// Event to open the modal
$('#openModalButton').on('click', function() {
$('#myModal').modal('show');
map.updateSize(); // Attempt to update map size
});
});