[mapserver-commits] r10857 - trunk/mapserver
svn at osgeo.org
svn at osgeo.org
Wed Jan 12 17:20:33 EST 2011
Author: assefa
Date: 2011-01-12 14:20:33 -0800 (Wed, 12 Jan 2011)
New Revision: 10857
Modified:
trunk/mapserver/maplegend.c
trunk/mapserver/mapserver.h
trunk/mapserver/mapwms.c
Log:
Generate legendurl for grouped layers #3411
Modified: trunk/mapserver/maplegend.c
===================================================================
--- trunk/mapserver/maplegend.c 2011-01-12 19:53:28 UTC (rev 10856)
+++ trunk/mapserver/maplegend.c 2011-01-12 22:20:33 UTC (rev 10857)
@@ -270,14 +270,16 @@
* MS_SUCCESS
* MS_FAILURE
*/
-int msLegendCalcSize(mapObj *map, int scale_independent, int *size_x, int *size_y, layerObj *psForLayer)
+int msLegendCalcSize(mapObj *map, int scale_independent, int *size_x, int *size_y,
+ int *layer_index, int num_layers)
{
int i, j;
int status, maxwidth=0, nLegendItems=0;
char *transformedText; /* Label text after applying wrapping, encoding if necessary */
layerObj *lp;
rectObj rect;
-
+ int current_layers=0;
+
/* Reset sizes */
*size_x = 0;
*size_y = 0;
@@ -294,14 +296,22 @@
* step through all map classes, and for each one that will be displayed
* calculate the label size
*/
- for(i=0; i<map->numlayers; i++) {
- if(psForLayer) {
- lp = psForLayer;
- i = map->numlayers;
- } else
+
+
+ if (layer_index != NULL && num_layers >0)
+ current_layers = num_layers;
+ else
+ current_layers = map->numlayers;
+
+
+ for(i=0; i< current_layers; i++) {
+
+ if (layer_index != NULL && num_layers > 0)
+ lp = GET_LAYER(map, layer_index[i]);
+ else
lp = (GET_LAYER(map, map->layerorder[i]));
- if((lp->status == MS_OFF && lp != psForLayer) || (lp->type == MS_LAYER_QUERY)) /* skip it */
+ if((lp->status == MS_OFF && (layer_index == NULL || num_layers <= 0)) || (lp->type == MS_LAYER_QUERY)) /* skip it */
continue;
if(!scale_independent && map->scaledenom > 0) {
@@ -401,7 +411,7 @@
return NULL;
}
if(msValidateContexts(map) != MS_SUCCESS) return NULL; /* make sure there are no recursive REQUIRES or LABELREQUIRES expressions */
- if(msLegendCalcSize(map, scale_independent, &size_x, &size_y, NULL) != MS_SUCCESS) return NULL;
+ if(msLegendCalcSize(map, scale_independent, &size_x, &size_y, NULL, 0) != MS_SUCCESS) return NULL;
/*
* step through all map classes, and for each one that will be displayed
Modified: trunk/mapserver/mapserver.h
===================================================================
--- trunk/mapserver/mapserver.h 2011-01-12 19:53:28 UTC (rev 10856)
+++ trunk/mapserver/mapserver.h 2011-01-12 22:20:33 UTC (rev 10857)
@@ -1930,7 +1930,8 @@
MS_DLL_EXPORT void freeImageCache(struct imageCacheObj *ic);
MS_DLL_EXPORT imageObj *msDrawLegend(mapObj *map, int scale_independent); /* in maplegend.c */
-MS_DLL_EXPORT int msLegendCalcSize(mapObj *map, int scale_independent, int *size_x, int *size_y, layerObj *lp);
+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);
Modified: trunk/mapserver/mapwms.c
===================================================================
--- trunk/mapserver/mapwms.c 2011-01-12 19:53:28 UTC (rev 10856)
+++ trunk/mapserver/mapwms.c 2011-01-12 22:20:33 UTC (rev 10857)
@@ -1730,7 +1730,9 @@
if (classnameset)
{
int size_x=0, size_y=0;
- if (msLegendCalcSize(map, 1, &size_x, &size_y, lp) == MS_SUCCESS)
+ int layer_index[1];
+ layer_index[0] = lp->index;
+ if (msLegendCalcSize(map, 1, &size_x, &size_y, layer_index, 1) == MS_SUCCESS)
{
snprintf(width, sizeof(width), "%d", size_x);
snprintf(height, sizeof(height), "%d", size_y);
@@ -2561,6 +2563,86 @@
"MO", "GROUP_ABSTRACT", OWS_NOERR,
" <Abstract>%s</Abstract>\n", lp->group);
+ /*build a getlegendgraphicurl*/
+ if( script_url_encoded)
+ {
+ int num_layers = 0;
+ size_t bufferSize = 0;
+ char width[10], height[10];
+ char *name_encoded = msEncodeHTMLEntities(lp->group);
+ int *group_layers = (int *)msSmallMalloc(sizeof(int)*map->numlayers);
+ char *legendurl = NULL;
+ int size_x=0, size_y=0;
+ char *mimetype = NULL;
+ char **tokens = NULL;
+ int numtokens = 0;
+
+ for(j=i; j<map->numlayers; j++)
+ if (!pabLayerProcessed[j] &&
+ GET_LAYER(map, j)->group &&
+ strcmp(lp->group, GET_LAYER(map, j)->group) == 0 )
+ group_layers[num_layers++] = j;
+ if ( num_layers > 0)
+ {
+ group_layers =(int *)msSmallRealloc(group_layers, sizeof(int)*num_layers);
+
+ if (msLegendCalcSize(map, 1, &size_x, &size_y, group_layers , num_layers) == MS_SUCCESS)
+ {
+ bufferSize = strlen(script_url_encoded)+200;
+ legendurl = (char*)msSmallMalloc(bufferSize);
+ snprintf(width, sizeof(width), "%d", size_x);
+ snprintf(height, sizeof(height), "%d", size_y);
+
+ format_list = msOWSLookupMetadata(&(map->web.metadata), "M",
+ "getlegendgraphic_formatlist");
+ if (format_list && strlen(format_list) > 0)
+ {
+ tokens = msStringSplit(format_list, ',', &numtokens);
+ if (tokens && numtokens > 0)
+ {
+ /*just grab the first mime type*/
+ mimetype = msEncodeHTMLEntities(tokens[0]);
+ msFreeCharArray(tokens, numtokens);
+ }
+ }
+ else
+ mimetype = msEncodeHTMLEntities("image/png; mode=24bit");
+
+ if (nVersion >= OWS_1_3_0)
+
+ snprintf(legendurl, bufferSize, "%sversion=%s&service=WMS&request=GetLegendGraphic&sld_version=1.1.0&layer=%s&format=%s&STYLE=default", script_url_encoded,msOWSGetVersionString(nVersion, szVersionBuf),name_encoded,
+ mimetype);
+ else
+ snprintf(legendurl, bufferSize, "%sversion=%s&service=WMS&request=GetLegendGraphic&layer=%s&format=%s&STYLE=default", script_url_encoded,msOWSGetVersionString(nVersion, szVersionBuf),name_encoded,
+ mimetype);
+ msIO_fprintf(stdout, " <Style>\n");
+ msIO_fprintf(stdout, " <Name>default</Name>\n");
+ msIO_fprintf(stdout, " <Title>default</Title>\n");
+
+ msOWSPrintURLType(stdout, NULL,
+ "O", "ttt",
+ OWS_NOERR, NULL,
+ "LegendURL", NULL,
+ " width=\"%s\"", " height=\"%s\"",
+ ">\n <Format>%s</Format",
+ "\n <OnlineResource "
+ "xmlns:xlink=\"http://www.w3.org/1999/xlink\""
+ " xlink:type=\"simple\" xlink:href=\"%s\"/>\n"
+ " ",
+ MS_FALSE, MS_FALSE, MS_FALSE, MS_FALSE, MS_FALSE,
+ NULL, width, height, mimetype, legendurl, " ");
+
+
+ msIO_fprintf(stdout, " </Style>\n");
+ msFree(legendurl);
+ msFree(mimetype);
+ msFree(name_encoded);
+
+
+
+ }
+ }
+ }
/* Dump all layers for this group */
for(j=i; j<map->numlayers; j++)
{
@@ -3452,7 +3534,7 @@
msSetError(MS_WMSERR, "SLD_VERSION must be 1.1.0", "GetLegendGraphic()");
return msWMSException(map, nVersion, "InvalidParameterValue", wms_exception_format);
}
- /* check if layer name is valid. we cjeck for layer's and group's name*/
+ /* check if layer name is valid. we check for layer's and group's name*/
for (i=0; i<map->numlayers; i++)
{
lp = GET_LAYER(map, i);
More information about the mapserver-commits
mailing list