<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=windows-1252"
 http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
The code looks alright.<br>
Do you refresh the map afterwards?<br>
What is in the "insertResults" ? <br>
(There can be a hidden error, due to a bug in MapGuide)<br>
Are you sure that the LayerDefinition matches the FeatureSource?<br>
Try to create the FeatureSource and LayerDefinition in "Library://"
instead,<br>
so you can examine the layer from Studio/Maestro.<br>
<pre class="moz-signature" cols="72">Regards, Kenneth Skovhede, GEOGRAF A/S
</pre>
<br>
<br>
saloua wakrim skrev:
<blockquote
 cite="mid:903cf3420904270626o48f96a39occfa6248e192f7a2@mail.gmail.com"
 type="cite">
  <div>i try the following code for displaying layer wich contains line
in map, so i digitize a line, create temporary feature for this line,
create a layer wich contains it and add it to the map. it doesn't give
me some error but  i can see the line in the map (i can draw it).
Please help me. the code is following:</div>
  <div> </div>
  <div> <font color="#008080" size="2">
  <p>String</p>
  </font><font size="2"> dataSource = </font><font color="#800000"
 size="2">"Session:"</font><font size="2"> + sessionid1 + </font><font
 color="#800000" size="2">"//"</font><font size="2"> + myLayerName + </font><font
 color="#800000" size="2">".FeatureSource"</font><font size="2">;
  </font><font color="#008080" size="2">MgResourceIdentifier</font><font
 size="2"> dataSourceId = </font><font color="#0000ff" size="2">new</font><font
 size="2"> </font><font color="#008080" size="2">MgResourceIdentifier</font><font
 size="2">(dataSource);
  </font><font color="#008080" size="2">MgFeatureService</font><font
 size="2"> featureSrvc = (</font><font color="#008080" size="2">MgFeatureService</font><font
 size="2">)siteConnection.CreateService(</font><font color="#008080"
 size="2">MgServiceType</font><font size="2">.FeatureService);
  </font><font color="#0000ff" size="2">if</font><font size="2">
