问题描述
///<summary>///绑定图层///</summary>///<paramname="pStrSql">提取图层的sql语句</param>///<paramname="lyrName">图层名称</param>///<paramname="Index">数据库连接字符串</param>publicMapXLib.LayerlyrBind(AxMapXLib.AxMapAxMap,stringpStrSql,stringlyrName,intIndex){MapXLib.Layerre=null;if(string.IsNullOrEmpty(strConString)){//读取ini,连接数据库,为提取空间图层生成数据库连接字符串ClassIniFilereadIni=newClassIniFile(Application.StartupPath+@"inisystem.ini");ComputerSNcomputerSn=newComputerSN("GIS1212");stringstrHead="db";stringstrServerName="ServerName";stringstrUserName="LogId";stringstrPassWord="LogPassword";stringstrDefult=string.Empty;stringSerever=readIni.GetString(strHead,strServerName,strDefult);stringUserid=readIni.GetString(strHead,strUserName,strDefult);stringPasswd=readIni.GetString(strHead,strPassWord,strDefult);//*********************加密后的数据库密码Passwd=computerSn.GetSourceText(Passwd);strConString="UID="+Userid+";PWD="+Passwd+";srvr="+Serever;}try{MapXLib.LayerInfoLayerInfoObject=newMapXLib.LayerInfoClass();LayerInfoObject.Type=MapXLib.LayerInfoTypeConstants.miLayerInfoTypeServer;LayerInfoObject.AddParameter("name",lyrName);LayerInfoObject.AddParameter("ConnectString",strConString);LayerInfoObject.AddParameter("Query",pStrSql);LayerInfoObject.AddParameter("toolkit","ORAINET");LayerInfoObject.AddParameter("AutoCreateDataset",1);if(lyrName=="高压线路"||lyrName=="高压杆塔"){LayerInfoObject.AddParameter("Cache","all");}LayerInfoObject.AddParameter("DatasetName",lyrName);re=AxMap.Layers.Add(LayerInfoObject,Index);LayerUserInfoList.Add(newLayerUserInfo(LayerInfoObject,lyrName,Index));}catch{MessageBox.Show("加载图层“"+lyrName+"”失败!","提示",MessageBoxButtons.OK,MessageBoxIcon.Asterisk);}returnre;}///<summary>///绑定图层///</summary>///<paramname="pStrSql">提取图层的sql语句</param>///<paramname="lyrName">图层名称</param>///<paramname="Index">数据库连接字符串</param>publicMapXLib.LayerInfolyrBind(stringpStrSql,stringlyrName){if(string.IsNullOrEmpty(strConString)){//读取ini,连接数据库,为提取空间图层生成数据库连接字符串ClassIniFilereadIni=newClassIniFile(Application.StartupPath+@"inisystem.ini");ComputerSNcomputerSn=newComputerSN("GIS1212");stringstrHead="db";stringstrServerName="ServerName";stringstrUserName="LogId";stringstrPassWord="LogPassword";stringstrDefult=string.Empty;stringSerever=readIni.GetString(strHead,strServerName,strDefult);stringUserid=readIni.GetString(strHead,strUserName,strDefult);stringPasswd=readIni.GetString(strHead,strPassWord,strDefult);//*********************加密后的数据库密码Passwd=computerSn.GetSourceText(Passwd);strConString="UID="+Userid+";PWD="+Passwd+";srvr="+Serever;}MapXLib.LayerInfoLayerInfoObject=newMapXLib.LayerInfoClass();LayerInfoObject.Type=MapXLib.LayerInfoTypeConstants.miLayerInfoTypeServer;LayerInfoObject.AddParameter("name",lyrName);LayerInfoObject.AddParameter("ConnectString",strConString);LayerInfoObject.AddParameter("Query",pStrSql);LayerInfoObject.AddParameter("toolkit","ORAINET");LayerInfoObject.AddParameter("AutoCreateDataset",1);LayerInfoObject.AddParameter("DatasetName",lyrName);returnLayerInfoObject;}以上是将存储在空间数据库(Oracle)中的信息绑定到图层上,下面的对上面函数的调用://指定生成图层的sql语句stringstrsql="select*frombdz_test_new";//在axmap上添加图层MapXLib.LayerlyrLineTemp=LayerSet.lyrBind(axMap1,strsql,layerName,1);//设置该图层可以样式覆盖lyrLineTemp.OverrideStyle=true;//设置线的宽度和颜色lyrLineTemp.Style.LineWidth=5;lyrLineTemp.Style.LineColor=785914;lyrLineTemp.Visible=true;但是,程序运行后,图层上并没有显示出新添加的图层,这是怎么回事呢?我猜想是不是一下原因:我上面做的只是告诉mapx数据源在哪里,需要查询哪些数据,下面还没有告诉mapx应该怎样呈现这些数据,是不是还应该在绑定的图层中说明一下应该显示哪些字段、怎样显示(点、线、面)?请高手帮助解答!!!
解决方案
解决方案二:
不懂,帮顶了!