Permalink
Browse files

take into account style min/max scale in legend (#4601)

the mapscript and template code calling these updated functions
are hardcoded to do scale-independant legend rendering to remain
backwards compatible.
  • Loading branch information...
1 parent 2a758fd commit 297fa3e71ae06b22a05b0b1d14364db74da2c96c @tbonfort tbonfort committed Apr 10, 2013
Showing with 63 additions and 24 deletions.
  1. +41 −12 maplegend.c
  2. +2 −2 mapscript/php/mapscript_i.c
  3. +2 −2 mapscript/swiginc/class.i
  4. +2 −2 mapserver.h
  5. +1 −1 mapservutil.c
  6. +2 −2 maptemplate.c
  7. +13 −3 mapwms.c
View
@@ -41,7 +41,8 @@
* this function
*/
int msDrawLegendIcon(mapObj *map, layerObj *lp, classObj *theclass,
- int width, int height, imageObj *image, int dstX, int dstY)
+ int width, int height, imageObj *image, int dstX, int dstY,
+ int scale_independant)
{
int i, type, hasmarkersymbol;
double offset;
@@ -145,13 +146,23 @@ int msDrawLegendIcon(mapObj *map, layerObj *lp, classObj *theclass,
marker.y = dstY + MS_NINT(height / 2.0);
hasmarkersymbol = 0;
for(i=0; i<theclass->numstyles; i++) {
- if (theclass->styles[i]->symbol < map->symbolset.numsymbols && theclass->styles[i]->symbol > 0) {
- hasmarkersymbol = 1;
- break;
- }
+ if(!scale_independant && map->scaledenom > 0) {
+ styleObj *lp = theclass->styles[i];
+ if((lp->maxscaledenom > 0) && (map->scaledenom > lp->maxscaledenom)) continue;
+ if((lp->minscaledenom > 0) && (map->scaledenom <= lp->minscaledenom)) continue;
+ }
+ if (theclass->styles[i]->symbol < map->symbolset.numsymbols && theclass->styles[i]->symbol > 0) {
+ hasmarkersymbol = 1;
+ break;
+ }
}
if (hasmarkersymbol) {
for(i=0; i<theclass->numstyles; i++)
+ if(!scale_independant && map->scaledenom > 0) {
+ styleObj *lp = theclass->styles[i];
+ if((lp->maxscaledenom > 0) && (map->scaledenom > lp->maxscaledenom)) continue;
+ if((lp->minscaledenom > 0) && (map->scaledenom <= lp->minscaledenom)) continue;
+ }
msDrawMarkerSymbol(&map->symbolset, image_draw, &marker, theclass->styles[i], lp->scalefactor);
} else if (theclass->labels && theclass->numlabels > 0) {
labelObj *label = theclass->labels[0]; /* use the first label definition */
@@ -204,8 +215,14 @@ int msDrawLegendIcon(mapObj *map, layerObj *lp, classObj *theclass,
msDrawMarkerSymbol(&map->symbolset,image_draw,&marker,&imgStyle,lp->scalefactor);
/* TO DO: we may want to handle this differently depending on the relative size of the keyimage */
} else {
- for(i=0; i<theclass->numstyles; i++)
+ for(i=0; i<theclass->numstyles; i++) {
+ if(!scale_independant && map->scaledenom > 0) {
+ styleObj *lp = theclass->styles[i];
+ if((lp->maxscaledenom > 0) && (map->scaledenom > lp->maxscaledenom)) continue;
+ if((lp->minscaledenom > 0) && (map->scaledenom <= lp->minscaledenom)) continue;
+ }
msDrawMarkerSymbol(&map->symbolset, image_draw, &marker, theclass->styles[i], lp->scalefactor);
+ }
}
break;
case MS_LAYER_LINE:
@@ -232,8 +249,14 @@ int msDrawLegendIcon(mapObj *map, layerObj *lp, classObj *theclass,
zigzag.line[0].point[3].x = dstX + width - offset;
zigzag.line[0].point[3].y = dstY + offset;
- for(i=0; i<theclass->numstyles; i++)
+ for(i=0; i<theclass->numstyles; i++) {
+ if(!scale_independant && map->scaledenom > 0) {
+ styleObj *lp = theclass->styles[i];
+ if((lp->maxscaledenom > 0) && (map->scaledenom > lp->maxscaledenom)) continue;
+ if((lp->minscaledenom > 0) && (map->scaledenom <= lp->minscaledenom)) continue;
+ }
msDrawLineSymbol(&map->symbolset, image_draw, &zigzag, theclass->styles[i], lp->scalefactor);
+ }
free(zigzag.line[0].point);
free(zigzag.line);
@@ -242,8 +265,14 @@ int msDrawLegendIcon(mapObj *map, layerObj *lp, classObj *theclass,
case MS_LAYER_RASTER:
case MS_LAYER_CHART:
case MS_LAYER_POLYGON:
- for(i=0; i<theclass->numstyles; i++)
+ for(i=0; i<theclass->numstyles; i++) {
+ if(!scale_independant && map->scaledenom > 0) {
+ styleObj *lp = theclass->styles[i];
+ if((lp->maxscaledenom > 0) && (map->scaledenom > lp->maxscaledenom)) continue;
+ if((lp->minscaledenom > 0) && (map->scaledenom <= lp->minscaledenom)) continue;
+ }
msDrawShadeSymbol(&map->symbolset, image_draw, &box, theclass->styles[i], lp->scalefactor);
+ }
break;
default:
return MS_FAILURE;
@@ -308,7 +337,7 @@ int msDrawLegendIcon(mapObj *map, layerObj *lp, classObj *theclass,
}
-imageObj *msCreateLegendIcon(mapObj* map, layerObj* lp, classObj* class, int width, int height)
+imageObj *msCreateLegendIcon(mapObj* map, layerObj* lp, classObj* class, int width, int height, int scale_independant)
{
imageObj *image;
outputFormatObj *format = NULL;
@@ -344,10 +373,10 @@ imageObj *msCreateLegendIcon(mapObj* map, layerObj* lp, classObj* class, int wid
msClearLayerPenValues(lp); /* just in case the mapfile has already been processed */
#endif
if (class) {
- msDrawLegendIcon(map, lp, class, width, height, image, 0, 0);
+ msDrawLegendIcon(map, lp, class, width, height, image, 0, 0, scale_independant);
} else {
for (i=0; i<lp->numclasses; i++) {
- msDrawLegendIcon(map, lp, lp->class[i], width, height, image, 0, 0);
+ msDrawLegendIcon(map, lp, lp->class[i], width, height, image, 0, 0, scale_independant);
}
}
}
@@ -594,7 +623,7 @@ imageObj *msDrawLegend(mapObj *map, int scale_independent)
map->cellsize = msAdjustExtent(&(map->extent), map->width, map->height);
cur->layer->scalefactor = (msInchesPerUnit(cur->layer->sizeunits,0)/msInchesPerUnit(map->units,0)) / map->cellsize;
}
- if(msDrawLegendIcon(map, cur->layer, cur->theclass, map->legend.keysizex, map->legend.keysizey, image, HMARGIN, (int) pnt.y) != MS_SUCCESS)
+ if(msDrawLegendIcon(map, cur->layer, cur->theclass, map->legend.keysizex, map->legend.keysizey, image, HMARGIN, (int) pnt.y, scale_independent) != MS_SUCCESS)
return NULL;
/*
@@ -1081,12 +1081,12 @@ int classObj_drawLegendIcon(classObj *self, mapObj *map, layerObj *layer, int wi
#ifdef USE_GD
msClearLayerPenValues(layer); // just in case the mapfile has already been processed
#endif
- return msDrawLegendIcon(map, layer, self, width, height, dstImg, dstX, dstY);
+ return msDrawLegendIcon(map, layer, self, width, height, dstImg, dstX, dstY, MS_TRUE);
}
imageObj *classObj_createLegendIcon(classObj *self, mapObj *map, layerObj *layer, int width, int height)
{
- return msCreateLegendIcon(map, layer, self, width, height);
+ return msCreateLegendIcon(map, layer, self, width, height, MS_TRUE);
}
@@ -178,12 +178,12 @@
}
int drawLegendIcon(mapObj *map, layerObj *layer, int width, int height, imageObj *dstImage, int dstX, int dstY) {
- return msDrawLegendIcon(map, layer, self, width, height, dstImage, dstX, dstY);
+ return msDrawLegendIcon(map, layer, self, width, height, dstImage, dstX, dstY, MS_TRUE);
}
%newobject createLegendIcon;
imageObj *createLegendIcon(mapObj *map, layerObj *layer, int width, int height) {
- return msCreateLegendIcon(map, layer, self, width, height);
+ return msCreateLegendIcon(map, layer, self, width, height, MS_TRUE);
}
%newobject getLabel;
View
@@ -2109,8 +2109,8 @@ extern "C" {
MS_DLL_EXPORT int msLegendCalcSize(mapObj *map, int scale_independent, int *size_x, int *size_y,
int *alayers, int numl_ayer);
MS_DLL_EXPORT int msEmbedLegend(mapObj *map, imageObj *img);
- MS_DLL_EXPORT int msDrawLegendIcon(mapObj* map, layerObj* lp, classObj* myClass, int width, int height, imageObj *img, int dstX, int dstY);
- MS_DLL_EXPORT imageObj *msCreateLegendIcon(mapObj* map, layerObj* lp, classObj* myClass, int width, int height);
+ MS_DLL_EXPORT int msDrawLegendIcon(mapObj* map, layerObj* lp, classObj* myClass, int width, int height, imageObj *img, int dstX, int dstY, int scale_independant);
+ MS_DLL_EXPORT imageObj *msCreateLegendIcon(mapObj* map, layerObj* lp, classObj* myClass, int width, int height, int scale_independant);
MS_DLL_EXPORT int msLoadFontSet(fontSetObj *fontSet, mapObj *map); /* in maplabel.c */
MS_DLL_EXPORT int msInitFontSet(fontSetObj *fontset);
View
@@ -1578,7 +1578,7 @@ int msCGIDispatchLegendIconRequest(mapservObj *mapserv)
/* drop this reference to output format */
msApplyOutputFormat(&format, NULL, MS_NOOVERRIDE, MS_NOOVERRIDE, MS_NOOVERRIDE);
- if(msDrawLegendIcon(mapserv->map, GET_LAYER(mapserv->map, layerindex), GET_LAYER(mapserv->map, layerindex)->class[classindex], mapserv->map->legend.keysizex, mapserv->map->legend.keysizey, img, 0, 0) != MS_SUCCESS)
+ if(msDrawLegendIcon(mapserv->map, GET_LAYER(mapserv->map, layerindex), GET_LAYER(mapserv->map, layerindex)->class[classindex], mapserv->map->legend.keysizex, mapserv->map->legend.keysizey, img, 0, 0, MS_TRUE) != MS_SUCCESS)
return MS_FAILURE;
if(mapserv->sendheaders) {
View
@@ -2407,10 +2407,10 @@ int processIcon(mapObj *map, int nIdxLayer, int nIdxClass, char** pszInstr, char
if(thisClass == NULL) {
/* Nonexistent class. Create an empty image */
- img = msCreateLegendIcon(map, NULL, NULL, nWidth, nHeight);
+ img = msCreateLegendIcon(map, NULL, NULL, nWidth, nHeight, MS_TRUE);
} else {
img = msCreateLegendIcon(map, GET_LAYER(map, nIdxLayer),
- thisClass, nWidth, nHeight);
+ thisClass, nWidth, nHeight, MS_TRUE);
}
if(!img) {
View
@@ -4611,9 +4611,19 @@ this request. Check wms/ows_enable_request settings.",
nHeight = 20;
}
- img = msCreateLegendIcon(map, GET_LAYER(map, iLayerIndex),
- GET_LAYER(map, iLayerIndex)->class[i],
- nWidth, nHeight);
+ if ( psScale != NULL ) {
+ /* Scale-dependent legend. calculate map->scaledenom */
+ map->cellsize = msAdjustExtent(&(map->extent), map->width, map->height);
+ msCalculateScale(map->extent, map->units, map->width, map->height, map->resolution, &map->scaledenom);
+ img = msCreateLegendIcon(map, GET_LAYER(map, iLayerIndex),
+ GET_LAYER(map, iLayerIndex)->class[i],
+ nWidth, nHeight, MS_FALSE);
+ } else {
+ /* Scale-independent legend */
+ img = msCreateLegendIcon(map, GET_LAYER(map, iLayerIndex),
+ GET_LAYER(map, iLayerIndex)->class[i],
+ nWidth, nHeight, MS_TRUE);
+ }
}
if (img == NULL) {
msSetError(MS_IMGERR,

0 comments on commit 297fa3e

Please sign in to comment.