(DoesLayerExist(myLayerName, map) == </font><font color="#0000ff"
 size="2">false</font><font size="2">)
  <p>{</p>
  <p> </p>
  </font><font color="#008000" size="2">//create Feature Source </font><font
 size="2">
  </font><font color="#008080" size="2">MgClassDefinition</font><font
 size="2"> myClassDef = </font><font color="#0000ff" size="2">new</font><font
 size="2"> </font><font color="#008080" size="2">MgClassDefinition</font><font
 size="2">();
  <p>myClassDef.SetName(myLayerName);</p>
  <p>myClassDef.SetDescription(myLayerName + </p>
  </font><font color="#800000" size="2">" Feature Source"</font><font
 size="2">);
  <p>myClassDef.SetDefaultGeometryPropertyName(</p>
  </font><font color="#800000" size="2">"SHPGEOM"</font><font size="2">);
  </font><font color="#008080" size="2">MgDataPropertyDefinition</font><font
 size="2"> prop = </font><font color="#0000ff" size="2">new</font><font
 size="2"> </font><font color="#008080" size="2">MgDataPropertyDefinition</font><font
 size="2">(</font><font color="#800000" size="2">"KEY"</font><font
 size="2">);
  <p>prop.SetDataType(</p>
  </font><font color="#008080" size="2">MgPropertyType</font><font
 size="2">.Int32);
  <p>prop.SetAutoGeneration(</p>
  </font><font color="#0000ff" size="2">true</font><font size="2">);
  <p>prop.SetReadOnly(</p>
  </font><font color="#0000ff" size="2">true</font><font size="2">);
  <p>myClassDef.GetIdentityProperties().Add(prop);</p>
  <p>myClassDef.GetProperties().Add(prop);</p>
  <p>prop = </p>
  </font><font color="#0000ff" size="2">new</font><font size="2"> </font><font
 color="#008080" size="2">MgDataPropertyDefinition</font><font size="2">(</font><font
 color="#800000" size="2">"ID"</font><font size="2">);
  <p>prop.SetDataType(</p>
  </font><font color="#008080" size="2">MgPropertyType</font><font
 size="2">.Int32);
  <p>myClassDef.GetProperties().Add(prop);</p>
  </font><font color="#008080" size="2">MgGeometricPropertyDefinition</font><font
 size="2"> geomProp = </font><font color="#0000ff" size="2">new</font><font
 size="2"> </font><font color="#008080" size="2">MgGeometricPropertyDefinition</font><font
 size="2">(</font><font color="#800000" size="2">"SHPGEOM"</font><font
 size="2">);
  <p>geomProp.SetGeometryTypes(</p>
  </font><font color="#008080" size="2">MgFeatureGeometricType</font><font
 size="2">.Curve);
  <p>myClassDef.GetProperties().Add(geomProp);</p>
  </font><font color="#008080" size="2">MgFeatureSchema</font><font
 size="2"> schema = </font><font color="#0000ff" size="2">new</font><font
 size="2"> </font><font color="#008080" size="2">MgFeatureSchema</font><font
 size="2">(myLayerName + </font><font color="#800000" size="2">"Schema"</font><font
 size="2">, myLayerName + </font><font color="#800000" size="2">"SchemaDesc"</font><font
 size="2">);
  <p>schema.GetClasses().Add(myClassDef);</p>
  </font><font color="#008080" size="2">MgCreateSdfParams</font><font
 size="2"> sdfParams = </font><font color="#0000ff" size="2">new</font><font
 size="2"> </font><font color="#008080" size="2">MgCreateSdfParams</font><font
 size="2">(</font><font color="#800000" size="2">"MGA-56 (GDA94 / MGA
zone 56)"</font><font size="2">, map.GetMapSRS(), schema);
  <p>featureSrvc.CreateFeatureSource(dataSourceId, sdfParams);</p>
  <p> </p>
  <p> </p>
  </font><font color="#008000" size="2">//create layer </font><font
 size="2">
  </font><font color="#008000" size="2">//String layerDef = "Session:"
+ sessionid1 + "//" + myLayerName + ".LayerDefinition";</font><font
 size="2">
  </font><font color="#008080" size="2">MgResourceIdentifier</font><font
 size="2"> layerDefId = </font><font color="#0000ff" size="2">new</font><font
 size="2"> </font><font color="#008080" size="2">MgResourceIdentifier</font><font
 size="2">(</font><font color="#800000" size="2">"Library://essaicalque/Redline.LayerDefinition"</font><font
 size="2">);
  <p> </p>
  <p> </p>
  </font><font color="#008080" size="2">MgByteSource</font><font
 size="2"> content = </font><font color="#0000ff" size="2">new</font><font
 size="2"> </font><font color="#008080" size="2">MgByteSource</font><font
 size="2">(</font><font color="#800000" size="2">@"C:\Program
Files\MapGuideOpenSource\WebServerExtensions\www\essaiselect2\Layerdef.xml"</font><font
 size="2">);
  <p>resourceSrvc.SetResource(layerDefId, content.GetReader(), </p>
  </font><font color="#0000ff" size="2">null</font><font size="2">);
  </font><font color="#008000" size="2">//code enlev‚ d'ici: ajouter
layer resource … la carte</font><font size="2">
  </font><font color="#008000" size="2">//il faut ajouter l'autre code:
add layer resource to map</font><font size="2">
  </font><font color="#008000" size="2">//DOMDocument domdoc = new
DOMdocument();</font><font size="2">
  </font><font color="#008080" size="2">MgLayer</font><font size="2">
result=add_layer_resource_to_map(layerDefId,resourceSrvc,myLayerName,myLayerName,map);
  <p>}</p>
  </font><font color="#008080" size="2">MgInsertFeatures</font><font
 size="2"> insertFeatures = </font><font color="#0000ff" size="2">new</font><font
 size="2"> </font><font color="#008080" size="2">MgInsertFeatures</font><font
 size="2">(myLayerName, makeLine(</font><font color="#800000" size="2">"1"</font><font
 size="2">, x0, y0, x1, y1));
  </font><font color="#008080" size="2">MgFeatureCommandCollection</font><font
 size="2"> commands = </font><font color="#0000ff" size="2">new</font><font
 size="2"> </font><font color="#008080" size="2">MgFeatureCommandCollection</font><font
 size="2">();
  <p>commands.Add(insertFeatures);</p>
  </font><font color="#0000ff" size="2">int</font><font size="2">
