[mapguide-users] Error: Unable to Make Permanent Changes to Map

Jim O'Leary joleary.public at gmail.com
Mon Feb 26 11:49:07 EST 2007


I found a solution here by following the documentation in
MgResourceService::SetResource.
You get the XML for the map content, insert  the new layer XML into the map
content and write it to disk, and call setResource() with the resource id,
new map XML, and header XML (which you get by calling getResourceHeader in
the mapagent and writing that XML to disk).

Here's the code:

$resourceID = new
MgResourceIdentifier("Library://whistler/Maps/whistlerMap.MapDefinition");
$byteReader = $this->resourceService->GetResourceContent($resourceID);
// Turn the byte reader to string.
$strMapXML = $byteReader->ToString();
// Find the spot between the last " </MapLayer>" and "<MapLayerGroup>".
$insertPoint = strpos($strMapXML,'<MapLayerGroup>');
// Use sprintf to insert the layer name and group name into a <layer>
template.
$layerXMLTemplate = file_get_contents("mapLayer.xml");
//$layerName and $groupName are already defined.
$newLayerXML =
sprintf($layerXMLTemplate,$layerName,$layerName,$layerName,$groupName);
// $newLayerXML now looks like:
<MapLayer><Name>Dogs</Name><ResourceId>Library://Whistler/Layers/Dogs.LayerDefinition</ResourceId><Selectable>true</Selectable><ShowInLegend>true</ShowInLegend>
<LegendLabel>Dogs</LegendLabel> <ExpandInLegend>true</ExpandInLegend>
<Visible>true</Visible> <Group>Kiwanis</Group></MapLayer>.
// Insert the layer XML into the map XML.
$content = substr_replace($strMapXML,$newLayerXML, $insertPoint,0);
// Make a unique file name and write the XML string to disk...
$pathToFile = $groupName . time() . ".txt";
file_put_contents($pathToFile,$content);
// ...so I can pass that file to MgByteSource.
$content_byteSource = new MgByteSource($pathToFile);
$content_byteSource->setMimeType("text/xml");
$content_byteReader = $content_byteSource->GetReader();
// The header XML I got from getResourceHeader() in mapagent, and wrote it
to disk previously.
$header = "mapHeader.xml";
$header_byteSource = new MgByteSource($header);
$header_byteSource->setMimeType("text/xml");
$header_byteReader = $header_byteSource->GetReader();
$this->resourceService->SetResource($resourceID, $content_byteReader,
$header_byteReader);


