ThinkGeo.com    |     Documentation    |     Premium Support

Graticule layer unreadable with small window

I’m creating a graticule feature layer like so:

var graticuleAdornmentLayer = new GraticuleFeatureLayer
           {
               DrawingMarginInPixel = 10
           };
graticuleAdornmentLayer.GraticuleLineStyle.OuterPen.Color = GeoColor.FromArgb(125, GeoColor.StandardColors.Navy);
graticuleAdornmentLayer.Name = GlobalVars.GridLayer;
gridOverlay.Layers.Add(GlobalVars.GridLayer, graticuleAdornmentLayer);
gridOverlay.TileType = TileType.SingleTile;
graticuleAdornmentLayer.WrappingExtent = worldOverlay.GetBoundingBox();
graticuleAdornmentLayer.WrappingMode = WrappingMode.WrapDateline;
gridOverlay.WrappingExtent = worldOverlay.GetBoundingBox(); //overlay containing the grid layer
gridOverlay.WrappingMode = WrappingMode.WrapDateline;

This works fine. However I noticed that at certain zoom levels when the window is smaller, all the lat/long values get scrunched up.

Here’s two pics of what I’m seeing:

If I expand the window, I have no problem at any zoom level seeing the grid lines. Is there a way to fix this?

Hi Dan,

I watched that also, but it looks it’s not easy to find a solution for this behavior.

Because when you resize the form to smaller, the lines have to be drawn densely, or else maybe you can only view one line in current extent. And when you zoom into deeper, the line text is wider than higher level, so when the lines are drawn densely, some part of the text get covered.

I think if you want to avoid it, you can hide GraticuleFeatureLayer when the form get smaller sized than a default value, or you can reset the GraticuleTextFont to solve it.

Wish that’s helpful.

Regards,

Ethan

Hi Ethan, what do you mean by reset the GraticuleTextFont?

Hi Dan,

I means if you set a smaller or thinner font, this problem can be solved partly.

Regards,

Ethan

Hi Ethan,

Is there a way to limit the amount of lines shown at small zoom levels? Or only show lines at whole numbers instead of decimal places?

I made a .gif of what I’m trying to achieve (from a different map product). You can see as the user zooms in closer, it’ll only show ~1 lat/lon grid line.

The .gif can be seen here: https://drive.google.com/open?id=1O7KbBj-FGRWPGWAeQM7P5-oPMMfToGNI

Hi Dan,

We don’t have special API for that, but I think you can try to override the DrawCore of GraticuleFeatureLayer.

Here is the simple logic for draw them, you can modify it follow your requirement:

  protected override void DrawCore(GeoCanvas canvas, Collection<SimpleCandidate> labelsInAllLayers)
{
    GraticuleFeatureSource graticuleFeatureSource = this.FeatureSource as GraticuleFeatureSource;

    Collection<Feature> features = graticuleFeatureSource.GetFeaturesForDrawing(canvas.CurrentWorldExtent, canvas.Width, canvas.Height, ReturningColumnsType.AllColumns);

    GraticuleLineStyle.Draw(features, canvas, new Collection<SimpleCandidate>(), new Collection<SimpleCandidate>());
    foreach (Feature item in features)
    {
        string text = item.ColumnValues["GraticuleLabel"];
        RectangleShape extent = item.GetBoundingBox();
        PointShape upperLeftPoint = extent.UpperLeftPoint;
        PointShape lowerRightPoint = extent.LowerRightPoint;
        ScreenPointF upperLeftScreenPointF = ExtentHelper.ToScreenCoordinate(canvas.CurrentWorldExtent, upperLeftPoint.X, upperLeftPoint.Y, canvas.Width, canvas.Height);
        ScreenPointF lowerRightScreenPointF = ExtentHelper.ToScreenCoordinate(canvas.CurrentWorldExtent, lowerRightPoint.X, lowerRightPoint.Y, canvas.Width, canvas.Height);

        if (upperLeftScreenPointF.Y < 0) upperLeftScreenPointF = new ScreenPointF(upperLeftScreenPointF.X, 0);
        if (upperLeftScreenPointF.X < 0) upperLeftScreenPointF = new ScreenPointF(0, upperLeftScreenPointF.Y);

        if (Math.Abs(upperLeftScreenPointF.Y - lowerRightScreenPointF.Y) < 1)
        {
            canvas.DrawText(text, GraticuleTextFont, GraticuleTextBrush, GraticuleTextHaloPen, new[] { upperLeftScreenPointF }, DrawingLevel.LevelFour, 8, 0, 90, DrawingTextAlignment.Default);
        }
        else
        {
            canvas.DrawText(text, GraticuleTextFont, GraticuleTextBrush, GraticuleTextHaloPen, new[] { upperLeftScreenPointF }, DrawingLevel.LevelFour, 8, 8, 0, DrawingTextAlignment.Default);
        }
    }
}

Regards,

Ethan