When trying to display a side panel, I want to ensure that the map's proportions stay within the new div width or height. Currently, the map is simply resized, causing the countries to appear distorted. I attempted to use map.updateSize without success. How can I achieve this?
var map = new ol.Map({
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
})
],
target: 'map',
view: new ol.View({
center: [0, 0],
zoom: 2
})/*,
minResolution: "auto",
maxResolution: "auto"*/
});
/*window.onresize = function(event)
{
map.zoomOut(); map.zoomIn();
}*/
/*$('#map').on('change',function(){setTimeout(() => { this.map.updateSize(); });})*/
$("#btn").click(function(){
$("main aside").css("display","block");
$("main section").css("width","1000px");
$("#map").css("width","1000px")
});
$("#close").click(function(){
$("main aside").css("display","none");
$("main section").css("width","1100px");
$("#map").css("width","1100px")
});
/*map.updateSize()*/
/*map.onresize = setTimeout(() => { this.map.updateSize() })*/
$(window).resize(function () {
if (window.resizeMapUpdateTimer) {
clearTimeout(window.resizeMapUpdateTimer)
}
window.resizeMapUpdateTimer= setTimeout(function () {
// Update container size
map.updateSize()
}, 500)
})`var map = new ol.Map({
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
})
],
target: 'map',
view: new ol.View({
center: [0, 0],
zoom: 2
})/*,
minResolution: "auto",
maxResolution: "auto"*/
});
/*window.onresize = function(event)
{
map.zoomOut(); map.zoomIn();
}*/
/*$('#map').on('change',function(){setTimeout(() => { this.map.updateSize(); });})*/
$("#btn").click(function(){
$("main aside").css("display","block");
$("main section").css("width","1000px");
$("#map").css("width","1000px")
});
$("#close").click(function(){
$("main aside").css("display","none");
$("main section").css("width","1100px");
$("#map").css("width","1100px")
});
/*map.updateSize()*/
/*map.onresize = setTimeout(() => { this.map.updateSize() })*/
$(window).resize(function () {
if (window.resizeMapUpdateTimer) {
clearTimeout(window.resizeMapUpdateTimer)
}
window.resizeMapUpdateTimer= setTimeout(function () {
// Update container size
map.updateSize()
}, 500)
})