[mapguide-users] pleease help

saloua wakrim wakrimsaloua.wakrim at gmail.com
Sun May 3 13:20:17 EDT 2009


<%
@ Page Language="C#" AutoEventWireup="true" CodeFile="essai.aspx.cs"

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" %>

<%
@ Import Namespace="OSGeo.MapGuide.Schema.LayerDefinition"%>;

<!-- #Include File="C:\Program
Files\Autodesk\MapGuideEnterprise2008\WebServerExtensions\www\mapviewernet\common.aspx-->



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

<%

String x0 = "100";

String y0 = "100";

String x1 = "109";

String y1 = "109";

String sessionid1;

MgSiteConnection siteConnection;

MgResourceService resourceSrvc;

String myLayerName = "linetest";

String mapname = "Sheboygan";

MgMap map;

MgFeatureService featureSrvc;



String configPath = "C:\\Program
Files\\Autodesk\\MapGuideEnterprise2008\\WebServerExtensions\\www\\webconfig.ini";


MapGuideApi.MgInitializeWebTier(configPath);

MgSite site1 = new MgSite();

MgUserInformation userInfo = new MgUserInformation("Administrator", "admin");


siteConnection =
new MgSiteConnection();

siteConnection.Open(userInfo);

site1 = siteConnection.GetSite();

sessionid1 = site1.CreateSession();

userInfo.SetMgSessionId(sessionid1);

resourceSrvc = (
MgResourceService)siteConnection.CreateService(MgServiceType.ResourceService)
as MgResourceService;

featureSrvc = siteConnection.CreateService(
MgServiceType.FeatureService) as MgFeatureService;

MgResourceIdentifier resourceID = new MgResourceIdentifier(
"Library://Samples/Sheboygan/Maps/Sheboygan.MapDefinition");

map =
new MgMap(siteConnection);

map.Create(resourceSrvc, resourceID, mapname);

//MgResourceIdentifier mapStateId = new MgResourceIdentifier("Session:" +
sessionid1 + "//" + mapname + "." + MgResourceType.Map);

map.Save();

map.Open(resourceSrvc, mapname);

Response.Charset =
"utf-8";

//String x0 = "100";

//String y0 = "100";

//String x1 = "109";

//String y1 = "109";

String layerDef = "Library://Samples/Sheboygan/Layers/" + myLayerName +
".LayerDefinition";

MgResourceIdentifier layerDefId = new MgResourceIdentifier(layerDef);

String dataSource = "Library://Samples/Sheboygan/Data/" + myLayerName +
".FeatureSource";

MgResourceIdentifier dataSourceId = new MgResourceIdentifier(dataSource);

if (DoesLayerExist(myLayerName, map) == false)

{

//create Feature Source

MgClassDefinition myClassDef = new MgClassDefinition();

myClassDef.SetName(
"linetest");

//myClassDef.SetDescription(myLayerName + " Feature Source");

myClassDef.SetDefaultGeometryPropertyName(
"SHPGEOM");

//Set KEY Property

MgDataPropertyDefinition prop = 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);

//Set geometry property

MgGeometricPropertyDefinition geomProp = 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

MgFeatureSchema schema = new MgFeatureSchema();

schema.SetName(
"SHP_Shema");

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";

//layerDef = "Session:" + sessionid1 + "//" + myLayerName +
".LayerDefinition";



MgByteReader layerDefContent = BuildLayerDefinitionContent(dataSource,
"SHP_Shema:linetest", "", "5", "F000F");

resourceSrvc.SetResource(layerDefId, layerDefContent,
null);

MgLayer myLayer = 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);

}

// Save the map back to the session repository

/*String sessionIdName = "Session:" + sessionid1 + "//" + mapname + ".Map";

MgResourceIdentifier sessionResourceID = new
MgResourceIdentifier(sessionIdName);

sessionResourceID.Validate();

map.Save(resourceSrvc, sessionResourceID);

//Response.Write(map.GetLayers().GetItem("layertest").GetName());

//Response.Write(map.GetLayers().GetItem("Redline2").GetLayerDefinition().ToString());





//

//myLayer.SetVisible(true);



//}*/

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);

  %>

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

MgPropertyCollection makeLine(String Name, String x0, String y0, String x1,
String 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;

 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();

return (layers.Contains(LayerName));

}

String LoadTemplate2(String filePath)

{

StreamReader sr = File.OpenText(filePath);

String template = sr.ReadToEnd();

return template;

}



MgByteReader
BuildLayerDefinitionContent(String ResourceId, String FeatureName,
StringToolTip,
String Thickness, String LineColor)

{

String layerTempl = LoadTemplate2("C:\\Program
Files\\Autodesk\\MapGuideEnterprise2008\\WebServerExtensions\\www\\viewerfiles\\linelayerdef.templ");


String[] vals = {

ResourceId,

FeatureName,

"SHPGEOM",

ToolTip,

Thickness,

LineColor

};

layerTempl = Substitute(layerTempl, vals);

byte[] bytes = Encoding.UTF8.GetBytes(layerTempl);

MgByteSource src = new MgByteSource(bytes, bytes.Length);

return src.GetReader();

}

void add_layer_group(MgLayer layer, String layergroupname, MgMap map)

{

MgLayerGroupCollection group = map.GetLayerGroups();

MgLayerGroup grouplayer = group.GetItem(layergroupname);

layer.SetGroup(grouplayer);

map.Save();

}

 </
script>









</
html>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/mapguide-users/attachments/20090503/259e59b9/attachment.html


More information about the mapguide-users mailing list