Exemple #1
0
        // Cancel the current shape drawing (if in Editor.RequestShapeAsync)
        // and draw new geometry
        private async void AddSearchGeometry_Click(object sender, RoutedEventArgs e)
        {
            if (MyMapView.Editor.IsActive)
            {
                MyMapView.Editor.Cancel.Execute(null);
            }

            _drawGraphicsOverlay.Graphics.Clear();
            findBtn.IsEnabled = false;

            // Hide floyout from the UI
            drawFlyout.Hide();
            BottomAppBar.IsOpen = false;

            try
            {
                var            selectedDrawShape = DrawShape.Polygon;
                var            symbolType        = (sender as Button).Tag.ToString();
                symbols.Symbol symbol            = null;
                switch (symbolType)
                {
                case "line":
                    selectedDrawShape = DrawShape.Polyline;
                    symbol            = Resources["GreenLineSymbol"] as symbols.Symbol;
                    break;

                case "polygon":
                    selectedDrawShape = DrawShape.Polygon;
                    symbol            = Resources["RedFillSymbol"] as symbols.Symbol;
                    break;

                case "circle":
                    selectedDrawShape = DrawShape.Circle;
                    symbol            = Resources["RedFillSymbol"] as symbols.Symbol;
                    break;

                case "rectangle":
                    selectedDrawShape = DrawShape.Rectangle;
                    symbol            = Resources["RedFillSymbol"] as symbols.Symbol;
                    break;
                }

                // wait for user to draw the shape
                _searchGeometry = await MyMapView.Editor.RequestShapeAsync(selectedDrawShape, symbol);

                // add the new graphic to the graphic layer
                var graphic = new Graphic(_searchGeometry, symbol);
                _drawGraphicsOverlay.Graphics.Add(graphic);
                findBtn.IsEnabled = true;
            }
            catch (TaskCanceledException)
            {
                // Ignore cancelations from selecting new shape type
                findBtn.IsEnabled = false;
            }
            catch (Exception ex)
            {
                var _x = new MessageDialog("Error drawing graphic: " + ex.Message, "S57 Search Sample").ShowAsync();
            }
        }
Exemple #2
0
        /// <summary>Construct Mensuration sample control</summary>
        public Mensuration()
        {
            InitializeComponent();

            _pointSymbol   = LayoutRoot.Resources["PointSymbol"] as Symbols.Symbol;
            _lineSymbol    = LayoutRoot.Resources["LineSymbol"] as Symbols.Symbol;
            _polygonSymbol = LayoutRoot.Resources["PolygonSymbol"] as Symbols.Symbol;

            _graphicsOverlay = MyMapView.GraphicsOverlays["graphicsOverlay"];

            comboLinearUnit.ItemsSource = typeof(LinearUnits).GetTypeInfo().DeclaredProperties
                                          .Select(p => p.GetValue(null, null))
                                          .Except(new LinearUnit[] { LinearUnits.NauticalMiles }).ToList();
            comboLinearUnit.SelectedItem = LinearUnits.Meters;

            comboAngularUnit.ItemsSource  = new AngularUnit[] { AngularUnits.Degrees, AngularUnits.Radians };
            comboAngularUnit.SelectedItem = AngularUnits.Degrees;

            comboAreaUnit.ItemsSource = typeof(AreaUnits).GetTypeInfo().DeclaredProperties
                                        .Select(p => p.GetValue(null, null)).ToList();
            comboAreaUnit.SelectedItem = AreaUnits.SquareMeters;

            var imageLayer = MyMapView.Map.Layers["ImageLayer"] as ArcGISTiledMapServiceLayer;

            _mensurationTask = new MensurationTask(new Uri(imageLayer.ServiceUri));
        }
        /// <summary>Construct Mensuration sample control</summary>
        public Mensuration()
        {
            InitializeComponent();

			_pointSymbol = LayoutRoot.Resources["PointSymbol"] as Symbols.Symbol;
			_lineSymbol = LayoutRoot.Resources["LineSymbol"] as Symbols.Symbol;
			_polygonSymbol = LayoutRoot.Resources["PolygonSymbol"] as Symbols.Symbol;

			_graphicsOverlay = MyMapView.GraphicsOverlays["graphicsOverlay"];

            comboLinearUnit.ItemsSource = typeof(LinearUnits).GetTypeInfo().DeclaredProperties
				.Select(p => p.GetValue(null, null))
                .Except(new LinearUnit[] { LinearUnits.NauticalMiles } ).ToList();
            comboLinearUnit.SelectedItem = LinearUnits.Meters;

            comboAngularUnit.ItemsSource = new AngularUnit[] { AngularUnits.Degrees, AngularUnits.Radians };
            comboAngularUnit.SelectedItem = AngularUnits.Degrees;

            comboAreaUnit.ItemsSource = typeof(AreaUnits).GetTypeInfo().DeclaredProperties
				.Select(p => p.GetValue(null, null)).ToList();
            comboAreaUnit.SelectedItem = AreaUnits.SquareMeters;

			var imageLayer = MyMapView.Map.Layers["ImageLayer"] as ArcGISTiledMapServiceLayer;
            _mensurationTask = new MensurationTask(new Uri(imageLayer.ServiceUri));
        }
