void CmapwingisTest2View::OnToolsAddTiffLayer()
{
TCHAR szFilters[]= _T("TIFF Files (*.tif)|*.tif||");
CFileDialog fileDlg (TRUE,_T("tif"),_T("*.tif"),
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("tif")==strExt)
{
// 创建图像接口打开图像加入地图
mapWindow::IImagePtr pImage;
pImage.CreateInstance(__uuidof(mapWindow::Image));
pImage->Open(_bstr_t(m_strFilePath),mapWindow::USE_FILE_EXTENSION,TRUE,NULL);
m_map.AddLayer(pImage,true);
mapWindow::ILabelsPtr labels;
pImage->get_Labels( &labels );
labels->PutFontSize(12);
labels->PutFontBold(true);
labels->PutFontOutlineVisible(true);
labels->PutFontOutlineWidth(4);
mapWindow::ILabelCategoryPtr cat;
labels->AddCategory("Red");
//cat->PutFontColor(RGB(255,0,0));
mapWindow::IExtentsPtr ext = pImage->GetExtents();
double xmin,xmax,ymin,ymax;
ext->get_xMax(&xmax);
ext->get_xMin(&xmin);
ext->get_yMax(&ymax);
ext->get_yMin(&ymin);
double xRange = xmax-xmin;
double yRange = ymax-ymin;
CString str;
for (int i = 0; i < 100; i++)
{
double x=xRange*(rand()%9)*0.1;
double y=yRange* ( rand()%9 )/10.0;
int categoryIndex = i % 3;
str.Format("%d",i);(http://www.amjmh.com/v/BIBRGZ_558768/)
labels->AddLabel( _bstr_t(str ),xmin+x,ymin+y,i*3.6,categoryIndex);
}
}
}
return;
}