用mapxtreme开发小结1(c#)

创建新表 Temp
    MapInfo.Data.Table tblTemp = Session.Current.Catalog.GetTable( " Temp " );
    
if  (tblTemp != null ) tblTemp.Close();
    mapControl1.Map.Clear();

    
//  create a temporary table and add a featurelayer for it
    FeatureLayer layerTemp = new  FeatureLayer(Session.Current.Catalog.CreateTable(    TableInfoFactory.CreateTemp( " Temp " ),  new  TableSessionInfo()));
    mapControl1.Map.Layers.Add(layerTemp);
                

图层筛选器

1  ToolFilter toolFilter  =  (ToolFilter) mapControl1.Tools.AddMapToolProperties.InsertionLayerFilter ;
2  if  (toolFilter  !=   null   &&   ! toolFilter.IncludeLayer(layerTemp) ) 
3  toolFilter.SetExplicitInclude(layerTemp,  true ); 
4  toolFilter = (ToolFilter) mapControl1.Tools.SelectMapToolProperties.EditableLayerFilter;
5  if  (toolFilter  !=   null   &&   ! toolFilter.IncludeLayer(layerTemp) ) 
6      toolFilter.SetExplicitInclude(layerTemp,  true ); 

设置地图中心点 

1  mapControl1.Map.SetView( new  DPoint( - 100 , 30 ),
2  Session.Current.CoordSysFactory.CreateLongLat(DatumID.WGS84), 60000000 );

 一些winform的知识:  

      string strPath=Application.StartupPath;

      strPath=strPath.Substring(0,strPath.LastIndexOf(Path.DirectorySeparatorChar)+1) // get rid of \bin

注册表操作:

      Microsoft.Win32.RegistryKey keySamp = Microsoft.Win32.Registry.LocalMachine.CreateSubKey(@"SOFTWARE\MapInfo\MapXtreme\6.8.0");

      keySamp.Close();

完整代码示例

 

 1  string  strPath = Application.StartupPath;
 2  strPath = strPath.Substring( 0 ,strPath.LastIndexOf(Path.DirectorySeparatorChar));  //  get rid of \Debug
 3  strPath = strPath.Substring( 0 ,strPath.LastIndexOf(Path.DirectorySeparatorChar) + 1 //  get rid of \bin
 4                       +   " Data "   +  Path.DirectorySeparatorChar;
 5  if  (File.Exists(strPath  +  strFName) == false )
 6  {
 7       //  check the registry for a known sample data search path
 8      Microsoft.Win32.RegistryKey keySamp  =  Microsoft.Win32.Registry.LocalMachine.CreateSubKey( @" SOFTWARE\MapInfo\MapXtreme\6.8.0 " );
 9       if  (keySamp  !=   null )
10      {
11           string  s  =  ( string )keySamp.GetValue( " SampleDataSearchPath " );
12          keySamp.Close();
13 
14                   if  (s  ==   null ) { s  =  Environment.CurrentDirectory; }
15                   else
16                  {
17                         if  (s.EndsWith(Path.DirectorySeparatorChar.ToString())  ==   false )
18                        {
19                              s  +=  Path.DirectorySeparatorChar;
20                        }
21 
22                        strPath  =  s;
23                   }
24      }
25  }

MapInfo.Geometry.DPoint ctr=mapControl1.Map.Center;
   MapInfo.Geometry.Distance z=mapControl1.Map.Zoom;

if (File.Exists(strPath+strFName))
    {
     mapControl1.Map.Load(new MapTableLoader(strPath + strFName));
     mapControl1.Map.Center=ctr; 
     mapControl1.Map.Zoom=z;  //地图缩放比例
    }
    else
    {
     txtResults.Text="Couldn't find table: \r\n"
      + strPath + strFName
      + "\r\n\r\nTo enable this function, copy the relevant files "
      + "to the above location, or reinstall the sample data.\r\n\r\n";
    }    
关于FeatureLayer的

 

1  FeatureLayer lyrTemp = (FeatureLayer) mapControl1.Map.Layers[ " Temp " ];
2  if  (lyrTemp != null )
3  {
4      IFeatureEnumerator fen  =  (lyrTemp.Table  as  IFeatureCollection).GetFeatureEnumerator();
5       int  n = 0 ;
6       while  (fen.MoveNext()) n ++ ;
7      txtNumObjects.Text = n.ToString();
8  }

 

显示选定的图元?图层个数:
1 
2              IEnumerator se  =  MapInfo.Engine.Session.Current.Selections.GetEnumerator();
3               int  i = 0 ;
4               while  (se.MoveNext()) i +=  ((Selection)se.Current).TotalCount;
5              txtNumSelected.Text = i.ToString();

你可能感兴趣的:(map)