ThinkGeo.com    |     Documentation    |     Premium Support

Make GraticuleFeatureLayer show less squares in grid

Here’s what my GraticuleFeatureLayer currently looks like:

As you can see, it’s showing basically every long/lat line. What I want to have is what the example for the web version shows like so:

How can I go about doing this? Below is the relevant snippet from my code:

private void map_Loaded(object sender, RoutedEventArgs e)
{
    Map1.Focus();
    Map1.MapUnit = GeographyUnit.DecimalDegree;
    
    ShapeFileFeatureLayer worldLayer = new ShapeFileFeatureLayer(@"C:/Users/dsweaver/Downloads/Countries02.shp");
    AreaStyle areaStyle = new AreaStyle();
    areaStyle.FillSolidBrush = new GeoSolidBrush(GeoColor.FromArgb(255, 233, 232, 214));
    areaStyle.OutlinePen = new GeoPen(GeoColor.FromArgb(255, 118, 138, 69), 1);
    areaStyle.OutlinePen.DashStyle = LineDashStyle.Solid;
    worldLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = areaStyle;
    worldLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

    GraticuleFeatureLayer graticuleAdornmentLayer = new GraticuleFeatureLayer();
    graticuleAdornmentLayer.GraticuleLineStyle.OuterPen.Color = GeoColor.FromArgb(125, GeoColor.StandardColors.Navy);

    worldOverlay.Layers.Add(new BackgroundLayer(new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean)));
    worldOverlay.Layers.Add(worldLayer);
    worldOverlay.Layers.Add("graticule", graticuleAdornmentLayer);

    Map1.Overlays.Add("WorldOverlay", worldOverlay);

    Map1.Refresh();
}

Thanks!

Hi Dan,

The code as below should works for you, please modify the DrawingMarginInPixel value:

        Map1.Focus();
        Map1.MapUnit = GeographyUnit.DecimalDegree;

        ShapeFileFeatureLayer worldLayer = new ShapeFileFeatureLayer(@"C:/Users/dsweaver/Downloads/Countries02.shp");
        AreaStyle areaStyle = new AreaStyle();
        areaStyle.FillSolidBrush = new GeoSolidBrush(GeoColor.FromArgb(255, 233, 232, 214));
        areaStyle.OutlinePen = new GeoPen(GeoColor.FromArgb(255, 118, 138, 69), 1);
        areaStyle.OutlinePen.DashStyle = LineDashStyle.Solid;
        worldLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = areaStyle;
        worldLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

        GraticuleFeatureLayer graticuleAdornmentLayer = new GraticuleFeatureLayer();
        graticuleAdornmentLayer.DrawingMarginInPixel = 50;        

        graticuleAdornmentLayer.GraticuleLineStyle.OuterPen.Color = GeoColor.FromArgb(125, GeoColor.StandardColors.Navy);

        LayerOverlay worldOverlay = new LayerOverlay();
        worldOverlay.Layers.Add(new BackgroundLayer(new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean)));
        worldOverlay.Layers.Add(worldLayer);

        LayerOverlay worldOverlay2 = new LayerOverlay();
        worldOverlay2.TileType = TileType.SingleTile;
        worldOverlay2.Layers.Add("graticule", graticuleAdornmentLayer);

        Map1.Overlays.Add("WorldOverlay", worldOverlay);
        Map1.Overlays.Add("WorldOverlay2", worldOverlay2);

        Map1.Refresh();

Wish that’s helpful.

Regards,

Ethan

Works great, thanks! One quick question, how would I go about changing this to a Mercator projection? Does that depend on the shape files I’m loading in, or can I just change the graticuleadornmentlayer’s projection?

Hi Dan,

Yes you’re right, you should set the projection value for graticuleAdornmentLayer, so make it suitable the data projection from 4326, and it will shows the correct value.

Regards,

Ethan

Great, thanks again!

Hi Dan,

Any question please let us know.

Regards,

Ethan