⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mapinfomapxtreme2005webgis.txt

📁 mapxtrexe查看地图,查询图层,按名查找等
💻 TXT
📖 第 1 页 / 共 2 页
字号:
MapInfo MapXtreme 2005 WebGIS 简单鹰眼设计(转) 
我在2005上研究了好长时间, 才弄出来个简单的鹰眼,与大家分享,我的设计思路是将后台设置两个map ,map1和map2,map1为主地图,map2为鹰眼地图,但是map2没有MapControl,定义一个实现类继承于MapBaseCommand,将map1.Bounds的矩形在map2上转换为System.Drawing.Rectangle,之后将这个Rectangle的左上坐标和width,height传到客户端,应用JS进行客户端绘图,在客户端加入一个Div,Div里放置一个IMG,如下为部分代码:
自定义类:

 1using System;
  2using System.Collections;
  3using System.Drawing;
  4using System.IO;
  5using System.Web;
  6using System.Web.UI.WebControls;
  7using System.Web.UI;
  8using MapInfo.Mapping;
  9using MapInfo.Data;
 10using MapInfo.WebControls;
 11
 12
 13namespace CustomWebTools
 14{
 15    /**//// <summary>
 16    /// Info command for InfoWebTool.
 17    /// </summary>
 18    [Serializable]
 19    public class Info : MapInfo.WebControls.MapBaseCommand
 20    {        
 21        /**//// <summary>
 22        /// Key to be used to get the pixel tolerance parameter value from the URL.
 23        /// </summary>
 24        protected const string PixelToleranceKey = "PixelTolerance";
 25        protected const string InfoCommand = "Info";
 26        
 27
 28        /**//// <summary>
 29        /// Constructor for Info class
 30        /// </summary>
 31        public Info()
 32        {
 33            Name = InfoCommand;
 34        }
 35
 36        /**//// <summary>
 37        /// Override the Execute method in MapBasicCommand class to not save state, because
 38        /// for info tool, which does not change map state, so there is no need to save map state.
 39        /// </summary>
 40        public override void Execute()
 41        {
 42            
 43            StateManager sm = StateManager.GetStateManagerFromSession();
 44            if (sm == null) 
 45            {
 46                if(StateManager.IsManualState())
 47                {
 48                    throw new NullReferenceException("Cannot find instance of StateManager in the ASP.NET session.");
 49                }
 50            } 
 51            ParseContext();
 52            if(sm != null)
 53            {
 54                PrepareStateManagerParamsDictionary(sm);
 55                sm.RestoreState();
 56            }
 57
 58            Process();
 59        }
 60
 61        /**//// <summary>
 62        /// method to do the real server side process for info tool.
 63        /// </summary>
 64        public override void Process()
 65        {
 66            //get pixel tolerance from url of client side.
 67            int pixelTolerance = System.Convert.ToInt32(HttpContext.Current.Request[PixelToleranceKey]);
 68            
 69            MapControlModel model = MapControlModel.GetModelFromSession();
 70            model.SetMapSize(MapAlias, MapWidth, MapHeight);
 71            
 72            //extract points from url of client side.
 73            System.Drawing.Point[]  points = ExtractPoints(DataString);
 74            
 75            //do searching and get results back
 76            MultiResultSetFeatureCollection mrfc = RetrieveInfo(points, pixelTolerance);
 77                        
 78            IEnumerator resultEnum = mrfc.GetEnumerator();
 79            
 80            //retrieve the selected feature from collection
 81            while(resultEnum.MoveNext())
 82            {
 83                IResultSetFeatureCollection irfc = (IResultSetFeatureCollection)resultEnum.Current;
 84                IFeatureEnumerator ftrEnum = irfc.GetFeatureEnumerator();
 85                
 86                while(ftrEnum.MoveNext())
 87                {
 88                    Feature ftr = (Feature)ftrEnum.Current;
 89                    //create a html table to display feature info and stream back to client side.
 90                    CreateInfoTable(ftr);        
 91                    irfc.Close();
 92                    mrfc.Clear();
 93                    break;
 94                }    
 95                break;
 96            }    
 97        }
 98
 99        /**//// <summary>
100        /// Creates html table to hold passed in feature info, and stream back to client.
101        /// </summary>
102        /// <param name="ftr">feature object</param>
103        private void CreateInfoTable(Feature ftr)
104        {
105            //create a table control and populat it with the column name/value(s) from the feature returned and
106            // and the name of the layer where the feature belong
107            System.Web.UI.WebControls.Table infoTable = new System.Web.UI.WebControls.Table();
108            //set table attribute/styles
109            infoTable.CellPadding = 4;            
110            infoTable.Font.Name = "Arial";
111            infoTable.Font.Size = new FontUnit(8);
112            infoTable.BorderWidth = 1;
113            //infoTable.BorderStyle = BorderStyle.Outset; 
114            
115            System.Drawing.Color backColor = Color.Bisque;
116
117            //add the first row, the layer name/value where the selected feature belongs 
118            TableRow r = new TableRow();
119            r.BackColor = backColor;
120
121            TableCell c = new TableCell();
122            c.Font.Bold = true;            
123            c.ForeColor = Color.Indigo;
124
125            c.Text = "Layer Name";            
126            r.Cells.Add(c);
127
128            c = new TableCell();
129
130            //the feature returned is from a resultset table whose name is got from appending _2
131            //to the real table name, so below is to get the real table name.
132            string alias = ftr.Table.Alias;
133            c.Text = alias.Substring(0, alias.Length-2);
134            c.Font.Bold = true;
135            r.Cells.Add(c);
136            
137            infoTable.Rows.Add(r);
138
139            foreach(Column col in ftr.Columns)
140            {
141                String upAlias = col.Alias.ToUpper();
142                //don't display obj, MI_Key or MI_Style columns
143                if(upAlias != "OBJ" && upAlias != "MI_STYLE" && upAlias != "MI_KEY")
144                {
145                    r = new TableRow();
146                    r.BackColor = backColor;
147
148                    r.Cells.Clear();
149                    c = new TableCell();
150                    c.Text = col.Alias;
151                    c.Font.Bold = true;
152                    c.ForeColor = Color.RoyalBlue;
153
154                    r.Cells.Add(c);
155                    c = new TableCell();
156                    c.Text = ftr[col.Alias].ToString();
157                    r.Cells.Add(c);
158                    infoTable.Rows.Add(r);
159                }
160            }
161
162            //stream the html table back to client
163            StringWriter sw = new StringWriter();
164            HtmlTextWriter hw = new HtmlTextWriter(sw);
165            infoTable.RenderControl(hw);
166            String strHTML = sw.ToString();
167            HttpContext.Current.Response.Output.Write(strHTML);
168        }
169
170        /**//// <summary>
171        /// Get a MultiFeatureCollection containing features in all layers falling into the tolerance of the point.
172        /// </summary>
173        /// <param name="points">points array</param>
174        /// <param name="pixelTolerance">pixel tolerance used when searching</param>
175        /// <returns>Returns a MultiResultSetFeatureCollection object</returns>
176        protected MultiResultSetFeatureCollection RetrieveInfo(Point[] points, int pixelTolerance) 
177        {
178            if(points.Length != 1)
179                return null;
180
181            MapControlModel model = MapControlModel.GetModelFromSession();
182            //get map object from map model
183            MapInfo.Mapping.Map map = model.GetMapObj(MapAlias);
184
185            if(map == null) return null;
186
187            //creat a layer filter to include normal visible layers for searching
188            IMapLayerFilter layerFilter = MapLayerFilterFactory.FilterForTools(
189                map, MapLayerFilterFactory.FilterByLayerType(LayerType.Normal), MapLayerFilterFactory.FilterVisibleLayers(true), 
190                "MapInfo.Tools.MapToolsDefault.SelectLayers", null);
191
192            ITableEnumerator tableEnum = map.Layers.GetTableEnumerator(layerFilter);
193            
194            //return if there is no valid layer to search
195            if(tableEnum == null) return null;
196
197            System.Drawing.Point center = points[0];
198            
199            //create a SearchInfo with a point and tolerance
200            SearchInfo si = MapInfo.Mapping.SearchInfoFactory.SearchNearest(map, center, pixelTolerance);
201            (si.SearchResultProcessor as ClosestSearchResultProcessor).Options = ClosestSearchOptions.StopAtFirstMatch;
202            //retrieve all columns

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -