加载地图

2015-06-10 11:30:53  访问(1298) 赞(0) 踩(0)

// Loads requested table, if any, and [re-]creates in-memory Temp table
		private void ReloadMap(string strFName)
		{
			MapInfo.Geometry.DPoint ctr=mapControl1.Map.Center;
			MapInfo.Geometry.Distance z=mapControl1.Map.Zoom;
			txtResults.Text="";

			if (strFName == "<None>")
			{
				// first close the temporary table -- an easy way to clean it up
				// (otherwise the table will remain open after the map is cleared)
				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);
				
				// set the insertion and edit filters to allow all tools to work on Temp
				ToolFilter toolFilter = 
					(ToolFilter) mapControl1.Tools.AddMapToolProperties.InsertionLayerFilter ;
				if (toolFilter != null && !toolFilter.IncludeLayer(layerTemp) ) 
					toolFilter.SetExplicitInclude(layerTemp, true); 
				toolFilter=(ToolFilter) mapControl1.Tools.SelectMapToolProperties.EditableLayerFilter;
				if (toolFilter != null && !toolFilter.IncludeLayer(layerTemp) ) 
					toolFilter.SetExplicitInclude(layerTemp, true); 

				txtResults.Text="A new in-memory temporary table (named 'Temp') "
					+ "has been added to the map.\r\n\r\nObjects can be added to this table with the "
					+ "Add tools; the objects can then be edited with the Select tool.";
			
				// this sample will automatically load point, line, and region tables
				//  in North America -- so set an appropriate view:
				mapControl1.Map.SetView(new DPoint(-100,30),
					Session.Current.CoordSysFactory.CreateLongLat(DatumID.WGS84),
					60000000);
			}
			else
			{
				// figure out what path to use for data
				// check the .csproj directory, two levels up from the .EXE

				string strPath=Application.StartupPath;
				strPath=strPath.Substring(0,strPath.LastIndexOf(Path.DirectorySeparatorChar)); // get rid of \Debug
				strPath=strPath.Substring(0,strPath.LastIndexOf(Path.DirectorySeparatorChar)+1) // get rid of \bin
					+ "Data" + Path.DirectorySeparatorChar;
				if (File.Exists(strPath + strFName)==false)
				{
					// check the registry for a known sample data search path
					Microsoft.Win32.RegistryKey keySamp 
                        = 
                        Microsoft.Win32.Registry.LocalMachine.CreateSubKey(@"SOFTWARE\MapInfo\MapXtreme\6.8.0");

					if (keySamp != null)
					{
						string s = (string)keySamp.GetValue("SampleDataSearchPath");
						keySamp.Close();

						if (s == null) s = Environment.CurrentDirectory;
						else if (s.EndsWith(Path.DirectorySeparatorChar.ToString())==false)
							s += Path.DirectorySeparatorChar;
						strPath=s;
					}
				}

				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";
				}
			}
			UpdateAllControls();
		}


标签:加载地图 

上一条:

下一条:


 

相关评论

评论加载中……
 

发表评论

类型:
内容:
  (Alt+Enter)