How to limit entries or improve performance with GeoDjango map?

I’m not sure if this is really along the lines of what you’re looking for, but I can tell you what we do.

You see a lot of examples of something like: L.marker(lat, lon).addTo(map). This creates an instance of a marker object and adds it to the map, but effectively ignores the reference to that marker.

What we do is track all markers in a dict (actually, a JavaScript object), and can then selectively add or remove them from a map.
Example:

points = {}'
points[point_id] = L.marker(point_lat, point_lon);
...
points[point_id].addTo(map);
...
points[point_id].remove();
...

However, depending upon the number of points involved, I’m not sure that you’re going to be that much more efficient with handling the display / removal of points from the map than Leaflet is going to be, unless you have a way of organizing your points such that they can be filtered quickly - at least to get “close” to what you need. (What I’d actually recommend in this case is that your “pre-filter” be a bit larger than the actual map bounding box to ensure no points are missed - and then let leaflet do the final decisions from that set.)
Handling zoom and scroll events might be a bit tricky as well. If you remove all points and then re-add them, it’s going to add a “flicker” to the display that may not be considered desirable. You might want to keep a separate index of points being displayed and only remove those points no longer of use.

From what I can tell, it all can be done. (We’ve never had to go that far, I’m only dealing with a couple thousand points.)

2 Likes