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

Kenneth Skovhede, GEOGRAF A/S ks at geograf.dk
Thu Oct 16 04:38:21 EDT 2008


I agree with Maksim, there seems to be some confusion as to what you 
want to do.
There are two basic scenarios:

1. You want to display some points based on context.
An example would be searching for hotels in a certain price interval, 
and the opening a map with the hotels shown.

2. You want to display a number of points, but the data changes more or 
less frequently.
An example of this would be position of vehicles.

A combination would be to show the position of vehicles that are using 
diesel engines.

Could you elaborate on what your scenario is like?

Regards, Kenneth Skovhede, GEOGRAF A/S



Maksim Sestic skrev:
> 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: mapguide-users-bounces at lists.osgeo.org
> [mailto:mapguide-users-bounces at lists.osgeo.org] On Behalf Of Galois
> Sent: Wednesday, October 15, 2008 16:29
> To: mapguide-users at lists.osgeo.org
> 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:
>   
>> If the MG->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: mapguide-users-bounces at lists.osgeo.org
>> [mailto:mapguide-users-bounces at lists.osgeo.org] On Behalf Of Galois
>> Sent: Wednesday, October 15, 2008 16:15
>> To: mapguide-users at lists.osgeo.org
>> 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:
>>     
>>> 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.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:
>>>>   
>>>>         
>>>>> 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.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;
>>>>>>     }
>>>>>> }
>>>>>>
>>>>>>   
>>>>>>       
>>>>>>             
>>>>> _______________________________________________
>>>>> mapguide-users mailing list
>>>>> mapguide-users at lists.osgeo.org
>>>>> http://lists.osgeo.org/mailman/listinfo/mapguide-users
>>>>>
>>>>>
>>>>>     
>>>>>           
>>>>   
>>>>         
>>> _______________________________________________
>>> 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-tp19954532p19994399.html
>> Sent from the MapGuide Users mailing list archive at Nabble.com.
>>
>> _______________________________________________
>> mapguide-users mailing list
>> mapguide-users at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/mapguide-users
>>
>> __________ Information from ESET NOD32 Antivirus, version of virus 
>> signature database 3523 (20081015) __________
>>
>> The message was checked by ESET NOD32 Antivirus.
>>
>> http://www.eset.com
>>
>>
>> _______________________________________________
>> 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-tp19954532p19994711.html
> Sent from the MapGuide Users mailing list archive at Nabble.com.
>
> _______________________________________________
> mapguide-users mailing list
> mapguide-users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/mapguide-users
>
> __________ Information from ESET NOD32 Antivirus, version of virus signature
> database 3523 (20081015) __________
>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>
>
> _______________________________________________
> 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/20081016/12398246/attachment.html


More information about the mapguide-users mailing list