[mapguide-users] help

saloua wakrim wakrimsaloua.wakrim at gmail.com
Sun May 10 18:08:02 EDT 2009


thanks a lot for your replay,yes, i'm sure, i've tried another code and with
mapguide studio i see the layer that i add, it contains the line wich i
insert, but on iframe (where the map is displayed) i don't see the layer and
even in mapguide studio with the layers belonging to the map, i don't see
the layer (it's not added), this is my complete code:


<%@ 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 x0 As String = "100"

Dim y0 As String = "100"



Dim x1 As String = "120"



Dim y1 As String = "120"



Dim sessionid1 As String



Dim siteConnection As MgSiteConnection

Dim resourceSrvc As MgResourceService

Dim myLayerName As String = "line6"



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 = NewMgResourceIdentifier(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("line6")

'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 =
NewMgGeometricPropertyDefinition(
"SHPGEOM")

geomProp.SetGeometryTypes(MgFeatureGeometricType.Point)

geomProp.SetHasElevation(False)

geomProp.SetHasMeasure(False)

geomProp.SetSpatialContextAssociation("LL84")

myClassDef.GetProperties().Add(geomProp)

'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,
makeLine2("1", x0, y0, x1, y1))



Dim commands As MgFeatureCommandCollection = NewMgFeatureCommandCollection()

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 />



</body>

<script type="text/javascript">



function refresh()

{

//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 makeLine2(ByVal Name As String, ByVal x0 As String, ByVal y0
As String, ByVal x1 As String, ByVal y1 As String) 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 MgGeometry = wktReaderWriter2.Read("LINESTRING XY (" + x0 +
" " + y0 + "," + x1 + " " + y1 + ")")

 Dim geometryByteReader2 As MgByteReader = agfReaderWriter2.Write(geometry2)

Dim geometryProperty2 As MgGeometryProperty = New MgGeometryProperty(
"SHPGEOM", 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



Function LoadTemplate2(ByVal filePath As String) As String



Dim sr As StreamReader = File.OpenText(filePath)

Dim template As String = sr.ReadToEnd()

Return template

End Function







</script>













</html>




------------------------------

_______________________________________________
mapguide-users mailing list
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/20090510/c136f878/attachment.html


More information about the mapguide-users mailing list