[mapguide-users] Newbie needs help with project to query web

Nick Aizen naizen at gcrconsulting.com
Tue May 6 13:13:04 EDT 2008


Thanks, so much I will have to send you care package from New Orleans for your help....lol, I was able to get things functioning correctly with a sample project. Now I'm moving from a sample to a real world map created by our GIS dept. My code seems to work  fine (no exceptions), but it seems that the XML selection.ToXML is not created correctly actually compared to the sample project, only the XML shell is present. I followed the exact process in code which should work, my real world map is less complex than the sample project. Consisting of a single layer, map, and feature source. Below I have listed the objects and resources setup in MapGuide. Thanks for the expert help.


Map is called "Map"
Layout is called = "Layout"
Layer is called  = "ABC_Terminal"
Feature Source is called = "ABC_Terminal"
Class: ABC_Terminal

Data Properties
Property Name   Property Type
*FestId                  init32


Geometry Properties
Property Name   Geometry
Property Type                     surface
hasMeasures                      false
hasElevation       false

View data
FestId                                   Id
1                                              1
2                                              2
3                                              3
4                                              4
5                                              5
6                                              6
7                                              7
8                                              8
9                                              9
10                                           10
11                                           10
12                                           12


Here is the code, please note that MgFeatureQueryOptions filter is hard coded to filter ("FeatId = " + 1) and highlight.

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

<script runat="server">
    MgGeometry getGeometry(MgFeatureService featureService)
    {
                MgFeatureQueryOptions berthQuery = new MgFeatureQueryOptions();
                berthQuery.SetFilter("FeatId = " + 1);
                MgResourceIdentifier ResIDen = new MgResourceIdentifier("Library://PBM/Data/ABC_Terminal.FeatureSource");
                MgFeatureReader featureReader = featureService.SelectFeatures(ResIDen, "ABC_Terminal", berthQuery);
                featureReader.ReadNext();
                MgByteReader geometryBytes = featureReader.GetGeometry("Geometry");
                MgAgfReaderWriter agfReader = new MgAgfReaderWriter();
                MgGeometry districtGeometry = agfReader.Read(geometryBytes);
                return districtGeometry;
    }
</script>
<%

                String sessionId = Globals.gSessionID;
                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, "Map");

                //Get Geometry object: districtGeometry
                MgGeometry districtGeometry = getGeometry(featureService);
                MgFeatureQueryOptions nameQuery = new MgFeatureQueryOptions();
                nameQuery.SetFilter("FeatId = " + 1);
                nameQuery.SetSpatialFilter("Geometry", districtGeometry, MgFeatureSpatialOperations.Inside);

                MgResourceIdentifier parcelId = new MgResourceIdentifier("Library://PBM/Data/ABC_Terminal.FeatureSource");
                MgFeatureReader featureReader = featureService.SelectFeatures(parcelId, "ABC_Terminal", nameQuery);

                //Highlight the query result on the map
                MgSelection selection = new MgSelection(map);
                MgLayer layer = (MgLayer)map.GetLayers().GetItem("ABC_Terminal");
                featureReader = featureService.SelectFeatures(parcelId, "ABC_Terminal", nameQuery);
                selection.AddFeatures(layer, featureReader, 0);
                String selectionXML = selection.ToXml();
                selection.Save(resService, "Map");

%>
<!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>
    <title>Make Query</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta http-equiv="content-script-type" content="text/javascript" />
    <meta http-equiv="content-style-type" content="text/css" />


    <script type="text/javascript">
        function onPageLoad() {
          var selectionXML = '<%= selectionXML %>';
            parent.parent.SetSelectionXML(selectionXML);
            parent.parent.refresh;
        }
    </script>

</head>
<body>
</body>
</html>




From: mapguide-users-bounces at lists.osgeo.org [mailto:mapguide-users-bounces at lists.osgeo.org] On Behalf Of Kenneth, GEOGRAF A/S
Sent: Monday, May 05, 2008 2:57 PM
To: MapGuide Users Mail List
Subject: Re: [mapguide-users] Newbie needs help with project to query web

In the last line, try replacing:
String selectionXML = selection.ToXml();
with:
selection.Save(resService, "Sheboygan");

And instead of the JavaScript SetSelectionXml, try to do only a map refresh:
parent.GetMapFrame().Refresh();

If it does not work, can you post the string you get from "selection.ToXml();"?

Regards, Kenneth, GEOGRAF A/S


Nick Aizen skrev:
Do you have any code snippets on how and when to do this? My process was taken from andf online example provided by Autodesk and the process works when the selection code is called from a button click and  save is never called, which leaves me to wonder.."Am I doing something wrong?" I don't think I'm even effecting the viewer at all. Anyway...thanks for the help.





Nick Aizen













________________________________










_______________________________________________

mapguide-users mailing list

mapguide-users at lists.osgeo.org<mailto:mapguide-users at lists.osgeo.org>

http://lists.osgeo.org/mailman/listinfo/mapguide-users




From: mapguide-users-bounces at lists.osgeo.org [mailto:mapguide-users-bounces at lists.osgeo.org] On Behalf Of Kenneth, GEOGRAF A/S
Sent: Monday, May 05, 2008 2:57 PM
To: MapGuide Users Mail List
Subject: Re: [mapguide-users] Newbie needs help with project to query web

In the last line, try replacing:
String selectionXML = selection.ToXml();
with:
selection.Save(resService, "Sheboygan");

And instead of the JavaScript SetSelectionXml, try to do only a map refresh:
parent.GetMapFrame().Refresh();

If it does not work, can you post the string you get from "selection.ToXml();"?


Regards, Kenneth, GEOGRAF A/S


Nick Aizen skrev:
Do you have any code snippets on how and when to do this? My process was taken from andf online example provided by Autodesk and the process works when the selection code is called from a button click and  save is never called, which leaves me to wonder.."Am I doing something wrong?" I don't think I'm even effecting the viewer at all. Anyway...thanks for the help.





Nick Aizen









________________________________






_______________________________________________

mapguide-users mailing list

mapguide-users at lists.osgeo.org<mailto:mapguide-users at lists.osgeo.org>

http://lists.osgeo.org/mailman/listinfo/mapguide-users


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/mapguide-users/attachments/20080506/8cf090d8/attachment.html


More information about the mapguide-users mailing list