onScaleUpdate method

  1. @override
void onScaleUpdate(
  1. OpsScaleUpdateDetails details
)
override

Implementation

@override
void onScaleUpdate(OpsScaleUpdateDetails details) {
  var needStateIfNotDispose = false;
  var pinchZoomEnabled = widget.controller.pinchZoomEnabled;

  if (!_isScaleDirectionConfirm) {
    _isScaleDirectionConfirm = true;
    _isYDirection = details.mainDirection == Direction.Y;
  }
  if (_scale == -1.0) {
    if (pinchZoomEnabled) {
      _scale = details.scale;
    } else {
      _scale =
          _isYDirection ? details.verticalScale : details.horizontalScale;
    }
    return;
  }

  var scale = 1.0;
  if (pinchZoomEnabled) {
    scale = details.scale / _scale;
  } else {
    scale = _isYDirection
        ? details.verticalScale / _scale
        : details.horizontalScale / _scale;
  }

  MPPointF trans = _getTrans(_curX, _curY);
  var h = widget.controller.painter!.viewPortHandler;
  scale = Utils.optimizeScale(scale);
  if (pinchZoomEnabled) {
    bool canZoomMoreX =
        scale < 1 ? h!.canZoomOutMoreX() : h!.canZoomInMoreX();
    bool canZoomMoreY = scale < 1 ? h.canZoomOutMoreY() : h.canZoomInMoreY();
    widget.controller.painter?.zoom(
        canZoomMoreX ? scale : 1, canZoomMoreY ? scale : 1, trans.x, trans.y);
    needStateIfNotDispose = true;
  } else {
    if (_isYDirection) {
      if (widget.controller.painter!.scaleYEnabled) {
        bool canZoomMoreY =
            scale < 1 ? h!.canZoomOutMoreY() : h!.canZoomInMoreY();
        widget.controller.painter!
            .zoom(1, canZoomMoreY ? scale : 1, trans.x, trans.y);
        needStateIfNotDispose = true;
      }
    } else {
      if (widget.controller.painter!.scaleXEnabled) {
        bool canZoomMoreX =
            scale < 1 ? h!.canZoomOutMoreX() : h!.canZoomInMoreX();
        widget.controller.painter!
            .zoom(canZoomMoreX ? scale : 1, 1, trans.x, trans.y);
        needStateIfNotDispose = true;
      }
    }
  }

  if (widget.controller.touchEventListener != null) {
    var point = _getTouchValue(
        widget.controller.touchEventListener!.valueType(),
        details.globalFocalPoint.dx,
        details.globalFocalPoint.dy,
        details.localFocalPoint.dx,
        details.localFocalPoint.dy);
    widget.controller.touchEventListener?.onScaleUpdate(point.x, point.y);
  }

  if (needStateIfNotDispose) {
    setStateIfNotDispose();
  }

  MPPointF.recycleInstance(trans);

  if (pinchZoomEnabled) {
    _scale = details.scale;
  } else {
    _scale = _isYDirection ? details.verticalScale : details.horizontalScale;
  }
}