Robert Bray-2 wrote:
> 
> Jim,
> 
> At this point there is no way to save an MgMap object to the Library 
> repository. I personally think there is a strong use case for this, so I 
> encourage you to go to this link (http://trac.osgeo.org/mapguide) and 
> add an enhancement request for this feature. Read the page on submitting 
> defects and enhancements, then use the "New Ticket" link.
> 
> In the meantime the only way to do this is to save the changes in "per 
> user" Map Definition resources or by recording the "per user" MgMap 
> changes in an external file or database. On application load you'll then 
> need to detect the presence of the per user information and take the 
> appropriate action to initialize the map before the user sees it for the 
> first time.
> 
> Sorry I don't have a better answer...
> 
> Bob
> 
> Jim O'Leary wrote:
>> Has there been an answer to this question? Can you save a runtime map to
>> the
>> repository?
>> 
>> I have a map to which a user can add a new layer to a given layer group
>> using the browser. My program can save the new layer to the repository
>> using
>> SetResource(), and can add it to the given layer group in the runtime
>> map.
>> Is there a way to programmatically save the runtime map with the new
>> layer
>> to the repository?
>> 
>> Thanks
>> 
>> 
>> 
>> Robert Bray-2 wrote:
>>> Stephen,
>>>
>>> There are two distinctly different object types at play here and I 
>>> suspect you might be confusing them. MapGuide Studio creates what we 
>>> refer to as a MapDefintion. It is defined by an XML document and 
>>> primarily contains a coordinate system, extent, background color, and 
>>> layer and group lists.
>>>
>>> The MgMap object represents something slightly different.  MgMap 
>>> represents an instance or run time representation of a MapDefinition. 
>>> Each client through the viewer has it's own copy of an MgMap that is 
>>> usually stored in a session. I'll have to check, but I am not sure an 
>>> MgMap can be saved to the Library repository (that is the software may 
>>> prevent them from being saved in Library://). Like I said I'll need to 
>>> check on that.
>>>
>>> Assuming it is allowed, the problem below may be because you are trying 
>>> to save an MgMap using a resource identifier with type 'MapDefinition'. 
>>> Before you go any further however, you should think about whether you 
>>> are really trying to create an MgMap or a MapDefinition.
>>>
>>> Hope this helps...
>>> Bob
>>>
>>> Stephen Park wrote:
>>>> I am unable to save a map permanently to the repository when the map
>>>> has
>>>> been opened via the MgMap.Create(.) API. I have seen 2 or 3 back-posts
>>>> about
>>>> this issue but no resolution. Could use some insite. 
>>>>
>>>> Win2k3 Server
>>>> MGOS 1.0.1
>>>> MapGuideDotNetApi
>>>>
>>>> Repro: 
>>>> Open an  existing map via MgMap.Create(.) API 
>>>> 	//Resource Id is of form Library://./MyMap.MapDefinition
>>>> Add layer created previously via Studio 2K7 R1 to the map 
>>>> 	MgMap.GetLayers().Add(newLayer);
>>>> Save the Map back to the repository: 
>>>> 	MgMap.Save(_resourceService, resourceId); 
>>>> 		**Exception Here**
>>>>
>>>> If I use the .Save method that accepts a single argument (resource
>>>> service)
>>>> I get a null reference exception. Adding the same layer to the same map
>>>> via
>>>> MapGuide Studio works correctly. Any hints?
>>>>
>>>> Exception Information: 
>>>>
>>>> OSGeo.MapGuide.MgXmlParserException: An exception occurred in the XML
>>>> parser.
>>>> - MgResourceServiceHandler.ProcessOperation line 80 file
>>>> c:\build_tux_area\mgdev_opensource\server\src\services\resource\ResourceServ
>>>> iceHandler.cpp
>>>> - MgOpSetResource.Execute line 109 file
>>>> c:\build_tux_area\mgdev_opensource\server\src\services\resource\OpSetResourc
>>>> e.cpp
>>>> - MgServerResourceService.SetResource line 712 file
>>>> c:\build_tux_area\mgdev_opensource\server\src\services\resource\ServerResour
>>>> ceService.cpp
>>>> - MgRepositoryManager.SetResource line 867 file
>>>> c:\build_tux_area\mgdev_opensource\server\src\services\resource\RepositoryMa
>>>> nager.cpp
>>>> - MgRepositoryManager.UpdateResource line 1004 file
>>>> c:\build_tux_area\mgdev_opensource\server\src\services\resource\RepositoryMa
>>>> nager.cpp
>>>> - MgResourceDefinitionManager.UpdateResource line 261 file
>>>> c:\build_tux_area\mgdev_opensource\server\src\services\resource\ResourceDefi
>>>> nitionManager.cpp
>>>> - MgResourceContentManager.UpdateDocument line 647 file
>>>> c:\build_tux_area\mgdev_opensource\server\src\services\resource\ResourceCont
>>>> entManager.cpp
>>>> - MgResourceDefinitionManager.UpdateDocument line 601 file
>>>> c:\build_tux_area\mgdev_opensource\server\src\services\resource\ResourceDefi
>>>> nitionManager.cpp
>>>> - MgResourceDefinitionManager.ValidateDocument line 429 file
>>>> c:\build_tux_area\mgdev_opensource\server\src\services\resource\ResourceDefi
>>>> nitionManager.cpp
>>>> - MgResourceContentManager.ValidateDocument line 536 file
>>>> c:\build_tux_area\mgdev_opensource\server\src\services\resource\ResourceCont
>>>> entManager.cpp
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe at mapguide.osgeo.org
>>>> For additional commands, e-mail: users-help at mapguide.osgeo.org
>>>>
>>>>   
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe at mapguide.osgeo.org
>>> For additional commands, e-mail: users-help at mapguide.osgeo.org
>>>
>>>
>>>
>> 
> _______________________________________________
> 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/Error%3A-Unable-to-Make-Permanent-Changes-to-Map-tf2482437s16610.html#a9162369
Sent from the MapGuide Users mailing list archive at Nabble.com.



More information about the mapguide-users mailing list