ThinkGeo.com    |     Documentation    |     Premium Support

Drawing on ExtentInteractiveOverlay

Greetings,


I am attempting to paint on an ExtentInteractiveOverlay with little luck.  Specifically, I'm trying to draw the coordinates of the current mouse location, however I can never get the DrawCore method to be called.  Any help would be appreciated, thanks.


 


Ryan



Ryan,


  I think this is an issue with our stuff.  I also did not get the DrawCore to fire.  I added some code to set the this.Lock.IsDirty = true; and that made it fire all the time.  I included my code that worked.  It just draws a small red circle wherever the cursor is at.


David




    public class TestInteractiveOverlay : InteractiveOverlay
    {
        ScreenPointF currentScreenPosition = new ScreenPointF();        

        protected override InteractiveResult MouseMoveCore(InteractionArguments interactionArguments)
        {
            InteractiveResult interactiveResult = new InteractiveResult();
            interactiveResult.DrawThisOverlay = InteractiveOverlayDrawType.Draw;
            interactiveResult.ProcessOtherOverlays = ProcessOtherOverlaysMode.ProcessOtherOverlays;            
            currentScreenPosition = new ScreenPointF(interactionArguments.ScreenX,interactionArguments.ScreenY);

            this.Lock.IsDirty = true;

            return interactiveResult;
        }        

        protected override void DrawCore(GeoCanvas canvas)
        {
            canvas.DrawEllipse(currentScreenPosition, 10, 10, null, new GeoSolidBrush(GeoColor.StandardColors.Red), DrawingLevel.LevelOne, 0, 0, PenBrushDrawingOrder.PenFirst);
        }
    }
 



David,


I copied your code into my application and was still not able to get the DrawCore to fire.  I also tried adding a MouseMove event listener to the map control itself at which point I would call a refresh on that overlay, but it still did not call DrawCore.  I've included a basic sample that demonstrates this on my machine.


Thanks for your help,


Ryan



1409-CoordinatesSample.zip (13.2 KB)

Ryan,


Thanks for your sample, that really help us find the problem quickly.
 
The problem is that the new InterativeOverlay did not contains any layer to be drawn, so its default value for empty is false.
 
Try this new code(with litter change in your DrawCore):

    class CoordinateOverlay : ExtentInteractiveOverlay
    {
        private double X { get; set; }
        private double Y { get; set; }

        public CoordinateOverlay()
            :base()
        {
        }

        public override bool IsEmpty
        {
            get
            {
                return false;
            }
        }

        /// <summary>
        /// Captures the mouse move events and stores the current world coordinates of the mouse
        /// </summary>
        /// <param name="interactionArguments">Information about the interaction with the map</param>
        /// <returns>Result telling the map what to do after this event occurs
        protected override InteractiveResult MouseMoveCore(InteractionArguments interactionArguments)
        {
            InteractiveResult interactiveResult = new InteractiveResult();
            interactiveResult.DrawThisOverlay = InteractiveOverlayDrawType.Draw;
            interactiveResult.ProcessOtherOverlays = ProcessOtherOverlaysMode.ProcessOtherOverlays;
            this.X = interactionArguments.ScreenX;
            this.Y = interactionArguments.ScreenY;
            return interactiveResult;
        }

        /// <summary>
        /// Draws the coordinates on the map
        /// </summary>
        /// <param name="canvas">The canvas to draw on</param>
        protected override void DrawCore(GeoCanvas canvas)
        {
            canvas.DrawTextWithScreenCoordinate("Lat: " + this.X + " Lon: " + this.Y, new GeoFont("Times New Roman", 8), new GeoSolidBrush(GeoColor.SimpleColors.Black), (float)this.X, (float)this.Y, DrawingLevel.LevelOne);
            System.Diagnostics.Debug.WriteLine("this.X" + this.X.ToString());
            System.Diagnostics.Debug.WriteLine("this.Y" + this.Y.ToString());
        }
    }

 
The test code is the same:

        void Window1_Loaded(object sender, RoutedEventArgs e)
        {
            map.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.GeographicColors.DeepOcean);
            map.InteractiveOverlays.Clear();
            map.InteractiveOverlays.Add(new CoordinateOverlay());
            //map.Refresh(map.InteractiveOverlays[0]);
            map.MouseMove += new MouseEventHandler(map_MouseMove);
        }

        void map_MouseMove(object sender, MouseEventArgs e)
        {
            map.Refresh(map.InteractiveOverlays[0]);
        }

 
Any new questions just feel free to let me know.
 
Thanks.
 
Yale

Thanks Yale, that solved my issue!

Ryan, 
  
 Thanks for letting me know status. 
  
 Thanks. 
  
 Yale