[mapguide-users] How to Create a layerDefinition programmtically , using xml?

Champin champingfor at 163.com
Tue Sep 25 04:39:20 EDT 2007


How to Create a layerDefinition programmtically , using xml?  
---------------------------------------


Here is my steps, but something wrong happened, MgNotImplementedException
raised when added the layer to the map and Map.Save()


1.Using MapGuide Studio, Open an LayerDefinition , File --> Save as xml;
   in fact, I want to create temp layer the same as the existing layer ,so ,
the temp layers' layerDefinition should be the same as the existing
layer,except the <ResourceID>.....</ResourceID>

2. Change the resourceId to the replace flage ,such as <ResourceID>
%resourceID</ResourceID> and save the xml as  layerDefinitionTemplate.xml

3.Create the Layer

 public MgLayerBase CreateTrackLineLayer(String rootPath, MgResourceService
resService, String featureSourceName, MgResourceIdentifier LayerId)
    {
        MgLayerBase newLayer = null;

        //字符串方法
        string layerDefinition = File.ReadAllText(rootPath +
@"\Template\TrackLineLayerDefinition2.xml");
        layerDefinition = layerDefinition.Replace("%resourId",
featureSourceName);

        MgByteReader reader = new MgByteReader(layerDefinition, "text/xml");
        resService.SetResource(LayerId, reader, null);

        newLayer = new MgLayerBase(LayerId, resService);
        return newLayer;
    }

   these code goes well while debuging

 4. Added the layer to the map and save .


            MgLayerBase TrackLineLayer =  CreateTrackLineLayer(.......);
             // 设置层属性
            TrackLineLayer.SetName("TrackLineLayer");
            TrackLineLayer.SetDisplayInLegend(true);
            TrackLineLayer.SetLegendLabel("航迹");
            TrackLineLayer.SetVisible(true);
            TrackLineLayer.ForceRefresh();
            map.GetLayers().Insert(0, TrackLineLayer);

        // add some feature to the layer feature source
	 MgPropertyCollection props =BuildeNewPropCollection(.......);  
        MgFeatureCommandCollection commands = new
MgFeatureCommandCollection();
        commands.Add(new MgInsertFeatures(featureName, props));
        featureService.UpdateFeatures(TrackLineFeatureSourceID, commands,
false);

       //Save the map 
         TrackLineLayer.SetVisible(true);
        TrackLineLayer.SetSelectable(true);
        TrackLineLayer.ForceRefresh();
    
         map.Save(resService);  //**** ERROR 
	    here raise the Exception  " MgNotImplementedException "



Can you tell me what am I doing wrong?  I have been blocked here for a whole
day, any suggestion will be very appreciate .
Thank you !

My envionment :
Windows XP SP2 
VS2005 .net 2.0  + MapGuide Open Source 1.2


-- 
View this message in context: http://www.nabble.com/How-to-Create-a-layerDefinition-programmtically-%2C-using-xml--tf4514122s16610.html#a12875305
Sent from the MapGuide Users mailing list archive at Nabble.com.



More information about the mapguide-users mailing list