Draw Point
This commit is contained in:
parent
c0df38bbf9
commit
0c97cd4d42
@ -30,8 +30,20 @@
|
||||
<MenuItem x:Name="Menu_Click_Indentify" Header="点击查询" Click="Menu_Click_Indentify_OnClick"></MenuItem>
|
||||
<MenuItem x:Name="Menu_Identify_Indentify" Header="Indentify查询" Click="Menu_Identify_Indentify_OnClick"></MenuItem>
|
||||
</MenuItem>
|
||||
<MenuItem x:Name="Menu_Symbology" Header="符号系统">
|
||||
<MenuItem x:Name="Menu_Point_Add_Layer" Header="添加图层" Click="Menu_OpenShp_Click"></MenuItem>
|
||||
<MenuItem x:Name="Menu_Point_Draw_Point" Header="画点" Click="Menu_Point_Symbol_Click"></MenuItem>
|
||||
<MenuItem x:Name="Menu_Point_Draw_Line" Header="画线" Click="Menu_Point_Draw_Line_OnClick"></MenuItem>
|
||||
<MenuItem x:Name="Menu_Point_Draw_Polygon" Header="画面" Click="Menu_Point_Draw_Polygon_OnClick"></MenuItem>
|
||||
<MenuItem x:Name="Menu_Layers_Options" Header="符号系统" Click="Menu_Layers_Options_OnClick"></MenuItem>
|
||||
</MenuItem>
|
||||
</Menu>
|
||||
<esri:MapView x:Name="MainMapView" Map="{Binding Map, Source={StaticResource MapViewModel}}" Margin="0,19,0,0" ViewpointChanged="MainMapView_OnViewpointChanged" GeoViewTapped="MainMapView_OnGeoViewTapped"/>
|
||||
<esri:MapView x:Name="MainMapView" Map="{Binding Map, Source={StaticResource MapViewModel}}" Margin="0,19,0,0" ViewpointChanged="MainMapView_OnViewpointChanged" GeoViewTapped="MainMapView_OnGeoViewTapped" MouseLeftButtonDown="MainMapView_OnMouseLeftButtonDown"/>
|
||||
<ListBox x:Name="LayerListBox" Width="143" SelectedIndex="0" RenderTransformOrigin="0.451,1.105" Margin="0,37,0,13" HorizontalAlignment="Left" PreviewMouseMove="LayerListBox_OnPreviewMouseMove" Drop="LayerListBox_OnDrop" ItemStringFormat="删除">
|
||||
<ListBox.ContextMenu>
|
||||
<ContextMenu/>
|
||||
</ListBox.ContextMenu>
|
||||
</ListBox>
|
||||
<Border BorderBrush="#FF8B1D76" BorderThickness="2,2,2,2" HorizontalAlignment="Right" Height="180" Width="202" VerticalAlignment="Top" IsEnabled="False">
|
||||
<esri:MapView x:Name="EagleMapView"/>
|
||||
</Border>
|
||||
|
||||
@ -31,6 +31,9 @@ enum CURRENTOPERATION
|
||||
SelectQuery = 0,
|
||||
IdentifyQuery,
|
||||
PanMap,
|
||||
DrawPoint,
|
||||
DrawLine,
|
||||
DrawPolygon,
|
||||
}
|
||||
|
||||
namespace GisDevelop_Exp
|
||||
@ -47,6 +50,13 @@ namespace GisDevelop_Exp
|
||||
|
||||
private ServiceFeatureTable _featureTable;
|
||||
|
||||
private List<MapPoint> linePoints;
|
||||
private List<Graphic> linesList;
|
||||
|
||||
private SimpleMarkerSymbol pointSymbol;
|
||||
private SimpleLineSymbol lineSymbol;
|
||||
private SimpleFillSymbol fillSymbol;
|
||||
|
||||
private readonly Dictionary<string, Basemap> _basemapOptions = new Dictionary<string, Basemap>()
|
||||
{
|
||||
{ "Streets (Raster)", new Basemap(BasemapStyle.OSMStreets) },
|
||||
@ -67,9 +77,19 @@ namespace GisDevelop_Exp
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
pointSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Circle, System.Drawing.Color.Blue, 3);
|
||||
lineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, System.Drawing.Color.Blue, 1);
|
||||
fillSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle.Solid, System.Drawing.Color.Blue,new SimpleLineSymbol(SimpleLineSymbolStyle.Solid,System.Drawing.Color.Pink,1));
|
||||
|
||||
linePoints = new List<MapPoint>();
|
||||
linesList = new List<Graphic>();
|
||||
|
||||
m_CurOper = CURRENTOPERATION.NullOpe;
|
||||
Initialize();
|
||||
EagleMapView.Map = new Map(BasemapStyle.ArcGISImageryStandard);
|
||||
GraphicsOverlay graphicLayer = new GraphicsOverlay();
|
||||
MainMapView.GraphicsOverlays.Add(graphicLayer);
|
||||
}
|
||||
|
||||
private void Initialize()
|
||||
@ -108,9 +128,10 @@ namespace GisDevelop_Exp
|
||||
ShapefileFeatureTable openedFeature = await ShapefileFeatureTable.OpenAsync(filePath);
|
||||
FeatureLayer opendFeatureLayer = new FeatureLayer(openedFeature);
|
||||
MainMapView.Map.OperationalLayers.Add(opendFeatureLayer);
|
||||
await MainMapView.SetViewpointGeometryAsync(opendFeatureLayer.FullExtent);
|
||||
await MainMapView.SetViewpointGeometryAsync(openedFeature.Extent);
|
||||
}
|
||||
}
|
||||
AddLayerNameToList();
|
||||
}
|
||||
|
||||
private async void OpenGeoDatabase()
|
||||
@ -135,14 +156,17 @@ namespace GisDevelop_Exp
|
||||
await table.LoadAsync();
|
||||
FeatureLayer layer = new FeatureLayer(table);
|
||||
layer.Name = table.TableName;
|
||||
geodatabaseMap.OperationalLayers.Add(layer);
|
||||
// geodatabaseMap.OperationalLayers.Add(layer);
|
||||
_featureLayer = layer;
|
||||
MainMapView.Map.OperationalLayers.Add(layer);
|
||||
}
|
||||
|
||||
Viewpoint geodatabaseViewPoint = new Viewpoint(_featureLayer.FullExtent);
|
||||
geodatabaseMap.InitialViewpoint = geodatabaseViewPoint;
|
||||
MainMapView.Map = geodatabaseMap;
|
||||
// geodatabaseMap.InitialViewpoint = geodatabaseViewPoint;
|
||||
MainMapView.Map.InitialViewpoint = geodatabaseViewPoint;
|
||||
// MainMapView.Map = geodatabaseMap;
|
||||
}
|
||||
AddLayerNameToList();
|
||||
}
|
||||
|
||||
private void Menu_OpenGeodatabase_Click(object sender, RoutedEventArgs e)
|
||||
@ -249,6 +273,7 @@ namespace GisDevelop_Exp
|
||||
pMap.OperationalLayers.Add(_featureLayer);
|
||||
MainMapView.Map = pMap;
|
||||
MainMapView.SelectionProperties.Color = Color.Cyan;
|
||||
AddLayerNameToList();
|
||||
}
|
||||
|
||||
private void BasemapChooser_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
@ -300,6 +325,7 @@ namespace GisDevelop_Exp
|
||||
FeatureLayer featureLayer = new FeatureLayer(portalItem, 0);
|
||||
map.OperationalLayers.Add(featureLayer);
|
||||
MainMapView.Map = map;
|
||||
AddLayerNameToList();
|
||||
}
|
||||
|
||||
private void MainMapView_OnGeoViewTapped(object? sender, GeoViewInputEventArgs e)
|
||||
@ -477,6 +503,190 @@ namespace GisDevelop_Exp
|
||||
aMap.InitialViewpoint = geodatabaseViewPoint;
|
||||
MainMapView.Map = aMap;
|
||||
}
|
||||
AddLayerNameToList();
|
||||
}
|
||||
|
||||
private void LayerListBox_OnPreviewMouseMove(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (e.LeftButton == System.Windows.Input.MouseButtonState.Pressed)
|
||||
{
|
||||
var pos = e.GetPosition(LayerListBox);
|
||||
if (pos.X < 20) return;
|
||||
System.Windows.Media.HitTestResult result =
|
||||
System.Windows.Media.VisualTreeHelper.HitTest(LayerListBox, pos);
|
||||
if (result == null) return;
|
||||
var listBoxItem = Utils.FindVisualParent<ListBoxItem>(result.VisualHit);
|
||||
|
||||
if (listBoxItem == null) return;
|
||||
DataObject dataObj = new DataObject(listBoxItem.Content as CheckBox);
|
||||
DragDrop.DoDragDrop(LayerListBox, dataObj, DragDropEffects.Move);
|
||||
}
|
||||
}
|
||||
|
||||
private void LayerListBox_OnDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
var pos = e.GetPosition(sender as ListBox);
|
||||
var result = System.Windows.Media.VisualTreeHelper.HitTest(LayerListBox, pos);
|
||||
if (result == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var sourcePerson = e.Data.GetData(typeof(CheckBox)) as CheckBox;
|
||||
if (sourcePerson == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var listBoxItem = Utils.FindVisualParent<ListBoxItem>(result.VisualHit);
|
||||
if (listBoxItem == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var targetPerson = listBoxItem.Content as CheckBox;
|
||||
if (ReferenceEquals(targetPerson, sourcePerson))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int targetIndex = LayerListBox.Items.IndexOf(targetPerson);
|
||||
int sourceIndex = LayerListBox.Items.IndexOf(sourcePerson);
|
||||
LayerListBox.Items.Remove(sourcePerson);
|
||||
LayerListBox.Items.Insert(targetIndex, sourcePerson);
|
||||
MoveLayer(sourcePerson.ToolTip as string,targetPerson.ToolTip as string);
|
||||
}
|
||||
|
||||
private void AddLayerNameToList()
|
||||
{
|
||||
LayerListBox.Items.Clear();
|
||||
LayerListBox.AllowDrop = true;
|
||||
LayerCollection pLayers = MainMapView.Map.OperationalLayers;
|
||||
if (pLayers.Count <= 0) return;
|
||||
for (int i = pLayers.Count - 1; i >= 0; i--)
|
||||
{
|
||||
CheckBox cb = new CheckBox()
|
||||
{
|
||||
Margin = new Thickness()
|
||||
{
|
||||
Left = 0,
|
||||
Top = 5,
|
||||
Right = 0,
|
||||
Bottom = 5
|
||||
}
|
||||
};
|
||||
Console.WriteLine(pLayers[i].Name);
|
||||
cb.Content = pLayers[i].Name;
|
||||
cb.ToolTip = pLayers[i].Name;
|
||||
cb.Name = pLayers[i].Name;
|
||||
cb.IsChecked = true;
|
||||
cb.Focusable = false;
|
||||
cb.Checked += new RoutedEventHandler(Checked_Layers_CheckBox);
|
||||
cb.Unchecked += new RoutedEventHandler(UnChecked_Layers_CheckBox);
|
||||
LayerListBox.Items.Add(cb);
|
||||
}
|
||||
}
|
||||
|
||||
private void UnChecked_Layers_CheckBox(object sender, RoutedEventArgs e)
|
||||
{
|
||||
CheckBox cb = sender as CheckBox;
|
||||
cb.IsChecked = false;
|
||||
int index = GetLayerIndex(cb.ToolTip as string);
|
||||
MainMapView.Map.OperationalLayers[index].IsVisible = false;
|
||||
}
|
||||
|
||||
private void Checked_Layers_CheckBox(object sender, RoutedEventArgs e)
|
||||
{
|
||||
CheckBox cb = sender as CheckBox;
|
||||
cb.IsChecked = true;
|
||||
int index = GetLayerIndex(cb.ToolTip as string);
|
||||
MainMapView.Map.OperationalLayers[index].IsVisible = true;
|
||||
}
|
||||
|
||||
internal static class Utils
|
||||
{
|
||||
public static T FindVisualParent<T>(DependencyObject obj) where T : class
|
||||
{
|
||||
while (obj != null)
|
||||
{
|
||||
if (obj is T)
|
||||
return obj as T;
|
||||
obj = System.Windows.Media.VisualTreeHelper.GetParent(obj);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private Layer GetLayer(string name)
|
||||
{
|
||||
LayerCollection pLayers = MainMapView.Map.OperationalLayers;
|
||||
for (int i = pLayers.Count - 1; i >= 0; i--)
|
||||
{
|
||||
if (pLayers[i].Name.Equals(name))
|
||||
{
|
||||
return pLayers[i];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void MoveLayer(string sourceLayer, string targetLayer)
|
||||
{
|
||||
LayerCollection pLayers = MainMapView.Map.OperationalLayers;
|
||||
Layer sourcLayer = GetLayer(sourceLayer);
|
||||
pLayers.Remove(sourcLayer);
|
||||
int targerIndex = GetLayerIndex(targetLayer);
|
||||
}
|
||||
|
||||
private int GetLayerIndex(string name)
|
||||
{
|
||||
LayerCollection pLayers = MainMapView.Map.OperationalLayers;
|
||||
for (int i = pLayers.Count - 1; i >= 0; i--)
|
||||
{
|
||||
if (pLayers[i].Name.Equals(name))
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
private void Menu_Point_Symbol_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
m_CurOper = CURRENTOPERATION.DrawPoint;
|
||||
}
|
||||
|
||||
private void MainMapView_OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
IInputElement mv = (IInputElement)sender;
|
||||
MapPoint location = MainMapView.ScreenToLocation(e.GetPosition(mv));
|
||||
|
||||
if (m_CurOper == CURRENTOPERATION.DrawPoint)
|
||||
{
|
||||
Graphic gPT = new Graphic(location, pointSymbol);
|
||||
MainMapView.GraphicsOverlays[0].Graphics.Add(gPT);
|
||||
}
|
||||
}
|
||||
|
||||
private void Menu_Layers_Options_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
OptionsWindow op = new OptionsWindow();
|
||||
op.PointSymbol = pointSymbol;
|
||||
op.LineSymbol = lineSymbol;
|
||||
op.FillSymbol = fillSymbol;
|
||||
op.ShowDialog();
|
||||
}
|
||||
|
||||
private void Menu_Point_Draw_Line_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
m_CurOper = CURRENTOPERATION.DrawLine;
|
||||
}
|
||||
|
||||
private void Menu_Point_Draw_Polygon_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
m_CurOper = CURRENTOPERATION.DrawPolygon;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user