ThinkGeo.com    |     Documentation    |     Premium Support

Flickering in zooming, drawing a background image

Hi.


I have a few questions with MapSuite Desktop 3.0


1. The map flickers when I zoom in/out using mouse wheel. It didn't happen in MapSuite 2.0. Will it be fixed?


2. I've been drawing a background image using GDI+ in BeforeImageLayerDrawing event in MapSuite 2.0. How can I do the same thing in 3.0? What I want to do is drawing a dynamic bitmap image based on the extent of the map.


Thanks.


 



Seungwoo, 
  
   In the next Desktop Edition beta we will introduce stretching on the zoom in and zoom out.  This will prevent the flashing you are mentioning.  We will also add a slight delay in using the scroll wheel so that it responds faster when you do multiple zoom in or out operations.  These steps will increase the responsiveness of these operations and I think you will like them.  The way the delay works to increase responsiveness is it allows us to not draw on every click.  What I mean by this is that it is often the case the users will zoom in and then quickly zoom in again.  Our strategy is to once they zoom in we stretch the bitmap and then we wait a small amount of time to see if they zoom in or out again.  After they do not then we do the drawing.  The delay is very slight but makes a big difference.   
  
 The new release will happen sometime next week.  I suggest you subscribe to the Events forum on our site, as well as the other 3.x forums so you will know when this is released and can try it out. 
  
   In regards to the drawing of an image on the map we have a new and better mechanism for this.  In the 2.x product there was no real inheritance model so people were forced to do extra drawing in events between layers.  In the 3.x Map Suite framework we have implemented a nice object inheritance hierarchy so that these kind of drawing can be encapsulated into a Layer.  In this way it is a Layer like everything else and you have more flexibility on how you can use it.  You could still do the old method with the Canvas but I highly suggest you create your own layer type.  I will work up a small sample on just how to do this and post it hopefully later today.  I think you will find it nice and that it fits better into the overall system. 
  
 David

Seungwoo,


  Here is the sample of a custom layer.  I hope you find it useful.  You can create this Layer just like any other in the system and use it.  If you still want to draw on the event just catch the LayerDrawing or LayerDrawn and then use the Canvas parameter on the event arguments to draw using the method like in the sample.  You will see we use the Canvas and there are four methods to draw an image onto it.  I highly suggest you go with the custom Layer route though.


David


 





    public class CustomLayer : Layer
    {
        protected override void DrawCore(GeoCanvas canvas, Collection<SimpleCandidate> labelsInAllLayers)
        {
            double scale = ExtentHelper.GetScale(canvas.CurrentWorldExtent, canvas.Width, canvas.MapUnit);
            // Here you set the scales at which you want to draw.  
            // If you also know the bounding box of your data set then I
            // suggest you uncomment our the last two methods and change the 
            // sample bounidng box I provided.  If you do not know then leave them
            // commented or remove them
            if (scale >= 0 && scale <= 1000000)
            {
                Bitmap customImage = GetImage(canvas.CurrentWorldExtent.UpperLeftPoint.X, canvas.CurrentWorldExtent.UpperLeftPoint.Y, canvas.CurrentWorldExtent.LowerRightPoint.X, canvas.CurrentWorldExtent.LowerRightPoint.Y, (int)canvas.Width, (int)canvas.Height);

                // Here we draw the image you generated to the canvas.
                canvas.DrawWorldImageWithoutScaling(canvas.ToGeoImage(customImage), canvas.CurrentWorldExtent.GetCenterPoint().X, canvas.CurrentWorldExtent.GetCenterPoint().Y, DrawingLevel.LevelOne);
                customImage.Dispose();

                // You can also use any one of these kinds fo draw depending on if you
                // have world or screen coordinates and if you need scaling or
                // not.
                //canvas.DrawScreenImage();
                //canvas.DrawScreenImageWithoutScaling();
                //canvas.DrawWorldImage();
                //canvas.DrawWorldImageWithoutScaling();                
            }
        }

        private Bitmap GetImage(double upperLeftX, double upperLeftY, double lowerRightX, double lowerRightY, int screenWidth, int screenHeight)
        {
            // In here you would get your image and return it.
            // I am just returning an image with some text so you can verify it works..

            Bitmap customImage = new Bitmap(screenWidth, screenHeight);
            Graphics g = Graphics.FromImage(customImage);
            g.DrawString("SimpleCustomLayer Test", new Font("Arial", 20, FontStyle.Bold), Brushes.Black, new PointF(screenWidth / 2, screenHeight / 2));
            g.Dispose();

            return customImage;
        }

        //// If you know the bounding box then you need
        //// set this to true as I have.  If you do not know
        //// then leave all of this commented out.
        //public override bool HasBoundingBox
        //{
        //    get
        //    {
        //        return true;
        //    }
        //}

        //// Here is where you would return what the extent of you data is 
        //// in whatever coordinate system it is.  I entered som decimal degree
        //// numbers but that is just a sample.
        //protected override RectangleShape GetBoundingBoxCore()
        //{
        //    return new RectangleShape(-180.0, 83.0, 180.0, -90.0);           
        //}
    }




 "we will introduce stretching on the zoom in and zoom out" 
 - i like… thanks 
  
 "we will also add a slight delay in using the scroll wheel" 
 - i also like… thanks again

Brendan, 
  
   Yea we are making the threading an option now and by default using a single thread.  Once we resolve our thread safety issues we will have this available as as default.  Now we are focusing in on allot of the little tricks to make the system more responsive for common scenarios.  There are quite a few optimization that are simple and small but make a big impact on perceived speed and responsiveness.  I think in the next few weeks you will see allot of enhancements on this front.   
  
   At the same time we are reviewing the object model to make it as thread safe as possible.  We are concerned that this will incur some performance loss though.  We are focusing in on making as many things lock in a non locking way, ie interlocks, double check sets, spin locks etc.  It’s a big task as there isn’t a one size fits all locking strategy.  These seems to be a lack of real concrete guidance from  Microsoft on this front and it seems that its a dark science indeed.  There is allot of work form MS on in the parallel extension however it is only in beta now and it wont be integrated into the .net framework until 4.0.  More information than you needed I am sure but wanted to let you know. 
  
   I am still very keep on gleaning some insight from you one your WPF experience.  I think there are some good opportunities to beef this part up.  When would be a good time for you next week?  We are in a fairly overlapping timezone so that should be good. 
  
 David

Threading is a very tricky task. We are using it in our custom feature source and it’s giving us serious gains. It’s not without it’s troubles though and is a tricky thing to implement. The parallel extensions are very useful. We are using them in a few of our in-house apps (we obviously cannot release beta code, so they’ll have to stay out of production for now).  
  
 Next week is good for us. We are quite used to conference calls to the states and time zones don’t bother us. Perhaps wed / thurs. Let’s discuss via email. If you pop me an email, we can set up a time. That will give Ian and I a chance to get our notes together.

Just letting you know that so far the new version is behaving itself, and the new features (zoom stretching / mouse delay / and the zoom to mouse position) are making a huge difference. Good Job. 


Brendan, 
  
   Excellent!  There is a little double edge sword to the mouse wheel and double click delay.  If you use them they can really cut down on drawing time while zooming in multiple times however there is a wait after you are finally done when we are waiting to see if you are really done.  This sucks because there isn’t much way around it.  We set the time for 1 second however I think we can trim this down a bit.  It’s hard to say how fast people double click between stretches.  I think we might expose these delays as well through the API, not sure yet though. 
  
 Also let’s set a call up doe Thursday?  Can you e-mail support with your ontact details and I will forward you my e-mail.  We can setup a time. 
  
 David