using System;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Location;
using ESRI.ArcGIS.Geometry;
namespace ZoomToEvent
{
class Program
{
static void Main(string[] args)
{
try
{
//Get license.
ESRI.ArcGIS.RuntimeManager.BindLicense(ESRI.ArcGIS.ProductCode.EngineOrDesktop);
//Open a map document with event tables and displayed event layers.
MapDocumentClass pMapDocumentClass = new MapDocumentClass();
string path = "C:\\temp\\Test.mxd";
pMapDocumentClass.Open(path, string.Empty);
IMapDocument pMapDocument = pMapDocumentClass;
IMap pMap = pMapDocument.ActiveView.FocusMap;
ILayer pLayer;
IFeatureLayer2 pFl;
IFeatureClass pFc;
IDataLayer2 pDLayer;
IRouteEventSourceName pESN;
IDatasetName pDSN;
IFeature pF;
IEnvelope pEnv;
IGeometry pGeo;
IFeatureCursor pFcursor;
Console.WriteLine("Checking " + path);
Console.WriteLine();
for (int i = 0; i < pMap.LayerCount; i++)//Loop TOC for displayed route events
{
if (pMap.get_Layer(i) is IFeatureLayer)
{
pLayer = pMap.get_Layer(i);
pFl = (IFeatureLayer2)(pLayer);
pFc = pFl.FeatureClass;
if (pFc is IRouteEventSource)
{
//Identify source table of event data.
pDLayer = (IDataLayer2)pLayer;
pESN = (IRouteEventSourceName)pDLayer.DataSourceName;
pDSN = (IDatasetName)pESN.EventTableName;
Console.WriteLine("Found displayed event layer.");
Console.WriteLine(" Layer Name: " + pLayer.Name);
Console.WriteLine(" Source Table: " + pDSN.Name);
//Print first record's envelope extent - use for display extent...
pFcursor = pFc.Search(null, false);
pF = pFcursor.NextFeature();
pGeo = pF.Shape;
pEnv = pGeo.Envelope;
Console.WriteLine(" First record's extent: ");
Console.WriteLine(" " +pEnv.XMax + ", " + pEnv.YMax + ", " + pEnv.XMin + ", " + pEnv.YMin);
Console.WriteLine();
}
}
}
}
catch (Exception e)
{
Console.WriteLine("{0} Exception caught.", e);
}
Console.ReadLine();
}
}
}
private void timer1_Tick(object sender, EventArgs e)
{
ESRI.ArcGIS.Carto.IActiveView pAV;
ESRI.ArcGIS.Carto.IMap pMap;
ESRI.ArcGIS.Geodatabase.IEnumFeature pEnumF;
ESRI.ArcGIS.Geodatabase.IFeature pF;
IDocument doc2 = m_application.Document;
IMxDocument mxdoc2 = (IMxDocument)doc2;
IMap map2= mxdoc2.FocusMap;
ITable table = (ITable)(map2.get_Layer(0) as IFeatureSelection);
QueryFilter searchFilter;
double minX, minY, maxX, maxY;
minX = 45600048.45;
maxX = 0;
minY = 80000054.56;
maxY = 0;
foreach (object cekirani in checkedListBox2.CheckedItems)
{
int d = cekirani.ToString().IndexOf(',');
//MessageBox.Show(cekirani.ToString().Remove(d));
searchFilter = new QueryFilter();
searchFilter.WhereClause = "Ime='"+cekirani.ToString().Remove(d)+"'";
ICursor kursor=(ICursor)table.Search(searchFilter,true);
IRow row = kursor.NextRow();
int ime=row.Fields.FindField("Ime");
int alias = row.Fields.FindField("Alias");
int iks = row.Fields.FindField("X");
int ipsilon = row.Fields.FindField("Y");
while(row!=null)
{
if (Convert.ToDouble(row.get_Value(iks))<minX)
minX = Convert.ToDouble(row.get_Value(iks));
if (Convert.ToDouble(row.get_Value(iks))>maxX)
maxX = Convert.ToDouble(row.get_Value(iks));
if (Convert.ToDouble(row.get_Value(ipsilon))<minY)
minY = Convert.ToDouble(row.get_Value(ipsilon));
if (Convert.ToDouble(row.get_Value(ipsilon))>maxY)
maxY = Convert.ToDouble(row.get_Value(ipsilon));
row = kursor.NextRow();
}
}
pMap = (IMap)map2;
pEnumF = (IEnumFeature)pMap.FeatureSelection;
pF = pEnumF.Next();
ESRI.ArcGIS.Geometry.IEnvelope pEnv;
pEnv = new EnvelopeClass();
pEnv.SetEmpty();
pEnv.XMin = minX;
pEnv.XMax = maxX;
pEnv.YMin = minY;
pEnv.YMax = maxY;
pEnv.Expand(2.5,2.5,true);
pAV = mxdoc2.ActiveView;
pAV.Extent = pEnv;
pAV.Refresh();
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
IMap pMap = pMxDoc.FocusMap;
//Clear all selected features.
pMap.FeatureSelection.Clear();
IFeatureLayer pFl = (IFeatureLayer)pMap.get_Layer(0);
IFeatureClass pFc = pFl.FeatureClass;
IQueryFilter pQf = new QueryFilterClass();
pQf.WhereClause = pFc.OIDFieldName + " = " + listBox1.SelectedItem;
IFeatureCursor pFcursor = pFc.Search(pQf, false);
IFeature pF = pFcursor.NextFeature();
IFeatureSelection pFsel = (IFeatureSelection)pFl;
ISelectionSet pSel = pFsel.SelectionSet;
if (pF != null)
{
pSel.Add(Convert.ToInt32(listBox1.SelectedItem));
ZoomToFeature(pF);//method called to zoom to feature extent.
}
}
catch (Exception ex)
{
MessageBox.Show("Exception caught." + ex);
}
}
private void timer1_Tick(object sender, EventArgs e)
{
ESRI.ArcGIS.Carto.IActiveView pAV;
ESRI.ArcGIS.Carto.IMap pMap;
ESRI.ArcGIS.Geodatabase.IEnumFeature pEnumF;
ESRI.ArcGIS.Geodatabase.IFeature pF;
IDocument doc2 = m_application.Document;
IMxDocument mxdoc2 = (IMxDocument)doc2;
IMap map2= mxdoc2.FocusMap;
ITable table = (ITable)(map2.get_Layer(0) as IFeatureSelection);
QueryFilter searchFilter;
double minX, minY, maxX, maxY;
minX = 45600048.45;
maxX = 0;
minY = 80000054.56;
maxY = 0;
foreach (object cekirani in checkedListBox2.CheckedItems)
{
int d = cekirani.ToString().IndexOf(',');
//MessageBox.Show(cekirani.ToString().Remove(d));
searchFilter = new QueryFilter();
searchFilter.WhereClause = "Ime='"+cekirani.ToString().Remove(d)+"'";
ICursor kursor=(ICursor)table.Search(searchFilter,true);
IRow row = kursor.NextRow();
int ime=row.Fields.FindField("Ime");
int alias = row.Fields.FindField("Alias");
int iks = row.Fields.FindField("X");
int ipsilon = row.Fields.FindField("Y");
while(row!=null)
{
if (Convert.ToDouble(row.get_Value(iks))<minX)
minX = Convert.ToDouble(row.get_Value(iks));
if (Convert.ToDouble(row.get_Value(iks))>maxX)
maxX = Convert.ToDouble(row.get_Value(iks));
if (Convert.ToDouble(row.get_Value(ipsilon))<minY)
minY = Convert.ToDouble(row.get_Value(ipsilon));
if (Convert.ToDouble(row.get_Value(ipsilon))>maxY)
maxY = Convert.ToDouble(row.get_Value(ipsilon));
row = kursor.NextRow();
}
}
pMap = (IMap)map2;
pEnumF = (IEnumFeature)pMap.FeatureSelection;
pF = pEnumF.Next();
ESRI.ArcGIS.Geometry.IEnvelope pEnv;
pEnv = new EnvelopeClass();
pEnv.SetEmpty();
pEnv.XMin = minX;
pEnv.XMax = maxX;
pEnv.YMin = minY;
pEnv.YMax = maxY;
pEnv.Expand(2.5,2.5,true);
pAV = mxdoc2.ActiveView;
pAV.Extent = pEnv;
pAV.Refresh();
}