I am trying to show a map on a page via OpenLayers and it looks ok, but I have noticed that when I save map using toBlob as a .png image size is wrong. Then I have taken a look into html code and I have noticed that the actual size of the layer is not the same as its div-container.
Div container is 512x512 pixels but the layer is 384x384 pixels. And the transform matrix of the layer has values 1.33333 but not 1.
Here is the screenshot: https://ibb.co/X25cMpd
I need a way to make my layer fit exactly size of its container but I failed to understand how to achieve this so far.
<!DOCTYPE html>
<html>
<head>
<title>Simple Map</title>
<link rel="stylesheet" href="https://openlayers.org/en/v5.3.0/css/ol.css" type="text/css">
<!-- The line below is only needed for old environments like Internet Explorer and Android 4.x -->
<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script>
<style>
html, body
{
height: 100%;
width: 100%;
}
.container
{
margin: 0;
height: 512px;
width: 512px;
font-family: sans-serif;
background-color: rgb(23, 46, 107);
position: absolute;
}
</style>
</head>
<body>
<div id="map" class="container"></div>
</body>
</html>
And js:
import Map from 'ol/Map.js';
import View from 'ol/View.js';
import TileLayer from 'ol/layer/Tile.js';
import OSM from 'ol/source/OSM.js';
import VectorLayer from 'ol/layer/Vector';
import VectorSource from 'ol/source/Vector';
import GeoJSON from 'ol/format/GeoJSON';
var layer = new VectorLayer
({
source: new VectorSource
({
format: new GeoJSON(),
url: './data/countries.json'
})
});
var map = new Map({
layers: [layer],
target: 'map',
view: new View({
center: [0, 0],
zoom: 2
})
});