Accessing ArcGIS Server From a Web Application

9
Accessing ArcGIS Server from a Web application The Web ADF provides the components necessary to work with ArcGIS Server services. The Web ADF controls utilize the Common API implementation classes for both ArcGIS Server local and internet data sources. ArcGIS Server local data sources connect to the ArcGIS Server Object Manager (SOM) and work with a server object directly. ArcGIS Server internet data sources connect to an ArcGIS Server Web service endpoint. A number of base classes (e.g. MapResourceBase, GISDataSourceBase) define shared members for both ArcGIS Server data source types, but different implementation and proxy classes are used to initiate and manage the connection with an ArcGIS Server service. The Web ADF works with local and internet ArcGIS Services using the ArcGIS Server SOAP API. To put this another way, the ArcGIS Server data source implementation of the Web ADF Common API uses the ArcGIS Server SOAP API. This means that almost all interaction between Web ADF controls and Common API implementation classes with ArcGIS Server data sources use SOAP. See the ArcGIS Server implementation discussion for more details. Note that an ArcGIS Server local data source can access server context to create and work with objects on the server via ArcObjects COM proxies on the client. However, the Web ADF is unaware of these changes unless you explicitly inform the Web ADF components. Use the following walkthrough as an introduction to working with ArcGIS Server data sources in a Web ADF application. Programming with both SOAP API Value objects on the client and ArcObjects API COM objects on the server will be demonstrated. This tutorial will provide step-by-step instructions for creating a Web ADF application in Visual Studio 2005 that works with an ArcGIS Server local data source. A custom tool will be created and used to add a graphic point to the Map using ArcGIS Server Value objects and buffer that point using ArcObjects on the GIS Server. The following Web ADF controls will be used: MapResourceManager, Map, Toc, Toolbar. Create a new Web application using the steps in the Creating a Web application with the Web controls tutorial. When adding a MapResourceInfo, select an ArcGIS Server local data source. The Web ADF application should appear as follows: 1. Add an ArcGIS identity to the web application. This is required when using ArcGIS Server local data sources. To add an identity, right-click on the project in the Solution Explorer window of Visual Studio, and choose Add ArcGIS Identity... from the context menu. This displays the Add ArcGIS Identity dialog. Enter the user name, password, and domain or machine name for the account you wish to use for this application. 2. EDN (ESRI Developer Network) Home Documentation Library Discussion Forums Downloads Code Exchange Media Center Conferences ESRI.com | Support | More ESRI Sites... Search GO Search Help Contents Library Home > Creating ArcGIS Server solutions > Developing Applications > Developing Web Applications using the Web ADF > Tutorials Overview Creating a Web application with a template Creating a Web application with the Web controls Accessing ArcGIS Server from a Web application Accessing ArcIMS from a Web application Developing Web Applications with the Web ADF Accessing ArcGIS Server from a Web application http://edndoc.esri.com/arcobjects/9.2/NET_Server_Doc/developer/ADF/... 1 of 9 7/21/2011 10:37 PM

Transcript of Accessing ArcGIS Server From a Web Application

Page 1: Accessing ArcGIS Server From a Web Application

Accessing ArcGIS Server from a Web application

The Web ADF provides the components necessary to work with ArcGIS Serverservices. The Web ADF controls utilize the Common API implementation classes forboth ArcGIS Server local and internet data sources. ArcGIS Server local datasources connect to the ArcGIS Server Object Manager (SOM) and work with a serverobject directly. ArcGIS Server internet data sources connect to an ArcGIS ServerWeb service endpoint. A number of base classes (e.g. MapResourceBase,GISDataSourceBase) define shared members for both ArcGIS Server data sourcetypes, but different implementation and proxy classes are used to initiate andmanage the connection with an ArcGIS Server service. The Web ADF works withlocal and internet ArcGIS Services using the ArcGIS Server SOAP API. To put thisanother way, the ArcGIS Server data source implementation of the Web ADFCommon API uses the ArcGIS Server SOAP API. This means that almost allinteraction between Web ADF controls and Common API implementation classeswith ArcGIS Server data sources use SOAP. See the ArcGIS Server implementationdiscussion for more details. Note that an ArcGIS Server local data source canaccess server context to create and work with objects on the server via ArcObjectsCOM proxies on the client. However, the Web ADF is unaware of these changesunless you explicitly inform the Web ADF components. Use the followingwalkthrough as an introduction to working with ArcGIS Server data sources in aWeb ADF application. Programming with both SOAP API Value objects on the clientand ArcObjects API COM objects on the server will be demonstrated.

