@@ -924,11 +924,11 @@ int msDrawVectorLayer(mapObj *map, layerObj *layer, imageObj *image)
924
924
int drawmode = MS_DRAWMODE_FEATURES ;
925
925
char annotate = MS_TRUE ;
926
926
shapeObj shape ;
927
+ shapeObj savedShape ;
927
928
rectObj searchrect ;
928
929
char cache = MS_FALSE ;
929
930
int maxnumstyles = 1 ;
930
931
featureListNodeObjPtr shpcache = NULL , current = NULL ;
931
- int classindex = -1 ;
932
932
int nclasses = 0 ;
933
933
int * classgroup = NULL ;
934
934
double minfeaturesize = -1 ;
@@ -1016,8 +1016,10 @@ int msDrawVectorLayer(mapObj *map, layerObj *layer, imageObj *image)
1016
1016
1017
1017
/* step through the target shapes and their classes */
1018
1018
msInitShape (& shape );
1019
- classindex = -1 ;
1019
+ int classindex = -1 ;
1020
+ int classcount = 0 ;
1020
1021
for (;;) {
1022
+ int rendermode ;
1021
1023
if (classindex == -1 ) {
1022
1024
status = msLayerNextShape (layer , & shape );
1023
1025
if (status != MS_SUCCESS ) {
@@ -1030,15 +1032,29 @@ int msDrawVectorLayer(mapObj *map, layerObj *layer, imageObj *image)
1030
1032
msDebug ("msDrawVectorLayer(): Skipping shape (%ld) because LAYER::MINFEATURESIZE is bigger than shape size\n" , shape .index );
1031
1033
continue ;
1032
1034
}
1035
+ classcount = 0 ;
1033
1036
}
1034
1037
1035
1038
classindex = msShapeGetNextClass (classindex , layer , map , & shape , classgroup , nclasses );
1036
1039
if ((classindex == -1 ) || (layer -> class [classindex ]-> status == MS_OFF )) {
1037
1040
continue ;
1038
1041
}
1039
1042
shape .classindex = classindex ;
1040
- classindex = -1 ; // This value indicates that no more class is to be
1041
- // fetched from current shape
1043
+
1044
+ // When only one class is applicable, rendering mode is forced to its default,
1045
+ // i.e. only the first applicable class is actually applied. As a consequence,
1046
+ // cache can be enabled when relevant.
1047
+ classcount ++ ;
1048
+ rendermode = layer -> rendermode ;
1049
+ if ((classcount == 1 ) && (msShapeGetNextClass (classindex , layer , map , & shape , classgroup , nclasses ) == -1 ))
1050
+ {
1051
+ rendermode = MS_FIRST_MATCHING_CLASS ;
1052
+ }
1053
+
1054
+ if (rendermode == MS_FIRST_MATCHING_CLASS )
1055
+ {
1056
+ classindex = -1 ;
1057
+ }
1042
1058
1043
1059
if (maxfeatures >=0 && featuresdrawn >= maxfeatures ) {
1044
1060
status = MS_DONE ;
@@ -1077,6 +1093,13 @@ int msDrawVectorLayer(mapObj *map, layerObj *layer, imageObj *image)
1077
1093
cache = MS_FALSE ;
1078
1094
}
1079
1095
1096
+ if (rendermode == MS_ALL_MATCHING_CLASSES )
1097
+ {
1098
+ // Cache is designed to handle only one class. Therefore it is
1099
+ // disabled when using SLD "painters model" rendering mode.
1100
+ cache = MS_FALSE ;
1101
+ }
1102
+
1080
1103
/* RFC77 TODO: check return value, may need a more sophisticated if-then test. */
1081
1104
if (annotate && layer -> class [shape .classindex ]-> numlabels > 0 ) {
1082
1105
drawmode |= MS_DRAWMODE_LABELS ;
@@ -1089,6 +1112,16 @@ int msDrawVectorLayer(mapObj *map, layerObj *layer, imageObj *image)
1089
1112
drawmode |= MS_DRAWMODE_UNCLIPPEDLINES ;
1090
1113
}
1091
1114
1115
+ if (rendermode == MS_ALL_MATCHING_CLASSES )
1116
+ {
1117
+ // In SLD "painters model" rendering mode, all applicable classes are actually applied.
1118
+ // Coordinates stored in the shape must keep their original values for
1119
+ // the shape to be drawn multiple times.
1120
+ // Here the original shape is saved.
1121
+ msInitShape (& savedShape );
1122
+ msCopyShape (& shape , & savedShape );
1123
+ }
1124
+
1092
1125
if (cache ) {
1093
1126
styleObj * pStyle = layer -> class [shape .classindex ]-> styles [0 ];
1094
1127
if (pStyle -> outlinewidth > 0 ) {
@@ -1115,6 +1148,17 @@ int msDrawVectorLayer(mapObj *map, layerObj *layer, imageObj *image)
1115
1148
1116
1149
else
1117
1150
status = msDrawShape (map , layer , & shape , image , -1 , drawmode ); /* all styles */
1151
+
1152
+ if (rendermode == MS_ALL_MATCHING_CLASSES )
1153
+ {
1154
+ // In SLD "painters model" rendering mode, all applicable classes are actually applied.
1155
+ // Coordinates stored in the shape must keep their original values for
1156
+ // the shape to be drawn multiple times.
1157
+ // Here the original shape is restored.
1158
+ msCopyShape (& savedShape , & shape );
1159
+ msFreeShape (& savedShape );
1160
+ }
1161
+
1118
1162
if (status != MS_SUCCESS ) {
1119
1163
retcode = MS_FAILURE ;
1120
1164
break ;
0 commit comments