|
Products:
ArcView: VB6Engine: Java
Platforms: Windows, Solaris, LinuxRequires: For VB Usage: An ArcMap session with at least one layer added.Minimum ArcGIS Release: 9.0 |
Public Sub TestRenderer()
' this VBA macro demonstrates using CustomSimpleRenderer.CustomSimpleRend
' run this macro with at least one feature layer of points, lines, or polygons in the active dataframe
' the macro creates a symbol depending on feature type and the draws the
' first featurelayer in the dataframe using this symbol
On Error GoTo ErrHand
Dim pApp As IMxApplication
Set pApp = Application
Dim pDoc As IMxDocument
Set pDoc = ThisDocument
Dim pMap As IMap
Set pMap = pDoc.ActiveView.FocusMap
Dim pFeatLyr As IFeatureLayer
Dim i As Long
' run through the layers and get the first featurelayer
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
' --------------------------------------------------
' symbol setup
' this macro will handle feature symbology according to the following rules:
' if we have point features, then use a marker symbol for rendering
' else, if we have line features, then use a line symbol
' else, if we have polygon features, then use a fill symbol
' else, (we don't have any of these feature types) so do not assign renderer to layer
Dim pColor As IRgbColor
Set pColor = New RgbColor
' use red. it's a good color
pColor.RGB = vbRed
Dim pSym As ISymbol
' based on feature type, make proper symbol, then assign to pSym
Select Case pFeatLyr.FeatureClass.ShapeType
Case esriGeometryPoint ' set up a marker symbol
Dim pMarkerSym As ISimpleMarkerSymbol
Set pMarkerSym = New SimpleMarkerSymbol
With pMarkerSym
.Size = 12
.Color = pColor
.Style = esriSMSX
End With
Set pSym = pMarkerSym
Case esriGeometryPolyline ' set up a line symbol
Dim pLineSymbol As ISimpleLineSymbol
Set pLineSymbol = New SimpleLineSymbol
With pLineSymbol
.Width = 1
.Color = pColor
.Style = esriSLSDashDotDot
End With
Set pSym = pLineSymbol
Case esriGeometryPolygon ' setup a fill symbol
Dim pFillSymbol As ISimpleFillSymbol
Set pFillSymbol = New SimpleFillSymbol
With pFillSymbol
.Color = pColor
.Style = esriSFSBackwardDiagonal
End With
Set pSym = pFillSymbol
Case Else
MsgBox "Invalid feature type"
GoTo EndProc
End Select
' --------------------------------------------------
' create a new CustomSimpleRend
Dim pRend As IFeatureRenderer
Set pRend = New CustomSimpleRenderer.CustomSimpleRend
' set symbol. we must use ISimpleRenderer interface
Dim pSimpleRend As ISimpleRenderer
Set pSimpleRend = pRend
Set pSimpleRend.Symbol = pSym
Dim pGeoFL As IGeoFeatureLayer
Set pGeoFL = pFeatLyr
' finally, set the new renderer to the layer and refresh the map
Set pGeoFL.Renderer = pRend
pDoc.ActiveView.Refresh
pDoc.UpdateContents
GoTo EndProc
ErrHand:
MsgBox "TestRenderer " & Err.Description
EndProc:
' set all variables to nothing
Set pApp = Nothing
Set pDoc = Nothing
Set pMap = Nothing
Set pFeatLyr = Nothing
Set pColor = Nothing
Set pSym = Nothing
Set pMarkerSym = Nothing
Set pLineSymbol = Nothing
Set pFillSymbol = Nothing
Set pRend = Nothing
Set pSimpleRend = Nothing
Set pGeoFL = Nothing
Exit Sub
End Sub| VB6 | Java |
| File | Description |
| CustomSimpleRend.cls | Class definition for the custom renderer. |
| CustomSimpleRenderer.vbp | Visual Basic project file. |
| CustomSimpleRenderer.dll | The compiled project. |