[mapguide-users] Viewer API Selection Timing Issues
Buscher, Shane
Shane.Buscher at nngco.com
Thu Mar 22 18:19:27 EDT 2007
Walt,
Thanks for your solution. Here's essentially what I had to do to get
my app to work. The fundamental difference between your example (very
helpful) and mine is that I'm selecting with SetSelectionXML viewer api
function, while you were having the user manually select a feature and
storing it in memory. Thanks again.
var xmlSelection
function pauseForMap(xmlSel, x, y)
{
xmlSelection = xmlSel
parent.parent.ZoomToView(x, y, 15, true);
setTimeout("select()", 0);
}
function select()
{
parent.parent.mapFrame.emapViewer.WaitForMapUpdated();
parent.parent.SetSelectionXML(xmlSelection);
}
________________________________
From: mapguide-users-bounces at lists.osgeo.org
[mailto:mapguide-users-bounces at lists.osgeo.org] On Behalf Of Walt
Welton-Lair
Sent: Friday, March 16, 2007 9:17 PM
To: MapGuide Users Mail List
Subject: RE: [mapguide-users] Viewer API Selection Timing Issues
Ok, I debugged into this a little and learned something. Here's the
test I did:
* selected a feature and stored the selection XML (using
SerializeSet)
* cleared the selection and panned the view until the feature
was no longer visible
* called the following code:
EMapViewer.ZoomToView(centerX, centerY, scale);
EMapViewer.Refresh();
EMapViewer.WaitForMapUpdated();
EMapViewer.SelectionSet =
EMapViewer.DeserializeSet(selectionXML);
The view was correctly updated, but, like you, nothing got selected.
I then looked at the viewer code, and here's what happens:
* we call Refresh, which posts a message to the message queue
* the handler for that message initiates the refresh, and also
sets the variable used by WaitForMapUpdated
So what I think goes wrong for us is that we call Refresh - which posts
the message - and then straight afterwards we call WaitForMapUpdated -
but the message has not yet been processed and so WaitForMapUpdated
returns right away.
I modified my code to pause slightly after the call to Refresh using
setWindow, and then it worked. In fact, it worked even when I set the
delay to 0 ms. I think that's because setWindow is asynchronous, and so
right after it's called Windows can get back to processing messages in
the queue.
I also did a test where I ran a loop after the call to Refresh to
simulate a delay, but that didn't work.
Anyway, I've attached a zip containing my test. You can try it out
yourself - just modify the LoadMap method to point to your server. Once
the map loads, zoom in and select a feature and click on "Capture
Selection". Then deselect it, adjust the view so the feature is no
longer visible, and click on "Restore Selection".
Walt
________________________________
From: mapguide-users-bounces at lists.osgeo.org
[mailto:mapguide-users-bounces at lists.osgeo.org] On Behalf Of Buscher,
Shane
Sent: Friday, March 16, 2007 6:32 PM
To: MapGuide Users Mail List
Subject: RE: [mapguide-users] Viewer API Selection Timing Issues
Walt,
I'm not having any success with the WaitForMapUpdated function. There's
several steps I've taken in my qwest to get this working:
Here's the original problem. When I do this on the client, passing in
the correct variables, the DWF viewer zooms to the point but does not
highlight it.
ZoomToView(x, y, scale, true);
SetSelectionXML(xmlSet);
If I pause after the zoom, the selected feature successfully highlights.
For instance, the time it takes to close a window after zooming will
result in a highlight:
ZoomToView(x, y, scale, true);
Alert('pausing');
SetSelectionXML(xmlSet);
So I tried several combinations of both the WaitForMapUpdated and the
Busy property. I was never successful at obtaining a 'busy' state for
the map. I think that this means WaitForMapUpdated doesn't include map
refreshes. I was successful at getting a non-busy state of the map with
the Busy property, making sure that my javascript code was executing
correctly.
ZoomToView(x, y, scale, true);
WaitForMapUpdated();
SetSelectionXML(xmlSet);
ZoomToView(x, y, scale, true);
while
(parent.parent.mapFrame.emapViewer.DocumentHandler.Busy==true) {
parent.parent.mapFrame.emapViewer.DocumentHandler.WaitForMapUpdated();
}
SetSelectionXML(xmlSet);
So now I am really stuck. My only option that I can see is to put some
predetermined pause between the ZoomToView and SetSelectionXML methods.
This isn't a good solution, but my only other alternative is to switch
over to the AJAX viewer. That's doable, but not preferred. Is there
anything else you can think of doing? Given that this problem makes it
impossible to zoom to a selected feature that's not in the viewer map
extent, would this be considered functionality that needs to be
supported by the DWF Viewer?
Regards,
Shane
________________________________
From: mapguide-users-bounces at lists.osgeo.org
[mailto:mapguide-users-bounces at lists.osgeo.org] On Behalf Of Walt
Welton-Lair
Sent: Thursday, March 15, 2007 10:12 AM
To: MapGuide Users Mail List
Subject: RE: [mapguide-users] Viewer API Selection Timing Issues
You're using DWF Viewer right?
With DWF Viewer there's a WaitForMapUpdated API you can call on the
EMapViewer document handler. That method is precisely there to solve
your kind of problem. Just call it after the zoom call and before the
select.
I sent you all the DWF Viewer API a while back, so you have the
necessary information.
In general, the difficulty is that the MapGuide "client API" is the API
common to DWF and AJAX. DWF Viewer has tons more API available (like
this WaitForMapUpdated method) that's just not exposed in the MapGuide
client API layer.
Walt
________________________________
From: mapguide-users-bounces at lists.osgeo.org
[mailto:mapguide-users-bounces at lists.osgeo.org] On Behalf Of Buscher,
Shane
Sent: Thursday, March 15, 2007 4:02 PM
To: Mapguide_users at lists.osgeo.org
Subject: [mapguide-users] Viewer API Selection Timing Issues
I may be going about this the wrong way, but here's my problem. I want
to select a feature based on an attribute query in the task pane,
automatically zoom to it, and highlight it. I have found highlighting
the feature to be the most problematic because the feature has to exist
within the map frame extent before it can be selected with the
SetSelectionXML() Viewer api function. As far as I know, this is the
only function call you can make in MapGuide to highlight features.
Knowing that SetSelectionXML() will only highlight features in the
current map extent, I preceded to zoom to the feature (ZoomToView)
before calling SetSelectionXML(). The problem is that the map can't
zoom quick enough, and so no features are highlighted:
ZoomToView(x, y, scale);
SetSelectionXML(xmlSet); //no features exist yet because of delay in
ZoomToView
I don't have any problems when the feature already exists in my map
extent. Does anyone have a workaround or better method to accomplish
this? The only hack can think of is to pause the execution of
SetSelectionXML() until ZoomoView is complete, but I'm not sure the best
way to code this.
Regards,
Shane
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/mapguide-users/attachments/20070322/590177ef/attachment-0001.html
More information about the mapguide-users
mailing list