private async void OnScreenshotButtonClicked(object sender, EventArgs e)
        {
            // Export the image from the MapView.
            RuntimeImage exportedImage = await _myMapView.ExportImageAsync();

            // Convert the exported image to a suitable display format, then display it.
            _overlayImageView.Image = await exportedImage.ToImageSourceAsync();

            // Enable the button to close image view.
            _closeImageViewButton.Enabled = true;

            // Show the overlay view.
            _overlayView.Hidden = false;
        }
Ejemplo n.º 2
0
        // A function that reads a mobile style file and builds a list for each of three symbol categories.
        private async Task ReadMobileStyle()
        {
            // Open a mobile style file.
            _emojiStyle = await SymbolStyle.OpenAsync(_mobileStyleFilePath);

            // Get the default style search parameters.
            SymbolStyleSearchParameters searchParams = await _emojiStyle.GetDefaultSearchParametersAsync();

            // Search the style with the default parameters to return all symbol results.
            IList <SymbolStyleSearchResult> styleResults = await _emojiStyle.SearchSymbolsAsync(searchParams);

            // Loop through the results and put symbols into the appropriate list according to category.
            foreach (SymbolStyleSearchResult result in styleResults)
            {
                // Get the symbol from the result.
                MultilayerPointSymbol multiLayerSym = result.Symbol as MultilayerPointSymbol;

                // Create an image from the symbol swatch.
                RuntimeImage swatch = await multiLayerSym.CreateSwatchAsync();

                UIImage symbolImage = await swatch.ToImageSourceAsync();

                // Create an instance of the custom SymbolLayerInfo class to store info about this symbol: name, swatch image, unique ID (key).
                SymbolLayerInfo symbolInfo = new SymbolLayerInfo(result.Name, symbolImage, result.Key);

                // Check the category for this result and place it into the correct list.
                switch (result.Category)
                {
                case "Eyes":
                {
                    //
                    _eyeSymbolInfos.Add(symbolInfo);
                    break;
                }

                case "Mouth":
                {
                    _mouthSymbolInfos.Add(symbolInfo);
                    break;
                }

                case "Hat":
                {
                    _hatSymbolInfos.Add(symbolInfo);
                    break;
                }
                }
            }
        }
Ejemplo n.º 3
0
        private async Task UpdateSymbolPreview(Symbol symbolToShow)
        {
            if (symbolToShow == null)
            {
                return;
            }

            // Create a swatch from the symbol with a white background.
            RuntimeImage swatch = await symbolToShow.CreateSwatchAsync(80, 80, 96, Color.White);

            // Convert the swatch to an image source and show it in the Image control.
            ImageSource symbolImage = await swatch.ToImageSourceAsync();

            SymbolPreviewImage.Source = symbolImage;
        }
