handleEvent method

  1. @override
void handleEvent(
  1. Map arguments
)

React to view events and call the listener functions.

Throws

  • An exception if it fails.

Implementation

@override
void handleEvent(final Map<dynamic, dynamic> arguments) {
  final String eventType = arguments['eventType'];

  if (eventType == 'mapViewResizedEvent') {
    final Rectangle<int> viewport = Rectangle<int>(
      arguments['rectLeft'],
      arguments['rectTop'],
      arguments['rectWidth'],
      arguments['rectHeight'],
    );
    onViewportResized(viewport);
  }
  if (eventType == 'mapViewOnTouch') {
    final int ptx = arguments['point']['ptX'];
    final int pty = arguments['point']['ptY'];
    onTouch(Point<int>(ptx, pty));
  } else if (eventType == 'mapViewFollowPositionEntered') {
    onFollowPositionState(FollowPositionState.entered);
  } else if (eventType == 'mapViewFollowPositionExited') {
    onFollowPositionState(FollowPositionState.exited);
  } else if (eventType == 'onEnterTouchHandlerModifyFollowingPosition') {
    onTouchHandlerModifyFollowPosition(FollowPositionState.entered);
  } else if (eventType == 'onExitTouchHandlerModifyFollowingPosition') {
    onTouchHandlerModifyFollowPosition(FollowPositionState.exited);
  } else if (eventType == 'onPointerUp') {
    final int ptx = arguments['ptX'];
    final int pty = arguments['ptY'];
    onPointerUp(arguments['pointerId'], Point<int>(ptx, pty));
  } else if (eventType == 'onPointerDown') {
    final int ptx = arguments['ptX'];
    final int pty = arguments['ptY'];
    onPointerDown(arguments['pointerId'], Point<int>(ptx, pty));
  } else if (eventType == 'onPointerMove') {
    final int ptx = arguments['ptX'];
    final int pty = arguments['ptY'];
    onPointerMove(arguments['pointerId'], Point<int>(ptx, pty));
  } else if (eventType == 'onMove') {
    final int ptx = arguments['startPoint']['ptX'];
    final int pty = arguments['startPoint']['ptY'];
    final int ptendx = arguments['endPoint']['ptX'];
    final int ptendy = arguments['endPoint']['ptY'];
    onMove(Point<int>(ptx, pty), Point<int>(ptendx, ptendy));
  } else if (eventType == 'onTouchMove') {
    final int ptx = arguments['startPoint']['ptX'];
    final int pty = arguments['startPoint']['ptY'];
    final int ptendx = arguments['endPoint']['ptX'];
    final int ptendy = arguments['endPoint']['ptY'];
    onTouchMove(Point<int>(ptx, pty), Point<int>(ptendx, ptendy));
  } else if (eventType == 'onSwipe') {
    final int distX = arguments['distX'];
    final int distY = arguments['distY'];
    final double speed = arguments['speed'];
    onSwipe(distX, distY, speed);
  } else if (eventType == 'onPinchSwipe') {
    final int centerPosInPixX = arguments['centerPosInPixX'];
    final int centerPosInPixY = arguments['centerPosInPixY'];
    final double zoomSpeed = arguments['zoomSpeed'];
    final double rotateSpeed = arguments['rotateSpeed'];
    onPinchSwipe(
      Point<int>(centerPosInPixX, centerPosInPixY),
      zoomSpeed,
      rotateSpeed,
    );
  } else if (eventType == 'onPinch') {
    final int start1X = arguments['start1X'];
    final int start1Y = arguments['start1Y'];
    final int start2X = arguments['start2X'];
    final int start2Y = arguments['start2Y'];
    final int end1X = arguments['end1X'];
    final int end1Y = arguments['end1Y'];
    final int end2X = arguments['end2X'];
    final int end2Y = arguments['end2Y'];
    final int centerX = arguments['centerX'];
    final int centerY = arguments['centerY'];
    onPinch(
      Point<int>(start1X, start1Y),
      Point<int>(start2X, start2Y),
      Point<int>(end1X, end1Y),
      Point<int>(end2X, end2Y),
      Point<int>(centerX, centerY),
    );
  } else if (eventType == 'onTouchPinch') {
    final int start1X = arguments['start1X'];
    final int start1Y = arguments['start1Y'];
    final int start2X = arguments['start2X'];
    final int start2Y = arguments['start2Y'];
    final int end1X = arguments['end1X'];
    final int end1Y = arguments['end1Y'];
    final int end2X = arguments['end2X'];
    final int end2Y = arguments['end2Y'];
    onTouchPinch(
      Point<int>(start1X, start1Y),
      Point<int>(start2X, start2Y),
      Point<int>(end1X, end1Y),
      Point<int>(end2X, end2Y),
    );
  } else if (eventType == 'mapViewOnLongDown') {
    final int ptx = arguments['ptX'];
    final int pty = arguments['ptY'];
    onLongPress(Point<int>(ptx, pty));
  } else if (eventType == 'onDoubleTouch') {
    final int ptx = arguments['ptX'];
    final int pty = arguments['ptY'];
    onDoubleTouch(Point<int>(ptx, pty));
  } else if (eventType == 'onTwoTouches') {
    final int ptx = arguments['ptX'];
    final int pty = arguments['ptY'];
    onTwoTouches(Point<int>(ptx, pty));
  } else if (eventType == 'onTwoDoubleTouches') {
    final int ptx = arguments['ptX'];
    final int pty = arguments['ptY'];
    onTwoDoubleTouches(Point<int>(ptx, pty));
  } else if (eventType == 'onMapAngleUpdate') {
    final double angle = arguments['angle'];
    onMapAngleUpdate(angle);
  } else if (eventType == 'onMarkerRender') {
    onMarkerRender(arguments);
  } else if (eventType == 'onViewRendered') {
    onViewRendered(arguments);
  } else if (eventType == 'onShove') {
    final double pointersAngleDeg = arguments['pointersAngleDeg'];
    final int initialX = arguments['initialX'];
    final int initialY = arguments['initialY'];
    final int startX = arguments['startX'];
    final int startY = arguments['startY'];
    final int endX = arguments['endX'];
    final int endY = arguments['endY'];

    onShove(
      pointersAngleDeg,
      Point<int>(initialX, initialY),
      Point<int>(startX, startY),
      Point<int>(endX, endY),
    );
  } else if (arguments['eventType'] == 'onMapCaptured') {
    _captureAsImageCompleter!.complete(
      Uint8List.fromList(base64Decode(arguments['buffer'])),
    );
    _captureAsImageCompleter = null;
  } else if (arguments['eventType'] == 'renderMapScale') {
    final int scaleWidth = arguments['scaleWidth'];
    final String scaleValueStr = arguments['scaleValue'];
    final int? scaleValue = int.tryParse(scaleValueStr);
    if (scaleValue == null) {
      return;
    }
    final String scaleUnits = arguments['scaleUnits'];

    if (_scaleWidthPrev == scaleWidth &&
        _scaleValuePrev == scaleValue &&
        _scaleUnitsPrev == scaleUnits) {
      return;
    }
    onRenderMapScale(scaleWidth, scaleValue, scaleUnits);
    _scaleWidthPrev = scaleWidth;
    _scaleValuePrev = scaleValue;
    _scaleUnitsPrev = scaleUnits;
  } else if (eventType == 'onCursorSelectionUpdatedLandmarks') {
    final int objectId = arguments['list'];
    final LandmarkList gemList = LandmarkList.init(objectId, 0);
    final List<Landmark> list = gemList.toList();
    onCursorSelectionUpdatedLandmarks(list);
  } else if (eventType == 'onCursorSelectionUpdatedOverlayItems') {
    final int objectId = arguments['list'];
    final OverlayItemList gemList = OverlayItemList.init(objectId);
    final List<OverlayItem> list = gemList.toList();
    onCursorSelectionUpdatedOverlayItems(list);
  } else if (eventType == 'onCursorSelectionUpdatedTrafficEvents') {
    final int objectId = arguments['list'];
    final TrafficEventList gemList = TrafficEventList.init(objectId, 0);
    final List<TrafficEvent> list = gemList.toList();
    onCursorSelectionUpdatedTrafficEvents(list);
  } else if (eventType == 'onCursorSelectionUpdatedRoutes') {
    final int objectId = arguments['list'];
    final RouteList gemList = RouteList.init(objectId, 0);
    final List<Route> list = gemList.toList();
    onCursorSelectionUpdatedRoutes(list);
  } else if (eventType == 'onCursorSelectionMarkerMatches') {
    final int objectId = arguments['list'];
    final MarkerMatchList gemList = MarkerMatchList.init(objectId, 0);
    final List<MarkerMatch> list = gemList.toList();
    onCursorSelectionUpdatedMarkers(list);
  } else if (eventType == 'onCursorSelectionPath') {
    final int objectId = arguments['list'];
    final Path path = Path.init(objectId, 0);
    onCursorSelectionUpdatedPath(path);
  } else if (eventType == 'onCursorSelectionMapSceneObject') {
    onCursorSelectionUpdatedMapSceneObject(
      MapSceneObject.getDefPositionTracker(),
    );
  } else if (eventType == 'onHoveredMapLabelHighlightedLandmark') {
    final int objectId = arguments['obj'];
    final Landmark obj = Landmark.init(objectId, 0);
    onHoveredMapLabelHighlightedLandmark(obj);
  } else if (eventType == 'onHoveredMapLabelHighlightedOverlayItem') {
    final int objectId = arguments['obj'];
    final OverlayItem obj = OverlayItem.init(objectId);
    onHoveredMapLabelHighlightedOverlayItem(obj);
  } else if (eventType == 'onHoveredMapLabelHighlightedTrafficEvent') {
    final int objectId = arguments['obj'];
    final TrafficEvent obj = TrafficEvent.init(objectId, 0);
    onHoveredMapLabelHighlightedTrafficEvent(obj);
  } else if (eventType == 'onSetMapStyle') {
    final int id = arguments['id'];
    final String stylePath = arguments['stylePath'];
    final bool viaApi = arguments['viaApi'];
    onSetMapStyle(id, stylePath, viaApi);
  } else {
    gemSdkLogger.log(
      Level.WARNING,
      'Unknown event subtype: $eventType in GemView',
    );
  }
}