Creating A Custom Renderer

Created:1/22/1998
Description:

This sample demonstrates how to create a very basic custom renderer and use it in ArcMap. The renderer draws symbology for point, line and polygon feature layers, rendering all features with the same symbol.

How to use:
  1. Add a point, polyline, or polygon layer to your dataframe.
  2. In the VBA Editor, go to Tools > References, and Browse to this sample's dll and select it.
  3. In the ThisDocument module, copy-paste the following procedure:
    
    '+++ This VBA script demonstrates use of the custom renderer clsMyRenderer
    Public Sub Test_Renderer()
      Dim pDoc As IMxDocument
      Dim pMap As IMap
      Dim pFeatLyr As IFeatureLayer
      Dim pGeoFeatLyr As IGeoFeatureLayer
      Dim pRen As IFeatureRenderer
      Dim i As Long
      
      Set pDoc = ThisDocument
      Set pMap = pDoc.ActiveView.FocusMap
    
      '+++ walk through the layers collection, and get the first feature layer
      For i = 0 To pMap.LayerCount - 1
        If TypeOf pMap.Layer(i) Is IFeatureLayer Then
          Set pFeatLyr = pMap.Layer(i)
          Exit For
        End If
      Next i
      
      '+++ create a new MyRenderer, and assign it to the featurelayer
      Set pRen = New CustomRenderer.clsMyRenderer
      If TypeOf pFeatLyr Is IGeoFeatureLayer Then
        Set pGeoFeatLyr = pFeatLyr
        Set pGeoFeatLyr.Renderer = pRen
        '+++ refresh the map
        pDoc.ActiveView.Refresh
        pDoc.UpdateContents
      End If
    End Sub
  4. Run the procedure. You should see that the default renderer gets replaced by clsMyRenderer.
  5. Save the ArcMap document as "MyRenderer.mxd". Exit ArcMap.
  6. Start ArcMap again and open "MyRenderer.mxd" file. You should see that the layer is still drawn using clsMyRenderer.

Application:
ArcMap

Difficulty: Intermediate


Visual Basic
File Description
MyRenderer.cls Class definition for custom renderer.
CustomRenderer.vbp Visual Basic project file.
CustomRenderer.dll The compiled project.


Key CoClasses: SimpleMarkerSymbol, SimpleLineSymbol, SimpleFillSymbol
Key Interfaces: IFeatureRenderer, IPersistVariant, ISymbol, ISimpleMarkerSymbol, ISimpleLineSymbol, ISimpleFillSymbol, IFeatureCursor