[mapguide-users] DWF Viewer API for managing selections
Traian Stanev
traian.stanev at autodesk.com
Thu May 4 19:44:03 EDT 2006
The reason is that the key can be binary, while for DWF output we need to put it in an XML file. Hence the base 64 encoding. Fortunately, it works the same for all FDO providers since it is done outside FDO on the MapGuide side of things.
Traian
-----Original Message-----
From: Joel Carranza [mailto:jec at gatekeeper.com]
Sent: Thu 5/4/2006 7:37 PM
To: users at mapguide.osgeo.org
Cc:
Subject: RE: [mapguide-users] DWF Viewer API for managing selections
That is helpful. Thanks Traian.
I Base64 decoded the feature ID and out came my PK. Cool.
Do both the Oracle and ODBC FDOs work this way?
Why does MapGuide base 64 encode in the first place? It seems like it is
just going to make things complicated for the developer. Any possibility
that this will change in the future?
You can use the below javascript code to encode and decode, which I stole
from
http://rumkin.com/tools/compression/base64.php
var keyStr =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
function encode64(input) {
var output = "";
var chr1, chr2, chr3;
var enc1, enc2, enc3, enc4;
var i = 0;
do {
chr1 = input.charCodeAt(i++);
chr2 = input.charCodeAt(i++);
chr3 = input.charCodeAt(i++);
enc1 = chr1 >> 2;
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
enc4 = chr3 & 63;
if (isNaN(chr2)) {
enc3 = enc4 = 64;
} else if (isNaN(chr3)) {
enc4 = 64;
}
output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) +
keyStr.charAt(enc3) + keyStr.charAt(enc4);
} while (i < input.length);
return output;
}
function decode64(input) {
var output = "";
var chr1, chr2, chr3;
var enc1, enc2, enc3, enc4;
var i = 0;
// remove all characters that are not A-Z, a-z, 0-9, +, /, or =
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
do {
enc1 = keyStr.indexOf(input.charAt(i++));
enc2 = keyStr.indexOf(input.charAt(i++));
enc3 = keyStr.indexOf(input.charAt(i++));
enc4 = keyStr.indexOf(input.charAt(i++));
chr1 = (enc1 << 2) | (enc2 >> 4);
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
chr3 = ((enc3 & 3) << 6) | enc4;
output = output + String.fromCharCode(chr1);
if (enc3 != 64) {
output = output + String.fromCharCode(chr2);
}
if (enc4 != 64) {
output = output + String.fromCharCode(chr3);
}
} while (i < input.length);
return output;
}
--Joel
-----Original Message-----
From: Traian Stanev [mailto:traian.stanev at autodesk.com]
Sent: Thursday, May 04, 2006 4:11 PM
To: users at mapguide.osgeo.org
Subject: RE: [mapguide-users] DWF Viewer API for managing selections
Not sure how helpful this will be, but... the MapGuide feature ID is a base
64 encoded version of the actual feature key (that comes from FDO). If you
run it through a base 64 decoder, you will get the binary original back. It
will be in little-endian format.
To see how the web extensions code decodes this for use with feature
queries, look at MgSelection::GenerateFilter, starting at a line saying
m_stream->FromBase64(). If you have the MgSelection object and one selected
feature, you could probably call this directly to get your feature id back
in a string.
To see how the feature ID is encoded, look in KeyEncode.cpp (less useful,
but good for information if you want to roll your own decoder).
All this get more complicated when you use more than one attribute as the
feature key, but this is rare.
Traian
-----Original Message-----
From: Andy Morsell [mailto:amorsell at spatialgis.com]
Sent: Thu 5/4/2006 6:49 PM
To: users at mapguide.osgeo.org
Cc:
Subject: RE: [mapguide-users] DWF Viewer API for managing selections
Regarding: "Can I somehow configure what the feature ID of a feature source
is based on?" I had this same question when setting up some functions to
emulate MapGuide 6.5 reporting functionality and determined that the answer
is "no". In this case, the source data in MGOS is completely disparate from
an external database (and joins did not work back then). I was using some
existing ASP reports from a MG6.5 site that accepted Parcel ID's as URL
parameters. In order to accomplish this, I had to use the API to get the
selection set, then use the FDO API to query the MGOS datasource to extract
the Parcel ID's that were in the datasource based on the Feature ID's and
then pass that on to the external report.
That's a lot of overhead for a simple function. I would much rather be able
to specify on a layer by layer basis what I want MY key field to be (much
like the old MapGuide). If the internal Feature ID also needs to come along
for the ride, then so be it. This is also a problem with the
$CurrentSelection parameter when using the Invoke URL command option in
Studio. In many cases, the Feature ID obtained from the selection is not
going to do the developer any good and they will have to add the step to go
get meaningful values.
Andy Morsell, P.E.
Spatial Integrators, Inc.
http://www.SpatialGIS.com
_____
From: Joel Carranza [mailto:jec at gatekeeper.com]
Sent: Thursday, May 04, 2006 3:12 PM
To: users at mapguide.osgeo.org
Subject: RE: [mapguide-users] DWF Viewer API for managing selections
My end goal is to emulate 6.5 behavior in that i need to able to select
objects via map key and get the selected objects's map key. The problem I
see is that the feature ID appears to be some kind of internal ID and not
related back to a user specified property of the feature source (say for
example the PK of the database row). As such, I have no way to tie my data
to a feature on the map. Making an additional server side call seems kindof
ridiculous.
So my question is this:
- Can I somehow configure what the feature ID of a feature source is based
on? How do you currently generate feature IDs ?
- We are willing to accept the limitation of only selecting/getting the
selection of onscreen objects. How can I access attribute data for the
features that are currently visible on the screen?
Thanks,
--Joel
_____
From: Walt Welton-Lair [mailto:walt.welton-lair at autodesk.com]
Sent: Thursday, May 04, 2006 2:44 PM
To: users at mapguide.osgeo.org
Subject: RE: [mapguide-users] DWF Viewer API for managing selections
The selection set will be a collection of IAdEMapInstance objects. Each
object has three properties:
- LayerObjectId the unique ID of the layer containing the instance
- ObjectClass the feature class
- Id the feature ID
You cannot directly access the attributes of features through the DWF Viewer
API. That's because the viewer only stores data (graphical + attributes)
for the features currently visible on the screen. This is one of the major
differences between MapGuide 6.5 and MapGuide OS. Note also that the
selection set is persistent. If you select a feature, pan the view so it's
offscreen, and then pan the view so its onscreeen again then you'll still
see it selected. The IAdEMapInstance objects provide the minimum
information needed to uniquely identify a feature, and are what allow this
persistent selection behavior.
If you want to obtain the attributes of a feature, then you'll need to go
beyond the DWF Viewer API and make a SelectFeatures feature service request.
_____
From: Joel Carranza [mailto:jec at gatekeeper.com]
Sent: Tuesday, May 02, 2006 4:02 PM
To: users at mapguide.osgeo.org
Subject: [mapguide-users] DWF Viewer API for managing selections
I am trying to write some code to inspect the current selection using the
DWF Viewer. However, I am unable to find any documentation on what comes out
of the "selectionSet" property of the viewer. I see that it is a collection
of some kind, but I don't know what the type that comes out of the
collection is. I consulted the "Viewer APIs for Emap" document but didn't
see any relevant information.
The code I am using is something like the following:
var selectionSet = emapViewer.SelectionSet;
for(selEnumerator = new Enumerator(selectionSet);
!selEnumerator.atEnd(); selEnumerator.moveNext())
{
var feature = selEnumerator.item();
var id = feature.id;
var layerId = feature.LayerObjectId;
// what is feature?
// what are its properties and methods?
}
Specifcally, I want programmatic access to the object properties that are
shown in the properties pane. Anybody know how to do this?
--Joel
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe at mapguide.osgeo.org
For additional commands, e-mail: users-help at mapguide.osgeo.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/ms-tnef
Size: 6776 bytes
Desc: not available
Url : http://lists.osgeo.org/pipermail/mapguide-users/attachments/20060504/1bb03ec0/attachment.bin
More information about the Mapguide-users
mailing list