Using callback functions

Draw callback function

Keymap SDK has callback mechanism, allowing developers to run custom code after each object rendering. In Keymap SDK draw callback function declared as below:

bool (*_callbackDraw)()=NULL;

To enable draw callback function, declare your own callback function and assign _callbackDraw:

bool _myCallBackDraw()
{
	//my code here
	return false;//continue map rendering. Return true to interrupt.
}
//assign callback function
_callbackDraw = &_myCallBackDraw;

Search callback function

Read Fastest method of accessing all map objects intersected with specific rectangle section in Accessing map objects from your source code article.

Data import callback function

Data import function declared as below:

enum MplImportResult
{
	MPL_IMPORT_SUCCESS, //Import success
	MPL_IMPORT_INTERRUPTED, //Import interrupted
	MPL_IMPORT_MEDIA_ERROR, //Storage media error
	MPL_IMPORT_RAM_ERROR, // Not enough RAM
	MPL_IMPORT_UNKNOWN_ERROR//Other error
};
MplImportResult (*OGR2Mpl)(const char* strFileSrc,const char* strFileDest, int iRAM, bool (*_callbackF)(float));

Input:

strFileSrc is full path of source DB (e.g. C:\abc.shp)

strFileDest is import result (e.g. C:\abc.mpl)

iRAM is allowed RAM used for this import operation (in KB)

_callbackF is import callback function

Return value:

Import result.

The OGR2Mpl function exported in ImEx.dll:

HINSTANCE hImportDll = ::LoadLibrary("ImEx.dll");
OGR2Mpl=(MplImportResult(*)(const char*, const char*, int, bool (*_callbackF)(float)))GetProcAddress(m_hImportDll, "OGR2Mpl");  

Declare your import callback function:

bool _callbackImp(float dProgress)
{
	//dProgress is import progress in percent (0-100)
	return false;//continue import; return true to interrupt
}

Import data:

MplImportResult iResult = OGR2Mpl(strSource, strDest, 50000, _callbackImp);