Ejemplo n.º 4
0
        // A function to update the current multilayer symbol based on selections in the dialog.
        private async Task UpdateSymbol()
        {
            // Call a function to read the current settings and create the appropriate symbol.
            // Assign the symbol to the public SelectedSymbol property.
            SelectedSymbol = await GetCurrentSymbol();

            if (SelectedSymbol != null)
            {
                // Create an image of the symbol swatch to display as a preview.
                RuntimeImage swatch = await SelectedSymbol.CreateSwatchAsync(80, 80, 96, System.Drawing.Color.White);

                UIImage symbolImage = await swatch.ToImageSourceAsync();

                _symbolPreviewImageView.Image = symbolImage;
            }
        }
        private async void OnTakeScreenshotClicked(object sender, EventArgs e)
        {
            try
            {
                // Wait for rendering to finish before taking the screenshot.
                await WaitForRenderCompleteAsync(_myMapView);

                // Export the image from map view.
                RuntimeImage exportedImage = await _myMapView.ExportImageAsync();

                // Create an image button (this will display the exported map view image).
                ImageButton myImageButton = new ImageButton(this)
                {
                    // Define the size of the image button to be 2/3 the size of the map view.
                    LayoutParameters = new Android.Views.ViewGroup.LayoutParams((int)(_myMapView.Width * .667), (int)(_myMapView.Height * .667))
                };

                // Set the source of the image button to be that of the exported map view image.
                myImageButton.SetImageBitmap(await exportedImage.ToImageSourceAsync());

                // Make the image that was captured from the map view export to fit within (aka scale-to-fit) the image button.
                myImageButton.SetScaleType(ImageView.ScaleType.FitCenter);

                // Define a popup with a single image button control and make the size of the popup to be 2/3 the size of the map view.
                PopupWindow myPopupWindow = new PopupWindow(myImageButton, (int)(_myMapView.Width * .667), (int)(_myMapView.Height * .667));

                // Display the popup in the middle of the map view.
                myPopupWindow.ShowAtLocation(_myMapView, Android.Views.GravityFlags.Center, 0, 0);

                // Define a lambda event handler to close the popup when the user clicks on the image button.
                myImageButton.Click += (s, a) => myPopupWindow.Dismiss();
            }
            catch (Exception ex)
            {
                // Display any errors to the user if capturing the map view image did not work.
                AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this);
                alertBuilder.SetTitle("ExportImageAsync error");
                alertBuilder.SetMessage("Capturing image failed. " + ex.Message);
                alertBuilder.Show();
            }
        }
        private async void OnScreenshotButtonClicked(object sender, EventArgs e)
        {
            try
            {
                // Export the image from the MapView.
                RuntimeImage exportedImage = await _myMapView.ExportImageAsync();

                // Convert the exported image to a suitable display format, then display it.
                _overlayImageView.Image = await exportedImage.ToImageSourceAsync();

                // Enable the button to close image view.
                _closeImageViewButton.Enabled = true;

                // Show the overlay view.
                _overlayView.Hidden = false;
            }
            catch (Exception ex)
            {
                new UIAlertView("Error", ex.ToString(), (IUIAlertViewDelegate)null, "OK", null).Show();
            }
        }
