[mapguide-users] help

Kenneth Skovhede, GEOGRAF A/S ks at geograf.dk
Mon May 11 09:30:09 EDT 2009


Yes, that looks right.

You must also refresh the map (refresh/pan/zoom/etc.) in the browser via 
javascript.

In addition to my other suggestions, you can also check the error log 
for messages.

Regards, Kenneth Skovhede, GEOGRAF A/S



saloua wakrim skrev:
> hi! please i want know if this code is that what all i must do for 
> adding new layer to map and see it in viewer frame or i must do some 
> relation with the feature source i create in my code?? thanks on advance
>  
>
> myLayer =
>
> New MgLayer(layerDefId, resourceSrvc)
>
> myLayer.SetName(myLayerName)
>
> myLayer.SetLegendLabel(myLayerName)
>
> myLayer.SetDisplayInLegend(
>
> True)
>
> myLayer.SetSelectable(
>
> False)
>
> map.GetLayers().Insert(0, myLayer)
>
> myLayer.ForceRefresh()
>
> map.Save(resourceSrvc)
>
> 2009/5/10 Kenneth Skovhede, GEOGRAF A/S <ks at geograf.dk 
> <mailto:ks at geograf.dk>>
>
>     The code looks alright.
>     Do you refresh the map afterwards?
>     What is in the "insertResults" ?
>     (There can be a hidden error, due to a bug in MapGuide)
>     Are you sure that the LayerDefinition matches the FeatureSource?
>     Try to create the FeatureSource and LayerDefinition in
>     "Library://" instead,
>     so you can examine the layer from Studio/Maestro.
>
>     Regards, Kenneth Skovhede, GEOGRAF A/S
>         
>
>
>
>     saloua wakrim skrev:
>>     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:
>>      
>>      
>>
>>     String
>>
>>     dataSource = "Session:" + sessionid1 + "//" + myLayerName +
>>     ".FeatureSource"; MgResourceIdentifier dataSourceId = new
>>     MgResourceIdentifier(dataSource); MgFeatureService featureSrvc =
>>     (MgFeatureService)siteConnection.CreateService(MgServiceType.FeatureService);
>>     if (DoesLayerExist(myLayerName, map) == false)
>>
>>     {
>>
>>      
>>
>>     //create Feature Source MgClassDefinition myClassDef = new
>>     MgClassDefinition();
>>
>>     myClassDef.SetName(myLayerName);
>>
>>     myClassDef.SetDescription(myLayerName +
>>
>>     " Feature Source");
>>
>>     myClassDef.SetDefaultGeometryPropertyName(
>>
>>     "SHPGEOM"); MgDataPropertyDefinition prop = new
>>     MgDataPropertyDefinition("KEY");
>>
>>     prop.SetDataType(
>>
>>     MgPropertyType.Int32);
>>
>>     prop.SetAutoGeneration(
>>
>>     true);
>>
>>     prop.SetReadOnly(
>>
>>     true);
>>
>>     myClassDef.GetIdentityProperties().Add(prop);
>>
>>     myClassDef.GetProperties().Add(prop);
>>
>>     prop =
>>
>>     new MgDataPropertyDefinition("ID");
>>
>>     prop.SetDataType(
>>
>>     MgPropertyType.Int32);
>>
>>     myClassDef.GetProperties().Add(prop);
>>
>>     MgGeometricPropertyDefinition geomProp = new
>>     MgGeometricPropertyDefinition("SHPGEOM");
>>
>>     geomProp.SetGeometryTypes(
>>
>>     MgFeatureGeometricType.Curve);
>>
>>     myClassDef.GetProperties().Add(geomProp);
>>
>>     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:" + sessionid1 + "//"
>>     + myLayerName + ".LayerDefinition"; MgResourceIdentifier
>>     layerDefId = new
>>     MgResourceIdentifier("Library://essaicalque/Redline.LayerDefinition");
>>
>>
>>      
>>
>>      
>>
>>     MgByteSource content = new MgByteSource(@"C:\Program
>>     Files\MapGuideOpenSource\WebServerExtensions\www\essaiselect2\Layerdef.xml");
>>
>>
>>     resourceSrvc.SetResource(layerDefId, content.GetReader(),
>>
>>     null); //code enlev‚ d'ici: ajouter layer resource … la carte
>>     //il faut ajouter l'autre code: add layer resource to map
>>     //DOMDocument domdoc = new DOMdocument(); MgLayer
>>     result=add_layer_resource_to_map(layerDefId,resourceSrvc,myLayerName,myLayerName,map);
>>
>>
>>     }
>>
>>     MgInsertFeatures insertFeatures = new
>>     MgInsertFeatures(myLayerName, makeLine("1", x0, y0, x1, y1));
>>     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();
>>
>>      
>>
>>     //commands.Add(new MgInsertFeatures(myLayerName,makeLine("1", x0,
>>     y0, x1, y1)));
>>
>>      
>>
>>     map.Save(resourceSrvc);
>>
>>      
>>
>>     <
>>
>>     script runat=server> Boolean result; MgPropertyCollection
>>     makeLine(String Name, Double x0, Double y0, Double x1, Double y1)
>>
>>     {
>>
>>     MgPropertyCollection PropertyCollection = new
>>     MgPropertyCollection(); MgInt32Property nameProperty = new
>>     MgInt32Property("ID", 1);
>>
>>     PropertyCollection.Add(nameProperty);
>>
>>     MgWktReaderWriter wktReaderWriter = new MgWktReaderWriter();
>>     MgAgfReaderWriter agfReaderWriter = new MgAgfReaderWriter();
>>     MgGeometry geometry = wktReaderWriter.Read("LINESTRING XY (" + x0
>>     + " " + y0 + "," + x1 + " " + y1 + ")") as MgLineString;
>>     //MgGeometry geometry = wktReaderWriter.Read("LINESTRING(3 4,10
>>     50,20 25)") as MgLineString; MgByteReader geometryByteReader =
>>     agfReaderWriter.Write(geometry); MgGeometryProperty
>>     geometryProperty = new MgGeometryProperty("SHPGEOM",
>>     geometryByteReader);
>>
>>     PropertyCollection.Add(geometryProperty);
>>
>>     return PropertyCollection;
>>
>>     }
>>
>>     Boolean
>>
>>     DoesLayerExist(String LayerName, MgMap Map)
>>
>>     {
>>
>>     MgLayerCollection layers = Map.GetLayers();
>>
>>     result = (layers.Contains(myLayerName));
>>
>>     return result;
>>
>>     }
>>
>>     MgLayer add_layer_resource_to_map(MgResourceIdentifier
>>     layerresourceid, MgResourceService rs, String layername, String
>>     layerlegendlabel, MgMap map)
>>
>>     {
>>
>>     MgLayer myLayer = new MgLayer(layerresourceid, rs);
>>
>>     myLayer.SetName(layername);
>>
>>     myLayer.SetLegendLabel(layerlegendlabel);
>>
>>     myLayer.SetDisplayInLegend(
>>
>>     true);
>>
>>     myLayer.SetSelectable(
>>
>>     true);
>>
>>      
>>
>>     if (!map.GetLayers().Contains(layername))
>>
>>     {
>>
>>     map.GetLayers().Insert(0, myLayer);
>>
>>     }
>>
>>     myLayer.SetVisible(
>>
>>     true);
>>
>>     myLayer.ForceRefresh();
>>
>>     map.Save(resourceSrvc);
>>
>>     return myLayer;
>>
>>     }
>>
>>     </
>>
>>     script>
>>
>>      
>>
>>      
>>
>>      
>>
>>     ------------------------------------------------------------------------
>>
>>     _______________________________________________
>>     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
>>       
>
>     _______________________________________________
>     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
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> mapguide-users mailing list
> 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/20090511/05ba4b98/attachment.html


More information about the mapguide-users mailing list