int msInsertClass(layerObj *layer, classObj *classobj, int nIndex) { int i; if (!classobj) { msSetError(MS_CHILDERR, "Cannot insert NULL class", "msInsertClass()"); return -1; } /* Ensure there is room for a new class */ if (msGrowLayerClasses(layer) == NULL) { return -1; } /* Catch attempt to insert past end of styles array */ else if (nIndex >= layer->numclasses) { msSetError(MS_CHILDERR, "Cannot insert class beyond index %d", "msInsertClass()", layer->numclasses-1); return -1; } else if (nIndex < 0) { /* Insert at the end by default */ #ifndef __cplusplus layer->class[layer->numclasses]=classobj; #else layer->_class[layer->numclasses]=classobj; #endif /* set parent pointer */ classobj->layer=layer; MS_REFCNT_INCR(classobj); layer->numclasses++; return layer->numclasses-1; }
/* eventually add a class to the layer to get the diameter from an attribute */ int pieLayerProcessDynamicDiameter(layerObj *layer) { const char *chartRangeProcessingKey=NULL; char *attrib; float mindiameter=-1, maxdiameter, minvalue, maxvalue; classObj *newclass; styleObj *newstyle; const char *chartSizeProcessingKey=msLayerGetProcessingKey( layer,"CHART_SIZE" ); if(chartSizeProcessingKey != NULL) return MS_FALSE; chartRangeProcessingKey=msLayerGetProcessingKey( layer,"CHART_SIZE_RANGE" ); if(chartRangeProcessingKey==NULL) return MS_FALSE; attrib = msSmallMalloc(strlen(chartRangeProcessingKey)+1); switch(sscanf(chartRangeProcessingKey,"%s %f %f %f %f",attrib, &mindiameter,&maxdiameter,&minvalue,&maxvalue)) { case 1: /*we only have the attribute*/ case 5: /*we have the attribute and the four range values*/ break; default: free(attrib); msSetError(MS_MISCERR, "Chart Layer format error for processing key \"CHART_RANGE\"", "msDrawChartLayer()"); return MS_FAILURE; } /*create a new class in the layer containing the wanted attribute * as the SIZE of its first STYLE*/ newclass=msGrowLayerClasses(layer); if(newclass==NULL) { free(attrib); return MS_FAILURE; } initClass(newclass); layer->numclasses++; /*create and attach a new styleObj to our temp class * and bind the wanted attribute to its SIZE */ newstyle=msGrowClassStyles(newclass); if(newstyle==NULL) { free(attrib); return MS_FAILURE; } initStyle(newstyle); newclass->numstyles++; newclass->name=(char*)msStrdup("__MS_SIZE_ATTRIBUTE_"); newstyle->bindings[MS_STYLE_BINDING_SIZE].item=msStrdup(attrib); newstyle->numbindings++; free(attrib); return MS_TRUE; }
int msEmbedScalebar(mapObj *map, imageObj *img) { int l,index,s; pointObj point; imageObj *image = NULL; rendererVTableObj *renderer = MS_MAP_RENDERER(map); symbolObj *embededSymbol; if( ! renderer ) { msSetError(MS_MISCERR,"unsupported outputformat","msEmbedScalebar()"); return MS_FAILURE; } index = msGetSymbolIndex(&(map->symbolset), "scalebar", MS_FALSE); if(index != -1) msRemoveSymbol(&(map->symbolset), index); /* remove cached symbol in case the function is called multiple times with different zoom levels */ if((embededSymbol=msGrowSymbolSet(&map->symbolset)) == NULL) return MS_FAILURE; s = map->symbolset.numsymbols; map->symbolset.numsymbols++; image = msDrawScalebar(map); if(!image) { return MS_FAILURE; } embededSymbol->pixmap_buffer = calloc(1,sizeof(rasterBufferObj)); MS_CHECK_ALLOC(embededSymbol->pixmap_buffer, sizeof(rasterBufferObj), MS_FAILURE); if(MS_SUCCESS != renderer->getRasterBufferCopy(image,embededSymbol->pixmap_buffer)) { return MS_FAILURE; } embededSymbol->type = MS_SYMBOL_PIXMAP; /* intialize a few things */ embededSymbol->name = msStrdup("scalebar"); embededSymbol->sizex = embededSymbol->pixmap_buffer->width; embededSymbol->sizey = embededSymbol->pixmap_buffer->height; if(map->scalebar.transparent) { embededSymbol->transparent = MS_TRUE; embededSymbol->transparentcolor = 0; } switch(map->scalebar.position) { case(MS_LL): point.x = MS_NINT(embededSymbol->pixmap_buffer->width/2.0); point.y = map->height - MS_NINT(embededSymbol->pixmap_buffer->height/2.0); break; case(MS_LR): point.x = map->width - MS_NINT(embededSymbol->pixmap_buffer->width/2.0); point.y = map->height - MS_NINT(embededSymbol->pixmap_buffer->height/2.0); break; case(MS_LC): point.x = MS_NINT(map->width/2.0); point.y = map->height - MS_NINT(embededSymbol->pixmap_buffer->height/2.0); break; case(MS_UR): point.x = map->width - MS_NINT(embededSymbol->pixmap_buffer->width/2.0); point.y = MS_NINT(embededSymbol->pixmap_buffer->height/2.0); break; case(MS_UL): point.x = MS_NINT(embededSymbol->pixmap_buffer->width/2.0); point.y = MS_NINT(embededSymbol->pixmap_buffer->height/2.0); break; case(MS_UC): point.x = MS_NINT(map->width/2.0); point.y = MS_NINT(embededSymbol->pixmap_buffer->height/2.0); break; } l = msGetLayerIndex(map, "__embed__scalebar"); if(l == -1) { if (msGrowMapLayers(map) == NULL) return(-1); l = map->numlayers; map->numlayers++; if(initLayer((GET_LAYER(map, l)), map) == -1) return(-1); GET_LAYER(map, l)->name = msStrdup("__embed__scalebar"); GET_LAYER(map, l)->type = MS_LAYER_POINT; if (msGrowLayerClasses( GET_LAYER(map, l) ) == NULL) return(-1); if(initClass(GET_LAYER(map, l)->class[0]) == -1) return(-1); GET_LAYER(map, l)->numclasses = 1; /* so we make sure to free it */ /* update the layer order list with the layer's index. */ map->layerorder[l] = l; } GET_LAYER(map, l)->status = MS_ON; if(map->scalebar.postlabelcache) { /* add it directly to the image */ if(msMaybeAllocateClassStyle(GET_LAYER(map, l)->class[0], 0)==MS_FAILURE) return MS_FAILURE; GET_LAYER(map, l)->class[0]->styles[0]->symbol = s; msDrawMarkerSymbol(&map->symbolset, img, &point, GET_LAYER(map, l)->class[0]->styles[0], 1.0); } else { if(!GET_LAYER(map, l)->class[0]->labels) {