MapXtreme 地图搜索之图元定位

js中的代码:

function analysis_map_search_result()
{

var mapImage = document.getElementById("MapControl1_Image_Image");
      
var url = "MapController.ashx?Command=map_search&Width=" + mapImage.width +"&Height=" + mapImage.height + "&ExportFormat=" + mapImage.exportFormat+"&Ran=" + Math.random()+"&feature_name="+encodeURI(jsTrim($("Text1").value))+"&feature_kind="+encodeURI($("Select1").value);

if (mapImage.mapAlias)

    url += "&MapAlias=" + mapImage.mapAlias;
   
     try
        {
         
         //获取数据
            var xmlHttp = CreateXMLHttp();
           
         xmlHttp.open("GET", url,false);    //提交搜索命令
        
         xmlHttp.send(null);
        
         var result = xmlHttp.responseText;
        
         if(result=="")
         {
        
            alert("没查到相关记录!");
           
            return;
           
         }
            
        }
       
     catch(e)
          {
       
              alert("Error!");
           
          }

var sel=$("Sel_name");

var result=result.split("$");

var leng=result.length;

if(leng==1)

{
alert("没有查询到相关记录!");

return;

}

var len=sel.length;

for(var i=0;i<len-1;i++)

    sel.options.remove(1);
   
for(var i=0;i<result.length;i++)

    if(result[i]!="")

       sel.options.add(new Option(result[i],result[i]));

sel.options[1].selected=true;

var count=sel.length-1;

location_feature(sel.value,$("Select1").value); //定位图元

if(sel.length>2)                              //只查询到一条记录,进行定位

    alert("共查询到"+count+"相关记录!");

current_kind=$("Select1").value;                            //最近查询类别
    
}

 

CustomizedCommands.cs中的map_search命令代码:

[Serializable]

    public class map_search : MapBaseCommand
    {

        public map_search()
        {

            this.Name = "map_search";

        }

        public override void Process()
        {

            string feature_name = Convert.ToString(HttpContext.Current.Request["feature_name"]);

                                                                                                                        //图元名称(模糊)

            string feature_kind = Convert.ToString(HttpContext.Current.Request["feature_kind"]);

                                                                                                                      //图元种类

            MapControlModel model = MapControlModel.GetModelFromSession();

            MapInfo.Mapping.Map map = model.GetMapObj(MapAlias);

            Catalog cat = MapInfo.Engine.Session.Current.Catalog;

            string result = "";                                             //返回结果:格式为$**$

            string _findColumnName, _findLayerName;

            _findLayerName = feature_kind;                    //图层名

            _findColumnName = "Name";                         //列名

            SearchInfo si = MapInfo.Data.SearchInfoFactory.SearchWhere(_findColumnName + " like '%" + feature_name + "%'");

                                                                      

            IResultSetFeatureCollection ifs = MapInfo.Engine.Session.Current.Catalog.Search(_findLayerName, si);

            MapInfo.Engine.Session.Current.Selections.DefaultSelection.Clear();

            int i = 0;

            foreach (Feature feature in ifs)
            {

                result = result + feature["name"].ToString() + "$";

                i++;


            }


            HttpContext.Current.Response.Output.Write(result);

        }
    }

 

 

[Serializable]

    public class location_feature : MapBaseCommand
    {
        public location_feature()
        {
            Name = "location_feature";

        }

        public override void Process()
        {

            string feature_name = System.Convert.ToString(HttpContext.Current.Request["feature_name"]);

            string findLayerName = System.Convert.ToString( HttpContext.Current.Request["feature_kind"]);

             MapControlModel model = MapControlModel.GetModelFromSession();

            model.SetMapSize(MapAlias, MapWidth, MapHeight);
           
            try
            {     
                  string _findColumnName = "NAME";

                MapInfo.Mapping.Map map = MapInfo.Engine.Session.Current.MapFactory["Map1"];

                SearchInfo si = MapInfo.Data.SearchInfoFactory.SearchWhere(_findColumnName + " like '%" + feature_name + "%'");

                IResultSetFeatureCollection ifs = MapInfo.Engine.Session.Current.Catalog.Search(findLayerName, si);

                MapInfo.Engine.Session.Current.Selections.DefaultSelection.Clear();//去除默认选择,达到不高亮显示

                                    if (ifs.Count == 1)
                    {


                        map.Center = new DPoint(ifs[0].Geometry.Centroid.x, ifs[0].Geometry.Centroid.y);

                           //使该图元位于屏幕中心

                        MapInfo.Geometry.Distance d = new MapInfo.Geometry.Distance(0.5, map.Zoom.Unit);

                           //设置地图的比例尺

                        map.Zoom = d;


                    }
                    else
                    {

                        map.SetView(ifs.Envelope);

                    }

                   
   }
            finally
            {
                System.IO.MemoryStream ms = model.GetMap(MapAlias, MapWidth,MapHeight,ExportFormat);

                StreamImageToClient(ms);
            }
   

        }
    }

}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值