onPositionMapChanged method

void onPositionMapChanged({
  1. required LatLngBounds updatedBounds,
  2. required LatLng updatedCenter,
  3. required double updatedZoom,
})

Implementation

void onPositionMapChanged({
  required LatLngBounds updatedBounds,
  required LatLng updatedCenter,
  required double updatedZoom,
}) {
  if(_lastBounds == null) {
    _lastBounds = updatedBounds;
    return;
  }

  double currentZoom = updatedZoom;

  //LatLngBounds actualBoundWithMargin = mapCamera.visibleBounds;
  LatLngBounds actualBoundWithMargin = BBoxUtils.getBoundsWithMargin(
    updatedBounds,
    _pixelThreshold,
    currentZoom
  );

  // Get the latitude difference for the pixel threshold
  double thresholdLatDiff = BBoxUtils.latitudeDifferenceForZoom(
    currentZoom,
    _pixelThreshold,
    updatedCenter.latitude
  );

  // Calculate the distance between the two bounds
  var dist = BBoxUtils.computeDistance(
    pointA: _lastBounds!.northEast,
    pointB: actualBoundWithMargin.northEast,
  );

  // If the distance exceeds the threshold, refresh the map
  if (dist >= thresholdLatDiff) {
    _debugLazyLoaderPrint("Distance exceeds $_pixelThreshold px threshold, refreshing map...");

    _lastBounds = actualBoundWithMargin;
    refreshInfos = LazyLoadLayerRefresh(
      boundsToRefresh: actualBoundWithMargin,
      zoomLevel: currentZoom,
    );
    //cameraBoundLayer = BBoxUtils.redrawBoundingBox(_lastBounds, 0);
    if(_refreshLayerCallback != null) {
      _refreshLayerCallback!(refreshInfos);
    }
  }
}