您的位置:首页 > 其它

MapXtreme 地图搜索之图元定位

2011-11-21 14:05 183 查看
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);

}

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