commandIndex = commands.IndexOf(insertFeatures);
  </font><font color="#008080" size="2">MgPropertyCollection</font><font
 size="2"> insertResults;
  <p>insertResults = featureSrvc.UpdateFeatures(dataSourceId, commands,
  </p>
  </font><font color="#0000ff" size="2">false</font><font size="2">);
  </font><font color="#008080" size="2">MgLayer</font><font size="2">
myLayer1 = map.GetLayers().GetItem(myLayerName) </font><font
 color="#0000ff" size="2">as</font><font size="2"> </font><font
 color="#008080" size="2">MgLayer</font><font size="2">;
  <p>myLayer1.ForceRefresh();</p>
  <p> </p>
  </font><font color="#008000" size="2">//commands.Add(new
MgInsertFeatures(myLayerName,makeLine("1", x0, y0, x1, y1)));
  <p> </p>
  </font><font size="2">
  <p>map.Save(resourceSrvc); </p>
  <p> </p>
  <font color="#0000ff" size="2">
  <p>&lt;</p>
  </font><font color="#800000" size="2">script</font><font size="2"> </font><font
 color="#ff0000" size="2">runat</font><font color="#0000ff" size="2">=server&gt;</font><font
 size="2">
  </font><font color="#008080" size="2">Boolean</font><font size="2">
result;
  </font><font color="#008080" size="2">MgPropertyCollection</font><font
 size="2"> makeLine(</font><font color="#008080" size="2">String</font><font
 size="2"> Name, </font><font color="#008080" size="2">Double</font><font
 size="2"> x0, </font><font color="#008080" size="2">Double</font><font
 size="2"> y0, </font><font color="#008080" size="2">Double</font><font
 size="2"> x1, </font><font color="#008080" size="2">Double</font><font
 size="2"> y1)
  <p>{ </p>
  </font><font color="#008080" size="2">MgPropertyCollection</font><font
 size="2"> PropertyCollection = </font><font color="#0000ff" size="2">new</font><font
 size="2"> </font><font color="#008080" size="2">MgPropertyCollection</font><font
 size="2">(); </font><font color="#008080" size="2">MgInt32Property</font><font
 size="2"> nameProperty = </font><font color="#0000ff" size="2">new</font><font
 size="2"> </font><font color="#008080" size="2">MgInt32Property</font><font
 size="2">(</font><font color="#800000" size="2">"ID"</font><font
 size="2">, 1);
  <p>PropertyCollection.Add(nameProperty); </p>
  </font><font color="#008080" size="2">MgWktReaderWriter</font><font
 size="2"> wktReaderWriter = </font><font color="#0000ff" size="2">new</font><font
 size="2"> </font><font color="#008080" size="2">MgWktReaderWriter</font><font
 size="2">(); </font><font color="#008080" size="2">MgAgfReaderWriter</font><font
 size="2"> agfReaderWriter = </font><font color="#0000ff" size="2">new</font><font
 size="2"> </font><font color="#008080" size="2">MgAgfReaderWriter</font><font
 size="2">(); </font><font color="#008080" size="2">MgGeometry</font><font
 size="2"> geometry = wktReaderWriter.Read(</font><font color="#800000"
 size="2">"LINESTRING XY ("</font><font size="2"> + x0 + </font><font
 color="#800000" size="2">" "</font><font size="2"> + y0 + </font><font
 color="#800000" size="2">","</font><font size="2"> + x1 + </font><font
 color="#800000" size="2">" "</font><font size="2"> + y1 + </font><font
 color="#800000" size="2">")"</font><font size="2">) </font><font
 color="#0000ff" size="2">as</font><font size="2"> </font><font
 color="#008080" size="2">MgLineString</font><font size="2">; </font><font
 color="#008000" size="2">//MgGeometry geometry =
wktReaderWriter.Read("LINESTRING(3 4,10 50,20 25)") as MgLineString; </font><font
 size="2">
  </font><font color="#008080" size="2">MgByteReader</font><font
 size="2"> geometryByteReader = agfReaderWriter.Write(geometry); </font><font
 color="#008080" size="2">MgGeometryProperty</font><font size="2">
geometryProperty = </font><font color="#0000ff" size="2">new</font><font
 size="2"> </font><font color="#008080" size="2">MgGeometryProperty</font><font
 size="2">(</font><font color="#800000" size="2">"SHPGEOM"</font><font
 size="2">, geometryByteReader);
  <p>PropertyCollection.Add(geometryProperty); </p>
  </font><font color="#0000ff" size="2">return</font><font size="2">
PropertyCollection;
  <p>} </p>
  </font><font color="#008080" size="2">
  <p>Boolean</p>
  </font><font size="2"> DoesLayerExist(</font><font color="#008080"
 size="2">String</font><font size="2"> LayerName, </font><font
 color="#008080" size="2">MgMap</font><font size="2"> Map)
  <p>{ </p>
  </font><font color="#008080" size="2">MgLayerCollection</font><font
 size="2"> layers = Map.GetLayers();
  <p>result = (layers.Contains(myLayerName));</p>
  </font><font color="#0000ff" size="2">return</font><font size="2">
result;
  <p>}</p>
  </font><font color="#008080" size="2">MgLayer</font><font size="2">
