Geoevents in a MapControl


PurposeThis sample demonstrates adding elements to a map's GraphicsContainer, then moving the elements in response to a timer. It also demonstrates setting a coordinate system and projecting data.

How to use

See How to use ArcGIS samples for help on compiling, setting up the debugger, and running the sample. If the sample has associated data, you will find that the sample's zip file includes a "data" folder alongside the language folders. However, you will need to update the sample to point to the location of the data once you have extracted all the files.

  1. Toggle between enabling and disabling GPS tracking.
  2. Use the left mouse button to zoom in and the other mouse buttons to buffer a point and create a polygon. If any of the agents are within the polygon, their symbology is changed.

Additional information

The application uses the AddShapeFile and AddLayerFromFile methods to load sample world data, which is then symbolized. The SpatialReference property of the MapControl is set to a projected coordinate system (esriSRProjCS_World_Mollweide). Points are created from an array containing latitude and longitude values and are given a SpatialReference property set to a geographic coordinate system (esriSRGeoCS_WGS1984). Each point is then projected onto the projected coordinate system of the MapControl and added to its GraphicsContainer.

When global positioning system (GPS) tracking is enabled by the user, a timer is used to randomly assign new x,y coordinates to each point within the GraphicsContainer after a specified time interval. Each point is projected onto the geographic coordinate system to ensure that it resides within the horizon of the esriSRGeoCS_WGS1984 coordinate system. Each point is then projected back onto the projected coordinate system (esriSRProjCS_World_Mollweide) of the MapControl before the graphics are refreshed to reflect the change in their geometry.

The OnMouseDown event uses either the TrackRectangle method to zoom in (if the left mouse button is used) or creates a point based on the location of the mouse (if the middle or right mouse button is used). A polygon is created by buffering the point using the ITopologicalOperator interface and drawn on the MapControl using the DrawShape method. Each element within the GraphicsContainer is tested using the IRelationalOperator interface to determine whether it is contained by the polygon. If a point is contained by the polygon, its symbol is then changed.

AssemblyInfo.cs Assembly information.
GeoEvents.cs Form file.
Download the C# files
AssemblyInfo.vb Assembly information.
GeoEvents.vb Form file.
Download the VB.NET files

Download the files for all languages

See Also:

MapControl class
IMapControl2 interface




Development licensing Deployment licensing
Engine Developer Kit Engine Runtime
ArcView
ArcEditor
ArcInfo