您的位置:首页 > 其它

Mapxtreme取地图表资料

2008-05-08 20:24 204 查看
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using MapInfo;
using MapInfo.Data.Find;
using MapInfo.Data;
using MapInfo.Geometry;
using MapInfo.Styles;
using MapInfo.Mapping.Thematics;
using MapInfo.Mapping;
using MapInfo.Mapping.Legends;
using MapInfo.WebControls;
using ApplicationStateManager;

命名空间

//将国家名称绑定到下来菜单中

private static string _findLayerName = "worldcap";
private static string _findColumnName = "Country";

protected override void OnPreRender(EventArgs e)
{
if (!IsPostBack)
{
FillDropDown(_findLayerName, _findColumnName);
}
}

private void FillDropDown(string tableName, string colName)
{
MapInfo.Mapping.Map map = null;

// Get the map
if (MapInfo.Engine.Session.Current.MapFactory.Count == 0 ||
(map = MapInfo.Engine.Session.Current.MapFactory[MapControl1.MapAlias]) == null)
{
return;
}

DDLCity.Items.Clear();

MapInfo.Mapping.FeatureLayer fl = (MapInfo.Mapping.FeatureLayer)map.Layers[tableName];
MapInfo.Data.Table t = fl.Table;
MIDataReader tr;
MIConnection con = new MIConnection();
MICommand tc = con.CreateCommand();
tc.CommandText = "select " + colName + " from " + t.Alias;
//Convert.ToDateTime("afds");
con.Open();
tr = tc.ExecuteReader();
while (tr.Read())
{
DDLCity.Items.Add(tr.GetString(0));

}
tc.Cancel();
tc.Dispose();
tr.Close();
con.Close();

}

//在地图上寻找国家
private static string _workingLayerName = "WorkingLayer";
protected void butFind_Click(object sender, EventArgs e)
{
Find find = null;
try
{
MapInfo.Mapping.Map map = null;

// Get the map
if (MapInfo.Engine.Session.Current.MapFactory.Count == 0 ||
(map = MapInfo.Engine.Session.Current.MapFactory[MapControl1.MapAlias]) == null)
{
return;
}

// Do the find
MapInfo.Mapping.FeatureLayer findLayer = (MapInfo.Mapping.FeatureLayer)map.Layers[_findLayerName];
find = new Find(findLayer.Table, findLayer.Table.TableInfo.Columns[_findColumnName]);
FindResult result = find.Search(DDLCity.SelectedItem.Text);

if (result.ExactMatch)
{
// Create a Feature (point) for the location we found
CoordSys csys = findLayer.CoordSys;
FeatureGeometry g = new MapInfo.Geometry.Point(csys, result.FoundPoint.X, result.FoundPoint.Y);
Feature f = new Feature(g, new MapInfo.Styles.SimpleVectorPointStyle(52, System.Drawing.Color.DarkGreen, 32));

// Delete the existing find object and add the new one
MapInfo.Mapping.FeatureLayer workingLayer = (MapInfo.Mapping.FeatureLayer)map.Layers[_workingLayerName];
if (workingLayer != null)
{
(workingLayer.Table as ITableFeatureCollection).Clear();
workingLayer.Table.InsertFeature(f);
}

// Set the map's center and zooom
map.Center = new DPoint(result.FoundPoint.X, result.FoundPoint.Y);
MapInfo.Geometry.Distance d = new MapInfo.Geometry.Distance(1, map.Zoom.Unit);
map.Zoom = d;
}
else
{
Response.Write("nothing");
}
find.Dispose();
}
catch (Exception)
{
if (find != null) find.Dispose();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: