[mapserver-commits] r11352 - trunk/mapserver

svn at osgeo.org svn at osgeo.org
Mon Mar 28 14:43:54 EDT 2011


Author: assefa
Date: 2011-03-28 11:43:54 -0700 (Mon, 28 Mar 2011)
New Revision: 11352

Modified:
   trunk/mapserver/mapkmlrenderer.cpp
   trunk/mapserver/mapkmlrenderer.h
Log:
Output ExtendedData (#3728)

Modified: trunk/mapserver/mapkmlrenderer.cpp
===================================================================
--- trunk/mapserver/mapkmlrenderer.cpp	2011-03-28 16:12:07 UTC (rev 11351)
+++ trunk/mapserver/mapkmlrenderer.cpp	2011-03-28 18:43:54 UTC (rev 11352)
@@ -251,6 +251,11 @@
     
 }
 
+/************************************************************************/
+/*                               getLayerName                           */
+/*                                                                      */
+/*      Internal utility function to build name used fo rthe layer.     */
+/************************************************************************/
 char* KmlRenderer::getLayerName(layerObj *layer)
 {
     char stmp[20];
@@ -272,6 +277,18 @@
 
 }
 
+const char* KmlRenderer::getAliasName(layerObj *lp, char *pszItemName, const char *namespaces)
+{
+    const char *pszAlias = NULL;
+    if (lp && pszItemName && strlen(pszItemName) > 0)
+    {
+        char szTmp[256];
+        snprintf(szTmp, sizeof(szTmp), "%s_alias", pszItemName);
+        pszAlias = msOWSLookupMetadata(&(lp->metadata), namespaces, szTmp);
+    }
+    return pszAlias;
+}
+
 int KmlRenderer::startNewLayer(imageObj *, layerObj *layer)
 {
     char *layerName=NULL;
@@ -1214,12 +1231,16 @@
     }
     else if (papszLayerIncludeItems && nIncludeItems > 0)
     {
+/* -------------------------------------------------------------------- */
+/*      preffered way is to use the ExtendedData tag (#3728)            */
+/*      http://code.google.com/apis/kml/documentation/extendeddata.html */
+/* -------------------------------------------------------------------- */
+        
         char lineBuf[512];
-        xmlNodePtr descriptionNode = xmlNewNode(NULL, BAD_CAST "description");
+        xmlNodePtr extendedDataNode = xmlNewNode(NULL, BAD_CAST "ExtendedData");
+        xmlNodePtr dataNode = NULL; 
+        const char*pszAlias=NULL;
 
-        /*xmlNodeAddContent(descriptionNode, BAD_CAST "\n\t<![CDATA[\n");*/
-        xmlNodeAddContent(descriptionNode, BAD_CAST "<table>");
-
         for (int i=0; i<currentLayer->numitems; i++)
         {
             int j=0;
@@ -1231,19 +1252,24 @@
             }
             if (j<nIncludeItems)
             {
+                dataNode = xmlNewNode(NULL, BAD_CAST "Data");
+                xmlNewProp(dataNode, BAD_CAST "name", BAD_CAST  currentLayer->items[i]);
+                pszAlias = getAliasName(currentLayer, currentLayer->items[i], "GO");
+                if (pszAlias)
+                  xmlNewChild(dataNode, NULL, BAD_CAST "displayName", BAD_CAST  pszAlias);
+                else
+                  xmlNewChild(dataNode, NULL, BAD_CAST "displayName", BAD_CAST  currentLayer->items[i]);
                 if (shape->values[i] && strlen(shape->values[i]))
-                  snprintf(lineBuf, sizeof(lineBuf), "<tr><td><b>%s</b></td><td>%s</td></tr>\n", currentLayer->items[i], shape->values[i]);
+                  xmlNewChild(dataNode, NULL, BAD_CAST "value", BAD_CAST  shape->values[i]);
                 else
-                  snprintf(lineBuf, sizeof(lineBuf), "<tr><td><b>%s</b></td><td></td></tr>\n", currentLayer->items[i]);
-                xmlNodeAddContent(descriptionNode, BAD_CAST lineBuf);
+                  xmlNewChild(dataNode, NULL, BAD_CAST "value", NULL);
+                xmlAddChild(extendedDataNode, dataNode);
             }
-           
         }
 
-        xmlNodeAddContent(descriptionNode, BAD_CAST "</table>");
-	/*xmlNodeAddContent(descriptionNode, BAD_CAST "\t]]>\n");*/
+        return extendedDataNode;
 
-        return descriptionNode;
+        
     }
 
     return NULL;

Modified: trunk/mapserver/mapkmlrenderer.h
===================================================================
--- trunk/mapserver/mapkmlrenderer.h	2011-03-28 16:12:07 UTC (rev 11351)
+++ trunk/mapserver/mapkmlrenderer.h	2011-03-28 18:43:54 UTC (rev 11352)
@@ -138,6 +138,7 @@
         char* getLayerName(layerObj *layer);
         void processLayer(layerObj *layer);
         void addLineStyleToList(strokeStyleObj *style);
+        const char *getAliasName(layerObj *lp, char *pszItemName, const char *namespaces);
 
 public:
 



More information about the mapserver-commits mailing list