📄 layervisibility.cs
字号:
// Copyright 2006 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 use restrictions at /arcgis/developerkit/userestrictions.
using ESRI.ArcGIS.ADF.BaseClasses;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.SystemUI;
namespace UI
{
public sealed class LayerVisibility : BaseCommand, ICommandSubType
{
private IHookHelper m_hookHelper = new HookHelperClass();
private long m_subType;
public LayerVisibility()
{
}
public override void OnClick()
{
for (int i = 0; i <= m_hookHelper.FocusMap.LayerCount - 1; i++)
{
if (m_subType == 1) m_hookHelper.FocusMap.get_Layer(i).Visible = true;
if (m_subType == 2) m_hookHelper.FocusMap.get_Layer(i).Visible = false;
}
m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
}
public override void OnCreate(object hook)
{
m_hookHelper.Hook = hook;
}
public int GetCount()
{
return 2;
}
public void SetSubType(int SubType)
{
m_subType = SubType;
}
public override string Caption
{
get
{
if (m_subType == 1) return "Turn All Layers On";
else return "Turn All Layers Off";
}
}
public override bool Enabled
{
get
{
bool enabled = false; int i;
if (m_subType == 1)
{
for (i = 0; i <= m_hookHelper.FocusMap.LayerCount - 1; i++)
{
if (m_hookHelper.ActiveView.FocusMap.get_Layer(i).Visible == false)
{
enabled = true;
break;
}
}
}
else
{
for (i = 0; i <= m_hookHelper.FocusMap.LayerCount - 1; i++)
{
if (m_hookHelper.ActiveView.FocusMap.get_Layer(i).Visible == true)
{
enabled = true;
break;
}
}
}
return enabled;
}
}
}
public sealed class LayerSelectable : BaseCommand, ICommandSubType
{
private IMapControl3 m_mapControl;
private long m_subType;
public LayerSelectable()
{
}
public override void OnClick()
{
IFeatureLayer layer = (IFeatureLayer)m_mapControl.CustomProperty;
if (m_subType == 1) layer.Selectable = true;
if (m_subType == 2) layer.Selectable = false;
}
public override void OnCreate(object hook)
{
m_mapControl = (IMapControl3)hook;
}
public override bool Enabled
{
get
{
ILayer layer = (ILayer)m_mapControl.CustomProperty;
if (layer is IFeatureLayer)
{
IFeatureLayer featureLayer = (IFeatureLayer)layer;
if (m_subType == 1) return !featureLayer.Selectable;
else return featureLayer.Selectable;
}
else
{
return false;
}
}
}
public int GetCount()
{
return 2;
}
public void SetSubType(int SubType)
{
m_subType = SubType;
}
public override string Caption
{
get
{
if (m_subType == 1) return "Layer Selectable";
else return "Layer Unselectable";
}
}
}
public sealed class RemoveLayer : BaseCommand
{
private IMapControl3 m_mapControl;
public RemoveLayer()
{
base.m_caption = "Remove Layer";
}
public override void OnClick()
{
ILayer layer = (ILayer)m_mapControl.CustomProperty;
m_mapControl.Map.DeleteLayer(layer);
}
public override void OnCreate(object hook)
{
m_mapControl = (IMapControl3)hook;
}
}
public class ScaleThresholds : BaseCommand, ICommandSubType
{
private IMapControl3 m_mapControl;
private long m_subType;
public ScaleThresholds()
{
}
public override void OnClick()
{
ILayer layer = (ILayer)m_mapControl.CustomProperty;
if (m_subType == 1) layer.MaximumScale = m_mapControl.MapScale;
if (m_subType == 2) layer.MinimumScale = m_mapControl.MapScale;
if (m_subType == 3)
{
layer.MaximumScale = 0;
layer.MinimumScale = 0;
}
m_mapControl.Refresh(esriViewDrawPhase.esriViewGeography, null, null);
}
public override void OnCreate(object hook)
{
m_mapControl = (IMapControl3)hook;
}
public int GetCount()
{
return 3;
}
public void SetSubType(int SubType)
{
m_subType = SubType;
}
public override string Caption
{
get
{
if (m_subType == 1) return "Set Maximum Scale";
else if (m_subType == 2) return "Set Minimum Scale";
else return "Remove Scale Thresholds";
}
}
public override bool Enabled
{
get
{
bool enabled = true;
ILayer layer = (ILayer)m_mapControl.CustomProperty;
if (m_subType == 3)
{
if ((layer.MaximumScale == 0) & (layer.MinimumScale == 0)) enabled = false;
}
return enabled;
}
}
}
public sealed class ZoomToLayer : BaseCommand
{
private IMapControl3 m_mapControl;
public ZoomToLayer()
{
base.m_caption = "Zoom To Layer";
}
public override void OnClick()
{
ILayer layer = (ILayer)m_mapControl.CustomProperty;
m_mapControl.Extent = layer.AreaOfInterest;
}
public override void OnCreate(object hook)
{
m_mapControl = (IMapControl3)hook;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -