<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-2" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
I agree with Maksim, there seems to be some confusion as to what you
want to do.<br>
There are two basic scenarios:<br>
<br>
1. You want to display some points based on context.<br>
An example would be searching for hotels in a certain price interval,
and the opening a map with the hotels shown.<br>
<br>
2. You want to display a number of points, but the data changes more or
less frequently.<br>
An example of this would be position of vehicles.<br>
<br>
A combination would be to show the position of vehicles that are using
diesel engines.<br>
<br>
Could you elaborate on what your scenario is like?<br>
<br>
<pre class="moz-signature" cols="72">Regards, Kenneth Skovhede, GEOGRAF A/S
</pre>
<br>
<br>
Maksim Sestic skrev:
<blockquote cite="mid:000d01c92ed3$c5bee910$0901a8c0@max2" type="cite">
  <pre wrap="">Hmm, if you're attending to batch-process large number of points (along with
attached data) then web service calling FDO directly will do it much more
efficiently, since you can preset it on server side to poke exact
datastore/schema (thus skipping enumeration). Especially if you're planning
to parse some client-side file holding actual information. Other way round
you'll be making too many client-server roundtrips.Of couse, it all depends
on the overall setup...

-----Original Message-----
From: <a class="moz-txt-link-abbreviated" href="mailto:mapguide-users-bounces@lists.osgeo.org">mapguide-users-bounces@lists.osgeo.org</a>
[<a class="moz-txt-link-freetext" href="mailto:mapguide-users-bounces@lists.osgeo.org">mailto:mapguide-users-bounces@lists.osgeo.org</a>] On Behalf Of Galois
Sent: Wednesday, October 15, 2008 16:29
To: <a class="moz-txt-link-abbreviated" href="mailto:mapguide-users@lists.osgeo.org">mapguide-users@lists.osgeo.org</a>
Subject: RE: [mapguide-users] Adding a point to a map... PLZ Help!!! (.NET
-C#)


This is not a solution, cause at the feature, I'll have lot of XML files and
the code will have to work in order to put all the interest points automatic
on the map....

ThanX anyway :-D



Maksim Sestic wrote:
  </pre>
  <blockquote type="cite">
    <pre wrap="">If the MG-&gt;Datastore approach is making you headaches, why don't you 
directly access the datastore (i.e. via FDO if it's managed after all) 
and store the point there "manually"? Of course, if you're poking it 
from a client you'll have to establish a web service to do the job on 
the server side. And don't forget to call MG refresh method from 
JavaScript once you have that point within a datastore.

Regards,
Maksim Sestic

-----Original Message-----
From: <a class="moz-txt-link-abbreviated" href="mailto:mapguide-users-bounces@lists.osgeo.org">mapguide-users-bounces@lists.osgeo.org</a>
[<a class="moz-txt-link-freetext" href="mailto:mapguide-users-bounces@lists.osgeo.org">mailto:mapguide-users-bounces@lists.osgeo.org</a>] On Behalf Of Galois
Sent: Wednesday, October 15, 2008 16:15
To: <a class="moz-txt-link-abbreviated" href="mailto:mapguide-users@lists.osgeo.org">mapguide-users@lists.osgeo.org</a>
Subject: Re: [mapguide-users] Adding a point to a map... PLZ Help!!! 
(.NET
-C#)


Maybe I'm stupid....

I cannot do it work. I have reconstruct the whole thing, but the new 
Layer doesn't appear in the page.

I followed the Dev's Guide in order to create a Layer and add it in 
the map but nothing.

Basically, I added these three functions. I really would appreciate if 
u could give me some help..


public MgLayer addLayerRsc2Map(MgResourceIdentifier layerResId, 
MgResourceService resourceSrvc, string layerName, string 
layerLegendLabel, MgMap map)
    {
        //MgLayer newLayer = new MgLayer(layerResId, resourceSrvc);
        MgLayer newLayer = new MgLayer(layerResId , resourceSrvc);

        //Add the new layer to the map's layer collection
        newLayer.SetName(layerName);
        newLayer.SetVisible(true);
        newLayer.SetLegendLabel(layerLegendLabel);
        newLayer.SetDisplayInLegend(true);
        MgLayerCollection layerCollection = map.GetLayers();
        if( !layerCollection.Contains(layerName) )
        {
            //Insert the new layer to position 0 so it is at
            //the top of the drawing order
            layerCollection.Insert(0,newLayer);
        }
        MgLayerGroupCollection skata = map.GetLayerGroups();
        return newLayer;
    }

    
    public MgLayer addLayerDef2Map(string layerDefinition, string 
layerName, string layerLegendLabel, string sessionId, 
MgResourceService resourceSrvc, MgMap map )
    {
        // Adds the layer definition (XML) to the map.
        // Returns the layer.

        //Validate the XML.
        XmlDocument domDocument = new XmlDocument();
        domDocument.LoadXml(layerDefinition);
        domDocument.PreserveWhitespace = true;
        MemoryStream stream = new System.IO.MemoryStream();
        domDocument.Save(stream);

        Byte[] byteArray = stream.ToArray();
        string outerXml = 
System.Text.Encoding.UTF8.GetString(byteArray,
0,
byteArray.Length);
        byteArray = System.Text.Encoding.UTF8.GetBytes(outerXml);

        //Save the new layer definition to the Session.
        MgByteSource byteSource = new MgByteSource(byteArray , 
byteArray.Length);
        byteSource.SetMimeType(MgMimeType.Xml);
        MgResourceIdentifier resourseId = new 
MgResourceIdentifier("Session:" + map.SessionId + "//" + layerName + 
"." + MgResourceType.LayerDefinition);
        
        // Set the map with the new resource
        resourceSrvc.SetResource(resourseId, byteSource.GetReader(), 
null);
        

        MgLayer newLayer = addLayerRsc2Map(resourseId, resourceSrvc, 
layerName, layerLegendLabel, map);
        return newLayer;
    }


    
    public void addLayer2Group(MgLayer layer, string layerGroupName, 
string layerGroupLegendLabel, MgMap map)
    // Adds a layer to a layer group. If necessary, it creates
    // the layer group.
    {
        //Get the layer group
        MgLayerGroup layerGroup;
        MgLayerGroupCollection layerGroupCollection = 
map.GetLayerGroups();
        if( layerGroupCollection.Contains(layerGroupName) )
        {
            layerGroup = layerGroupCollection.GetItem(layerGroupName);
        }
        else
        {
            //It does not exist, so create it.
            layerGroup = new MgLayerGroup(layerGroupName);
            layerGroup.SetVisible(true);
            layerGroup.SetDisplayInLegend(true);
            layerGroup.SetLegendLabel(layerGroupLegendLabel);
            layerGroupCollection.Add(layerGroup);
        }
        //Add the layer to the group.
        layer.SetGroup(layerGroup);
    }




Kenneth Skovhede, GEOGRAF A/S wrote:
    </pre>
    <blockquote type="cite">
      <pre wrap="">Did you look at the buffer sample code in the AJAX viewer?
It does exactly what is required, besides inserting your points.

About your code:
You do not use the "resourceIdentifier" variable, which means your 
layer might reference something else.
You save the layers to the regular repository, which is fine, but 
each use will overwrite the previous copy, making it impossible to 
reliably serve more than one user.
You do not add the layer to the runtime map, and you do not save the 
runtime map.

You write: "I just want to display them".
Well, MapGuide works by displaying data from a FeatureSource, styled 
through a LayerDefinition.
You cannot insert data in the LayerDefinition, it must be in a 
FeatureSource.

If you insert the data in an existing FeatureSource, with an existing 
layer, that is fine too, but I cannot guess that is what you want.

You did not mention an Xml file with points before, just a single point.

Depending on your data, you may want to insert them into a database 
(like Sqlite or Access), or into an SDF file.
If you choose the database version, your FeatureSource can be of type 
ODBC.

If you use a database, you can insert the points using regular SQL 
queries against the database.
If the points are persistent (that is, not tied to a particular users 
map, like session values), you can just create a FeatureSource + 
Layer through Maestro or Studio without requirering any code.

If you are looking to create something similar to "Points of interrest" 
with a nice little flag, you might
consider using OpenLayers instead of the AJAX viewer:
<a class="moz-txt-link-freetext" href="http://www.openlayers.org/">http://www.openlayers.org/</a>
<a class="moz-txt-link-freetext" href="http://www.openlayers.org/dev/examples/georss-markers.html">http://www.openlayers.org/dev/examples/georss-markers.html</a>
(OpenLayers also supports MapGuide as the backend server)


Regards, Kenneth Skovhede, GEOGRAF A/S



Galois skrev:
      </pre>
      <blockquote type="cite">
        <pre wrap="">First of all, thank u fro your reply.

I don't get why should I create a temp layer.
I have some coordinates in an XML file, and I just want to display 
them on an existing layer.

Though I tried to create a new layer, it does not appear in my maps 
layers.

That's what I did...



MgResourceIdentifier resourceIdentifier = new 
MgResourceIdentifier("Library://GoSpatial/Data/airports.FeatureSource");
        MgResourceIdentifier layerResId = new 
MgResourceIdentifier("Library://GoSpatial/Layers/TmpLayer.LayerDefin
i
tion");


        string layerDefinition =
File.ReadAllText("C:/Inetpub/wwwroot/iwaygis/TmpLayer.LayerDefinitio
n
.xml");


        MgByteReader reader = new MgByteReader(layerDefinition, 
"text/xml");

        resourceSrvc.SetResource(layerResId, reader, null);


        tmpLayer = new MgLayer(layerResId, resourceSrvc);
        tmpLayer.SetName("TempLayer");
        tmpLayer.SetLegendLabel("TempLayer");
        tmpLayer.SetDisplayInLegend(true);
        tmpLayer.SetSelectable(true);

        MgLayerCollection layers = map.GetLayers();
        layers.Insert(0, tmpLayer);
        tmpLayer.SetVisible(true);
        tmpLayer.ForceRefresh();

Thx!



Kenneth Skovhede, GEOGRAF A/S wrote:
  
        </pre>
        <blockquote type="cite">
          <pre wrap="">A few steps are involved:

1. Create a temporary featuresource 2. Create a temporary layer to 
display the features 3. Insert the temporary layer into the runtime 
map

The buffer files in the MapGuide viewer has template code for all 
three steps.
All steps are explained in the Developer Guide (PDF version at least).

You might also want to look here:
<a class="moz-txt-link-freetext" href="http://trac.osgeo.org/mapguide/wiki/CodeSamples/ASP.Net/ScribbleApp">http://trac.osgeo.org/mapguide/wiki/CodeSamples/ASP.Net/ScribbleApp</a>

Regards, Kenneth Skovhede, GEOGRAF A/S



Galois skrev:
    
          </pre>
          <blockquote type="cite">
            <pre wrap="">Hello,

I´m trying to add a point to a map but I have no idea how to it.

I have declare the map object, and also I create a point with it's 
coordinates.

But I don't know what is the next step that I have to do...

The code follows....


public partial class _Default : System.Web.UI.Page {
    public string sessionId;
    public string webLayout;

    protected void Page_Load(object sender, EventArgs e)
    {
        string physicalPath = @"C:\Program 
Files\MapGuideOpenSource\WebServerExtensions\www\webconfig.ini";

        try
        {
            MapGuideApi.MgInitializeWebTier(physicalPath);


            passAndSession();

            //Associate a session ID with the MgSiteConnection Object
            MgUserInformation userInfo_new = new 
MgUserInformation(sessionId);

            MgSiteConnection siteConnection = new 
MgSiteConnection();

            siteConnection.Open(userInfo_new);

            MgResourceService resourceSrvc = 
(MgResourceService)siteConnection.CreateService(MgServiceType.Reso
u
rceService);


            MgMap map = new MgMap(siteConnection);

            webLayout =
"Library://GoSpatial/Web+Layouts/Autostrada+Brescia+Padova+Map.Web
L
ayout";

            MgResourceIdentifier resId = new 
MgResourceIdentifier("Library://GoSpatial/Maps/Italy
Map.MapDefinition");

            String mapName = resId.GetName();

            MgResourceIdentifier mapStateId = new 
MgResourceIdentifier("Session:" + sessionId + "//" + mapName + "."
+ MgResourceType.Map);

            map.Create(resourceSrvc, resId, mapName);

            map.Save(resourceSrvc, mapStateId);

            map.Open(resourceSrvc, mapName);

            createPoint();

           
        }
        catch (Exception ex)
        {
            throw (ex);
        }
    }




    public string passAndSession()
    {
        MgUserInformation userInfo = new 
MgUserInformation("Administrator",
"admin");

        MgSite site = new MgSite();

        site.Open(userInfo);

        sessionId = site.CreateSession();
        return sessionId;
    }

    public MgPoint createPoint()
    {
        MgGeometryFactory geometryFactory = new 
MgGeometryFactory();

        MgCoordinateXY coordinate = (MgCoordinateXY) 
geometryFactory.CreateCoordinateXY(10.913161, 45.408046);

        MgPoint point = geometryFactory.CreatePoint(coordinate);
        return point;
    }
}

  
      
            </pre>
          </blockquote>
          <pre wrap="">_______________________________________________
mapguide-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:mapguide-users@lists.osgeo.org">mapguide-users@lists.osgeo.org</a>
<a class="moz-txt-link-freetext" href="http://lists.osgeo.org/mailman/listinfo/mapguide-users">http://lists.osgeo.org/mailman/listinfo/mapguide-users</a>


    
          </pre>
        </blockquote>
        <pre wrap="">  
        </pre>
      </blockquote>
      <pre wrap="">_______________________________________________
mapguide-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:mapguide-users@lists.osgeo.org">mapguide-users@lists.osgeo.org</a>
<a class="moz-txt-link-freetext" href="http://lists.osgeo.org/mailman/listinfo/mapguide-users">http://lists.osgeo.org/mailman/listinfo/mapguide-users</a>


      </pre>
    </blockquote>
    <pre wrap="">--
View this message in context:
<a class="moz-txt-link-freetext" href="http://www.nabble.com/Adding-a-point-to-a-map...-PLZ-Help%21%21%21-%28">http://www.nabble.com/Adding-a-point-to-a-map...-PLZ-Help%21%21%21-%28</a>
.NET--
-C-%29-tp19954532p19994399.html
Sent from the MapGuide Users mailing list archive at Nabble.com.

_______________________________________________
mapguide-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:mapguide-users@lists.osgeo.org">mapguide-users@lists.osgeo.org</a>
<a class="moz-txt-link-freetext" href="http://lists.osgeo.org/mailman/listinfo/mapguide-users">http://lists.osgeo.org/mailman/listinfo/mapguide-users</a>

__________ Information from ESET NOD32 Antivirus, version of virus 
signature database 3523 (20081015) __________

The message was checked by ESET NOD32 Antivirus.

<a class="moz-txt-link-freetext" href="http://www.eset.com">http://www.eset.com</a>


_______________________________________________
mapguide-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:mapguide-users@lists.osgeo.org">mapguide-users@lists.osgeo.org</a>
<a class="moz-txt-link-freetext" href="http://lists.osgeo.org/mailman/listinfo/mapguide-users">http://lists.osgeo.org/mailman/listinfo/mapguide-users</a>


    </pre>
  </blockquote>
  <pre wrap=""><!---->
--
View this message in context:
<a class="moz-txt-link-freetext" href="http://www.nabble.com/Adding-a-point-to-a-map...-PLZ-Help%21%21%21-%28.NET">http://www.nabble.com/Adding-a-point-to-a-map...-PLZ-Help%21%21%21-%28.NET</a>--
-C-%29-tp19954532p19994711.html
Sent from the MapGuide Users mailing list archive at Nabble.com.

_______________________________________________
mapguide-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:mapguide-users@lists.osgeo.org">mapguide-users@lists.osgeo.org</a>
<a class="moz-txt-link-freetext" href="http://lists.osgeo.org/mailman/listinfo/mapguide-users">http://lists.osgeo.org/mailman/listinfo/mapguide-users</a>

__________ Information from ESET NOD32 Antivirus, version of virus signature
database 3523 (20081015) __________

The message was checked by ESET NOD32 Antivirus.

<a class="moz-txt-link-freetext" href="http://www.eset.com">http://www.eset.com</a>


_______________________________________________
mapguide-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:mapguide-users@lists.osgeo.org">mapguide-users@lists.osgeo.org</a>
<a class="moz-txt-link-freetext" href="http://lists.osgeo.org/mailman/listinfo/mapguide-users">http://lists.osgeo.org/mailman/listinfo/mapguide-users</a>
  </pre>
</blockquote>
</body>
</html>