// Continuosly accepts new points from the user
        private async Task DrawPoints()
        {
            try
            {
                await MyMapView.LayersLoadedAsync();

                var point = await MyMapView.Editor.RequestPointAsync();

                // reset graphics layers if we've already created a convex hull polygon
                if (_convexHullGraphicsOverlay.Graphics.Count > 0)
                {
                    _inputGraphicsOverlay.Graphics.Clear();
                    _convexHullGraphicsOverlay.Graphics.Clear();
                }

                _inputGraphicsOverlay.Graphics.Add(new Graphic(point, _pointSymbol));

                if (_inputGraphicsOverlay.Graphics.Count > 2)
                {
                    btnConvexHull.IsEnabled = true;
                }

                await DrawPoints();
            }
            catch (TaskCanceledException) { }
            catch (Exception ex)
            {
                MessageBox.Show("Error adding points: " + ex.Message, "Convex Hull Sample");
            }
        }
Esempio n. 2
0
        // Continuosly accept polygons from the user and calculate label points
        private async Task CalculateLabelPointsAsync()
        {
            try
            {
                await MyMapView.LayersLoadedAsync();

                while (MyMapView.Extent != null)
                {
                    if (MyMapView.Editor.IsActive)
                        MyMapView.Editor.Cancel.Execute(null);

                    //Get the input polygon geometry from the user
                    var poly = await MyMapView.Editor.RequestShapeAsync(DrawShape.Polygon, ((SimpleRenderer)_labelOverlay.Renderer).Symbol);
                    if (poly != null)
                    {
                        //Add the polygon drawn by the user
                        _labelOverlay.Graphics.Add(new Graphic(poly));

                        //Get the label point for the input geometry
                        var labelPoint = GeometryEngine.LabelPoint(poly);
                        if (labelPoint != null)
                        {
                            _labelOverlay.Graphics.Add(new Graphic(labelPoint, _pictureMarkerSymbol));
                        }
                    }
                }
            }
            catch (TaskCanceledException) { }
            catch (Exception ex)
            {
                var _x = new MessageDialog("Label Point Error: " + ex.Message, "Sample Error").ShowAsync();
            }
        }
