Switching to OpenMapTiles and Fixing Small Bugs #155
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This description follows a
[problem] => [commit link]format where each problem's description followed by the commit that resolves it.Runtime Error
After cloning the repo, when you run
npm installfollowed bynode main.js, you will encounter:To fix it, we need to always return the buffer in the
_getHTTPmethod ofTileSource.js.commit
1736dac: fixed undefined slice error at runtimeRemote Tile Source Issues
After fixing the initial runtime error, running
node main.jsreveals rendering bugs at certain zoom levels.These issues stem from problems with files hosted on
mapscii.merather than the codebase itself. You can verify this by using a local .mbtiles file. As osm2vectortiles was archived a while ago, you can only download such.mbtilesfrom Wayback Machine.Planet from z0 to z5 (20MB)
Planet from z0 to z8 (411MB)
However, when running
You will encounter
Error: no TileSource defined. To fix the issue, we need to make theinitmethod inTileSource.jsand_initTileSourcemethod inMapscii.jsasynchronous.commit
ea69053: fixed no tilesource defined error when using local mbtiles fileZoom Level Crashes
When using the .mbtiles files linked above, if you keep on zooming, the program crashes with
Tile does not existerror as the file only supports zooming upto a certain point.commit
5a1d9b0: prevent zooming beyond max zoom level in local mbtiles fileMigrating to OpenMapTiles
The main three changes are:
Layer Name Updates
_generateDrawOrderfunction inRenderer.jslayersarray inconfig.js.Change tile source
config.jsandTileSource.spec.jsUnimplemented type: 4error.https://tiles.openfreemap.org/planet/map/but themappart is a wildcard.Update styles in
dark.jsonCommit
ea03d52: migrate to OpenMapTilesFilter Interpreting Issue
At this point, when you zoom in, you will see color of the
roadlayer has changed from yellow to pink.To find the reason, we need to go back to commit
5a1d9b0i.e. the codebase before migrating to OpenMapTiles. Now, take a look at the first two instances of"source-layer": "road"in the olddark.json.{ "type": "line", "id": "tunnel_path_pedestrian", "paint": { "line-color": "@tunnel_path_pedestrian" }, "source-layer": "road", "filter": [ "all", ["==", "$type", "LineString"], [ "all", ["==", "structure", "tunnel"], ["in", "class", "path", "pedestrian"] ] ] }, { "type": "line", "id": "tunnel_motorway_link", "paint": { "line-color": "@tunnel_motorway_link" }, "source-layer": "road", "filter": [ "all", ["==", "structure", "tunnel"], ["==", "class", "motorway_link"] ] }If you change the value of
@tunnel_path_pedestrian, you won't notice a change in the map. However, if you change value of@tunnel_motorway_link, you will see a change in the color of all roads. This is problematic because the filter should color aroadonly if it's atunneland amotorway_linkbut it seems like it is coloring all the roads.However, in the new version, when you modify the value of
@tunnel_path, it is changing color of everything intransportationlayer. This is most likely because the filter does not have double nesting anymore, implying an issue with interpretation of double nesting inside a filter. Fortunately, we do not have to fix it right now because we can write the same filter condition without using double nesting due to filter conditions being essentially just AND logic,{ "type": "line", "id": "tunnel_path", "paint": { "line-color": "@tunnel_path" }, "source-layer": "transportation", "filter": [ "all", ["==", "$type", "LineString"], ["==", "brunnel", "tunnel"], ["==", "class", "path"] ] }, { "type": "line", "id": "tunnel_motorway_ramp", "paint": { "line-color": "@tunnel_motorway_ramp" }, "source-layer": "transportation", "filter": [ "all", ["==", "brunnel", "tunnel"], ["==", "class", "motorway"], ["==", "ramp", 1] ] }However, we do have to fix the issue of all transportation paths being colored with the first instance of layer
transportation, regardless of the filter condition. This issue stems from handling of the 'all' keyword inStyler.js.As the styles are now rendering properly, we can proceed to fix some issues with styling. As the map becomes cluttered with country names and boundaries at early zoom levels, I added some zoom limits via
minzoomindark.json. Additionally, I changed@admin_level_2from#fffto#aacto reduce eye strain.commit
1015ecd: fixed handling of filter keyword 'all' and updated stylesPolygon Rendering
There are still some rendering issues like blacked out areas where there is supposed to be ocean, and a huge water block appearing across Europe. To fix these issues, you have to modify the polygon rendering in
Canvas.js. In the new version, we first separate between outer and inner rings and then use point-in-polygon to figure out which inner ring belongs to which outer ring.commit
d85535e: fixed water appearing over land and areas with missing waterWater Block Blackouts
Now, another issue you will notice is when zoomed in a bit, certain water blocks black out. You need to increase the range in
_getTileFeaturesfunction inRenderer.jsto fix the issue.commit
ecda55a: fixed empty blocks at some zoom levelsAdapt bright.json
Finally, I just converted
bright.jsonto be compatible with OpenMapTiles.commit
588ec3c: adapted bright.json for OpenMapTiles