- 积分
- 57046
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2011-6-21
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
接着上一讲补充一下多MapFrame的功能,在LayersLegend中用鼠标右键点击MapFrame名,在弹出菜单中有Active子菜单,用这个功能可以设置LayersLegend中的ActiveMapFrame。为了使MapView显示为ActiveMapFrame中的MapView,也就是在切换ActiveMapFrame后MapView也跟着切换。写一个SetMapView函数来切换MapView,再给LayersLegend对象添加一个ActiveMapFrameChanged事件,代码如下:
- private void SetMapView()
- {
- //Add map view
- tabControl1.TabPages[0].Controls.Clear();
- tabControl1.TabPages[0].Controls.Add(mapView1);
- mapView1.Dock = DockStyle.Fill;
- }
- private void ActiveMapFrameChanged(object sender, EventArgs e)
- {
- mapView1 = layersLegend1.ActiveMapFrame.MapView;
- SetMapView();
- if (tabControl1.SelectedIndex == 0)
- mapView1.PaintLayers();
- }
复制代码
在主窗体的Load事件中加入如下代码:
- //Add ActiveMapFrameChanged event
- layersLegend1.ActiveMapFrameChanged += new EventHandler(ActiveMapFrameChanged);
复制代码
下面再说说处理气象数据,以GrADS格式的经典示例数据model.ctl和model.dat为例。气象数据中有一个很重要的类MeteoDataInfo,先创建一个对象,然后可以用各种Open语句打开不同格式的气象数据,比如用OpenGrADSData函数来打开GrADS格式数据。下一步是获取格点或者站点数据,分别用GridData和StationData类来表示,这两个类也非常重要。之后可以创建并添加图层。添加一个MeteoData菜单和GrADS Data子菜单,在子菜单里再加一个Contour菜单,打开model.ctl文件并绘制等值线图层的代码如下:
- private void TSMI_GrADSContour_Click(object sender, EventArgs e)
- {
- //Create a MeteoDataInfo object
- MeteoDataInfo aDataInfo = new MeteoDataInfo();
- //Open GrADS data file
- string aFile = Application.StartupPath + "\\Sample\\model.ctl";
- aDataInfo.OpenGrADSData(aFile);
- //Get GridData
- GridData press = aDataInfo.GetGridData("PS");
- //Create a legend scheme
- bool hasUndefData = false;
- LegendScheme aLS = LegendManage.CreateLegendSchemeFromGridData(press,
- LegendType.UniqueValue, ShapeTypes.Polyline, ref hasUndefData);
- //Create a contour layer
- VectorLayer aLayer = DrawMeteoData.CreateContourLayer(press, aLS, "Contour_PS");
- //Add layer
- layersLegend1.ActiveMapFrame.AddLayer(aLayer);
- layersLegend1.ActiveMapFrame.MoveLayer(aLayer.Handle, 2);
- layersLegend1.Refresh();
- //Change title of the layout
- LayoutGraphic aTitle = mapLayout1.GetTexts()[0];
- aTitle.SetLabelText("MeteoInfo Class Library Demo - Contour Layer");
- //Add a legend in layout
- LayoutLegend aLegend = mapLayout1.AddLegend(650, 100);
- aLegend.LegendStyle = LegendStyleEnum.Normal;
- aLegend.LegendLayer = aLayer;
- mapLayout1.PaintGraphics();
- }
复制代码
代码里还演示了修改Layout中的标题,以及添加图例的功能。运行结果如下:
|
|