www.sdlsuite.com Forum Index www.sdlsuite.com
Discussion of technical aspects of the SDL Component Suite
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Saving map center location

 
Post new topic   Reply to topic    www.sdlsuite.com Forum Index -> GeoPack
View previous topic :: View next topic  
Author Message
hansdb



Joined: 21 Nov 2012
Posts: 4

PostPosted: Sat Dec 15, 2012 1:45 pm    Post subject: Saving map center location Reply with quote

We need to be able to restore the last session a user had with our application. Regarding GeoMap this means restoring the zoom-level and the part of the map that was visible.
Saving and restoring the zoom-level works fine. However, when saving and restoring the map we get some strange behavour.

Our approach is to save & restore the GeoMap center position. We restore using:
Code:
GeoMap.Magnification := IniFile.State_Zoomlevel
GeoMap.BringLocationToCenter( IniFile.State_CenterLatitude, IniFile.State_CenterLongitude )


As there is no function available to retrieve GeoMap's center position at any time, we used the following code to save the center position:

Code:

X := GeoMap.Width div 2;
Y := GeoMap.Height div 2;
CenterPoint := GeoMap.ControlToMapImage( Point(X,Y) );
IniFile.State_CenterLatitude := GeoMap.CalcLatitude( CenterPoint, valid );
IniFile.State_CenterLongitude := GeoMap.CalcLongitude( CenterPoint, valid );


The result is that when the session is restored, the former center position is offset to the upper-left quadrant. I dont know if I made a mistake in the code or if there is something else going on...

Does anyone have a sample available to save the GeoMap center position at any time?

@Hans: would you consider adding a function to TGeoMap to retrieve the center position?
_________________
Hans de Bue
----------------------
Promanent b.v.
www.promanent.com
Back to top
View user's profile Send private message
hansdb



Joined: 21 Nov 2012
Posts: 4

PostPosted: Fri Feb 01, 2013 3:05 pm    Post subject: An update Reply with quote

Cause and workaround found.

The code to determine the mapcenter and restore it later (see post) works. The observed offset was caused by the main form windowstate property. If FormMain.WindowState is set to wsMaximized, the maximization takes place after OnFormShow() is handled.

The code to restore the map center was put in OnFormShow(). As a result, the order of things executes was: a) fetch last known center, b) set map to that centerpoint, c) maximize window. As a result of this, the map appears to be offset from that center.

The workaround I used is to set WindowState to wsNormal and force FormMain.BoundsRect to Screen.PrimaryMonitor.WorkingArea just before restoring the centerpoint.

If anyone knows a better approach, please share.
_________________
Hans de Bue
----------------------
Promanent b.v.
www.promanent.com
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    www.sdlsuite.com Forum Index -> GeoPack All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group