Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add the base64 decoded image to openlayer map?

This is my version. But it is not working. Canvas is displayed, but does not respond to the tug and zoom.

               var layer = new ol.layer.Image({
                source: new ol.source.ImageCanvas({
                    canvasFunction: function(){
                        var canvas = document.createElement('canvas');
                        var context = canvas.getContext('2d');
                        var image = new Image();

                        canvas.setAttribute('width', attachment.width);
                        canvas.setAttribute('height', attachment.height);

                        image.onload = function(){
                            context.drawImage(image, 0, 0);
                        };

                        image.src = attachment.src;

                        return canvas;
                    },
                    projection: view.getProjection()
                })
            });
like image 228
Aleksandr Avatar asked Dec 29 '25 22:12

Aleksandr


1 Answers

I find answer! Just use ol.source.ImageStatic and imageLoadFunction :

            var layer = new ol.layer.Image({
            source : new ol.source.ImageStatic({
                imageExtent : view.getProjection().getExtent(),
                size : [attachment.width, attachment.height],
                imageLoadFunction : function(image){
                    image.getImage().src = attachment.src;
                },
                projection : view.getProjection(),
                url : ''
            })
        });
like image 122
Aleksandr Avatar answered Jan 01 '26 10:01

Aleksandr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!