ThinkGeo.com    |     Documentation    |     Premium Support

Zoom level of Shape file in 2 maps in same page

Hello Peter,





I have two maps on a same page and I add a shape file in both of them. I want to set different zoom level of shape file in both map but both shape files set the same zoom levels which I set first, I have put both shape files in different folder but problem still exists.


Map1 = new Map("map",
         new System.Web.UI.WebControls.Unit(100, System.Web.UI.WebControls.UnitType.Percentage), 510);
            new System.Web.UI.WebControls.Unit(100, System.Web.UI.WebControls.UnitType.Percentage);
            WorldMapKitWmsWebOverlay worldMapKitOverlay = new WorldMapKitWmsWebOverlay("WorldMapKitOverlay");
            Map1.CustomOverlays.Add(worldMapKitOverlay);
            Map1.MapTools.LoadingImage.ImageUri = new Uri(Server.MapPath(@"~/ShapeFiles/loading_logofinal_by_zegerdon-d60eb1v.gif"));
            Map1.MapTools.LoadingImage.Enabled = true;
            Map1.MapTools.LoadingImage.Height = 64;
            Map1.MapTools.LoadingImage.Width = 64;
            Map1.MapTools.ScaleLine.Enabled = true;
            Map1.MapUnit = GeographyUnit.DecimalDegree;
            Map1.MapTools.MouseCoordinate.MouseCoordinateType = MouseCoordinateType.LongitudeLatitude;
            Map1.MapTools.MouseCoordinate.Enabled = true;
            Map1.Cursor = CursorType.Pointer;
            //Map1.MapBackground.BackgroundBrush = new GeoSolidBrush(GeoColor.GeographicColors.Swamp);
            ShapeFileFeatureLayer PakLayer = new ShapeFileFeatureLayer(Server.MapPath(@"~/ShapeFiles/PAK_adm0.shp"));
            PakLayer.ZoomLevelSet.ZoomLevel03.DefaultAreaStyle = AreaStyles.Country1;
            PakLayer.ZoomLevelSet.ZoomLevel03.DefaultTextStyle = TextStyles.CreateSimpleTextStyle("NAME_ENGLI""Arial", 8, DrawingFontStyles.Italic, GeoColor.StandardColors.Crimson, 3, 3);//TextStyles.Capital3("NAME_1");
            PakLayer.ZoomLevelSet.ZoomLevel03.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level04;
            ShapeFileFeatureLayer.BuildIndexFile(Server.MapPath(@"~/ShapeFiles/PAK_adm0.shp"));
LayerOverlay staticOverlay2 = new LayerOverlay("StaticOverlay2");
            staticOverlay.IsBaseOverlay = false;
            staticOverlay.Layers.Add("PakLayer2", PakLayer);
            PakLayer.Open();
            Map1.CurrentExtent = PakLayer2.GetBoundingBox();
            Map1.CustomOverlays.Add(staticOverlay2);
            PakLayer.Close();
//—Map2
 Map2 = new Map("map2",
      new System.Web.UI.WebControls.Unit(100, System.Web.UI.WebControls.UnitType.Percentage), 510);
            //new System.Web.UI.WebControls.Unit(100, System.Web.UI.WebControls.UnitType.Percentage);
            //WorldMapKitWmsWebOverlay worldMapKitOverlay = new WorldMapKitWmsWebOverlay("WorldMapKitOverlay");
            //Map2.CustomOverlays.Add(worldMapKitOverlay);
            Map2.MapTools.LoadingImage.ImageUri = new Uri(Server.MapPath(@"~/ShapeFiles2/loading_logofinal_by_zegerdon-d60eb1v.gif"));
            Map2.MapTools.LoadingImage.Enabled = true;
            Map2.MapTools.LoadingImage.Height = 64;
            Map2.MapTools.LoadingImage.Width = 64;
            Map2.MapTools.ScaleLine.Enabled = true;
            Map2.MapUnit = GeographyUnit.DecimalDegree;
            Map2.MapTools.MouseCoordinate.MouseCoordinateType = MouseCoordinateType.LongitudeLatitude;
            Map2.MapTools.MouseCoordinate.Enabled = true;
            Map2.Cursor = CursorType.Default;
            Map2.MapBackground.BackgroundBrush = new GeoSolidBrush(GeoColor.StandardColors.SlateGray);
            ShapeFileFeatureLayer PakLayer2 = new ShapeFileFeatureLayer(Server.MapPath(@"~/ShapeFiles2/PAK_adm0.shp"));
            PakLayer2.ZoomLevelSet.ZoomLevel06.DefaultAreaStyle = AreaStyles.Country1;
            PakLayer2.ZoomLevelSet.ZoomLevel06.DefaultTextStyle = TextStyles.CreateSimpleTextStyle("NAME_ENGLI""Arial", 8, DrawingFontStyles.Italic, GeoColor.StandardColors.Crimson, 3, 3);//TextStyles.Capital3("NAME_1");
            PakLayer2.ZoomLevelSet.ZoomLevel06.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
            ShapeFileFeatureLayer.BuildIndexFile(Server.MapPath(@"~/ShapeFiles2/PAK_adm0.shp"));
            LayerOverlay staticOverlay2 = new LayerOverlay("StaticOverlay2");
            staticOverlay2.IsBaseOverlay = false;
            staticOverlay2.Layers.Add("PakLayer2", PakLayer);
            PakLayer2.Open();
            Map2.CurrentExtent = PakLayer2.GetBoundingBox();
            Map2.CustomOverlays.Add(staticOverlay2);
            PakLayer2.Close();



Thank you for support.

Hi Shehraz, 



Sorry I can’t reproduce the issue and I do the following steps to render the maps. Please give it a go. 



1. Split the code you appended above into two actions like the following: 


public ActionResult Map1() 

  var map1 = new Map(“map”, new System.Web.UI.WebControls.Unit(100, System.Web.UI.WebControls.UnitType.Percentage), 510); new System.Web.UI.WebControls.Unit(100, System.Web.UI.WebControls.UnitType.Percentage);
   … 
 
  return View(map1);
 }






public ActionResult Map2() 

  var map2 = new Map(“map2”, new System.Web.UI.WebControls.Unit(100, System.Web.UI.WebControls.UnitType.Percentage), 510); new System.Web.UI.WebControls.Unit(100, System.Web.UI.WebControls.UnitType.Percentage);
   … 
 
  return View(map2); 
}





2. Use Html.RenderAction(“actionName”) to render the two actions created in the #1 step. 





Thanks, 

Peter