I'm trying to figure out what's the proper way of storing and filtering spatial data inside a running program.
I have a 2D map of theoretically infinite size. Users generate objects which are placed on the map, so infinite objects, theoretically.
I'm storing all this data inside an SQL database.
Whenever a user opens the map I fetch all of the objects within the rectangle they are viewing. When they move the map I subtract the already loaded rectangle from the new view box rectangle and fetch only the missing objects.
This is all fine until it gets to a point where there are a couple thousand objects cached in memory and I navigate the map to a place where I have all the objects loaded, but it takes a bunch of seconds to only go through the entire array of objects and determine which ones I need to draw - i.e. the ones within the current view box.
I'm pretty certain this problem has a name and is well known and solved, so as much as I loved to do that before I'd like to save some time and not reinvent the wheel, however I lack the terminology to help myself.