Ejemplo n.º 1
0
        // Summary:
        //     Select objects by geometry
        // Remarks:
        //     The function selects graphics at first,
        //     then it returns the corresponding DGObjects as a list.
        //     If a graphic has no corresponding DGObject, it will
        //     still be in a selected state.
        public List <DGObject> selectObjectsByRect(IGeometry geom)
        {
            Esri.ArcGISRuntime.Geometry.Geometry rect = geom
                                                        as Esri.ArcGISRuntime.Geometry.Geometry;

            foreach (Graphic g in graphics)
            {
                if (!GeometryEngine.Contains(rect, g.Geometry))
                {
                    continue;
                }

                IGraphic ig = g as IGraphic;
                // make sure all graphics with the name is selected.
                if (_graphic2Objs != null &&
                    _graphic2Objs.ContainsKey(ig))
                {
                    DGObject           obj = _graphic2Objs[ig];
                    IGraphicCollection gc  = _obj2Graphics[obj];
                    foreach (IGraphic item in gc)
                    {
                        item.IsSelected = true;
                    }
                }
                else
                {
                    g.IsSelected = true;
                }
            }
            List <DGObject> objs = getHighlightedObjects();

            return(objs);
        }
Ejemplo n.º 2
0
        // Accepts two user shapes and adds them to the graphics layer
        private async Task AcceptShapeAsync()
        {
            // Shape One
            Geometry shapeOne = await mapView.Editor.RequestShapeAsync(
                (DrawShape)comboShapeOne.SelectedValue, _symbols[comboShapeOne.SelectedIndex]);

            _graphicsLayer.Graphics.Add(new Graphic(shapeOne, _symbols[comboShapeOne.SelectedIndex]));

            // Shape Two
            Geometry shapeTwo = await mapView.Editor.RequestShapeAsync(
                (DrawShape)comboShapeTwo.SelectedValue, _symbols[comboShapeTwo.SelectedIndex]);

            _graphicsLayer.Graphics.Add(new Graphic(shapeTwo, _symbols[comboShapeTwo.SelectedIndex]));

            var relations = new List <Tuple <string, bool> >();

            relations.Add(new Tuple <string, bool>("Contains", GeometryEngine.Contains(shapeOne, shapeTwo)));
            relations.Add(new Tuple <string, bool>("Crosses", GeometryEngine.Crosses(shapeOne, shapeTwo)));
            relations.Add(new Tuple <string, bool>("Disjoint", GeometryEngine.Disjoint(shapeOne, shapeTwo)));
            relations.Add(new Tuple <string, bool>("Equals", GeometryEngine.Equals(shapeOne, shapeTwo)));
            relations.Add(new Tuple <string, bool>("Intersects", GeometryEngine.Intersects(shapeOne, shapeTwo)));
            relations.Add(new Tuple <string, bool>("Overlaps", GeometryEngine.Overlaps(shapeOne, shapeTwo)));
            relations.Add(new Tuple <string, bool>("Touches", GeometryEngine.Touches(shapeOne, shapeTwo)));
            relations.Add(new Tuple <string, bool>("Within", GeometryEngine.Within(shapeOne, shapeTwo)));
            resultsListView.ItemsSource = relations;

            resultsPanel.Visibility = Visibility.Visible;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns a list of spatial relationships between two geometries
        /// </summary>
        /// <param name="a">The 'a' in "a contains b"</param>
        /// <param name="b">The 'b' in "a contains b"</param>
        /// <returns>A list of spatial relationships that are true for a and b.</returns>
        private static List <SpatialRelationship> GetSpatialRelationships(Geometry a, Geometry b)
        {
            List <SpatialRelationship> relationships = new List <SpatialRelationship>();

            if (GeometryEngine.Crosses(a, b))
            {
                relationships.Add(SpatialRelationship.Crosses);
            }
            if (GeometryEngine.Contains(a, b))
            {
                relationships.Add(SpatialRelationship.Contains);
            }
            if (GeometryEngine.Disjoint(a, b))
            {
                relationships.Add(SpatialRelationship.Disjoint);
            }
            if (GeometryEngine.Intersects(a, b))
            {
                relationships.Add(SpatialRelationship.Intersects);
            }
            if (GeometryEngine.Overlaps(a, b))
            {
                relationships.Add(SpatialRelationship.Overlaps);
            }
            if (GeometryEngine.Touches(a, b))
            {
                relationships.Add(SpatialRelationship.Touches);
            }
            if (GeometryEngine.Within(a, b))
            {
                relationships.Add(SpatialRelationship.Within);
            }
            return(relationships);
        }
Ejemplo n.º 4
0
        private void MapView_Tapped(object sender, GeoViewInputEventArgs e)
        {
            // Reset the error message.
            ErrorTextBlock.Text = "";

            // Make sure the stop is valid before proceeding.
            if (!GeometryEngine.Contains(_routableArea, e.Location))
            {
                ShowMessage("Can't add stop.", "That location is outside of the area where offline routing data is available.");
                return;
            }

            if (_selectedStopGraphic == null && _stopsOverlay.Graphics.Count < 5)
            {
                // Select or add a stop.
                AddStop(e.Position);
            }
            else if (_selectedStopGraphic == null)
            {
                ShowMessage("Can't add stop.", "Sample limits to 5 stops per route.");
            }
            else
            {
                // Finish updating the geometry.
                _selectedStopGraphic.Geometry = e.Location;

                // Reset the selected graphic.
                _selectedStopGraphic = null;

                // Update the route with the final list of stops.
                UpdateRoute((TravelMode)TravelModesCombo.SelectedItem);
            }
        }
Ejemplo n.º 5
0
        internal async virtual void OnFlashPointCommandAsync(object obj)
        {
            var point = obj as MapPoint;

            if (point == null)
            {
                return;
            }

            if (!IsToolActive)
            {
                await SetAsCurrentToolAsync();
            }

            await QueuedTask.Run(() =>
            {
                // is point within current map extent
                var projectedPoint = GeometryEngine.Project(point, MapView.Active.Extent.SpatialReference);
                if (!GeometryEngine.Contains(MapView.Active.Extent, projectedPoint))
                {
                    MapView.Active.PanTo(point);
                }
                Mediator.NotifyColleagues("UPDATE_FLASH", point);
            });
        }
Ejemplo n.º 6
0
 private void FindTagByPosition(Android.Graphics.PointF position)
 {
     try
     {
         if (null != listGraphicsOverlay && listGraphicsOverlay.Count > 0)
         {
             foreach (var item in listGraphicsOverlay)
             {
                 var      pointFind = new MapPoint(position.X, position.Y, mapView.LocationDisplay.Location.Position.SpatialReference);
                 var      simpleMarkerSymbolFind = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Circle, Color.Red, 10);
                 var      graphicFind            = new Graphic(pointFind, simpleMarkerSymbolFind);
                 Geometry geometryData           = GeometryEngine.Project(item.Value, mapView.LocationDisplay.Location.Position.SpatialReference);
                 Boolean  result          = GeometryEngine.Contains(geometryData, graphicFind.Geometry);
                 Boolean  resultIntersect = GeometryEngine.Intersects(geometryData, graphicFind.Geometry);
                 if (result && resultIntersect)
                 {
                     var intent = new Intent(this, typeof(ConsultarTap));
                     intent.PutExtra("codigoTag", item.Key);
                     StartActivity(intent);
                     SetContentView(Resource.Layout.Fragment_ConsultarTap);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Log.Info("Error", ex.Message);
         throw new System.Exception(ex.Message);
     }
 }
        /// <summary>
        /// Method used to check to see if a point is contained by an envelope
        /// </summary>
        /// <param name="point">MapPoint</param>
        /// <param name="env">Envelope</param>
        /// <returns>bool</returns>
        internal async Task <bool> IsPointWithinExtent(MapPoint point, Envelope env)
        {
            var result = await QueuedTask.Run(() =>
            {
                return(GeometryEngine.Contains(env, point));
            });

            return(result);
        }
        private void MyMapView_GeoViewTapped(object sender, GeoViewInputEventArgs e)
        {
            try
            {
                // Get the input map point (in the map's coordinate system, State Plane for North Central Texas).
                MapPoint tapMapPoint = e.Location;

                // Check if the point coordinates are within the spatial reference envelope.
                bool withinValidExent = GeometryEngine.Contains(_spatialReferenceArea, tapMapPoint);

                // If the input point is not within the valid extent for the spatial reference, warn the user and return.
                if (!withinValidExent)
                {
                    // Display a message to warn the user.
                    AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this);
                    alertBuilder.SetTitle("Out of bounds");
                    alertBuilder.SetMessage("Location is not valid to buffer using the defined spatial reference.");
                    alertBuilder.Show();

                    return;
                }

                // Get the buffer radius (in miles) from the text box.
                double bufferDistanceMiles = Convert.ToDouble(_bufferDistanceMilesEditText.Text);

                // Use a helper method to get the buffer distance in feet (unit that's used by the spatial reference).
                double bufferDistanceFeet = LinearUnits.Miles.ConvertTo(LinearUnits.Feet, bufferDistanceMiles);

                // Create a simple marker symbol (red circle) to display where the user tapped/clicked on the map.
                SimpleMarkerSymbol tapSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Circle, Color.Red, 10);

                // Create a new graphic to show the tap location.
                Graphic tapGraphic = new Graphic(tapMapPoint, tapSymbol)
                {
                    // Specify a z-index value on the point graphic to make sure it draws on top of the buffer polygons.
                    ZIndex = 2
                };

                // Store the specified buffer distance as an attribute with the graphic.
                tapGraphic.Attributes["distance"] = bufferDistanceFeet;

                // Add the tap point graphic to the buffer graphics overlay.
                _myMapView.GraphicsOverlays["buffers"].Graphics.Add(tapGraphic);
            }
            catch (Exception ex)
            {
                // Display an error message.
                AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this);
                alertBuilder.SetTitle("Error creating buffer point");
                alertBuilder.SetMessage(ex.Message);
                alertBuilder.Show();
            }
        }
        public async Task <bool> FlyToAsync(MapPoint to, double scale, Thickness margin)
        {
            var mapExtent = MapView.Extent;

            if (!GeometryEngine.Contains(mapExtent, to))                                                  //Destination is outside current view
            {
                if (!(await MapView.SetViewAsync(mapExtent.Union(to), TimeSpan.FromSeconds(1), margin) && //Zoom out to see both destinations
                      await MapView.SetViewAsync(to, TimeSpan.FromSeconds(1.5), margin)))                 //center on destination
                {
                    return(false);
                }
            }
            return(await MapView.SetViewAsync(to, scale, margin));
        }
        public async Task <bool> FlyToAsync(Geometry flyTo, Thickness margin)
        {
            Envelope to = flyTo.Extent;

            if (to.Width > 0 || to.Height > 0)
            {
                var mapExtent = MapView.Extent;
                if (!GeometryEngine.Contains(mapExtent, to))                                                  //Destination is outside current view
                {
                    if (!(await MapView.SetViewAsync(mapExtent.Union(to), TimeSpan.FromSeconds(1), margin) && //Zoom out to see both destinations
                          await MapView.SetViewAsync(to, TimeSpan.FromSeconds(1.5), margin)))                 //center on destination
                    {
                        return(false);
                    }
                }
                return(await MapView.SetViewAsync(to, margin));
            }
            return(await MapView.SetViewAsync(to, margin)); //Pan to Point
        }
