/*
MapInfo Products Knowledge Base
Product: MapX
Version: 2.0
Platform: Window 95/Windows NT
Category: C++
Summary:
A ToolUsed handler for C++ that changes the style of a feature.
Question:
A ToolUsed handler for C++.
Answer:
Below is a ToolUsed handler for C++ that: changes the style of an existing feature; and adds new Symbol features to the layer.
*/
void CMapxSampleView::OnToolUsed( short ToolNum, double X1, double Y1, double X2, double Y2, double Distance,
BOOL Shift, BOOL Ctrl, BOOL * EnableDefault)
{
CString str;
CMapXPoint pnt;
str.Format("Tool=%d, [%f,%f] [%f, %f], dist=%f, %s %s ",ToolNum, X1,Y1,X2,Y2,Distance, (Shift)?"Shift":"",(Ctrl)?"Ctrl":"");
TRACE(str);
// change the style of the feature under the cursor
if (ToolNum == MAP_TOOL_CHANGESTYLE) {
try
{
// Need the dispatch to use the point
if (pnt.CreateDispatch(pnt.GetClsid()))
{
pnt.Set(X1, Y1);
}
else
{
// something went wrong, can't use the point...
AfxThrowOleException(CO_E_CLASS_CREATE_FAILED);
}
CMapXLayers layers = m_ctrlMapX.GetLayers();
// Get the USA Layer features under the cursor
CMapXFeatures ftrs = layers.Item("USA").SearchAtPoint(LPDISPATCH(pnt));
// work on only the first feature
CMapXFeature ftr = ftrs.Item(1);
// get the style object from the feature
CMapXStyle style = ftr.GetStyle();
style.SetRegionBackColor(255);
// update the feature in the layer
ftr.Update();
}
catch (COleDispatchException *e)
{
e->ReportError();
e->Delete();
}
catch (COleException *e)
{
e->ReportError();
e->Delete();
}
}
// place a new symbol at the point clicked on
else if (ToolNum == MAP_TOOL_NEWPOINT)
{
try
{
CMapXLayers layers = m_ctrlMapX.GetLayers();
CMapXFeature ftr;
// Need the dispatch id to use the feature
if (ftr.CreateDispatch(ftr.GetClsid()))
{
// Symbol feature
ftr.SetType(miFeatureTypeSymbol);
// Get the point object from the feature and call the Set method
ftr.GetPoint().Set(X1, Y1);
// Add it to the layer
layers.Item("USA").AddFeature(ftr);
}
else
{
AfxThrowOleException(CO_E_CLASS_CREATE_FAILED);
}
}
catch (COleDispatchException *e)
{
e->ReportError();
e->Delete();
}
catch (COleException *e)
{
e->ReportError();
e->Delete();
}
}
}
// Last Modified: 2001-06-04 12:56:31
MapInfo Products Knowledge Base
Product: MapX
Version: 2.0
Platform: Window 95/Windows NT
Category: C++
Summary:
A ToolUsed handler for C++ that changes the style of a feature.
Question:
A ToolUsed handler for C++.
Answer:
Below is a ToolUsed handler for C++ that: changes the style of an existing feature; and adds new Symbol features to the layer.
*/
void CMapxSampleView::OnToolUsed( short ToolNum, double X1, double Y1, double X2, double Y2, double Distance,
BOOL Shift, BOOL Ctrl, BOOL * EnableDefault)
{
CString str;
CMapXPoint pnt;
str.Format("Tool=%d, [%f,%f] [%f, %f], dist=%f, %s %s ",ToolNum, X1,Y1,X2,Y2,Distance, (Shift)?"Shift":"",(Ctrl)?"Ctrl":"");
TRACE(str);
// change the style of the feature under the cursor
if (ToolNum == MAP_TOOL_CHANGESTYLE) {
try
{
// Need the dispatch to use the point
if (pnt.CreateDispatch(pnt.GetClsid()))
{
pnt.Set(X1, Y1);
}
else
{
// something went wrong, can't use the point...
AfxThrowOleException(CO_E_CLASS_CREATE_FAILED);
}
CMapXLayers layers = m_ctrlMapX.GetLayers();
// Get the USA Layer features under the cursor
CMapXFeatures ftrs = layers.Item("USA").SearchAtPoint(LPDISPATCH(pnt));
// work on only the first feature
CMapXFeature ftr = ftrs.Item(1);
// get the style object from the feature
CMapXStyle style = ftr.GetStyle();
style.SetRegionBackColor(255);
// update the feature in the layer
ftr.Update();
}
catch (COleDispatchException *e)
{
e->ReportError();
e->Delete();
}
catch (COleException *e)
{
e->ReportError();
e->Delete();
}
}
// place a new symbol at the point clicked on
else if (ToolNum == MAP_TOOL_NEWPOINT)
{
try
{
CMapXLayers layers = m_ctrlMapX.GetLayers();
CMapXFeature ftr;
// Need the dispatch id to use the feature
if (ftr.CreateDispatch(ftr.GetClsid()))
{
// Symbol feature
ftr.SetType(miFeatureTypeSymbol);
// Get the point object from the feature and call the Set method
ftr.GetPoint().Set(X1, Y1);
// Add it to the layer
layers.Item("USA").AddFeature(ftr);
}
else
{
AfxThrowOleException(CO_E_CLASS_CREATE_FAILED);
}
}
catch (COleDispatchException *e)
{
e->ReportError();
e->Delete();
}
catch (COleException *e)
{
e->ReportError();
e->Delete();
}
}
}
// Last Modified: 2001-06-04 12:56:31