ThinkGeo.com    |     Documentation    |     Premium Support

ZoomLevel not working as expected

Greetings. I have an issue with ZoomLevel not working correctly. If I set my ZoomLevel as follows, it works:

landLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;




I can zoom in as far as I want, and zoom out as far as I want. BUT, if I change the ZoomLevel01 to something like ZoomLevel02, it only shows the layer when completely zoomed out: 

landLayer.ZoomLevelSet.ZoomLevel02.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;


Any ideas? 


Thanks in advance. 


Charley. 

 



Charley, 
  
 I doubt you set the wrong unit for the MapControl. Could you double check that? 
  
 Any more questions just feel free to let  me know. 
  
 Thanks. 
  
 Yale 


I have it set for Meters: 
 map.MapUnit = GeographyUnit.Meter; 
  
 If I change it to DecimalDegrees, the map does not display. 
 If I change it to feet, same issue with the zoom level. 
  
 It is odd.

Charley, 
  
   Can you check the version of the Desktop Edition you are on and if you are on Winfroms or WPF.  The easiest way to check the version is to call the Map.GetVersion, or some method like that. 
  
 Can you also give us an idea of the coordinates of your bounding box when you no longer see it etc.  It sounds like the scale is not getting calculated correctly for some reason.  Do you have anything in the ZoomLevelSet.CustomZoomLevels collection? 
  
 David

David: 
  
 I’m using version: 
 ThinkGeo.MapSuite.DesktopEdition.WinformsMap.GetVersion() 
 “MapSuiteCore:3.1.246;DesktopEdition:3.0.426” 
  
 I found out the issue, which is a bit odd… 
 This code works: 
 landLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Country1; 
 landLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; 
  
 This code does not: 
 landLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Country1; 
 landLayer.ZoomLevelSet.ZoomLevel05.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; 
  
 You must set the DefaultAreaStyle at the same level as the ZoomLevelSet… 
 So the solution is: 
 landLayer.ZoomLevelSet.ZoomLevel05.DefaultAreaStyle = AreaStyles.Country1; 
 landLayer.ZoomLevelSet.ZoomLevel05.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; 
  
 Thanks for the help. 
 Charley.

Charley, 
  
   You are correct, they work in ranges.   
  
 The code shoulld really be  
  
 ZoomLevel1 … Set the style 
 ZoomLevel1.ApplyUntil ZoomLevel5 
  
 ZoomLevel5 … Set the style 
 ZoomLevel5.ApplyUntil ZoomLevel20 
  
 In this way zoom level one spans to zoom level 5 and zoom level 5 spans to zoom level 20. 
  
 David

So, how to I set the first zoom level by code?  The zoom levels seem to work opposite of what they were in 2.0. 
  
 In my case, I need to be able to add a layer, and say something like: 
  
 layer.ZoomLevelSet.ApplyFromZoomLevel = Level05;  // Can’t programatically set the upper range 
 layer.ZoomLevelSet.ApplyToZoomLevel = Level20; 
  
 How would I go about this?   
  
 For my application, the “ApplyToZoomLevel” will always be 20 (the lowest level).  The variable will be when to show items as they zoom in. 
  
 Thanks for your help. 
 Charley. 


 


Charley,
 
Does your code work after you try to David’s suggestion? 
 
The zoom levels work the opposite way between 2.0 and 3.0, so what do you mean first zoom level? Is it zoomlevel01 or zoomlevel20, whatever it is, you can set the style for following code:
landLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Country1; 

landLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
or
landLayer.ZoomLevelSet.ZoomLevel20.DefaultAreaStyle = AreaStyles.Country1; 

landLayer.ZoomLevelSet.ZoomLevel20.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
 
And in your case, you want to use country1 style from zoom level 5 to 20, right? So you code will be:
landLayer.ZoomLevelSet.ZoomLevel05.DefaultAreaStyle = AreaStyles.Country1; 

landLayer.ZoomLevelSet.ZoomLevel05.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
 
Your description is not clear, I don’t know what exactly you want. But I can tell how to use zoomLevelSet, for example, you want set style1 from zoom level x to zoom level y
landLayer.ZoomLevelSet.ZoomLevel x.DefaultAreaStyle = style1; 

landLayer.ZoomLevelSet.ZoomLevel x.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level y;
 
Please let me know if you have more questions.
 
Thanks
James

 



