Handling cross-origin data/Tainted Canvas

36 views
Skip to first unread message

Sarva Pulla

unread,
Feb 21, 2017, 4:29:18 PM2/21/17
to Tethys Platform
I am trying to add an external WMS directly(aka not using a gizmo) to an openlayers3 map. However, if I use crossOrigin as anonymous it doesn't show up. But, the WMS gets added properly if I use the map view gizmo. After adding the WMS through the gizmo, I was trying to use the Map View Gizmo Javascript API to get the Map. However, It returns a tainted canvas thus not allowing me to add interaction onto the map. My question is, How does the map_view gizmo handle wms cross-origin data request or is there a way to work around adding external wms' without getting a CORS error/tainted canvas?

var wms_source = new ol.source.TileWMS({
            params:{
                LAYERS:"preview:fl_frequency"
            },
            serverType: 'geoserver'
        });

swainn

unread,
Feb 22, 2017, 10:16:11 PM2/22/17
to Tethys Platform
The MapView gizmo isn't working any differently than the example you provided, although it is not easily understood without carefully studying the code due to the generalization. 

Unfortunately, unless you have control over the external source, this will not be easy to resolve due to the Same Origin policy. Essentially, the external server needs to whitelist the domain your code is coming from via the Access-Control-Allow-Origin header. Check out this post for a better understanding of same origin and CORS considerations:


This post indicates that what you are experiencing is not a bug, but expected behavior:


It seems that preview.grid.unep.ch has been locked down to only accept requests from certain origins (perhaps inadvertently). Wish I could be more help.
Reply all
Reply to author
Forward
0 new messages