labelitemfix.txt

patch for issue - Richard Duivenvoorde, 2010-05-17 01:29 PM

Download (1.79 KB)

 
1
Index: python/plugins/mapserver_export/ms_export.py
2
===================================================================
3
--- python/plugins/mapserver_export/ms_export.py	(revision 13489)
4
+++ python/plugins/mapserver_export/ms_export.py	(working copy)
5
@@ -590,17 +590,26 @@
6
         if maxscale > '':
7
           layer_def += "    MAXSCALE " + maxscale + "\n"
8
 
9
-      
10
       # Check for label field (ie LABELITEM) and label status
11
       try:
12
-        labelOn    = lyr.getElementsByTagName(     "label")[0].childNodes[0].nodeValue.encode('utf-8')
13
-        labelField = lyr.getElementsByTagName("labelfield")[0].childNodes[0].nodeValue.encode('utf-8')
14
-        if labelField != '' and labelField is not None and labelOn == "1":
15
+        labelElements = lyr.getElementsByTagName("label")
16
+        labelOn = '0'
17
+        labelField = None
18
+        # there are actually 3 different label-element in a layer element:
19
+        for element in labelElements:
20
+            labelParent = element.parentNode.localName
21
+            if labelParent == 'maplayer':
22
+                labelOn = element.childNodes[0].nodeValue.encode('utf-8')
23
+            if labelParent == 'labelattributes':
24
+                labelField = element.getAttribute('fieldname').encode('utf-8')
25
+        # is this also the right labelfield? Or is it an obsolete one?
26
+        #labelField = labelattrs.getElementsByTagName("labelfield")[0].childNodes[0].nodeValue.encode('utf-8')
27
+        if labelField != '' and labelField is not None and labelOn == "1" and labelOn is not None:
28
           layer_def += "    LABELITEM '" + labelField + "'\n"
29
       except:
30
         # no labels
31
         pass
32
-      
33
+    
34
       # write the CLASS section for rendering
35
       # First see if there is a single symbol renderer
36
       if lyr.getElementsByTagName("singlesymbol").length > 0: