/// <summary>
        /// Called when the OnToolMouseDown event is handled. Allows the opportunity to perform asynchronous operations corresponding to the event.
        /// </summary>
        protected override Task HandleMouseDownAsync(MapViewMouseButtonEventArgs e)
        {
            //Get the instance of the ViewModel
            var vm = OverlayEmbeddableControl as EmbeddedControlViewModel;

            if (vm == null)
            {
                return(Task.FromResult(0));
            }

            //Get the map coordinates from the click point and set the property on the ViewModel.
            return(QueuedTask.Run(() =>
            {
                var mapPoint = ActiveMapView.ClientToMap(e.ClientPoint);
                var coords = GeometryEngine.Project(mapPoint, SpatialReferences.WGS84) as MapPoint;
                if (coords == null)
                {
                    return;
                }
                var sb = new StringBuilder();
                sb.AppendLine($"X: {coords.X:0.000}");
                sb.Append($"Y: {coords.Y:0.000}");
                if (coords.HasZ)
                {
                    sb.AppendLine();
                    sb.Append($"Z: {coords.Z:0.000}");
                }
                vm.Text = sb.ToString();
            }));
        }
Пример #2
0
        private Task <Tuple <IDisposable, long> > AddFeatureToOverlay(MapViewMouseEventArgs e)
        {
            return(QueuedTask.Run(() => {
                double llx = e.ClientPoint.X - 3;
                double lly = e.ClientPoint.Y - 3;
                double urx = e.ClientPoint.X + 3;
                double ury = e.ClientPoint.Y + 3;

                EnvelopeBuilder envBuilder = new EnvelopeBuilder(ActiveMapView.ClientToMap(new Point(llx, lly)),
                                                                 ActiveMapView.ClientToMap(new Point(urx, ury)));

                MapPoint mp = ActiveMapView.ClientToMap(e.ClientPoint);
                var cursor = _trees.Search(new SpatialQueryFilter()
                {
                    FilterGeometry = envBuilder.ToGeometry(), SpatialRelationship = SpatialRelationship.Intersects
                });
                if (cursor.MoveNext())
                {
                    return new Tuple <IDisposable, long>(
                        ActiveMapView.AddOverlay(ActiveMapView.ClientToMap(e.ClientPoint),
                                                 _overlaySymbol.MakeSymbolReference()),
                        cursor.Current.GetObjectID());
                }

                //var select = _trees.Select(new SpatialQueryFilter() {
                //    FilterGeometry = envBuilder.ToGeometry(),
                //    SpatialRelationship = SpatialRelationship.Intersects
                //});
                //if (select.GetCount() > 0) {
                //    return ActiveMapView.AddOverlay(ActiveMapView.ClientToMap(e.ClientPoint), _overlaySymbol.MakeSymbolReference());
                //}

                return new Tuple <IDisposable, long>(null, -1);
            }));
        }
        protected override void OnToolMouseMove(MapViewMouseEventArgs e)
        {
            if (_active)
            {
                QueuedTask.Run(() =>
                {
                    _counter++;
                    if (_counter % 10 == 0)
                    {
                        MapView.Active.LookAtAsync(ActiveMapView.ClientToMap(e.ClientPoint), new TimeSpan(0, 0, 0, 0, 15));
                        _counter = 0;
                    }
                });
            }

            e.Handled = true;
        }
Пример #4
0
        protected override void OnToolMouseMove(MapViewMouseEventArgs e)
        {
            if (_selectedRaster == null)
            {
                return;
            }
            // bIsMouseMoveActive is preventing the creation of too many threads  via QueuedTask.Run
            // especially if imagery is via a remote service
            if (bIsMouseMoveActive)
            {
                return;
            }
            bIsMouseMoveActive = true;
            System.Diagnostics.Debug.WriteLine($@"{DateTime.Now} OnToolMouseMove");
            QueuedTask.Run(() =>
            {
                try
                {
                    // create a pixelblock representing a 3x3 window to hold the raster values
                    var pixelBlock = _selectedRaster.CreatePixelBlock(3, 3);

                    // determine the cursor position in mapping coordinates
                    var clientCoords = new System.Windows.Point(e.ClientPoint.X, e.ClientPoint.Y);
                    if (clientCoords == null || ActiveMapView == null)
                    {
                        return;
                    }
                    var mapPointAtCursor = ActiveMapView.ClientToMap(clientCoords);
                    if (mapPointAtCursor == null)
                    {
                        return;
                    }

                    // create a container to hold the pixel values
                    Array pixelArray = new object[pixelBlock.GetWidth(), pixelBlock.GetHeight()];

                    // reproject the raster envelope to match the map spatial reference
                    var rasterEnvelope = GeometryEngine.Instance.Project(_selectedRaster.GetExtent(), mapPointAtCursor.SpatialReference);

                    // if the cursor is within the extent of the raster
                    if (GeometryEngine.Instance.Contains(rasterEnvelope, mapPointAtCursor))
                    {
                        // find the map location expressed in row,column of the raster
                        var pixelLocationAtRaster = _selectedRaster.MapToPixel(mapPointAtCursor.X, mapPointAtCursor.Y);

                        // fill the pixelblock with the pointer location
                        _selectedRaster.Read(pixelLocationAtRaster.Item1, pixelLocationAtRaster.Item2, pixelBlock);

                        if (_bandindex != -1)
                        {
                            // retrieve the actual pixel values from the pixelblock representing the red raster band
                            pixelArray = pixelBlock.GetPixelData(_bandindex, false);
                        }
                    }
                    else
                    {
                        // fill the container with 0s
                        Array.Clear(pixelArray, 0, pixelArray.Length);
                    }

                    // pass the pass the raster values to the view model
                    RasterValuesPaneViewModel.Current.RasterValues = ConvertArray(pixelArray);
                }
                finally
                {
                    bIsMouseMoveActive = false;
                }
            });
        }