[mapguide-users] Changing Draw Order Priority of a Temporary Layer

saloua wakrim wakrimsaloua.wakrim at gmail.com
Mon May 11 03:42:22 EDT 2009


i want create temporary layer too wich contains polygone this is what i do,
idon't see layer after refreshing map (on iframe) and when i use mapguide
studio for see the layer i find layer but it doesn't contain polygon i
insert, pleaaase correct me my code if you can,i give it you:

 as cordinates i pass

 Dim x() As Double = {0, 2, 2, 0, 0}
  Dim y() As Double = {0, 0, 2, 2, 0}
just for testing and for constituting polygone i do that:


        Dim poly As MgPolygon
        Dim geomfactory As MgGeometryFactory = New MgGeometryFactory()
        Dim coordcol As MgCoordinateCollection = New
MgCoordinateCollection()
        Dim j As Integer
        For j = 0 To 4
        Dim coord As MgCoordinate = geomfactory.CreateCoordinateXY(a(j),
b(j))
        coordcol.Add(coord)
        j = j + 1

        Next
        Dim outring As MgLinearRing = geomfactory.CreateLinearRing(coordcol)
         poly = geomfactory.CreatePolygon(outring, Nothing)

        Dim agf As MgAgfReaderWriter = New MgAgfReaderWriter()

        properties.Add(New MgGeometryProperty("GEOM", agf.Write(poly)))

 i can't see the layer i add after refreshing map (conntained in
