Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 552 lines (466 sloc) 19.792 kB
6d276a0 @warmerdam Added standardized headers. Added MS_CVSID().
warmerdam authored
1 /******************************************************************************
2 *
3 * Project: MapServer
4 * Purpose: Legend generation.
5 * Author: Steve Lime and the MapServer team.
6 *
7 ******************************************************************************
ec3dabc @dmorissette Updated copyright date to 2005
dmorissette authored
8 * Copyright (c) 1996-2005 Regents of the University of Minnesota.
6d276a0 @warmerdam Added standardized headers. Added MS_CVSID().
warmerdam authored
9 *
10 * Permission is hereby granted, free of charge, to any person obtaining a
11 * copy of this software and associated documentation files (the "Software"),
12 * to deal in the Software without restriction, including without limitation
13 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 * and/or sell copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following conditions:
16 *
17 * The above copyright notice and this permission notice shall be included in
18 * all copies of this Software or works derived from this Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26 * DEALINGS IN THE SOFTWARE.
27 ******************************************************************************
28 *
29 * $Log$
eef3f40 @unicolet RFC24: fix segfaults due to unchecked access to array items (styles, …
authored
30 * Revision 1.66 2007/04/25 11:35:57 umberto
31 * RFC24: fix segfaults due to unchecked access to array items (styles, classes)
32 *
b7b78ab @unicolet RFC24: added styleObj support
authored
33 * Revision 1.65 2007/04/24 08:55:32 umberto
34 * RFC24: added styleObj support
35 *
9d2254e @unicolet RFC24: mapObj, layerObj, initial classObj support
authored
36 * Revision 1.64 2007/04/17 10:36:53 umberto
37 * RFC24: mapObj, layerObj, initial classObj support
38 *
e4431bc First AGG commit.
John Novak authored
39 * Revision 1.63 2007/03/06 11:22:39 novak
40 * First AGG commit.
41 *
42 * Config and Makefile changes are necessary for a proper build.
43 *
3188233 @sdlime Removed cut & paste artifact (oops).
sdlime authored
44 * Revision 1.62 2006/08/04 04:36:12 sdlime
45 * Removed cut & paste artifact (oops).
46 *
a4c0c17 @sdlime Fixed a problem with full-image legends where layer sizeunits were no…
sdlime authored
47 * Revision 1.61 2006/08/04 04:33:45 sdlime
48 * Fixed a problem with full-image legends where layer sizeunits were not taken into account when rendering a legend. (bug 1147)
49 *
2aefdc0 @sdlime Fixed symbol initialization error with embedded scalebars and legends…
sdlime authored
50 * Revision 1.60 2006/03/27 05:48:03 sdlime
51 * Fixed symbol initialization error with embedded scalebars and legends. (bug 1725)
52 *
bf67c6a @sdlime Initial code for curved labels. (bug 1620)
sdlime authored
53 * Revision 1.59 2006/02/18 20:59:13 sdlime
54 * Initial code for curved labels. (bug 1620)
55 *
b02ed4f @sdlime Fixed error with image legends (shifted text) introduced by the 1449 …
sdlime authored
56 * Revision 1.58 2006/01/16 20:21:18 sdlime
57 * Fixed error with image legends (shifted text) introduced by the 1449 bug fix. (bug 1607)
58 *
730640b @sdlime Updated msDrawLegend to respect class min/max scale values. (bug 1524)
sdlime authored
59 * Revision 1.57 2005/11/17 05:56:30 sdlime
60 * Updated msDrawLegend to respect class min/max scale values. (bug 1524)
61 *
20da047 @sdlime Updated msDrawLegend() to consider layer order. (bug 1484)
sdlime authored
62 * Revision 1.56 2005/10/31 06:03:26 sdlime
63 * Updated msDrawLegend() to consider layer order. (bug 1484)
64 *
df9b962 @warmerdam fixed leak of imageObj when embedding legends
warmerdam authored
65 * Revision 1.55 2005/09/14 00:11:35 frank
66 * fixed leak of imageObj when embedding legends
67 *
ec3dabc @dmorissette Updated copyright date to 2005
dmorissette authored
68 * Revision 1.54 2005/06/14 16:03:33 dan
69 * Updated copyright date to 2005
70 *
116fd0c @sgillies turn on GD alpha blending for legend icon images if specified by the …
sgillies authored
71 * Revision 1.53 2005/02/18 18:57:26 sean
72 * turn on GD alpha blending for legend icon images if specified by the target layer (bugs 490, 1250)
73 *
f6e6a66 @dmorissette Turned all C++ (//) comments into C comments (bug 1238)
dmorissette authored
74 * Revision 1.52 2005/02/18 03:06:46 dan
75 * Turned all C++ (//) comments into C comments (bug 1238)
76 *
f91f66c @warmerdam added labelObj arg to msAddLabel()
warmerdam authored
77 * Revision 1.51 2005/01/11 00:24:07 frank
78 * added labelObj arg to msAddLabel()
79 *
d3249df @sdlime Added tests to mimimize the threat of recursion problems when evaluat…
sdlime authored
80 * Revision 1.50 2004/11/22 03:43:54 sdlime
81 * Added tests to mimimize the threat of recursion problems when evaluating LAYER REQUIRES or LABELREQUIRES expressions. Note that via MapScript it is possible to circumvent that test by defining layers with problems after running prepareImage. Other things crop up in that case too (symbol scaling dies) so it should be considered bad programming practice.
82 *
d197570 @warmerdam avoid casting warning i msDrawLegendIcon call
warmerdam authored
83 * Revision 1.49 2004/11/05 19:19:05 frank
84 * avoid casting warning i msDrawLegendIcon call
85 *
24b351a @warmerdam Removed unused variable.
warmerdam authored
86 * Revision 1.48 2004/11/04 21:33:08 frank
87 * Removed unused variable.
88 *
3b5d5e5 @dmorissette Fixed WMS GetLegendGraphic which was returning an exception (GD error)
dmorissette authored
89 * Revision 1.47 2004/10/28 18:16:17 dan
90 * Fixed WMS GetLegendGraphic which was returning an exception (GD error)
91 * when requested layer was out of scale (bug 1006)
92 *
6d276a0 @warmerdam Added standardized headers. Added MS_CVSID().
warmerdam authored
93 * Revision 1.46 2004/10/21 04:30:55 frank
94 * Added standardized headers. Added MS_CVSID().
95 *
96 */
2db58af @dmorissette Fixed crash with call to msClearLayerPenValues() in msCreateLegendIcon()
dmorissette authored
97
abe3c7a @sdlime Initial revision
sdlime authored
98 #include "map.h"
99
6d276a0 @warmerdam Added standardized headers. Added MS_CVSID().
warmerdam authored
100 MS_CVSID("$Id$")
101
abe3c7a @sdlime Initial revision
sdlime authored
102 #define PSF .8
103 #define VMARGIN 5 /* margin at top and bottom of legend graphic */
104 #define HMARGIN 5 /* margin at left and right of legend graphic */
105
cb263c0 @sdlime Initial coding of styleObj addition and removal of paletteObj. Close …
sdlime authored
106 int msDrawLegendIcon(mapObj *map, layerObj *lp, classObj *class, int width, int height, gdImagePtr img, int dstX, int dstY)
ae79e98 Add two functions in maplegend.c
Sacha Fournier authored
107 {
218f753 @sdlime Tweaked code in legend builder to handle polygon layers slightly diff…
sdlime authored
108 int i, type;
cb263c0 @sdlime Initial coding of styleObj addition and removal of paletteObj. Close …
sdlime authored
109 shapeObj box, zigzag;
110 pointObj marker;
8385900 @sdlime KEYIMAGE parameter should be working now.
sdlime authored
111 char szPath[MS_MAXPATHLEN];
112 imageObj *image = NULL;
f782abf @sdlime Restored legend key outlines (triggered by setting OUTLINECOLOR). If …
sdlime authored
113 styleObj outline_style;
8385900 @sdlime KEYIMAGE parameter should be working now.
sdlime authored
114
f6e6a66 @dmorissette Turned all C++ (//) comments into C comments (bug 1238)
dmorissette authored
115 /* if drawing an outline (below) we need to set clipping to keep symbols withing the outline */
f782abf @sdlime Restored legend key outlines (triggered by setting OUTLINECOLOR). If …
sdlime authored
116 if(MS_VALID_COLOR(map->legend.outlinecolor))
117 gdImageSetClip(img, dstX, dstY, dstX + width - 1, dstY + height - 1);
8385900 @sdlime KEYIMAGE parameter should be working now.
sdlime authored
118
f6e6a66 @dmorissette Turned all C++ (//) comments into C comments (bug 1238)
dmorissette authored
119 /* initialize the box used for polygons and for outlines */
cb263c0 @sdlime Initial coding of styleObj addition and removal of paletteObj. Close …
sdlime authored
120 box.line = (lineObj *)malloc(sizeof(lineObj));
121 box.numlines = 1;
122 box.line[0].point = (pointObj *)malloc(sizeof(pointObj)*5);
123 box.line[0].numpoints = 5;
124
125 box.line[0].point[0].x = dstX;
126 box.line[0].point[0].y = dstY;
127 box.line[0].point[1].x = dstX + width - 1;
128 box.line[0].point[1].y = dstY;
129 box.line[0].point[2].x = dstX + width - 1;
130 box.line[0].point[2].y = dstY + height - 1;
131 box.line[0].point[3].x = dstX;
132 box.line[0].point[3].y = dstY + height - 1;
133 box.line[0].point[4].x = box.line[0].point[0].x;
134 box.line[0].point[4].y = box.line[0].point[0].y;
135 box.line[0].numpoints = 5;
f782abf @sdlime Restored legend key outlines (triggered by setting OUTLINECOLOR). If …
sdlime authored
136
f6e6a66 @dmorissette Turned all C++ (//) comments into C comments (bug 1238)
dmorissette authored
137 /* if the class has a keyimage then load it, scale it and we're done */
f782abf @sdlime Restored legend key outlines (triggered by setting OUTLINECOLOR). If …
sdlime authored
138 if(class->keyimage != NULL) {
139 image = msImageLoadGD(msBuildPath(szPath, map->mappath, class->keyimage));
140 if(!image) return(MS_FAILURE);
141
f6e6a66 @dmorissette Turned all C++ (//) comments into C comments (bug 1238)
dmorissette authored
142 /* TO DO: we may want to handle this differently depending on the relative size of the keyimage */
f782abf @sdlime Restored legend key outlines (triggered by setting OUTLINECOLOR). If …
sdlime authored
143 gdImageCopyResampled(img, image->img.gd, dstX, dstY, 0, 0, width, height, image->img.gd->sx, image->img.gd->sy);
144 } else {
f6e6a66 @dmorissette Turned all C++ (//) comments into C comments (bug 1238)
dmorissette authored
145 /* some polygon layers may be better drawn using zigzag if there is no fill */
f782abf @sdlime Restored legend key outlines (triggered by setting OUTLINECOLOR). If …
sdlime authored
146 type = lp->type;
147 if(type == MS_LAYER_POLYGON) {
148 type = MS_LAYER_LINE;
149 for(i=0; i<class->numstyles; i++) {
b7b78ab @unicolet RFC24: added styleObj support
authored
150 if(MS_VALID_COLOR(class->styles[i]->color)) { /* there is a fill */
f782abf @sdlime Restored legend key outlines (triggered by setting OUTLINECOLOR). If …
sdlime authored
151 type = MS_LAYER_POLYGON;
152 break;
153 }
218f753 @sdlime Tweaked code in legend builder to handle polygon layers slightly diff…
sdlime authored
154 }
155 }
156
f782abf @sdlime Restored legend key outlines (triggered by setting OUTLINECOLOR). If …
sdlime authored
157 /*
158 ** now draw the appropriate color/symbol/size combination
116fd0c @sgillies turn on GD alpha blending for legend icon images if specified by the …
sgillies authored
159 */
160
161 /* Bug 490 - switch alpha blending on for a layer that requires it */
162 if (lp->transparency == MS_GD_ALPHA) {
163 gdImageAlphaBlending(img, 1);
164 }
165
f782abf @sdlime Restored legend key outlines (triggered by setting OUTLINECOLOR). If …
sdlime authored
166 switch(type) {
167 case MS_LAYER_ANNOTATION:
168 case MS_LAYER_POINT:
169 marker.x = dstX + MS_NINT(width / 2.0);
170 marker.y = dstY + MS_NINT(height / 2.0);
171
172 for(i=0; i<class->numstyles; i++)
b7b78ab @unicolet RFC24: added styleObj support
authored
173 msDrawMarkerSymbolGD(&map->symbolset, img, &marker, class->styles[i], lp->scalefactor);
f782abf @sdlime Restored legend key outlines (triggered by setting OUTLINECOLOR). If …
sdlime authored
174 break;
175 case MS_LAYER_LINE:
176 zigzag.line = (lineObj *)malloc(sizeof(lineObj));
177 zigzag.numlines = 1;
178 zigzag.line[0].point = (pointObj *)malloc(sizeof(pointObj)*4);
179 zigzag.line[0].numpoints = 4;
180
181 zigzag.line[0].point[0].x = dstX;
182 zigzag.line[0].point[0].y = dstY + height - 1;
183 zigzag.line[0].point[1].x = dstX + MS_NINT(width / 3.0) - 1;
184 zigzag.line[0].point[1].y = dstY;
185 zigzag.line[0].point[2].x = dstX + MS_NINT(2.0 * width / 3.0) - 1;
186 zigzag.line[0].point[2].y = dstY + height - 1;
187 zigzag.line[0].point[3].x = dstX + width - 1;
188 zigzag.line[0].point[3].y = dstY;
189 zigzag.line[0].numpoints = 4;
190
191 for(i=0; i<class->numstyles; i++)
b7b78ab @unicolet RFC24: added styleObj support
authored
192 msDrawLineSymbolGD(&map->symbolset, img, &zigzag, class->styles[i], lp->scalefactor);
f782abf @sdlime Restored legend key outlines (triggered by setting OUTLINECOLOR). If …
sdlime authored
193
194 free(zigzag.line[0].point);
195 free(zigzag.line);
196 break;
197 case MS_LAYER_CIRCLE:
198 case MS_LAYER_RASTER:
199 case MS_LAYER_POLYGON:
200 for(i=0; i<class->numstyles; i++)
b7b78ab @unicolet RFC24: added styleObj support
authored
201 msDrawShadeSymbolGD(&map->symbolset, img, &box, class->styles[i], lp->scalefactor);
f782abf @sdlime Restored legend key outlines (triggered by setting OUTLINECOLOR). If …
sdlime authored
202 break;
203 default:
204 return MS_FAILURE;
205 break;
206 } /* end symbol drawing */
207 }
208
f6e6a66 @dmorissette Turned all C++ (//) comments into C comments (bug 1238)
dmorissette authored
209 /* handle an outline if necessary */
f782abf @sdlime Restored legend key outlines (triggered by setting OUTLINECOLOR). If …
sdlime authored
210 if(MS_VALID_COLOR(map->legend.outlinecolor)) {
211 initStyle(&outline_style);
212 outline_style.color = map->legend.outlinecolor;
213 msDrawLineSymbolGD(&map->symbolset, img, &box, &outline_style, 1.0);
f6e6a66 @dmorissette Turned all C++ (//) comments into C comments (bug 1238)
dmorissette authored
214 gdImageSetClip(img, 0, 0, img->sx - 1, img->sy - 1); /* undo any clipping settings */
f782abf @sdlime Restored legend key outlines (triggered by setting OUTLINECOLOR). If …
sdlime authored
215 }
216
cb263c0 @sdlime Initial coding of styleObj addition and removal of paletteObj. Close …
sdlime authored
217 free(box.line[0].point);
218 free(box.line);
f782abf @sdlime Restored legend key outlines (triggered by setting OUTLINECOLOR). If …
sdlime authored
219
cb263c0 @sdlime Initial coding of styleObj addition and removal of paletteObj. Close …
sdlime authored
220 return MS_SUCCESS;
ae79e98 Add two functions in maplegend.c
Sacha Fournier authored
221 }
222
a33fc56 @dmorissette Make msCreateLegendIcon() return imageObj + properly handle format (b…
dmorissette authored
223 imageObj *msCreateLegendIcon(mapObj* map, layerObj* lp, classObj* class, int width, int height)
ae79e98 Add two functions in maplegend.c
Sacha Fournier authored
224 {
a33fc56 @dmorissette Make msCreateLegendIcon() return imageObj + properly handle format (b…
dmorissette authored
225 imageObj *image;
226 outputFormatObj *format = NULL;
ce887a4 Modify a bit the msCreateLegendIcon to draw all classes if needed.
Assefa Yewondwossen authored
227 int i = 0;
a33fc56 @dmorissette Make msCreateLegendIcon() return imageObj + properly handle format (b…
dmorissette authored
228
e4431bc First AGG commit.
John Novak authored
229 if(!map->outputformat || (!MS_RENDERER_GD(map->outputformat) && !MS_RENDERER_AGG(map->outputformat) )) {
a4c0c17 @sdlime Fixed a problem with full-image legends where layer sizeunits were no…
sdlime authored
230 msSetError(MS_GDERR, "Map outputformat must be set to a GD format!", "msCreateLegendIcon()");
231 return(NULL);
a33fc56 @dmorissette Make msCreateLegendIcon() return imageObj + properly handle format (b…
dmorissette authored
232 }
233
f6e6a66 @dmorissette Turned all C++ (//) comments into C comments (bug 1238)
dmorissette authored
234 /* ensure we have an image format representing the options for the legend */
f8b04e4 @sdlime Fixed bug in legending code. Transparency and interlacing options wer…
sdlime authored
235 msApplyOutputFormat(&format, map->outputformat, map->legend.transparent, map->legend.interlace, MS_NOOVERRIDE);
a33fc56 @dmorissette Make msCreateLegendIcon() return imageObj + properly handle format (b…
dmorissette authored
236
f6e6a66 @dmorissette Turned all C++ (//) comments into C comments (bug 1238)
dmorissette authored
237 /* create image */
f8b04e4 @sdlime Fixed bug in legending code. Transparency and interlacing options wer…
sdlime authored
238 image = msImageCreateGD(width, height, map->outputformat, map->web.imagepath, map->web.imageurl);
cb263c0 @sdlime Initial coding of styleObj addition and removal of paletteObj. Close …
sdlime authored
239
f6e6a66 @dmorissette Turned all C++ (//) comments into C comments (bug 1238)
dmorissette authored
240 /* drop this reference to output format */
f8b04e4 @sdlime Fixed bug in legending code. Transparency and interlacing options wer…
sdlime authored
241 msApplyOutputFormat( &format, NULL, MS_NOOVERRIDE, MS_NOOVERRIDE, MS_NOOVERRIDE );
a33fc56 @dmorissette Make msCreateLegendIcon() return imageObj + properly handle format (b…
dmorissette authored
242
243 if(image == NULL) {
244 msSetError(MS_GDERR, "Unable to initialize image.","msCreateLegendIcon()");
cb263c0 @sdlime Initial coding of styleObj addition and removal of paletteObj. Close …
sdlime authored
245 return(NULL);
246 }
a33fc56 @dmorissette Make msCreateLegendIcon() return imageObj + properly handle format (b…
dmorissette authored
247
f6e6a66 @dmorissette Turned all C++ (//) comments into C comments (bug 1238)
dmorissette authored
248 /* allocate the background color */
a33fc56 @dmorissette Make msCreateLegendIcon() return imageObj + properly handle format (b…
dmorissette authored
249 msImageInitGD( image, &(map->legend.imagecolor));
cb263c0 @sdlime Initial coding of styleObj addition and removal of paletteObj. Close …
sdlime authored
250
f6e6a66 @dmorissette Turned all C++ (//) comments into C comments (bug 1238)
dmorissette authored
251 /* Call drawLegendIcon with destination (0, 0) */
252 /* Return an empty image if lp==NULL || class=NULL */
253 /* (If class is NULL draw the legend for all classes. Modifications done */
254 /* Fev 2004 by AY) */
ce887a4 Modify a bit the msCreateLegendIcon to draw all classes if needed.
Assefa Yewondwossen authored
255 if (lp) {
f6e6a66 @dmorissette Turned all C++ (//) comments into C comments (bug 1238)
dmorissette authored
256 msClearLayerPenValues(lp); /* just in case the mapfile has already been processed */
ce887a4 Modify a bit the msCreateLegendIcon to draw all classes if needed.
Assefa Yewondwossen authored
257 if (class) {
258 msDrawLegendIcon(map, lp, class, width, height, image->img.gd, 0, 0);
a4c0c17 @sdlime Fixed a problem with full-image legends where layer sizeunits were no…
sdlime authored
259 } else {
ce887a4 Modify a bit the msCreateLegendIcon to draw all classes if needed.
Assefa Yewondwossen authored
260 for (i=0; i<lp->numclasses; i++) {
9d2254e @unicolet RFC24: mapObj, layerObj, initial classObj support
authored
261 msDrawLegendIcon(map, lp, lp->class[i], width, height, image->img.gd, 0, 0);
ce887a4 Modify a bit the msCreateLegendIcon to draw all classes if needed.
Assefa Yewondwossen authored
262 }
263 }
2db58af @dmorissette Fixed crash with call to msClearLayerPenValues() in msCreateLegendIcon()
dmorissette authored
264 }
265
a33fc56 @dmorissette Make msCreateLegendIcon() return imageObj + properly handle format (b…
dmorissette authored
266 return image;
ae79e98 Add two functions in maplegend.c
Sacha Fournier authored
267 }
268
abe3c7a @sdlime Initial revision
sdlime authored
269 /*
270 ** Creates a GD image of a legend for a specific map. msDrawLegend()
271 ** respects the current scale, and classes without a name are not
272 ** added to the legend.
3b5d5e5 @dmorissette Fixed WMS GetLegendGraphic which was returning an exception (GD error)
dmorissette authored
273 **
274 ** scale_independent is used for WMS GetLegendGraphic. It should be set to
275 ** MS_FALSE in most cases. If it is set to MS_TRUE then the layers' minscale
276 ** and maxscale are ignored and layers that are currently out of scale still
277 ** show up in the legend.
abe3c7a @sdlime Initial revision
sdlime authored
278 */
3b5d5e5 @dmorissette Fixed WMS GetLegendGraphic which was returning an exception (GD error)
dmorissette authored
279 imageObj *msDrawLegend(mapObj *map, int scale_independent)
abe3c7a @sdlime Initial revision
sdlime authored
280 {
70e076f @sdlime Changed scale computation function to throw errors with bad input dat…
sdlime authored
281 int status;
ae79e98 Add two functions in maplegend.c
Sacha Fournier authored
282
abe3c7a @sdlime Initial revision
sdlime authored
283 gdImagePtr img; /* image data structure */
284 int i,j; /* loop counters */
285 pointObj pnt;
286 int size_x, size_y;
287 layerObj *lp;
288 int maxwidth=0, maxheight=0, n=0;
289 int *heights;
290 rectObj rect;
20da047 @sdlime Updated msDrawLegend() to consider layer order. (bug 1484)
sdlime authored
291 imageObj *image = NULL;
f8b04e4 @sdlime Fixed bug in legending code. Transparency and interlacing options wer…
sdlime authored
292 outputFormatObj *format = NULL;
abe3c7a @sdlime Initial revision
sdlime authored
293
3b5d5e5 @dmorissette Fixed WMS GetLegendGraphic which was returning an exception (GD error)
dmorissette authored
294 if (!scale_independent) {
a4c0c17 @sdlime Fixed a problem with full-image legends where layer sizeunits were no…
sdlime authored
295 map->cellsize = msAdjustExtent(&(map->extent), map->width, map->height);
296 status = msCalculateScale(map->extent, map->units, map->width, map->height, map->resolution, &map->scale);
297 if(status != MS_SUCCESS) return(NULL);
3b5d5e5 @dmorissette Fixed WMS GetLegendGraphic which was returning an exception (GD error)
dmorissette authored
298 }
abe3c7a @sdlime Initial revision
sdlime authored
299
f6e6a66 @dmorissette Turned all C++ (//) comments into C comments (bug 1238)
dmorissette authored
300 if(msValidateContexts(map) != MS_SUCCESS) return NULL; /* make sure there are no recursive REQUIRES or LABELREQUIRES expressions */
d3249df @sdlime Added tests to mimimize the threat of recursion problems when evaluat…
sdlime authored
301
abe3c7a @sdlime Initial revision
sdlime authored
302 /*
303 ** allocate heights array
304 */
305 for(i=0; i<map->numlayers; i++) {
9d2254e @unicolet RFC24: mapObj, layerObj, initial classObj support
authored
306 lp = (GET_LAYER(map, map->layerorder[i]));
20da047 @sdlime Updated msDrawLegend() to consider layer order. (bug 1484)
sdlime authored
307
308 if((lp->status == MS_OFF) || (lp->type == MS_LAYER_QUERY)) /* skip it */
abe3c7a @sdlime Initial revision
sdlime authored
309 continue;
9232bf4 @sdlime Added map file writing. Added variables to hold scaled sizes for font…
sdlime authored
310
20da047 @sdlime Updated msDrawLegend() to consider layer order. (bug 1484)
sdlime authored
311 for(j=0;j<lp->numclasses;j++) {
9d2254e @unicolet RFC24: mapObj, layerObj, initial classObj support
authored
312 if(!lp->class[j]->name) continue; /* skip it */
abe3c7a @sdlime Initial revision
sdlime authored
313 n++;
314 }
315 }
316
317 if((heights = (int *)malloc(sizeof(int)*n)) == NULL) {
318 msSetError(MS_MEMERR, "Error allocating heights array.", "msDrawLegend()");
319 return(NULL);
320 }
321
322 /*
323 ** Calculate the optimal image size for the legend
324 */
325 n=0;
326 for(i=0; i<map->numlayers; i++) { /* Need to find the longest legend label string */
9d2254e @unicolet RFC24: mapObj, layerObj, initial classObj support
authored
327 lp = (GET_LAYER(map, map->layerorder[i]));
20da047 @sdlime Updated msDrawLegend() to consider layer order. (bug 1484)
sdlime authored
328
329 if((lp->status == MS_OFF) || (lp->type == MS_LAYER_QUERY)) /* skip it */
abe3c7a @sdlime Initial revision
sdlime authored
330 continue;
28fb366 @sdlime Added WBMP support for gd-1.8 and higher. Fixed legend bug associated…
sdlime authored
331
20da047 @sdlime Updated msDrawLegend() to consider layer order. (bug 1484)
sdlime authored
332 if(!scale_independent && map->scale > 0) {
a4c0c17 @sdlime Fixed a problem with full-image legends where layer sizeunits were no…
sdlime authored
333 if((lp->maxscale > 0) && (map->scale > lp->maxscale)) continue;
334 if((lp->minscale > 0) && (map->scale <= lp->minscale)) continue;
28fb366 @sdlime Added WBMP support for gd-1.8 and higher. Fixed legend bug associated…
sdlime authored
335 }
336
20da047 @sdlime Updated msDrawLegend() to consider layer order. (bug 1484)
sdlime authored
337 for(j=0;j<lp->numclasses;j++) {
9d2254e @unicolet RFC24: mapObj, layerObj, initial classObj support
authored
338 if(!lp->class[j]->name)
abe3c7a @sdlime Initial revision
sdlime authored
339 continue; /* skip it */
730640b @sdlime Updated msDrawLegend to respect class min/max scale values. (bug 1524)
sdlime authored
340
341 if(!scale_independent && map->scale > 0) { /* verify class scale here */
9d2254e @unicolet RFC24: mapObj, layerObj, initial classObj support
authored
342 if((lp->class[j]->maxscale > 0) && (map->scale > lp->class[j]->maxscale))
730640b @sdlime Updated msDrawLegend to respect class min/max scale values. (bug 1524)
sdlime authored
343 continue;
9d2254e @unicolet RFC24: mapObj, layerObj, initial classObj support
authored
344 if((lp->class[j]->minscale > 0) && (map->scale <= lp->class[j]->minscale))
730640b @sdlime Updated msDrawLegend to respect class min/max scale values. (bug 1524)
sdlime authored
345 continue;
346 }
347
9d2254e @unicolet RFC24: mapObj, layerObj, initial classObj support
authored
348 if(msGetLabelSize(lp->class[j]->name, &map->legend.label, &rect, &(map->fontset), 1.0, MS_FALSE) != 0)
abe3c7a @sdlime Initial revision
sdlime authored
349 return(NULL); /* something bad happened */
b02ed4f @sdlime Fixed error with image legends (shifted text) introduced by the 1449 …
sdlime authored
350
abe3c7a @sdlime Initial revision
sdlime authored
351 maxheight = MS_MAX(maxheight, MS_NINT(rect.maxy - rect.miny));
352 maxwidth = MS_MAX(maxwidth, MS_NINT(rect.maxx - rect.minx));
353 heights[n] = MS_NINT(rect.maxy - rect.miny);
317d5fa @sdlime Changed color macros in map.h to use . notation rather than ->. Makes…
sdlime authored
354
abe3c7a @sdlime Initial revision
sdlime authored
355 n++;
356 }
357 }
f4c6439 @sdlime Ok, now KEYIMAGE works...
sdlime authored
358
abe3c7a @sdlime Initial revision
sdlime authored
359 size_x = (2*HMARGIN)+(maxwidth)+(map->legend.keyspacingx)+(map->legend.keysizex);
360 size_y = (2*VMARGIN) + ((n-1)*map->legend.keyspacingy);
361 for(i=0; i<n; i++) {
362 heights[i] = MS_MAX(heights[i], maxheight);
363 size_y += MS_MAX(heights[i], map->legend.keysizey);
364 }
365
f6e6a66 @dmorissette Turned all C++ (//) comments into C comments (bug 1238)
dmorissette authored
366 /* ensure we have an image format representing the options for the legend. */
f8b04e4 @sdlime Fixed bug in legending code. Transparency and interlacing options wer…
sdlime authored
367 msApplyOutputFormat(&format, map->outputformat, map->legend.transparent, map->legend.interlace, MS_NOOVERRIDE);
368
f6e6a66 @dmorissette Turned all C++ (//) comments into C comments (bug 1238)
dmorissette authored
369 /* initialize the legend image */
f8b04e4 @sdlime Fixed bug in legending code. Transparency and interlacing options wer…
sdlime authored
370 image = msImageCreateGD(size_x, size_y, format, map->web.imagepath, map->web.imageurl);
371
f6e6a66 @dmorissette Turned all C++ (//) comments into C comments (bug 1238)
dmorissette authored
372 /* drop this reference to output format */
f8b04e4 @sdlime Fixed bug in legending code. Transparency and interlacing options wer…
sdlime authored
373 msApplyOutputFormat(&format, NULL, MS_NOOVERRIDE, MS_NOOVERRIDE, MS_NOOVERRIDE);
317d5fa @sdlime Changed color macros in map.h to use . notation rather than ->. Makes…
sdlime authored
374
36e8963 Add imageObj support to be able to output additional formats.
Assefa Yewondwossen authored
375 if (image)
cb263c0 @sdlime Initial coding of styleObj addition and removal of paletteObj. Close …
sdlime authored
376 img = image->img.gd;
377 else {
378 msSetError(MS_GDERR, "Unable to initialize image.", "msDrawLegend()");
abe3c7a @sdlime Initial revision
sdlime authored
379 return(NULL);
380 }
80888aa @warmerdam fix support for backgroundcolor/transparency in RGB{A} images
warmerdam authored
381
382 /* Set background */
cb263c0 @sdlime Initial coding of styleObj addition and removal of paletteObj. Close …
sdlime authored
383 if(image != NULL)
384 msImageInitGD(image, &(map->legend.imagecolor));
abe3c7a @sdlime Initial revision
sdlime authored
385
f6e6a66 @dmorissette Turned all C++ (//) comments into C comments (bug 1238)
dmorissette authored
386 msClearPenValues(map); /* just in case the mapfile has already been processed */
19dbf0d @sdlime Changed legend builder to clear any colorObj pen values. Need to do t…
sdlime authored
387
abe3c7a @sdlime Initial revision
sdlime authored
388 pnt.y = VMARGIN;
389
7db71e3 @sdlime Inverted legend layer ordering.
sdlime authored
390 /* for(i=0; i<map->numlayers; i++) { */
391 for(i=map->numlayers-1; i>=0; i--) {
9d2254e @unicolet RFC24: mapObj, layerObj, initial classObj support
authored
392 lp = (GET_LAYER(map, map->layerorder[i])); /* for brevity */
abe3c7a @sdlime Initial revision
sdlime authored
393
4f12a00 @sdlime Expanded layer and shape type enumerations. Switched shape parameter …
sdlime authored
394 if((lp->numclasses == 0) || (lp->status == MS_OFF) || (lp->type == MS_LAYER_QUERY))
abe3c7a @sdlime Initial revision
sdlime authored
395 continue; /* skip this layer */
396
3b5d5e5 @dmorissette Fixed WMS GetLegendGraphic which was returning an exception (GD error)
dmorissette authored
397 if(!scale_independent && map->scale > 0) {
9232bf4 @sdlime Added map file writing. Added variables to hold scaled sizes for font…
sdlime authored
398 if((lp->maxscale > 0) && (map->scale > lp->maxscale))
399 continue;
400 if((lp->minscale > 0) && (map->scale <= lp->minscale))
401 continue;
a4c0c17 @sdlime Fixed a problem with full-image legends where layer sizeunits were no…
sdlime authored
402
403 /* Should we also consider lp->symbolscale? I don't think so. Showing the "standard" size makes the most sense. */
404 if(lp->sizeunits != MS_PIXELS)
405 lp->scalefactor = (msInchesPerUnit(lp->sizeunits,0)/msInchesPerUnit(map->units,0)) / map->cellsize;
9232bf4 @sdlime Added map file writing. Added variables to hold scaled sizes for font…
sdlime authored
406 }
407
abe3c7a @sdlime Initial revision
sdlime authored
408 for(j=0; j<lp->numclasses; j++) { /* always at least 1 class */
409
9d2254e @unicolet RFC24: mapObj, layerObj, initial classObj support
authored
410 if(!lp->class[j]->name) continue; /* skip it */
730640b @sdlime Updated msDrawLegend to respect class min/max scale values. (bug 1524)
sdlime authored
411
412 if(!scale_independent && map->scale > 0) { /* verify class scale here */
9d2254e @unicolet RFC24: mapObj, layerObj, initial classObj support
authored
413 if((lp->class[j]->maxscale > 0) && (map->scale > lp->class[j]->maxscale))
730640b @sdlime Updated msDrawLegend to respect class min/max scale values. (bug 1524)
sdlime authored
414 continue;
9d2254e @unicolet RFC24: mapObj, layerObj, initial classObj support
authored
415 if((lp->class[j]->minscale > 0) && (map->scale <= lp->class[j]->minscale))
730640b @sdlime Updated msDrawLegend to respect class min/max scale values. (bug 1524)
sdlime authored
416 continue;
417 }
418
abe3c7a @sdlime Initial revision
sdlime authored
419 pnt.x = HMARGIN + map->legend.keysizex + map->legend.keyspacingx;
ae79e98 Add two functions in maplegend.c
Sacha Fournier authored
420
f6e6a66 @dmorissette Turned all C++ (//) comments into C comments (bug 1238)
dmorissette authored
421 /* TODO */
9d2254e @unicolet RFC24: mapObj, layerObj, initial classObj support
authored
422 if(msDrawLegendIcon(map, lp, lp->class[j], map->legend.keysizex, map->legend.keysizey, image->img.gd, HMARGIN, (int) pnt.y) != MS_SUCCESS)
a4c0c17 @sdlime Fixed a problem with full-image legends where layer sizeunits were no…
sdlime authored
423 return NULL;
abe3c7a @sdlime Initial revision
sdlime authored
424
425 pnt.y += MS_MAX(map->legend.keysizey, maxheight);
f6e6a66 @dmorissette Turned all C++ (//) comments into C comments (bug 1238)
dmorissette authored
426 /* TODO */
9d2254e @unicolet RFC24: mapObj, layerObj, initial classObj support
authored
427 msDrawLabel(image, pnt, lp->class[j]->name, &(map->legend.label), &map->fontset, 1.0);
abe3c7a @sdlime Initial revision
sdlime authored
428
429 pnt.y += map->legend.keyspacingy; /* bump y for next label */
430
f6e6a66 @dmorissette Turned all C++ (//) comments into C comments (bug 1238)
dmorissette authored
431 } /* next label */
432 } /* next layer */
abe3c7a @sdlime Initial revision
sdlime authored
433
434 free(heights);
36e8963 Add imageObj support to be able to output additional formats.
Assefa Yewondwossen authored
435 return(image);
abe3c7a @sdlime Initial revision
sdlime authored
436 }
437
f6e6a66 @dmorissette Turned all C++ (//) comments into C comments (bug 1238)
dmorissette authored
438 /* TODO */
abe3c7a @sdlime Initial revision
sdlime authored
439 int msEmbedLegend(mapObj *map, gdImagePtr img)
440 {
441 int s,l;
442 pointObj point;
36e8963 Add imageObj support to be able to output additional formats.
Assefa Yewondwossen authored
443 imageObj *image = NULL;
abe3c7a @sdlime Initial revision
sdlime authored
444
1ea96c6 @dmorissette Added try_addimage_if_notfound to msGetSymbolIndex() (bug 612)
dmorissette authored
445 s = msGetSymbolIndex(&(map->symbolset), "legend", MS_FALSE);
abe3c7a @sdlime Initial revision
sdlime authored
446 if(s == -1) {
3de732e @sdlime Stacked symbol support partially enabled. Symbol caching partially en…
sdlime authored
447 s = map->symbolset.numsymbols;
448 map->symbolset.numsymbols++;
6b33c18 @sdlime Fixed a symbol allocation error with embeded scalebars and legends.
sdlime authored
449 initSymbol(&(map->symbolset.symbol[s]));
abe3c7a @sdlime Initial revision
sdlime authored
450 } else {
3de732e @sdlime Stacked symbol support partially enabled. Symbol caching partially en…
sdlime authored
451 if(map->symbolset.symbol[s].img)
452 gdImageDestroy(map->symbolset.symbol[s].img);
abe3c7a @sdlime Initial revision
sdlime authored
453 }
36e8963 Add imageObj support to be able to output additional formats.
Assefa Yewondwossen authored
454
df9b962 @warmerdam fixed leak of imageObj when embedding legends
warmerdam authored
455 /* render the legend. */
3b5d5e5 @dmorissette Fixed WMS GetLegendGraphic which was returning an exception (GD error)
dmorissette authored
456 image = msDrawLegend(map, MS_FALSE);
df9b962 @warmerdam fixed leak of imageObj when embedding legends
warmerdam authored
457
458 /* steal the gdImage and free the rest of the imageObj */
459 map->symbolset.symbol[s].img = image->img.gd;
460 image->img.gd = NULL;
461 msFreeImage( image );
462
463
f6e6a66 @dmorissette Turned all C++ (//) comments into C comments (bug 1238)
dmorissette authored
464 if(!map->symbolset.symbol[s].img) return(-1); /* something went wrong creating scalebar */
abe3c7a @sdlime Initial revision
sdlime authored
465
f6e6a66 @dmorissette Turned all C++ (//) comments into C comments (bug 1238)
dmorissette authored
466 map->symbolset.symbol[s].type = MS_SYMBOL_PIXMAP; /* intialize a few things */
3de732e @sdlime Stacked symbol support partially enabled. Symbol caching partially en…
sdlime authored
467 map->symbolset.symbol[s].name = strdup("legend");
2aefdc0 @sdlime Fixed symbol initialization error with embedded scalebars and legends…
sdlime authored
468 map->symbolset.symbol[s].sizex = map->symbolset.symbol[s].img->sx;
469 map->symbolset.symbol[s].sizey = map->symbolset.symbol[s].img->sy;
abe3c7a @sdlime Initial revision
sdlime authored
470
f6e6a66 @dmorissette Turned all C++ (//) comments into C comments (bug 1238)
dmorissette authored
471 /* I'm not too sure this test is sufficient ... NFW. */
f8fa225 @warmerdam OUTPUTFORMAT support added
warmerdam authored
472 if(map->legend.transparent == MS_ON)
3de732e @sdlime Stacked symbol support partially enabled. Symbol caching partially en…
sdlime authored
473 gdImageColorTransparent(map->symbolset.symbol[s].img, 0);
abe3c7a @sdlime Initial revision
sdlime authored
474
475 switch(map->legend.position) {
476 case(MS_LL):
3de732e @sdlime Stacked symbol support partially enabled. Symbol caching partially en…
sdlime authored
477 point.x = MS_NINT(map->symbolset.symbol[s].img->sx/2.0);
478 point.y = map->height - MS_NINT(map->symbolset.symbol[s].img->sy/2.0);
abe3c7a @sdlime Initial revision
sdlime authored
479 break;
480 case(MS_LR):
3de732e @sdlime Stacked symbol support partially enabled. Symbol caching partially en…
sdlime authored
481 point.x = map->width - MS_NINT(map->symbolset.symbol[s].img->sx/2.0);
482 point.y = map->height - MS_NINT(map->symbolset.symbol[s].img->sy/2.0);
abe3c7a @sdlime Initial revision
sdlime authored
483 break;
484 case(MS_LC):
485 point.x = MS_NINT(map->width/2.0);
3de732e @sdlime Stacked symbol support partially enabled. Symbol caching partially en…
sdlime authored
486 point.y = map->height - MS_NINT(map->symbolset.symbol[s].img->sy/2.0);
abe3c7a @sdlime Initial revision
sdlime authored
487 break;
488 case(MS_UR):
3de732e @sdlime Stacked symbol support partially enabled. Symbol caching partially en…
sdlime authored
489 point.x = map->width - MS_NINT(map->symbolset.symbol[s].img->sx/2.0);
490 point.y = MS_NINT(map->symbolset.symbol[s].img->sy/2.0);
abe3c7a @sdlime Initial revision
sdlime authored
491 break;
492 case(MS_UL):
3de732e @sdlime Stacked symbol support partially enabled. Symbol caching partially en…
sdlime authored
493 point.x = MS_NINT(map->symbolset.symbol[s].img->sx/2.0);
494 point.y = MS_NINT(map->symbolset.symbol[s].img->sy/2.0);
abe3c7a @sdlime Initial revision
sdlime authored
495 break;
496 case(MS_UC):
497 point.x = MS_NINT(map->width/2.0);
3de732e @sdlime Stacked symbol support partially enabled. Symbol caching partially en…
sdlime authored
498 point.y = MS_NINT(map->symbolset.symbol[s].img->sy/2.0);
abe3c7a @sdlime Initial revision
sdlime authored
499 break;
500 }
501
a2c8f2d @sdlime Changed layer names for embedded scalebar/legend to start with __embe…
sdlime authored
502 l = msGetLayerIndex(map, "__embed__legend");
abe3c7a @sdlime Initial revision
sdlime authored
503 if(l == -1) {
504 l = map->numlayers;
505 map->numlayers++;
eef3f40 @unicolet RFC24: fix segfaults due to unchecked access to array items (styles, …
authored
506 GET_LAYER(map, l)=(layerObj*)malloc(sizeof(layerObj));
507 if (GET_LAYER(map, l)==NULL) {
508 msSetError(MS_MISCERR, "Failed to init new layerObj",
509 "msEmbedLegend()");
510 return(MS_FAILURE);
511 }
9d2254e @unicolet RFC24: mapObj, layerObj, initial classObj support
authored
512 if(initLayer((GET_LAYER(map, l)), map) == -1) return(-1);
513 GET_LAYER(map, l)->name = strdup("__embed__legend");
514 GET_LAYER(map, l)->type = MS_LAYER_ANNOTATION;
abe3c7a @sdlime Initial revision
sdlime authored
515
eef3f40 @unicolet RFC24: fix segfaults due to unchecked access to array items (styles, …
authored
516 GET_LAYER(map, l)->class[0]=(classObj*)malloc(sizeof(classObj));
517 if (GET_LAYER(map, l)->class[0]==NULL) {
518 msSetError(MS_MISCERR, "Failed to init new classObj",
519 "msEmbedLegend()");
520 return(MS_FAILURE);
521 }
9d2254e @unicolet RFC24: mapObj, layerObj, initial classObj support
authored
522 if(initClass(GET_LAYER(map, l)->class[0]) == -1) return(-1);
523 GET_LAYER(map, l)->numclasses = 1; /* so we make sure to free it */
55872ca @sdlime Fixed bug 720, but this time for embedded legends. Memory leak with e…
sdlime authored
524
f6e6a66 @dmorissette Turned all C++ (//) comments into C comments (bug 1238)
dmorissette authored
525 /* update the layer order list with the layer's index. */
8e4392c Remove #ifdef USE_PRIOLIST. Change name from panPriolist to layerorder.
Assefa Yewondwossen authored
526 map->layerorder[l] = l;
abe3c7a @sdlime Initial revision
sdlime authored
527 }
528
9d2254e @unicolet RFC24: mapObj, layerObj, initial classObj support
authored
529 GET_LAYER(map, l)->status = MS_ON;
655ca16 @dmorissette Set embedded legend and scalebar layer status to MS_DELETE to avoid i…
dmorissette authored
530
eef3f40 @unicolet RFC24: fix segfaults due to unchecked access to array items (styles, …
authored
531 if (msMaybeAllocateStyle(GET_LAYER(map, l)->class[0], 0)==MS_FAILURE) return MS_FAILURE;
9d2254e @unicolet RFC24: mapObj, layerObj, initial classObj support
authored
532 GET_LAYER(map, l)->class[0]->numstyles = 1;
b7b78ab @unicolet RFC24: added styleObj support
authored
533 GET_LAYER(map, l)->class[0]->styles[0]->symbol = s;
534 GET_LAYER(map, l)->class[0]->styles[0]->color.pen = -1;
9d2254e @unicolet RFC24: mapObj, layerObj, initial classObj support
authored
535 GET_LAYER(map, l)->class[0]->label.force = MS_TRUE;
536 GET_LAYER(map, l)->class[0]->label.size = MS_MEDIUM; /* must set a size to have a valid label definition */
abe3c7a @sdlime Initial revision
sdlime authored
537
f6e6a66 @dmorissette Turned all C++ (//) comments into C comments (bug 1238)
dmorissette authored
538 if(map->legend.postlabelcache) /* add it directly to the image */
b7b78ab @unicolet RFC24: added styleObj support
authored
539 msDrawMarkerSymbolGD(&map->symbolset, img, &point, GET_LAYER(map, l)->class[0]->styles[0], 1.0);
abe3c7a @sdlime Initial revision
sdlime authored
540 else
bf67c6a @sdlime Initial code for curved labels. (bug 1620)
sdlime authored
541 msAddLabel(map, l, 0, -1, -1, &point, NULL, " ", 1.0, NULL);
abe3c7a @sdlime Initial revision
sdlime authored
542
f6e6a66 @dmorissette Turned all C++ (//) comments into C comments (bug 1238)
dmorissette authored
543 /* Mark layer as deleted so that it doesn't interfere with html legends or */
544 /* with saving maps */
9d2254e @unicolet RFC24: mapObj, layerObj, initial classObj support
authored
545 GET_LAYER(map, l)->status = MS_DELETE;
655ca16 @dmorissette Set embedded legend and scalebar layer status to MS_DELETE to avoid i…
dmorissette authored
546
abe3c7a @sdlime Initial revision
sdlime authored
547 return(0);
548 }
ae79e98 Add two functions in maplegend.c
Sacha Fournier authored
549
550
551
Something went wrong with that request. Please try again.