[mapguide-commits] r9591 - in sandbox/jng/querymapfeatures_selectionkey: Common/MapGuideCommon/Controller Web/src/HttpHandler

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Mon Aug 5 09:32:32 PDT 2019


Author: jng
Date: 2019-08-05 09:32:31 -0700 (Mon, 05 Aug 2019)
New Revision: 9591

Modified:
   sandbox/jng/querymapfeatures_selectionkey/Common/MapGuideCommon/Controller/HtmlController.cpp
   sandbox/jng/querymapfeatures_selectionkey/Common/MapGuideCommon/Controller/HtmlController.h
   sandbox/jng/querymapfeatures_selectionkey/Web/src/HttpHandler/HttpQueryMapFeatures.cpp
Log:
Implement v4.0.0 QUERYMAPFEATURES. This version of the operation includes the individual feature selection key for every set of feature attributes rendered. This is needed because the rendering of selected feature attribute *is not* guaranteed to be rendered in the same order as the raw selection set, thus an array index between selection set and selected feature attributes is not a reliable enough correlation data point, we have to explicitly include the selection key with the attributes. The selection key will only be written out for this version of the operation and is not rendered out for older operation versions.

Modified: sandbox/jng/querymapfeatures_selectionkey/Common/MapGuideCommon/Controller/HtmlController.cpp
===================================================================
--- sandbox/jng/querymapfeatures_selectionkey/Common/MapGuideCommon/Controller/HtmlController.cpp	2019-08-05 10:52:11 UTC (rev 9590)
+++ sandbox/jng/querymapfeatures_selectionkey/Common/MapGuideCommon/Controller/HtmlController.cpp	2019-08-05 16:32:31 UTC (rev 9591)
@@ -248,7 +248,8 @@
     INT32 layerAttributeFilter,
     INT32 requestData,
     CREFSTRING selectionColor,
-    CREFSTRING selectionFormat)
+    CREFSTRING selectionFormat,
+    bool bIncludeSelectionKey)
 {
     Ptr<MgByteReader> result;
     Ptr<MgFeatureInformation> featureInfo;
@@ -310,7 +311,7 @@
         inlineSelectionImg = service->RenderDynamicOverlay(map, newSelection, renderOpts);
     }
 
-    result = CollectQueryMapFeaturesResult(resourceService, featureService, map, requestData, featureInfo, newSelection, inlineSelectionImg);
+    result = CollectQueryMapFeaturesResult(resourceService, featureService, map, requestData, featureInfo, newSelection, inlineSelectionImg, bIncludeSelectionKey);
 
     // Return XML
     return result.Detach();
@@ -322,7 +323,8 @@
                                                               INT32 requestData,
                                                               MgFeatureInformation* featInfo,
                                                               MgSelection* selectionSet,
