[mapguide-users] Adding a point to a map... PLZ Help!!! (.NET - C#)

Kenneth Skovhede, GEOGRAF A/S ks at geograf.dk
Tue Oct 14 11:07:45 EDT 2008


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:
http://www.openlayers.org/
http://www.openlayers.org/dev/examples/georss-markers.html
(OpenLayers also supports MapGuide as the backend server)


Regards, Kenneth Skovhede, GEOGRAF A/S



Galois skrev:
> 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.LayerDefinition");
>
>
>         string layerDefinition =
> File.ReadAllText("C:/Inetpub/wwwroot/iwaygis/TmpLayer.LayerDefinition.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:
>   
>> 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:
>> http://trac.osgeo.org/mapguide/wiki/CodeSamples/ASP.Net/ScribbleApp
>>
>> Regards, Kenneth Skovhede, GEOGRAF A/S
>>
>>
>>
>> Galois skrev:
>>     
>>> 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.ResourceService);
>>>
>>>
>>>             MgMap map = new MgMap(siteConnection);
>>>
>>>             webLayout =
>>> "Library://GoSpatial/Web+Layouts/Autostrada+Brescia+Padova+Map.WebLayout";
>>>
>>>             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;
>>>     }
>>> }
>>>
>>>   
>>>       
>> _______________________________________________
>> 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/20081014/70942987/attachment.html


More information about the mapguide-users mailing list