[mapguide-users] Newbie needs help with project to query web -Thanks Kenneth, GEOGRAF one more question please?

Nick Aizen naizen at gcrconsulting.com
Sun May 4 22:02:21 EDT 2008


You’re idea helped me get over one obstacle, but I now seem to have one more. Below is my code from Deafult.aspx.

<%@ Page Language="c#" Debug="true"  %>
<%@ Import Namespace="OSGeo.MapGuide" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Text" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Collections.Specialized" %>


<%

MapGuideApi.MgInitializeWebTier(@"C:\Program Files\Autodesk\MapGuideEnterprise2008\WebServerExtensions\www\webconfig.ini");
MgUserInformation userInfo = new MgUserInformation("Administrator", "admin");
MgSite site = new MgSite();
site.Open(userInfo);
String sessionId = site.CreateSession();
String webLayout = "Library://DevTV/HelloWorld.WebLayout";
Globals.gSessionID = sessionId; //Holds my session ID value

%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<body>
<iframe id="viewerFrame"  width="100%" height="1000px" src="/mapguide2008/mapviewernet/ajaxviewer.aspx?SESSION=<%=sessionId%>&WEBLAYOUT=<%=webLayout%>"onload="OnMapLoaded()"></></iframe>
<iframe style="display: none" src="" id="maploaded""></iframe>
<script>
function OnMapLoaded()
{
   document.getElementById('maploaded').src = 'maploaded.aspx';
}
</script>
</body>
</html>


Code in maploaded.aspx

<%@ Page Language="C#" %>
<%@ Import Namespace="OSGeo.MapGuide" %>

<script runat="server">
    MgGeometry getGeometry(String district, MgFeatureService featureService)
    {
        MgFeatureQueryOptions districtQuery = new MgFeatureQueryOptions();
        districtQuery.SetFilter("Autogenerated_SDF_ID = " + district);
        MgResourceIdentifier districtId = new MgResourceIdentifier("Library://Samples/Sheboygan/Data/VotingDistricts.FeatureSource");
        MgFeatureReader featureReader = featureService.SelectFeatures(districtId, "VotingDistricts", districtQuery);
        featureReader.ReadNext();
        MgByteReader geometryBytes = featureReader.GetGeometry("Data");
        MgAgfReaderWriter agfReader = new MgAgfReaderWriter();
        MgGeometry districtGeometry = agfReader.Read(geometryBytes);
        return districtGeometry;
    }
</script>

<%
    String sessionId = Globals.gSessionID; //Global from Default.aspx
    String district = "3";
    String name = "ELSO";

    string realPath = Request.ServerVariables["APPL_PHYSICAL_PATH"];
    String configPath = realPath + "webconfig.ini";
    MapGuideApi.MgInitializeWebTier(configPath);
    MgUserInformation userInfo = new MgUserInformation(sessionId);
    MgSiteConnection siteConnection = new MgSiteConnection();
    siteConnection.Open(userInfo);

    MgResourceService resService = (MgResourceService)siteConnection.CreateService(MgServiceType.ResourceService);
    MgFeatureService featureService = (MgFeatureService)siteConnection.CreateService(MgServiceType.FeatureService);
    MgMap map = new MgMap();
    map.Open(resService, "Sheboygan");

    //Get Geometry object: districtGeometry
    MgGeometry districtGeometry = getGeometry(district, featureService);
    MgFeatureQueryOptions nameQuery = new MgFeatureQueryOptions();
    nameQuery.SetFilter("RNAME LIKE '" + name + "%'");
    nameQuery.SetSpatialFilter("SHPGEOM", districtGeometry, MgFeatureSpatialOperations.Inside);
    MgResourceIdentifier parcelId = new MgResourceIdentifier("Library://Samples/Sheboygan/Data/Parcels.FeatureSource");
    MgFeatureReader featureReader = featureService.SelectFeatures(parcelId, "Parcels", nameQuery);
    //Highlight the query result on the map
    MgSelection selection = new MgSelection(map);
    MgLayer layer = (MgLayer)map.GetLayers().GetItem("Parcels");
    featureReader = featureService.SelectFeatures(parcelId, "Parcels", nameQuery);
    selection.AddFeatures(layer, featureReader, 0);
    String selectionXML = selection.ToXml();

%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<script type="text/javascript">
        function onPageLoad() {
            var selectionXML = '<%= selectionXML %>';
            parent.SetSelectionXML(selectionXML);
        }
    </script>
</html>


When the map comes up, nothing is selected…..you’ve been such a “HUGE” help, could you review what I have and give me you opinion please…many thanks.


Nick Aizen



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/mapguide-users/attachments/20080504/9cce1fa9/attachment.html


More information about the mapguide-users mailing list