Ejemplo n.º 11
0
        private void MapView_Tapped(object sender, Esri.ArcGISRuntime.Xamarin.Forms.GeoViewInputEventArgs e)
        {
            // Make sure the user isn't adding too many stops.
            if (_stopsOverlay.Graphics.Count >= 5)
            {
                ShowMessage("Can't add stop.", "Sample limits to 5 stops per route.");
                return;
            }

            // Make sure the stop is valid before proceeding.
            if (!GeometryEngine.Contains(_routableArea, e.Location))
            {
                ShowMessage("Can't add stop.", "That location is outside of the area where offline routing data is available.");
                return;
            }

            // Add the stop for the tapped position.
            AddStop(e.Position);

            // Update the route with the final list of stops.
            UpdateRoute((TravelMode)TravelModesCombo.SelectedItem);
        }
Ejemplo n.º 12
0
        private void MapView_PointerMoved(object sender, PointerRoutedEventArgs e)
        {
            if (_selectedStopGraphic != null)
            {
                // Get the position of the mouse relative to the map view.
                var hoverPoint = e.GetCurrentPoint(MyMapView);

                // Get the physical map location corresponding to the mouse position.
                MapPoint hoverLocation = MyMapView.ScreenToLocation(hoverPoint.Position);

                // Return if the location is outside the routable area.
                if (!GeometryEngine.Contains(_routableArea, hoverLocation))
                {
                    return;
                }

                // Update the location of the stop graphic.
                _selectedStopGraphic.Geometry = hoverLocation;

                // Update the route with the temporary stop.
                UpdateRoute((TravelMode)TravelModesCombo.SelectedItem ?? _availableTravelModes.First());
            }
        }
