Using different image in L.imageOverlay if the specified one doesn't exist

17 views
Skip to first unread message

Luis Carvalheiro

unread,
Mar 3, 2017, 8:16:57 AM3/3/17
to Leaflet

Dear all,

Does any of you knows a simple and CORS unaffected way of changing an L.imageOverlay image of the specified one does not exist?

I mean, i have, as a minimal working example


var startDate = new Date();
var today=(startDate.toISOString().slice(0,10).replace(/-/g,""));
var imageUrltoday='http://somesite.somedomain/'+today+'/day_0.png';
var imageBounds= [[36.25710105895996,-10.347503662109375],[42.64484977722168,-5.233795166015625]];


var map = L.map('map', {
    zoom: 5,
    fullscreenControl: true,
        timeDimension: false,

   center: [40.0, -4.50],    
});


var image_today=L.imageOverlay(imageUrltoday, imageBounds, {opacity: 0.7, attribution: 'blablabla'});
image_today.addTo(map);


so, the day_0.png might not always exist, and i'd like to replace it when it doesn't, by another image.
Can Anyone give me a hand on this?
Thanks in advance!
regards

devque...@gmail.com

unread,
Mar 8, 2017, 2:39:49 PM3/8/17
to Leaflet
Why cant you check its existence before calling  

>>L.imageOverlay(imageUrltoday, imageBounds, {opacity: 0.7, attribution: 'blablabla'});
Reply all
Reply to author
Forward
0 new messages