-
-
Notifications
You must be signed in to change notification settings - Fork 888
Open
Description
What do you want implemented?
Not sure how much performance improvements we can get from this.
We have a couple of methods for projecting LatLng.
(double, double) latLngToXY(LatLng latlng, double scale);
/// Similar to [latLngToXY] but converts the XY coordinates to an [Offset].
Offset latLngToOffset(LatLng latlng, double zoom) {
final (x, y) = latLngToXY(checkLatLng(latlng), scale(zoom));
return Offset(x, y);
}The most used method is latLngToOffset, that computes a scale.
/// Zoom to Scale function.
double scale(double zoom) => 256.0 * math.pow(2, zoom);The thing is that we constantly compute math.pow(2, zoom).
Given that most of the time (always?) we work on a single zoom level for all points, we could cache the latest zoom/scale values.
Something like that:
double _latestZoom = -1;
double _latestScale = -1;
double scale(double zoom) {
if ((_latestZoom == -1 && _latestScale == -1) || _latestZoom != zoom) {
_latestZoom = zoom;
return _latestScale = 256.0 * math.pow(2, zoom);
}
return _latestScale;
}What other alternatives are available?
No response
Can you provide any other information?
No response
Metadata
Metadata
Assignees
Labels
No labels