add_layer_resource_to_map(</font><font color="#008080" size="2">MgResourceIdentifier</font><font
 size="2"> layerresourceid, </font><font color="#008080" size="2">MgResourceService</font><font
 size="2"> rs, </font><font color="#008080" size="2">String</font><font
 size="2"> layername, </font><font color="#008080" size="2">String</font><font
 size="2"> layerlegendlabel, </font><font color="#008080" size="2">MgMap</font><font
 size="2"> map)
  <p>{</p>
  </font><font color="#008080" size="2">MgLayer</font><font size="2">
myLayer = </font><font color="#0000ff" size="2">new</font><font
 size="2"> </font><font color="#008080" size="2">MgLayer</font><font
 size="2">(layerresourceid, rs);
  <p>myLayer.SetName(layername);</p>
  <p>myLayer.SetLegendLabel(layerlegendlabel);</p>
  <p>myLayer.SetDisplayInLegend(</p>
  </font><font color="#0000ff" size="2">true</font><font size="2">);
  <p>myLayer.SetSelectable(</p>
  </font><font color="#0000ff" size="2">true</font><font size="2">);
  <p> </p>
  </font><font color="#0000ff" size="2">if</font><font size="2">
(!map.GetLayers().Contains(layername))
  <p>{</p>
  <p>map.GetLayers().Insert(0, myLayer);</p>
  <p>}</p>
  <p>myLayer.SetVisible(</p>
  </font><font color="#0000ff" size="2">true</font><font size="2">);
  <p>myLayer.ForceRefresh();</p>
  <p>map.Save(resourceSrvc);</p>
  </font><font color="#0000ff" size="2">return</font><font size="2">
myLayer;
  <p>}</p>
  </font><font color="#0000ff" size="2">
  <p>&lt;/</p>
  </font><font color="#800000" size="2">script</font><font
 color="#0000ff" size="2">&gt;</font>
  <p> </p>
  <p> </p>
  <p> </p>
  </font></div>
  <pre wrap="">
<hr size="4" width="90%">
_______________________________________________
mapguide-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:mapguide-users@lists.osgeo.org">mapguide-users@lists.osgeo.org</a>
<a class="moz-txt-link-freetext" href="http://lists.osgeo.org/mailman/listinfo/mapguide-users">http://lists.osgeo.org/mailman/listinfo/mapguide-users</a>
  </pre>
</blockquote>
</body>
</html>