需求問題:
多個影像文件圖層,和其對應的幾何範圍,需要一起顯示,GIS內核只設計了基本的單個影像和單個地物類繪製的圖層,請參見前面
GIS內核-加載tif 影像文件圖層,以及GsFeatureLayer.
class GsCoustomRasterLayer :public GsLayer
{
public:
GsCoustomRasterLayer();
~GsCoustomRasterLayer();
private:
GsVector<GsRasterLayerPtr> m_Lys;
GsFeatureLayerPtr m_ptrfcsLayer;
GsString m_ClipGeometryField;
virtual bool InnerDraw(GsDisplay* pDisplay, GsTrackCancel* pCancel, GsDrawPhase eDrawPhase);
//根據特定規則找到每個影像圖層對應的數據集裁切幾何的對象
GsGeometry* FindGeometry(const char *strLyrName);
public:
// 通過 GsLayer 繼承
virtual GsBox Extent(GsSpatialReference * pTargetSR = 0) override;
virtual bool HasSelection() override;
virtual GsSmarterPtr<GsLayer> Clone() override;
void AddRasterLayer(GsRasterLayer *pLayer);
void RemoveRasterLayer(const char * strLyrName);
void ClearLayers();
GsVector<GsRasterLayerPtr >* RasterLayers();
GsFeatureLayer* FeatureLayer();
void FeatureLayer(GsFeatureLayer* pFeaLyr);
};
GS_SMARTER_PTR(GsCoustomRasterLayer);
cpp文件實現:
GsCoustomRasterLayer::GsCoustomRasterLayer()
{
}
GsCoustomRasterLayer::~GsCoustomRasterLayer()
{
}
bool GsCoustomRasterLayer::InnerDraw(GsDisplay * pDisplay, GsTrackCancel * pCancel, GsDrawPhase eDrawPhase)
{
std::vector<GsRasterLayerPtr >::iterator it = m_Lys.begin();
for (; it != m_Lys.end(); it++)
{
GsGeometryPtr pGeo = FindGeometry((*it)->Name().c_str());
(*it)->ClipGeometry(pGeo);
(*it)->Draw(pDisplay, pCancel, eDrawPhase);
}
m_ptrfcsLayer->Draw(pDisplay, pCancel, eDrawPhase);
return false;
}
GsGeometry * GsCoustomRasterLayer::FindGeometry(const char * strLyrName)
{
return nullptr;
}
GsBox GsCoustomRasterLayer::Extent(GsSpatialReference * pTargetSR)
{
std::vector<GsRasterLayerPtr >::iterator it = m_Lys.begin();
GsBox boxret;
for (; it != m_Lys.end(); it++)
{
GsBox box = (*it)->Extent();
if (box.IsValid())
boxret.Union(box);
}
return boxret;
}
bool GsCoustomRasterLayer::HasSelection()
{
return false;
}
GsSmarterPtr<GsLayer> GsCoustomRasterLayer::Clone()
{
std::vector<GsRasterLayerPtr >::iterator it = m_Lys.begin();
GsCoustomRasterLayerPtr ptrColne = new GsCoustomRasterLayer();
for (; it != m_Lys.end(); it++)
ptrColne->RasterLayers()->push_back((*it)->Clone());
GsFeatureLayerPtr pLyr = m_ptrfcsLayer->Clone();
ptrColne->FeatureLayer(pLyr);
//基礎屬性
GsLayerPtr pLayer = ptrColne;
pLayer->Name(Name().c_str());
pLayer->Visible(Visible());
pLayer->AliasName(AliasName().c_str());
pLayer->MinScale(MinScale());
pLayer->MaxScale(MaxScale());
pLayer->ReferenceScale(ReferenceScale());
pLayer->Tag(Tag());
return ptrColne;
}
void GsCoustomRasterLayer::AddRasterLayer(GsRasterLayer * pLayer)
{
m_Lys.push_back(pLayer);
}
void GsCoustomRasterLayer::RemoveRasterLayer(const char * strLyrName)
{
std::vector<GsRasterLayerPtr >::iterator it = m_Lys.begin();
for (; it != m_Lys.end(); it++)
{
if (GsCRT::_stricmp((*it)->Name().c_str(), strLyrName))
{
m_Lys.erase(it);
break;
}
}
}
void GsCoustomRasterLayer::ClearLayers()
{
m_Lys.clear();
}
GsVector<GsRasterLayerPtr>* GsCoustomRasterLayer::RasterLayers()
{
return &m_Lys;
}
GsFeatureLayer * GsCoustomRasterLayer::FeatureLayer()
{
return m_ptrfcsLayer.p;
}
void GsCoustomRasterLayer::FeatureLayer(GsFeatureLayer * pFeaLyr)
{
m_ptrfcsLayer = pFeaLyr;
}
這個圖層的使用 就是填充兩個 GsVector<GsRasterLayerPtr> m_Lys和 GsFeatureLayerPtr m_ptrfcsLayer; 其中有個Clipgeometry 對象 這個需要根據業務自身去定義,目前這裏接口定義好的位根據名稱去FetureLayer內部找Geometry .