Esempio n. 3
0
        // Zoom to combined extent of the group layer that contains all hydrographic layers
        private async void ZoomToHydrographicLayers()
        {
            try
            {
                // wait until all layers are loaded
                await MyMapView.LayersLoadedAsync();

                // Get group layer from Map and set list items source
                _hydrographicGroupLayer   = MyMapView.Map.Layers.OfType <GroupLayer>().First();
                s57CellList.ItemsSource   = _hydrographicGroupLayer.ChildLayers;
                s57CellList.SelectedIndex = 0;

                Envelope extent = _hydrographicGroupLayer.ChildLayers.First().FullExtent;

                // Create combined extent from child hydrographic layers
                foreach (var layer in _hydrographicGroupLayer.ChildLayers)
                {
                    extent = extent.Union(layer.FullExtent);
                }

                // Zoom to full extent
                await MyMapView.SetViewAsync(extent);

                // Enable controls
                addCellButton.IsEnabled             = true;
                zoomToSelectedButton.IsEnabled      = true;
                removeSelectedCellsButton.IsEnabled = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error occured : " + ex.Message, "Sample error");
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 鹰眼地图显示调整
        /// </summary>
        /// <returns></returns>
        private async Task AddSingleGraphicAsync()
        {
            try
            {
                await MyMapView.LayersLoadedAsync();

                var    graphicsOverlay = overviewMap.GraphicsOverlays["overviewOverlay"];
                Symbol symbol          = symbol = Resources["RedFillSymbol"] as Symbol;
                while (true)
                {
                    var geometry = await overviewMap.Editor.RequestShapeAsync(DrawShape.Rectangle, symbol);

                    graphicsOverlay.Graphics.Clear();

                    var graphic = new Graphic(geometry, symbol);
                    graphicsOverlay.Graphics.Add(graphic);

                    var viewpointExtent = geometry.Extent;
                    await MyMapView.SetViewAsync(viewpointExtent);
                }
            }
            catch (TaskCanceledException)
            {
                // Ignore cancellations from selecting new shape type
            }
            catch (Exception ex)
            {
            }
        }
        // Zoom to combined extent of the group layer that contains all hydrographic layers
        private async void ZoomToHydrographicLayers()
        {
            try
            {
                // wait until all layers are loaded
                await MyMapView.LayersLoadedAsync();

                var extent = _hydrographicLayers.ChildLayers.First().FullExtent;

                // Create combined extent from child hydrographic layers
                foreach (var layer in _hydrographicLayers.ChildLayers)
                {
                    extent = extent.Union(layer.FullExtent);
                }

                // Zoom to full extent
                await MyMapView.SetViewAsync(extent);

                SearchArea.IsEnabled = true;
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
        }
        // Load data - enable functionality after layers are loaded.
        private async void MyMapView_ExtentChanged(object sender, EventArgs e)
        {
            try
            {
                MyMapView.ExtentChanged -= MyMapView_ExtentChanged;

                // Get group layer from Map and set list items source
                _hydrographicGroupLayer = MyMapView.Map.Layers.OfType <GroupLayer>().First();

                // Check that sample data is downloaded to the client
                await CreateHydrographicLayerAsync(LAYER_1_PATH);
                await CreateHydrographicLayerAsync(LAYER_2_PATH);

                // Wait until all layers are loaded
                var layers = await MyMapView.LayersLoadedAsync();

                Envelope extent = _hydrographicGroupLayer.ChildLayers.First().FullExtent;

                // Create combined extent from child hydrographic layers
                foreach (var layer in _hydrographicGroupLayer.ChildLayers)
                {
                    extent = extent.Union(layer.FullExtent);
                }


                // Zoom to full extent
                await MyMapView.SetViewAsync(extent);
            }
            catch (Exception ex)
            {
                var _x = new MessageDialog(ex.Message, "S57 Display Properties Sample").ShowAsync();
            }
        }
        // Create three List<Graphic> objects with random graphics to serve as layer GraphicsSources
        private async void CreateGraphics()
        {
			try
			{
				await MyMapView.LayersLoadedAsync();

				_graphicsSources = new List<List<Graphic>>()
				{
					new List<Graphic>(),
					new List<Graphic>(),
					new List<Graphic>()
				};

				foreach (var graphicList in _graphicsSources)
				{
					for (int n = 0; n < 10; ++n)
					{
						graphicList.Add(CreateRandomGraphic());
					}
				}

				_graphicSourceIndex = 0;
				_graphicsLayer.GraphicsSource = _graphicsSources[_graphicSourceIndex];
			}
			catch (Exception ex)
			{
				var _x = new MessageDialog("Exception occurred : " + ex.ToString(), "Sample error").ShowAsync();
			}
        }
        // Load data - enable functionality after layers are loaded.
        private async void MyMapView_ExtentChanged(object sender, EventArgs e)
        {
            try
            {
                MyMapView.ExtentChanged -= MyMapView_ExtentChanged;

                // Get group layer from Map and set list items source
                _hydrographicGroupLayer = MyMapView.Map.Layers.OfType <GroupLayer>().First();

                // Check that sample data is downloaded to the client
                await CreateHydrographicLayerAsync(LAYER_1_PATH);
                await CreateHydrographicLayerAsync(LAYER_2_PATH);

                // Wait until all layers are loaded
                var layers = await MyMapView.LayersLoadedAsync();

                // Set item sources
                s57CellList.ItemsSource   = _hydrographicGroupLayer.ChildLayers;
                s57CellList.SelectedIndex = 0;

                // Zoom to hydrographic layer
                await MyMapView.SetViewAsync(_hydrographicGroupLayer.FullExtent);
            }
            catch (Exception ex)
            {
                var _x = new MessageDialog(ex.Message, "S57 Cell Info Sample").ShowAsync();
            }
        }
Esempio n. 9
0
        // Zoom to combined extent of the group layer that contains all hydrographic layers
        private async void ZoomToHydrographicLayers()
        {
            try
            {
                // wait until all layers are loaded
                await MyMapView.LayersLoadedAsync();

                var hydroGroupLayer = MyMapView.Map.Layers.OfType <GroupLayer>().First();
                var extent          = hydroGroupLayer.ChildLayers.First().FullExtent;

                // Create combined extent from child hydrographic layers
                foreach (var layer in hydroGroupLayer.ChildLayers)
                {
                    extent = extent.Union(layer.FullExtent);
                }

                // Zoom to full extent
                await MyMapView.SetViewAsync(extent);

                // Enable controls
                displayPropertiesArea.IsEnabled = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        // Add new random graphics to the graphics layer
        private async Task CreateGraphicsAsync(int numGraphics)
        {
            await MyMapView.LayersLoadedAsync();

            if (_maxExtent == null)
            {
                _maxExtent = MyMapView.Extent;
            }

            for (int n = 0; n < numGraphics; ++n)
            {
                _graphics.Add(CreateRandomGraphic());
            }
        }
        // Setup graphic layers with test graphics and calculated boundaries of each
        private async void CreateGraphics()
        {
            try
            {
                await MyMapView.LayersLoadedAsync();

                CreateTestGraphics();
                CalculateBoundaries();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error occured : " + ex.Message, "Boundary Sample");
            }
        }
        private async void Init()
        {
            // Wait until all layers are loaded
            await MyMapView.LayersLoadedAsync();

            bool isSymbolDictionaryInitialized = false;

            try
            {
                // Create a new SymbolDictionary instance
                _symbolDictionary             = new SymbolDictionary(SymbolDictionaryType.Mil2525c);
                isSymbolDictionaryInitialized = true;
            }
            catch { }

            if (!isSymbolDictionaryInitialized)
            {
                MessageBox.Show("Failed to create symbol dictionary.", "Symbol Dictionary Search Sample");
                return;
            }

            // Collection of strings to hold the selected symbol dictionary keywords
            SelectedKeywords = new ObservableCollection <string>();

            // Remove any empty strings space from keywords
            _keywords = _symbolDictionary.Keywords.OrderBy(k => k).ToList();
            _keywords = _keywords.Where(s => !string.IsNullOrWhiteSpace(s)).Distinct().ToList();

            // Remove any empty strings space from categories
            _categories = new[] { "" }.Concat(_symbolDictionary.Filters["CATEGORY"]);
            Categories  = _categories.Where(s => !string.IsNullOrWhiteSpace(s)).Distinct();

            // Collection of view models for the displayed list of symbols
            Symbols = new ObservableCollection <SymbolViewModel>();

            // Set the image size
            _imageSize = 64;

            // Get reference to MessageLayer to use with messages
            _messageLayer = MyMapView.Map.Layers.OfType <MessageLayer>().First();

            // Fire initial search to populate the results with all symbols
            Search();

            // Enable the UI
            btnSearch.IsEnabled = true;

            // Set the DataContext for binding
            DataContext = this;
        }
        // Add new random graphics to the graphics layer
        private async Task CreateGraphicsAsync(int numGraphics)
        {
            await MyMapView.LayersLoadedAsync();

            if (_maxExtent == null)
            {
                _maxExtent = MyMapView.GetCurrentViewpoint(ViewpointType.BoundingGeometry).TargetGeometry.Extent;
            }

            for (int n = 0; n < numGraphics; ++n)
            {
                _graphics.Add(CreateRandomGraphic());
            }
        }
        // Make sure the map is ready for user interaction
        private async void MyMapView_ExtentChanged(object sender, EventArgs e)
        {
            try
            {
                MyMapView.ExtentChanged -= MyMapView_ExtentChanged;
                await MyMapView.LayersLoadedAsync();

                _isMapReady = true;
            }
            catch (Exception ex)
            {
                var _x = new MessageDialog(ex.Message, "Sample Error").ShowAsync();
            }
        }
        // Draw graphics infinitely
        private async void AddGraphicsAsync()
        {
            await MyMapView.LayersLoadedAsync();

            while (true)
            {
                // if the map is not in a valid state
                if (MyMapView.Extent == null)
                {
                    break;
                }

                await AddSingleGraphicAsync();
            }
        }
Esempio n. 16
0
        // Draw graphics infinitely
        private async void AddGraphicsAsync()
        {
            await MyMapView.LayersLoadedAsync();

            while (true)
            {
                // if the map is not in a valid state
                if (MyMapView.GetCurrentViewpoint(ViewpointType.BoundingGeometry).TargetGeometry.Extent == null)
                {
                    break;
                }

                await AddSingleGraphicAsync();
            }
        }
        // Make sure the map is ready for user interaction
        private async void MyMapView_ExtentChanged(object sender, EventArgs e)
        {
            try
            {
                MyMapView.ExtentChanged -= MyMapView_ExtentChanged;

                await MyMapView.LayersLoadedAsync();

                _isMapReady = true;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
            }
        }
        // Setup graphic layers with test graphics and calculated boundaries of each
        private async void CreateGraphics()
        {
            try
            {
                await MyMapView.LayersLoadedAsync();

                CreateTestGraphics();
                CalculateBoundaries();
            }
            catch (Exception ex)
            {
                var _x = new MessageDialog(
                    string.Format("Error occured : {0}", ex.ToString(), "Boundary Sample")).ShowAsync();
            }
        }
        // Create three List<Graphic> objects with random graphics to serve as layer GraphicsSources
        private async void CreateGraphics()
        {
            try
            {
                await MyMapView.LayersLoadedAsync();

                for (int n = 1; n <= MAX_GRAPHICS; ++n)
                {
                    _graphicsLayer.Graphics.Add(CreateRandomGraphic(n));
                }
            }
            catch (Exception ex)
            {
                var _x = new MessageDialog(ex.ToString(), "Sample error").ShowAsync();
            }
        }
Esempio n. 20
0
        // Draw graphics infinitely
        private async Task AddGraphicsAsync()
        {
            await MyMapView.LayersLoadedAsync();

            while (InDrawMode)
            {
                // if the map is not in a valid state - quit and turn drawing mode off
                if (MyMapView.GetCurrentViewpoint(ViewpointType.BoundingGeometry).TargetGeometry.Extent == null)
                {
                    InDrawMode = false;
                    break;
                }

                await AddSingleGraphicAsync();
            }
        }
        // Draw graphics infinitely
        private async Task AddGraphicsAsync()
        {
            await MyMapView.LayersLoadedAsync();

            while (InDrawMode)
            {
                // if the map is not in a valid state - quit and turn drawing mode off
                if (MyMapView.Extent == null)
                {
                    InDrawMode = false;
                    break;
                }

                await AddSingleGraphicAsync();
            }
        }
        // Create three List<Graphic> objects with random graphics to serve as layer GraphicsSources
        private async Task CreateGraphics()
        {
            try
            {
                await MyMapView.LayersLoadedAsync();

                for (int n = 1; n <= MAX_GRAPHICS; ++n)
                {
                    _graphicsLayer.Graphics.Add(CreateRandomGraphic(n));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error occurred : " + ex.ToString(), "Sample error");
            }
        }
        // Load data - enable functionality after layers are loaded.
        private async void MyMapView_ExtentChanged(object sender, EventArgs e)
        {
            try
            {
                MyMapView.ExtentChanged -= MyMapView_ExtentChanged;

                // Wait until all layers are loaded
                var layers = await MyMapView.LayersLoadedAsync();

                _messageLayer = MyMapView.Map.Layers.OfType <MessageLayer>().First();
                processMessagesBtn.IsEnabled = true;
            }
            catch (Exception ex)
            {
                var _x = new MessageDialog(ex.Message, "Message Processing Sample").ShowAsync();
            }
        }
        private async void MyMapView_NavigationCompleted(object sender, EventArgs e)
        {
            try
            {
                MyMapView.NavigationCompleted -= MyMapView_NavigationCompleted;

                await LoadParcelsAsync();

                await MyMapView.LayersLoadedAsync();

                await ProcessUserPointsAsync(false);
            }
            catch (Exception ex)
            {
                var _x = new MessageDialog("Error loading parcels: " + ex.Message, "Sample Error").ShowAsync();
            }
        }
        // Load data - set initial renderer after the map has an extent and feature layer loaded
        private async void MyMapView_SpatialReferenceChanged(object sender, EventArgs e)
        {
            try
            {
                MyMapView.SpatialReferenceChanged -= MyMapView_SpatialReferenceChanged;

                var table = _featureLayer.FeatureTable as ServiceFeatureTable;
                table.MaxAllowableOffset = MyMapView.UnitsPerPixel;

                await MyMapView.LayersLoadedAsync();

                comboField.SelectedIndex = 0;
            }
            catch (Exception ex)
            {
                var _x = new MessageDialog(ex.Message, "Sample Error").ShowAsync();
            }
        }
        // Load data - set initial renderer after the map has an extent and feature layer loaded
        private async void MyMapView_ExtentChanged(object sender, EventArgs e)
        {
            try
            {
                MyMapView.ExtentChanged -= MyMapView_ExtentChanged;

                var table = featureLayer.FeatureTable as ServiceFeatureTable;
                table.MaxAllowableOffset = MyMapView.UnitsPerPixel;

                await MyMapView.LayersLoadedAsync();

                comboField.SelectedIndex = 0;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Generate Renderer Task Sample");
            }
        }
        private async void MyMapView_NavigationCompleted(object sender, EventArgs e)
        {
            try
            {
                MyMapView.NavigationCompleted -= MyMapView_NavigationCompleted;

                await LoadParcelsAsync();

                await MyMapView.LayersLoadedAsync();

                layoutGrid.IsEnabled = true;
                await ProcessUserPointsAsync(false);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error loading parcels: " + ex.Message, "Nearest Coordinate Sample");
            }
        }
        private async void GetLayerUrls()
        {
            await MyMapView.LayersLoadedAsync();

            var basemapLayer = MyMapView.Map.Layers["Basemap"] as ArcGISTiledMapServiceLayer;

            if (basemapLayer != null)
            {
                this.basemapLayerServiceUrl = basemapLayer.ServiceUri;
            }

            var featureLayer = MyMapView.Map.Layers["POI"] as FeatureLayer;
            var table        = featureLayer.FeatureTable as ServiceFeatureTable;

            if (table != null)
            {
                this.featureLayerServiceUrl = table.ServiceUri;
            }
        }
        private async void HandleLayersInitialized()
        {
            try
            {
                var loadresult = await MyMapView.LayersLoadedAsync();

                LayersInitializedProperty = "Initialized!";
                foreach (var res in loadresult)
                {
                    if (res.LoadError != null)
                    {
                        MessageBox.Show(string.Format("Layer {0} failed to load. {1} ", res.Layer.ID, res.LoadError.Message.ToString()));
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error occured : " + ex.ToString(), "Sample error");
            }
        }
Esempio n. 30
0
        /// <summary>
        /// 改变主视图的范围  放大缩小
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        private async Task ChangeMainMapSacleAsync(int type)
        {
            try
            {
                await MyMapView.LayersLoadedAsync();

                var    graphicsOverlay = MyMapView.GraphicsOverlays["overviewOverlay"];
                Symbol symbol          = symbol = Resources["OutlineSymbol"] as Symbol;
                while (true)
                {
                    var geometry = await MyMapView.Editor.RequestShapeAsync(DrawShape.Rectangle, symbol);

                    graphicsOverlay.Graphics.Clear();

                    var graphic = new Graphic(geometry, symbol);
                    graphicsOverlay.Graphics.Add(graphic);

                    var viewpointExtent = geometry.Extent;
                    if (type == 1)
                    {
                        await MyMapView.SetViewAsync(viewpointExtent);
                    }
                    else if (type == 2)
                    {
                        await MyMapView.SetViewAsync(viewpointExtent.GetCenter(), MyMapView.Scale * 2);
                    }
                    graphicsOverlay.Graphics.Clear();
                }
            }
            catch (TaskCanceledException)
            {
                // Ignore cancellations from selecting new shape type
            }
            catch (Exception ex)
            {
            }
        }