ThinkGeo.com    |     Documentation    |     Premium Support

Version 4.xx Scale still changes?

I need some insight as how to handle this. If I dynamically set the scale and new width and height of the control like this.


CurrentScale = NewScale;

winformsMap1.Height = NewHeight; 

winformsMap1.Width = NewWidth; 

 After this executes the current scale is set to some fractional number and a folders are created using the new CurrentScale.


I check it and set it back to NewScale but the component has already created about 1/2 dozen new png's in the Cache folder impacting performance. The folders always show up with a fractional value like 32159.7732587224


How do I stop this from happening? 

I have tried to set winformsMap1.ZoomLevelSnapping =  to any of these. Default SnapUp and NONE ZoomLevelSnappingMode.Default;

 


And I set  winformsMap1.MapResizeMode = MapResizeMode.PreserveScale; 


Help..  I am currently using the latest Version 4.0. 


Just from my point of view the size of the control should not be tied to the scale of the image. The size of the control is effectively a clipping region for painting the image and should not effect the scale. Am I missing something here? Thanks and if this is still in process please let me know so I can tell my boss.



Bob,


Thanks for pointing this out again.


I think this problem is expected to have been fixed in this release, and I double checked again and found it works fine this morning. Attachment is a sample which you could have tries after changing the data path. You could notice this by dragging the sample to resize it.


May following explanations can give you some hints for I think your problem is a bit special. In the MapControl, the CurrentScale is caculated according to the current extent dynamically, so every time you change the scale, it will re-calculate the scale again when it is needed. So, do not try to set the current scale directly , try the following logic to set a correct extent, hope this will fix your problem.



currentExtent = ExtentHelper.ResizeExtent(currentExtent, previousWidth, Width, Height, mapUnit, mapResizeMode);
if (zoomLevelSnapping != ZoomLevelSnappingMode.None)
{
     currentExtent = ExtentHelper.SnapToZoomLevel(currentExtent, mapUnit, Width, Height, zoomLevelSet);
}

Any more questions just feel free to let me know.


Thanks.


Yale

 



2030-Post7461Sample.zip (10.4 KB)

Hi Yale, Still having problems. In this sample 

Height is new height and Width is new Width of the control 

I tried both ZoomLevelSnappingMode.None and ZoomLevelSnappingMode.Default


I start with the window at 1/4 screen then I stretch the window larger. I execute this code and the control did not resize. The control stayed exactly the same size. Also the example you sent ?? I am not sure how this applied.




RectangleShape rs = new RectangleShape(); 

rs = ExtentHelper.ResizeExtent(winformsMap1.CurrentExtent, (float)winformsMap1.Width, (float)Width, (float)Height, winformsMap1.MapUnit, winformsMap1.MapResizeMode); 

if (winformsMap1.ZoomLevelSnapping != ZoomLevelSnappingMode.None) 



rs = ExtentHelper.SnapToZoomLevel(rs, winformsMap1.MapUnit, (float)Width, (float)Height, winformsMap1.ZoomLevelSet); 



 



Bob,


I think in MapControl itself (both in Winforms and Wpf), we have the size-changed event implemented internally for this. Could you have a try on the sample above by dragging it from a small sized map to a large one? Before trying it, please reference the 4.0.0.0 set of DLLs and then change the data folder if needed to see if this problem still exists.
 
If so, we probably need to arrange a go-to meeting or something to get on the same line with the problem:).
 
Any more questions just let me know.
 
Thanks.
 
Yale

Ok Yale.  
 I will see what I can do. I am busy with something else at the moment so there will be a delay before I can get back to you. 


Bob, OK, get your time and let me know when you are there. 
  
 Thanks. 
  
 Yale

Yale,



   Can you provide a WPF sample?  I have attached my attempt to recreate your sample in wpf and it is missing something because the control will not grow to fill the window.  I can add the same functionaliy Bob has to force the map control to the height and width of the control, but that is where the original issue is happening.


*Note, the application was built on a 64bit machine with desktop full edition so you will have to change paths to build.



Jake


Edit:  I added the force map control to height/width of the window in the attachment now.  If you watch the cache directory it will create new folders when you change the map size.



2045-WpfApplication1.zip (19.9 KB)

Jake,


Try following code instead; hope it is what we are seeking:

 



private void Grid_SizeChanged(object sender, SizeChangedEventArgs e)
{
    //wpfmap.Width = e.NewSize.Width;
    //wpfmap.Height = e.NewSize.Height;
    //try
    //{
    //    wpfmap.Refresh(wpfmap.Overlays);
    //}
    //catch
    //{
    //}
    wpfmap.Width = e.NewSize.Width;
    wpfmap.Height = e.NewSize.Height;

    Dispatcher.BeginInvoke(new Action(() =>
    {
         wpfmap.Refresh();
    }), DispatcherPriority.Background);
}



Any more questions just feel free to let me know.


Thanks.


Yale

 



Thanks Yale!

Welcome, Jake! 
  
 Yale