ThinkGeo.com    |     Documentation    |     Premium Support

Using GoogleMapZoomLevelSet for drawing certain layer

 Hi guys,


I was  wondering how do I use the GoogleMapZoomLevelSet to add a layer on google maps depending on a zoom level which can be configured. The problem that I am trying to solve is I am trying to draw zip boundaries after a certain zoom level. My approach to the prob was as follows:


 


 


 private BaseLayer AddZipLayer()


        {


            var zipLayer = new AreaLayer("ZipLayer", ConfigurationManager.AppSettings[ConstZipCodeShapeFile);


            var outlinePen = new GeoPen(GeoColor.StandardColors.HotPink);


            var fillBrush = new GeoSolidBrush(GeoColor.StandardColors.Transparent);


            var minZoomLevelZip = ConfigurationManager.AppSetting[ShowZipBoundary]; 


            var googleMapZoomLevelSet = new GoogleMapZoomLevelSet();


            var zoomLevelToApplyStyleAt= googleMapZoomLevelSet.GetZoomLevelAtIndex(minZoomLevelZip);


            zoomLevelToApplyStyleAt.DefaultAreaStyle = new AreaStyle(outlinePen, fillBrush);


            zoomLevelToApplyStyleAt.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;


            zipLayer.FeatureLayer.ZoomLevelSet = googleMapZoomLevelSet;


            return zipLayer;


        }


Am I doing something wrong here?


 



Hi Anil,


I used web edition V4.5 and the following code to add layer on google maps, it worked.


protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        Map1.MapBackground.BackgroundBrush = new GeoSolidBrush(GeoColor.FromHtml("#E5E3DF"));
        Map1.CurrentExtent = new RectangleShape(-13939426.6371, 6701997.4056, -7812401.86, 2626987.386962);
        Map1.MapUnit = GeographyUnit.Meter;
        Map1.MapTools.OverlaySwitcher.Enabled = true;
        Map1.MapTools.MouseCoordinate.Enabled = true;

        GoogleOverlay google = new GoogleOverlay("Google Map");
        google.JavaScriptLibraryUri = new Uri(ConfigurationManager.AppSettings["GoogleUri"]);
        google.GoogleMapType = GoogleMapType.Normal;
        Map1.CustomOverlays.Add(google);

        LayerOverlay staticOverlay = new LayerOverlay();
        staticOverlay.IsBaseOverlay = false;
        Layer layer = AddZipLayer();
        staticOverlay.Layers.Add(layer);
        Map1.CustomOverlays.Add(staticOverlay);
    }
}

private Layer AddZipLayer()
{
    var zipLayer = new ShapeFileFeatureLayer(MapPath("~/SampleData/world/cntry02.shp"));
    ManagedProj4Projection projection = new ManagedProj4Projection(ManagedProj4Projection.GetEpsgParametersString(4326), ManagedProj4Projection.GetGoogleMapParametersString());
    zipLayer.FeatureSource.Projection = projection;

    var outlinePen = new GeoPen(GeoColor.StandardColors.HotPink);
    var fillBrush = new GeoSolidBrush(GeoColor.StandardColors.Transparent);
    var googleMapZoomLevelSet = new GoogleMapZoomLevelSet();
    var zoomLevelToApplyStyleAt = googleMapZoomLevelSet.GetZoomLevels()[2];
    zoomLevelToApplyStyleAt.DefaultAreaStyle = new AreaStyle(outlinePen, fillBrush);
    zoomLevelToApplyStyleAt.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
    zipLayer.ZoomLevelSet = googleMapZoomLevelSet;
    Map1.SyncClientZoomLevels(googleMapZoomLevelSet);

    return zipLayer;
}


The output image is below:



When we add a layer to the map, we should check the projection of the source file ("cntry02.shp" in my code snippet).


Please let us know if you have further questions.


Regards,


Ivan