Search code examples
javascriptphpmapboxopenmaptiles

When I try to apply my own style to the tiles served by Tileserver PHP, I get this error: "Unable to parse URL object"


In search of a simple tileserver, I found Tileserver PHP. I tried to follow this tutorial. I'm hosting the files on a Linux box with address 192.168.2.22 in my network, of course with Apache and PHP. I had success when I opened http://192.168.2.22/tileserver/, because I then saw the tiles I downloaded in *.mbtiles format. Then I tried to apply this version of OSM Bright Style. As described in the tutorial, I adapted file style-cdn.json. In my case, the modified section looks like this:

"sources": {
    "openmaptiles": {
        "type": "vector",
        "url": "/tileserver/tileserver.php?/2017-07-03_bangladesh_dhaka.json"
    }
},
"sprite": "/brightstyle/sprite",

As you can see, I used a relative URL. I also tried things with the absolute address, but I did not see any differences. Anyway, when I point my browser to http://192.168.2.22/brightstyle/, I don't see any tiles appearing. I noticed that an error occurs in the client - unfortunately. It is shown in the console of my Firefox browser: Error: "Unable to parse URL object". It occurs after retrieving https://api.tiles.mapbox.com/mapbox-gl-js/v1.5.0/mapbox-gl.js. Further info from the console:
ajax.js:169
evented.js:136:20
fire evented.js:136
_request style.js:201.

What is causing this error and what can I do to solve this?


Solution

  • After further inspecting and trying, it was indeed the relative URL which caused the problem. After specifying the URL as http://192.169.2.22/tileserver/tileserver.php?/2017-07-03_bangladesh_dhaka.json", I encountered another error: Source layer "aerodrome_label" does not exist on source "openmaptiles" as specified by style layer "airport-label-major". I solved this by removing the layer with id = "airport-label-major" altogether. Finally I solved errors like "Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at .." by hosting the tiles on my own machine. I'm now seeing tiles ;-)