Exemple #4
0
        // An event handler for list box and combo box selection changes that will update the current symbol.
        private async void SymbolPropertyChanged(object sender, SelectionChangedEventArgs e)
        {
            // Call a function that will construct the current symbol.
            Symbol faceSymbol = await GetCurrentSymbol();

            // Call a function to update the symbol preview.
            await UpdateSymbolPreview(faceSymbol);
        }
		public DensifyPolygons()
		{
			InitializeComponent();

			polygonSymbol = LayoutRoot.Resources["MySimpleFillSymbol"] as SimpleFillSymbol;
			graphicsLayerVertices = MyMapView.Map.Layers["MyVerticesGraphicsLayer"] as GraphicsLayer;
			graphicsLayerPolygon = MyMapView.Map.Layers["MyPolygonGraphicsLayer"] as GraphicsLayer;
			defaultVertexMarkerSymbol = LayoutRoot.Resources["MyDefaultVertexMarkerSymbol"] as Esri.ArcGISRuntime.Symbology.Symbol;
			densifyVertexMarkerSymbol = LayoutRoot.Resources["MyDensifyVertexMarkerSymbol"] as Esri.ArcGISRuntime.Symbology.Symbol;
		}
        public DensifyPolygons()
        {
            InitializeComponent();

            polygonSymbol             = LayoutRoot.Resources["MySimpleFillSymbol"] as SimpleFillSymbol;
            graphicsLayerVertices     = mapView1.Map.Layers["MyVerticesGraphicsLayer"] as GraphicsLayer;
            graphicsLayerPolygon      = mapView1.Map.Layers["MyPolygonGraphicsLayer"] as GraphicsLayer;
            defaultVertexMarkerSymbol = LayoutRoot.Resources["MyDefaultVertexMarkerSymbol"] as Esri.ArcGISRuntime.Symbology.Symbol;
            densifyVertexMarkerSymbol = LayoutRoot.Resources["MyDensifyVertexMarkerSymbol"] as Esri.ArcGISRuntime.Symbology.Symbol;
        }
        public DensifyPolygons()
        {
            InitializeComponent();
            mapView1.Map.InitialViewpoint = new Viewpoint(new Envelope(-344448.8744537411, -1182136.4258723476, 3641336.505047027, 1471520.6499406511, SpatialReference.Create(21897)));

            polygonSymbol             = LayoutRoot.Resources["MySimpleFillSymbol"] as SimpleFillSymbol;
            graphicsLayerVertices     = mapView1.Map.Layers["MyVerticesGraphicsLayer"] as GraphicsLayer;
            graphicsLayerPolygon      = mapView1.Map.Layers["MyPolygonGraphicsLayer"] as GraphicsLayer;
            defaultVertexMarkerSymbol = LayoutRoot.Resources["MyDefaultVertexMarkerSymbol"] as Esri.ArcGISRuntime.Symbology.Symbol;
            densifyVertexMarkerSymbol = LayoutRoot.Resources["MyDensifyVertexMarkerSymbol"] as Esri.ArcGISRuntime.Symbology.Symbol;
        }
 private async Task UpdateImageSourceAsync()
 {
     try
     {
         _image.Source = await Symbol.CreateSwatchAsync(WidthPixels, HeightPixels, _swatchDpi, BackgroundColor, GeometryType);
     }
     catch
     {
         _image.Source = null;
     }
     InvalidateMeasure();
 }
