[mapguide-users] RuntimeMap with Points layer .NET

murphyRic murphyrichards at gmail.com
Thu May 13 07:01:27 EDT 2010


Hi,

I am facing an issue to display a point (initially) on the map at runtime.
Below is my code in c# / aspx, XML file of "Redline.Featuresource" through
debugging in Maestro and the Error-Log. The error is "Error: An exception
occurred in the XML parser", I checked on all the parameters to the .templ
files but not a clue.  
I request for a solution as I am not able to get a clue on this. 
Further, I also need if this can be extended for highlighting the nodes(as
point layer-Runtime) of a polygon?

Thanks in Advance.

/////////////////////////CODE
START//////////////////////////////////////////////////////////////////////////
	    Response.Charset = "utf-8";
            sessionId = Request.QueryString["SESSION"];
            mapName = Request.QueryString["MAPNAME"];
            myLayerName = "Redline";

            Response.Charset = "utf-8";
            Response.Write("****RESULT****" + "<br>");
            Response.Write("myLayerName = " + myLayerName + "<br>");
            Response.Write("SESSION = " + sessionId + "<br>");
            Response.Write("MAPNAME = " + mapName + "<br>");
            

            try
            {
                MapGuideApi.MgInitializeWebTier(@"C:\Program
Files\OSGeo\MapGuide\Web\www\fusion\templates\mapguide\MyApp\Customize\webconfig.ini");
                Response.Write("sessionId = " + sessionId + "<br>");

                MgUserInformation cred = new MgUserInformation(sessionId);
                Response.Write("cred = " + cred + "<br>");
                
                //connect to the site and get a feature service and a
resource service instances
                MgSiteConnection site = new MgSiteConnection();
                site.Open(cred);
                Response.Write("site = " + site + "<br>");

                MgResourceService resourceSrvc =
site.CreateService(MgServiceType.ResourceService) as MgResourceService;
                MgFeatureService featureSrvc =
site.CreateService(MgServiceType.FeatureService) as MgFeatureService;

                //Create a temporary map runtime object, locate the layer
                MgMap map = new MgMap();
				map.Open(resourceSrvc, mapName);
				Response.Write("mapName = " + mapName + "<br>");


                //Datasource
                String dataSource = "Session:" + sessionId + "//" +
myLayerName + ".FeatureSource";
                
                MgResourceIdentifier dataSourceId = new
MgResourceIdentifier(dataSource);
                Response.Write("dataSource = " + dataSource +"<br>");
                Response.Write("dataSourceId = " + dataSourceId +"<br>");

                if (DoesLayerExist(myLayerName, map) == false)
                {
                    //create Feature Source
                    MgClassDefinition myClassDef = new MgClassDefinition();
                    myClassDef.SetName(myLayerName);
                    myClassDef.SetDescription(myLayerName + " Feature
Source");

                    myClassDef.SetDefaultGeometryPropertyName("SHPGEOM");

                    //Set KEY Property
                    MgDataPropertyDefinition prop = new
MgDataPropertyDefinition("KEY");
                    prop.SetDataType(MgPropertyType.Int32);
                    prop.SetAutoGeneration(true);
                    prop.SetReadOnly(true);
                    myClassDef.GetIdentityProperties().Add(prop);
                    myClassDef.GetProperties().Add(prop);

                    //Set ID Property
                    prop = new MgDataPropertyDefinition("ID");
                    prop.SetDataType(MgPropertyType.Int32);
                    myClassDef.GetProperties().Add(prop);

                    //Set geometry property
                    MgGeometricPropertyDefinition geomProp = new
MgGeometricPropertyDefinition("SHPGEOM");
                    geomProp.SetGeometryTypes(MgFeatureGeometricType.Curve);
                    myClassDef.GetProperties().Add(geomProp);

                    //Create the schema
                    MgFeatureSchema schema = new MgFeatureSchema(myLayerName
+ "Schema", myLayerName + "SchemaDesc");
                    schema.GetClasses().Add(myClassDef);


                    MgCreateSdfParams sdfParams = new
MgCreateSdfParams("MGA-56 (GDA94 / MGA zone 56)", map.GetMapSRS(), schema);
                    featureSrvc.CreateFeatureSource(dataSourceId,
sdfParams);

                    //create layer
                    String layerDef = "Session:" + sessionId + "//" +
myLayerName + ".LayerDefinition";
                    //For Debugging save it to Library://Debug/    
                    //String layerDef = "Library://Debug/" + myLayerName +
".LayerDefinition";
                    
                    MgResourceIdentifier layerDefId = new
MgResourceIdentifier(layerDef);

                    MgByteReader layerDefContent =
BuildLayerDefinitionContent(dataSource, myLayerName, "", "2", "ff0000");
                    Response.Write("EndOF BuildLayerDefinitionContent:
Done...layerDefContent->" + layerDefContent + "<br>");
                    Response.Write("layerDefId / layerDefContent" +
layerDefId + " /" + layerDefContent+ "<br>");

		////@@@@@@ ERROR HERE @@@@@@@@@@@@@//////////////////
                    resourceSrvc.SetResource(layerDefId, layerDefContent,
null);
                    //resourceSrvc.SetResource(layerDefId, bs.GetReader(),
null);
                    Response.Write("@@AFTER resourceSrvc@@ <br>");

                    MgLayer myLayer = new MgLayer(layerDefId, resourceSrvc);
                    myLayer.SetName(myLayerName);
                    myLayer.SetLegendLabel(myLayerName);
                    myLayer.SetDisplayInLegend(true);
                    myLayer.SetSelectable(true);
                    map.GetLayers().Insert(0, myLayer);

                    //map.GetLayers().Add(myLayer);
                    myLayer.ForceRefresh();
                    map.Save(resourceSrvc);
                    

                }

                //ADD POINT
                MgInsertFeatures insertFeatures = new
MgInsertFeatures(myLayerName, addPoints());
                
                MgFeatureCommandCollection commands = new
MgFeatureCommandCollection();
                commands.Add(insertFeatures);
                int commandIndex = commands.IndexOf(insertFeatures);
                
                MgPropertyCollection insertResults;
				insertResults = featureSrvc.UpdateFeatures(dataSourceId, commands,
false);

                MgLayer myLayer1 = map.GetLayers().GetItem(myLayerName) as
MgLayer;
                myLayer1.ForceRefresh();

                RegisterStartupScript("1",
"<script>parent.parent.parent.parent.parent.mapFrame.Refresh();</script>");

                Response.Write("<BR>");
                Response.Write("Layer Name = " +
map.GetLayers().GetItem(myLayerName).GetLegendLabel());
                Response.Write("<BR>");
                Response.Write("FeatureClass Name = " +
map.GetLayers().GetItem(myLayerName).GetFeatureClassName());
                Response.Write("<BR>");
                Response.Write("<BR>");

            }
            catch (MgException e)
            {
                Response.Write("Exception : " + e.StackTrace + "<br>");
            }
        





MgByteReader BuildLayerDefinitionContent(String ResourceId, String
FeatureName, String ToolTip, String Thickness, String LineColor)
    {
        ///////for POINT/////
        //Marker
        String marker = LoadTemplate(Request, "C:\\Program
Files\\OSGeo\\MapGuide\\Web\\www
                                               
\\viewerfiles\\marksymbol.templ");
        String[] markerVals = {
                    "25",
                    "25",
                    ResourceId,
                    FeatureName,
                    "FFFF0000"
                    };
        marker = Substitute(marker, markerVals);

        String text = LoadTemplate(Request, "C:\\Program
Files\\OSGeo\\MapGuide\\Web\\www\\viewerfiles
                                              \\textsymbol.templ");
        String[] textvals = {
                    "12",
                    "12",
                    "ID",
                    "FF000000"
                    };
        text = Substitute(text, textvals);

        String pointRule = LoadTemplate(Request, "C:\\Program
Files\\OSGeo\\MapGuide\\Web\\www
                                                   
\\viewerfiles\\pointrule.templ");
        String[] pointRuleVals = {
                    "Nodes",
                    "",
                    text,
                    marker
                     };
        pointRule = Substitute(pointRule, pointRuleVals);

        String pointTypeStyle = LoadTemplate(Request, "C:\\Program
Files\\OSGeo\\MapGuide\\Web\\www
                                                           
\\viewerfiles\\pointtypestyle.templ");
        String[] pointTypeStyleVals = {
                  pointRule  
                  };
        pointTypeStyle = Substitute(pointTypeStyle, pointTypeStyleVals);


        String scaleRange = LoadTemplate(Request, "C:\\Program
Files\\OSGeo\\MapGuide\\Web\\www
                                                     
\\viewerfiles\\scalerange.templ");
        String[] scaleRangeVals = {
                    "0",
                    "1000000000000",
                    pointTypeStyle
                     };
        scaleRange = Substitute(scaleRange, scaleRangeVals);

        UTF8Encoding enc = new UTF8Encoding(false);
        byte[] bytes = enc.GetBytes(scaleRange);
        string xml = Encoding.UTF8.GetString(bytes);
Response.Write("@@@ XML @@@ <br>" + xml + "<br>");
        MgByteSource src = new MgByteSource(bytes, bytes.Length);
        src.SetMimeType(MgMimeType.Xml);

        return src.GetReader();
        
    }



/////Function to add points/////
MgPropertyCollection addPoints()
    {
        MgPropertyCollection PropertyCollection = new
MgPropertyCollection();
        MgGeometryFactory geoFactory = new MgGeometryFactory();
        MgCoordinateCollection codCollection = new MgCoordinateCollection();

        MgInt32Property nameProperty = new MgInt32Property("ID", 1);
        PropertyCollection.Add(nameProperty);

        MgWktReaderWriter wktReaderWriter = new MgWktReaderWriter();
        MgAgfReaderWriter agfReaderWriter = new MgAgfReaderWriter();
       
        MgByteReader geometryByteReader =
agfReaderWriter.Write(geoFactory.CreatePoint(geoFactory.CreateCoordinateXY(175179.42358398438,
862004.0009765625)));
        MgGeometryProperty geometryProperty = new
MgGeometryProperty("SHPGEOM", geometryByteReader);
        PropertyCollection.Add(geometryProperty);
    
        return PropertyCollection;
    }
/////////////////////////DEBUG - REDLINE.FeatureSource in  MAESTRO  
///////////////////////////////////////

<?xml version="1.0" encoding="utf-8"?>
<FeatureSource xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xsi:noNamespaceSchemaLocation="FeatureSource-1.0.0.xsd" version="1.0.0">
  <Provider>OSGeo.SDF</Provider>
  <Parameter>
    <Name>File</Name>
    <Value>%MG_DATA_FILE_PATH%Redline.sdf</Value>
  </Parameter>
  <Parameter>
    <Name>ReadOnly</Name>
    <Value>FALSE</Value>
  </Parameter>
</FeatureSource>

/////////////////////////ERROR
LOG///////////////////////////////////////////////////////////////////////
<2010-05-13T16:07:40> 	3664			Anonymous
 Error: An exception occurred in the XML parser.
 StackTrace:
  - MgResourceServiceHandler.ProcessOperation() line 80 file
c:\osgeo\mapguide_21\mgdev\server\src\services\resource\ResourceServiceHandler.cpp
  - MgOpSetResource.Execute() line 103 file
c:\osgeo\mapguide_21\mgdev\server\src\services\resource\OpSetResource.cpp
  - MgServerResourceService.SetResource() line 751 file
c:\osgeo\mapguide_21\mgdev\server\src\services\resource\ServerResourceService.cpp
  - MgRepositoryManager.SetResource() line 859 file
c:\osgeo\mapguide_21\mgdev\server\src\services\resource\RepositoryManager.cpp
  - MgRepositoryManager.AddResource() line 832 file
c:\osgeo\mapguide_21\mgdev\server\src\services\resource\RepositoryManager.cpp
  - MgResourceContentManager.AddResource() line 183 file
c:\osgeo\mapguide_21\mgdev\server\src\services\resource\ResourceContentManager.cpp
  - MgResourceContentManager.PutDocument() line 624 file
c:\osgeo\mapguide_21\mgdev\server\src\services\resource\ResourceContentManager.cpp
  - MgResourceDefinitionManager.PutDocument
(MgSessionResourceContents.dbxml)() line 545 file
c:\osgeo\mapguide_21\mgdev\server\src\services\resource\ResourceDefinitionManager.cpp
  - MgResourceDefinitionManager.ValidateDocument
(MgSessionResourceContents.dbxml)() line 420 file
c:\osgeo\mapguide_21\mgdev\server\src\services\resource\ResourceDefinitionManager.cpp
  - MgResourceContentManager.ValidateDocument() line 556 file
c:\osgeo\mapguide_21\mgdev\server\src\services\resource\ResourceContentManager.cpp	




-- 
View this message in context: http://osgeo-org.1803224.n2.nabble.com/RuntimeMap-with-Points-layer-NET-tp5045583p5045583.html
Sent from the MapGuide Users mailing list archive at Nabble.com.


More information about the mapguide-users mailing list