I have a very large set of features that outline city borders. Trying to convert them all to markers and load all onto a map at once seems to be bogging down my app.
What I’d like to do instead is only show these city border markers at an appropriate zoom level, and only those that are in the current view. This is what I have tried, with some small success:
public void mapChanged(MapEvent mapEvent){
if (mapEvent.getType().equals(PanMapEvent.TYPE_PAN)
|| mapEvent.getType().equals(ZoomMapEvent.TYPE_ZOOM)){
List<Marker> toAdd = new LinkedList<>();
List<Marker> toRemove = new LinkedList<>();
borderManager.clearMarkers();
if (map.getZoomLevel() > 6){
for (Marker m : cityBorderMarkers){
if (map.isHit(map.getScreenPosition(m.getLocation()))){
toAdd.add(m);
}
}
borderManager.addMarkers(toAdd);
}
}
}
However, it seems that using map.isHit(ScreenPosition)
returns true
even for locations that are a decent ways outside the current view and sometimes returns false
even if the location is clearly in the center of the map.
Any solution is appreciated.