you are right surely it's verry normal that the point desappear when you
refresh if you create it by DigitizePoint cause it relatif to session user
and it's normally given by mapguide for replying to user cli on map, but if
you want save your point on map permanently you musn't use this method you
must create layer wich display this point and associate feature source to
this layer wich contains your point and add layer after to map, and as that
you will save it even you close and open another time your map, as following
i send you code showing you exactlly how proceed, i explain, at first open
map, and define function to create point with giving coordinates, create the
feature wich contains this point and add layer corresponding to map, i send
you code, ther is xmlfile with code wich files i send wich constitutes the
definition for layer keep it as txt format as i send it, verufy as i sayed
coordinates map you use (minextent,maxextent.....) and give coordinates to
pint wich are beteen these min and max if you want that the point appear in
map else you can at first verify that the point is added by mapguidestudio,
you will see it sure cause i debug before send you code, good luck




2009/6/9 sathishpsk9 <sathishp...@gmail.com>

>
>
>  Hi saloua,
>             Thanks for reply .... but i what have you disscussed is not the
> problem.... because i have taken co-ordinates from Digitized()
> method......that might be beacuase of map ... bcoz i open it in session and
> whatever i add to it are being stored in session only ....and when i
> refresh
> the page session id changes ... so the changes i made not in current
> sessions .....so any other way out or if possible send your code which does
> this .......... i could analyze
>
> my code of adding layerdefination which have created to add point to
> current
> map goes like this
>
>        String layerDef = "Library:" + "//" + "ShapeFile" +  "/" +
> "lay1.LayerDefinition";
>        MgResourceIdentifier layerDefId = new
> MgResourceIdentifier(layerDef);
>        resourceSrvc.SetResource(layerDefId, layerDefContent,
> null);//layerdefContentis  layerdefination which have created to add point
> to current map
>
>        MgLayer myLayer = new MgLayer(layerDefId, resourceSrvc);
>        myLayer.SetName(myLayerName);
>        myLayer.SetVisible(true);
>        myLayer.SetLegendLabel("Point oF Interest ");
>        myLayer.SetDisplayInLegend(true);
>        myLayer.SetSelectable(true);
>        map.GetLayers().Insert(0, myLayer);
>
>        //map.GetLayers().Add(myLayer);
>
>        map.Save(resourceSrvc);
>        myLayer.ForceRefresh();
>
> thanks & regards,
> Satish
>
> --
> View this message in context:
> http://n2.nabble.com/Saving-a-point-to-map-permanently-tp3041754p3049093.html
>  Sent from the MapGuide Users mailing list archive at Nabble.com.
>
> _______________________________________________
> mapguide-users mailing list
> mapguide-users@lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/mapguide-users
>
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class essai : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
}
<%@ 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="System.Xml" %>



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



<%

  
    
    String sessionid1;
     MgSiteConnection siteConnection;
     MgResourceService resourceSrvc;
     String mapname;
     MgMap map;

         mapname = "Shboygan";

        String configPath = "C:\\Program 
Files\\MapGuideOpenSource\\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;
        MgResourceIdentifier resourceID = new 
MgResourceIdentifier("Library://Samples/Sheboygan/Maps/Sheboygan.MapDefinition");
        MgFeatureService featureService = 
(MgFeatureService)siteConnection.CreateService(MgServiceType.FeatureService);
        map = new MgMap(siteConnection);
        map.Create(resourceSrvc, resourceID, mapname);
      
        map.Save();
        map.Open(resourceSrvc, mapname);


        string myLayerName = "drawdeuxpoints";

        String wkt = map.GetMapSRS();

        MgClassDefinition bufferClass = new MgClassDefinition();
        bufferClass.SetName("BufferClass");
        MgPropertyDefinitionCollection properties = bufferClass.GetProperties();

        MgDataPropertyDefinition idProperty = new 
MgDataPropertyDefinition("ID");
        idProperty.SetDataType(MgPropertyType.Int32);
        idProperty.SetReadOnly(true);
        idProperty.SetNullable(false);
        idProperty.SetAutoGeneration(true);
        properties.Add(idProperty);

        MgPropertyDefinitionCollection idProperties =  
bufferClass.GetIdentityProperties();
        idProperties.Add(idProperty);



        MgGeometricPropertyDefinition polygonProperty = new 
MgGeometricPropertyDefinition("BufferGeometry");
        polygonProperty.SetGeometryTypes(MgFeatureGeometricType.Point);
        polygonProperty.SetHasElevation(false);
        polygonProperty.SetHasMeasure(false);
        polygonProperty.SetSpatialContextAssociation("LL84");
        properties.Add(polygonProperty);

        bufferClass.SetDefaultGeometryPropertyName("BufferGeometry");

        MgDataPropertyDefinition labelProperty = new 
