`

MapXtreme点取地图获得信息

阅读更多
拖一个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;
        }
    }
  
分享到:
评论

相关推荐

    C#环境下基于MapXtreme的电子地图开发实例_mapxtremec#_

    在C#环境中,MapXtreme是一款强大的地理信息系统(GIS)开发工具,它允许开发者创建交互式的电子地图应用程序。MapXtreme提供了丰富的API和功能,使得开发者可以轻松地集成地图功能到各种软件系统中,如Web应用、...

    MapXtreme电子地图

    MapXtreme是一款专业的地理信息系统(GIS)软件,主要用于创建、管理和展示电子地图。这款工具由Intergraph公司开发,提供了一种高效的方式来进行地理数据的处理和可视化。MapXtreme电子地图的主要特点在于它的灵活...

    mapxtreme 地图定义 在oraclespatial中的加载与存储

    在IT行业中,地图服务是地理信息系统(GIS)的重要组成部分,MapXtreme作为一个强大的地图解决方案,广泛应用于数据可视化、地理数据分析等领域。Oracle Spatial是Oracle数据库系统的一个组件,它提供了对空间数据的...

    MapXtreme 加载地图MapXtreme是MapInfo公司推出的一个组件

    ### MapXtreme:MapInfo公司的地理信息系统组件 MapXtreme是由MapInfo公司推出的用于开发桌面和网络地理信息系统(GIS)的专业组件。该组件既适用于桌面应用开发,也能支持基于浏览器的网络地理信息系统开发。下面...

    c# mapxtreme 图层上画线

    本文将详细讲解如何在MapXtreme图层上绘制线段,涉及的主要知识点包括地图对象的初始化、图层的管理、点坐标处理和线形绘制。 首先,我们需要引用MapXtreme的相关库,这通常通过在项目中添加对MapXtreme .NET DLL的...

    MapXTreme电子地图C#2008技术笔记总结

    在MapXTreme电子地图应用中,加载地图图层是实现地理信息系统(GIS)功能的基础步骤。以下是对给定代码片段的深入解析: 1. **设置地图查找路径与加载图层** 通过`MapInfo.Engine.Session.Current.TableSearchPath....

    基于MapXtreme的地理信息发布.pdf

    ### 基于MapXtreme的地理信息发布 #### 1. WebGIS的发展趋势 随着计算机技术特别是网络技术的快速发展,地理信息系统(GIS)在组成结构和应用技术方面与传统GIS技术相比发生了巨大变化。基于MapXtreme的WebGIS...

    c#中用MapXtreme开发的地理信息系统

    在IT行业中,地理信息系统(GIS)是用于处理和分析地理数据的重要工具,而MapXtreme是Esri公司推出的一款强大的地图开发平台。本主题主要关注如何在C#环境中利用MapXtreme来构建功能丰富的地理信息系统。MapXtreme为...

    C_环境下基于MapXtreme的电子地图开发实例.

    它提供强大的地图可视化功能,广泛应用于地理信息系统(GIS)、国土管理、测绘、军事等领域。MapXtreme的核心优势在于其集成的地图数据显示控制开发接口,允许开发者在其他应用程序中利用MapXtreme的.NET组件进行...

    MapXtreme2005操作地图及GPS接收模块源码实例

    MapXtreme 2005是一款由MapInfo公司开发的专业地图服务器软件,它提供了强大的地理信息系统(GIS)功能,支持地图数据的操作、管理和展示。本实例主要关注MapXtreme 2005如何与GPS接收模块进行交互,通过源码实现...

    mapxtreme 实现专题图

    MapXtreme是一款强大的地图开发工具,主要用于构建地理信息系统(GIS)应用。它支持Java平台,使得开发者可以利用Java语言创建交互式、高性能的地图应用程序。本主题将详细讲解如何使用MapXtreme for Java实现自定义...

    MapXtreme for java源码

    MapXtreme是一款由Intergraph公司开发的GIS(地理信息系统)软件,主要应用于地图数据的管理和展示。在Java环境中,MapXtreme for Java提供了一套API,允许开发者集成地图功能到自己的应用程序中,实现地图的绘制、...

    mapXtreme 入门资料大全

    MapXtreme是一款强大的地图开发工具,主要用于构建地理信息系统(GIS)应用。它提供了一整套API和控件,使得开发者能够轻松地在各种平台上创建交互式地图应用,包括Web、桌面以及移动设备。这份“MapXtreme入门资料...

    MapXtreme2008中文教程

    MapXtreme2008是一款强大的地理信息系统(GIS)开发工具,专为构建地图应用程序而设计。这个中文教程详细解读了MapXtreme2008的核心功能和使用技巧,帮助用户深入理解和掌握这款软件。 教程首先会介绍MapXtreme2008...

    mapxtreme 桌面完整示例

    MapXtreme是一款强大的地图开发工具,主要用于构建桌面和移动应用程序中的地理信息系统(GIS)解决方案。这个"MapXtreme 桌面完整示例"提供了25个不同的实例,帮助用户深入理解和学习如何利用MapXtreme进行地图操作...

    mapxtreme简介

    MapXtreme是一款强大的地图开发工具,主要用于构建和管理地理信息系统(GIS)应用程序。MapXtreme 2004是其2004年的版本,该版本在介绍中涉及了多个关键知识点,包括地图概览、地图和图层管理、数据管理、数据查询、...

    MapXtreme画线

    MapXtreme是一款强大的地图开发工具,主要用于地理信息系统(GIS)的应用。在“MapXtreme画线”这个主题中,我们关注的是如何在MapXtreme中进行地图上的线对象绘制。以下是对相关知识点的详细说明: 1. **DPoint类*...

    MapXtreme For Java简单例子

    MapXtreme for Java是一款由Intergraph公司开发的地理信息系统(GIS)开发工具,它允许开发者构建基于地图的应用程序。这个工具集成了Java技术,使得开发者可以利用Java平台的强大功能来处理地理空间数据。在...

    Mapxtreme2008读取Oracle数据库加载地图

    MapXtreme 2008是一款强大的地理信息系统(GIS)开发工具,它允许开发者创建交互式的地图应用程序。在本文中,我们将深入探讨如何利用MapXtreme 2008来读取Oracle数据库中的数据,并将其加载为地图。这个过程涉及到...

Global site tag (gtag.js) - Google Analytics