Example #1
0
        private void ARViewTapped(object sender, GeoViewInputEventArgs e)
        {
            // Don't add features when calibrating the AR view.
            if (_isCalibrating)
            {
                return;
            }

            // Try to get the real-world position of that tapped AR plane.
            MapPoint planeLocation = MyARSceneView.ARScreenToLocation(e.Position);

            // Remove any existing graphics.
            _graphicsOverlay.Graphics.Clear();

            // Check if a Map Point was identified.
            if (planeLocation != null)
            {
                // Add a graphic at the tapped location.
                _graphicsOverlay.Graphics.Add(new Graphic(planeLocation, _tappedPointSymbol));
                AddButton.IsEnabled = true;
                HelpLabel.Text      = "Placed relative to ARCore plane";
            }
            else
            {
                Application.Current.MainPage.DisplayAlert("Error", "Didn't find anything, try again.", "OK");
                AddButton.IsEnabled = false;
            }
        }
Example #2
0
 private void ARGeoViewTapped(object sender, Esri.ArcGISRuntime.Xamarin.Forms.GeoViewInputEventArgs e)
 {
     // If the tapped position is valid, display the scene.
     if (MyARSceneView.SetInitialTransformation(e.Position))
     {
         DisplayScene();
     }
 }
Example #3
0
 // This method is called by the sample viewer when the AR sample has appeared.
 async void IARSample.StartAugmentedReality()
 {
     // Start device tracking.
     try
     {
         await MyARSceneView.StartTrackingAsync();
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine(ex.Message);
     }
 }
Example #4
0
 protected override async void OnAppearing()
 {
     // Start device tracking.
     try
     {
         await MyARSceneView.StartTrackingAsync(ARLocationTrackingMode.Continuous);
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine(ex.Message);
     }
 }
Example #5
0
        private async void RealScaleValueChanged(object sender, EventArgs e)
        {
            // Prevent this from being called concurrently
            if (_changingScale)
            {
                return;
            }
            _changingScale = true;

            // Disable the associated UI controls while switching.
            RoamingButton.IsEnabled = false;
            LocalButton.IsEnabled   = false;

            // Check if using roaming for AR location mode.
            if (((Button)sender).Text == "GPS")
            {
                await MyARSceneView.StopTrackingAsync();

                // Start AR tracking using a continuous GPS signal.
                await MyARSceneView.StartTrackingAsync(ARLocationTrackingMode.Continuous);

                ElevationSlider.IsEnabled = true;
                LocalButton.IsEnabled     = true;
            }
            else
            {
                await MyARSceneView.StopTrackingAsync();

                // Start AR tracking without using a GPS signal.
                await MyARSceneView.StartTrackingAsync(ARLocationTrackingMode.Ignore);

                ElevationSlider.IsEnabled = false;
                RoamingButton.IsEnabled   = true;
            }
            _changingScale = false;
        }
Example #6
0
 void IARSample.StopAugmentedReality()
 {
     MyARSceneView.StopTrackingAsync();
 }
Example #7
0
 protected override void OnDisappearing()
 {
     MyARSceneView.StopTrackingAsync();
 }
Example #8
0
        private async void Initialize()
        {
            try
            {
                // Create the custom location data source and configure the AR scene view to use it.
#if XAMARIN_ANDROID
                bool locationGranted = await MainActivity.Instance.AskForLocationPermission();

                if (!locationGranted)
                {
                    return;
                }
                _locationDataSource = new ARLocationDataSource(Android.App.Application.Context);
                _locationDataSource.AltitudeMode = ARLocationDataSource.AltitudeAdjustmentMode.NmeaParsedMsl;

                MyARSceneView.LocationDataSource = _locationDataSource;
                await MyARSceneView.StartTrackingAsync(ARLocationTrackingMode.Continuous);
#elif __IOS__
                _locationDataSource = new ARLocationDataSource();
                MyARSceneView.LocationDataSource = _locationDataSource;
#endif
                // Create the scene and show it.
                _scene = new Scene(BasemapStyle.ArcGISImageryStandard);
                MyARSceneView.Scene = _scene;

                // Create and add the elevation surface.
                _elevationSource  = new ArcGISTiledElevationSource(new Uri("https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer"));
                _elevationSurface = new Surface();
                _elevationSurface.ElevationSources.Add(_elevationSource);
                MyARSceneView.Scene.BaseSurface = _elevationSurface;

                // Hide the surface in AR.
                _elevationSurface.NavigationConstraint = NavigationConstraint.None;
                _elevationSurface.Opacity = 0;

                // Configure the space and atmosphere effects for AR.
                MyARSceneView.SpaceEffect      = SpaceEffect.None;
                MyARSceneView.AtmosphereEffect = AtmosphereEffect.None;

                // Add a graphics overlay for displaying points in AR.
                _graphicsOverlay = new GraphicsOverlay();
                _graphicsOverlay.SceneProperties.SurfacePlacement = SurfacePlacement.Absolute;
                _graphicsOverlay.Renderer = new SimpleRenderer(_tappedPointSymbol);
                MyARSceneView.GraphicsOverlays.Add(_graphicsOverlay);

                // Add the exisiting features to the scene.
                FeatureLayer treeLayer = new FeatureLayer(_featureTable);
                treeLayer.SceneProperties.SurfacePlacement = SurfacePlacement.Absolute;
                MyARSceneView.Scene.OperationalLayers.Add(treeLayer);

                // Add the event for the user tapping the screen.
                MyARSceneView.GeoViewTapped += ARViewTapped;

                // Disable scene interaction.
                MyARSceneView.InteractionOptions = new SceneViewInteractionOptions()
                {
                    IsEnabled = false
                };

                // Enable the calibrate button.
                CalibrateButton.IsEnabled = true;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                await Application.Current.MainPage.DisplayAlert("Error", "Could not create feature", "OK");
            }
        }
Example #9
0
 protected override void OnDisappearing()
 {
     base.OnDisappearing();
     MyARSceneView.StopTrackingAsync();
     Dispose();
 }