克隆一個IFeatureLayer
IFeatureLayerPtr CMapControlView::CloneFeatureLayer(IFeatureLayerPtr aFeatureLayer,CString strLayerName)
{
?IFeatureLayerPtr pFeatureLayer;
?IGeoFeatureLayerPtr pGeoLayer;
?IFeatureRendererPtr pFRender;
?IUIDPtr pUID,pUID2;
?IAnnotateLayerPropertiesCollectionPtr pAnnotateLayerPropertiesCollection;
?VARIANT_BOOL pDisplayAnnotation,pSelectable,pScale,pVisible,pShow,pCached;
?IUniqueValueRendererPtr pURen;
?ISimpleRendererPtr pSRen;
?ISymbolPtr pSym;
?BOOL blnUVR;
?BSTR pDSType,pFieldName;
?IFeatureIDSetPtr pFeatureIDSet;
?IFeatureClassPtr pFeatureClass;
?double pMinScale,pMaxScale;
?try
?{
?? //get all
?? pGeoLayer = (IGeoFeatureLayerPtr)aFeatureLayer;
?? pGeoLayer->get_Renderer(&pFRender);
?? pURen = pFRender;
?? blnUVR = TRUE;
?? if (pURen == NULL)
?? {
? ??pSRen = pFRender;
???blnUVR = FALSE;
?? }
?? if(blnUVR)
?? {
???pURen->get_DefaultSymbol(&pSym);
?? }
?? else
?? {
???pSRen->get_Symbol(&pSym);
?? }
??
?? pGeoLayer->get_RendererPropertyPageClassID(&pUID2);
?? pGeoLayer->get_DisplayAnnotation(&pDisplayAnnotation);
?? pGeoLayer->get_AnnotationPropertiesID(&pUID);
?? pGeoLayer->get_AnnotationProperties(&pAnnotateLayerPropertiesCollection);
?? pGeoLayer->get_ExclusionSet(&pFeatureIDSet);
?? pGeoLayer->get_FeatureClass(&pFeatureClass);
?? pGeoLayer->get_DataSourceType(&pDSType);
?? pGeoLayer->get_DisplayField(&pFieldName);
?? pGeoLayer->get_Selectable(&pSelectable);
?? pGeoLayer->get_ScaleSymbols(&pScale);
?? pGeoLayer->get_MinimumScale(&pMinScale);
?? pGeoLayer->get_MaximumScale(&pMaxScale);
?? pGeoLayer->get_Visible(&pVisible);
?? pGeoLayer->get_ShowTips(&pShow);
?? pGeoLayer->get_Cached(&pCached);
?? ILayerEffectsPtr pLayerEffects;
?? pLayerEffects = pGeoLayer;
?? short pTransparency;
?? pLayerEffects->get_Transparency(&pTransparency);
??
?? //set all
?? pFeatureLayer.CreateInstance(CLSID_FeatureLayer);
?? pGeoLayer = (IGeoFeatureLayerPtr)pFeatureLayer;
?? IClonePtr pClone1,pClone2;
?? pClone1 = pSym;
?? pClone1->Clone(&pClone2);
?? pSym = pClone2;
?? if(blnUVR)
?? {
??? pURen.CreateInstance(CLSID_UniqueValueRenderer);??
??? pURen->put_DefaultSymbol(pSym);
??? pFRender = pURen;
?? }
?? else
?? {
??? pSRen.CreateInstance(CLSID_SimpleRenderer);?
??? pSRen->putref_Symbol(pSym);
??? pFRender = pSRen;
?? }
?? pGeoLayer->putref_Renderer(pFRender);
?? //pGeoLayer->put_RendererPropertyPageClassID(pUID2);
?? pGeoLayer->put_DisplayAnnotation(pDisplayAnnotation);
?? pGeoLayer->putref_AnnotationPropertiesID(pUID);
?? pGeoLayer->put_AnnotationProperties(pAnnotateLayerPropertiesCollection);
?? pGeoLayer->putref_ExclusionSet(pFeatureIDSet);
?? pGeoLayer->putref_FeatureClass(pFeatureClass);
?? pGeoLayer->put_DataSourceType(pDSType);
?? pGeoLayer->put_DisplayField(pFieldName);
?? pGeoLayer->put_Selectable(pSelectable);
?? pGeoLayer->put_ScaleSymbols(pScale);
?? pGeoLayer->put_Name(_bstr_t(strLayerName));
?? pGeoLayer->put_MinimumScale(pMinScale);
?? pGeoLayer->put_MaximumScale(pMaxScale);
?? pGeoLayer->put_Visible(pVisible);
?? pGeoLayer->put_ShowTips(pShow);
?? pGeoLayer->put_Cached(pCached);
?? pLayerEffects = pGeoLayer;
?? pLayerEffects->put_Transparency(pTransparency);
?? IDataLayerPtr pDLayer = pGeoLayer;
?? INamePtr pName;
?? pDLayer->get_DataSourceName(&pName);
????? IDatasetNamePtr pDSName = pName;
????? BSTR pFCName;
????? pDSName->get_Name(&pFCName);
????? CString strName = pFCName;
?? CString pDataSourceName = "";
?? int N;
?? while(strName.Find(".") != -1)
?? {
??? N = strName.Find(".");
??? pDataSourceName = pDataSourceName+strName.Left(N)+'.';
??? strName = strName.Right(strName.GetLength()-N-1);
?? }
?? strName = pDataSourceName+strLayerName;
?? pDSName->put_Name(_bstr_t(strName));
?? pDLayer->put_DataSourceName((INamePtr)pDSName);
?? return pFeatureLayer;
?}
?catch(...)
?{
??return NULL;
?}
}
posted on 2006-09-10 11:15 zdygis 閱讀(678) 評論(0) 編輯 收藏 所屬分類: ArcGis