Creating A Scale Dependent Renderer


This sample demonstrates how to create and use a custom renderer in ArcInfo. This renderer will tailor how polygon features are drawn based on the current map scale.

How to use:
  1. Start ArcMap, and open the VBA Editor.
  2. Go to Tools > References and browse for this sample's DLL, and add it to your VBA project's reference.
  3. Go to the "ArcMap Objects - ThisDocument" code window, and copy-paste the following procedure into it.
    '+++ This VBA script uses this sample's Renderer.
    Public Sub TestScaleDependRend()
      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
      Set pFeatLyr = pDoc.SelectedLayer
      If pFeatLyr Is Nothing Then
        MsgBox "you must select the polygon layer to apply the renderer"
        Exit Sub
      End If
      Set pRen = New scaleRendererVB.scaleRenderer
      Set pGeoFeatLyr = pFeatLyr
      Set pGeoFeatLyr.Renderer = pRen
    End Sub
  4. Load some polygon data into the ArcMap application.
  5. Select a polygon feature layer in the map and run the procedure. You should see the default renderer get replaced by the scaleRenderer. You may have to edit the renderer implementation and recompile the dll to adjust at what scale the features get displayed.


Difficulty: Advanced

Visual Basic Visual C++
File Description
scaleRenderer.cls Class file demonstrating how to create the renderer.
scaleRendererVB.vbp The Visual Basic project file.
scaleRendererVB.dll The compiled project.

Key Interfaces: IFeatureRenderer, IPersistVariant, IDisplay, ISymbol, IColor, IEnvelope