阅读:1885回复:4
紧急求助...为什么在mapcontrol中,addlayer不起作用,先拜谢啦
<P>我的代码如下:dbxy.mdb里有表xy,存放的是点的x,y值。代码改写至Help中的Add a layer from XY data。</P>
<P>现在的问题是,执行后mapcontrol中没任何变化,我用TOCcontrol来看也没有添上一个图层,不知是什么原因,请高手解答,我先拜谢了.</P> <P>void CGISOCXDlg::AddXYData()<BR>{<BR> IWorkspaceFactoryPtr pWorkspaceFactory;<BR> IWorkspacePtr pWorkspace;<BR> IFeatureWorkspacePtr pFeatureWorkspace;<BR> ITablePtr pTable;</P> <P> IWorkspaceNamePtr ipWorkspaceName (CLSID_WorkspaceName);<BR> ipWorkspaceName->put_WorkspaceFactoryProgID(CComBSTR(_T("esriDataSourcesGDB.AccessWorkspaceFactory")));<BR> ipWorkspaceName->put_PathName(CComBSTR(_T("c:\\dbxy.mdb")));<BR> IUnknownPtr ipUnk;<BR> ((INamePtr)ipWorkspaceName)->Open(;ipUnk); <BR> // QI, WorkspaceName implements both IWorkspaceName and IName<BR> IWorkspacePtr ipWorkspace (ipUnk); </P> <P> pFeatureWorkspace = ipWorkspace;<BR> pFeatureWorkspace->OpenTable(CComBSTR(_T("xy")),;pTable);<BR> <BR> IActiveViewPtr ipActiveView;<BR> m_ipMapControl->get_ActiveView(;ipActiveView);</P> <P> // Get the table name object<BR> IDatasetPtr pDataSet = NULL;<BR> INamePtr pTableName = NULL;<BR> pDataSet = (IDatasetPtr) pTable;<BR> pDataSet->get_FullName(;pTableName);</P> <P> // Specify the X and Y fields<BR> IXYEvent2FieldsPropertiesPtr pXYEvent2FieldsProperties(CLSID_XYEvent2FieldsProperties);<BR> CString s1("x") , s2("y") , s3("");<BR> pXYEvent2FieldsProperties->put_XFieldName(s1.AllocSysString());<BR> pXYEvent2FieldsProperties->put_YFieldName(s2.AllocSysString());<BR> pXYEvent2FieldsProperties->put_ZFieldName(s3.AllocSysString());</P> <P> // Specify the projection</P> <P> ISpatialReferenceFactoryPtr pSpatialReferenceFactory(CLSID_SpatialReferenceEnvironment);<BR> IProjectedCoordinateSystemPtr pProjectedCoordinateSystem(CLSID_ProjectedCoordinateSystem);<BR> pSpatialReferenceFactory->CreateProjectedCoordinateSystem(26911, ;pProjectedCoordinateSystem);<BR> // esriSRProjCS_NAD1983UTM_11N = </P> <P> // Create the XY name object and set it's properties <BR> IXYEventSourceNamePtr pXYEventSourceName(CLSID_XYEventSourceName);</P> <P> pXYEventSourceName->putref_EventProperties(pXYEvent2FieldsProperties);<BR> pXYEventSourceName->putref_SpatialReference(pProjectedCoordinateSystem);<BR> pXYEventSourceName->putref_EventTableName(pTableName);<BR> INamePtr pXYName;<BR> pXYName = (INamePtr) pXYEventSourceName;</P> <P> IUnknownPtr ipUnkw;<BR> pXYName->Open(;ipUnkw);<BR> IXYEventSourcePtr pXYEventSource(ipUnkw);</P> <P> // Create a new Map Layer <BR> IFeatureLayerPtr pFLayer(CLSID_FeatureLayer);<BR> pFLayer->putref_FeatureClass((IFeatureClassPtr) pXYEventSource);<BR> CString name("Sample XY Event layer");<BR> pFLayer->put_Name(name.AllocSysString());</P> <P> m_ipMapControl->AddLayer(pFLayer, 5);</P> <P> ipActiveView->Refresh();</P> <P>}</P> |
|
1楼#
发布于:2006-08-14 13:27
<P>自己顶一个,在线等。。555</P>
|
|
2楼#
发布于:2006-08-14 13:44
<P>建议:(本人不学C++,应该只能大概看一下)</P>
<P>跟一下pFLayer,是否是空?看你的代码好象不为空,否则就崩掉了,所以是废话。</P> <P>重点:</P> <P>IActiveViewPtr ipActiveView;<BR>m_ipMapControl->get_ActiveView(;ipActiveView);</P> <P>此方法请在最后再调用一遍,因为添加完层后地图的Map的ipActiveView应该改变了,最好改为m_ipMapControl->get_Map->get_ActiveView(;ipActiveView);</P> <P>还有</P> <P>m_ipMapControl->AddLayer(pFLayer, 5);为什么索引为5?默认为0的,放在最前面,换一下试试?难道你前面已经添加了5个图层,而你现在添加的是点图层,给前面的覆盖了,那当然看不到了?</P> <P>最后刷新一下,试试!</P> |
|
|
3楼#
发布于:2006-08-14 13:50
<P>流泪感谢。。。。555,搞定了,确实是要再get一次。。非常非常感谢</P>
|
|
4楼#
发布于:2006-08-14 13:57
<P>...唉,原本上来请教别人的,没想到帮你解决问题先了,可我的问题谁帮我解决呢?</P>
<P><STRONG>SDE编辑版本给用户锁定了,如何解锁。。。<BR></STRONG>数据库SDE建立了N个版本,给某一版本下的用户锁住了,该用户就无法再次进行编辑,目前本人知道除了重新启动SDE服务或杀死该用户版本进程可解锁!可是很麻烦,得手动操作!请问大家在程序代码中有没有办法在该用户登陆时进行控制,使该版本解锁?AO中有这样的接口吗?我没找到啊<IMG src="http://www.gisempire.com/bbs/Skins/Default/emot/em12.gif"></P> |
|
|