MCPcopy Index your code
hub / github.com/MapServer/MapServer / msDrawScalebar

Function msDrawScalebar

mapscale.c:152–340  ·  view source on GitHub ↗

TODO : the will be msDrawScalebarGD */

Source from the content-addressed store, hash-verified

150
151/* TODO : the will be msDrawScalebarGD */
152imageObj *msDrawScalebar(mapObj *map)
153{
154 int status;
155 char label[32];
156 double i, msx;
157 int j;
158 int isx, sx, sy, ox, oy, state, dsx;
159 pointObj p;
160 rectObj r;
161 imageObj *image = NULL;
162 double fontWidth, fontHeight;
163 outputFormatObj *format = NULL;
164 strokeStyleObj strokeStyle;
165 shapeObj shape;
166 lineObj line;
167 pointObj points[5];
168 rendererVTableObj *renderer;
169
170 strokeStyle.patternlength=0;
171
172 if(map->units == -1) {
173 msSetError(MS_MISCERR, "Map units not set.", "msDrawScalebar()");
174 return(NULL);
175 }
176
177 renderer = MS_MAP_RENDERER(map);
178 if(!renderer || !MS_MAP_RENDERER(map)->supports_pixel_buffer) {
179 msSetError(MS_MISCERR, "Outputformat not supported for scalebar", "msDrawScalebar()");
180 return(NULL);
181 }
182
183/*
184 * A string containing the ten decimal digits is rendered to compute an average cell size
185 * for each number, which is used later to place labels on the scalebar.
186 */
187
188 if(msGetLabelSize(map,&map->scalebar.label,"0123456789",map->scalebar.label.size,&r,NULL) != MS_SUCCESS) {
189 return NULL;
190 }
191 fontWidth = (r.maxx-r.minx)/10.0;
192 fontHeight = r.maxy -r.miny;
193
194 map->cellsize = msAdjustExtent(&(map->extent), map->width, map->height);
195 status = msCalculateScale(map->extent, map->units, map->width, map->height, map->resolution, &map->scaledenom);
196 if(status != MS_SUCCESS)
197 {
198 return(NULL);
199 }
200 dsx = map->scalebar.width - 2*HMARGIN;
201 do {
202 msx = (map->cellsize * dsx)/(msInchesPerUnit(map->scalebar.units,0)/msInchesPerUnit(map->units,0));
203 i = roundInterval(msx/map->scalebar.intervals);
204 snprintf(label, sizeof(label), "%g", map->scalebar.intervals*i); /* last label */
205 isx = MS_NINT((i/(msInchesPerUnit(map->units,0)/msInchesPerUnit(map->scalebar.units,0)))/map->cellsize);
206 sx = (map->scalebar.intervals*isx) + MS_NINT((1.5 + strlen(label)/2.0 + strlen(unitText[map->scalebar.units]))*fontWidth);
207
208 if(sx <= (map->scalebar.width - 2*HMARGIN)) break; /* it will fit */
209

Callers 5

msEmbedScalebarFunction · 0.85
mainFunction · 0.85
msGenerateImagesFunction · 0.85
mainFunction · 0.85
mapObj_drawScalebarFunction · 0.85

Calls 12

msSetErrorFunction · 0.85
msGetLabelSizeFunction · 0.85
msAdjustExtentFunction · 0.85
msCalculateScaleFunction · 0.85
msInchesPerUnitFunction · 0.85
roundIntervalFunction · 0.85
MS_NINTFunction · 0.85
msApplyOutputFormatFunction · 0.85
msImageCreateFunction · 0.85
msDrawLabelFunction · 0.85
renderLineMethod · 0.80
renderPolygonMethod · 0.45

Tested by

no test coverage detected