grst / geos

Google Earth Overlay Server - display map overlays in Google Earth
https://grst.github.io/geos
BSD 3-Clause "New" or "Revised" License
42 stars 12 forks source link

Correct CORS configuration #25

Closed nono303 closed 4 years ago

nono303 commented 4 years ago

Hi,

According to https://help.openstreetmap.org/questions/38308/osm-tile-server-how-to-enable-cors, crossOrigin for OL must be nulland not 'anonymous' to avoid CORS blocking.

Here is the working patch:

diff --git "a/geos/static/custom.js" "b/geos/static/custom.js"
index ab2b30e..85de081 100644
--- "a/geos/static/custom.js"
+++ "b/geos/static/custom.js"
@@ -307,14 +307,15 @@ function activateMap(mapSource) {
     currentMap = mapSource;
     $('#maps li.active').removeClass('active');
     $('#' + mapSource.id).addClass('active');
-    console.log(mapSource.name);
+    console.log('loading: '+mapSource.name);
     layers = map.getLayers();
     layers.clear();
     $.each(mapSource.layers, function (i, tileLayer) {
         tmpLayer = new ol.layer.Tile({
             source: new ol.source.XYZ({
                 url: tileLayer.tile_url,
-                crossOrigin: 'anonymous',
+               // https://help.openstreetmap.org/questions/38308/osm-tile-server-how-to-enable-cors
+                crossOrigin: null,
                 minZoom: tileLayer.min_zoom,
                 maxZoom: tileLayer.max_zoom
             })
grst commented 4 years ago

:+1:

Would you make that a PR?

nono303 commented 4 years ago

there you go! https://github.com/grst/geos/pull/26