Creating A Custom Line Symbol

Created:1/22/1998
Last Modified:6/9/2000
Description:

This sample demonstrates how you can create a custom line symbol. This symbol draws the lines in your layer using Bezier curves.

How to use:
  1. Start ArcMap. Add a polyline feature layer into the map.
  2. In the Visual Basic Editor, go to Tools > References and Browse to this sample's dll, double-click it and dismiss the References dialog.
  3. Copy-paste the following procedure into the editor and run it.
    ' This VBA script demonstrates rendering a polyline featurelayer using
    ' MyLineSymbol that we've created earlier.
    Public Sub Test_MyLineSymbol()
      Dim pLSym As ILineSymbol
      Dim pDoc As IMxDocument
      Dim pMap As IMap
      Dim pFeatLyr As IFeatureLayer
      Dim i As Long
      Dim bFound As Boolean  ' find a polyline feature layer?
      
      Dim pColor As IRgbColor
      Set pLSym = New CustomLineSymbol.MyLineSymbol
      pLSym.Width = 2
      
      Set pColor = New RgbColor
      pColor.RGB = 0
      pLSym.Color = pColor
    
      Set pDoc = ThisDocument
      Set pMap = pDoc.FocusMap
      
      ' walks through the layers collection of the map, and finds the 1st
      ' polyline feature layer
      For i = 0 To pMap.LayerCount - 1
        If TypeOf pMap.Layer(i) Is IFeatureLayer Then
          Set pFeatLyr = pMap.Layer(i)
          If pFeatLyr.FeatureClass.ShapeType = esriGeometryPolyline Then
            bFound = True
            Exit For
          End If
        End If
      Next i
      
      ' if a polyline feature layer is found, assign our MyLineSymbol to
      ' the layer's renderer.  If not, prompt the user to add a polyline
      ' feature layer
      If bFound Then
        Dim pRen As ISimpleRenderer
        Dim pGeoFeatLyr As IGeoFeatureLayer
        Set pGeoFeatLyr = pFeatLyr
        Set pRen = pGeoFeatLyr.Renderer
        Set pRen.Symbol = pLSym
        pDoc.ActiveView.Refresh
        pDoc.UpdateContents
      Else
        MsgBox "Add a polyline feature layer"
      End If
    End Sub
    
  4. You should see your layer drawn with MyLineSymbol.
  5. Save the ArcMap document as "MyLineSymbol.mxd". Exit ArcMap.
  6. Start ArcMap again and open "MyLineSymbol.mxd" file. You should still see the polyline layer rendered in MyLineSymbol.

Application:
ArcMap

Difficulty: Advanced


Visual Basic
File Description
CustomLineSymbol.vbp Visual Basic Project File.
MyLineSymbol.cls Class file demonstrating how to create a custom line symbol.


Key CoClasses: LineSymbol
Key Interfaces: ILineSymbol, ISymbol, IClone, IPersistVariant, IPolyCurve
Key Members: ILineSymbol::Draw, IPolyCurve::Smooth