[mapguide-commits] r9190 - sandbox/jng/utfgrid/Common/Renderers

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Fri May 26 09:05:42 PDT 2017


Author: jng
Date: 2017-05-26 09:05:42 -0700 (Fri, 26 May 2017)
New Revision: 9190

Modified:
   sandbox/jng/utfgrid/Common/Renderers/UTFGridContent.cpp
   sandbox/jng/utfgrid/Common/Renderers/UTFGridContent.h
   sandbox/jng/utfgrid/Common/Renderers/UTFGridRenderer.cpp
Log:
UTFGridRenderer changes:
 - Pass layerinfo, tooltip and url to UTFGridContent::AddFeature
 - Emit extra debugging attributes of UTFGrid feature data if DEBUG_UTFGRID is defined
 - Remove the use of auto keyword, for I am reminded that we need to build this on GCC versions with questionable support for what we now take for granted as "modern C++"

Modified: sandbox/jng/utfgrid/Common/Renderers/UTFGridContent.cpp
===================================================================
--- sandbox/jng/utfgrid/Common/Renderers/UTFGridContent.cpp	2017-05-02 17:01:31 UTC (rev 9189)
+++ sandbox/jng/utfgrid/Common/Renderers/UTFGridContent.cpp	2017-05-26 16:05:42 UTC (rev 9190)
@@ -3,6 +3,10 @@
 #include "agg_utfgrid_context.h"
 #include "KeyEncode.h"
 
+//Uncomment this line below to render UTFGrid content with extra debugging information attached to each
+//feature
+#define DEBUG_UTFGRID
+
 UTFGridContent::UTFGridContent()
 {
 }
@@ -18,7 +22,7 @@
     return mbContent;
 }
 