Ejemplo n.º 7
0
        private async void OnScreenshotButtonClicked(object sender, RoutedEventArgs e)
        {
            try
            {
                // Wait for rendering to finish before taking the screenshot.
                await WaitForRenderCompleteAsync(MyMapView);

                // Export the image from MapView.
                RuntimeImage image = await MyMapView.ExportImageAsync();

                // Display the image in the UI.
                ImageView.Source = await image.ToImageSourceAsync();

                // Make the image visible.
                ImageView.Visibility = Visibility.Visible;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error");
            }
        }
        private async void OnTakeScreenshotButtonClicked(object sender, RoutedEventArgs e)
        {
            try
            {
                // Wait for rendering to finish before taking the screenshot.
                await WaitForRenderCompleteAsync(MyMapView);

                // Export the image from the map view.
                RuntimeImage image = await MyMapView.ExportImageAsync();

                // Convert the image to a displayable format.
                ImageSource exportedImage = await image.ToImageSourceAsync();

                // Set the screenshot view to the new exported image.
                ScreenshotView.Source = exportedImage;

                // Make the screenshot view visible in the UI.
                ScreenshotView.Visibility = Visibility.Visible;
            }
            catch (Exception ex)
            {
                await new MessageDialog2(ex.ToString(), "Error").ShowAsync();
            }
        }
        // Get the current symbol and update the preview image.
        private async Task UpdateSymbol()
        {
            // Call a function to get the currrent multilayer point symbol from the selected layers.
            MultilayerPointSymbol emojiSymbol = await GetCurrentSymbol();

            try
            {
                // Use a swatch from the symbol to create an image.
                RuntimeImage swatch = await emojiSymbol.CreateSwatchAsync(100, 100, 96, System.Drawing.Color.White);

                Bitmap symbolImage = await swatch.ToImageSourceAsync();

                // Display the preview image.
                _symbolPreviewImage.SetImageBitmap(symbolImage);
            }
            catch (Exception ex)
            {
                // Show the exception message.
                AlertDialog.Builder alertBuilder = new AlertDialog.Builder(Activity);
                alertBuilder.SetTitle("Error creating preview");
                alertBuilder.SetMessage(ex.Message);
                alertBuilder.Show();
            }
        }
        private async void Initialize()
        {
            try
            {
                // Create the utility network.
                _utilityNetwork = await UtilityNetwork.CreateAsync(new Uri(FeatureServerUrl));

                // Create the map.
                _myMapView.Map = new Map(Basemap.CreateTopographicVector());

                // Get all of the edges and junctions in the network.
                IEnumerable <UtilityNetworkSource> edges     = _utilityNetwork.Definition.NetworkSources.Where(n => n.SourceType == UtilityNetworkSourceType.Edge);
                IEnumerable <UtilityNetworkSource> junctions = _utilityNetwork.Definition.NetworkSources.Where(n => n.SourceType == UtilityNetworkSourceType.Junction);

                // Add all edges that are not subnet lines to the map.
                foreach (UtilityNetworkSource source in edges)
                {
                    if (source.SourceUsageType != UtilityNetworkSourceUsageType.SubnetLine && source.FeatureTable != null)
                    {
                        _myMapView.Map.OperationalLayers.Add(new FeatureLayer(source.FeatureTable));
                    }
                }

                // Add all junctions to the map.
                foreach (UtilityNetworkSource source in junctions)
                {
                    if (source.FeatureTable != null)
                    {
                        _myMapView.Map.OperationalLayers.Add(new FeatureLayer(source.FeatureTable));
                    }
                }

                // Create a graphics overlay for associations.
                _associationsOverlay = new GraphicsOverlay();
                _myMapView.GraphicsOverlays.Add(_associationsOverlay);

                // Symbols for the associations.
                Symbol attachmentSymbol   = new SimpleLineSymbol(SimpleLineSymbolStyle.Dot, Color.Green, 5d);
                Symbol connectivitySymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Dot, Color.Red, 5d);

                // Create a renderer for the associations.
                var attachmentValue   = new UniqueValue("Attachment", string.Empty, attachmentSymbol, UtilityAssociationType.Attachment.ToString());
                var connectivityValue = new UniqueValue("Connectivity", string.Empty, connectivitySymbol, UtilityAssociationType.Connectivity.ToString());
                _associationsOverlay.Renderer = new UniqueValueRenderer(new List <string> {
                    "AssociationType"
                }, new List <UniqueValue> {
                    attachmentValue, connectivityValue
                }, string.Empty, null);

                // Populate the legend in the UI.
                RuntimeImage attachmentSwatch = await attachmentSymbol.CreateSwatchAsync();

                Android.Graphics.Bitmap attachmentBitmap = await attachmentSwatch?.ToImageSourceAsync();

                _attachmentImageView.SetImageBitmap(attachmentBitmap);

                RuntimeImage connectSwatch = await connectivitySymbol.CreateSwatchAsync();

                Android.Graphics.Bitmap connectivityBitmap = await connectSwatch?.ToImageSourceAsync();

                _connectivityImageView.SetImageBitmap(connectivityBitmap);

                // Set the starting viewpoint.
                await _myMapView.SetViewpointAsync(InitialViewpoint);

                // Add the associations in the starting viewpoint.
                AddAssociations();
            }
            catch (Exception ex)
            {
                new AlertDialog.Builder(this).SetMessage(ex.Message).SetTitle(ex.GetType().Name).Show();
            }
        }