This tutorial will provide step-by-step instructions for creating a Web ADFapplication in Visual Studio 2005 that works with an ArcGIS Server local datasource. A custom tool will be created and used to add a graphic point to the Mapusing ArcGIS Server Value objects and buffer that point using ArcObjects on theGIS Server. The following Web ADF controls will be used: MapResourceManager,Map, Toc, Toolbar.

Create a new Web application using the steps in the Creating a Webapplication with the Web controls tutorial. When adding a MapResourceInfo,select an ArcGIS Server local data source.

The Web ADF application should appear as follows:

1.

Add an ArcGIS identity to the web application. This is required when usingArcGIS Server local data sources. To add an identity, right-click on theproject in the Solution Explorer window of Visual Studio, and choose AddArcGIS Identity... from the context menu. This displays the Add ArcGISIdentity dialog. Enter the user name, password, and domain or machinename for the account you wish to use for this application.

2.

EDN (ESRI Developer Network)

Home Documentation Library Discussion Forums Downloads Code Exchange Media Center Conferences

ESRI.com | Support | More ESRI Sites...

Search

GO

Search Help

Contents

Library Home >Creating ArcGIS Server

solutions > Developing

Applications > Developing Web

Applications using the Web ADF >

Tutorials

Overview

Creating a Web applicationwith a template

Creating a Web applicationwith the Web controls

Accessing ArcGIS Serverfrom a Web application

Accessing ArcIMS from aWeb application

Developing Web Applications with the Web ADF

Accessing ArcGIS Server from a Web application http://edndoc.esri.com/arcobjects/9.2/NET_Server_Doc/developer/ADF/...

1 of 9 7/21/2011 10:37 PM

Edy
Typewriter
http://edndoc.esri.com/arcobjects/9.2/NET_Server_Doc/developer/ADF/accessing_arcobjects_web_app.htm
Edy
Typewriter
Page 2: Accessing ArcGIS Server From a Web Application

The account used in the identity must be an existing account that is amember of the agsusers or agsadmin group on the machine where theArcGIS Server Object Manager (SOM) runs. The account must also berecognized by the computer where you are running Visual Studio. Therefore,if the SOM is not running on the local Visual Studio machine, the accountmust be a domain account, and the local Visual Studio computer must be amember of the domain.

This step adds the identity with credentials to the web.config file in the webapplication. By default the credentials are encrypted.

In Solution Explorer, right-click the Web project and select "Add NewItem...". In the Add New Item dialog, under the Visual Studio InstalledTemplates section, select the "Class" item. Set the class file name to"PointBufferTool.cs" and make sure the language is "Visual C#". VisualStudio will prompt you to create an "App_Code" folder and place the newclass file inside. Click Yes. The PointBufferTool.cs file should open for you tostart adding content. This file will contain the executable code associatedwith the custom tool.

3.

In Solution Explorer, right-click the Web project and select "Add ArcGISReference...". This dialog works similarly to the Add Reference dialog, butonly shows ArcGIS-related assemblies. A couple of ArcObjects PrimaryInterop Assemblies need to added to the project to work with ArcObjectsremotely via the ArcGIS Server ArcObjects API. In addition, the Web ADFCommon API implementation of ArcGIS Server data sources, contained inthe ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer assembly, enablesyou to work with ArcGIS Server capabilities exposed by Web ADF controls(e.g. MapFunctionality). It also provides the ability to hook into ArcObjectson the server via server context. The value objects and proxies utilized bythe Web ADF to work with ArcGIS Server data sources are contained in theESRI.ArcGIS.ADF.ArcGISServer assembly. In the dialog, select the followingcomponents, click Add, then Finish:

