[mapguide-commits] r1059 - in trunk/MgDev/Common: MapGuideCommon/MapLayer PlatformBase/MapLayer

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Thu Jan 18 21:07:28 EST 2007


Author: waltweltonlair
Date: 2007-01-18 21:07:28 -0500 (Thu, 18 Jan 2007)
New Revision: 1059

Modified:
   trunk/MgDev/Common/MapGuideCommon/MapLayer/Map.cpp
   trunk/MgDev/Common/PlatformBase/MapLayer/MapBase.cpp
Log:
The current code has some trouble handling MgMap changes in the context of
DWF Viewer.  In particular, if the server-side code makes some changes to
the map (e.g. adds a layer) then the changelist stored with the MgMap is
never cleared.  With each subsequent refresh of the viewer the server will
process the changes.

Here's the sequence in detail, for the case of adding a layer:

1/ The server-side code will open the MgMap, access the layer collection
   (forces the layers/groups blob to load), and add the new layer.  This
   adds a change to the MgMap's changelist.  The custom code saves the
   MgMap, and so the updated blob gets saved in the session.

2/ The refresh call gets made, and the viewer makes a GetMapUpdate request.
   The request does not include any map view commands.

3/ MgDwfController::GetMapUpdate is called and we open the instance of the
   MgMap.  Because there are no map view commands the code does not access
   the layers / groups / changelist, and therefore the blob is not loaded.

4/ The code calls ProxyMappingService::GenerateMapUpdate.  The MgMap (without
   any blob) gets serialized into the TCP/IP request that gets sent to the
   server.

5/ The server gets the MgMap, and accesses the layers / groups / changelist.
   Since the blob was not included with the MgMap, it gets read from the
   repository.  The server processes the changelist, and finishes processing
   the GenerateMapUpdate request.

6/ Once back in ProxyMappingService::GenerateMapUpdate the code clears the
   changelist, but in this case it does nothing - the changelist was never
   loaded into this instance of MgMap.

7/ Back in MgDwfController::GetMapUpdate the code then saves the updated MgMap.
   Because the layers / groups / changelist collections are all empty the blob
   is not updated in the session repository, and so the stored changelist never
   gets cleared.

The fix is to serialize the changelist directly with the MgMap (like it was
in 1.1.x).  In most cases the changelist is empty, and so the only overhead to
MgMap serialization is an integer - the size of the changelist.


Modified: trunk/MgDev/Common/MapGuideCommon/MapLayer/Map.cpp
===================================================================
--- trunk/MgDev/Common/MapGuideCommon/MapLayer/Map.cpp	2007-01-18 18:58:10 UTC (rev 1058)
+++ trunk/MgDev/Common/MapGuideCommon/MapLayer/Map.cpp	2007-01-19 02:07:28 UTC (rev 1059)
@@ -447,25 +447,26 @@
 
 //////////////////////////////////////////////////////////////////
 /// \brief
-/// Unpacks Layers and groups from Memory stream - Lazy Initialization
+/// Unpacks layers and groups from memory stream - lazy initialization
 ///
-/// How does lazy initialization work?  Basically, the layers, groups, and
-/// changeList collections are stored in a separate binary blob within MgMap.
-/// For large maps, the "layers groups" blob can be tens/hundreds of kbytes.
-/// In some cases, the application does not actually need this information from
-/// MgMap so serializing it is a big waste of resources.
+/// How does lazy initialization work?  Basically, the layer and group
+/// collections are stored in a separate binary blob within MgMap.  For
+/// large maps, the "layers groups" blob can be tens/hundreds of kbytes.
+/// In some cases, the application does not actually need this information
+/// from MgMap so serializing it is a big waste of resources.
 ///
-/// All saved MgMap objects know how to pull the layer groups blob on the fly
-/// using the internal m_resourceService/m_resId.  If GetLayers(), GetLayerGroups() or
-/// TrackChange() is called then the blob will automatically be pulled.  Note:
-/// m_resourceService must be set using SetDelayedLoadResourceService if MgMap
-/// is not set using Create or Open  (ie. when deserialized).
+/// All saved MgMap objects know how to pull the layer groups blob on the
+/// fly using the internal m_resourceService/m_resId.  If GetLayers() or
+/// GetLayerGroups() is called then the blob will automatically be pulled.
+/// Note: m_resourceService must be set using SetDelayedLoadResourceService
+/// if MgMap is not set using Create or Open (i.e. when deserialized).
 ///
-/// The "layers groups" blob is only serialized on the wire if it has changed.
-/// If none of the collections contain data then they are assumed to be unchanged.
+/// The "layers groups" blob is only serialized on the wire if it has
+/// changed.  If none of the collections contain data then they are assumed
+/// to be unchanged.
 ///
-/// The same applies to the Save.  If the collections do not contain data then they
-/// will not be saved.
+/// The same applies to the Save.  If the collections do not contain data
+/// then they will not be saved.
 ///
 void MgMap::UnpackLayersAndGroups()
 {
@@ -474,7 +475,7 @@
 
     if (NULL == (MgMemoryStreamHelper*) m_layerGroupHelper)
     {
-        if (m_changeLists->GetCount() || m_layers->GetCount() || m_groups->GetCount())
+        if (m_layers->GetCount() || m_groups->GetCount())
         {
             // Already unpacked, just return.
             return;
@@ -502,42 +503,6 @@
     Ptr<MgStream> stream = new MgStream(m_layerGroupHelper);
     MgStreamReader* streamReader = (MgStreamReader*)stream;
 
-    //change lists
-    INT32 changeListCount;
-    streamReader->GetInt32(changeListCount);
-
-    m_changeLists->SetCheckForDuplicates(false);
-
-    for(INT32 i = 0; i < changeListCount; i++)
-    {
-        STRING objectId;
-        bool isLayer;
-
-        streamReader->GetBoolean(isLayer);
-        streamReader->GetString(objectId);
-
-        Ptr<MgChangeList> changeList = new MgChangeList(objectId, isLayer);
-        m_changeLists->Add(changeList);
-
-        INT32 changeCount;
-        streamReader->GetInt32(changeCount);
-        for(INT32 j = 0; j < changeCount; j++)
-        {
-            INT32 type;
-            stream->GetInt32(type);
-
-            Ptr<MgObjectChange> change = new MgObjectChange((MgObjectChange::ChangeType)type);
-
-            STRING param;
-            streamReader->GetString(param);
-            change->SetParam(param);
-
-            changeList->AddChange(change);
-        }
-    }
-
-    m_changeLists->SetCheckForDuplicates(true);
-
     //groups
     //this map speeds up the process of attaching groups together and attaching layers to groups
     map<STRING, MgLayerGroup*> knownGroups;
@@ -593,7 +558,6 @@
     //done with this list
     knownGroups.clear();
 
-
     // Throw away the blob data.  It is no longer valid.
     streamReader = NULL;
     stream = NULL;
@@ -605,12 +569,11 @@
 
 //////////////////////////////////////////////////////////////////
 /// \brief
-/// Packs Layers and groups to a Memory stream (lazy initialization)
+/// Packs layers and groups to a memory stream (lazy initialization)
 ///
 MgMemoryStreamHelper* MgMap::PackLayersAndGroups()
 {
-    if (0 == m_changeLists->GetCount() && 0 == m_layers->GetCount() &&
-        0 == m_groups->GetCount())
+    if (0 == m_layers->GetCount() && 0 == m_groups->GetCount())
     {
         // Nothing to pack, or data has not changed.  Return NULL;
         return NULL;
@@ -621,23 +584,6 @@
     Ptr<MgMemoryStreamHelper> streamHelper = new MgMemoryStreamHelper();
     Ptr<MgStream> stream = new MgStream(streamHelper);
 
-    //change lists
-    INT32 changeListCount = m_changeLists->GetCount();
-    stream->WriteInt32(changeListCount);
-    for(INT32 i = 0; i < changeListCount; i++)
-    {
-        Ptr<MgChangeList> changeList = (MgChangeList*)m_changeLists->GetItem(i);
-        stream->WriteBoolean(changeList->IsLayer());
-        stream->WriteString(changeList->GetObjectId());
-        stream->WriteInt32(changeList->GetChangeCount());
-        for(INT32 j = 0; j < changeList->GetChangeCount(); j++)
-        {
-            Ptr<MgObjectChange> change = (MgObjectChange*)changeList->GetChangeAt(j);
-            stream->WriteInt32((INT32)change->GetType());
-            stream->WriteString(change->GetParam());
-        }
-    }
-
     //groups
     INT32 groupCount = m_groups->GetCount();
     stream->WriteInt32(groupCount);
@@ -648,16 +594,15 @@
         stream->WriteString(parent != NULL? parent->GetName(): L"");
         stream->WriteObject(group);
     }
+
     //layers
     INT32 layerCount = m_layers->GetCount();
     stream->WriteInt32(layerCount);
     for(int layerIndex = 0; layerIndex < layerCount; layerIndex++)
     {
         Ptr<MgLayerBase> layer = m_layers->GetItem(layerIndex);
-
         Ptr<MgLayerGroup> parent = layer->GetGroup();
         stream->WriteString(parent != NULL? parent->GetName(): L"");
-
         stream->WriteObject(layer);
     }
 
@@ -716,6 +661,23 @@
             stream->WriteDouble(*it);
     }
 
+    //change lists
+    INT32 changeListCount = m_changeLists->GetCount();
+    stream->WriteInt32(changeListCount);
+    for(INT32 i = 0; i < changeListCount; i++)
+    {
+        Ptr<MgChangeList> changeList = (MgChangeList*)m_changeLists->GetItem(i);
+        stream->WriteBoolean(changeList->IsLayer());
+        stream->WriteString(changeList->GetObjectId());
+        stream->WriteInt32(changeList->GetChangeCount());
+        for(INT32 j = 0; j < changeList->GetChangeCount(); j++)
+        {
+            Ptr<MgObjectChange> change = (MgObjectChange*)changeList->GetChangeAt(j);
+            stream->WriteInt32((INT32)change->GetType());
+            stream->WriteString(change->GetParam());
+        }
+    }
+
     // Serialize Layers and Groups as a blob.
     if (m_inSave)
     {
@@ -798,6 +760,43 @@
         m_finiteDisplayScales.push_back(displayScale);
     }
 
+    //change lists
+    INT32 changeListCount;
+    streamReader->GetInt32(changeListCount);
+
+    m_changeLists->SetCheckForDuplicates(false);
+
+    for(INT32 i = 0; i < changeListCount; i++)
+    {
+        STRING objectId;
+        bool isLayer;
+
+        streamReader->GetBoolean(isLayer);
+        streamReader->GetString(objectId);
+
+        Ptr<MgChangeList> changeList = new MgChangeList(objectId, isLayer);
+        m_changeLists->Add(changeList);
+
+        INT32 changeCount;
+        streamReader->GetInt32(changeCount);
+        for(INT32 j = 0; j < changeCount; j++)
+        {
+            INT32 type;
+            stream->GetInt32(type);
+
+            Ptr<MgObjectChange> change = new MgObjectChange((MgObjectChange::ChangeType)type);
+
+            STRING param;
+            streamReader->GetString(param);
+            change->SetParam(param);
+
+            changeList->AddChange(change);
+        }
+    }
+
+    m_changeLists->SetCheckForDuplicates(true);
+
+    //blob for layers and groups
     INT32 nBytes = 0;
     streamReader->GetInt32(nBytes);
     m_layerGroupHelper = NULL;

Modified: trunk/MgDev/Common/PlatformBase/MapLayer/MapBase.cpp
===================================================================
--- trunk/MgDev/Common/PlatformBase/MapLayer/MapBase.cpp	2007-01-18 18:58:10 UTC (rev 1058)
+++ trunk/MgDev/Common/PlatformBase/MapLayer/MapBase.cpp	2007-01-19 02:07:28 UTC (rev 1059)
@@ -670,8 +670,6 @@
 
     MG_TRY()
 
-    UnpackLayersAndGroups();
-
     //check if there is already a changelist for this object. If not, created it
     Ptr<MgChangeList> changeList = (MgChangeList*)m_changeLists->FindItem(objectId);
     if(changeList == NULL)



More information about the mapguide-commits mailing list