[mapguide-commits] r7515 - branches/maestro-4.0.x/OSGeo.MapGuide.MaestroAPI/Mapping
svn_mapguide at osgeo.org
svn_mapguide at osgeo.org
Tue May 21 09:44:01 PDT 2013
Author: jng
Date: 2013-05-21 09:44:00 -0700 (Tue, 21 May 2013)
New Revision: 7515
Modified:
branches/maestro-4.0.x/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMap.cs
branches/maestro-4.0.x/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMapGroup.cs
branches/maestro-4.0.x/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMapLayer.cs
Log:
#2273, #2274: Port over r7513 to 4.0.x
Modified: branches/maestro-4.0.x/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMap.cs
===================================================================
--- branches/maestro-4.0.x/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMap.cs 2013-05-21 16:34:18 UTC (rev 7514)
+++ branches/maestro-4.0.x/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMap.cs 2013-05-21 16:44:00 UTC (rev 7515)
@@ -763,7 +763,49 @@
protected void SerializeLayerData(MgBinarySerializer s)
{
s.Write((int)this.Groups.Count);
- foreach (var g in this.Groups)
+ //Workaround a deserialization quirk in the MgMap. It deserializes groups sequentially
+ //without first checking if a parented group exists before doing the parent association
+ //
+ //We workaround this by re-ordering the groups, so that unparented groups are serialized first
+ var groups = new List<RuntimeMapGroup>();
+ var remaining = new List<RuntimeMapGroup>();
+ var processed = new Dictionary<string, RuntimeMapGroup>();
+ foreach (var grp in this.Groups)
+ {
+ if (string.IsNullOrEmpty(grp.Group)) //Un-parented
+ {
+ groups.Add(grp);
+ processed.Add(grp.Name, grp);
+ }
+ else
+ {
+ remaining.Add(grp);
+ }
+ }
+ var indices = new List<int>();
+ //Whittle down this list until all parents are resolved
+ while (remaining.Count > 0)
+ {
+ indices.Clear();
+ //Collect the indices which can be added to the final list
+ for (int i = 0; i < remaining.Count; i++)
+ {
+ var grp = remaining[i];
+ if (processed.ContainsKey(grp.Group)) //Parent of a group already processed
+ indices.Add(i);
+ }
+ //Reverse iterate so that higher indices are removed first
+ for (int i = indices.Count - 1; i >= 0; i--)
+ {
+ var index = indices[i];
+ var grp = remaining[index];
+ remaining.RemoveAt(index);
+ groups.Add(grp);
+ processed.Add(grp.Name, grp);
+ }
+ }
+
+ foreach (var g in groups)
g.Serialize(s);
s.Write(this.Layers.Count);
@@ -1205,6 +1247,8 @@
this.ResourceService.SetResourceData(resourceID, "LayerGroupData", ResourceDataType.Stream, ms2);
SaveSelectionXml(resourceID);
+ //Our changes have been persisted. Wipe our change list
+ ClearChanges();
}
finally
{
@@ -1260,6 +1304,8 @@
var change = new Change(type, param);
changes.Changes.Add(change);
+
+ Debug.WriteLine("Tracked change for " + (isLayer ? "Layer " : "Group ") + objectId + " (type: " + type + ", value: " + param + ")");
}
/// <summary>
Modified: branches/maestro-4.0.x/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMapGroup.cs
===================================================================
--- branches/maestro-4.0.x/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMapGroup.cs 2013-05-21 16:34:18 UTC (rev 7514)
+++ branches/maestro-4.0.x/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMapGroup.cs 2013-05-21 16:44:00 UTC (rev 7515)
@@ -281,7 +281,11 @@
switch (propertyName)
{
case "Group":
- this.Parent.OnGroupParentChanged(this, this.ObjectId);
+ var name = this.Group;
+ if (this.Parent.Groups[name] != null)
+ this.Parent.OnGroupParentChanged(this, this.Parent.Groups[name].ObjectId);
+ else
+ this.Parent.OnGroupParentChanged(this, string.Empty);
break;
case "Visible":
this.Parent.OnGroupVisibilityChanged(this, this.Visible ? "1" : "0");
Modified: branches/maestro-4.0.x/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMapLayer.cs
===================================================================
--- branches/maestro-4.0.x/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMapLayer.cs 2013-05-21 16:34:18 UTC (rev 7514)
+++ branches/maestro-4.0.x/OSGeo.MapGuide.MaestroAPI/Mapping/RuntimeMapLayer.cs 2013-05-21 16:44:00 UTC (rev 7515)
@@ -939,7 +939,11 @@
switch (propertyName)
{
case "Group":
- this.Parent.OnLayerParentChanged(this, this.ObjectId);
+ var name = this.Group;
+ if (this.Parent.Groups[name] != null)
+ this.Parent.OnLayerParentChanged(this, this.Parent.Groups[name].ObjectId);
+ else
+ this.Parent.OnLayerParentChanged(this, string.Empty);
break;
case "Visible":
this.Parent.OnLayerVisibilityChanged(this, this.Visible ? "1" : "0");
More information about the mapguide-commits
mailing list