iselection取消高亮显示
时间: 2023-12-19 17:04:00 浏览: 19
要取消iSelection中的高亮显示,您可以使用以下代码:
```javascript
window.getSelection().removeAllRanges();
```
这将从文档中删除所有选定的文本范围,从而取消高亮显示。您可以将此代码放在适当的事件处理程序中,例如点击事件或失去焦点事件。
相关问题
arcengine选择要素代码
以下是使用 ArcEngine API 选择要素的示例代码:
```c#
// 获取当前地图控件中的工作空间
IWorkspace workspace = ((IMxDocument)ArcMap.Application.Document).FocusMap.Layer[0].FeatureClass.Workspace;
// 获取要素类
IFeatureClass featureClass = workspace.OpenFeatureClass("要素类名称");
// 创建查询过滤器
IQueryFilter queryFilter = new QueryFilterClass();
queryFilter.WhereClause = "字段名 = '字段值'";
// 执行查询
IFeatureCursor featureCursor = featureClass.Search(queryFilter, true);
// 选择要素
ISelection selection = (ISelection)featureClass;
ISelectionSet selectionSet = selection.SelectionSet;
selectionSet.Clear();
IFeature feature = featureCursor.NextFeature();
while (feature != null)
{
selectionSet.Add(feature.OID);
feature = featureCursor.NextFeature();
}
// 刷新地图控件
IMxDocument mxDocument = (IMxDocument)ArcMap.Application.Document;
mxDocument.ActiveView.Refresh();
```
其中,需要将“要素类名称”和“字段名 = '字段值'”替换为实际的要素类名称和查询条件。此代码将根据查询条件选择要素,并在地图控件中高亮显示选定要素。
ArcEngine 编写ITool工具获取鼠标框选内容
在 ArcEngine 中编写 ITool 工具获取鼠标框选内容,可以按照以下步骤进行:
1. 实现 ITool 接口,重写 OnMouseDown、OnMouseMove、OnMouseUp 等方法,以响应鼠标事件。
2. 在 OnMouseDown 方法中记录鼠标按下时的位置,并在 OnMouseUp 方法中记录鼠标抬起时的位置,计算出鼠标框选的矩形范围。
3. 在 OnMouseMove 方法中判断鼠标是否处于框选状态,如果是,则根据框选范围执行相应的操作,比如选择要素、高亮显示等。
4. 在 ITool 工具中可以通过 IMap 接口和 ISelection 接口来获取当前地图和选择集对象,从而实现对地图和图层上要素的操作。
以下是一个简单的示例代码:
```c#
public class SelectionTool : ITool
{
private IMap m_map;
private bool m_isSelecting;
private IEnvelope m_selectionEnvelope;
private ISelection m_selection;
public void OnMouseDown(int button, int shift, int x, int y)
{
if (button == 1)
{
m_isSelecting = true;
m_selectionEnvelope = new EnvelopeClass();
m_selectionEnvelope.XMin = x;
m_selectionEnvelope.YMin = y;
m_selectionEnvelope.XMax = x;
m_selectionEnvelope.YMax = y;
}
}
public void OnMouseMove(int button, int shift, int x, int y)
{
if (m_isSelecting)
{
m_selectionEnvelope.XMax = x;
m_selectionEnvelope.YMax = y;
IGeometry selectionGeometry = m_selectionEnvelope as IGeometry;
m_map.SelectByShape(selectionGeometry, null, false);
m_selection = m_map.FeatureSelection;
m_map.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
}
}
public void OnMouseUp(int button, int shift, int x, int y)
{
if (m_isSelecting)
{
m_isSelecting = false;
m_selectionEnvelope.XMax = x;
m_selectionEnvelope.YMax = y;
IGeometry selectionGeometry = m_selectionEnvelope as IGeometry;
m_map.SelectByShape(selectionGeometry, null, false);
m_selection = m_map.FeatureSelection;
m_map.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
}
}
public void OnCreate(IMap map)
{
m_map = map;
}
public bool Enabled
{
get { return true; }
}
public int Cursor
{
get { return (int)esriSystemMouseCursor.esriSystemMouseCursorCrosshair; }
}
public void OnKeyDown(int keyCode, int shift)
{
}
public void OnKeyUp(int keyCode, int shift)
{
}
public string Name
{
get { return "SelectionTool"; }
}
public void OnDoubleClick()
{
}
public void OnContextMenu(int x, int y)
{
}
public void Refresh(int hDC)
{
}
public void OnDeactivate()
{
}
public int HelpContextID
{
get { return 0; }
}
public string HelpFile
{
get { return ""; }
}
public string Message
{
get { return "Use the mouse to select features."; }
}
public void OnActivate()
{
}
public void OnFocus(int x, int y)
{
}
public void OnBlur()
{
}
}
```
在上述代码中,我们实现了一个简单的 ITool 工具,用于在地图上进行鼠标框选,并将框选的要素进行选择。在 OnMouseMove 方法中,我们通过 IMap 接口的 SelectByShape 方法来进行要素选择,并通过 PartialRefresh 方法来更新地图的显示。在实际开发中,我们可以根据具体需求对代码进行修改和扩展。