void OnInputHold(MapInputEventArgs e) { var coords = GetCoordinatesForScreenPosition(e.TouchPosition); if (coords != null) { OnHold.Invoke(new MapControllerEventArgs(coords)); } }
protected virtual void Update() { if (!m_firstUpdateComplete) { if (ForegroundPositionService.Instance.HasLocationData) { if (Ready != null) { Ready.Invoke(new MapControllerEventArgs(ForegroundPositionService.Instance.Position)); } m_userAnnotation = new UserAnnotation(); m_userAnnotation.Coordinates = ForegroundPositionService.Instance.Position; if (LockToUser) { LockOnUser(true); } MapView.AddAnnotation(m_userAnnotation); var startCoords = m_startCoordinates ?? ForegroundPositionService.Instance.Position; SetMapRegion(startCoords, ZoomLevel); //m_startMapZoom = ZoomLevel; m_firstUpdateComplete = true; } } else { // Add/remove any annotations on the correct thread if (m_toAdd.Count > 0) { lock (m_toAdd) { var toAdd = m_toAdd.ToArray(); m_toAdd.Clear(); foreach (var ann in toAdd) { MapView.AddAnnotation(ann); } } } if (m_toRemove.Count > 0) { lock (m_toRemove) { var toRemove = m_toRemove.ToArray(); m_toRemove.Clear(); foreach (var ann in toRemove) { MapView.RemoveAnnotation(ann); } } } // The map view will not necessarily re-check the coordinates unless the // told directly. m_userAnnotation.UpdateCoordinates(ForegroundPositionService.Instance.Position, Time.deltaTime); MapView.UpdateAnnotation(m_userAnnotation); if (m_lockAnnotation != null) { SetMapRegion(m_lockAnnotation.Coordinates, MapView.Zoom); if (MapInput.PointerDown && DeselectAnnotationOnMapInput) { SelectAnnotation(null); } } else { if (MapInput.IsTranslating) { m_panToCoordinates = null; m_panToZoom = null; if (DeselectAnnotationOnMapInput) { SelectAnnotation(null); } if (MapInput.Translation.sqrMagnitude > 0) { var tx = -MapInput.Translation.x / (m_mapPixWidth); var ty = MapInput.Translation.y / (m_mapPixWidth); MapView.Translate(tx, ty); } } else { //m_currTranslate = Vector2.zero; if (m_panToCoordinates != null) { var zoom = MapView.Zoom == 0 ? ZoomLevel : MapView.Zoom; Coordinates coordinates = null; if (m_panDuration.HasValue) { // Use smoothstep for time-based transitions var dt = Mathf.Min((Time.time - m_panStartTime) / m_panDuration.Value, 1f); var delta = Mathf.SmoothStep(0, 1, dt); coordinates = m_panStartCoordinates.Interpolate(m_panToCoordinates, delta); if (m_panToZoom.HasValue) { zoom = Mathf.SmoothStep((float)m_panStartZoom, (float)m_panToZoom, dt); } } else { // Use exponential - good for general purpose as it takes longer over long // distances coordinates = MapView.CenterCoordinates.Approach(m_panToCoordinates, PanSpeed, Time.deltaTime); if (m_panToZoom.HasValue) { zoom = MathHelper.Approach(zoom, m_panToZoom.Value, PanSpeed, Time.deltaTime); } } var dz = m_panToZoom.HasValue ? Math.Abs(zoom - m_panToZoom.Value) : 0; SetMapRegion(coordinates, zoom); if (coordinates.GetDistanceFrom(m_panToCoordinates) < 0.5 && dz < 0.1) { SetMapRegion(m_panToCoordinates, m_panToZoom ?? MapView.Zoom); m_panToCoordinates = null; if (m_onPanComplete != null) { m_onPanComplete(); } } } } } if (MapInput.IsPinching) { SetMapRegion(MapView.CenterCoordinates, MapView.Zoom + MapInput.ZoomDelta); } } }