MgDataPropertyDefinition("Label");
        labelProperty.SetDataType(MgPropertyType.String);
        properties.Add(labelProperty);



        MgFeatureSchema bufferSchema = new MgFeatureSchema("BufferLayerSchema", 
 "temporary schema to hold a buffer");
        bufferSchema.GetClasses().Add(bufferClass);

        //String wkt = "GEOGCS["+"WGS84 Lat/Long's, Degrees, -180 ==> +180"+", 
DATUM["+"D_WGS_1984"+", SPHEROID["+"World_Geodetic_System_of_1984"+", 6378137, 
298.257222932867]], PRIMEM["+"Greenwich"+", 0], UNIT["+"Degree"+", 
0.017453292519943295]]";
        MgCreateSdfParams sdfParams = new MgCreateSdfParams("LL84", 
map.GetMapSRS(), bufferSchema);

        string featurePath = 
"Library://Samples/Sheboygan/Data/drawdeuxpoints.FeatureSource";
        MgResourceIdentifier bufferFeatureResId =  new 
MgResourceIdentifier(featurePath);

        featureService.CreateFeatureSource(bufferFeatureResId, sdfParams); 

        /*MgPropertyCollection propertyValues = new MgPropertyCollection();
        MgPropertyCollection propertyValues2 = new MgPropertyCollection();
        MgGeometryFactory factory = new MgGeometryFactory();
        propertyValues.Add(new MgGeometryProperty("BufferGeometry", new 
MgAgfReaderWriter().Write(factory.CreatePoint(factory.CreateCoordinateXY(-87.704986990962839,
 43.707520000480347)))));
        propertyValues2.Add(new MgGeometryProperty("BufferGeometry", new 
MgAgfReaderWriter().Write(factory.CreatePoint(factory.CreateCoordinateXY(-87.744986990962839,
 43.747520000480347)))));

        //à revoir c koi feature source name    
        propertyValues.Add(new MgStringProperty("Label", "point1"));
        propertyValues.Add(new MgStringProperty("Label", "ponit2"));*/

        MgInsertFeatures insert = new 
MgInsertFeatures("BufferLayerSchema:BufferClass", point1());
        MgInsertFeatures insert2 = new 
MgInsertFeatures("BufferLayerSchema:BufferClass", point2());

        MgFeatureCommandCollection commands = new MgFeatureCommandCollection();
        commands.Add(insert);
        commands.Add(insert2);

        featureService.UpdateFeatures(bufferFeatureResId, commands, false);


        //LayerDefinition

        //MgResourceIdentifier templateLayerId = new 
MgResourceIdentifier("Library://Samples/Sheboygan/Layers/calquepoint.LayerDefinition");
        //MgByteReader oldContent = 
