Hi Philippe,

`ol.style.Icon` does not provide an `error` or `load` event. But you could 
take care of loading the image yourself and then create an instance of 
`ol.style.Icon` by setting the loaded image as `img` argument (see in the 
documentation <http://openlayers.org/en/latest/apidoc/ol.style.Icon.html>). 
It would be something like this (untested):

    var image = new Image();
>     image.src = '33496-1.png';
>
>     var setStyle = function() {
>       var icon = new ol.style.Icon({img: image});
>       ..
>     };
>
>     if (image.complete) {
>       setStyle()
>     } else {
>       img.addEventListener('load', setStyle)
>       img.addEventListener('error', function() {
>           // use the default icon
>       })
>     }
>

See https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/Image 
and http://stackoverflow.com/a/24201249/119937 for reference.

Tobias


On Saturday, June 25, 2016 at 1:49:00 PM UTC+2, Philippe prevautel wrote:
>
> I wrote the following code:
>
> var icon = new ol.style.Icon({
>             src: '33496-1.png',  //  THIS IMAGE DOES NOT EXIST
>             scale: 0.7
>         });
>         icon.load();
>         
>         if (icon.getImageState() === ol.style.ImageState.ERROR) {
>             vector.setStyle(new ol.style.Style({
>                 image: new ol.style.Icon({
>                     src: 'no-icon.png',
>                     scale: 0.7
>                 })
>             }));
>         } else if (icon.getImageState() === ol.style.ImageState.LOADING || 
> icon.getImageState() === ol.style.ImageState.LOADED)  {
>             vector.setStyle(new ol.style.Style({
>                 image: icon
>             }));
>         }
>
> it works with firebug because of breakpoints. In fact the load function is 
> still running. How can i catch the event load or error or onchange on this 
> icon
>
> Thanks in advance
>

-- 
You received this message because you are subscribed to the Google Groups "OL3 
Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/ol3-dev.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ol3-dev/83669e51-51db-4ba1-b10b-5ebd0a741f81%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to