Common Custom EditorTaskCommon_CustomEditorTask_VBNet\CustomEditorTask_VBNet\CustomEditorTask.vb
' Copyright 2007 ESRI
'
' All rights reserved under the copyright laws of the United States
' and applicable international laws, treaties, and conventions.
'
' You may freely redistribute and use this sample code, with or
' without modification, provided you include the original copyright
' notice and use restrictions.
'
' See the use restrictions.
'
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools
Imports ESRI.ArcGIS.Geodatabase
Imports ESRI.ArcGIS.ADF.ArcGISServer.Editor
Imports System.Web.UI
Imports System.ComponentModel
Imports ESRI.ArcGIS.ADF.ArcGISServer
Namespace CustomEditorTask_VBNet
Public Class CustomEditorTask
Inherits ESRI.ArcGIS.ADF.ArcGISServer.Editor.EditorTask
Private m_customEditorSettingsPanel As CustomEditorSettingsPanel
' Override to create and return a custom Editor
Protected Overrides Function CreateEditor() As ESRI.ArcGIS.ADF.ArcGISServer.Editor.Editor
Return New CustomEditor(Me)
End Function
' Custom property to define snapping in map units
<Browsable(True), Category("Snapping"), PersistenceMode(PersistenceMode.Attribute), DefaultValue(CustomSnappingPanel.DEFAULT_SNAP_TOL_MAPUNITS), Description("The maximum distance in map units for which snapping rules will be effective.")> _
Public Property SnapToleranceMapUnits() As Double
Get
Dim o As Object = StateManager.GetProperty("snapTolMapUnits")
If o Is Nothing Then
Return CustomSnappingPanel.DEFAULT_SNAP_TOL_MAPUNITS
End If
Return CDbl(o)
End Get
Set
StateManager.SetProperty("snapTolMapUnits", Value)
End Set
End Property
' Custom property to define if snapping should use pixels (default) or map units.
<Browsable(True), Category("Snapping"), PersistenceMode(PersistenceMode.Attribute), DefaultValue(True), Description("Indicates if snapping use map units or pixels.")> _
Public Property UseMapUnitsForSnapping() As Boolean
Get
Dim obj As Object = StateManager.GetProperty("useSnappingMapUnits")
If Not obj Is Nothing Then
Return CBool(obj)
End If
Return True
End Get
Set
StateManager.SetProperty("useSnappingMapUnits", Value)
End Set
End Property
' Override to create and return a custom settings panel
Protected Overrides Function CreateSettingsPanel() As ESRI.ArcGIS.ADF.ArcGISServer.Editor.EditorSettingsPanel
m_customEditorSettingsPanel = New CustomEditorSettingsPanel(Me)
Return m_customEditorSettingsPanel
End Function
Protected Overrides Sub OnLoad(ByVal e As EventArgs)
MyBase.OnLoad(e)
' Set attribute filtering parameters for the EditorTask during the
' Page Load event of the initial request.
If (Not Me.Page.IsPostBack) Then
FilterAttributes()
End If
End Sub
' Override OnPostToolExecute event
Protected Overrides Sub OnPostToolExecute(ByVal e As EditorToolEventArgs, ByVal returnMessages As StringList)
MyBase.OnPostToolExecute(e, returnMessages)
CustomEditorTask_PostToolExecute(Me, e)
End Sub
' After a tool that modifies features has executed, add creation and modified time to edited feature.
Private Sub CustomEditorTask_PostToolExecute(ByVal sender As Object, ByVal e As ESRI.ArcGIS.ADF.ArcGISServer.Editor.Tools.EditorToolEventArgs)
' The Tentative Assessed Parcel" layer contains two Date fields: CreationTime and LastModified.
' If a new feature was created, update the CreationTime field with the current Date.
' If an existing feature was modified (via the tools listed), update the LastModified field with the current Date.
If e.ServerAction.Editor.SelectedLayerName = "Tentative Assessed Parcels" Then
Dim featureClass As IFeatureClass = e.ServerAction.Editor.FeatureLayer.FeatureClass
If TypeOf e.ServerAction Is CreateFeature Then
Dim createFeature As CreateFeature = CType(e.ServerAction, CreateFeature)
Dim feature As IFeature = featureClass.GetFeature(createFeature.Feature)
Dim index As Integer = feature.Fields.FindField("CreationTime")
If index > -1 Then
feature.Value(index) = DateTime.Now
feature.Store()
End If
' For simplicity only a few tools that modify features have been included
ElseIf TypeOf e.ServerAction Is AddVertex Then
Dim addVertex As AddVertex = CType(e.ServerAction, AddVertex)
UpdateLastModifiedTime(addVertex.Features, featureClass)
ElseIf TypeOf e.ServerAction Is MoveVertex Then
Dim moveVertex As MoveVertex = CType(e.ServerAction, MoveVertex)
UpdateLastModifiedTime(moveVertex.Features, featureClass)
ElseIf TypeOf e.ServerAction Is MoveFeature Then
Dim moveFeature As MoveFeature = CType(e.ServerAction, MoveFeature)
UpdateLastModifiedTime(moveFeature.Features, featureClass)
End If
' Refreshes the EditAttributesPanel (returned from call to Editor.AttributesEditor property)
' and adds callbacks to the Map control associated with the Editor.
EditorUtilities.RefreshAttributes(e.ServerAction.Editor, Nothing)
End If
End Sub
' Used during post tool execute
Private Sub UpdateLastModifiedTime(ByVal fids As List(Of Integer), ByVal featureClass As ESRI.ArcGIS.Geodatabase.IFeatureClass)
Dim index As Integer = featureClass.Fields.FindField("LastModified")
For Each fid As Integer In fids
Dim feature As IFeature = featureClass.GetFeature(fid)
feature.Value(index) = DateTime.Now
feature.Store()
Next fid
End Sub
Private Sub FilterAttributes()
' Get the ArcGIS Server Local MapFunctionality associated with the EditorTask
Dim agsLocalMapFunctionality As ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality = Me.Editor.MapFunctionality
Dim layerIDs As String() = Nothing
Dim layerNames As String() = Nothing
agsLocalMapFunctionality.GetLayers(layerIDs, layerNames)
' Iterate through feature layers in the MapFunction (map resource) and set
' attribute display parameters when editing attributes in the EditAttributesPanel.
Dim i As Integer = 0
Do While i < layerIDs.Length
Dim layerName As String = layerNames(i)
Dim layerID As Integer = Int32.Parse(layerIDs(i))
If layerName = "Tentative Assessed Parcels" Then
Dim attributeDisplayInfo As AttributeDisplayInfo = New AttributeDisplayInfo(layerID, AttributeDisplayMode.ReadOnly)
attributeDisplayInfo.Overrides.Add(New AttributeDisplayOverride("APN", AttributeDisplayMode.Editable))
Me.AttributeDisplay.AttributeDisplayInfos.Add(attributeDisplayInfo)
ElseIf layerName = "Address Points" Then
Dim attributeDisplayInfo As AttributeDisplayInfo = New AttributeDisplayInfo(layerID, AttributeDisplayMode.Editable)
attributeDisplayInfo.Overrides.Add(New AttributeDisplayOverride("APN", AttributeDisplayMode.ReadOnly))
Me.AttributeDisplay.AttributeDisplayInfos.Add(attributeDisplayInfo)
ElseIf layerName = "Water Bodies" Then
Dim attributeDisplayInfo As AttributeDisplayInfo = New AttributeDisplayInfo(layerID, AttributeDisplayMode.Hidden)
attributeDisplayInfo.Overrides.Add(New AttributeDisplayOverride("NAME", AttributeDisplayMode.Editable))
Me.AttributeDisplay.AttributeDisplayInfos.Add(attributeDisplayInfo)
End If
i += 1
Loop
End Sub
End Class
End Namespace