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

Galois amihalas at yahoo.gr
Tue Oct 14 10:05:59 EDT 2008


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

-- 
View this message in context: http://www.nabble.com/Adding-a-point-to-a-map...-PLZ-Help%21%21%21-%28.NET---C-%29-tp19954532p19974224.html
Sent from the MapGuide Users mailing list archive at Nabble.com.



More information about the mapguide-users mailing list