-                                                              MgByteReader* inlineSelection)
+                                                              MgByteReader* inlineSelection,
+                                                              bool bIncludeSelectionKey)
 {
     STRING xml;
     STRING tooltip;
@@ -390,7 +392,7 @@
     if ((requestData & REQUEST_ATTRIBUTES) == REQUEST_ATTRIBUTES)
     {
         xml.append(L"<SelectedFeatures>\n");
-        WriteSelectedFeatureAttributes(resourceService, featureService, map, selectionSet, xml);
+        WriteSelectedFeatureAttributes(resourceService, featureService, map, selectionSet, bIncludeSelectionKey, xml);
         xml.append(L"</SelectedFeatures>\n");
     }
     else
@@ -443,12 +445,13 @@
                                                       MgFeatureService* featureService,
                                                       MgMapBase* map,
                                                       MgSelection* selectionSet,
+                                                      bool bIncludeSelectionKey,
                                                       REFSTRING xmlOut)
 {
     MgAgfReaderWriter agfRw;
     MgWktReaderWriter wktRw;
     MgCoordinateSystemFactory csFactory;
-
+    MgMemoryStreamHelper streamHelper;
     Ptr<MgReadOnlyLayerCollection> selLayers = selectionSet->GetLayers();
     if (NULL != selLayers.p)
     {
@@ -462,6 +465,7 @@
         //                         are used for property names for each feature. This element provides a reverse lookup table to ascertain the FDO system 
         //                         property name for each attribute for client applications that require such information
         //     [0...n] <Feature> - Each selected feature in the layer
+        //       [0...1] <SelectionKey> - Selection key for this feature [only if requested]
         //       [1] <Bounds> - The feature's bounding box [minx miny maxx maxy]
         //       [0...n] <Property> - Property value for current feature
 
@@ -537,9 +541,17 @@
                 propNames->Add(selLayer->GetFeatureGeometryName()); //Don't forget geometry
             xmlOut.append(L"</LayerMetadata>\n");
             Ptr<MgReader> reader = selectionSet->GetSelectedFeatures(selLayer, selLayer->GetFeatureClassName(), propNames);
-            while(reader->ReadNext())
+            while (reader->ReadNext())
             {
                 xmlOut.append(L"<Feature>\n");
+                if (bIncludeSelectionKey)
+                {
+                    STRING selKey = EncodeKey(&streamHelper, reader, selLayer);
+                    xmlOut.append(L"<SelectionKey>\n");
+                    xmlOut.append(selKey);
+                    xmlOut.append(L"</SelectionKey>\n");
+                }
+
                 STRING geomPropName = selLayer->GetFeatureGeometryName();
                 if (!reader->IsNull(geomPropName))
                 {
@@ -730,6 +742,67 @@
     }
 }
 
+STRING MgHtmlController::EncodeKey(MgMemoryStreamHelper* stream, MgReader* feature, MgLayerBase* layer)
+{
+    //This is effectively a carbon-copy impl of MgSelectionBase::AddFeatureIds()
+
+    stream->Clear();
+
+    Ptr<MgClassDefinition> classDef = layer->GetClassDefinition();
+    Ptr<MgPropertyDefinitionCollection> props = classDef->GetProperties();
+    MgLayerBase::IdPropertyList propList = layer->GetIdPropertyList();
+    MgLayerBase::IdPropertyList::iterator idIter;
+    for (idIter = propList.begin(); idIter != propList.end(); ++idIter)
+    {
+        switch (idIter->type)
+        {
+        case MgPropertyType::Int16:
+        {
+            stream->WriteUINT16((UINT16)feature->GetInt16(idIter->name));
+        }
+        break;
+        case MgPropertyType::Int32:
+        {
+            stream->WriteUINT32((UINT32)feature->GetInt32(idIter->name));
+        }
+        break;
+        case MgPropertyType::Int64:
+        {
+            stream->WriteINT64(feature->GetInt64(idIter->name));
+        }
+        break;
+        case MgPropertyType::String:
+        {
+            stream->WriteNullTermString(feature->GetString(idIter->name));
+        }
+        break;
+        case MgPropertyType::Double:
+        {
+            stream->WriteDouble(feature->GetDouble(idIter->name));
+        }
+        break;
+        case MgPropertyType::Single:
+        {
+            stream->WriteSingle(feature->GetSingle(idIter->name));
+        }
+        break;
+        case MgPropertyType::DateTime:
+        {
+            Ptr<MgDateTime> dateTime = feature->GetDateTime(idIter->name);
+            Ptr<MgStream> tempStream = new MgStream(stream);
+            dateTime->Serialize(tempStream);
+        }
+        break;
+        default:
+            break;
+        }
+    }
+
+    STRING b64;
+    UnicodeString::MultiByteToWideChar(stream->ToBase64().c_str(), b64);
+    return b64;
+}
+
 //////////////////////////////////////////////////////////////////
 // Generates JavaScript code that can be embedded in an HTML response
 // to a non-viewer initiated web application request. The returned code

Modified: sandbox/jng/querymapfeatures_selectionkey/Common/MapGuideCommon/Controller/HtmlController.h
===================================================================
--- sandbox/jng/querymapfeatures_selectionkey/Common/MapGuideCommon/Controller/HtmlController.h	2019-08-05 10:52:11 UTC (rev 9590)
+++ sandbox/jng/querymapfeatures_selectionkey/Common/MapGuideCommon/Controller/HtmlController.h	2019-08-05 16:32:31 UTC (rev 9591)
@@ -205,7 +205,8 @@
         INT32 layerAttributeFilter,
         INT32 requestData,
         CREFSTRING selectionColor,
-        CREFSTRING selectionFormat);
+        CREFSTRING selectionFormat,
+        bool bIncludeSelectionKey);
 
     //////////////////////////////////////////////////////////////////
     /// \brief
@@ -311,7 +312,8 @@
                                                         INT32 requestData, 
                                                         MgFeatureInformation* featInfo,
                                                         MgSelection* selectionSet, 
-                                                        MgByteReader* inlineSelection);
+                                                        MgByteReader* inlineSelection,
+                                                        bool bIncludeSelectionKey);
 
     //////////////////////////////////////////////////////////////////
     /// \brief
@@ -326,10 +328,13 @@
     }
 
 private:
+    static STRING EncodeKey(MgMemoryStreamHelper* stream, MgReader* feature, MgLayerBase* layer);
+
     static void WriteSelectedFeatureAttributes(MgResourceService* resourceService,
                                                MgFeatureService* featureService,
                                                MgMapBase* map,
                                                MgSelection* selectionSet,
+                                               bool bIncludeSelectionKey,
                                                REFSTRING xmlOut);
 
     static MgCoordinateSystemTransform* GetLayerToMapTransform(MgLayerBase* layer, 

Modified: sandbox/jng/querymapfeatures_selectionkey/Web/src/HttpHandler/HttpQueryMapFeatures.cpp
===================================================================
--- sandbox/jng/querymapfeatures_selectionkey/Web/src/HttpHandler/HttpQueryMapFeatures.cpp	2019-08-05 10:52:11 UTC (rev 9590)
+++ sandbox/jng/querymapfeatures_selectionkey/Web/src/HttpHandler/HttpQueryMapFeatures.cpp	2019-08-05 16:32:31 UTC (rev 9591)
@@ -153,7 +153,9 @@
     }
     else if (version >= MG_API_VERSION(2, 6, 0))
     {
-        featureDescriptionInfo = controller.QueryMapFeatures(m_mapName, layerNames, filterGeometry, selectionVariant, m_featureFilter, m_maxFeatures, m_persist, m_layerAttributeFilter, m_requestData, m_selectionColor, m_selectionFormat);
+        //We only render selection keys alongside attributes for v4.0.0 and higher requests
+        bool bIncludeSelectionKey = version >= MG_API_VERSION(4, 0, 0);
+        featureDescriptionInfo = controller.QueryMapFeatures(m_mapName, layerNames, filterGeometry, selectionVariant, m_featureFilter, m_maxFeatures, m_persist, m_layerAttributeFilter, m_requestData, m_selectionColor, m_selectionFormat, bIncludeSelectionKey);
     }
     //Convert to alternate response format, if necessary
     ProcessFormatConversion(featureDescriptionInfo);



More information about the mapguide-commits mailing list