TransWikia.com

Resizing a marker icon in OpenLayers 6

Geographic Information Systems Asked by spj_uk on March 10, 2021

I have an icon that 4px by 4px and I use it as a marker. However I want to display it larger than 4×4, lets say 40px x 40px for example. Here is my code

var iconStyle = new ol.style.Style({
                image: new ol.style.Icon(({
                    size: [40, 40],
                    offset: [-20, -20],
                    //anchor: [0.5, 1],                    
                    src: "/images/historymarker.png",
                    opacity: 1,
                    id: num + "_" + x
                }))
            });            
            marker.setStyle(iconStyle);

However the icons comes out as it original size, Is there a way to resize it? I thought that size would have done it.

One Answer

You can use scale:

var iconStyle = new ol.style.Style({
                image: new ol.style.Icon(({
                    scale: 10,
                    offset: [-20, -20],
                    //anchor: [0.5, 1],                    
                    src: "/images/historymarker.png",
                    opacity: 1,
                    id: num + "_" + x
                }))
            });            
            marker.setStyle(iconStyle);

Documentation

Example with a scale of 0.5

Correct answer by geocodezip on March 10, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP