I am trying to showcase static images as maps using a StaticImage layer in ol3, with the image size set at 100% in pixels. However, I am facing difficulty in ensuring that the displayed images are always the correct size based on the extent and zoom variables. Despite reading numerous forum entries, I seem to be misunderstanding something crucial.
You can view a demo where incorrect image sizes are being displayed. The reference image is 128x128 pixels, yet the displayed image appears slightly larger at zoom level 0.
The example provided by OpenLayers here works perfectly when integrated into my demo. It suggests that setting the extent variable as [0,0,wid,len] and zoom: 2 should result in 100% display. However, this approach does not work consistently for all images.
Can anyone guide me on how to ensure that static images are reliably shown at 100% of their pixel size?
Thank you in advance for your assistance.
var extent = [0,0,128,128] // Image size is 128x128 px
var projection = new ol.proj.Projection({
code: 'local_image',
units: 'pixels',
extent: extent
});
var map = new ol.Map({
target: 'map',
view: new ol.View({
projection: projection,
center: ol.extent.getCenter(extent),
zoom: 0,
}),
controls: [],
});
var im_layer = new ol.layer.Image({
source: new ol.source.ImageStatic({
url: 'http://img4.wikia.nocookie.net/__cb20071014061100/freeciv/images/1/1c/Crystal_128_penguin.png', // Image size is 128x128 px
projection: projection,
imageExtent: extent
})
})
map.addLayer(im_layer)