public static MGLMapCamera ToNative(this CameraPosition cameraPosition, CGSize size) { var heading = cameraPosition.Bearing ?? 0; var centerCoordinate = cameraPosition.Target ?? LatLng.Zero; var pitch = (nfloat)(cameraPosition.Tilt ?? 0); var altitude = 0.0; // TODO iOS Convert Zoom to Altitude if (cameraPosition.Zoom.HasValue) { var result = MapboxIndependentFunction.MGLAltitudeForZoomLevel( cameraPosition.Zoom.Value, (nfloat)(cameraPosition.Tilt ?? 0), cameraPosition.Target?.Lat ?? 0, size); altitude = result; } var camera = MGLMapCamera.CameraLookingAtCenterCoordinateAndAltitude( centerCoordinate.ToCLCoordinate(), altitude, pitch, heading ); return(camera); }
public static MGLMapCamera ToNative(this CameraBounds cameraBounds, MGLMapView map) { var camera = map.CameraThatFitsCoordinateBounds( cameraBounds.Bounds.ToNative(), cameraBounds.Padding.ToEdgeInsets() ); var heading = cameraBounds.Bearing ?? camera.Heading; var pitch = (nfloat)(cameraBounds.Tilt ?? camera.Pitch); var result = MGLMapCamera.CameraLookingAtCenterCoordinateAndAltitude( camera.CenterCoordinate, camera.Altitude, pitch, heading ); return(result); }
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) { base.OnElementPropertyChanged(sender, e); if (map == null || Element == null) { return; } if (e.PropertyName == MapView.VisibleBoundsProperty.PropertyName) { UpdateRegion(); } else if (e.PropertyName == MapView.CenterProperty.PropertyName) { UpdateCenter(); } else if (e.PropertyName == MapView.ZoomLevelProperty.PropertyName) { if (Element.ZoomLevel.HasValue == false) { return; // TODO Set to default value } var isSameLevel = Math.Round(Element.ZoomLevel.Value * 100).Equals(Math.Round(map.ZoomLevel * 100)); if (isSameLevel) { return; } map.ZoomLevel = Element.ZoomLevel.Value; } else if (e.PropertyName == MapView.PitchEnabledProperty.PropertyName) { if (map.PitchEnabled == Element.PitchEnabled) { return; } map.PitchEnabled = Element.PitchEnabled; } else if (e.PropertyName == MapView.ScrollEnabledProperty.PropertyName) { if (map.ScrollEnabled == Element.ScrollEnabled) { return; } map.ScrollEnabled = Element.ScrollEnabled; } else if (e.PropertyName == MapView.RotateEnabledProperty.PropertyName) { if (map.RotateEnabled == Element.RotateEnabled) { return; } map.RotateEnabled = Element.RotateEnabled; } else if (e.PropertyName == MapView.AnnotationsProperty.PropertyName) { if (Element.Annotations == null || Element.Annotations.Count() == 0) { return; } AddAnnotations(Element.Annotations.ToArray()); if (Element.Annotations is INotifyCollectionChanged observable) { observable.CollectionChanged -= OnAnnotationsCollectionChanged; observable.CollectionChanged += OnAnnotationsCollectionChanged; } } else if (e.PropertyName == MapView.MapStyleProperty.PropertyName) { var shouldNotUpdate = string.IsNullOrWhiteSpace(Element.MapStyle?.UrlString) || string.Equals(Element.MapStyle.UrlString, map.StyleURL?.AbsoluteString); if (shouldNotUpdate) { return; } UpdateMapStyle(); } else if (e.PropertyName == MapView.PitchProperty.PropertyName) { var shouldNotUpdate = Math.Abs(Element.Pitch - map.Camera.Pitch) < 0.05; if (shouldNotUpdate) { return; } var currentCamera = map.Camera; var newCamera = MGLMapCamera.CameraLookingAtCenterCoordinateAndAltitude( currentCamera.CenterCoordinate, currentCamera.Altitude, (nfloat)Element.Pitch, currentCamera.Heading); map.SetCamera(newCamera, true); } else if (e.PropertyName == MapView.RotatedDegreeProperty.PropertyName) { var shouldNotUpdate = Math.Abs(Element.RotatedDegree - map.Camera.Heading) < 0.05; if (shouldNotUpdate) { return; } var currentCamera = map.Camera; var newCamera = MGLMapCamera.CameraLookingAtCenterCoordinateAndAltitude( currentCamera.CenterCoordinate, currentCamera.Altitude, currentCamera.Pitch, (nfloat)Element.RotatedDegree); map.SetCamera(newCamera, true); } else if (e.PropertyName == MapView.ShowUserLocationProperty.PropertyName) { map.ShowsUserLocation = Element.ShowUserLocation; } }