ThinkGeo.com    |     Documentation    |     Premium Support

Bug with Proj4Projection and ZoomLevels?

This may have been reported previously so please forgive me if it has.


I have a set of shapefiles that need to be projected into a different projection.  Additionally, I need to show some of the layers after a certain zoom level.  I am having issues with showing the layers if they are set to a zoom level other than 1.  The layers starting with a zoom level of 1 work just fine.  I've put together a simple example of the problem I am having using the "Use a different projection for a vector layer" sample provided.  I've made just a couple of minor alterations to it.  The first is I added the PanZoomBar to the map.  And secondly, I changed the ZoomLevelSet from ZoomLevel01 to ZoomLevel02.  By doing so, no layer appears.




protected void Page_Load(object sender, EventArgs e)
 { 
if (!Page.IsPostBack) 

Map1.BackgroundFillBrush = new GeoSolidBrush(GeoColor.FromHtml("#B3C6D4")); 
Map1.MapUnit = GeographyUnit.DecimalDegree; 

// The following two lines of code enable the client and server caching. 
// If you enable these features it will greatly increase the scalability of your 
// mapping application however there some side effects that may be counter intuitive. 

// Please read the white paper on web caching or the documentation regarding these methods.
// Map1.ClientCache.CacheId = "WorldLayer"; 
// Map1.ServerCache.CacheDirectory = MapPath("~/ImageCache/" + Request.Path); 
Map1.IsSingleTile = true; 
Map1.PanZoomBar.Enabled = true; 

// If want to know more srids, please refer Projections.rtf in Documentation folder. 
Proj4Projection proj4Projection = new Proj4Projection(4326, 2163); 
ShapeFileLayer worldLayer = new ShapeFileLayer(MapPath("~/SampleData/world/cntry02.shp")); 
worldLayer.ZoomLevelSet.ZoomLevel02.DefaultAreaStyle = AreaStyles.GetSimpleAreaStyle(GeoColor.FromArgb(255, 243, 239, 228), GeoColor.FromArgb(255, 218, 193, 163), 1); 
worldLayer.ZoomLevelSet.ZoomLevel02.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; 
worldLayer.FeatureSource.Projection = proj4Projection; worldLayer.Open(); 
Map1.CurrentExtent = worldLayer.GetBoundingBox(); 
worldLayer.Close(); 
Map1.StaticLayers.Add("WorldLayer", worldLayer); 





 


 Thanks,


Binu



99-differentprojection.txt (1.02 KB)

Binu, 
  
 Seems your Map unit is not right. Set it to Meter and have another try. 
  
 Ben

That fixed the problem.  However, for what it is worth, that particular sample app does have the map unit in decimal degree.  Why would it work at zoom level 1 but not zoom level 2? 
  
 Thank you once again :-) 
  
 Binu

Binu, 
  
 Although the original data is in Decimal Degree, after you converted to another projection, the data for displaying is not in DecimalDegree any more. If we insist to set the unit to DecimalDegree, ZoomLevel2 will still work, but you should zoom in to an unmeaningful small extent.  
  
 Let’s say I have a world cities map in decimal degree, and every city in that map is composed of a longitude and latitude. Later, I converted the map to another projection, let’s say Mercator, now every city is composed of Easting / Nothing, which usually is a big value, like 100000 or something. Now if we still tell the control this map is in DecimalDegree, it will use the logic under DecimalDegree to decide which zoomlevel it fits. For example, if the width of the map is more than 180 degrees, it’s ZoomLevel1, if the width is between 150 and 180 degrees, it’s ZoomLevel2. Now after projection, we passed in a map with the width of maybe 1000000 degrees, so of course it’s in ZoomLevel1, and will never change until you zoom in very far to a quite small area where the map width is within the range of ZoomLevel2.   
  
 If we set it to meter which is the unit of Mercator, the control will use another logic to decide which zoomlevel now it fits. That will solve the problem.  
  
 Ben.