- 积分
- 1632
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2016-1-5
- 最后登录
- 1970-1-1
|

楼主 |
发表于 2016-2-17 15:49:48
|
显示全部楼层
老师好,我又捣鼓了一下,还是没成功。我编了测试程序,窗体添加了MapView,splitContainerButton,把部分代码贴过来。
private void Test_Load(object sender, EventArgs e)
{
this.Width = 1000;
this.Height = 625;
//Load layers
LoadLayers();
splitContainer1.Dock = DockStyle.Fill;
}
private void LoadLayers()
{
//Load country layer
string aFile = Application.StartupPath + "\\Map\\country1.shp";
MapLayer aLayer = MapDataManage.OpenLayer(aFile);
aLayer.LegendScheme.LegendBreaks[0].Color = Color.WhiteSmoke;
PolygonBreak aPGB = (PolygonBreak)aLayer.LegendScheme.LegendBreaks[0];
aPGB.DrawFill = false;
aPGB.OutlineColor = Color.Black;
mapView1.AddLayer(aLayer);
//Load China layer
aFile = Application.StartupPath + "\\Map\\china.shp";
aLayer = MapDataManage.OpenLayer(aFile);
aLayer.Visible = false;
mapView1.AddLayer(aLayer);
//Load river layer
aFile = Application.StartupPath + "\\Map\\rivers.shp";
aLayer = MapDataManage.OpenLayer(aFile);
aLayer.LegendScheme.LegendBreaks[0].Color = Color.Aqua;
((PolyLineBreak)aLayer.LegendScheme.LegendBreaks[0]).Size = 2;
mapView1.AddLayer(aLayer);
//Load city layer
aFile = Application.StartupPath + "\\Map\\CITIES.shp";
aLayer = MapDataManage.OpenLayer(aFile);
((PointBreak)aLayer.LegendScheme.LegendBreaks[0]).Color = Color.Red;
aLayer.Expanded = true;
mapView1.AddLayer(aLayer);
//Label city name
VectorLayer cityLayer = (VectorLayer)aLayer;
cityLayer.LabelSet.FieldName = "NAME";
cityLayer.LabelSet.AvoidCollision = true;
cityLayer.LabelSet.LabelAlignType = MeteoInfoC.Legend.AlignType.Center;
cityLayer.LabelSet.YOffset = 0;
cityLayer.LabelSet.LabelFont = new Font("Arial", 8);
cityLayer.LabelSet.LabelColor = Color.Red;
cityLayer.LabelSet.DrawShadow = false;
cityLayer.LabelSet.ShadowColor = Color.White;
cityLayer.LabelSet.ColorByLegend = false;
cityLayer.AddLabels();
mapView1.ZoomToExtent(78, 130, 16, 55);
//layersLegend1.Refresh();
}
private void button1_Click(object sender, EventArgs e)
{
mapView1.MouseTool = MouseTools.SelectFeatures_Rectangle;
}
private void mapView1_ShapeSelected(object sender, EventArgs e)
{
mapView1.PaintLayers();
VectorLayer cityMapLayer = (VectorLayer)mapView1.GetLayerFromName("CITIES.shp");
string nameStr = "Selected: ";
for (int i = 0; i < cityMapLayer.ShapeNum; i++)
{
if (cityMapLayer.ShapeList.Selected)
{
nameStr = nameStr + " " + cityMapLayer.GetCellValue("NAME", i).ToString() + ",";
}
}
nameStr.TrimEnd(',');
MessageBox.Show(nameStr);
}
我这里和demo程序的主要区别是没有用到LayersLegend控件,而是直接用到mapView1.AddLayer方法。加一个button,单击后执行 mapView1.MouseTool = MouseTools.SelectFeatures_Rectangle。我也把mapView1_ShapeSelected和控件mapView1进行了关联。这时间单击站点,仍没有反映。我想问题是不是出在我没用LayersLegend、MapFrame有关。怎么解决呢?
|
|