//初始化地图,更换地图 private void InitMap(MapFile mapFile) { currentMap = mapFile; if (preMap == mapFile.File) { return; } mapControl.Map.Clear(); mapControl.Map.Load(MapInfo.Mapping.MapLoader.CreateFromFile(mapFile.File)); mapControlOver.Map.Load(MapInfo.Mapping.MapLoader.CreateFromFile(mapFile.File)); initZoom = mapControl.Map.Zoom; initCenter = mapControl.Map.Bounds.Center(); ClearDistanceLayer(); preMap = mapFile.File; comboBoxLayers.Items.Clear(); listBoxLayerPlace.Items.Clear(); for (int i = 1; i < mapControl.Map.Layers.Count; i++) { if (mapControl.Map.Layers[i].Name != "Watching" && mapControl.Map.Layers[i].Name != "Place" && mapControl.Map.Layers[i].Name != "HisPos" && mapControl.Map.Layers[i].Name != "HisLine" && mapControl.Map.Layers[i].Name != "HisAlarm" && mapControl.Map.Layers[i].Name != "Alarm" && mapControl.Map.Layers[i].Name != "DisLine" && mapControl.Map.Layers[i].Name != "Temp" && mapControl.Map.Layers[i].Name != "HisPlayPos" && mapControl.Map.Layers[i].Name != "HisPlayLine" && mapControl.Map.Layers[i].Name != "Watching_L" && mapControl.Map.Layers[i].Name != "Place_L" && mapControl.Map.Layers[i].Name != "HisPos_L" && mapControl.Map.Layers[i].Name != "HisAlarm_L" && mapControl.Map.Layers[i].Name != "Alarm_L" && mapControl.Map.Layers[i].Name != "HisPlayPos_L" && mapControl.Map.Layers[i].Name != "Administrative") { comboBoxLayers.Items.Add(mapControl.Map.Layers[i].Name); } } if (comboBoxLayers.Items.Count > 0) { comboBoxLayers.SelectedIndex = 0; } if (tableWatching == null) { //监控点图层 TableInfo ti = TableInfoFactory.CreateTemp("Watching"); ti.Columns.Add(ColumnFactory.CreateStringColumn("ID", 10)); ti.Columns.Add(ColumnFactory.CreateStringColumn("Label", 20)); tableWatching = Session.Current.Catalog.CreateTable(ti); TextStyle ts = new TextStyle(); ts.Font.Size = 8; ts.Font.FontWeight = FontWeight.Bold; ts.Font.ForeColor = Color.Green; labLayWatching = new LabelLayer("Watching_L", "Watching_L"); LabelSource source = new LabelSource(tableWatching); source.DefaultLabelProperties.Caption = "Label"; source.DefaultLabelProperties.Style = ts; source.DefaultLabelProperties.CalloutLine.Use = false; source.DefaultLabelProperties.Layout.Alignment = MapInfo.Text.Alignment.CenterRight; source.DefaultLabelProperties.Layout.Offset = 10; source.DefaultLabelProperties.Visibility.AllowOverlap = true; //labLayWatching = (LabelLayer)mapControl.Map.Layers["Watching_L"]; labLayWatching.Sources.Append(source); //自定义标注点图层 TableInfo ti2 = TableInfoFactory.CreateTemp("Place"); ti2.Columns.Add(ColumnFactory.CreateStringColumn("Label", 20)); tablePlace = Session.Current.Catalog.CreateTable(ti2); TextStyle ts2 = new TextStyle(); ts2.Font.Size = 8; ts2.Font.FontWeight = FontWeight.Bold; ts2.Font.ForeColor = Color.Blue; labLayPlace = new LabelLayer("Place_L", "Place_L"); LabelSource source2 = new LabelSource(tablePlace); source2.DefaultLabelProperties.Caption = "Label"; source2.DefaultLabelProperties.Style = ts2; source2.DefaultLabelProperties.CalloutLine.Use = false; source2.DefaultLabelProperties.Layout.Alignment = MapInfo.Text.Alignment.CenterRight; source2.DefaultLabelProperties.Layout.Offset = 10; source2.DefaultLabelProperties.Visibility.AllowOverlap = false; //labLayPlace = (LabelLayer)mapControl.Map.Layers["Place_L"]; labLayPlace.Sources.Append(source2); //历史轨迹点图层 TableInfo ti3 = TableInfoFactory.CreateTemp("HisPos"); ti3.Columns.Add(ColumnFactory.CreateStringColumn("Label", 20)); tableHisPos = Session.Current.Catalog.CreateTable(ti3); TextStyle ts3 = new TextStyle(); ts3.Font.Size = 8; ts3.Font.FontWeight = FontWeight.Bold; ts3.Font.ForeColor = Color.Navy; labLayHisPos = new LabelLayer("HisPos_L", "HisPos_L"); LabelSource source3 = new LabelSource(tableHisPos); source3.DefaultLabelProperties.Caption = "Label"; source3.DefaultLabelProperties.Style = ts3; source3.DefaultLabelProperties.CalloutLine.Use = false; source3.DefaultLabelProperties.Layout.Alignment = MapInfo.Text.Alignment.CenterRight; source3.DefaultLabelProperties.Layout.Offset = 10; source3.DefaultLabelProperties.Visibility.AllowOverlap = false; //labLayHisPos = (LabelLayer)mapControl.Map.Layers["HisPos_L"]; labLayHisPos.Sources.Append(source3); //历史轨迹线图层 TableInfo ti4 = TableInfoFactory.CreateTemp("HisLine"); tableHisLine = Session.Current.Catalog.CreateTable(ti4); //历史报警点图层 TableInfo ti5 = TableInfoFactory.CreateTemp("HisAlarm"); ti5.Columns.Add(ColumnFactory.CreateStringColumn("Label", 20)); tableHisAlarm = Session.Current.Catalog.CreateTable(ti5); TextStyle ts5 = new TextStyle(); ts5.Font.Size = 8; ts5.Font.FontWeight = FontWeight.Bold; ts5.Font.ForeColor = Color.Red; labLayHisAlarm = new LabelLayer("HisAlarm_L", "HisAlarm_L"); LabelSource source5 = new LabelSource(tableHisAlarm); source5.DefaultLabelProperties.Caption = "Label"; source5.DefaultLabelProperties.Style = ts5; source5.DefaultLabelProperties.CalloutLine.Use = false; source5.DefaultLabelProperties.Layout.Alignment = MapInfo.Text.Alignment.CenterRight; source5.DefaultLabelProperties.Layout.Offset = 10; source5.DefaultLabelProperties.Visibility.AllowOverlap = false; //labLayHisAlarm = (LabelLayer)mapControl.Map.Layers["HisAlarm_L"]; labLayHisAlarm.Sources.Append(source5); //报警点图层 TableInfo ti6 = TableInfoFactory.CreateTemp("Alarm"); ti6.Columns.Add(ColumnFactory.CreateStringColumn("Label", 20)); tableAlarm = Session.Current.Catalog.CreateTable(ti6); TextStyle ts6 = new TextStyle(); ts6.Font.Size = 8; ts6.Font.FontWeight = FontWeight.Bold; ts6.Font.ForeColor = Color.Red; labLayAlarm = new LabelLayer("Alarm_L", "Alarm_L"); LabelSource source6 = new LabelSource(tableAlarm); source6.DefaultLabelProperties.Caption = "Label"; source6.DefaultLabelProperties.Style = ts6; source6.DefaultLabelProperties.CalloutLine.Use = false; source6.DefaultLabelProperties.Layout.Alignment = MapInfo.Text.Alignment.CenterRight; source6.DefaultLabelProperties.Layout.Offset = 10; source6.DefaultLabelProperties.Visibility.AllowOverlap = false; //labLayAlarm = (LabelLayer)mapControl.Map.Layers["Alarm_L"]; labLayAlarm.Sources.Append(source6); //测距线图层 TableInfo ti7 = TableInfoFactory.CreateTemp("DisLine"); tableDisLine = Session.Current.Catalog.CreateTable(ti7); //临时图层 TableInfo ti8 = TableInfoFactory.CreateTemp("Temp"); tableTemp = Session.Current.Catalog.CreateTable(ti8); //轨迹回放点图层 TableInfo ti9 = TableInfoFactory.CreateTemp("HisPlayPos"); ti9.Columns.Add(ColumnFactory.CreateStringColumn("Label", 20)); tableHisPlay = Session.Current.Catalog.CreateTable(ti9); TextStyle ts9 = new TextStyle(); ts9.Font.Size = 8; ts9.Font.FontWeight = FontWeight.Bold; ts9.Font.ForeColor = Color.Black; labLayHisPlayPos = new LabelLayer("HisPlayPos_L", "HisPlayPos_L"); LabelSource source9 = new LabelSource(tableHisPlay); source9.DefaultLabelProperties.Caption = "Label"; source9.DefaultLabelProperties.Style = ts9; source9.DefaultLabelProperties.CalloutLine.Use = false; source9.DefaultLabelProperties.Layout.Alignment = MapInfo.Text.Alignment.CenterRight; source9.DefaultLabelProperties.Layout.Offset = 10; source9.DefaultLabelProperties.Visibility.AllowOverlap = false; labLayHisPlayPos.Sources.Append(source9); //轨迹回放线图层 TableInfo ti10 = TableInfoFactory.CreateTemp("HisPlayLine"); tableHisPlayLine = Session.Current.Catalog.CreateTable(ti10); } FeatureLayer lyr = new FeatureLayer(tableWatching); mapControl.Map.Layers.Insert(0, lyr); FeatureLayer lyr2 = new FeatureLayer(tablePlace); mapControl.Map.Layers.Insert(0, lyr2); FeatureLayer lyr3 = new FeatureLayer(tableHisPos); mapControl.Map.Layers.Insert(0, lyr3); FeatureLayer lyr4 = new FeatureLayer(tableHisLine); mapControl.Map.Layers.Insert(0, lyr4); FeatureLayer lyr5 = new FeatureLayer(tableHisAlarm); mapControl.Map.Layers.Insert(0, lyr5); FeatureLayer lyr6 = new FeatureLayer(tableAlarm); mapControl.Map.Layers.Insert(0, lyr6); FeatureLayer lyr7 = new FeatureLayer(tableDisLine); mapControl.Map.Layers.Insert(0, lyr7); FeatureLayer lyr8 = new FeatureLayer(tableTemp); mapControl.Map.Layers.Insert(0, lyr8); FeatureLayer lyr9 = new FeatureLayer(tableHisPlay); mapControl.Map.Layers.Insert(0, lyr9); FeatureLayer lyr10 = new FeatureLayer(tableHisPlayLine); mapControl.Map.Layers.Insert(0, lyr10); //标注图层 mapControl.Map.Layers.Add(labLayWatching); mapControl.Map.Layers.Add(labLayPlace); mapControl.Map.Layers.Add(labLayHisPos); mapControl.Map.Layers.Add(labLayHisAlarm); mapControl.Map.Layers.Add(labLayAlarm); mapControl.Map.Layers.Add(labLayHisPlayPos); }