拖一个pointselectiontool到页面,
修改属性clientcommand为InfoCommand,clientinteraction为ClickInteraction,command为Info,
新增一个CustomCommand.js,新增一个CustomizedCommands.cs,
此CS文件命名空间名称为CustomWebTools,
在网页CS文件中添加using CustomWebTools;
在ASPX中引入<script language="javascript" src="CustomCommand.js" type="text/javascript"></script>,
将Page_Load事件内容改为
复制内容到剪贴板
代码:
// Put user code to initialize the page here
if (Session.IsNewSession)
{
MapInfo.WebControls.MapControlModel controlModel = MapControlModel.SetDefaultModelInSession();
// add custom commands to control model
controlModel.Commands.Add(new CustomWebTools.Info());
//instanciate AppStateManager class
AppStateManager myStateManager = new AppStateManager();
//put current map alias to state manager dictionary
myStateManager.ParamsDictionary[StateManager.ActiveMapAliasKey] = this.MapControl1.MapAlias;
//put state manager to session
StateManager.PutStateManagerInSession(myStateManager);
}
// Now Restore State
StateManager.GetStateManagerFromSession().RestoreState();
CustomCommand.js
复制内容到剪贴板
代码:
//client info command to control client behavior for info tool.
function InfoCommand(name, interaction)
{
if (arguments.length > 0) {
this.Init(name, interaction);
}
}
InfoCommand.prototype = new MapCommand();
InfoCommand.prototype.constructor = InfoCommand;
InfoCommand.superclass = MapCommand.prototype;
InfoCommand.prototype.Execute = function()
{
this.CreateUrl();
this.AddParamToUrl("PixelTolerance", this.pixelTolerance);
//create an XMLHttp obj to send request to server
var xmlHttp = CreateXMLHttp();
xmlHttp.open("GET", this.url, false);
xmlHttp.send(null);
//get response back
this.result = xmlHttp.responseText;
var div = FindElement("Info");
if(div.style.visibility != "visible")
div.style.visibility = "visible";
//display the response at client html
var d = new Date() ;
var NowTime=d.getFullYear() + "-" + (d.getMonth()+1) + "-" + d.getDate() + " " + d.getHours() + ":" + d.getMinutes() + "-" + d.getSeconds();
div.innerHTML = "<font size=2 face=Arial><b>Selected Feature Info:</b></font><p>" + this.result+" "+NowTime;
};
CustomizedCommands.cs
复制内容到剪贴板
代码:
using System;
using System.Collections;
using System.Drawing;
using System.IO;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI;
using MapInfo.Mapping;
using MapInfo.Data;
using MapInfo.WebControls;
namespace CustomWebTools
{
/// <summary>
/// Info command for InfoWebTool.
/// </summary>
[Serializable]
public class Info : MapInfo.WebControls.MapBaseCommand
{
/// <summary>
/// Key to be used to get the pixel tolerance parameter value from the URL.
/// </summary>
protected const string PixelToleranceKey = "PixelTolerance";
protected const string InfoCommand = "Info";
/// <summary>
/// Constructor for Info class
/// </summary>
public Info()
{
Name = InfoCommand;
}
/// <summary>
/// Override the Execute method in MapBasicCommand class to not save state, because
/// for info tool, which does not change map state, so there is no need to save map state.
/// </summary>
public override void Execute()
{
StateManager sm = StateManager.GetStateManagerFromSession();
if (sm == null)
{
if (StateManager.IsManualState())
{
throw new NullReferenceException("Cannot find instance of StateManager in the ASP.NET session.");
}
}
ParseContext();
if (sm != null)
{
PrepareStateManagerParamsDictionary(sm);
sm.RestoreState();
}
Process();
}
/// <summary>
/// method to do the real server side process for info tool.
/// </summary>
public override void Process()
{
//get pixel tolerance from url of client side.
int pixelTolerance = System.Convert.ToInt32(HttpContext.Current.Request[PixelToleranceKey]);
MapControlModel model = MapControlModel.GetModelFromSession();
model.SetMapSize(MapAlias, MapWidth, MapHeight);
//extract points from url of client side.
System.Drawing.Point[] points = ExtractPoints(DataString);
//do searching and get results back
MultiResultSetFeatureCollection mrfc = RetrieveInfo(points, pixelTolerance);
IEnumerator resultEnum = mrfc.GetEnumerator();
//retrieve the selected feature from collection
while (resultEnum.MoveNext())
{
IResultSetFeatureCollection irfc = (IResultSetFeatureCollection)resultEnum.Current;
IFeatureEnumerator ftrEnum = irfc.GetFeatureEnumerator();
while (ftrEnum.MoveNext())
{
Feature ftr = (Feature)ftrEnum.Current;
//create a html table to display feature info and stream back to client side.
CreateInfoTable(ftr);
irfc.Close();
mrfc.Clear();
break;
}
break;
}
}
/// <summary>
/// Creates html table to hold passed in feature info, and stream back to client.
/// </summary>
/// <param name="ftr">feature object</param>
private void CreateInfoTable(Feature ftr)
{
//create a table control and populat it with the column name/value(s) from the feature returned and
// and the name of the layer where the feature belong
System.Web.UI.WebControls.Table infoTable = new System.Web.UI.WebControls.Table();
//set table attribute/styles
infoTable.CellPadding = 4;
infoTable.Font.Name = "Arial";
infoTable.Font.Size = new FontUnit(8);
infoTable.BorderWidth = 1;
//infoTable.BorderStyle = BorderStyle.Outset;
System.Drawing.Color backColor = Color.Bisque;
//add the first row, the layer name/value where the selected feature belongs
TableRow r = new TableRow();
r.BackColor = backColor;
TableCell c = new TableCell();
c.Font.Bold = true;
c.ForeColor = Color.Indigo;
c.Text = "Layer Name";
r.Cells.Add(c);
c = new TableCell();
//the feature returned is from a resultset table whose name is got from appending _2
//to the real table name, so below is to get the real table name.
string alias = ftr.Table.Alias;
c.Text = alias.Substring(0, alias.Length - 2);
c.Font.Bold = true;
r.Cells.Add(c);
infoTable.Rows.Add(r);
foreach (Column col in ftr.Columns)
{
String upAlias = col.Alias.ToUpper();
//don't display obj, MI_Key or MI_Style columns
if (upAlias != "OBJ" && upAlias != "MI_STYLE" && upAlias != "MI_KEY")
{
r = new TableRow();
r.BackColor = backColor;
r.Cells.Clear();
c = new TableCell();
c.Text = col.Alias;
c.Font.Bold = true;
c.ForeColor = Color.RoyalBlue;
r.Cells.Add(c);
c = new TableCell();
c.Text = ftr[col.Alias].ToString();
r.Cells.Add(c);
infoTable.Rows.Add(r);
}
}
//stream the html table back to client
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
infoTable.RenderControl(hw);
String strHTML = sw.ToString();
HttpContext.Current.Response.Output.Write(strHTML);
}
/// <summary>
/// Get a MultiFeatureCollection containing features in all layers falling into the tolerance of the point.
/// </summary>
/// <param name="points">points array</param>
/// <param name="pixelTolerance">pixel tolerance used when searching</param>
/// <returns>Returns a MultiResultSetFeatureCollection object</returns>
protected MultiResultSetFeatureCollection RetrieveInfo(Point[] points, int pixelTolerance)
{
if (points.Length != 1)
return null;
MapControlModel model = MapControlModel.GetModelFromSession();
//get map object from map model
MapInfo.Mapping.Map map = model.GetMapObj(MapAlias);
if (map == null) return null;
//creat a layer filter to include normal visible layers for searching
IMapLayerFilter layerFilter = MapLayerFilterFactory.FilterForTools(
map, MapLayerFilterFactory.FilterByLayerType(LayerType.Normal), MapLayerFilterFactory.FilterVisibleLayers(true),
"MapInfo.Tools.MapToolsDefault.SelectLayers", null);
ITableEnumerator tableEnum = map.Layers.GetTableEnumerator(layerFilter);
//return if there is no valid layer to search
if (tableEnum == null) return null;
System.Drawing.Point center = points[0];
//create a SearchInfo with a point and tolerance
SearchInfo si = MapInfo.Mapping.SearchInfoFactory.SearchNearest(map, center, pixelTolerance);
(si.SearchResultProcessor as ClosestSearchResultProcessor).Options = ClosestSearchOptions.StopAtFirstMatch;
//retrieve all columns
si.QueryDefinition.Columns = null;
MapInfo.Geometry.Distance d = MapInfo.Mapping.SearchInfoFactory.ScreenToMapDistance(map, pixelTolerance);
(si.SearchResultProcessor as ClosestSearchResultProcessor).DistanceUnit = d.Unit;
(si.SearchResultProcessor as ClosestSearchResultProcessor).MaxDistance = d.Value;
//do search
MultiResultSetFeatureCollection mrfc = MapInfo.Engine.Session.Current.Catalog.Search(tableEnum, si);
return mrfc;
}
}
修改属性clientcommand为InfoCommand,clientinteraction为ClickInteraction,command为Info,
新增一个CustomCommand.js,新增一个CustomizedCommands.cs,
此CS文件命名空间名称为CustomWebTools,
在网页CS文件中添加using CustomWebTools;
在ASPX中引入<script language="javascript" src="CustomCommand.js" type="text/javascript"></script>,
将Page_Load事件内容改为
复制内容到剪贴板
代码:
// Put user code to initialize the page here
if (Session.IsNewSession)
{
MapInfo.WebControls.MapControlModel controlModel = MapControlModel.SetDefaultModelInSession();
// add custom commands to control model
controlModel.Commands.Add(new CustomWebTools.Info());
//instanciate AppStateManager class
AppStateManager myStateManager = new AppStateManager();
//put current map alias to state manager dictionary
myStateManager.ParamsDictionary[StateManager.ActiveMapAliasKey] = this.MapControl1.MapAlias;
//put state manager to session
StateManager.PutStateManagerInSession(myStateManager);
}
// Now Restore State
StateManager.GetStateManagerFromSession().RestoreState();
CustomCommand.js
复制内容到剪贴板
代码:
//client info command to control client behavior for info tool.
function InfoCommand(name, interaction)
{
if (arguments.length > 0) {
this.Init(name, interaction);
}
}
InfoCommand.prototype = new MapCommand();
InfoCommand.prototype.constructor = InfoCommand;
InfoCommand.superclass = MapCommand.prototype;
InfoCommand.prototype.Execute = function()
{
this.CreateUrl();
this.AddParamToUrl("PixelTolerance", this.pixelTolerance);
//create an XMLHttp obj to send request to server
var xmlHttp = CreateXMLHttp();
xmlHttp.open("GET", this.url, false);
xmlHttp.send(null);
//get response back
this.result = xmlHttp.responseText;
var div = FindElement("Info");
if(div.style.visibility != "visible")
div.style.visibility = "visible";
//display the response at client html
var d = new Date() ;
var NowTime=d.getFullYear() + "-" + (d.getMonth()+1) + "-" + d.getDate() + " " + d.getHours() + ":" + d.getMinutes() + "-" + d.getSeconds();
div.innerHTML = "<font size=2 face=Arial><b>Selected Feature Info:</b></font><p>" + this.result+" "+NowTime;
};
CustomizedCommands.cs
复制内容到剪贴板
代码:
using System;
using System.Collections;
using System.Drawing;
using System.IO;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI;
using MapInfo.Mapping;
using MapInfo.Data;
using MapInfo.WebControls;
namespace CustomWebTools
{
/// <summary>
/// Info command for InfoWebTool.
/// </summary>
[Serializable]
public class Info : MapInfo.WebControls.MapBaseCommand
{
/// <summary>
/// Key to be used to get the pixel tolerance parameter value from the URL.
/// </summary>
protected const string PixelToleranceKey = "PixelTolerance";
protected const string InfoCommand = "Info";
/// <summary>
/// Constructor for Info class
/// </summary>
public Info()
{
Name = InfoCommand;
}
/// <summary>
/// Override the Execute method in MapBasicCommand class to not save state, because
/// for info tool, which does not change map state, so there is no need to save map state.
/// </summary>
public override void Execute()
{
StateManager sm = StateManager.GetStateManagerFromSession();
if (sm == null)
{
if (StateManager.IsManualState())
{
throw new NullReferenceException("Cannot find instance of StateManager in the ASP.NET session.");
}
}
ParseContext();
if (sm != null)
{
PrepareStateManagerParamsDictionary(sm);
sm.RestoreState();
}
Process();
}
/// <summary>
/// method to do the real server side process for info tool.
/// </summary>
public override void Process()
{
//get pixel tolerance from url of client side.
int pixelTolerance = System.Convert.ToInt32(HttpContext.Current.Request[PixelToleranceKey]);
MapControlModel model = MapControlModel.GetModelFromSession();
model.SetMapSize(MapAlias, MapWidth, MapHeight);
//extract points from url of client side.
System.Drawing.Point[] points = ExtractPoints(DataString);
//do searching and get results back
MultiResultSetFeatureCollection mrfc = RetrieveInfo(points, pixelTolerance);
IEnumerator resultEnum = mrfc.GetEnumerator();
//retrieve the selected feature from collection
while (resultEnum.MoveNext())
{
IResultSetFeatureCollection irfc = (IResultSetFeatureCollection)resultEnum.Current;
IFeatureEnumerator ftrEnum = irfc.GetFeatureEnumerator();
while (ftrEnum.MoveNext())
{
Feature ftr = (Feature)ftrEnum.Current;
//create a html table to display feature info and stream back to client side.
CreateInfoTable(ftr);
irfc.Close();
mrfc.Clear();
break;
}
break;
}
}
/// <summary>
/// Creates html table to hold passed in feature info, and stream back to client.
/// </summary>
/// <param name="ftr">feature object</param>
private void CreateInfoTable(Feature ftr)
{
//create a table control and populat it with the column name/value(s) from the feature returned and
// and the name of the layer where the feature belong
System.Web.UI.WebControls.Table infoTable = new System.Web.UI.WebControls.Table();
//set table attribute/styles
infoTable.CellPadding = 4;
infoTable.Font.Name = "Arial";
infoTable.Font.Size = new FontUnit(8);
infoTable.BorderWidth = 1;
//infoTable.BorderStyle = BorderStyle.Outset;
System.Drawing.Color backColor = Color.Bisque;
//add the first row, the layer name/value where the selected feature belongs
TableRow r = new TableRow();
r.BackColor = backColor;
TableCell c = new TableCell();
c.Font.Bold = true;
c.ForeColor = Color.Indigo;
c.Text = "Layer Name";
r.Cells.Add(c);
c = new TableCell();
//the feature returned is from a resultset table whose name is got from appending _2
//to the real table name, so below is to get the real table name.
string alias = ftr.Table.Alias;
c.Text = alias.Substring(0, alias.Length - 2);
c.Font.Bold = true;
r.Cells.Add(c);
infoTable.Rows.Add(r);
foreach (Column col in ftr.Columns)
{
String upAlias = col.Alias.ToUpper();
//don't display obj, MI_Key or MI_Style columns
if (upAlias != "OBJ" && upAlias != "MI_STYLE" && upAlias != "MI_KEY")
{
r = new TableRow();
r.BackColor = backColor;
r.Cells.Clear();
c = new TableCell();
c.Text = col.Alias;
c.Font.Bold = true;
c.ForeColor = Color.RoyalBlue;
r.Cells.Add(c);
c = new TableCell();
c.Text = ftr[col.Alias].ToString();
r.Cells.Add(c);
infoTable.Rows.Add(r);
}
}
//stream the html table back to client
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
infoTable.RenderControl(hw);
String strHTML = sw.ToString();
HttpContext.Current.Response.Output.Write(strHTML);
}
/// <summary>
/// Get a MultiFeatureCollection containing features in all layers falling into the tolerance of the point.
/// </summary>
/// <param name="points">points array</param>
/// <param name="pixelTolerance">pixel tolerance used when searching</param>
/// <returns>Returns a MultiResultSetFeatureCollection object</returns>
protected MultiResultSetFeatureCollection RetrieveInfo(Point[] points, int pixelTolerance)
{
if (points.Length != 1)
return null;
MapControlModel model = MapControlModel.GetModelFromSession();
//get map object from map model
MapInfo.Mapping.Map map = model.GetMapObj(MapAlias);
if (map == null) return null;
//creat a layer filter to include normal visible layers for searching
IMapLayerFilter layerFilter = MapLayerFilterFactory.FilterForTools(
map, MapLayerFilterFactory.FilterByLayerType(LayerType.Normal), MapLayerFilterFactory.FilterVisibleLayers(true),
"MapInfo.Tools.MapToolsDefault.SelectLayers", null);
ITableEnumerator tableEnum = map.Layers.GetTableEnumerator(layerFilter);
//return if there is no valid layer to search
if (tableEnum == null) return null;
System.Drawing.Point center = points[0];
//create a SearchInfo with a point and tolerance
SearchInfo si = MapInfo.Mapping.SearchInfoFactory.SearchNearest(map, center, pixelTolerance);
(si.SearchResultProcessor as ClosestSearchResultProcessor).Options = ClosestSearchOptions.StopAtFirstMatch;
//retrieve all columns
si.QueryDefinition.Columns = null;
MapInfo.Geometry.Distance d = MapInfo.Mapping.SearchInfoFactory.ScreenToMapDistance(map, pixelTolerance);
(si.SearchResultProcessor as ClosestSearchResultProcessor).DistanceUnit = d.Unit;
(si.SearchResultProcessor as ClosestSearchResultProcessor).MaxDistance = d.Value;
//do search
MultiResultSetFeatureCollection mrfc = MapInfo.Engine.Session.Current.Catalog.Search(tableEnum, si);
return mrfc;
}
}
发表评论
-
mapxtreme添加标记和删除标记
2009-03-30 16:23 1791新增2个pointselectiontool, clientc ... -
添加数据库中的经纬度信息
2009-03-30 16:22 1746C# Code: 复制内容到剪贴板 代码: MapInfo ... -
MapXtreme 2005自定义图层控制代码(WEB)
2009-03-30 16:21 1555虽然MapXtreme 2005 6.7.1提供了图层控制的控 ... -
MapxTreme测试:绘制图标和文字标注
2009-03-30 16:19 3660代码: using System; using System ... -
mapxtreme 2004 改变feature颜色
2009-03-30 16:18 15561.C# code: 复制内容到剪贴板 代码: MapI ... -
MapxTreme2005地图打印
2009-03-30 16:18 1189MapxTreme2005地图打印 一、语言: c# net2 ... -
在C#应用中如何读取存在ORACLE(或SQL Server)中的MapInfo表
2009-03-30 16:17 1219using MapInfo.Data; ... -
MapXtreme 2005查找图元方法,web的
2009-03-30 16:16 1761先添加一个TextBox和 DropDownList控件 复 ... -
MapXtreme查看整个地图的代码
2009-03-30 16:14 907Map map = mapControl1.Map; IMap ... -
MapXtreme 2005 鹰眼源代码
2009-03-30 16:13 1769研究了一段时间的MapXtreme2005 v6.6, 实现了 ... -
实现手动画线
2009-03-30 16:12 1211为了实现在地图上手动画线的功能,煞费了一翻苦心,不过最后实现的 ... -
Web页面中实现鼠标中键缩放
2009-03-30 16:11 1508在MapXtreme 2005中,在Windows应用程序中自 ... -
两种方法实现动态轨迹
2009-03-30 16:11 1352在GIS中,动态轨迹的实现是非常有用的,可用GPS定位,热点跟 ... -
总结查找图元的三种方法
2009-03-30 16:10 1234在MapXtreme 2005中,查找图元提供了非常多的方法, ... -
添加标注图层
2009-03-30 16:08 1158在MapXtreme 2005中添加标注图层是非常容易的,只要 ... -
向图层中添加线段
2009-03-30 16:07 917向图层中添加线段和向图层中添加点是一样的,其本质都是向图层中添 ... -
向图层中添加点
2009-03-30 16:06 1004在添加点之前先要在地图上创建一个临时图层,创建临时图层请参考《 ... -
mapxtreme2005 改变选中的图元样式
2009-03-30 16:05 1063MapInfo.Styles.CompositeStyle c ... -
Mapxtreme2005 两点之间画直线
2009-03-30 16:04 1123private void DrawLine(MapInfo.D ... -
mapxtreme2005 创建各种样式
2009-03-30 16:04 1108public MapInfo.Styles.Composite ...
相关推荐
MapXtreme电子地图 有详细的帮助文档和源代码
MapXTreme电子地图C#2008技术笔记总结
.net2008 c# mapxtreme 加载地图,传进2个点在图层上画线
c#环境下的mapxtrme开发实例讲解,详细介绍mapxtreme开发应用方法
本文简单介绍W ehGIS的发展趋势,结合一些例子介绍了利用MapXtreme的地理信息发布的技术和原理。 0 引言 1 WebGIS的发布原理 2 MapXtreme应用程序的工作流程 3 利用MapX对应用中的地图进行编辑、查询和空间分析 4 ...
mapxtreme 地图定义 在oraclespatial中的加载与存储
MapXtreme是MapInfo公司推出的一个组件,用它可以开发桌面地理信息系统,也可以开发在浏览器上阅读的网络地理信息系统。 由于工作需要,笔者最近开始使用MapXtreme进行网络方面的工作。我把使用过程中的点滴感想...
基于MapXtreme Java电子地图的设计,李俊,王原丽,本文从体系结构、应用程序的部署对基于MapXtreme Java电子地图的整体设计进行了介绍,并结合京珠高速武汉段的地图实现对基于MapXtreme Jav
c#中用MapXtreme开发的地理信息系统 运用MAPXtreme与C#开发地图设计(可做网站)
MapXtreme2005操作地图及GPS接收模块源码实例
Mapxtrem C_环境下基于MapXtreme的电子地图开发实例.pdfe
通过MapXtreme,用户可以在Internet/Intranet上发布基于电子地图的应用系统。所有的最终用户只需在自己的机器上安装浏览器即可访问存放在服务器端的空间数据,用户可以很方便地对地图进行放大、缩小、漫游、查询、...
mapxtreme for java 实现自定义范围专题图
mapxtreme sample mapxtreme的示例程序
MapXtreme6.8中文 完美 破解版
之前发布了一个相同的例子,只是地图用的是我安装mapXtreme for Java4.8.2后的mdf格式地图,这个地图中用了我电脑的主机名加密,所以很多人都运行不了,现在我改用它的gst地图了。这样大家就可以直接运行了,不过web...
MapXtreme2008中文教程详细介绍了MapXtreme2008的各方面特性,并结合例子介绍了MapXtreme的使用方法,附注了MapXtreme的各项新特性和指标。
MapXtreme Java Edition 是企业级的地图绘制开发工具,可实现数据的可视化和 地图绘制,帮助企业作出更加出色的决策,并更加有效地进行运营和管理资产。
MapXtreme Java 版是企业级的地图绘制开发工具,可实现数据的可视化和地图绘制,帮助企业作出更加出色的决策,并更加有效地进行运营和管理资产。在可管理的服务器网络上实现应用程序的运行,不仅在很大程度上提高了...
MapXtreme6.0破解文件附有详细破解说明