You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
294 lines
9.4 KiB
294 lines
9.4 KiB
using System; |
|
using System.Collections.Generic; |
|
using System.Linq; |
|
using System.Text; |
|
using ESRI.ArcGIS.Controls; |
|
using ESRI.ArcGIS.Geometry; |
|
using ESRI.ArcGIS.Carto; |
|
using ESRI.ArcGIS.SystemUI; |
|
using ESRI.ArcGIS.Geodatabase; |
|
using KGIS.Framework.Utils; |
|
|
|
namespace Kingo.Plugin.MapView.Commands |
|
{ |
|
public class ControlsMapFullExtent : ICommand |
|
{ |
|
private IHookHelper m_hookHelper; |
|
//ControlsMapFullExtentCommandClass mapFull = new ControlsMapFullExtentCommandClass(); |
|
public void OnCreate(object hook) |
|
{ |
|
if (m_hookHelper == null) |
|
{ |
|
m_hookHelper = new HookHelperClass |
|
{ |
|
Hook = hook |
|
}; |
|
} |
|
} |
|
public void OnClick() |
|
{ |
|
//IEnvelope envelop = null; |
|
//mapFull.OnClick(); |
|
//for (int i = 0; i < m_hookHelper.FocusMap.LayerCount; i++) |
|
//{ |
|
// Common.Utility.LayerHelper.GetIEnvelope(m_hookHelper.FocusMap.get_Layer(i), ref envelop); |
|
//} |
|
//if (envelop != null) |
|
//{ |
|
// (m_hookHelper.FocusMap as IActiveView).Extent = envelop; |
|
//} |
|
m_hookHelper = new HookHelperClass |
|
{ |
|
Hook = KGIS.Framework.Maps.MapsManager.Instance.MapService.getAxMapControl().Object |
|
}; |
|
RoomToMap(m_hookHelper.FocusMap); |
|
} |
|
|
|
#region |
|
public bool RoomToMap(IMap pMap) |
|
{ |
|
try |
|
{ |
|
if (pMap == null) |
|
{ |
|
return false; |
|
} |
|
IActiveView pActiveView = pMap as IActiveView; |
|
double minValue = double.MinValue; |
|
double maxValue = double.MaxValue; |
|
double dlYMax = double.MinValue; |
|
double dlYMin = double.MaxValue; |
|
ILayer pLayer = null; |
|
//IFeatureLayer layer2 = null; |
|
for (int i = 0; i < pMap.LayerCount; i++) |
|
{ |
|
pLayer = pMap.get_Layer(i); |
|
//layer2 = pLayer as IFeatureLayer; |
|
//if ((layer2 != null) && (layer2.FeatureClass != null)) |
|
//{ |
|
// string str = TrimUserName((layer2.FeatureClass as IDataset).BrowseName); |
|
// if (((str == DBConst.TB_LSD) || (str == DBConst.TB_LSX)) || (str == DBConst.TB_LSM)) |
|
// { |
|
// continue; |
|
// } |
|
//} |
|
if (pLayer is ICompositeLayer) |
|
{ |
|
GetCompositeLayerSideCoordinate(pLayer as ICompositeLayer, ref minValue, ref maxValue, ref dlYMax, ref dlYMin); |
|
|
|
} |
|
else |
|
{ |
|
GetLayerSideCoordinate(pLayer, ref minValue, ref maxValue, ref dlYMax, ref dlYMin); |
|
} |
|
} |
|
if ((((minValue == double.MinValue) && (maxValue == double.MaxValue)) && (dlYMax == double.MinValue)) && (dlYMin == double.MaxValue)) |
|
{ |
|
pActiveView.Extent = pActiveView.FullExtent; |
|
PartialRefresh(pActiveView); |
|
} |
|
else |
|
{ |
|
IEnvelope pGeometry = new EnvelopeClass();//GetEnvByCoor(minValue, maxValue, dlYMax, dlYMin); |
|
pGeometry.XMax = minValue; |
|
pGeometry.XMin = maxValue; |
|
pGeometry.YMax = dlYMax; |
|
pGeometry.YMin = dlYMin; |
|
|
|
LocateGeometry(pActiveView, pGeometry, 0.2); |
|
} |
|
|
|
return true; |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug(ex); |
|
return false; |
|
} |
|
finally |
|
{ |
|
|
|
} |
|
} |
|
|
|
|
|
private bool GetCompositeLayerSideCoordinate(ICompositeLayer pCompositeLayer, ref double dlXMax, ref double dlXMin, ref double dlYMax, ref double dlYMin) |
|
{ |
|
if (pCompositeLayer == null) |
|
{ |
|
return false; |
|
} |
|
for (int i = 0; i < pCompositeLayer.Count; i++) |
|
{ |
|
ILayer pLayer = pCompositeLayer.get_Layer(i); |
|
if (pLayer is ICompositeLayer) |
|
{ |
|
if (!GetCompositeLayerSideCoordinate(pLayer as ICompositeLayer, ref dlXMax, ref dlXMin, ref dlYMax, ref dlYMin)) |
|
{ |
|
return false; |
|
} |
|
} |
|
else if (!GetLayerSideCoordinate(pLayer, ref dlXMax, ref dlXMin, ref dlYMax, ref dlYMin)) |
|
{ |
|
return false; |
|
} |
|
} |
|
return true; |
|
} |
|
|
|
private bool GetLayerSideCoordinate(ILayer pLayer, ref double dlXMax, ref double dlXMin, ref double dlYMax, ref double dlYMin) |
|
{ |
|
if (pLayer == null || !pLayer.Valid) |
|
{ |
|
return false; |
|
} |
|
if (pLayer.Name.ToUpper() == "DEFAULT") |
|
return true; |
|
if (pLayer is ITable) |
|
{ |
|
try |
|
{ |
|
if ((pLayer as ITable).RowCount(null) == 0) |
|
{ |
|
return true; |
|
} |
|
} |
|
catch (Exception) |
|
{ |
|
} |
|
} |
|
IEnvelope areaOfInterest = pLayer.AreaOfInterest; |
|
if (areaOfInterest != null) |
|
{ |
|
dlXMax = Math.Max(dlXMax, areaOfInterest.XMax); |
|
dlXMin = Math.Min(dlXMin, areaOfInterest.XMin); |
|
dlYMax = Math.Max(dlYMax, areaOfInterest.YMax); |
|
dlYMin = Math.Min(dlYMin, areaOfInterest.YMin); |
|
} |
|
return true; |
|
} |
|
|
|
|
|
public bool LocateGeometry(IActiveView pActiveView, IGeometry pGeometry, double dblRatio) |
|
{ |
|
try |
|
{ |
|
if ((pGeometry == null) || (pActiveView == null)) |
|
{ |
|
return false; |
|
} |
|
if (pGeometry.IsEmpty) |
|
{ |
|
return false; |
|
} |
|
if ((pGeometry is IPoint) || (pGeometry is IMultipoint)) |
|
{ |
|
ITopologicalOperator @operator = pGeometry as ITopologicalOperator; |
|
@operator.Simplify(); |
|
pGeometry = @operator.Buffer(100.0); |
|
} |
|
IEnvelope envelope = pGeometry.Envelope; |
|
IPoint p = new PointClass(); |
|
if (envelope != null) |
|
{ |
|
p.X = (envelope.XMin + envelope.XMax) / 2.0; |
|
p.Y = (envelope.YMin + envelope.YMax) / 2.0; |
|
} |
|
double num = pActiveView.Extent.Width / pActiveView.Extent.Height; |
|
double num2 = envelope.Width / envelope.Height; |
|
if (num > num2) |
|
{ |
|
envelope.Width = envelope.Height * num; |
|
} |
|
else |
|
{ |
|
envelope.Height = envelope.Width / num; |
|
} |
|
envelope.Expand(1.0 + dblRatio, 1.0 + dblRatio, true); |
|
envelope.CenterAt(p); |
|
if (envelope.SpatialReference != pActiveView.FocusMap.SpatialReference) |
|
{ |
|
envelope.Project(pActiveView.FocusMap.SpatialReference); |
|
} |
|
pActiveView.Extent = envelope; |
|
//pActiveView.Extent.PutCoords(envelope.XMin, envelope.YMin, envelope.XMax, envelope.YMax); |
|
PartialRefresh(pActiveView); |
|
pActiveView.ScreenDisplay.UpdateWindow(); |
|
return true; |
|
} |
|
catch (Exception) |
|
{ |
|
return false; |
|
} |
|
} |
|
public bool PartialRefresh(IActiveView pActiveView) |
|
{ |
|
if (pActiveView == null) |
|
{ |
|
return false; |
|
} |
|
PartialRefresh(pActiveView, esriViewDrawPhase.esriViewForeground | esriViewDrawPhase.esriViewGraphicSelection | esriViewDrawPhase.esriViewGraphics | esriViewDrawPhase.esriViewGeoSelection | esriViewDrawPhase.esriViewGeography | esriViewDrawPhase.esriViewBackground); |
|
return true; |
|
} |
|
public bool PartialRefresh(IActiveView pActiveView, esriViewDrawPhase enumViewDrawPhase) |
|
{ |
|
if (pActiveView == null) |
|
{ |
|
return false; |
|
} |
|
pActiveView.PartialRefresh(enumViewDrawPhase, null, pActiveView.Extent); |
|
return true; |
|
} |
|
#endregion |
|
|
|
public int Bitmap |
|
{ |
|
get; |
|
} |
|
|
|
public string Caption |
|
{ |
|
get; |
|
} |
|
|
|
public string Category |
|
{ |
|
get; |
|
} |
|
|
|
public bool Checked |
|
{ |
|
get; |
|
} |
|
|
|
public bool Enabled |
|
{ |
|
get { return true; } |
|
} |
|
|
|
public int HelpContextID |
|
{ |
|
get; |
|
} |
|
|
|
public string HelpFile |
|
{ |
|
get; |
|
} |
|
|
|
public string Message |
|
{ |
|
get; |
|
} |
|
|
|
public string Name |
|
{ |
|
get; |
|
} |
|
|
|
public string Tooltip |
|
{ |
|
get; |
|
} |
|
} |
|
}
|
|
|