Nelson,
No problem. I think the scaling styles is a cool idea. We entered an issue into out tracking system to come out with a complete line of scaling styles. Thanks for the idea. On the VB / C# I understand. I was a VB developer from way way back and just recently converted to C#. We will try and post more VB samples in the future. For now I converted the code above with a free website, link below. I havent tried to run the code so it may not even compile but it's at least a good start.
David
Convert C# to VB.NET
developerfusion.com/tool...arp-to-vb/
Class ScalingLineStyle
Inherits Style
' A default constructor that just calls the main constructor
Public Sub New()
Me.New(GeographyUnit.Unknown, Double.MaxValue, Double.MinValue, New LineWidth(0, 0, 0), New LineWidth(0, 0, 0), GeoColor.SimpleColors.Transparent, _
GeoColor.SimpleColors.Transparent, GeoColor.SimpleColors.Transparent, 0, 0)
End Sub
' The main constructor, it allows you to set all of the options available.
Public Sub New(ByVal mapUnit As GeographyUnit, ByVal maximumScale As Double, ByVal minimumScale As Double, ByVal maximumLineWidth As LineWidth, ByVal minimumLineWidth As LineWidth, ByVal centerPenColor As GeoColor, _
ByVal innerPenColor As GeoColor, ByVal outerPenColor As GeoColor, ByVal xOffset As Single, ByVal yOffset As Single)
MyBase.New()
Me.MapUnit = mapUnit
Me.MaximumScale = maximumScale
Me.MinimumScale = minimumScale
Me.MaximumLineWidth = maximumLineWidth
Me.MinimumLineWidth = minimumLineWidth
Me.CenterPenColor = centerPenColor
Me.InnerPenColor = innerPenColor
Me.OuterPenColor = outerPenColor
Me.XOffset = xOffset
Me.YOffset = yOffset
End Sub
' This is the map unit to determine the scale.
Private _MapUnit As GeographyUnit
Public Property MapUnit() As GeographyUnit
Get
Return _MapUnit
End Get
Set(ByVal value As GeographyUnit)
_MapUnit = value
End Set
End Property
' The maximum scale will be the largest scale used to calculate the resizing.
' If the scale gets larger than the max then we compute the scaling based on
' this number instead. This is mean that after this scale the image will not get
' any smaller no matter how much more you zoom out.
Private _MaximumScale As Double
Public Property MaximumScale() As Double
Get
Return _MaximumScale
End Get
Set(ByVal value As Double)
_MaximumScale = value
End Set
End Property
' The minimum scale will be the smallest scale used to calculate the resizing.
' If the scale gets smaller than the min then we compute the scaling based on
' this number instead. This is mean that after this scale the image will not get
' any larger no matter how much more you zoom in.
Private _MinimumScale As Double
Public Property MinimumScale() As Double
Get
Return _MinimumScale
End Get
Set(ByVal value As Double)
_MinimumScale = value
End Set
End Property
' The MaximumSize is the width of the line at MinimumScale and lower.
Private _MaximumLineWidth As LineWidth
Public Property MaximumLineWidth() As LineWidth
Get
Return _MaximumLineWidth
End Get
Set(ByVal value As LineWidth)
_MaximumLineWidth = value
End Set
End Property
' The MinimumLineWidth is the size of the image at MaximumScale and higher
Private _MinimumLineWidth As LineWidth
Public Property MinimumLineWidth() As LineWidth
Get
Return _MinimumLineWidth
End Get
Set(ByVal value As LineWidth)
_MinimumLineWidth = value
End Set
End Property
' The color of the center pen for the line
Private _CenterPenColor As GeoColor
Public Property CenterPenColor() As GeoColor
Get
Return _CenterPenColor
End Get
Set(ByVal value As GeoColor)
_CenterPenColor = value
End Set
End Property
' The color of the inner pen for the line
Private _InnerPenColor As GeoColor
Public Property InnerPenColor() As GeoColor
Get
Return _InnerPenColor
End Get
Set(ByVal value As GeoColor)
_InnerPenColor = value
End Set
End Property
' The color of the outer pen for the line
Private _OuterPenColor As GeoColor
Public Property OuterPenColor() As GeoColor
Get
Return _OuterPenColor
End Get
Set(ByVal value As GeoColor)
_OuterPenColor = value
End Set
End Property
' This is the X offset in pixels for the image.
Private _XOffset As Single
Public Property XOffset() As Single
Get
Return _XOffset
End Get
Set(ByVal value As Single)
_XOffset = value
End Set
End Property
' This is the Y offset in pixels for the image.
Private _YOffset As Single
Public Property YOffset() As Single
Get
Return _YOffset
End Get
Set(ByVal value As Single)
_YOffset = value
End Set
End Property
Protected Overloads Overrides Sub DrawCore(ByVal features As IEnumerable(Of Feature), ByVal canvas As GeoCanvas, ByVal labelsInThisLayer As Collection(Of SimpleCandidate), ByVal labelsInAllLayers As Collection(Of SimpleCandidate))
' Loop through all of the features being passed in to draw.
For Each feature As Feature In features
' Let's make sure the features being passed in are line or multi lines.
Dim shapeWellKnownType As WellKnownType = feature.GetWellKnownType()
If shapeWellKnownType = WellKnownType.Line OrElse shapeWellKnownType = WellKnownType.Multiline Then
Dim currentScale As Double = ExtentHelper.GetScale(canvas.CurrentWorldExtent, canvas.Width, MapUnit)
' Enforce the minimum and maximum scale properties
If currentScale > MaximumScale Then
currentScale = MaximumScale
End If
If currentScale < MinimumScale Then
currentScale = MinimumScale
End If
' Get the width of the line according to the current scale
Dim centerPenWidth As Single = GetCurrentWidth(currentScale, MaximumLineWidth.CenterPenWidth, MinimumLineWidth.CenterPenWidth)
Dim innerPenWidth As Single = GetCurrentWidth(currentScale, MaximumLineWidth.InnerPenWidth, MinimumLineWidth.InnerPenWidth)
Dim outerPenWidth As Single = GetCurrentWidth(currentScale, MaximumLineWidth.OuterPenWidth, MinimumLineWidth.OuterPenWidth)
' Draw the line
If outerPenWidth <> 0 Then
canvas.DrawLine(feature, New GeoPen(OuterPenColor, outerPenWidth), DrawingLevel.LevelOne, XOffset, YOffset)
End If
If innerPenWidth <> 0 Then
canvas.DrawLine(feature, New GeoPen(InnerPenColor, innerPenWidth), DrawingLevel.LevelOne, XOffset, YOffset)
End If
If centerPenWidth <> 0 Then
canvas.DrawLine(feature, New GeoPen(CenterPenColor, centerPenWidth), DrawingLevel.LevelOne, XOffset, YOffset)
End If
End If
Next
End Sub
Private Function GetCurrentWidth(ByVal currentScale As Double, ByVal maxWidth As Double, ByVal minWidth As Double) As Single
Return CSng((maxWidth - (currentScale - MinimumScale) * (maxWidth - minWidth) / (MaximumScale - MinimumScale)))
End Function
End Class
' This class is a wrapper for the widths of line's pens.
Class LineWidth
Public Sub New()
Me.New(0, 0, 0)
End Sub
Public Sub New(ByVal centerPenWidth As Single, ByVal innerPenWidth As Single, ByVal outerPenWidth As Single)
Me.CenterPenWidth = centerPenWidth
Me.InnerPenWidth = innerPenWidth
Me.OuterPenWidth = outerPenWidth
End Sub
Private _CenterPenWidth As Single
Public Property CenterPenWidth() As Single
Get
Return _CenterPenWidth
End Get
Set(ByVal value As Single)
_CenterPenWidth = value
End Set
End Property
Private _InnerPenWidth As Single
Public Property InnerPenWidth() As Single
Get
Return _InnerPenWidth
End Get
Set(ByVal value As Single)
_InnerPenWidth = value
End Set
End Property
Private _OuterPenWidth As Single
Public Property OuterPenWidth() As Single
Get
Return _OuterPenWidth
End Get
Set(ByVal value As Single)
_OuterPenWidth = value
End Set
End Property
End Class