[mapserver-commits] r11152 - trunk/mapserver

svn at osgeo.org svn at osgeo.org
Fri Mar 11 12:14:23 EST 2011


Author: assefa
Date: 2011-03-11 09:14:23 -0800 (Fri, 11 Mar 2011)
New Revision: 11152

Modified:
   trunk/mapserver/HISTORY.TXT
   trunk/mapserver/mapkmlrenderer.cpp
   trunk/mapserver/mapkmlrenderer.h
Log:
possiblity to us kml_name_item (#3728)

Modified: trunk/mapserver/HISTORY.TXT
===================================================================
--- trunk/mapserver/HISTORY.TXT	2011-03-11 13:22:21 UTC (rev 11151)
+++ trunk/mapserver/HISTORY.TXT	2011-03-11 17:14:23 UTC (rev 11152)
@@ -14,6 +14,8 @@
 Current Version (SVN trunk):
 ----------------------------
 
+- Add possibility to use KML_NAME_ITEM (#3728)
+
 - Fixed mapfile parsing error when a label angle referenced an attribute 
   (e.g. ANGLE [angle]) #3727
 

Modified: trunk/mapserver/mapkmlrenderer.cpp
===================================================================
--- trunk/mapserver/mapkmlrenderer.cpp	2011-03-11 13:22:21 UTC (rev 11151)
+++ trunk/mapserver/mapkmlrenderer.cpp	2011-03-11 17:14:23 UTC (rev 11152)
@@ -51,6 +51,7 @@
     pszLayerDescMetadata = NULL;  
     papszLayerIncludeItems = NULL;
     nIncludeItems=0;
+    pszLayerNameAttributeMetadata = NULL;  /*metadata to use for a name for each feature*/
     
     LineStyle = NULL;
     numLineStyle = 0;
@@ -365,6 +366,9 @@
      if (value)
        papszLayerIncludeItems = msStringSplit(value, ',', &nIncludeItems);
 
+     if (msLookupHashTable(&layer->metadata, "kml_name_item"))
+       pszLayerNameAttributeMetadata = msLookupHashTable(&layer->metadata, "kml_name_item");
+
      /*get all attributes*/
      msLayerWhichItems(layer, MS_TRUE, NULL);
 
@@ -410,6 +414,8 @@
 
     if (pszLayerDescMetadata)
       pszLayerDescMetadata = NULL;
+    if (pszLayerNameAttributeMetadata)
+      pszLayerNameAttributeMetadata = NULL;
 
     if (papszLayerIncludeItems && nIncludeItems>0)
       msFreeCharArray(papszLayerIncludeItems, nIncludeItems);
@@ -526,11 +532,18 @@
     /*always add a name. It will be replaced by a text value if available*/
     char tmpid[100];
     char *stmp=NULL, *layerName=NULL;
+    if (CurrentShapeName && strlen(CurrentShapeName)>0)
+    {
+        xmlNewChild(placemarkNode, NULL, BAD_CAST "name", BAD_CAST CurrentShapeName);
+    }
+    else
+    {
     sprintf(tmpid, ".%d", CurrentShapeIndex);
     layerName = getLayerName(currentLayer);
     stmp = msStringConcatenate(stmp, layerName);
     stmp = msStringConcatenate(stmp, tmpid);
     xmlNewChild(placemarkNode, NULL, BAD_CAST "name", BAD_CAST stmp);
+    }
     msFree(layerName);
     msFree(stmp);
     if (styleUrl)
@@ -845,6 +858,7 @@
 
     CurrentShapeIndex=-1;
     CurrentDrawnShapeIndex = -1;
+    CurrentShapeName=NULL;
 
     /*should be done at endshape but the plugin architecture does not call endshape yet*/
     if(LineStyle)
@@ -858,6 +872,17 @@
     if (shape)
     {
         CurrentShapeIndex = shape->index;
+        if (pszLayerNameAttributeMetadata)
+        {
+            for (int i=0; i<currentLayer->numitems; i++)
+            {
+                if (strcasecmp(currentLayer->items[i], pszLayerNameAttributeMetadata) == 0 && shape->values[i])
+                {
+                    CurrentShapeName = msStrdup(shape->values[i]);
+                    break;
+                }
+            }
+        }
     }
     PlacemarkNode = NULL;
     GeomNode = NULL;
@@ -877,6 +902,9 @@
 void KmlRenderer::endShape(imageObj*, shapeObj*)
 {
     CurrentShapeIndex = -1;
+    if (CurrentShapeName)
+      msFree(CurrentShapeName);
+    CurrentShapeName = NULL;
 }
 
 xmlNodePtr KmlRenderer::getGeomParentNode(const char *geomName)

Modified: trunk/mapserver/mapkmlrenderer.h
===================================================================
--- trunk/mapserver/mapkmlrenderer.h	2011-03-11 13:22:21 UTC (rev 11151)
+++ trunk/mapserver/mapkmlrenderer.h	2011-03-11 17:14:23 UTC (rev 11152)
@@ -43,6 +43,7 @@
   const char *pszLayerDescMetadata; /*if the kml_description is set*/
   char **papszLayerIncludeItems;
   int nIncludeItems;
+  char *pszLayerNameAttributeMetadata;
 
 protected:
 
@@ -65,6 +66,7 @@
 
 	int	        CurrentShapeIndex;
 	int	        CurrentDrawnShapeIndex;
+        char            *CurrentShapeName;
 	char		**Items;
 	int			NumItems;
 	int			DumpAttributes;



More information about the mapserver-commits mailing list