James. 
  
 Yes, if I set the layers to go from, say, ZoomLevel05 to ZoomLevel20, it works correctly… 
  
 But, say I have a control that shows a bunch of layers, and the user can say: 
 I want to show the streets from ZoomLevel5 to ZoomLevel20. 
  
 How do I programatically set up the initial ZoomLevel?  I know you can set the ApplyUntilZoomLevel property, but it doesn’t seem that you can set the initial (ZoomLevel05) property… 
  
 The way that it is designed now, you can only programmatically set the ApplyUntilZoomLevel, or so it seems. 
  
 A work around that I can think is having a big switch statement that sets the initial zoom level accordingly, which isn’t ideal. 
  
 Thanks. 
 Charley. 


To make it more clear, this is what I’m trying to do: 
  
 // initalZoomLevel will be set by the user 
 // finalZoomLevel will be set by the user 
  
 switch (initialZoomLevel) 
 { 
     case 1: 
         layer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(style); 
         layer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = finalZoomLevel; 
         break; 
     case 2: 
         layer.ZoomLevelSet.ZoomLevel02.CustomStyles.Add(style); 
         layer.ZoomLevelSet.ZoomLevel02.ApplyUntilZoomLevel = finalZoomLevel; 
         break; 
     case 3: 
         layer.ZoomLevelSet.ZoomLevel03.CustomStyles.Add(style); 
         layer.ZoomLevelSet.ZoomLevel03.ApplyUntilZoomLevel = finalZoomLevel; 
         break; 
     case 4: 
         layer.ZoomLevelSet.ZoomLevel04.CustomStyles.Add(style); 
         layer.ZoomLevelSet.ZoomLevel04.ApplyUntilZoomLevel = finalZoomLevel; 
         break; 
     case 5: 
         layer.ZoomLevelSet.ZoomLevel05.CustomStyles.Add(style); 
         layer.ZoomLevelSet.ZoomLevel05.ApplyUntilZoomLevel = finalZoomLevel; 
         break; 
     default: 
         break; 
 } 


Charley,


 
I got your mean, your sample code is very helpful to lead me what you want. I just say you are a smart guy, because you want do so amazing things, I think a tricky way to fix your problem.
 
First, you need to know one thing, ApplyUntilZoomLevel is not a necessary property need set, it’s just a short-path which can make code less, but it’s not flexible like you see. So you can set style for every zoom level instead. Normal code from our HowDoI samples set style from zoomlevel from 05 to 07 is like this:
layer.ZoomLevelSet.ZoomLevel05.DefaultAreaStyle = AreaStyles.Country1;
layer.ZoomLevelSet.ZoomLevel05.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level07;

 
You also can use this code as well:
layer.ZoomLevelSet.ZoomLevel05.DefaultAreaStyle = AreaStyles.Country1;
layer.ZoomLevelSet.ZoomLevel06.DefaultAreaStyle = AreaStyles.Country1;
layer.ZoomLevelSet.ZoomLevel07.DefaultAreaStyle = AreaStyles.Country1;

 
 
If you know this, you can use customZoomLevels which is a collection, you can pass in the initialZoomLevel and finalZoomLevel set style to corresponding zoomlevels
private void SetZoomLevelStyle(FeatureLayer layer, int initialZoomLevel, int finalZoomLevel, Style style)
{
    Collection<ZoomLevel> zoomLevels = layer.ZoomLevelSet.GetZoomLevels();
layer.ZoomLevelSet.CustomZoomLevels.Clear();
    foreach (ZoomLevel item in zoomLevels)
    {
        layer.ZoomLevelSet.CustomZoomLevels.Add(item);
    }

    for (int i = initialZoomLevel; i <= finalZoomLevel; i++)
    {
        layer.ZoomLevelSet.CustomZoomLevels<i>.CustomStyles.Add(style);
    }    
}

 
Please let me know if you have more questions.
 
Thanks
James  
 

 



Thanks James; that works. 
  
 For those that might use this code, the for loop needs to be changed as indicated below: 
  
 for (int i = initialZoomLevel; i < finalZoomLevel; i++) 
 { 
     layer.ZoomLevelSet.CustomZoomLevels[i - 1].CustomStyles.Add(style); 
 } 
  
 Thanks again! 
 Charley.

Charley, 
  
 I am very happy that solve your problem! 
  
 Please let me know if you have more questions. 
  
 James