Exemple #9
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;
        }
Exemple #10
0
        // Draw and add a single graphic to the graphic layer
        private async Task AddSingleGraphicAsync()
        {
            try
            {
                var drawShape = (DrawShape)comboDrawShape.SelectedValue;

                sym.Symbol symbol = null;
                switch (drawShape)
                {
                case DrawShape.Point:
                    symbol = Resources["BluePointSymbol"] as sym.Symbol;
                    break;

                case DrawShape.LineSegment:
                case DrawShape.Freehand:
                case DrawShape.Polyline:
                    symbol = Resources["GreenLineSymbol"] as sym.Symbol;
                    break;

                case DrawShape.Arrow:
                case DrawShape.Circle:
                case DrawShape.Ellipse:
                case DrawShape.Polygon:
                case DrawShape.Rectangle:
                case DrawShape.Triangle:
                case DrawShape.Envelope:
                    symbol = Resources["RedFillSymbol"] as sym.Symbol;
                    break;
                }

                // wait for user to draw the shape
                var geometry = await MyMapView.Editor.RequestShapeAsync(drawShape, symbol);

                // add the new graphic to the graphic layer
                var graphic = new Graphic(geometry, symbol);
                _graphicsLayer.Graphics.Add(graphic);
            }
            catch (TaskCanceledException)
            {
                // Ignore cancellations from selecting new shape type
            }
            catch (Exception ex)
            {
                var _x = new MessageDialog("Error drawing graphic: " + ex.Message, "Add Graphic Interactively").ShowAsync();
            }
        }
Exemple #11
0
        // Retrieve the given shape type from the user
        private async Task <Geometry> RequestUserShape(DrawShape drawShape, Symbols.Symbol symbol)
        {
            try
            {
                _graphicsOverlay.Graphics.Clear();

                var shape = await MyMapView.Editor.RequestShapeAsync(drawShape, symbol);

                _graphicsOverlay.Graphics.Add(new Graphic(shape, symbol));
                return(shape);
            }
            catch (TaskCanceledException)
            {
                return(null);
            }
            catch (Exception ex)
            {
                var _ = new MessageDialog(ex.Message, "Sample Error").ShowAsync();
                return(null);
            }
        }
Exemple #12
0
        public MapPage()
        {
            this.InitializeComponent();

            MyMapView.LocationDisplay.LocationProvider = new SystemLocationProvider();
            MyMapView.LocationDisplay.LocationProvider.StartAsync();

            HardwareButtons.BackPressed += HardwareButtons_BackPressed;

            MyMapView.Loaded          += MyMapView_Loaded;
            _locatorTask               = new OnlineLocatorTask(new Uri(OnlineLocatorUrl));
            _locatorTask.AutoNormalize = true;

            _directionPointSymbol = LayoutRoot.Resources["directionPointSymbol"] as Esri.ArcGISRuntime.Symbology.Symbol;
            _stopsOverlay         = MyMapView.GraphicsOverlays["StopsOverlay"];
            _routesOverlay        = MyMapView.GraphicsOverlays["RoutesOverlay"];
            _directionsOverlay    = MyMapView.GraphicsOverlays["DirectionsOverlay"];
            _myLocationOverlay    = MyMapView.GraphicsOverlays["LocationOverlay"];
            _routeTask            = new OnlineRouteTask(new Uri(OnlineRoutingService));

            _campos = new Dictionary <String, String>();
            if (PortalSearch.GetSelectedItem().Map.Layers.Count() > 0)
            {
                foreach (Layer i in PortalSearch.GetSelectedItem().Map.Layers)
                {
                    try
                    {
                        if (!((FeatureLayer)i).FeatureTable.IsReadOnly && ((FeatureLayer)i).FeatureTable.GeometryType == GeometryType.Point)
                        {
                            _layer = i as FeatureLayer;
                            _table = (ArcGISFeatureTable)_layer.FeatureTable;
                            MenuFlyoutAddButton.IsEnabled = true;
                        }
                    }
                    catch
                    {
                    }
                }
            }
        }
