以下代码演示了当鼠标按下时,在按下的点处画一个图片
void CAddBasicResourceTool::OnMouseDownMap(short Button, short Shift, float X, float Y)
{
CMapXFeature ftr;
CMapXStyle style;
if ( !m_pView ) return ;
float screenX,screenY ;
double mapX,mapY ;
screenX = X;
screenY = Y;
CHtMapX & m_MapX = m_pView->GetMapX() ;
if ( m_MapX.GetCurrentTool() == MAP_ADDBASICRESOURCE_TOOL ) {
if (ftr.CreateDispatch(ftr.GetClsid())){
ftr = m_MapX.GetFeatureFactory().CreateSymbol() ;
style = ftr.GetStyle() ;
style.SetSymbolBitmapName("CAR1-32.BMP");
style.SetSymbolBitmapSize( 32 );
style.SetSymbolBitmapTransparent( TRUE ) ;
ftr.SetStyle( style ) ;
m_MapX.ConvertCoord(&screenX,&screenY,&mapX,&mapY,miScreenToMap);
ftr.GetPoint().Set( mapX , mapY ) ;
if ( !m_MapX.LayerExist("tmp") ) {
m_MapX.GetLayers().CreateLayer( "tmp" , "layertmp" ) ;
}
m_MapX.GetLayers().Item("tmp").AddFeature( ftr ) ;
}
}
}
{
CMapXFeature ftr;
CMapXStyle style;
if ( !m_pView ) return ;
float screenX,screenY ;
double mapX,mapY ;
screenX = X;
screenY = Y;
CHtMapX & m_MapX = m_pView->GetMapX() ;
if ( m_MapX.GetCurrentTool() == MAP_ADDBASICRESOURCE_TOOL ) {
if (ftr.CreateDispatch(ftr.GetClsid())){
ftr = m_MapX.GetFeatureFactory().CreateSymbol() ;
style = ftr.GetStyle() ;
style.SetSymbolBitmapName("CAR1-32.BMP");
style.SetSymbolBitmapSize( 32 );
style.SetSymbolBitmapTransparent( TRUE ) ;
ftr.SetStyle( style ) ;
m_MapX.ConvertCoord(&screenX,&screenY,&mapX,&mapY,miScreenToMap);
ftr.GetPoint().Set( mapX , mapY ) ;
if ( !m_MapX.LayerExist("tmp") ) {
m_MapX.GetLayers().CreateLayer( "tmp" , "layertmp" ) ;
}
m_MapX.GetLayers().Item("tmp").AddFeature( ftr ) ;
}
}
}