Ejemplo n.º 1
0
 private async void ResetViewPoint()
 {
     try
     {
         await MapViewService.ResetViewpointAsync();
     }
     catch (Exception)
     {
         // ignored
     }
 }
        /// <summary>
        /// Selects feature.
        /// </summary>
        private async void SelectFeature(MapViewInputEventArgs parameters)
        {
            // If editor is active skip selecting features
            if (Editor.IsActive)
            {
                return;
            }

            // Unselect all features
            var featureLayers = Map.Layers.OfType <FeatureLayer>();

            foreach (var layer in featureLayers)
            {
                layer.ClearSelection();
            }

            GeodatabaseFeature feature           = null;
            Exception          exceptionToHandle = null;

            try
            {
                foreach (var layer in featureLayers.Where(l => l.Status == LayerStatus.Initialized).Reverse())
                {
                    // Using MapViewService to handle hit testing.
                    var hit = await MapViewService.HitTestAsync(parameters.Position, layer) as GeodatabaseFeature;

                    if (hit != null)
                    {
                        // Set feature selected
                        layer.SelectFeatures(new[] { (long)hit.Attributes[layer.FeatureTable.ServiceInfo.ObjectIdField] });

                        // Take feature and its layer for later use
                        feature        = hit;
                        _selectedLayer = layer;
                        break;
                    }
                }
            }
            catch (Exception exception)
            {
                exceptionToHandle = exception;
            }

            if (exceptionToHandle != null)
            {
                // Initialization failed, show message and return
                await MessageService.Instance.ShowMessage(string.Format(
                                                              "Could not create basemap. Error = {0}", exceptionToHandle.ToString()),
                                                          "An error occured");
            }

            // Select or clear selection
            SelectedFeature = feature;
        }
Ejemplo n.º 3
0
 private async void ZoomOut()
 {
     try
     {
         double currentScale = MapViewService.MapScale;
         await MapViewService.SetViewpointScaleAsync(currentScale * 1.5);
     }
     catch (Exception)
     {
         // Ignored
     }
 }
        private async void MouseMoved(MouseEventArgs parameters)
        {
            if (startGraphic == null)
            {
                return;
            }

            // Get mouses location relative to MapView.
            var point = MapViewService.GetLocation(parameters);

            Exception exceptionToHandle = null;;

            try
            {
                var graphic = await GetGeocodedGraphicAsync(point);

                if (graphic == null)
                {
                    return;
                }

                graphic.Attributes.Add("PointType", "EndPoint");

                // Get endpoint graphic from the layer and replace that with new location
                var existingGraphic = _graphicLayer
                                      .Graphics
                                      .FirstOrDefault(g => g.Attributes["PointType"].ToString() == "EndPoint");
                if (existingGraphic != null)
                {
                    _graphicLayer.Graphics.Remove(existingGraphic);
                }

                _graphicLayer.Graphics.Add(graphic);

                var routeGraphic = await GetRouteGraphicAsync(
                    startGraphic.Geometry as MapPoint,
                    graphic.Geometry as MapPoint);

                if (routeGraphic == null)
                {
                    return;
                }

                _routeLayer.Graphics.Clear();
                _routeLayer.Graphics.Add(routeGraphic);
            }
            catch (Exception exception)
            {
            }
        }