Mapxtreme取地图表资料

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();
        }
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值