ESRI.ArcGIS.ADF.ArcGISServerESRI.ArcGIS.ADF.Web.DataSources.ArcGISServerESRI.ArcGIS.ServerESRI.ArcGIS.CartoESRI.ArcGIS.GeometryESRI.ArcGIS.SystemESRI.ArcGIS.Display

After selecting these components, click Add, then click Finish. The referenceitems are added to the web.config file and are available to use within theweb project.

4.

At the top of the PointBufferTool.cs file, add the following using statements:

[C#]

using ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools;using ESRI.ArcGIS.ADF.Web.UI.WebControls;using ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer;using ESRI.ArcGIS.Server;using ESRI.ArcGIS.Carto;using ESRI.ArcGIS.Geometry;

5.

Accessing ArcGIS Server from a Web application http://edndoc.esri.com/arcobjects/9.2/NET_Server_Doc/developer/ADF/...

2 of 9 7/21/2011 10:37 PM

Page 3: Accessing ArcGIS Server From a Web Application

using ESRI.ArcGIS.esriSystem;using ESRI.ArcGIS.Display;

[VB]

Imports ESRI.ArcGIS.ADF.Web.UI.WebControls.ToolsImports ESRI.ArcGIS.ADF.Web.UI.WebControlsImports ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServerImports ESRI.ArcGIS.ServerImports ESRI.ArcGIS.CartoImports ESRI.ArcGIS.GeomeTryImports ESRI.ArcGIS.esriSystemImports ESRI.ArcGIS.Display

Remove the PointBufferTool constructor and implement theIMapServerToolAction interface on the PointBufferTool class. The code forthe class should appear as follows:

[C#]

public class PointBufferTool : IMapServerToolAction { public void ServerAction(ToolEventArgs args) { } }

[VB]

Public Class PointBufferTool Implements IMapServerToolAction

Public Sub ServerAction(ByVal args As ToolEventArgs) _ Implements IMapServerToolAction.ServerAction

End SubEnd Class

6.

Inside the ServerAction method (Sub), insert code to get a reference to theMap control from the ToolEventArgs.Control property. This and theremainder of the code in the tutorial should be placed before the close of themethod (for C#, before the first of the two closing braces; for VB, before theEnd Sub).

[C#]

ESRI.ArcGIS.ADF.Web.UI.WebControls.Map mapctrl; mapctrl = (ESRI.ArcGIS.ADF.Web.UI.WebControls.Map)args.Control;

[VB]

Dim mapctrl As ESRI.ArcGIS.ADF.Web.UI.WebControls.Mapmapctrl = CType(args.Control, ESRI.ArcGIS.ADF.Web.UI.WebControls.Map)

7.

Since the ClientAction for the tool will be set to "Point", castthe ToolEventArgs to PointEventArgs and get the point (mouseclick) provided by the end-user in screen coordinates. This point will beconverted to map coordinates and added to the ArcGIS Server data sourceas custom graphics.

[C#]

PointEventArgs pea = (PointEventArgs)args; System.Drawing.Point screen_point = pea.ScreenPoint;

[VB]

Dim pea As PointEventArgs = CType(args, PointEventArgs)Dim screen_point As System.Drawing.Point = pea.ScreenPoint

8.

Since we're going to add custom graphics to the map generated by ArcGISServer, we need to get the Web ADF functionality associated with drawingmap images. When a Map control consumes a resource, it generates aMapFunctionality, one for each resource. As a result, a Map control can havean array of MapFunctionalities. In this tutorial, there is only one resource,and ArcGIS Server resource. To get the MapFunctionality associated withthe first (and in this case only) resource, use the following code. Since weknow it is a type of ArcGIS Server resource, we can cast the functionality tothe ArcGIS Server specific MapFunctionality. We'll need to do this to work

9.

Accessing ArcGIS Server from a Web application http://edndoc.esri.com/arcobjects/9.2/NET_Server_Doc/developer/ADF/...

3 of 9 7/21/2011 10:37 PM

Page 4: Accessing ArcGIS Server From a Web Application

with ArcGIS Server specific implementation classes to draw graphics andwork with server context.

[C#]

ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality mf; mf = (ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality)mapctrl.GetFunctionality(0);

[VB]

Dim mf As ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionalitymf = CType(mapctrl.GetFunctionality(0), _ ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality)

The Web ADF manages the state of the ArcGIS Server resource,functionality and Map control for us. It uses ArcGIS Server Value objectsand proxies, which are inherently stateless, in a shallowly statefulmanner (state maintained on the client). The Value objects are included aspart of the ArcGIS Server data source implementation in theESRI.ArcGIS.ADF.ArcGISServer assembly and are shared for internet andlocal connections. When working with an ArcGIS Server MapFunctionality,the MapDescription property provides a Value object which can be used tomodify the appearance and content of a map generated by an ArcGIS Servermap service. In this tutorial, we'll work with the CustomGraphics propertyto add a set of custom graphics to the map.

[C#]

ESRI.ArcGIS.ADF.ArcGISServer.MapDescription mapDescription = mf.MapDescription;

[VB]

Dim mapDescription As ESRI.ArcGIS.ADF.ArcGISServer.MapDescription = _mf.MapDescription

10.

Since we're working with a MapDescription Value object on the client, weneed to create the objects associated with our custom graphics using Valueobjects too. In this example, we're using a point retrieved from a user-clickin a Map control to create a graphic. First, convert the user defined pointfrom screen units to map units using the Web ADF geometry conversioncapabilities. Second, create a PointN Value object to store the mapcoordinates used to draw the graphic.

[C#]

ESRI.ArcGIS.ADF.Web.Geometry.Point adf_map_point;adf_map_point = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(screen_point, mapctrl.Extent, mf.DisplaySettings.ImageDescriptor.Width, mf.DisplaySettings.ImageDescriptor.Height);

ESRI.ArcGIS.ADF.ArcGISServer.PointN ags_map_point;ags_map_point = ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.FromAdfPoint(adf_map_point);

[VB]

Dim adf_map_point As ESRI.ArcGIS.ADF.Web.Geometry.Pointadf_map_point = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint( _ screen_point, mapctrl.Extent, mf.DisplaySettings.ImageDescriptor.Width, _ mf.DisplaySettings.ImageDescriptor.Height)Dim ags_map_point As ESRI.ArcGIS.ADF.ArcGISServer.PointNags_map_point = _ ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.FromAdfPoint(adf_map_point)

11.

To render the PointN as a graphic, we need to define a graphic element forpoints, a MarkerElement. A MarkerElement has a Geometry and Symbolproperty to define where and how it is drawn on the map. The Geometryproperty is set to the PointN object created earlier. The Symbol property isset to the appropriate symbol for the element type - in this case, aMarkerSymbol. The MarkerSymbol stores the type, color, and size of thesymbol.

[C#]

ESRI.ArcGIS.ADF.ArcGISServer.RgbColor rgb;rgb = new ESRI.ArcGIS.ADF.ArcGISServer.RgbColor(); rgb.Red = 0; rgb.Green = 255; rgb.Blue = 0;

12.

Accessing ArcGIS Server from a Web application http://edndoc.esri.com/arcobjects/9.2/NET_Server_Doc/developer/ADF/...

4 of 9 7/21/2011 10:37 PM

Page 5: Accessing ArcGIS Server From a Web Application

rgb.AlphaValue = 255;

ESRI.ArcGIS.ADF.ArcGISServer.SimpleMarkerSymbol sms; sms = new ESRI.ArcGIS.ADF.ArcGISServer.SimpleMarkerSymbol(); sms.Style = ESRI.ArcGIS.ADF.ArcGISServer.esriSimpleMarkerStyle.esriSMSDiamond; sms.Color = rgb;sms.Size = 20.0; ESRI.ArcGIS.ADF.ArcGISServer.MarkerElement marker; marker = new ESRI.ArcGIS.ADF.ArcGISServer.MarkerElement(); marker.Symbol = sms; marker.Point = ags_map_point;

[VB]

Dim rgb As New ESRI.ArcGIS.ADF.ArcGISServer.RgbColor()rgb.Red = 0rgb.Green = 255rgb.Blue = 0rgb.AlphaValue = 255

Dim sms As New ESRI.ArcGIS.ADF.ArcGISServer.SimpleMarkerSymbol()sms.Style = ESRI.ArcGIS.ADF.ArcGISServer.esriSimpleMarkerStyle.esriSMSDiamondsms.Color = rgbsms.Size = 20.0

Dim marker As New ESRI.ArcGIS.ADF.ArcGISServer.MarkerElement()marker.Symbol = smsmarker.Point = ags_map_point

The MarkerElement is ready to added as a graphic to the map created byArcGIS Server and rendered in a Map control. The steps presented thusfarcan be used by both ArcGIS Server internet and local data sources to drawgraphics in a map. To work with ArcObjects on the GIS Server an ArcGISServer local resource is required. The following steps will use ArcObjects tobuffer the point provided by the end user and return a buffer polygon. Thepolygon will be added to MapDescription as another custom graphic. First, areference to an ArcGIS Server local map resource must be retrieved. Casting the MapResource of an ArcGIS Server MapFunctionality to typeMapResourceLocal will provide access to server context. TheServerContextInfo property on MapResourceLocal exposes the map server'sserver context. [C#]

ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceLocal mrl;mrl = (ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceLocal) mf.MapResource; ESRI.ArcGIS.Server.IServerContext serverContext = mrl.ServerContextInfo.ServerContext;

[VB]

Dim mrl As ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceLocalmrl = CType(mf.MapResource, _ ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceLocal)Dim serverContext As ESRI.ArcGIS.Server.IServerContext = _ mrl.ServerContextInfo.ServerContext

13.

Now that we have access to server context, we can create ArcObjects on theGIS Server to perform work. Since we already have an ArcGIS Server Valueobject point object, we can use the Web ADF's ArcGIS Server specificConverter class to use the Value object to create a COM object on the GISServer. A reference to the COM object (ArcObject) is returned. In this case,a reference to point geometry via the IPoint interface is returned. For apoint object in ArcObjects, buffer operations are available via theITopologicalOperator interface. Cast (or query interface) to this interfaceand call the Buffer method. For purposes of this example, the bufferdistance is a proportion of the map extent width. [C#]

ESRI.ArcGIS.Geometry.IPoint ipnt; ipnt = (ESRI.ArcGIS.Geometry.IPoint) ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.ValueObjectToComObject(ags_map_point, serverContext);

14.

Accessing ArcGIS Server from a Web application http://edndoc.esri.com/arcobjects/9.2/NET_Server_Doc/developer/ADF/...

5 of 9 7/21/2011 10:37 PM

Page 6: Accessing ArcGIS Server From a Web Application

ESRI.ArcGIS.Geometry.ITopologicalOperator topop = (ESRI.ArcGIS.Geometry.ITopologicalOperator)ipnt;double bufferdistance = mapctrl.Extent.Width/6; ESRI.ArcGIS.Geometry.IPolygon bufferpolygon = (ESRI.ArcGIS.Geometry.IPolygon)topop.Buffer(bufferdistance);

[VB]

Dim ipnt As ESRI.ArcGIS.Geometry.IPointipnt = CType( _ ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.ValueObjectToComObject(ags_map_point, serverContext), _ ESRI.ArcGIS.Geometry.IPoint)Dim topop As ESRI.ArcGIS.Geometry.ITopologicalOperator = _ CType(ipnt, ESRI.ArcGIS.Geometry.ITopologicalOperator)Dim bufferdistance As Double = mapctrl.Extent.Width / 6Dim bufferpolygon As ESRI.ArcGIS.Geometry.IPolygon = _ CType(topop.Buffer(bufferdistance), ESRI.ArcGIS.Geometry.IPolygon)

The result buffer polygon has been generate and is available as a polygonobject on the GIS Server. Since the ArcGIS Server MapFunctionality uses aclient-side, Value object version of MapDescription, the polygon must beconverted to a Value object to be added to the MapDescription as customgraphics. The Web ADF's ArcGIS Server specific Converter class can alsoconvert from ArcObjects on the server (via COM proxy reference) to nativeclient Value objects. The code below creates a PolygonN Value object fromthe buffer polygon.

[C#]

ESRI.ArcGIS.ADF.ArcGISServer.PolygonN buffer_polyn; buffer_polyn = (ESRI.ArcGIS.ADF.ArcGISServer.PolygonN) ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.ComObjectToValueObject(bufferpolygon, serverContext, typeof(PolygonN));

[VB]

Dim buffer_polyn As ESRI.ArcGIS.ADF.ArcGISServer.PolygonNbuffer_polyn = CType( _ ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.ComObjectToValueObject( _ bufferpolygon, serverContext, _ GetType(ESRI.ArcGIS.ADF.ArcGISServer.PolygonN)), _ ESRI.ArcGIS.ADF.ArcGISServer.PolygonN)

15.

To render the PolygonN as a graphic, we need to define a graphic elementfor polygons, a PolygonElement. A PolygonElement has a Geometry andSymbol property to define where and how it is drawn on the map. TheGeometry property is set to the PolygonN object associated with our buffer. The Symbol property is set to the appropriate symbol for the element type -in this case, a FillSymbol. The FillSymbol stores the style and color of thesymbol. [C#]

ESRI.ArcGIS.ADF.ArcGISServer.RgbColor rgb1;rgb1 = new ESRI.ArcGIS.ADF.ArcGISServer.RgbColor(); rgb1.Red = 255; rgb1.Green = 255; rgb1.Blue = 0; rgb1.AlphaValue = 255; ESRI.ArcGIS.ADF.ArcGISServer.SimpleFillSymbol sfs1;sfs1 = new ESRI.ArcGIS.ADF.ArcGISServer.SimpleFillSymbol(); sfs1.Style = ESRI.ArcGIS.ADF.ArcGISServer.esriSimpleFillStyle.esriSFSForwardDiagonal;sfs1.Color = rgb1; ESRI.ArcGIS.ADF.ArcGISServer.PolygonElement polyelement1; polyelement1 = new ESRI.ArcGIS.ADF.ArcGISServer.PolygonElement(); polyelement1.Symbol = sfs1; polyelement1.Polygon = buffer_polyn;

[VB]

Dim rgb1 As New ESRI.ArcGIS.ADF.ArcGISServer.RgbColor()rgb1.Red = 255rgb1.Green = 255rgb1.Blue = 0rgb1.AlphaValue = 255

Dim sfs1 As New ESRI.ArcGIS.ADF.ArcGISServer.SimpleFillSymbol()sfs1.Style = ESRI.ArcGIS.ADF.ArcGISServer.esriSimpleFillStyle.esriSFSForwardDiagonal

16.

Accessing ArcGIS Server from a Web application http://edndoc.esri.com/arcobjects/9.2/NET_Server_Doc/developer/ADF/...

6 of 9 7/21/2011 10:37 PM

Page 7: Accessing ArcGIS Server From a Web Application

sfs1.Color = rgb1

Dim polyelement1 As New ESRI.ArcGIS.ADF.ArcGISServer.PolygonElement()polyelement1.Symbol = sfs1polyelement1.Polygon = buffer_polyn

Both the MarkerElement to display the user-provided point andthe PolygonElement to display the ArcObjects generated buffer polygon areready to added to the MapFunctionality MapDescription as customgraphics. The CustomGraphics property on the MapDescription Value objectaccepts an array of GraphicElement Value objects. Both MarkerElement andPolygonElement derive from the GraphicElement base class. So all we needto do is create a new GraphicElement array and initialize it with the numberof elements. Add the MarkerElement and PolygonElement to the array andassign it to the MapDescription.CustomGraphics property. [C#]

ESRI.ArcGIS.ADF.ArcGISServer.GraphicElement[] ges; ges = new ESRI.ArcGIS.ADF.ArcGISServer.GraphicElement[2]; ges[0] = marker; ges[1] = polyelement1; mapDescription.CustomGraphics = ges;

[VB]

Dim polyelement1 As New ESRI.ArcGIS.ADF.ArcGISServer.PolygonElement()polyelement1.Symbol = sfs1polyelement1.Polygon = buffer_polyn

Dim ges(2) As ESRI.ArcGIS.ADF.ArcGISServer.GraphicElementges(0) = markerges(1) = polyelement1mapDescription.CustomGraphics = ges

17.

To inform the Map control that its content has changed, call theMap.Refresh() method. [C#]

mapctrl.Refresh();

[VB]

mapctrl.Refresh()

18.

Now that the implementation code for our custom tool is finished, we needto add a tool item to the Toolbar control to trigger the action that executesthe custom tool. Select the Toolbar control in design view or in theProperties window, then click the ellipsis for the ToolbarItems property. Inthe ToolbarItems Collection Editor dialog, add a new "Tool" item. In theToolbar Items section, select the Tool item and click the Add button. Thenew Tool should appear under the Current Toolbar Items section.

19.

Select the new Tool item and click the Show Properties button. A propertiesdialog for the new Tool should be displayed.

20.

Accessing ArcGIS Server from a Web application http://edndoc.esri.com/arcobjects/9.2/NET_Server_Doc/developer/ADF/...

7 of 9 7/21/2011 10:37 PM

Page 8: Accessing ArcGIS Server From a Web Application

Property Value Description

Text Point Buffer Tool Label for the tool in the Toolbar

ClientAction Point Client event passed to the server

Name PointBufferTool Object name of the tool, if used in code

ServerActionAssembly App_Code Class libraries associated with a Web site are compiled intoan assembly named App_Code

ServerActionClass PointBufferTool The name of the custom class which implementsIMapServerToolAction and will be executed when this toolis used in the map

Note that the EnablePostBack property is set to false by default. If false,using the tool at runtime will trigger an asynchronous callback. If true,using the tool will trigger a synchronous postback. Keep theEnablePostBack property set to "False". Set the following properties:

Run the application. Use the "Point Buffer Tool" tool by activating the tool inthe toolbar and clicking on the map. The initial mouse click will trigger acallback to execute the code in the PointBufferTool class. The custom tooladds graphics to the ArcGIS Server map resource and redraws the Mapcontrol. Each time the tool is applied, a new point and buffer polygon aredrawn as graphics in the map.

21.

Accessing ArcGIS Server from a Web application http://edndoc.esri.com/arcobjects/9.2/NET_Server_Doc/developer/ADF/...

8 of 9 7/21/2011 10:37 PM

Page 9: Accessing ArcGIS Server From a Web Application

Note: graphics in a Web ADF application can be rendered at three levels:the resource, the Web-tier, or the client tier. This walkthrough is anexample of working with graphics at the resource level. For more discussionon different options for creating graphics with a Web ADF application, seethe section on Graphics Layers.

Accessing ArcGIS Server from a Web application http://edndoc.esri.com/arcobjects/9.2/NET_Server_Doc/developer/ADF/...

9 of 9 7/21/2011 10:37 PM