Ejemplo n.º 11
0
        private async Task ReadMobileStyle(string stylePath)
        {
            try
            {
                // Open the mobile style file at the provided path.
                _emojiStyle = await SymbolStyle.OpenAsync(stylePath);

                // Get the default style search parameters.
                SymbolStyleSearchParameters searchParams = await _emojiStyle.GetDefaultSearchParametersAsync();

                // Search the style with the default parameters to return all symbol results.
                IList <SymbolStyleSearchResult> styleResults = await _emojiStyle.SearchSymbolsAsync(searchParams);

                // Create an empty placeholder image to represent "no symbol" for each category.
                ImageSource emptyImage = null;

                // Create lists to contain the available symbol layers for each category of symbol and add an empty entry as default.
                List <SymbolLayerInfo> eyeSymbolInfos = new List <SymbolLayerInfo> {
                    new SymbolLayerInfo("", emptyImage, "")
                };
                List <SymbolLayerInfo> mouthSymbolInfos = new List <SymbolLayerInfo> {
                    new SymbolLayerInfo("", emptyImage, "")
                };
                List <SymbolLayerInfo> hatSymbolInfos = new List <SymbolLayerInfo>()
                {
                    new SymbolLayerInfo("", emptyImage, "")
                };

                // Loop through the results and put symbols into the appropriate list according to category.
                foreach (SymbolStyleSearchResult result in styleResults)
                {
                    // Get the symbol for this result.
                    MultilayerPointSymbol multiLayerSym = await result.GetSymbolAsync() as MultilayerPointSymbol;

                    // Create a swatch image from the symbol.
                    RuntimeImage swatch = await multiLayerSym.CreateSwatchAsync();

                    ImageSource symbolImage = await swatch.ToImageSourceAsync();

                    // Create a symbol layer info object to represent the symbol in the list.
                    // The symbol key will be used to retrieve the symbol from the style.
                    SymbolLayerInfo symbolInfo = new SymbolLayerInfo(result.Name, symbolImage, result.Key);

                    // Add the symbol layer info to the correct list for its category.
                    switch (result.Category)
                    {
                    case "Eyes":
                    {
                        eyeSymbolInfos.Add(symbolInfo);
                        break;
                    }

                    case "Mouth":
                    {
                        mouthSymbolInfos.Add(symbolInfo);
                        break;
                    }

                    case "Hat":
                    {
                        hatSymbolInfos.Add(symbolInfo);
                        break;
                    }
                    }
                }

                // Show the symbols in the category list boxes.
                EyeSymbolList.ItemsSource   = eyeSymbolInfos;
                MouthSymbolList.ItemsSource = mouthSymbolInfos;
                HatSymbolList.ItemsSource   = hatSymbolInfos;

                // Call a function to construct the current symbol (default yellow circle).
                Symbol faceSymbol = await GetCurrentSymbol();

                // Call a function to show a preview image of the symbol.
                await UpdateSymbolPreview(faceSymbol);
            }
            catch (Exception ex)
            {
                // Report the exception.
                MessageDialog dialog = new MessageDialog("Error reading symbols from style: " + ex.Message);
                await dialog.ShowAsync();
            }
        }
        private async void Initialize()
        {
            // As of ArcGIS Enterprise 10.8.1, using utility network functionality requires a licensed user. The following login for the sample server is licensed to perform utility network operations.
            AuthenticationManager.Current.ChallengeHandler = new ChallengeHandler(async(info) =>
            {
                try
                {
                    // WARNING: Never hardcode login information in a production application. This is done solely for the sake of the sample.
                    string sampleServer7User = "******";
                    string sampleServer7Pass = "******";

                    return(await AuthenticationManager.Current.GenerateCredentialAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass));
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                    return(null);
                }
            });

            try
            {
                // Create the utility network.
                _utilityNetwork = await UtilityNetwork.CreateAsync(new Uri(FeatureServerUrl));

                // Create the map.
                MyMapView.Map = new Map(BasemapStyle.ArcGISTopographic);

                // Get all of the edges and junctions in the network.
                IEnumerable <UtilityNetworkSource> edges     = _utilityNetwork.Definition.NetworkSources.Where(n => n.SourceType == UtilityNetworkSourceType.Edge);
                IEnumerable <UtilityNetworkSource> junctions = _utilityNetwork.Definition.NetworkSources.Where(n => n.SourceType == UtilityNetworkSourceType.Junction);

                // Add all edges that are not subnet lines to the map.
                foreach (UtilityNetworkSource source in edges)
                {
                    if (source.SourceUsageType != UtilityNetworkSourceUsageType.SubnetLine && source.FeatureTable != null)
                    {
                        MyMapView.Map.OperationalLayers.Add(new FeatureLayer(source.FeatureTable));
                    }
                }

                // Add all junctions to the map.
                foreach (UtilityNetworkSource source in junctions)
                {
                    if (source.FeatureTable != null)
                    {
                        MyMapView.Map.OperationalLayers.Add(new FeatureLayer(source.FeatureTable));
                    }
                }

                // Create a graphics overlay for associations.
                _associationsOverlay = new GraphicsOverlay();
                MyMapView.GraphicsOverlays.Add(_associationsOverlay);

                // Symbols for the associations.
                Symbol attachmentSymbol   = new SimpleLineSymbol(SimpleLineSymbolStyle.Dot, Color.Green, 5d);
                Symbol connectivitySymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Dot, Color.Red, 5d);

                // Create a renderer for the associations.
                var attachmentValue   = new UniqueValue("Attachment", string.Empty, attachmentSymbol, UtilityAssociationType.Attachment.ToString());
                var connectivityValue = new UniqueValue("Connectivity", string.Empty, connectivitySymbol, UtilityAssociationType.Connectivity.ToString());
                _associationsOverlay.Renderer = new UniqueValueRenderer(new List <string> {
                    "AssociationType"
                }, new List <UniqueValue> {
                    attachmentValue, connectivityValue
                }, string.Empty, null);

                // Populate the legend in the UI.
                Dictionary <UtilityAssociationType, System.Windows.Media.ImageSource> legend;
                legend = new Dictionary <UtilityAssociationType, System.Windows.Media.ImageSource>();

                RuntimeImage attachmentSwatch = await attachmentSymbol.CreateSwatchAsync();

                legend[UtilityAssociationType.Attachment] = await attachmentSwatch?.ToImageSourceAsync();

                RuntimeImage connectSwatch = await connectivitySymbol.CreateSwatchAsync();

                legend[UtilityAssociationType.Connectivity] = await connectSwatch?.ToImageSourceAsync();

                AssociationLegend.ItemsSource = legend;

                // Set the starting viewpoint.
                await MyMapView.SetViewpointAsync(InitialViewpoint);

                // Add the associations in the starting viewpoint.
                AddAssociations();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.GetType().Name, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private async void ReadMobileStyle(string mobileStyleFilePath)
        {
            try
            {
                // Make sure the file exists.
                if (!System.IO.File.Exists(mobileStyleFilePath))
                {
                    throw new System.IO.FileNotFoundException("Mobile style file not found at " + mobileStyleFilePath);
                }

                // Open the mobile style file at the path provided.
                _emojiStyle = await SymbolStyle.OpenAsync(mobileStyleFilePath);

                // Get the default style search parameters.
                SymbolStyleSearchParameters searchParams = await _emojiStyle.GetDefaultSearchParametersAsync();

                // Search the style with the default parameters to return a list of all symbol results.
                IList <SymbolStyleSearchResult> styleResults = await _emojiStyle.SearchSymbolsAsync(searchParams);

                // Loop through the results and put symbols into the appropriate list according to category (eyes, mouth, hat).
                foreach (SymbolStyleSearchResult result in styleResults)
                {
                    // Get the result symbol as a multilayer point symbol.
                    MultilayerPointSymbol multiLayerSym = result.Symbol as MultilayerPointSymbol;

                    // Create a swatch for the symbol and use it to create a bitmap image.
                    RuntimeImage swatch = await multiLayerSym.CreateSwatchAsync();

                    Bitmap symbolImage = await swatch.ToImageSourceAsync();

                    // Check the symbol category.
                    switch (result.Category)
                    {
                    // Add a new SymbolLayerInfo to represent the symbol and add it to its category list.
                    // SymbolLayerInfo is a custom class with properties for the symbol name, swatch image, and unique key.
                    case "Eyes":
                    {
                        _eyeSymbolInfos.Add(new SymbolLayerInfo(result.Name, symbolImage, result.Key));
                        break;
                    }

                    case "Mouth":
                    {
                        _mouthSymbolInfos.Add(new SymbolLayerInfo(result.Name, symbolImage, result.Key));
                        break;
                    }

                    case "Hat":
                    {
                        _hatSymbolInfos.Add(new SymbolLayerInfo(result.Name, symbolImage, result.Key));
                        break;
                    }

                    case "Face":
                    {
                        break;
                    }
                    }
                }
            }
            catch (Exception ex)
            {
                // Show the exception message.
                AlertDialog.Builder alertBuilder = new AlertDialog.Builder(Activity);
                alertBuilder.SetTitle("Error reading style");
                alertBuilder.SetMessage(ex.Message);
                alertBuilder.Show();
            }
        }
        private async void Initialize()
        {
            try
            {
                // Create the utility network.
                _utilityNetwork = await UtilityNetwork.CreateAsync(new Uri(FeatureServerUrl));

                // Create the map.
                MyMapView.Map = new Map(Basemap.CreateTopographicVector());

                // Get all of the edges and junctions in the network.
                IEnumerable <UtilityNetworkSource> edges     = _utilityNetwork.Definition.NetworkSources.Where(n => n.SourceType == UtilityNetworkSourceType.Edge);
                IEnumerable <UtilityNetworkSource> junctions = _utilityNetwork.Definition.NetworkSources.Where(n => n.SourceType == UtilityNetworkSourceType.Junction);

                // Add all edges that are not subnet lines to the map.
                foreach (UtilityNetworkSource source in edges)
                {
                    if (source.SourceUsageType != UtilityNetworkSourceUsageType.SubnetLine && source.FeatureTable != null)
                    {
                        MyMapView.Map.OperationalLayers.Add(new FeatureLayer(source.FeatureTable));
                    }
                }

                // Add all junctions to the map.
                foreach (UtilityNetworkSource source in junctions)
                {
                    if (source.FeatureTable != null)
                    {
                        MyMapView.Map.OperationalLayers.Add(new FeatureLayer(source.FeatureTable));
                    }
                }

                // Create a graphics overlay for associations.
                _associationsOverlay = new GraphicsOverlay();
                MyMapView.GraphicsOverlays.Add(_associationsOverlay);

                // Symbols for the associations.
                Symbol attachmentSymbol   = new SimpleLineSymbol(SimpleLineSymbolStyle.Dot, Color.Green, 5d);
                Symbol connectivitySymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Dot, Color.Red, 5d);

                // Create a renderer for the associations.
                var attachmentValue   = new UniqueValue("Attachment", string.Empty, attachmentSymbol, UtilityAssociationType.Attachment.ToString());
                var connectivityValue = new UniqueValue("Connectivity", string.Empty, connectivitySymbol, UtilityAssociationType.Connectivity.ToString());
                _associationsOverlay.Renderer = new UniqueValueRenderer(new List <string> {
                    "AssociationType"
                }, new List <UniqueValue> {
                    attachmentValue, connectivityValue
                }, string.Empty, null);

                // Populate the legend in the UI.
                Dictionary <UtilityAssociationType, System.Windows.Media.ImageSource> legend;
                legend = new Dictionary <UtilityAssociationType, System.Windows.Media.ImageSource>();

                RuntimeImage attachmentSwatch = await attachmentSymbol.CreateSwatchAsync();

                legend[UtilityAssociationType.Attachment] = await attachmentSwatch?.ToImageSourceAsync();

                RuntimeImage connectSwatch = await connectivitySymbol.CreateSwatchAsync();

                legend[UtilityAssociationType.Connectivity] = await connectSwatch?.ToImageSourceAsync();

                AssociationLegend.ItemsSource = legend;

                // Set the starting viewpoint.
                await MyMapView.SetViewpointAsync(InitialViewpoint);

                // Add the associations in the starting viewpoint.
                AddAssociations();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.GetType().Name, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }