<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:st1="urn:schemas-microsoft-com:office:smarttags" xmlns="http://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 11 (filtered medium)">
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]--><o:SmartTagType
 namespaceuri="urn:schemas-microsoft-com:office:smarttags" name="PersonName"/>
<!--[if !mso]>
<style>
st1\:*{behavior:url(#default#ieooui) }
</style>
<![endif]-->
<style>
<!--
 /* Font Definitions */
 @font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman";
        color:black;}
a:link, span.MsoHyperlink
        {color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {color:blue;
        text-decoration:underline;}
pre
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";
        color:black;}
tt
        {font-family:"Courier New";}
span.EmailStyle19
        {mso-style-type:personal-reply;
        font-family:Arial;
        color:navy;}
@page Section1
        {size:595.3pt 841.9pt;
        margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.Section1
        {page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
 <o:shapelayout v:ext="edit">
  <o:idmap v:ext="edit" data="1" />
 </o:shapelayout></xml><![endif]-->
</head>

<body bgcolor=white lang=EN-GB link=blue vlink=blue>

<div class=Section1>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>Thank you for the suggestion, unfortunately
I have just tried and resetting the XML header as discussed does not seem to
have made any difference.<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>I am still getting the same error message
in the viewer;<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=3 color=black face="Times New Roman"><span
style='font-size:12.0pt'>The map definition is invalid.<br>
The map definition is invalid. Exception occurred in method MgMap.Create at
line 303 in file c:\build_tux_area\mgdev\common\service\maplayer\Map.cpp </span></font><font
size=2 color=navy face=Arial><span style='font-size:10.0pt;font-family:Arial;
color:navy'>&nbsp;<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>However I have written the MapDefinition
XML to file and validated against the MapDefinition Schema and it validates. I
have compared the XML produced in my code with an XML document from saved from studio
and they also have an identical structure. So I have no idea why the Map
Definition is invalid.<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>

<div>

<p class=MsoNormal><font size=2 color=navy face="Times New Roman"><span
style='font-size:10.0pt;color:navy'>Carl Grice<br>
Keynetix Ltd<br>
Tel. +44 (0) 1527 68888<br>
Fax. +44 (0) 1527 62880<br>
Web Site: </span></font><font size=2 color=navy face=Arial><span
style='font-size:10.0pt;font-family:Arial;color:navy'><a
href="http://www.keynetix.com/"
title="blocked::http://www.keynetix.com/&#10;http://www.keynetix.com"><font
size=3 face="Times New Roman"><span style='font-size:12.0pt;font-family:"Times New Roman"'>http://www.keynetix.com</span></font></a><br>
<br>
</span></font><font size=2 color=navy><span style='font-size:10.0pt;color:navy'>IMPORTANT:
Please address all&nbsp;support &amp; sales correspondence </span></font><font
size=2 color=navy face=Arial><span style='font-size:10.0pt;font-family:Arial;
color:navy'><a href="mailto:keynetix@key-systems.com"
title="blocked::mailto:keynetix@key-systems.com&#10;mailto:keynetix@key-systems.com"><font
size=3 face="Times New Roman" title="blocked::mailto:keynetix@key-systems.com"><span
title="blocked::mailto:keynetix@key-systems.com"><span style='font-size:12.0pt;
font-family:"Times New Roman"'>keynetix@key-systems.com</span></span></font></a></span></font><font
size=2 color=navy><span style='font-size:10.0pt;color:navy'>.<br>
Addressing support questions to individuals may delay the response.</span></font><o:p></o:p></p>

</div>

<div>

<div class=MsoNormal align=center style='text-align:center'><font size=3
color=black face="Times New Roman"><span lang=EN-US style='font-size:12.0pt;
color:windowtext'>

<hr size=2 width="100%" align=center tabindex=-1>

</span></font></div>

<p class=MsoNormal><b><font size=2 color=black face=Tahoma><span lang=EN-US
style='font-size:10.0pt;font-family:Tahoma;color:windowtext;font-weight:bold'>From:</span></font></b><font
size=2 color=black face=Tahoma><span lang=EN-US style='font-size:10.0pt;
font-family:Tahoma;color:windowtext'> mapguide-users-bounces@lists.osgeo.org
[mailto:mapguide-users-bounces@lists.osgeo.org] <b><span style='font-weight:
bold'>On Behalf Of </span></b>Kenneth, GEOGRAF A/S<br>
<b><span style='font-weight:bold'>Sent:</span></b> 16 August 2007 12:22<br>
<b><span style='font-weight:bold'>To:</span></b> <st1:PersonName w:st="on">MapGuide
 Users Mail List</st1:PersonName><br>
<b><span style='font-weight:bold'>Subject:</span></b> Re: [mapguide-users]
programmatically add layer to initial map</span></font><font color=black><span
lang=EN-US style='color:windowtext'><o:p></o:p></span></font></p>

</div>

<p class=MsoNormal><font size=3 color=black face="Times New Roman"><span
style='font-size:12.0pt'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=3 color=black face="Times New Roman"><span
style='font-size:12.0pt'><br>
You should insert the &quot;UTF-8&quot; header into the mapDoc. <br>
On top of my head it is something like:<br>
</span></font><tt><font size=2 face="Courier New"><span style='font-size:10.0pt'>XmlNode
decl = mapDoc.CreateXmlDefinition(&quot;1.0&quot;, &quot;UTF-8&quot;);</span></font></tt><font
size=2 face="Courier New"><span style='font-size:10.0pt;font-family:"Courier New"'><br>
<tt><font face="Courier New">mapDoc.Insert(0, decl);</font></tt><br>
</span></font>You might have to remove an existing xmldefinition.<br>
<br>
After that, you can get the byte stream, and it will be UTF-8 encoded:<br>
<tt><font size=2 face="Courier New"><span style='font-size:10.0pt'>MemoryStream
xmlStream = new MemoryStream();</span></font></tt><font size=2
face="Courier New"><span style='font-size:10.0pt;font-family:"Courier New"'><br>
<tt><font face="Courier New">mapDoc.Save(xmlStream);</font></tt></span></font><br>
<br>
If your stream starts with:<font size=2 face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New"'><br>
<tt><font face="Courier New">byte[] { 0xEF 0xBB 0xBF };</font></tt><br>
</span></font>you must remove those three bytes.<br>
<br>
You can then get the byte array by: <br>
<tt><font size=2 face="Courier New"><span style='font-size:10.0pt'>byte[]
utf8EncodedXml = xmlStream.ToArray();</span></font></tt><br>
<br>
And finally:<br>
<tt><font size=2 face="Courier New"><span style='font-size:10.0pt'>MgByteSource
byteSource = new MgByteSource(utf8EncodedXml , utf8EncodedXml.Length);</span></font></tt><font
size=2 face="Courier New"><span style='font-size:10.0pt;font-family:"Courier New"'><br>
<tt><font face="Courier New">byteSource.SetMimeType(MgMimeType.Xml);</font></tt></span></font><br>
<br>
<br>
<br>
<o:p></o:p></p>

<pre><font size=2 color=black face="Courier New"><span style='font-size:10.0pt'>Regards, Kenneth, GEOGRAF A/S<o:p></o:p></span></font></pre>

<p class=MsoNormal><font size=3 color=black face="Times New Roman"><span
style='font-size:12.0pt'><br>
<br>
Carl skrev: <o:p></o:p></span></font></p>

<pre wrap=""><font size=2 color=black face="Courier New"><span
style='font-size:10.0pt'>Following the logic below to create a weblayout and mapdefinition by<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>modifying the xml and using SetResource to save the updated xml into the<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>session repository, I am having some problems. <o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'><o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>Initialize web tier<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>Create a session, and open connection<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>Use GetResource to retrieve the Xml for the WebLayout AND MapDefinition<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>Modify the MapDefinition Xml to your liking (add layers etc.)<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>Save the MapDefinition to the session repository, using SetResource.<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>Update the WebLayout's map resourceid to point towards your modified <o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>WebLayout.<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>Save the WebLayout to the session repositiory, using SetResource<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>Start the viewer, pointing at the newly created WebLayout.<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'><o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>I am getting an error message 'The map definition is invalid.' when the<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>viewer loads.<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'><o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>The following code works no problem and the viewer displays the weblayout<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>and map from the session repository.<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'><o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>//Code above for modifying xml for web layout changing map resource and<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>persisting to session<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'><o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>MgResourceIdentifier mapResourceID = new<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>MgResourceIdentifier(&quot;Library://Demo/Maps/Demo.MapDefinition&quot;);<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>MgByteReader byteRdr2 = resService.GetResourceContent(mapResourceID);<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>String sessMapName = mapResourceID.GetName();<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>MgResourceIdentifier SessMapResId = new MgResourceIdentifier(&quot;Session:&quot; +<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>sessionId + &quot;//&quot; + sessMapName + &quot;.MapDefinition&quot;);<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>resService.SetResource(SessMapResId, byteRdr2, null);<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'><o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>//Loads into viewer no problem<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'><o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>But as soon as I try to load the map definition xml using SetResource I get<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>the invalid XML error<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'><o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>//Code above for modifying xml for web layout changing map resource and<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>persisting to session<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'><o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>MgResourceIdentifier mapResourceID = new<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>MgResourceIdentifier(&quot;Library://Demo/Maps/Demo.MapDefinition&quot;);<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>MgByteReader byteRdr2 = resService.GetResourceContent(mapResourceID);<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>String sessMapName = mapResourceID.GetName();<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'><o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>String mapResStr = byteRdr2.ToString();<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'><o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>//Load the web layout into an xml document<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>XmlDocument mapDoc = new XmlDocument();<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>mapDoc.LoadXml(mapResStr);<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>XmlElement mapRoot = mapDoc.DocumentElement;<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'><o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>MemoryStream xmlStream = new MemoryStream();<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>mapDoc.Save(xmlStream);<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>byte[] mapDefinition = xmlStream.ToArray();<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>Encoding utf8 = Encoding.UTF8;<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>String mapDefStr = new String(utf8.GetChars(mapDefinition));<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>mapDefinition = new byte[mapDefStr.Length - 1];<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>int byteCount = utf8.GetBytes(mapDefStr, 1, mapDefStr.Length - 1,<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>mapDefinition, 0);<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>MgByteSource byteSource = new MgByteSource(mapDefinition,<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>mapDefinition.Length);<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>byteSource.SetMimeType(MgMimeType.Xml);<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'><o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>//Load the modified map into the session repository<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>MgResourceIdentifier SessMapResId = new MgResourceIdentifier(&quot;Session:&quot; +<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>sessionId + &quot;//&quot; + sessMapName + &quot;.MapDefinition&quot;);<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>resService.SetResource(SessMapResId, byteSource.GetReader(), null);<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'><o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>//This causes an invalid map error when the viewer loads<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'><o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'><o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>Any pointers on why manipulating the map definition is causing problems<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>would be great. Using the same techniques I am having no problems<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>manipulating the webDefintion or layerDefinition<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'><o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>Thanks&nbsp; <o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'><o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>Carl Grice<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>Keynetix Ltd<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>Tel. +44 (0) 1527 68888<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>Fax. +44 (0) 1527 62880<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>Web Site: <a
href="http://www.keynetix.com">http://www.keynetix.com</a><o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'><o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>IMPORTANT: Please address all support &amp; sales correspondence<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'><a
href="mailto:keynetix@key-systems.com">keynetix@key-systems.com</a>.<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>Addressing support questions to individuals may delay the response.<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>-----Original Message-----<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>From: <a
href="mailto:mapguide-users-bounces@lists.osgeo.org">mapguide-users-bounces@lists.osgeo.org</a><o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>[<a
href="mailto:mapguide-users-bounces@lists.osgeo.org">mailto:mapguide-users-bounces@lists.osgeo.org</a>] On Behalf Of Kenneth,<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>GEOGRAF A/S<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>Sent: 13 August 2007 15:16<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>To: <st1:PersonName
w:st="on">MapGuide Users Mail List</st1:PersonName><o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>Subject: Re: [mapguide-users] programmatically add layer to initial map<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'><o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>When the viewer loads, it creates a map from the weblayout/mapdefinition <o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>passed.<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>Your runtime map gets overwritten when the viewer starts.<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>Instead you can do this:<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'><o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>Initialize web tier<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>Create a session, and open connection<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>Use GetResource to retrieve the Xml for the WebLayout AND MapDefinition<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>Modify the MapDefinition Xml to your liking (add layers etc.)<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>Save the MapDefinition to the session repository, using SetResource.<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>Update the WebLayout's map resourceid to point towards your modified <o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>WebLayout.<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>Save the WebLayout to the session repositiory, using SetResource<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>Start the viewer, pointing at the newly created WebLayout.<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'><o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>You may of course use the &quot;Library://&quot; repository, if you want the <o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>changes to persist.<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'><o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>Regards, Kenneth, GEOGRAF A/S<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'><o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'><o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'><o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>Scott, Brian skrev:<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>&nbsp; <o:p></o:p></span></font></pre>

<blockquote style='margin-top:5.0pt;margin-bottom:5.0pt' type=cite><pre wrap=""><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>Hi Carl - <o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'><o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>What db are you using?&nbsp; I found, for example, that I could not filter at<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>&nbsp;&nbsp;&nbsp; <o:p></o:p></span></font></pre></blockquote>

<pre wrap=""><font size=2 color=black face="Courier New"><span
style='font-size:10.0pt'>run time against Postgres/PostGIS.&nbsp; I was able to create a whole new layer<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>based on points available in PG, but I&nbsp; had to extact the attributes, create<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>points, then apply them to a new layer.&nbsp; Very cumbersome, but for whatever<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>reason, filtering just wouldn't work w/PostGIS.&nbsp; <o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>&nbsp;&nbsp;<o:p></o:p></span></font></pre>

<blockquote style='margin-top:5.0pt;margin-bottom:5.0pt' type=cite><pre wrap=""><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>Good luck!<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>brian<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'><o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>-----Original Message-----<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>From: <a
href="mailto:mapguide-users-bounces@lists.osgeo.org">mapguide-users-bounces@lists.osgeo.org</a><o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>[<a
href="mailto:mapguide-users-bounces@lists.osgeo.org">mailto:mapguide-users-bounces@lists.osgeo.org</a>]On Behalf Of Carl Grice<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>Sent: Monday, August 13, 2007 10:01 AM<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>To: <a
href="mailto:mapguide-users@lists.osgeo.org">mapguide-users@lists.osgeo.org</a><o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>Subject: [mapguide-users] programmatically add layer to initial map<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'><o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'><o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'><o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>Hi,<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'><o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>I am trying to programmatically filter and add a layer to a map that<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>&nbsp;&nbsp;&nbsp; <o:p></o:p></span></font></pre></blockquote>

<pre wrap=""><font size=2 color=black face="Courier New"><span
style='font-size:10.0pt'>exists<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>&nbsp; <o:p></o:p></span></font></pre>

<blockquote style='margin-top:5.0pt;margin-bottom:5.0pt' type=cite><pre wrap=""><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>in the repository before the map is initially loaded in the clients<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>&nbsp;&nbsp;&nbsp; <o:p></o:p></span></font></pre></blockquote>

<pre wrap=""><font size=2 color=black face="Courier New"><span
style='font-size:10.0pt'>viewer.<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>&nbsp; <o:p></o:p></span></font></pre>

<blockquote style='margin-top:5.0pt;margin-bottom:5.0pt' type=cite><pre wrap=""><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>The steps i am performing are as follows;<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'><o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>1)Initialize the web teir and open site<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>2)Create a new session and open a site connection<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>3)Use map.create() to create a map from an existing map definition in the<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>repository<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>4)Create a session resource identifier and use map.Save() to save the<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>existing map into the session repository<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>5)Use map.Open() to open the map resource just created in the session<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>repository<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>6)Use map.Getlayers() and insert() to add a new layer into the map<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>7)use map.save() to save the map with the added layer into the session<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>repository<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'><o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>When i debug my code i get no errors and the map displays in the viewer<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>&nbsp;&nbsp;&nbsp; <o:p></o:p></span></font></pre></blockquote>

<pre wrap=""><font size=2 color=black face="Courier New"><span
style='font-size:10.0pt'>but<o:p></o:p></span></font></pre><pre><font size=2
color=black face="Courier New"><span style='font-size:10.0pt'>&nbsp; <o:p></o:p></span></font></pre>

<blockquote style='margin-top:5.0pt;margin-bottom:5.0pt' type=cite><pre wrap=""><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>the added layer does not (even after performing a map refresh).<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'><o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>Please can you point me in the direction of a sample that performs a<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>&nbsp;&nbsp;&nbsp; <o:p></o:p></span></font></pre></blockquote>

<pre wrap=""><font size=2 color=black face="Courier New"><span
style='font-size:10.0pt'>similar<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>&nbsp; <o:p></o:p></span></font></pre>

<blockquote style='margin-top:5.0pt;margin-bottom:5.0pt' type=cite><pre wrap=""><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>task or provide a code example? (I have found similar problems disscussed<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>but cannot find a solution)<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'><o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>Thanks in advance.<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>&nbsp; <o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>&nbsp;&nbsp;&nbsp;&nbsp;<o:p></o:p></span></font></pre></blockquote>

<pre wrap=""><font size=2 color=black face="Courier New"><span
style='font-size:10.0pt'>_______________________________________________<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>mapguide-users mailing list<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'><a
href="mailto:mapguide-users@lists.osgeo.org">mapguide-users@lists.osgeo.org</a><o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'><a
href="http://lists.osgeo.org/mailman/listinfo/mapguide-users">http://lists.osgeo.org/mailman/listinfo/mapguide-users</a><o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'><o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'><o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>_______________________________________________<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>mapguide-users mailing list<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'><a
href="mailto:mapguide-users@lists.osgeo.org">mapguide-users@lists.osgeo.org</a><o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'><a
href="http://lists.osgeo.org/mailman/listinfo/mapguide-users">http://lists.osgeo.org/mailman/listinfo/mapguide-users</a><o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>&nbsp; <o:p></o:p></span></font></pre></div>

</body>

</html>