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.
330 lines
11 KiB
330 lines
11 KiB
using ESRI.ArcGIS.Carto; |
|
using ESRI.ArcGIS.Controls; |
|
using ESRI.ArcGIS.Geodatabase; |
|
using KGIS.Framework.AE; |
|
using KGIS.Framework.Maps; |
|
using KGIS.Framework.Utils; |
|
using Kingo.PluginServiceInterface; |
|
using System; |
|
using System.Collections.Generic; |
|
using System.Collections.ObjectModel; |
|
using System.ComponentModel; |
|
using System.IO; |
|
using System.Linq; |
|
using System.Text; |
|
using System.Threading.Tasks; |
|
using System.Windows; |
|
using System.Windows.Controls; |
|
using System.Windows.Data; |
|
using System.Windows.Documents; |
|
using System.Windows.Input; |
|
using System.Windows.Media; |
|
using System.Windows.Media.Animation; |
|
using System.Windows.Media.Imaging; |
|
using System.Windows.Navigation; |
|
using System.Windows.Shapes; |
|
using UIShell.OSGi; |
|
|
|
namespace Kingo.Plugin.BHTB_Extract.View |
|
{ |
|
/// <summary> |
|
/// MulitMapCatalog.xaml 的交互逻辑 |
|
/// </summary> |
|
public partial class MulitMapCatalog : Window |
|
{ |
|
Storyboard sbShow = null; |
|
Storyboard sbClose = null; |
|
Storyboard sbLoading = null; |
|
private System.Drawing.Point point; |
|
private AxMapControl axMapControl; |
|
private static MulitMapCatalog instance; |
|
bool isShow = false; |
|
|
|
LayerCfg layerInfo = null; |
|
private List<ILayer> mapLayers = new List<ILayer>(); |
|
|
|
MapTreeViewModel treeViewModel = new MapTreeViewModel(); |
|
bool isFirst = true; |
|
List<MapTreeViewModel> nodes = new List<MapTreeViewModel>(); |
|
private MulitMapCatalog(System.Drawing.Point topLeftPt, AxMapControl tempaxMapControl, List<ILayer> layers) |
|
{ |
|
this.point = topLeftPt; |
|
this.axMapControl = tempaxMapControl; |
|
this.mapLayers = layers; |
|
InitializeComponent(); |
|
|
|
} |
|
public static MulitMapCatalog Getlnstance(System.Drawing.Point topLeftPt, AxMapControl tempaxMapControl, List<ILayer> layers) |
|
{ |
|
if (instance == null) |
|
instance = new MulitMapCatalog(topLeftPt, tempaxMapControl, layers); |
|
else |
|
{ |
|
instance.point = topLeftPt; |
|
instance.axMapControl = tempaxMapControl; |
|
instance.mapLayers = layers; |
|
} |
|
return instance; |
|
} |
|
public void ShowWin() |
|
{ |
|
treeViewModel = new MapTreeViewModel(); |
|
isFirst = true; |
|
//0 |
|
//Top = point.Y + 29; |
|
//Left = point.X - 8; |
|
|
|
//1 |
|
Top = point.Y + 30; |
|
Left = point.X - 7; |
|
|
|
sbShow = this.Resources["ShowDetail"] as Storyboard; |
|
sbClose = this.Resources["CloseDetail"] as Storyboard; |
|
sbLoading = this.Resources["loading"] as Storyboard; |
|
sbLoading.Begin(); |
|
|
|
if (axMapControl != null && axMapControl.DocumentMap != null) |
|
{ |
|
byte[] contentArray = Convert.FromBase64String(axMapControl.DocumentMap); |
|
string LayerCfg = System.Text.Encoding.Default.GetString(contentArray); |
|
layerInfo = KGIS.Framework.Utils.SerializeAPI.DeserializeToObject<LayerCfg>(LayerCfg); |
|
} |
|
else |
|
{ |
|
ProjectInfo ProInfo = MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo; |
|
if (ProInfo.MulitMapData == null) |
|
ProInfo.MulitMapData = ProInfo.TempData; |
|
if (ProInfo != null && !string.IsNullOrWhiteSpace(ProInfo.MulitMapData)) |
|
{ |
|
byte[] contentArray = Convert.FromBase64String(ProInfo.MulitMapData); |
|
string LayerCfg = System.Text.Encoding.Default.GetString(contentArray); |
|
layerInfo = KGIS.Framework.Utils.SerializeAPI.DeserializeToObject<LayerCfg>(LayerCfg); |
|
} |
|
} |
|
//InitMapLayers(); |
|
if (layerInfo != null) |
|
{ |
|
nodes.Clear(); |
|
AddNodeTree(treeViewModel, layerInfo); |
|
} |
|
tvTypes.ItemsSource = new List<MapTreeViewModel>() { treeViewModel }; |
|
|
|
this.Show(); |
|
|
|
if (isShow) |
|
{ |
|
isShow = false; |
|
if (sbClose != null) |
|
sbClose.Begin(); |
|
} |
|
else |
|
{ |
|
isShow = true; |
|
if (sbShow != null) |
|
sbShow.Begin(); |
|
} |
|
} |
|
private void InitMapLayers() |
|
{ |
|
try |
|
{ |
|
mapLayers.Clear(); |
|
int layerCount = axMapControl.LayerCount; |
|
for (int i = 0; i < layerCount; i++) |
|
{ |
|
ILayer templayer = axMapControl.get_Layer(i); |
|
mapLayers.Add(templayer); |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
|
|
return; |
|
} |
|
} |
|
|
|
private void AddNodeTree(MapTreeViewModel treeViewModel, LayerCfg layerInfo) |
|
{ |
|
if (isFirst) |
|
{ |
|
isFirst = false; |
|
treeViewModel.PID = 0; |
|
treeViewModel.ID = 1; |
|
treeViewModel.IsChecked = layerInfo.Visible; |
|
treeViewModel.LayerName = layerInfo.LayerName; |
|
nodes.Add(treeViewModel); |
|
} |
|
for (int i = 0; i < layerInfo.Layers.Count; i++) |
|
{ |
|
MapTreeViewModel childTreeViewModel = new MapTreeViewModel(); |
|
childTreeViewModel.PID = treeViewModel.ID; |
|
childTreeViewModel.ID = treeViewModel.ID * 100 + i + 1; |
|
childTreeViewModel.IsChecked = layerInfo.Layers[i].Visible; |
|
childTreeViewModel.LayerName = layerInfo.Layers[i].LayerName; |
|
treeViewModel.Children.Add(childTreeViewModel); |
|
nodes.Add(childTreeViewModel); |
|
AddNodeTree(childTreeViewModel, layerInfo.Layers[i]); |
|
|
|
} |
|
|
|
} |
|
|
|
private void txtBox_Click(object sender, RoutedEventArgs e) |
|
{ |
|
try |
|
{ |
|
if (treeViewModel == null || treeViewModel.Children == null) return; |
|
CheckBox checkBox = sender as CheckBox; |
|
MapTreeViewModel parent = nodes.FirstOrDefault(a => a.LayerName == checkBox.Content.ToString()); |
|
if (parent == null) return; |
|
if (checkBox.Content.ToString() == treeViewModel.LayerName) |
|
{ |
|
if (!treeViewModel.IsChecked) |
|
{ |
|
UpdataMap(null, false); |
|
return; |
|
} |
|
} |
|
List<MapTreeViewModel> child = new List<MapTreeViewModel>(); |
|
GetChildMapTreeByParent(parent, child); |
|
|
|
UpdateLayer(child); |
|
|
|
//保存勾选记录 |
|
ProjectInfo ProInfo = MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo; |
|
layerInfo.GetAllItem().Find(a => a.LayerName == parent.LayerName).Visible = checkBox.IsChecked == true; |
|
Byte[] bytearr = System.Text.Encoding.Default.GetBytes(SerializeAPI.SerializeToXML<LayerCfg>(layerInfo)); |
|
string strBase64 = Convert.ToBase64String(bytearr); |
|
ProInfo.MulitMapData = strBase64; |
|
ProInfo.Save(); |
|
axMapControl.DocumentMap = ProInfo.MulitMapData; |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("更新图层列表失败!" + ex); |
|
return; |
|
} |
|
} |
|
|
|
private void UpdataMap(string LayerName, bool isChecked) |
|
{ |
|
try |
|
{ |
|
if (LayerName == null)//所有图层 |
|
{ |
|
foreach (ILayer templayer in mapLayers) |
|
{ |
|
templayer.Visible = false; |
|
axMapControl.Refresh(); |
|
} |
|
} |
|
else |
|
{ |
|
ILayer templayer = null; |
|
foreach (ILayer item in mapLayers) |
|
{ |
|
if ((item as RasterLayer) != null || (item as KOTilesLayer) != null) |
|
{ |
|
if (item.Name == LayerName) |
|
{ |
|
templayer = item; |
|
break; |
|
} |
|
} |
|
else if ((item as IFeatureLayer) != null) |
|
{ |
|
IFeatureClass fc = (item as IFeatureLayer).FeatureClass; |
|
if (fc == null) continue; |
|
if (fc.AliasName == LayerName) |
|
{ |
|
templayer = item; |
|
break; |
|
} |
|
} |
|
} |
|
if (templayer == null) return; |
|
if (isChecked) |
|
templayer.Visible = true; |
|
else |
|
templayer.Visible = false; |
|
axMapControl.Refresh(); |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
|
|
return; |
|
} |
|
} |
|
|
|
private void UpdateLayer(List<MapTreeViewModel> child) |
|
{ |
|
foreach (MapTreeViewModel item in child) |
|
{ |
|
if (!item.IsChecked) |
|
{ |
|
UpdataMap(item.LayerName, false); |
|
} |
|
if (item.IsChecked) |
|
{ |
|
bool parentIsCheck = GetParentIsChecked(item.PID); |
|
if (parentIsCheck) |
|
UpdataMap(item.LayerName, true); |
|
else |
|
UpdataMap(item.LayerName, false); |
|
} |
|
} |
|
} |
|
|
|
private bool GetParentIsChecked(int PID) |
|
{ |
|
if (!treeViewModel.IsChecked) return false; |
|
MapTreeViewModel parent = nodes.FirstOrDefault(a => a.ID == PID); |
|
if (parent == null) |
|
{ |
|
return true; |
|
} |
|
else if (!parent.IsChecked) |
|
{ |
|
return false; |
|
} |
|
else |
|
{ |
|
return GetParentIsChecked(parent.PID); |
|
} |
|
} |
|
|
|
private void GetChildMapTreeByParent(MapTreeViewModel parent, List<MapTreeViewModel> child) |
|
{ |
|
List<MapTreeViewModel> temp = nodes.FindAll(a => a.PID == parent.ID); |
|
if (temp.Count == 0) |
|
{ |
|
temp = nodes.FindAll(a => a.ID == parent.ID); |
|
child.AddRange(temp); |
|
return; |
|
} |
|
child.AddRange(temp); |
|
foreach (MapTreeViewModel item in temp) |
|
{ |
|
GetChildMapTreeByParent(item, child); |
|
} |
|
} |
|
|
|
private void btClose_MouseDown(object sender, MouseButtonEventArgs e) |
|
{ |
|
instance = null; |
|
this.Close(); |
|
} |
|
|
|
internal class MapTreeViewModel |
|
{ |
|
public bool IsChecked { get; set; } |
|
public string LayerName { get; set; } |
|
public int PID { get; set; } |
|
public int ID { get; set; } |
|
public ObservableCollection<MapTreeViewModel> Children { get; set; } = new ObservableCollection<MapTreeViewModel>(); |
|
} |
|
|
|
} |
|
|
|
}
|
|
|