How to resize markers in Openlayers based on zoom?

I am currently working with openlayers in an angular component. I am currently using the npm package 'ol 5.1.3'

I am trying to get markers to resize based on zoom levels. At a lower zoom level, show smaller markers. At a higher zoom level, show larger markers.

I am thinking perhaps a resize() function exists somewhere in the library and I should use that, however, I haven't been able to find one.

Another approach that I am currently taking is just re-drawing the vectorlayer by deleting it and re-doing it to draw new markers.

createFeatures() {
        const features = [];

        for (let i = 0; i < this.markers.length; i++) {

            const color = this.markers[i].status;
            const lon = this.markers[i].coordinates[0];
            const lat = this.markers[i].coordinates[1];

            const feature = new Feature({
                geometry: new Point(fromLonLat([lon, lat])),
                type: 'icon'

            // { externalGraphic: 'assets/map_features/sign.png', graphicHeight: 25, graphicWidth: 21, graphicXOffset: -12, graphicYOffset: -25 }
            feature.setStyle(new Style({
                image: new Icon({
                    src: 'assets/map_features/markers/sign_' + color + '_' + this.currentIconSize + '.png'


        this.iconSource = new VectorSource({
            features: features

        this.iconLayer = new VectorLayer({
            source: this.iconSource


calculateZoom(evt) {
        const map =;
        const currentZoom = map.getView().getZoom();

        if (currentZoom >= 12 && currentZoom <= 14) {
            this.currentIconSize = 'small';
        } else if (currentZoom === 15) {
            this.currentIconSize = 'medium';
        } else if (currentZoom === 16) {
            this.currentIconSize = 'large';


I am currently using a the function 'createFeatures' to generate my markers. I was thinking perhaps I could just re-run that function to do what I would like. Not sure if this is the best approach. I also am having an issue when I run


it will be undefined.