1

I have successfully installed OSM tile server on a local server. I verified operation using direct calls

http://server_ip/hot/z/x/y.png

I setup a page with OpenLayers 5.2.0. The layer init :

osm = new ol.layer.Tile({
    source: new ol.source.OSM({
        opaque: false,
        url: 'http://server_ip/hot/{z}/{x}/{y}.png'
        //url: 'http://a.tile.openstreetmap.org/{z}/{x}/{y}.png'
    })
});

When I use the a.tile.openstreetmap.org it works ok, but shows blank tiles on my local server call.

I verified the call to my server using wireshark, http request and reply. The return of HTTP are the required tiles (verified by saving them to disk). But OpenLayers is showing blank.

Does OpenLayers expect other parameters (in layer init code) when not specifically using osm server? (or timeout problem since my server is slower?)

  • 1
    If you are not using the default OSM url if may be better to use ol.source.XYZ instead of ol.source.OSM. As well as defaulting the url and attribution ol.source.OSM sets crossOrigin anonymous (which isn't needed unless you are accessing the canvas and will cause problems if the server isn't CORS enabled). – Mike Nov 10 '18 at 19:11
  • I just changed (ol.source.OSM) to (ol.source.XYZ) and it works. Thanks. Any side effects, moving from OSM to XYZ? – alsaleem Nov 10 '18 at 19:25
  • could you move to answer to accept. – alsaleem Nov 10 '18 at 19:26
1

If you are not using the default OSM url if may be better to use ol.source.XYZ instead of ol.source.OSM. ol.source.OSM extents ol.source.XYZ by setting default values if the following are not defined:

attributions
attributionsCollapsible (new in 5.3.0)
crossOrigin
maxZoom
url

The OSM default of crossOrigin anonymous when combined with a different url which isn't CORS enabled may result in tiles not loading.

  • thanks Mike. yes, indeed, it works with ol.source.OSM when I added (crossOrigin: null,). – alsaleem Nov 10 '18 at 20:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.