Exemple #13
0
        private async void ExecuteDrawing(Func <SceneView, Task <Esri.ArcGISRuntime.Geometry.Geometry> > createGeometryAsync, Esri.ArcGISRuntime.Symbology.Symbol symbol)
        {
            Esri.ArcGISRuntime.Geometry.Geometry DrawedGeometry = null;
            bool toContinueDrawing = true;

            while (toContinueDrawing)
            {
                try
                {
                    DrawedGeometry = await createGeometryAsync(View);
                }
                catch (DrawCanceledExeption e)
                {
                    DrawedGeometry    = e.DrawedGepmetry;
                    toContinueDrawing = false;
                }
                finally
                {
                    if (DrawedGeometry != null && !DrawedGeometry.IsEmpty)
                    {
                        var graphic = new Graphic(DrawedGeometry);
                        graphic.Symbol = symbol;
                        _drawingOverlay.Graphics.Add(graphic);
                    }
                }
            }
        }
Exemple #14
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();
            }
        }
Exemple #15
0
        private async void OnGeoViewTapped(object sender, GeoViewInputEventArgs e)
        {
            try
            {
                IsBusy.Visibility = Visibility.Visible;
                Status.Text       = "Identifying trace locations...";

                // Identify the feature to be used.
                IEnumerable <IdentifyLayerResult> identifyResult = await MyMapView.IdentifyLayersAsync(e.Position, 10.0, false);

                ArcGISFeature feature = identifyResult?.FirstOrDefault()?.GeoElements?.FirstOrDefault() as ArcGISFeature;
                if (feature == null)
                {
                    return;
                }

                // Create element from the identified feature.
                UtilityElement element = _utilityNetwork.CreateElement(feature);

                if (element.NetworkSource.SourceType == UtilityNetworkSourceType.Junction)
                {
                    // Select terminal for junction feature.
                    IEnumerable <UtilityTerminal> terminals = element.AssetType.TerminalConfiguration?.Terminals;
                    if (terminals?.Count() > 1)
                    {
                        element.Terminal = await GetTerminalAsync(terminals);
                    }
                    Status.Text = $"Terminal: {element.Terminal?.Name ?? "default"}";
                }
                else if (element.NetworkSource.SourceType == UtilityNetworkSourceType.Edge)
                {
                    // Compute how far tapped location is along the edge feature.
                    if (feature.Geometry is Polyline line)
                    {
                        line = GeometryEngine.RemoveZ(line) as Polyline;
                        double fraction = GeometryEngine.FractionAlong(line, e.Location, -1);
                        if (double.IsNaN(fraction))
                        {
                            return;
                        }
                        element.FractionAlongEdge = fraction;
                        Status.Text = $"Fraction along edge: {element.FractionAlongEdge}";
                    }
                }

                // Check whether starting location or barrier is added to update the right collection and symbology.
                Symbol symbol = null;
                if (IsAddingStartingLocations.IsChecked.Value == true)
                {
                    _startingLocations.Add(element);
                    symbol = _startingPointSymbol;
                }
                else
                {
                    _barriers.Add(element);
                    symbol = _barrierPointSymbol;
                }

                // Add a graphic for the new utility element.
                Graphic traceLocationGraphic = new Graphic(feature.Geometry as MapPoint ?? e.Location, symbol);
                MyMapView.GraphicsOverlays.FirstOrDefault()?.Graphics.Add(traceLocationGraphic);
            }
            catch (Exception ex)
            {
                Status.Text = "Identifying locations failed.";
                await new MessageDialog2(ex.Message, ex.GetType().Name).ShowAsync();
            }
            finally
            {
                if (Status.Text.Equals("Identifying trace locations..."))
                {
                    Status.Text = "Could not identify location.";
                }
                IsBusy.Visibility = Visibility.Collapsed;
            }
        }