[mapguide-users] Create programmatically a map

Ivan Milicevic Ivan.Milicevic at supranet.hr
Wed Feb 18 05:34:40 EST 2009


Can you provide us code sample?

-----Original Message-----
From: mapguide-users-bounces at lists.osgeo.org
[mailto:mapguide-users-bounces at lists.osgeo.org] On Behalf Of sekko970
Sent: Wednesday, February 18, 2009 10:38 AM
To: mapguide-users at lists.osgeo.org
Subject: RE: [mapguide-users] Create programmatically a map


Hi Ivan,

thanks for your suggestion, but my problem is not to refresh the viewer
to
show the map just created, but is the correct creation of new map and
layout.

I think to have found the origin of my problem, but I don't understand
the
error:

Argument is null. Exception occurred in method
MgWebLayout.ParsePrintCommand
at line 880 in file
c:\build_bond_area\bond_nightly\build_41.3\ent\os\web\src\webapp\WebLayo
ut.cpp 

Have you some idea?
Thanks, Fabio

------------------------------------------------------------------------
------------------------------


Ivan Milicevic wrote:
> 
> Hello,
> 
> You can change href of mapFrame. Here is sample code.
> 
> var mapa = "cijevi"; //defines map name
> var stringMape = "Library%3a%2f%2fPROJEKTI%2fSUPRANET%2fMAPE%2f" +
mapa;
> var hrefMapa =
>
"http://172.21.10.3/mapguide/mapviewernet/mapframe.aspx?MAPDEFINITION="
> + stringMape +
>
".MapDefinition&TYPE=HTML&SHOWLEGEND=0&SHOWPROP=0&INFOWI
>
DTH=0&LOCALE=en&HLTGT=1&HLTGTNAME=&SHOWSLIDER=0&SESS
> ION=" + mgSessionId + ";
> 
> //changing mapFrame href
> mapFrame.location.href = hrefMapa;
> 
> 
> Hope this helps.
> 
> -----Original Message-----
> From: mapguide-users-bounces at lists.osgeo.org
> [mailto:mapguide-users-bounces at lists.osgeo.org] On Behalf Of sekko970
> Sent: Wednesday, February 18, 2009 9:57 AM
> To: mapguide-users at lists.osgeo.org
> Subject: Re: [mapguide-users] Create programmatically a map
> 
> 
> Hi Kenneth,
> I need again your help about my problem.
> 
> I think the problem is that after new map run-time creation in library
> repository, I cannot use its map definition to create its web layout.
> 
> How can I assign the new map to the layout?
> 
> Thanks again, Fabio
> 
>
------------------------------------------------------------------------
> ------------------------------
> 
> 
> Kenneth Skovhede, GEOGRAF A/S wrote:
>> 
>> Try to look at the Maestro code:
>>
>
http://trac.osgeo.org/mapguide/browser/trunk/Tools/Maestro/MaestroAPI/Lo
> calNativeConnection.cs#L182
>> 
>> Hopefully you will find a small difference there.
>> 
>> Regards, Kenneth Skovhede, GEOGRAF A/S
>> 
>> 
>> 
>> sekko970 skrev:
>>> Yes, the "OuterXml" property contains the XML header line.
>>> Fabio
>>>
>>>
>
------------------------------------------------------------------------
> ------------------------------
>>>
>>>
>>> Kenneth Skovhede, GEOGRAF A/S wrote:
>>>   
>>>> Does the "OuterXml" property contain the <? version="1.0" 
>>>> encoding="utf-8" standalone="true" ?> line?
>>>>
>>>> Regards, Kenneth Skovhede, GEOGRAF A/S
>>>>
>>>>
>>>>
>>>> sekko970 skrev:
>>>>     
>>>>> Hi Kenneth, and thanks for your promptly reply.
>>>>>
>>>>> I had used an ancoding instance.
>>>>>
>>>>> Below, you can see my code to create the new map:
>>>>>
>>>>> Dim resID As New
>>>>> MgResourceIdentifier(Library://.../maps/MyMap.MapDefinition)
>>>>>
>>>>> Dim enc As New System.Text.UTF8Encoding(False)
>>>>>
>>>>> Dim newMapDef As New
>>>>> MgByteSource(enc.GetBytes(XMLMapTemplate.OuterXml),
>>>>> enc.GetByteCount(XMLMapTemplate.OuterXml))
>>>>>
>>>>> newMapDef.SetMimeType(MgMimeType.Xml)
>>>>>
>>>>> Dim resourceSrvc As MgResourceService =
>>>>> siteConn.CreateService(MgServiceType.ResourceService)
>>>>>
>>>>> resourceSrvc.SetResource(resID, newMapDef.GetReader(), Nothing)
>>>>>
>>>>> Dim map As New MgMap()
>>>>>
>>>>> map.Create(resourceSrvc, resID, MapName)
>>>>>
>>>>> ...
>>>>>
>>>>> Then, this is my code to create the map layout:
>>>>>
>>>>> Dim resID As New
>>>>> MgResourceIdentifier(Library://.../Layouts/MyMap.WebLayout)
>>>>>
>>>>> Dim enc As New System.Text.UTF8Encoding(False)
>>>>>
>>>>> Dim newLayoutDef As New
>>>>> MgByteSource(enc.GetBytes(XMLLayoutTemplate.OuterXml),
>>>>> enc.GetByteCount(XMLLayoutTemplate.OuterXml))
>>>>>
>>>>> newLayoutDef.SetMimeType(MgMimeType.Xml)
>>>>>
>>>>> resourceSrvc As MgResourceService =
>>>>> siteConn.CreateService(MgServiceType.ResourceService)
>>>>>
>>>>> resourceSrvc.SetResource(resID, newLayoutDef.GetReader(), Nothing)
>>>>>
>>>>> map.Save(resourceSrvc)
>>>>>
>>>>>
>>>>> Thanks for your help.
>>>>> Fabio
>>>>>
>>>>>
>
------------------------------------------------------------------------
> ------------------------------
>>>>>
>>>>>
>>>>> Kenneth Skovhede, GEOGRAF A/S wrote:
>>>>>   
>>>>>       
>>>>>> You could have the problem that .Net emits an utf-8
> byte-order-marker 
>>>>>> (BOM), when
>>>>>> writing xml.
>>>>>> http://en.wikipedia.org/wiki/Byte-order_mark
>>>>>>
>>>>>> To counter this, explicitly create an encoding instance:
>>>>>> System.Text.Encoding enc = new System.Text.UTF8Encoding(false);
>>>>>>
>>>>>> Then implement a xml writer, or manually convert the xml to
bytes,
>>>>>> using 
>>>>>> the encoding.
>>>>>>
>>>>>> FYI, the MaestroAPI is LGPL, and so you may use it as a library,
> even 
>>>>>> for commercial applications,
>>>>>> and it handles this quirk and others.
>>>>>>
>>>>>> Regards, Kenneth Skovhede, GEOGRAF A/S
>>>>>>
>>>>>>
>>>>>>
>>>>>> sekko970 skrev:
>>>>>>     
>>>>>>         
>>>>>>> Dear all,
>>>>>>>
>>>>>>> I have created programmatically a map (and its layout) using MG
> .Net
>>>>>>> web
>>>>>>> API.
>>>>>>> After creation, the new map and layout are visible in MG
Maestro,
> and
>>>>>>> using
>>>>>>> the 'Show in browser" button are correctly shown in browser.
>>>>>>>
>>>>>>> The problem happens when I load the map directly from browser,
> and
>>>>>>> the
>>>>>>> following error appears:
>>>>>>> << The type 'OSGeo.MapGuide.MgNullArgumentException' in assembly
>>>>>>> 'MapGuideDotNetApi, Version= 2.0.2.30 11, Culture=neutral,
>>>>>>> PublicKeyToken=null' is not marked as serializable >>.
>>>>>>>
>>>>>>> Then, simply saving the new layout from MG Maestro (without any
>>>>>>> modification), and reloading the map directly from browser, the
> error
>>>>>>> disappears and the map is correctly shown.
>>>>>>>
>>>>>>> After saving the layout, there aren't differences in map and
> layout
>>>>>>> XML
>>>>>>> definitions.
>>>>>>>
>>>>>>> Have you any idea about?
>>>>>>> Thank you in advance.
>>>>>>> Fabio
>>>>>>>
>>>>>>>   
>>>>>>>       
>>>>>>>           
>>>>>> _______________________________________________
>>>>>> 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
>>>>
>>>>
>>>>     
>>>
>>>   
>> 
>> _______________________________________________
>> mapguide-users mailing list
>> mapguide-users at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/mapguide-users
>> 
>> 
> 
> -- 
> View this message in context:
>
http://n2.nabble.com/Create-programmatically-a-map-tp2314238p2345737.htm
> l
> 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
> _______________________________________________
> mapguide-users mailing list
> mapguide-users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/mapguide-users
> 
> 

-- 
View this message in context:
http://n2.nabble.com/Create-programmatically-a-map-tp2314238p2345874.htm
l
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


More information about the mapguide-users mailing list