In my app at the moment, a 'grid' is drawn onto the map by drawing each polygon square one by one, and filling it with a color. I then add the polygon object to a map to modify later if I need to.
I only create each polygon once, however there is a major consistent 'lag' and low frame rate with the more I add (tens of thousands potentially), eventually breaking the app.
Here is the current part of code that creates and adds each 'Square' to a hashmap.
double latScale = 0.000180;
double lngScale = 0.000288;
PolygonOptions po = new PolygonOptions()
.add( new LatLng(lat, lng),
new LatLng(lat, lng + lngScale),
new LatLng(lat - latScale, lng + lngScale),
new LatLng(lat - latScale, lng))
.strokeWidth(3f)
.strokeColor(Color.argb(220, 0, 0, 0));
if (colors.containsKey(color)){
po.fillColor(colors.get(color));
}
else{
po.fillColor(colors.get("default"));
}
gridSquares.put(square_id, mMap.addPolygon(po));
My question is, what exactly is causing it to lag so much (I realize it must be the sheer amount, but I need specifics, re drawing every frame? memory?) And how could I fulfill my need for this giant grid overlay in some way which doesn't lag so much. Either with my current line of thinking or a new way.
If any more clarification is needed please ask.