resourceService.GetResourceContent(templateLayerId);


        StreamReader sr = File.OpenText("C:\\Program 
Files\\MapGuideOpenSource\\WebServerExtensions\\www\\point.txt");
        String template  = sr.ReadToEnd();
      
        //string strXml = oldContent.ToString();

        XmlDocument document = new XmlDocument();
        document.LoadXml(template);

        XmlNode node = 
document.SelectSingleNode("LayerDefinition/VectorLayerDefinition/ResourceId");

        node.InnerText = featurePath;


        System.IO.MemoryStream outStream = new System.IO.MemoryStream();
        document.Save(outStream);

        byte[] newByteXml = outStream.ToArray();
        outStream.Close();
        string newStrXml = Encoding.UTF8.GetString(newByteXml);



        newByteXml = Encoding.UTF8.GetBytes(newStrXml.Substring(1));


        MgByteSource source = new MgByteSource(newByteXml, newByteXml.Length);
        MgByteReader newContent = source.GetReader();

        string layerPath = 
"Library://Samples/Sheboygan/Layers/drawdeuxpoints.LayerDefinition";
        MgResourceIdentifier newLayerId = new MgResourceIdentifier(layerPath);

        resourceSrvc.SetResource(newLayerId, newContent, null);




        MgLayer layer = new MgLayer(newLayerId, resourceSrvc);
        layer.SetDisplayInLegend(true);
        layer.SetLegendLabel("BufferClass");
        layer.SetName("BufferClass");
        layer.SetSelectable(true);
        layer.SetVisible(true);
        layer.ForceRefresh();

        MgLayerCollection layers = map.GetLayers();
        layers.Add(layer);

        map.Save(resourceSrvc);

        mesuredistance(map);


            //Response.Write(DoesLayerExist(myLayerName, map).ToString());

        MgByteSource content2 = new MgByteSource("C:\\Program 
Files\\MapGuideOpenSource\\WebServerExtensions\\www\\drawpoint\\mapdefinition.xml");
            resourceSrvc.SetResource(resourceID, content2.GetReader(), null);
           map.Save(resourceSrvc);
   
       

    
 %>
 
 <div id="Div1">
 <iframe id="carte" width="1000" height="800" frameborder="0" scrolling="no" 
src="http://localhost/mapguide/mapviewerajax/?SESSION=<%=sessionid1 
%>&WEBLAYOUT=Library%3a%2f%2fSamples%2fSheboygan%2fLayouts%2fSheboyganAsp.WebLayout"
 name="fenetre"></iframe>
 </div>
 <br />
 <div> 
<input type="button" value="rafresh" name="digitligne" onclick="rafresh();"/>
</div>
 
</body>
<script type="text/javascript">

     function rafresh()
    {
    //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>
    MgGeometry pointa;
    MgGeometry pointb;
    Double distanceunits;
    Double distancemeters;
   
    Boolean DoesLayerExist(String LayerName, MgMap Map)
    {
        MgLayerCollection layers = Map.GetLayers();
        return (layers.Contains(LayerName));
    }
    MgPropertyCollection point1()
    {
        MgPropertyCollection propertyValues = new MgPropertyCollection();
        //MgPropertyCollection propertyValues2 = new MgPropertyCollection();
        MgGeometryFactory factory = new MgGeometryFactory();
        pointa = 
factory.CreatePoint(factory.CreateCoordinateXY(-87.704986990962839, 
43.707520000480347));
        propertyValues.Add(new MgGeometryProperty("BufferGeometry", new 
MgAgfReaderWriter().Write(pointa)));
        //propertyValues2.Add(new MgGeometryProperty("BufferGeometry", new 
MgAgfReaderWriter().Write(factory.CreatePoint(factory.CreateCoordinateXY(-87.744986990962839,
 43.747520000480347)))));

        //à revoir c koi feature source name    
        propertyValues.Add(new MgStringProperty("Label", "point1"));
        //propertyValues.Add(new MgStringProperty("Label", "ponit2"));
        return propertyValues;
    }

    MgPropertyCollection point2()
    {
        MgPropertyCollection propertyValues2 = new MgPropertyCollection();
        MgGeometryFactory factory2 = new MgGeometryFactory();
        //propertyValues.Add(new MgGeometryProperty("BufferGeometry", new 
MgAgfReaderWriter().Write(factory2.CreatePoint(factory.CreateCoordinateXY(-87.704986990962839,
 43.707520000480347)))));

        pointb = 
factory2.CreatePoint(factory2.CreateCoordinateXY(-87.744986990962839, 
43.747520000480347));
        propertyValues2.Add(new MgGeometryProperty("BufferGeometry", new 
MgAgfReaderWriter().Write(pointb)));

        //à revoir c koi feature source name    
        propertyValues2.Add(new MgStringProperty("Label", "point2"));
        //propertyValues.Add(new MgStringProperty("Label", "ponit2"));
        return propertyValues2;
    }
   public Double mesuredistance(MgMap map)
    {
        
        String srs=map.GetMapSRS();
        MgCoordinateSystemMeasure mesure = new MgCoordinateSystemMeasure(srs);
        distanceunits = pointa.Distance(pointb, mesure);
        Response.Write(distanceunits.ToString());
        //distancemeters = 
srs.ConvertCoordinateSystemUnitsToMeters(distanceunits);
        //Response.Write(distancemeters.ToString());


        return distancemeters;
    }
    
      
</script>





 
</html>
<?xml version="1.0" encoding="UTF-8"?>
<LayerDefinition version="1.1.0" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:noNamespaceSchemaLocation="LayerDefinition-1.1.0.xsd">
  <VectorLayerDefinition>
    <ResourceId>%s</ResourceId>
    <FeatureName>BufferLayerSchema:BufferClass</FeatureName>
    <FeatureNameType>FeatureClass</FeatureNameType>
    <Geometry>BufferGeometry</Geometry>
    <ToolTip> </ToolTip>
    <VectorScaleRange>
      <PointTypeStyle>
                <DisplayAsText>true</DisplayAsText>
                <AllowOverpost>false</AllowOverpost>
                <PointRule>
                    <LegendLabel>point1</LegendLabel>
                    <PointSymbolization2D>
                        <Mark>
                            <Unit>Centimeters</Unit>
                            <SizeContext>DeviceUnits</SizeContext>
                            <SizeX>0.3</SizeX>
                            <SizeY>0.3</SizeY>
                            <Rotation>0</Rotation>
                            <Shape>Square</Shape>
                            <Fill>
                                <FillPattern>Solid</FillPattern>
                                <ForegroundColor>FF0000FF</ForegroundColor>
                                <BackgroundColor>FF000000</BackgroundColor>
                            </Fill>
                        </Mark>
                    </PointSymbolization2D>
                </PointRule>
            </PointTypeStyle>

    </VectorScaleRange>
  </VectorLayerDefinition>
</LayerDefinition>
_______________________________________________
mapguide-users mailing list
mapguide-users@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/mapguide-users

Reply via email to