-bool UTFGridContent::AddFeature(unsigned int decodedColor, RS_FeatureReader* feature)
+bool UTFGridContent::AddFeature(RS_LayerUIInfo* layer, unsigned int decodedColor, RS_FeatureReader* feature, const RS_String * tooltip, const RS_String * url)
 {
     static const size_t MAX_STRING = 64;
 
@@ -28,15 +32,15 @@
     {
         std::wstring wVal = L"{";
 
-        auto geomName = feature->GetGeomPropName();
-        auto rasterName = feature->GetRasterPropName();
+        const wchar_t * geomName = feature->GetGeomPropName();
+        const wchar_t * rasterName = feature->GetRasterPropName();
 
         bool bFirst = true;
         int count = 0;
-        auto propNames = feature->GetPropNames(count);
+        const wchar_t* const* propNames = feature->GetPropNames(count);
         for (int i = 0; i < count; i++)
         {
-            auto propName = propNames[i];
+            const wchar_t* propName = propNames[i];
             //Skip geometry/raster
             if ((geomName && wcscmp(propName, geomName) == 0) ||
                 (rasterName && wcscmp(propName, rasterName) == 0))
@@ -48,13 +52,13 @@
             {
                 wVal.append(L",");
             }
-            auto propVal = feature->GetAsString(propName);
+            const wchar_t* propVal = feature->GetAsString(propName);
 
             wVal.append(L"\"");
             wVal.append(propName);
             wVal.append(L"\": ");
 
-            auto propType = feature->GetPropertyType(propName);
+            int propType = feature->GetPropertyType(propName);
             if (propType == FdoDataType_String || propType == FdoDataType_DateTime)
             {
                 wVal.append(L"\"");
@@ -69,6 +73,43 @@
             bFirst = false;
         }
 
+#ifdef DEBUG_UTFGRID
+        wVal.append(L",\"_MGLAYER_NAME\": ");
+        wVal.append(L"\"");
+        wVal.append(layer->name());
+        wVal.append(L"\"");
+        wVal.append(L",\"_MGLAYER_ID\": ");
+        wVal.append(L"\"");
+        wVal.append(layer->layerdef());
+        wVal.append(L"\"");
+        wVal.append(L",\"_MGLAYER_TOOLTIP\": ");
+        if (NULL != tooltip) 
+        {
+            wVal.append(L"\"");
+            wVal.append(*tooltip);
+            wVal.append(L"\"");
+        }
+        else 
+        {
+            wVal.append(L"null");
+        }
+        wVal.append(L",\"_MGLAYER_URL\": ");
+        if (NULL != url)
+        {
+            wVal.append(L"\"");
+            wVal.append(*url);
+            wVal.append(L"\"");
+        }
+        else
+        {
+            wVal.append(L"null");
+        }
+        wVal.append(L",\"_MGLAYER_SELECTABLE\": ");
+        wVal.append(layer->selectable() ? L"true" : L"false");
+        wVal.append(L",\"_MGLAYER_HASTOOLTIPS\": ");
+        wVal.append(layer->hastooltips() ? L"true" : L"false");
+#endif
+
         wVal += L"}";
 
         m_features.insert(std::make_pair(key, wVal));
@@ -111,7 +152,7 @@
 {
     m_content << "," << std::endl;
     m_content << "  \"keys\": [" << std::endl;
-    for (auto it = m_trackedEncodedColors.begin(); it != m_trackedEncodedColors.end(); it++)
+    for (ColorSet::iterator it = m_trackedEncodedColors.begin(); it != m_trackedEncodedColors.end(); it++)
     {
         if (it != m_trackedEncodedColors.begin())
             m_content << "," << std::endl;
@@ -122,7 +163,7 @@
         }
         else
         {
-            auto decodedKey = DecodeChar(*it);
+            unsigned int decodedKey = DecodeChar(*it);
             m_content << "    \"" << decodedKey << "\"";
         }
     }
@@ -134,18 +175,18 @@
     m_content << "," << std::endl;
     m_content << "  \"data\": {" << std::endl;
     bool bFirst = true;
-    for (auto it = m_trackedEncodedColors.begin(); it != m_trackedEncodedColors.end(); it++)
+    for (ColorSet::iterator it = m_trackedEncodedColors.begin(); it != m_trackedEncodedColors.end(); it++)
     {
         if (*it == 32) // This is the "empty space" pixel
         {
             continue;
         }
 
-        auto colorKey = DecodeChar(*it);
+        unsigned int colorKey = DecodeChar(*it);
         if (m_pixels.find(colorKey) != m_pixels.end())
         {
-            auto featKey = m_pixels[colorKey];
-            auto featData = m_features[featKey];
+            std::string featKey = m_pixels[colorKey];
+            std::wstring featData = m_features[featKey];
             if (!bFirst)
                 m_content << "," << std::endl;
 

Modified: sandbox/jng/utfgrid/Common/Renderers/UTFGridContent.h
===================================================================
--- sandbox/jng/utfgrid/Common/Renderers/UTFGridContent.h	2017-05-02 17:01:31 UTC (rev 9189)
+++ sandbox/jng/utfgrid/Common/Renderers/UTFGridContent.h	2017-05-26 16:05:42 UTC (rev 9190)
@@ -19,6 +19,7 @@
 #define _UTFGRIDCONTENT_H_
 
 #include "Renderers.h"
+#include "RendererStyles.h"
 #include "RS_FeatureReader.h"
 #include "KeyEncode.h"
 #include <set>
@@ -26,6 +27,7 @@
 
 typedef std::map<unsigned int, std::string> ColorKeyMap;
 typedef std::map<std::string, std::wstring> KeyFeatureMap;
+typedef std::set<unsigned int> ColorSet;
 
 class UTFGridContent
 {
@@ -35,7 +37,7 @@
 
     RENDERERS_API std::string GetString();
 
-    bool AddFeature(unsigned int color, RS_FeatureReader* feature);
+    bool AddFeature(RS_LayerUIInfo* layer, unsigned int color, RS_FeatureReader* feature, const RS_String * tooltip, const RS_String * url);
 
     void StartGrid();
     void StartGridRow(bool bFirst);
@@ -52,7 +54,7 @@
 private:
 
     std::wstringstream m_content;
-    std::set<unsigned int> m_trackedEncodedColors;
+    ColorSet m_trackedEncodedColors;
 
     KeyFeatureMap m_features;
     ColorKeyMap m_pixels;

Modified: sandbox/jng/utfgrid/Common/Renderers/UTFGridRenderer.cpp
===================================================================
--- sandbox/jng/utfgrid/Common/Renderers/UTFGridRenderer.cpp	2017-05-02 17:01:31 UTC (rev 9189)
+++ sandbox/jng/utfgrid/Common/Renderers/UTFGridRenderer.cpp	2017-05-26 16:05:42 UTC (rev 9190)
@@ -122,7 +122,7 @@
     for (int y = m_context->rendering_buffer.height() - 1; y >= 0; y--)
     {
         m_content->StartGridRow(bFirst);
-        auto row_ptr = m_context->rendering_buffer.row_ptr(y);
+        utfgrid_band_type* row_ptr = m_context->rendering_buffer.row_ptr(y);
         for (int x = 0; x < m_context->rendering_buffer.width(); x++)
         {
             m_content->AppendRowPixel(row_ptr[x]);
@@ -149,12 +149,12 @@
     m_fcInfo = NULL;
 }
 
-void UTFGridRenderer::StartFeature(RS_FeatureReader * feature, bool /* initialPass */, const RS_String * /* tooltip */, const RS_String * /* url */, const RS_String * /* theme */, double /* zOffset */, double /* zExtrusion */, RS_ElevationType /* zOffsetType */)
+void UTFGridRenderer::StartFeature(RS_FeatureReader * feature, bool /* initialPass */, const RS_String * tooltip, const RS_String * url, const RS_String * /* theme */, double /* zOffset */, double /* zExtrusion */, RS_ElevationType /* zOffsetType */)
 {
     m_currentColor++;
-    m_renderThisFeature = m_content->AddFeature(m_currentColor, feature);
+    m_renderThisFeature = m_content->AddFeature(m_layerInfo, m_currentColor, feature, tooltip, url);
     if (!m_renderThisFeature)
-        m_currentColor--; //Rewind
+        m_currentColor--; //Rewind, as we have a limited budget for available pixel values and want to maximize the use of each value available to us
 }
 
 void UTFGridRenderer::ProcessPolygon(LineBuffer * lb, RS_FillStyle & fill)



More information about the mapguide-commits mailing list