<iframe>)for saying layer i use mapguide studio where i see the layer wich
doesn't contain the polygon, may be pro in type of geometry i give or
another, i'll give all complete code it will help you see my error and help
me if you can, i've spent a lot of time at that but i don't see my error and
why even i add layer in map i don't see it and when i see it using mapguide
studio it doesn't contain polygone i insert.i have even tested to insert
polygone with text shape (("POLYGON XY ((0 0, 2 0, 2 2, 0 2, 0 0))" in
function makeLine2() as you see)but it doesn't run too.i don't know what do,
please help me if you can do it. Thanks a lot in advance.


<%@ Page Language="VB" AutoEventWireup="true" CodeFile="essai.aspx.vb"
Inherits="essai" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Collections.Specialized" %>
<%@ Import Namespace="OSGeo.MapGuide" %>
<%@ Import Namespace="System.Text" %>
<%@ Import Namespace="System.Globalization" %>

<!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 id="Head1" runat="server">
    <title>selection</title>

</head>
<body>
<br />
 <%


        Dim sessionid1 As String
     Dim siteConnection As MgSiteConnection
     Dim resourceSrvc As MgResourceService
     Dim myLayerName As String = "line9"
     Dim mapname As String = "Sheboygan"
     Dim map As MgMap
     Dim featureSrvc As MgFeatureService
     Dim myLayer As MgLayer

     Dim configPath As String = "C:\Program
Files\Autodesk\MapGuideEnterprise2008\WebServerExtensions\www\webconfig.ini"
     MapGuideApi.MgInitializeWebTier(configPath)
     Dim site1 As MgSite = New MgSite()
     Dim userInfo As MgUserInformation = New
MgUserInformation("Administrator", "admin")
     siteConnection = New MgSiteConnection()
     siteConnection.Open(userInfo)
     site1 = siteConnection.GetSite()
     sessionid1 = site1.CreateSession()
     userInfo.SetMgSessionId(sessionid1)
     resourceSrvc =
siteConnection.CreateService(MgServiceType.ResourceService)
     featureSrvc =
siteConnection.CreateService(MgServiceType.FeatureService)

     Response.Charset = "utf-8"
     Dim layerDef As String = "Library://Samples/Sheboygan/Layers/" +
myLayerName + ".LayerDefinition"
     Dim layerDefId As MgResourceIdentifier = New
MgResourceIdentifier(layerDef)
     Dim dataSource As String = "Library://Samples/Sheboygan/Data/" +
myLayerName + ".FeatureSource"
     Dim dataSourceId As MgResourceIdentifier = New
MgResourceIdentifier(dataSource)
     Dim resourceID2 As MgResourceIdentifier = New
MgResourceIdentifier("Library://Samples/Sheboygan/Maps/Sheboygan.MapDefinition")

     map = New MgMap(siteConnection)
     map.Create(resourceSrvc, resourceID2, mapname)

     map.Save()
     map.Open(resourceSrvc, mapname)
     Dim myClassDef As MgClassDefinition
     If (DoesLayerExist(myLayerName, map) = False) Then

         '//create Feature Source
         myClassDef = New MgClassDefinition()
         myClassDef.SetName("line9")
         'myClassDef.SetDescription(myLayerName + " Feature Source")
         'myClassDef.SetDefaultGeometryPropertyName("SHPGEOM")
         'Set KEY Property
         Dim prop As MgDataPropertyDefinition = New
MgDataPropertyDefinition("KEY")
         prop.SetDataType(MgPropertyType.Int32)
         prop.SetAutoGeneration(True)
         prop.SetReadOnly(True)
         prop.SetNullable(False)
         myClassDef.GetProperties().Add(prop)
         myClassDef.GetIdentityProperties().Add(prop)
         'Set ID Property
         prop = New MgDataPropertyDefinition("ID")
         prop.SetDataType(MgPropertyType.Int32)
         myClassDef.GetProperties().Add(prop)


         'et geometry property
         Dim geomProp As MgGeometricPropertyDefinition = New
MgGeometricPropertyDefinition("GEOM")
         geomProp.SetGeometryTypes(MgFeatureGeometricType.Surface)
         geomProp.SetHasElevation(False)
         geomProp.SetHasMeasure(False)
         geomProp.SetSpatialContextAssociation("LL84")
         myClassDef.GetProperties().Add(geomProp)
         'myClassDef.SetDefaultGeometryPropertyName("SHPGEOM")
         'Create the schema
         Dim schema As MgFeatureSchema = New MgFeatureSchema()
         schema.SetName("SHP_Shema")
         schema.GetClasses().Add(myClassDef)

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



         Dim content As MgByteSource = New MgByteSource("C:\Program
Files\Autodesk\MapGuideEnterprise2008\WebServerExtensions\www\createpoint\LayerDefinition.xml")
         resourceSrvc.SetResource(layerDefId, content.GetReader(), Nothing)
         myLayer = New MgLayer(layerDefId, resourceSrvc)
         myLayer.SetName(myLayerName)
         myLayer.SetLegendLabel(myLayerName)
         myLayer.SetDisplayInLegend(True)
         myLayer.SetSelectable(False)
         map.GetLayers().Insert(0, myLayer)
         'map.GetLayers().Add(myLayer)
         myLayer.ForceRefresh()
       map.Save(resourceSrvc)



     End If


       Dim insertFeatures2 As MgInsertFeatures = New
MgInsertFeatures(myLayerName, makeLine())

     Dim commands As MgFeatureCommandCollection = New
MgFeatureCommandCollection()

     commands.Add(insertFeatures2)

    myLayer.UpdateFeatures(commands)












 %>
<div id="viewer">
 <iframe id="carte" width="800" height="300" frameborder="0" scrolling="no"
src="http://localhost/mapguide2008/mapviewerajax/?SESSION=<%=sessionid1%>&WEBLAYOUT=Library%3a%2f%2fSamples%2fSheboygan%2fLayouts%2fSheboyganAsp.WebLayout"
name="fenetre"></iframe>
 </div>
 <br />
 <div>
<input type="button" value="zoom" name="zoom" onclick="zoom()"/>
</div>
<br />
<div>
<input type="button" value="rafraichir" name="calque"
onclick="testcalque();"/>
</div>

</body>
<script type="text/javascript">
    var str2;
    var str;


    function zoom()
    {
    carte.GetMapFrame().ZoomToView(-87.7116768,43.7766789973,5000,true);

     }
     function testcalque()
    {
    //carte.GetMapFrame().GetLayers(true,true);
   //carte.GetScriptFrame().location.href = "essai.aspx";
   frames['fenetre'].location.reload();
    carte.GetMapFrame().Refresh();
    //carte.ExecuteMapAction(20);
    //carte.GetMapFrame().ExecuteMapAction(1);
    //carte.GetTaskFrame().location.href = "essai.aspx"
    //carte.GetScriptFrame().location.href = "essai.aspx"
    //carte.GetMapFrame().ExecuteMapAction(20);

    //carte.GetMapFrame().ExecuteMapAction(20);
    }


</script>

<script runat="server">

    Public Function makeLine() As MgPropertyCollection

        Dim x() As Double = {0, 2, 2, 0, 0}
     Dim y() As Double = {0, 0, 2, 2, 0}

        Dim poly As MgPolygon
        Dim geomfactory As MgGeometryFactory = New MgGeometryFactory()
        Dim coordcol As MgCoordinateCollection = New
MgCoordinateCollection()
        Dim j As Integer
        For j = 0 To 4
        Dim coord As MgCoordinate = geomfactory.CreateCoordinateXY(x(j),
y(j))
        coordcol.Add(coord)
        j = j + 1

        Next
        Dim outring As MgLinearRing = geomfactory.CreateLinearRing(coordcol)
        poly = geomfactory.CreatePolygon(outring, Nothing)

        Dim agf As MgAgfReaderWriter = New MgAgfReaderWriter()

        properties.Add(New MgGeometryProperty("GEOM", agf.Write(poly)))


    return properties

    End Function
    Public Function makeLine2() As MgPropertyCollection
        Dim PropertyCollection2 As MgPropertyCollection = New
MgPropertyCollection()
        Dim nameProperty2 As MgInt32Property = New MgInt32Property("ID", 1)
        PropertyCollection2.Add(nameProperty2)
        Dim wktReaderWriter2 As MgWktReaderWriter = New MgWktReaderWriter()
        Dim agfReaderWriter2 As MgAgfReaderWriter = New MgAgfReaderWriter()
        Dim geometry2 As MgPolygon = wktReaderWriter2.Read("POLYGON XY ((0
0, 2 0, 2 2, 0 2, 0 0))")


        Dim geometryByteReader2 As MgByteReader =
agfReaderWriter2.Write(geometry2)
        Dim geometryProperty2 As MgGeometryProperty = New
MgGeometryProperty("GEOM", geometryByteReader2)
        PropertyCollection2.Add(geometryProperty2)
        Return PropertyCollection2
    End Function


    Function DoesLayerExist(ByVal LayerName As String, ByVal Map As MgMap)
As Boolean
        Dim layers As MgLayerCollection = Map.GetLayers()
        Return (layers.Contains(LayerName))
    End Function




</script>



</html>




2009/5/11 javed shaikh <jaspune at hotmail.com>

> Wakrim
>
> Could you tell me what is the error?
>
> You were code is technically correct, if you can tell me what is the error
> i can help you.
>
> Before that make sure you are passing corrrect cordinates (last co ordinate
> is same as first) you are passing correct layer scheme and inserting in
> correct session.
>
> J
>
> > From: wakrimsaloua.wakrim at gmail.com
> > To: jaspune at hotmail.com
> > Subject: please help me if you can
> > Date: Sat, 9 May 2009 04:13:56 -0700
> >
> > hi, i've the same prob that you have, but i can't resolve it, i use this
> code for drawning polygon ,but it doesn't draw it, please correct it me if
> you have time to do it, this is my mail: wakrimsaloua.wakrim at gmail.com,
> this is my code:
> >
> > If (DoesLayerExist(myLayerName, map) = False) Then
> >
> >
> > '//create Feature Source
> > Dim myClassDef As MgClassDefinition = New MgClassDefinition()
> > myClassDef.SetName("saloua3")
> > 'myClassDef.SetDescription(myLayerName + " Feature Source")
> > myClassDef.SetDefaultGeometryPropertyName("SHPGEOM")
> >
> > 'Set KEY Property
> > Dim prop As MgDataPropertyDefinition = New
> MgDataPropertyDefinition("KEY")
> > prop.SetDataType(MgPropertyType.Int32)
> > prop.SetAutoGeneration(True)
> > prop.SetReadOnly(True)
> > prop.SetNullable(False)
> > myClassDef.GetProperties().Add(prop)
> > myClassDef.GetIdentityProperties().Add(prop)
> >
> > 'Set ID Property
> > prop = New MgDataPropertyDefinition("ID")
> > prop.SetDataType(MgPropertyType.Int32)
> > myClassDef.GetProperties().Add(prop)
> >
> > 'add poly
> >
> > Dim poly As MgPolygon
> > Dim geomfactory As MgGeometryFactory = New MgGeometryFactory()
> > Dim coordcol As MgCoordinateCollection = New MgCoordinateCollection()
> > Dim j As Integer
> > For j = 0 To 3
> > Dim coord As MgCoordinate = geomfactory.CreateCoordinateXY(x(j), y(j))
> > coordcol.Add(coord)
> >
> > Next
> > Dim outring As MgLinearRing = geomfactory.CreateLinearRing(coordcol)
> > poly = geomfactory.CreatePolygon(outring, Nothing)
> > Dim agf As MgAgfReaderWriter = New MgAgfReaderWriter()
> >
> > 'Dim geom As MgByteReader = geometryReaderWriter.Write(poly)
> > properties = New MgPropertyCollection()
> > properties.Add(New MgGeometryProperty("GEOM", agf.Write(poly)))
> >
> > 'et geometry property
> > Dim geomProp As MgGeometricPropertyDefinition = New
> MgGeometricPropertyDefinition("SHPGEOM")
> > geomProp.SetGeometryTypes(MgFeatureGeometricType.Curve)
> > geomProp.SetHasElevation(False)
> > geomProp.SetHasMeasure(False)
> > geomProp.SetSpatialContextAssociation("LL84")
> > myClassDef.GetProperties().Add(geomProp)
> > myClassDef.SetDefaultGeometryPropertyName("SHPGEOM")
> >
> > 'Create the schema
> > Dim schema As MgFeatureSchema = New MgFeatureSchema()
> > schema.SetName("SHP_Shema")
> > schema.GetClasses().Add(myClassDef)
> >
> >
> > Dim sdfParams As MgCreateSdfParams = New MgCreateSdfParams("MGA-56 (GDA94
> /MGA zone 56)", map.GetMapSRS(), schema)
> >
> > featureSrvc.CreateFeatureSource(dataSourceId, sdfParams)
> >
> >
> > 'Dim layerDefContent As MgByteReader =
> BuildLayerDefinitionContent(dataSource, "SHP_Shema:linetestvb4", "", "5",
> "F000F")
> > 'resourceSrvc.SetResource(layerDefId, layerDefContent, nothing)
> >
> > Dim content As MgByteSource = New MgByteSource("C:\Program
> Files\Autodesk\MapGuideEnterprise2008\WebServerExtensions\www\testvb\LayerDefinition.xml")
> > resourceSrvc.SetResource(layerDefId, content.GetReader(), Nothing)
> >
> > Dim myLayer As MgLayer = New MgLayer(layerDefId, resourceSrvc)
> > myLayer.SetName(myLayerName)
> > myLayer.SetLegendLabel("legend" + myLayerName)
> > myLayer.SetDisplayInLegend(True)
> > myLayer.SetSelectable(True)
> > map.GetLayers().Insert(0, myLayer)
> > 'map.GetLayers().Add(myLayer)
> > myLayer.ForceRefresh()
> > map.Save(resourceSrvc)
> > Dim insertFeatures As MgInsertFeatures = New
> MgInsertFeatures(myLayerName, properties)
> > Dim commands As MgFeatureCommandCollection = New
> MgFeatureCommandCollection()
> > commands.Add(insertFeatures)
> > Dim commandIndex As Integer = commands.IndexOf(insertFeatures)
> >
> > Dim insertResults As MgPropertyCollection
> >
> > insertResults = featureSrvc.UpdateFeatures(dataSourceId, commands, False)
> > End If
>
>
>
> 2009/5/8 adnanc <adnan.chughtai at keynetix.com>

>
> Hello all,
>
> I've created a temporary map layer in the session, which appears fine on
> the
> map, however it is added as the top most layer.  I believe this is the
> default behaviour.
>
> Any ideas as to how I can modify its draw order priority? Modify the
> MapDefinition document?
>
> Regards,
>
> Adnan
> --
> View this message in context:
> http://n2.nabble.com/Changing-Draw-Order-Priority-of-a-Temporary-Layer-tp2845838p2845838.html
> Sent from the MapGuide Users mailing list archive at Nabble.com.
>
> _______________________________________________
> 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/b2064e75/attachment.html


More information about the mapguide-users mailing list