void CmapwingisTest2View::OnToolsAdd32780()
{
TCHAR szFilters[]= _T("SHP Files (*.shp)|*.shp||");
CFileDialog fileDlg (TRUE,_T("shp"),_T("*.shp"),
OFN_FILEMUSTEXIST| OFN_HIDEREADONLY, szFilters, this);
if( fileDlg.DoModal ()!=IDOK ) return;
CString m_strFilePath = fileDlg.GetPathName();
if (_T("")!=m_strFilePath)
{
// 先删除所有图层
//m_map.RemoveAllLayers();
// 获取后缀名判断文件是tif图像还是shp文件
CString strExt = m_strFilePath.Right(3);
if (_T("shp")==strExt)
{
mapWindow::IShapefilePtr pshapefilebound;
pshapefilebound.CreateInstance(__uuidof(mapWindow::Shapefile));
pshapefilebound->Open(_bstr_t(m_strFilePath),false );
m_map.AddLayer( pshapefilebound,TRUE) ;
mapWindow::ILabelsPtr labels=pshapefilebound->GetLabels( );//?
labels->PutFontSize(12);
labels->PutFontBold(true);
labels->PutFontOutlineVisible(true);
labels->PutFontOutlineWidth(4);
mapWindow::ILabelCategoryPtr cat;
labels->AddCategory("Red");
long fieldIndex = 1;//默认首个列
CString str;
IFieldPtr Fields;
//pshapefilebound->GetField(0);
_variant_t var;
for (long i = 0; i < pshapefilebound->GetNumShapes() ; i++)
{
IShapePtr shp = pshapefilebound->GetShape(i);
IPointPtr pt= shp->GetCenter( );
var = pshapefilebound->GetCellValue(fieldIndex, i);
str = var.bstrVal; //需要判断本列是否为文本,待解决
labels->AddLabel( _bstr_t(str ),pt->Getx(),pt->Gety(),0,laCenter);
}
labels->put_Synchronized(true);