ThinkGeo.com    |     Documentation    |     Premium Support

Define default value for ZoomLeveSet

Hi,


I saw in the samples that when you loading a shapefilelayer, or any other type of layer, you set the ZoomLevelSet like this:


ShapeFileFeatureLayer worldLayer = new ShapeFileFeatureLayer(SampleFolder + "Countries02.shp");
worldLayer.Name = "Countries02";
worldLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Country1;
worldLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

ShapeFileFeatureLayer statesLayer = new ShapeFileFeatureLayer(SampleFolder + "USStates.shp");
statesLayer.Name = "USStates";
statesLayer.ZoomLevelSet.ZoomLevel04.DefaultAreaStyle = AreaStyles.State1;
statesLayer.ZoomLevelSet.ZoomLevel04.DefaultAreaStyle.OutlinePen.LineJoin = DrawingLineJoin.Round;
statesLayer.ZoomLevelSet.ZoomLevel04.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;


even sometimes we set the the special column name, like:


 


shapeFileLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.SimpleColors.Transparent, GeoColor.FromArgb(100, GeoColor.SimpleColors.Green));
shapeFileLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
shapeFileLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = TextStyles.CreateSimpleTextStyle("CITY_NAME", "Arial", 8, DrawingFontStyles.Italic, GeoColor.StandardColors.Black, 3, 3);
shapeFileLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.LocalRoad1;


the problem is, when the user ask to open an unknown shape file, we do not know the file type is country,county,city,... .

so, How we can set that ZoomLevelSet?


Another Issue is CurrentExtent, I have Shapefile, When I load it the control just shows me a very small part of it, and Zoomout/Zoomin do not work currectly. I used the below code to set current extend and load the shapfile:  worldLayer.Open();
wpfMap1.CurrentExtent = worldLayer.GetBoundingBox();
worldLayer.Close();




 Hi, Ben, 
  
 We should be responsible to know the description of a shape file before opening it, which means we should know if a shape file is country, county or city…, as we cannot get that information from the shape data itself.  Usually, the place you get a shape should have some description about that file.  
  
 If there is some unknown shape file and we have no idea where is from, we can drag and drop it to Map Suite Explorer, see what it looks like and check the tabular data, and guess what it is. But that not works every time. 
  
 About your 2nd question, can you try to load that file with Map Suite Explorer? If the explorer works fine, it should be something wrong with the code and please shows us your codes, if not, maybe there’s something wrong with the data and please send it to us so we can have a check. 
  
 Thanks, 
  
 Ben 


Hi, Ben 

Many thanks for your response,

About the first question, we want to write something like 'Map Suite Explorer', I mean that the user can add any type of file and we dont want to ask him about the type of file content.So I want to know what's your way to understand the shapefile or any othe file properties in the 'Map Suite Explorer’ ?

About the second question, This is my code:





string addr = @"C:\Users\Ben\Desktop\ThinkGeo\Sample Data\1\Cheshire MED2_polyline.shp";
wpfMap1.MapUnit = GeographyUnit.DecimalDegree;
wpfMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean);

ShapeFileFeatureLayer worldLayer = new ShapeFileFeatureLayer(addr);            
worldLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.LocalRoad1;
worldLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

LayerOverlay staticOverlay = new LayerOverlay();
staticOverlay.Layers.Add("WorldLayer", worldLayer);
wpfMap1.Overlays.Add(staticOverlay);

worldLayer.Open();
wpfMap1.CurrentExtent = worldLayer.GetBoundingBox();
worldLayer.Close();

wpfMap1.Refresh();



And I checked this way too:




worldLayer.Open();
Collection<Feature> allFeatures = worldLayer.QueryTools.GetAllFeatures(ReturningColumnsType.AllColumns);
worldLayer.Close();
wpfMap1.CurrentExtent = ExtentHelper.GetBoundingBoxOfItems(allFeatures);


 


 


I tried it on many different shape file and all of them except your shapefile samples (Sample Data Folder) have the problem (it just show a small part file and I can just zoom in more) but becuse of the attache limitation, I could not upload a sample for you.


Regards,

Ben

 



Ben, 
  
 1, Our “Map Suite Explorer” has no idea about whether the input shape file is a country or a county, whether it is for roads or for railway, we can only tell the input data is point, polyline or polygon, and draw them out accordingly.  So that’s what you want? If yes you can check the shape file specification which shows how to identify the type of a shape file. 
  
 2, I think that’s because the unit for your shape file is not in Decimal Degree, could you try to change the following line  
 wpfMap1.MapUnit = GeographyUnit.DecimalDegree; 
 to  
 wpfMap1.MapUnit = GeographyUnit.Meter; or wpfMap1.MapUnit = GeographyUnit.Feet; 
  
 as DecimalDegree has a Max Extent limit which will be a very small extent if your unit in fact is Meter or Feet. 
  
 Thanks, 
  
 Ben 


Cool, 
  
 The problem solved.

We are glad we helped you solve your problem. I let you know that in relation to setting the extent of the map based on a series of layers, we have a Code Community project, Zoom to Full Extent, that shows how to do that. You can check it out at code.thinkgeo.com/projects/show/zoomtofullextent. Thank you.