zoukankan      html  css  js  c++  java
  • MapXtreme开发(一)

    1、简单专题图的显示 MapControl1.Map.Clear(); MapGeosetLoader gl=new MapGeosetLoader(@"F:\test.gst"); MapControl1.Map.Load(gl);//打开地图 MapControl1.Map.Load(new MapTableLoader(@"F:\test.tab"));//打开test.tab地图文件 FeatureLayer lyrPnt=MapControl1.Map.Layers["test"] as FeatureLayer; RangedTheme thm = new RangedTheme(lyrPnt,"PH__1999","ph",3,DistributionMethod.EqualCountPerRange); lyrPnt.Modifiers.Insert(0,thm);//定义一个RangedTheme ThemeLegendFrame frame = LegendFrameFactory.CreateThemeLegendFrame("PH__1999","pp",thm); Legend legend = MapControl1.Map.Legends.CreateLegend(new Size(5,5)); legend.Frames.Append(frame);//定义一个Legend //MapControl1.Map.Adornments.Append(legend);//如果保留此句,MapControl1中将显示Legend LegendControl1.Map = MapControl1.Map; if (MapControl1.Map.Legends.Count > 0) { LegendControl1.Legend = MapControl1.Map.Legends[0]; }//在LegendControl1控件中显示Legend 
    2、从MapX到MapXtreme2004[1]-工具选择在Mapx中为控件选择工具比较迅速,也很直观,如下: Map1.CurrentTool = miZoomInTool miZoomInTool是个枚举量,指定给CurrentTool属性即可,而且象在VB中,直接在等号之后就把备选项就列出来了,非常容易。 在MapXtreme中,这个不起眼的问题却搞得有点麻烦,主要是架构有点变化,设置位置很容易找 MapControl1.MapTools.CurrentTool= 可是,要赋的值却比较麻烦,因为C#中并没有给出智能提示,而且在帮助和对象浏览器中也没有找到什么枚举值。帮助中说要赋String类型,试着 MapControl1.MapTools.CurrentTool="ZoomInMapTool"; 但是出错。于是查找帮助,了解MapXtreme中的架构,大致如此:MapTools属于MapControl控件的工具集合,其中已经包含了10个工具,debug中挨个求出如下: 0:ZoomInMapTool 1:ZoomOutMapTool 2:PanMapTool 3:CenterMapTool 4:PointSelectionMapTool 5:RadiusSelectionMapTool 6:RectangleSelectionMapTool 7:PolygonSelectionMapTool 8:DistanceMapTool 9:InfoMapTool 但是要选择工具,却不能用Index,也不能用某项的名字字符串,必须用toolname属性,而且必须这样 MapControl1.MapTools.CurrentTool =ZoomInMapTool.Toolname; 因为Toolname是一个静态属性,所以必须用类名来引用,其他别的方式都不行。 看来,以后要用哪个工具,得先查到工具名称,然后才能指定了。 
    其他相关:
    1、Toolname是这几个类的特定属性,在其他的工具类中没有。
    2、如果界面中已经放置了同功能的操作控件并关联到MapControl控件,那么将会干扰到程序选择的工具。比如,既放了自带的移动控件,又有一个按钮可以设置移动工具,在点击自定义的按钮,选择移动工具时,那么,界面中的移动控件就会自动处于被按下的状态。这时,再用自定义的选择工具去设置别的功能就不管用了,怎么都是移动功能。所以,最好只要一个就行了。 
    3、从MapX到MapXtreme2004[2]-图层操作 Mapx中基本的图层操作还是比较简单的,集中在对Layers和Layer的处理上,对别的没有太多要求。 在MapXtreme中,要完成类似功能,发生了一点变化,如下:
    1、图层的显示 在MapXtreme中,图层的显示控制发生了奇怪的变化,有一个IsVisible属性,但它是只读的,不能通过它来改变图层的显示。要控制图层的显示与隐藏,可以通过设置Layer.Enable来控制。
    2、图层的动态添加 代码如下: Catalog _catalog=MapInfo.Engine.Session.Current.Catalog; MapInfo.Data.Table _tempTable=null; Map _map=MapControl1.Map ; TableInfo ti = TableInfoFactory.CreateTemp("临时"); _tempTable = _catalog.CreateTable(ti); _map.Layers.Insert(0, new FeatureLayer(_tempTable));
    可以看出:加图层实际就是加表;Catalog对象统管表的加载以及列举;
    查帮助还可以了解:表信息其实还可以包括表的类型和坐标系。类型是指原生表,文本,access ...
    上面的ti也可以这样取得,但是,上面的表默认是MeMTab,应该是内存中的吧。 CoordSys cs=_map.GetDisplayCoordSys(); TableInfo ti = TableInfoFactory.CreateTemp("临时",MapInfo.Data.TableType.Native,cs); 
    4、从MapX到MapXtreme2004[3]-搜索图元一、根据名称搜索图元
    1、Mapxtreme的架构和Mapx有所变化,Mapx中,Layer包含Features,而Mapxtreme中则不是
    2、Mapxtreme的例子中的查找,是通过Find对象来实现的,而Find对象的构造,需要指定Table和Colume,Table好办,FeatureLayer.table即可,而Colume通过FeatureLayer.table.tableinfo.colums["列名"]来指定。但是,关键问题,大多数的地图,并未设计过多的字段来供查询,查的其实就是个标题和label而已。
    3、要用笨办法,遍历图层的features,通过这个方法 foreach(Feature feature in lyr.table) { }
    4、Feature派生自Object,包含一个Geometry属性,这个属性是各种几何图形对象的基类 Geometry classes that derive from FeatureGeometry include: Point, MultiPoint, MultiCurve, MultiPolygon, FeatureGeometryCollection, Rectangle, RoundedRectangle, Ellipse, LegacyArc, and LegacyText.
    5、通过如下方式引用feature对象 ((MapInfo.Geometry.LegacyText)feature.Geometry).Caption 
    二、通过search方法搜索
    1、catalog的search方法可以按条件搜索图元(第一个图元) // also uses search for feature Feature fDEU = _catalog.SearchForFeature("europe", MapInfo.Data.SearchInfoFactory.SearchWhere ("Country='DEU'"));
    2、先利用SearchInfoFactory构造一个SearchInfo对象,指定其搜索属性: SearchAll: Returns all the rows. SearchNearest: Returns the rows with table geometries that are closest to the given search point. SearchWhere: Returns the rows specified by the given where Clause. SearchWithinDistance: Returns the rows where the table geometry is contained within a buffer of the search point, rectangle or geometry. SearchWithinFeature: Returns the rows where the table geometry is contained within the search features's geometry. SearchWithinGeometry: Returns the rows where the table geometry is contained within the search geometry. SearchWithinRect: Returns the rows where the table geometry intersects the given rectangle. SearchIntersectsFeature: Returns the rows where the table geometry intersects with the search features's geometry. SearchIntersectsGeometry: Returns the rows where the table geometry intersects with the search geometry. SearchWithinScreenRadius: Creates a SearchInfo that returns the rows where the table geometry intersects a screen circle. SearchWithinScreenRect:Returns the rows where the table geometry intersects the given screen rectangle
    3、再调用search方法,将结果放到 MultiResultSetFeatureCollection IResultSetFeatureCollection
    4、或许还要设置视图 MapInfo.Engine.Session.Current.MapFactory[0].SetView(fc.Envelope); 
    三、通过选择工具来选择一个范围 1、需要控制选择的图层 2、选择的结果,通过MapInfo.Engine.Session.Current.Selections.DefaultSelection得到一个Selection对象 3、Selection对象,是一个IResultSetFeatureCollection的集合,每个对应一个表 
    4、对每一个IResultSetFeatureCollection,可以通过枚举器来遍历访问 Selection sl =MapInfo.Engine.Session.Current.Selections.DefaultSelection; IResultSetFeatureCollection fc=sl[0]; IFeatureEnumerator fn=fc.GetFeatureEnumerator(); ListBox1.Items.Clear(); while(fn.MoveNext()) if(fn.Current.Geometry.GetType().ToString()=="MapInfo.Geometry.LegacyText") ListBox1.Items.Add(((MapInfo.Geometry.LegacyText)fn.Current.Geometry).Caption); 
    5、从MapX到MapXtreme2004[4]-标注AutoLabel 好日子一去不复返了,原来总觉得Mapx很多地方设计得不是很自然,比如,feature和具体的feature之间的某些属性的关系,有时令人迷惑。但是,用了Mapxtreme,才感觉到Mapx的方便。真不知MapInfo怎么想的!原来的标注非常简单,layer有个autolabel属性,一设就可以了。现在呢: //James.Liu的代码 Table table = Session.Current.Catalog.OpenTable("usa.tab"); Map map = Session.Current.MapFactory.CreateEmptyMap(new Size(300, 300)); LabelLayer layer = new LabelLayer(); map.Layers.Add(layer); LabelSource source = new LabelSource(table); source.DefaultLabelProperties.Caption = "State_Name"; layer.Sources.Append(source); //我的 LabelLayer layer = new LabelLayer(); MapControl1.Map.Layers.Add(layer); LabelSource source = new LabelSource(MapInfo.Engine.Session.Current.Catalog.GetTable("地名")); source.DefaultLabelProperties.Caption = "f_name"; //标注用到的那个字段名称 layer.Sources.Append(source); 看Layer.Sources的架势,好像可以共用一个LabelLayer,试试,的确可以 
    6、从MapX到MapXtreme2004[5]-自定义工具从MapX到MapXtreme2004[5]-自定义工具 参见月光宝盒的文章http://jerry429.blogchina.com/2149736.html 参见 《MapXtreme2004_DevGuide_A4.pdf》 p155 Example 
    1: Writing a Server SIde Custom Tool 自己的体会: 1、要写一个自定义的事件参数,传递需要的信息 
    2、最好从一个MapTool派生新的工具类,而不要从现成的工具如点选工具派生,否则会带来很多问题。 感谢James.Liu给出的提示 http://www.mygis.com.cn/forum/dispbbs.asp?boardID=23&replyID=38340&ID=8090&skin=1 
    3、创建好的自定义工具,必须先建立实例,加到MapControl的Maptools中,才能被设置为当前工具。还有一点也很重要,Maptools似乎没有Viewstate,每次postback都会还原,所有在pageload中必须每次都加入新工具。 
    4、自定义工具的类型可以是多种多样,如下: To draw a rectangle: MapInfoWebRectangleStart MapInfoWebRectangleStop To process a click: MapInfoWebPointStart MapInfoWebPointStop To process panning of a map: MapInfoWebPanStart MapInfoWebPanStop To draw a circle: MapInfoWebCircleStart MapInfoWebCircleStop To draw a polyline: MapInfoWebDistanceStart MapInfoWebDistanceStop To draw a polygon: MapInfoWebPolygonStart MapInfoWebPolygonStop 
    7、从MapX到MapXtreme2004[6]-对Table、Feature等的理解一、Table 2004中,Table还是表,可以来自原始的mapinfo表,也可以来自数据库的二维表、文本等。Table的等价概念是feature集合,如下代码: (_tempTable as IFeatureCollection).Clear(); 当然,可以通过枚举器,来逐个访问table的行,如下: Selection sl =MapInfo.Engine.Session.Current.Selections.DefaultSelection; IResultSetFeatureCollection fc=sl[0]; IFeatureEnumerator fn=fc.GetFeatureEnumerator(); //IFeatureCollection也有GetFeatureEnumerator ListBox1.Items.Clear(); while(fn.MoveNext()) if(fn.Current.Geometry.GetType().ToString()=="MapInfo.Geometry.LegacyText") ListBox1.Items.Add(((MapInfo.Geometry.LegacyText)fn.Current.Geometry).Caption); 当然,用 foreach(Feature feature in tb) 也是毫无问题的,因而,table和结果集是等价的。 
    二、Feature Feature等价于表中的行。只与行有关,而与具体的图元的类型无关。换言之,Feature只是指图元对应的表行,而与图元的属性无关。 用Feature.Table可以引用到所属的表。 用Table.TableInfo可以引用到表的结构信息。 Feature具有的默认列,一般都包括obj,Mi_key,Mi_Style。obj我个人认为就是Feature对应的几何对象。用Feature.Geometry属性可以引用。 Feature.Geometry的类型是FeatureGeometry,它是各种具体图元(点线面文字...)的父类,Feature.Geometry属性所对应的,其实是具体的类。(我向这个属性赋点对象,发现没错)。 对Feature的使用,可以通过CataLog的SearchForFeature来查找,如下 MapInfo.Engine.Session.Current.Catalog.SearchForFeature("Layer1",MapInfo.Data.SearchInfoFactory.SearchWhere("MI_Key='"+strKey+"'") ) 由于ID其实并不唯一,所以,较好的查找对象是MI_Key。同时,Catalog还有其他的查找函数,如SearchNearest等。 加入Feature时,往往需要指定这些基本的信息,有多种加入方法。

  • 相关阅读:
    网站优化记录
    在pc游览器端模拟移动端幻灯片
    jquery消息提示框
    开发jquery tab 插件
    js检测是否安装了flash插件
    javaweb项目下解决360兼容模式不能下载文件问题
    简单的excel上传解析和错误反馈信息下载
    sqlserver带游标存储过程及调用函数
    oracle带游标存储过程编写
    简单的spring+dubbo提供和消费方
  • 原文地址:https://www.cnblogs.com/googlegis/p/2978836.html
Copyright © 2011-2022 走看看