SharpMap学习7-模拟数据流-结果

界面放一个打开数据按钮,再放一个Picture控件(显示Image也就是Map用)。声明一个Map对象

 

private Map map;
private void btnReadData_Click(object sender, EventArgs e)
{
if (map == null)
{
map = new Map(this.pbMapImage.ClientSize);
}
//找到图层文件
OpenFileDialog openDlg = new OpenFileDialog();
openDlg.Title = "打开图层文件";
openDlg.Multiselect = false;
openDlg.RestoreDirectory = true;
openDlg.Filter = "*.xml|*.xml";
if (openDlg.ShowDialog() == DialogResult.Cancel)
{
return;
}

//加载地图数据
DataProviderXML provider = new DataProviderXML();
VectorLayer addLayer = provider.SetLayerDataSource(openDlg.FileName);
map.Layers.Add(addLayer);
//刷新PictureBox控件
this.pbMapImage.Image = map.GetMap();
this.pbMapImage.Invalidate();
}

点数据XML:

<?xml version="1.0" encoding="utf-8" ?>
<Layer name="点图层模板" type="LayerPoint">
<Element id="0">
<Point x="10" y="10"/>
</Element>
<Element id="1">
<Point x="10" y="30"/>
</Element>
<Element id="2">
<Point x="10" y="50"/>
</Element>
<Element id="3">
<Point x="10" y="70"/>
</Element>
<Element id="4">
<Point x="10" y="90"/>
</Element>
</Layer>

线数据XML:

<?xml version="1.0" encoding="utf-8" ?>
<Layer name="面图层模板" type="LayerPolygon">
<Element id="0">
<Point x="70" y="10"/>
<Point x="100" y="10"/>
<Point x="100" y="50"/>
<Point x="70" y="50"/>
</Element>
<Element id="1">
<Point x="70" y="70"/>
<Point x="100" y="70"/>
<Point x="100" y="100"/>
<Point x="70" y="100"/>
</Element>
</Layer>

面数据XML:

<?xml version="1.0" encoding="utf-8" ?>
<Layer name="线图层模板" type="LayerLine">
<Element id="0">
<Point x="200" y="10" />
<Point x="250" y="30" />
<Point x="450" y="50" />
<Point x="250" y="70" />
<Point x="450" y="80" />
<Point x="250" y="90" />
<Point x="200" y="100" />
</Element>
<Element id="1">
<Point x="200" y="10" />
<Point x="350" y="30" />
<Point x="250" y="50" />
<Point x="450" y="70" />
<Point x="350" y="80" />
<Point x="250" y="90" />
<Point x="200" y="100" />
</Element>
</Layer>

打开数据读取后显示效果:

image

虽然代码没啥技术含量,但是模拟的过程还是走通了。

你可能感兴趣的:(map)