Search Results for

    Show / Hide Table of Contents

    Class ScaleBarWidget

    A ScaleBarWidget displays the ratio of a distance on the map to the corresponding distance on the ground. It uses always the center of a given Viewport to calc this ratio.

    Usage To show a ScaleBarWidget, add a instance of the ScaleBarWidget to Map.Widgets by

    map.Widgets.Add(new ScaleBarWidget(map));

    Customize ScaleBarMode: Determines, how much scalebars are shown. Could be Single or Both. SecondaryUnitConverter: First UnitConverter for upper scalebar. There are UnitConverters for metric, imperial and nautical units. SecondaryUnitConverter = NauticalUnitConverter.Instance }); MaxWidth: Maximal width of the scalebar. Real width could be smaller. HorizontalAlignment: Where the ScaleBarWidget is shown. Could be Left, Right, Center or Position. VerticalAlignment: Where the ScaleBarWidget is shown. Could be Top, Bottom, Center or Position. PositionX: If HorizontalAlignment is Position, this value determines the distance to the left PositionY: If VerticalAlignment is Position, this value determines the distance to the top TextColor: Color for text and lines Halo: Color used around text and lines, so the scalebar is better visible TextAlignment: Alignment of scalebar text to the lines. Could be Left, Right or Center TextMargin: Space between text and lines of scalebar Font: Font which is used to draw text TickLength: Length of the ticks at scalebar

    Inheritance
    object
    BaseWidget
    ScaleBarWidget
    Implements
    IWidget
    Inherited Members
    BaseWidget.InputAreaType
    BaseWidget.HorizontalAlignment
    BaseWidget.VerticalAlignment
    BaseWidget.Margin
    BaseWidget.Position
    BaseWidget.Width
    BaseWidget.Height
    BaseWidget.Envelope
    BaseWidget.Enabled
    BaseWidget.InputTransparent
    BaseWidget.WithTappedEvent
    BaseWidget.WithPointerPressedEvent
    BaseWidget.WithPointerMovedEvent
    BaseWidget.WithPointerReleased
    BaseWidget.Tapped
    BaseWidget.PointerPressed
    BaseWidget.PointerMoved
    BaseWidget.PointerReleased
    BaseWidget.UpdateEnvelope(double, double, double, double)
    BaseWidget.OnTapped(WidgetEventArgs)
    BaseWidget.OnPointerPressed(WidgetEventArgs)
    BaseWidget.OnPointerMoved(WidgetEventArgs)
    BaseWidget.OnPointerReleased(WidgetEventArgs)
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Mapsui.Widgets.ScaleBar
    Assembly: Mapsui.dll
    Syntax
    public class ScaleBarWidget : BaseWidget, IWidget

    Constructors

    | Edit this page View Source

    ScaleBarWidget(Map, IProjection?)

    Declaration
    public ScaleBarWidget(Map map, IProjection? projection = null)
    Parameters
    Type Name Description
    Map map
    IProjection projection

    Properties

    | Edit this page View Source

    Font

    Font to use for drawing text

    Declaration
    public Font? Font { get; set; }
    Property Value
    Type Description
    Font
    | Edit this page View Source

    Halo

    Halo color of scalebar and text, so that it is better visible

    Declaration
    public Color Halo { get; set; }
    Property Value
    Type Description
    Color
    | Edit this page View Source

    MaxWidth

    Maximum usable width for scalebar. The real used width could be less, because we want only integers as text.

    Declaration
    public double MaxWidth { get; set; }
    Property Value
    Type Description
    double
    | Edit this page View Source

    Scale

    Declaration
    public double Scale { get; }
    Property Value
    Type Description
    double
    | Edit this page View Source

    ScaleBarMode

    ScaleBarMode of scalebar. Could be Single to show only one or Both for showing two units.

    Declaration
    public ScaleBarMode ScaleBarMode { get; set; }
    Property Value
    Type Description
    ScaleBarMode
    | Edit this page View Source

    SecondaryUnitConverter

    Secondary unit converter for lower text if ScaleBarMode is Both. Default is ImperialUnitConverter.

    Declaration
    public IUnitConverter? SecondaryUnitConverter { get; set; }
    Property Value
    Type Description
    IUnitConverter
    | Edit this page View Source

    ShowEnvelop

    Draw a rectangle around the scale bar for testing

    Declaration
    public bool ShowEnvelop { get; set; }
    Property Value
    Type Description
    bool
    | Edit this page View Source

    StrokeWidth

    Stroke width for lines

    Declaration
    public double StrokeWidth { get; set; }
    Property Value
    Type Description
    double
    | Edit this page View Source

    StrokeWidthHalo

    Stroke width for halo of lines

    Declaration
    public double StrokeWidthHalo { get; set; }
    Property Value
    Type Description
    double
    | Edit this page View Source

    TextAlignment

    Alignment of text of scalebar

    Declaration
    public Alignment TextAlignment { get; set; }
    Property Value
    Type Description
    Alignment
    | Edit this page View Source

    TextColor

    Foreground color of scalebar and text

    Declaration
    public Color TextColor { get; set; }
    Property Value
    Type Description
    Color
    | Edit this page View Source

    TextMargin

    Margin between end of tick and text

    Declaration
    public static double TextMargin { get; }
    Property Value
    Type Description
    double
    | Edit this page View Source

    TickLength

    Length of the ticks

    Declaration
    public double TickLength { get; set; }
    Property Value
    Type Description
    double
    | Edit this page View Source

    UnitConverter

    Normal unit converter for upper text. Default is MetricUnitConverter.

    Declaration
    public IUnitConverter UnitConverter { get; set; }
    Property Value
    Type Description
    IUnitConverter

    Methods

    | Edit this page View Source

    CanProject()

    Declaration
    public bool CanProject()
    Returns
    Type Description
    bool
    | Edit this page View Source

    GetScaleBarLengthAndText(Viewport)

    Calculates the length and text for both scalebars

    Declaration
    public (double scaleBarLength1, string? scaleBarText1, double scaleBarLength2, string? scaleBarText2) GetScaleBarLengthAndText(Viewport viewport)
    Parameters
    Type Name Description
    Viewport viewport
    Returns
    Type Description
    (double scaleBarLength1, string scaleBarText1, double scaleBarLength2, string scaleBarText2)

    Length of upper scalebar Text of upper scalebar Length of lower scalebar Text of lower scalebar

    | Edit this page View Source

    GetScaleBarLinePositions(Viewport, double, double, double)

    Get pairs of points, which determine start and stop of the lines used to draw the scalebar

    Declaration
    public IReadOnlyList<MPoint> GetScaleBarLinePositions(Viewport viewport, double scaleBarLength1, double scaleBarLength2, double stroke)
    Parameters
    Type Name Description
    Viewport viewport

    The viewport of the map

    double scaleBarLength1

    Length of upper scalebar

    double scaleBarLength2

    Length of lower scalebar

    double stroke

    Width of line

    Returns
    Type Description
    IReadOnlyList<MPoint>

    Array with pairs of Points. First is always the start point, the second is the end point.

    | Edit this page View Source

    GetScaleBarTextPositions(Viewport, MRect, MRect, double)

    Calculates the top-left-position of upper and lower text

    Declaration
    public (double posX1, double posY1, double posX2, double posY2) GetScaleBarTextPositions(Viewport viewport, MRect textSize1, MRect textSize2, double stroke)
    Parameters
    Type Name Description
    Viewport viewport

    The viewport

    MRect textSize1

    Size of upper text of scalebar

    MRect textSize2

    Size of lower text of scalebar

    double stroke

    Width of line

    Returns
    Type Description
    (double posX1, double posY1, double posX2, double posY2)

    posX1 as left position of upper scalebar text posY1 as top position of upper scalebar text posX2 as left position of lower scalebar text posY2 as top position of lower scalebar text

    Implements

    IWidget

    Extension Methods

    DisposableExtension.DisposeIfDisposable(object?)
    • Edit this page
    • View Source
    In this article
    Back to top Generated by DocFX