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

Function msEmbedScalebar

mapscale.c:342–454  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

340}
341
342int msEmbedScalebar(mapObj *map, imageObj *img)
343{
344 int l,index;
345 pointObj point;
346 imageObj *image = NULL;
347 rendererVTableObj *renderer = MS_MAP_RENDERER(map);
348 symbolObj *embededSymbol;
349
350 if( ! renderer ) {
351 msSetError(MS_MISCERR,"unsupported outputformat","msEmbedScalebar()");
352 return MS_FAILURE;
353 }
354 index = msGetSymbolIndex(&(map->symbolset), "scalebar", MS_FALSE);
355 if(index != -1)
356 msRemoveSymbol(&(map->symbolset), index); /* remove cached symbol in case the function is called multiple
357 times with different zoom levels */
358
359 if((embededSymbol=msGrowSymbolSet(&map->symbolset)) == NULL)
360 return MS_FAILURE;
361 map->symbolset.numsymbols++;
362
363 image = msDrawScalebar(map);
364 if(!image) {
365 msSetError(MS_RENDERERERR,"failed to create scalebar image","msEmbedScalebar()");
366 return MS_FAILURE;
367 }
368 embededSymbol->pixmap_buffer = calloc(1,sizeof(rasterBufferObj));
369 MS_CHECK_ALLOC(embededSymbol->pixmap_buffer, sizeof(rasterBufferObj), MS_FAILURE);
370
371 if(MS_SUCCESS != renderer->getRasterBufferCopy(image,embededSymbol->pixmap_buffer)) {
372 return MS_FAILURE;
373 }
374
375 embededSymbol->type = MS_SYMBOL_PIXMAP; /* intialize a few things */
376 embededSymbol->name = msStrdup("scalebar");
377 embededSymbol->sizex = embededSymbol->pixmap_buffer->width;
378 embededSymbol->sizey = embededSymbol->pixmap_buffer->height;
379 if(map->scalebar.transparent) {
380 embededSymbol->transparent = MS_TRUE;
381 embededSymbol->transparentcolor = 0;
382 }
383
384 switch(map->scalebar.position) {
385 case(MS_LL):
386 point.x = MS_NINT(embededSymbol->pixmap_buffer->width/2.0);
387 point.y = map->height - MS_NINT(embededSymbol->pixmap_buffer->height/2.0);
388 break;
389 case(MS_LR):
390 point.x = map->width - MS_NINT(embededSymbol->pixmap_buffer->width/2.0);
391 point.y = map->height - MS_NINT(embededSymbol->pixmap_buffer->height/2.0);
392 break;
393 case(MS_LC):
394 point.x = MS_NINT(map->width/2.0);
395 point.y = map->height - MS_NINT(embededSymbol->pixmap_buffer->height/2.0);
396 break;
397 case(MS_UR):
398 point.x = map->width - MS_NINT(embededSymbol->pixmap_buffer->width/2.0);
399 point.y = MS_NINT(embededSymbol->pixmap_buffer->height/2.0);

Callers 2

msDrawMapFunction · 0.85
mapObj_embedScalebarFunction · 0.85

Calls 15

msSetErrorFunction · 0.85
msGetSymbolIndexFunction · 0.85
msRemoveSymbolFunction · 0.85
msGrowSymbolSetFunction · 0.85
msDrawScalebarFunction · 0.85
msStrdupFunction · 0.85
MS_NINTFunction · 0.85
msGetLayerIndexFunction · 0.85
msGrowMapLayersFunction · 0.85
initLayerFunction · 0.85
msGrowLayerClassesFunction · 0.85
initClassFunction · 0.85

Tested by

no test coverage detected