maptiler / tileserver-gl

Vector and raster maps with GL styles. Server side rendering by MapLibre GL Native. Map tile server for MapLibre GL JS, Android, iOS, Leaflet, OpenLayers, GIS via WMTS, etc.
https://tileserver.readthedocs.io/en/latest/
Other
2.22k stars 636 forks source link

Some refactoring ideas #537

Open mnutt opened 3 years ago

mnutt commented 3 years ago

First off, thank you for creating this project, it is really great to have high-quality map rendering in node!

I was in the process of adding a feature (rendering multiple markers) and trying to write tests for it, and one thing led to another and I found myself making some significant code changes so I thought I'd start a discussion here rather than dropping a massive PR that totally changes the project layout.

It looks like the project is roughly split into Styles, Data, Fonts, and Rendering. Data and Fonts are completely standalone, while Styles somewhat depends on Data for resolving its sources, and Rendering depends on Styles, Data, and Fonts.

What if we created "manager" classes (I'm not at all attached to the word "manager") for each of these components in src/managers/*, and then individual routes files in src/routes/*. That would let us instantiate and test the manager functionality separate from the express app, and also be able to instantiate the express app without needing to pass a lot of state around except options. The entrypoint would await initialization of the managers, then create the express app and bind it to a port.

If this general direction sounds good I'd be happy to take this effort on. I have a working implementation of it here with the caveats that 1) while it passes all of the existing tests, I'm sure there are edge cases I'm missing, and 2) there's still a lot of cleanup to be done and tests for me to write, and 3) there's some markers-related code in there that really should be in its own PR.

mnutt commented 3 years ago

Also if you think these changes go in the totally wrong direction or are just too large for a project at this stage feel free to say so; I'm happy to maintain my changes as a (differently-named) fork.