I am building a vector tileserver in node.js using mongo 2.4.7 as database.
My database contains geojson data from multiple sources and they are in many layers. It is important to render the layers in the correct sort order.
Since I have little, or no control of the client rendering the individual tiles I have to clip the geojson data before returning it to the client so one “lower lying” polygon does not hide another higher lying tile in an adjacent tile.
I have created an simple rectangle ->polygon clipper that works for now - but this should be improved later on. If anyone knows an efficient clipper library that is usable from node.js please let me know. This is, however, not the issue.
My real challenge is the finding the correct polygons within the database. I am currently using both $geoIntersects and $geoWithin in my query.
Let say that we have a polygon A that in zoom level x just fits within one tile bounding box (tile A). Here the Polygon will be returned by the $geoWithin clause and all is well.
Going several zoom levels in, the area from the tile A now fits within 9 tiles in a square. How do I find Polygon A when the server needs to render tile number 5 (the middle one)? And yes - in this situation I would like to render a square covering the complete tile due to the clipping.
I have created a drawing to illustrate my challenge.