Ejemplo n.º 13
0
        // Accepts two user shapes and adds them to the graphics layer
        private async Task AcceptShapeAsync()
        {
            // Shape One
            DrawShape drawShape1 = (DrawShape)comboShapeOne.SelectedItem;
            Geometry  shapeOne   = null;

            if (drawShape1 == DrawShape.Point)
            {
                shapeOne = await mapView.Editor.RequestPointAsync();
            }
            else
            {
                shapeOne = await mapView.Editor.RequestShapeAsync(drawShape1, _symbols[comboShapeOne.SelectedIndex]);
            }

            graphicsLayer.Graphics.Add(new Graphic(shapeOne, _symbols[comboShapeOne.SelectedIndex]));

            // Shape Two
            Geometry shapeTwo = await mapView.Editor.RequestShapeAsync(
                (DrawShape)comboShapeTwo.SelectedItem, _symbols[comboShapeTwo.SelectedIndex]);

            graphicsLayer.Graphics.Add(new Graphic(shapeTwo, _symbols[comboShapeTwo.SelectedIndex]));

            Dictionary <string, bool> relations = new Dictionary <string, bool>();

            relations["Contains"]   = GeometryEngine.Contains(shapeOne, shapeTwo);
            relations["Crosses"]    = GeometryEngine.Crosses(shapeOne, shapeTwo);
            relations["Disjoint"]   = GeometryEngine.Disjoint(shapeOne, shapeTwo);
            relations["Equals"]     = GeometryEngine.Equals(shapeOne, shapeTwo);
            relations["Intersects"] = GeometryEngine.Intersects(shapeOne, shapeTwo);
            relations["Overlaps"]   = GeometryEngine.Overlaps(shapeOne, shapeTwo);
            relations["Touches"]    = GeometryEngine.Touches(shapeOne, shapeTwo);
            relations["Within"]     = GeometryEngine.Within(shapeOne, shapeTwo);

            resultsPanel.Visibility     = Visibility.Visible;
            resultsListView.ItemsSource = relations;
        }
        private void MapView_Tapped(object sender, GeoViewInputEventArgs e)
        {
            // Make sure the user isn't adding too many stops.
            if (_stopsOverlay.Graphics.Count >= 5)
            {
                ShowMessage("Can't add stop.", "Sample limits to 5 stops per route.");
                return;
            }

            // Make sure the stop is valid before proceeding.
            if (!GeometryEngine.Contains(_routableArea, e.Location))
            {
                ShowMessage("Can't add stop.", "That location is outside of the area where offline routing data is available.");
                return;
            }

            // Add the stop.
            AddStop(e.Position);

            // Update the route with the final list of stops.
            TravelMode selectedTravelMode = _availableTravelModes[_travelModeSpinner.SelectedItemPosition];

            UpdateRoute(selectedTravelMode);
        }
        /// <summary>
        /// Handle any map-related viewmodel property changes
        /// </summary>
        /// <param name="sender">The viewmodel</param>
        /// <param name="e">Information about the property change</param>
        private void ViewModelPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            switch (e.PropertyName)
            {
            case nameof(_viewModel.Map):
                if (_viewModel.Map != null)
                {
                    // Add the map to the MapView to be displayed
                    _mapView.Map = _viewModel.Map;

                    // Update attribution visibility in case it changed.
                    SetAttributionForCurrentState();
                }

                break;

            case nameof(_viewModel.CurrentState):
                // Hide or show cards as needed for the new UI state
                UpdateUiForNewState();
                // Ensure relevant layers are visible
                if (_viewModel.CurrentState == UiState.LocationFound || _viewModel.CurrentState == UiState.PlanningRoute)
                {
                    _identifiedFeatureOverlay.IsVisible = true;
                    _homeOverlay.IsVisible = true;
                }
                break;

            case nameof(_viewModel.CurrentRoom):
                // Clear any existing graphics when the selected/identified room changes
                _identifiedFeatureOverlay.Graphics.Clear();
                _homeOverlay.Graphics.Clear();
                // If the room is null, the view is now reset to a neutral state
                if (_viewModel.CurrentRoom is Room room)
                {
                    // If the room is home, show the home graphic and zoom to it
                    if (room.IsHome)
                    {
                        _homeOverlay.Graphics.Add(new Graphic(room.CenterPoint));
                        if (!GeometryEngine.Contains(_mapView.VisibleArea, room.CenterPoint))
                        {
                            TrySetViewpoint(room.CenterPoint, 150);
                        }

                        // Turn off location display
                        _mapView.LocationDisplay.AutoPanMode = LocationDisplayAutoPanMode.Off;
                    }
                    // If the room is standing in for the user's current location, re-enable location display automatic panning
                    else if (_viewModel.CurrentRoom.IsCurrentLocation)
                    {
                        _mapView.LocationDisplay.AutoPanMode = LocationDisplayAutoPanMode.Recenter;
                    }
                    // If the room is just a room, show the default graphic and zoom to the room geometry
                    else
                    {
                        // Turn off location display
                        _mapView.LocationDisplay.AutoPanMode = LocationDisplayAutoPanMode.Off;

                        _identifiedFeatureOverlay.Graphics.Add(new Graphic(room.CenterPoint));
                        if (!GeometryEngine.Contains(_mapView.VisibleArea, room.Geometry))
                        {
                            TrySetViewpoint(room.Geometry, 30);
                        }
                    }
                }
                else
                {
                    _mapView.LocationDisplay.AutoPanMode = LocationDisplayAutoPanMode.Off;
                    _locationButton.SetImage(UIImage.FromBundle("gps-on"), UIControlState.Normal);
                }
                // need to explicitly request re-layout because identified room can change without UI state changing
                _bottomSheet.SetState(BottomSheetViewController.BottomSheetState.Partial);
                break;

            case nameof(_viewModel.CurrentRoute):
                // Clear any existing route
                _routeOverlay.Graphics.Clear();

                // Show the route and configure other layers if the route isn't null
                if (_viewModel.CurrentRoute?.Routes?.FirstOrDefault() is Route route)
                {
                    // Hide other graphics
                    _identifiedFeatureOverlay.IsVisible = false;
                    _homeOverlay.IsVisible = false;

                    // Add the route stops and route geometry
                    _routeOverlay.Graphics.Add(new Graphic(route.RouteGeometry.Parts.First().Points.First(), _routeStartSymbol));
                    _routeOverlay.Graphics.Add(new Graphic(route.RouteGeometry.Parts.Last().Points.Last(), _routeEndSymbol));
                    _routeOverlay.Graphics.Add(new Graphic(route.RouteGeometry));

                    // Zoom to the route
                    TrySetViewpoint(route.RouteGeometry, 30);
                }
                break;
            }
        }