Need help increasing speed adding a set of pushpins

SinoTech
02-04-2008, 09:57 AM
Hi all,
I'm not very familiar with MapPoint yet, but already got some basics. However, currently I have a problem when displaying a bunch of push-pins. Somewhere here in the fourm I found code importing data from a file, which works fine.
That's the code:

m_dsStopPoints = m_DataSets.ImportData(m_strStopPointsPath, NULL, geoCountryDefault, geoDelimiterDefault, NULL);
m_dsStopPoints.SetSymbol(18);
int iLength = m_dsStopPoints.GetRecordCount();

if(!m_dsStopPoints.GetRecordCount ())
return;

m_DataSets.ZoomTo ();
That code needs around 0.5 seconds for importing and displaying around 135 pushpins. Unfortunatelly the pushpins I need to display are not contained in a file, but in memory instead. So the code above does not work. The code I use for my purpose is as follows:

_myPushPinSet= m_DataSets.AddPushpinSet(L"Pushpins");

for(itGPSPoints = _vecStopPoints.begin() ; itGPSPoints != _vecStopPoints.end(); itGPSPoints++)
{
locLocation = m_objMap.GetLocation( (*itGPSPoints)->GetLatitude(), (*itGPSPoints)->GetLongitude(), 2.0);
pinPushpin = m_objMap.AddPushpin(locLocation, L"Stoppoint");
pinPushpin.SetSymbol(18);
pinPushpin.MoveTo(_setStopPoints);
}
_myPushPinSet.SetFieldNamesVisibleInBalloon(TRUE);
_myPushPinSet.ZoomTo();
So I create a "CDataSet" and fill it with points ("itGPSPoints" is an iterator of a vector containg GPS-Points). However, this code needs arround 3 - 4 seconds, which is 8 times of what the first code does.

My theorie is as follows:
The first code imports all the data first, and then draws them all to the map.
The second code adds the data point by point, and draws them each time a new point is added.
That's just a theory, but would explain why my code is so slow.

Maybe someone can point me out on how to update my code in a way to make it more efficient.

Cheers,

Sino

208_Fireball
02-04-2008, 06:04 PM
From what I have seen, every call for the ActiveX control costs time. When you've got calls in a loop, this makes it quite obvious.

You've probably thought of, or discounted the following ideas already:

You could create an add-in for MapPoint which does some of the grunt-work (Add-ins run in-process with MapPoint.)

Alternatively, you could pre-form your mappoint Location objects as soon as you know the lat/lon data for each position you're interested in. This might speed things up a little, if you're using your code more than once per session.

Other than that, I'm out of ideas - sorry!

Cheers,

Dave

Wilfried
02-05-2008, 04:29 AM
Hi,

You can do 2 things, and probably you will get for both the same speed. That is writing your data to a file and then import it like in your first code. And secondly call windows API function LockWindowUpdate with the windows handle of the activeX control befor the loop, and again with a null after the loop.

the latter will prevent mappoint by drawing on the screen during the loop. Probably this is the major difference in speed if comparing the individual pushpins and the import.

SinoTech
02-06-2008, 03:12 PM
Thank you for your answers. It sounds obvious that invoking an ActiveX control within a loop slows down ... thank you for pointing that out (a point a I did not think about). The next thing I will try is the thing with the "LockWindowUpdate" function, as this is the easiest way ;-). If that did not work, I will try the other things such as writing my own add-in (a thing I've never tried before) and exporting the data to an external file first (not good programmers style :-( ).
Thank you again for your answers.

Cheers,

Sino

diyguypaul
02-26-2008, 09:42 AM
Just tried the lockwindowupdate and it works a treat:-D

I would also like to be able to print a mini map for each of the waypoints, bit like MapPoint does itself. I've got the directions ok, but the map is more tricky. Can you ZoomTo and then take a snapshot?

Any ideas?

Mattys Consulting
02-26-2008, 10:38 AM
For the purpose of archive searching, this topic should be moved
to a new thread.

Thanks,

Mike Mattys

SinoTech
03-06-2008, 04:22 PM
@diyguypaul
What did you exactly? For me it does not work. When I use "lockWindowUpdate" the added pushPins are only shown after all are added, but the time it needs is still the same. Also it seems as it still invokes a repaint for each added pushpin (at least the OnAfterRedrawMappointCtrl() function is still invoked).
What I have tired is the following:

1. Invoking the "LockWindowUpdate" functin of the mapPoint control directly:
m_wndMapPointCtrl.LockWindowUpdate();
[...]
m_wndMapPointCtrl.UnlockWindowUpdate();

2. Using the LockWindowUpdate(HWND) function
::LockWindowUpdate(m_wndMapPointCtrl.m_hWnd);
[...]
::LockWindowUpdate(NULL);

In both cases the PushPins are only shown after all have been added, but as said above, MapPoint seems to invoke a repaint for each added PushPin.

Cheers,

Sino

diyguypaul
03-07-2008, 09:05 AM
Hi Sino

Sorry my code is VB.Net but hopefully will help ;-)

PrivateDeclareAutoFunction SendMessage Lib"user32.dll" (ByVal hWnd As IntPtr, ByVal wMsg As Int32, ByVal wParam AsBoolean, ByVal lParam As Int32) As Int32
PrivateConst WM_SETREDRAW As Int32 = &HB
PrivateSub PlanIt()
.....SendMessage(AxMappointControl1.Handle, WM_SETREDRAW, False, 0)

Draw all the pins then when you finished

SendMessage(AxMappointControl1.Handle, WM_SETREDRAW, True, 0)

 
Web mp2kmag.com
mapforums.com