From 9232bf4ab055423c076de581cba3a3907fb59b6d Mon Sep 17 00:00:00 2001 From: Steve Lime Date: Thu, 22 Jun 2000 13:13:43 +0000 Subject: [PATCH] Added map file writing. Added variables to hold scaled sizes for fonts and symbols leaving the original values untouched. Killed msApplyScale() function. git-svn-id: http://svn.osgeo.org/mapserver/trunk@66 7532c77e-422f-0410-93f4-f0b67bdd69e2 --- map.h | 8 +- mapfile.c | 433 +++++++++++++++++++++++++++++++++--------- maplabel.c | 18 +- maplegend.c | 16 +- mapquery.c | 28 +++ mapscript/mapscript.i | 15 +- mapsde.c | 31 +++ mapserv.c | 9 +- mapsymbol.c | 20 +- maputil.c | 337 ++++++++++++++++---------------- 10 files changed, 616 insertions(+), 299 deletions(-) diff --git a/map.h b/map.h index 6b98dc3706..b2930aeaaa 100644 --- a/map.h +++ b/map.h @@ -255,7 +255,9 @@ typedef struct { int shadowsizex, shadowsizey; int size; + int sizescaled; int minsize, maxsize; + int position; int offsetx, offsety; @@ -299,8 +301,11 @@ typedef struct { int outlinecolor; int symbol; char *symbolname; + int size; + int sizescaled; int minsize, maxsize; + labelObj label; char *name; /* used for legend labeling */ #ifndef SWIG @@ -439,7 +444,6 @@ typedef struct { int offsite; /* offsite value for raster images */ - int annotate; /* can this layer be annotated */ int transform; /* does this layer have to be transformed to file coordinates */ int labelcache; /* on or off */ @@ -495,8 +499,6 @@ typedef struct { /* structure for a map */ enum MS_UNITS units; /* units of the projection */ double scale; /* scale of the output image */ - int scaled; // has this map had a scaling applied - char *shapepath; /* where are the shape files located */ char *tile; /* an optional tile name to use as well */ diff --git a/mapfile.c b/mapfile.c index 41bdc6e70f..407f404a59 100644 --- a/mapfile.c +++ b/mapfile.c @@ -18,15 +18,15 @@ extern char *msyystring; ** Must be kept in sync with enumerations and defines found in map.h. */ static char *msUnits[7]={"INCHES", "FEET", "MILES", "METERS", "KILOMETERS", "DD", "PIXELS"}; -static char *msFeatureTypes[6]={"POINT", "LINE", "POLYGON", "POLYLINE", "RASTER", "ANNOTATION"}; -static char *msFontTypes[2]={"TRUETYPE", "BITMAP"}; +static char *msLayerTypes[6]={"POINT", "LINE", "POLYGON", "POLYLINE", "RASTER", "ANNOTATION"}; static char *msLabelPositions[10]={"UL", "LR", "UR", "LL", "CR", "CL", "UC", "LC", "CC", "AUTO"}; static char *msBitmapFontSizes[5]={"TINY", "SMALL", "MEDIUM", "LARGE", "GIANT"}; static char *msQueryMapStyles[4]={"NORMAL", "HILITE", "SELECTED", "INVERTED"}; static char *msStatus[5]={"OFF", "ON", "DEFAULT", "QUERYONLY", "EMBED"}; -static char *msOnOff[2]={"OFF", "ON"}; +// static char *msOnOff[2]={"OFF", "ON"}; static char *msTrueFalse[2]={"FALSE", "TRUE"}; -static char *msYesNo[2]={"NO", "YES"}; +// static char *msYesNo[2]={"NO", "YES"}; +static char *msJoinType[2]={"SINGLE", "MULTIPLE"}; /* ** Palette maniputation routines. Temporary until a good 24-bit @@ -350,6 +350,23 @@ static int loadFeature(struct featureObj *feature) } /* next token */ } +static void writeFeature(struct featureObj *feature, FILE *stream) +{ + int i,j; + + fprintf(stream, " FEATURE\n"); + if(feature->class) fprintf(stream, " CLASS \"%s\"\n", feature->class); + + for(i=0; ishape.numlines; i++) { + fprintf(stream, " POINTS\n"); + for(j=0; jshape.line[i].numpoints; j++) + fprintf(stream, " %g %g\n", feature->shape.line[i].point[j].x, feature->shape.line[i].point[j].y); + fprintf(stream, " END\n"); + } + + if(feature->text) fprintf(stream, " TEXT \"%s\"\n", feature->text); + fprintf(stream, " END\n"); +} /* ** Initialize, load and free a projectionObj structure @@ -438,12 +455,15 @@ int loadProjectionString(projectionObj *p, char *value) } static void writeProjection(projectionObj *p, FILE *stream, char *tab) { +#ifdef USE_PROJ int i; + if(p->numargs > 0); fprintf(stream, "%sPROJECTION\n", tab); for(i=0; inumargs; i++) - fprintf(stream, "\t%s%s\n", tab, p->projargs[i]); + fprintf(stream, " %s%s\n", tab, p->projargs[i]); fprintf(stream, "%sEND\n", tab); +#endif } /* @@ -460,7 +480,8 @@ static void initLabel(labelObj *label) label->font = NULL; label->type = MS_BITMAP; - label->size = MS_MEDIUM; + label->sizescaled = label->size = MS_MEDIUM; + label->position = MS_CC; label->angle = 0; label->autoangle = MS_FALSE; @@ -585,6 +606,7 @@ static int loadLabel(labelObj *label, mapObj *map) if((label->size = getSymbol(5, MS_TINY,MS_SMALL,MS_MEDIUM,MS_LARGE,MS_GIANT)) == -1) return(-1); #endif + label->sizescaled = label->size; break; case(TYPE): if((label->type = getSymbol(2, MS_TRUETYPE,MS_BITMAP)) == -1) return(-1); @@ -600,45 +622,6 @@ static int loadLabel(labelObj *label, mapObj *map) } /* next token */ } -static void writeLabel(mapObj *map, labelObj *label, FILE *stream, char *tab) -{ - fprintf(stream, "%sLABEL\n", tab); - if(label->type == MS_BITMAP) { - fprintf(stream, "\t%sSIZE %s\n", tab, msBitmapFontSizes[label->size]); - fprintf(stream, "\t%sTYPE BITMAP\n", tab); - } else { - if(label->autoangle) - fprintf(stream, "\t%sANGLE AUTO\n", tab); - else - fprintf(stream, "\t%sANGLE %f\n", tab, label->angle*MS_RAD_TO_DEG); - if(label->antialias) fprintf(stream, "\t%sANTIALIAS\n", tab); - fprintf(stream, "\t%sFONT %s\n", tab, label->font); - fprintf(stream, "\t%sMAXSIZE %d\n", tab, label->maxsize); - fprintf(stream, "\t%sMINSIZE %d\n", tab, label->minsize); - fprintf(stream, "\t%sSIZE %d\n", tab, label->size); - fprintf(stream, "\t%sTYPE TRUETYPE\n", tab); - } - - fprintf(stream, "\t%sBUFFER %d\n", tab, label->buffer); - fprintf(stream, "\t%sCOLOR %d %d %d\n", tab, map->palette.colors[label->color].red, map->palette.colors[label->color].green, map->palette.colors[label->color].blue); - fprintf(stream, "\t%sFORCE %s\n", tab, msTrueFalse[label->force]); - fprintf(stream, "\t%sMINDISTANCE %d\n", tab, label->mindistance); - if(label->autominfeaturesize) - fprintf(stream, "\t%sMINFEATURESIZE AUTO\n", tab); - else - fprintf(stream, "\t%sMINFEATURESIZE %d\n", tab, label->minfeaturesize); - fprintf(stream, "\t%sOFFSET %d %d\n", tab, label->offsetx, label->offsety); - if(label->outlinecolor > -1) fprintf(stream, "\t%sOUTLINECOLOR %d %d %d\n", tab, map->palette.colors[label->outlinecolor].red, map->palette.colors[label->outlinecolor].green, map->palette.colors[label->outlinecolor].blue); - fprintf(stream, "\t%sPARTIALS %s\n", tab, msTrueFalse[label->partials]); - fprintf(stream, "\t%sPOSITION %s\n", tab, msLabelPositions[label->position]); - if(label->shadowcolor > -1) { - fprintf(stream, "\t%sSHADOWCOLOR %d %d %d\n", tab, map->palette.colors[label->shadowcolor].red, map->palette.colors[label->shadowcolor].green, map->palette.colors[label->shadowcolor].blue); - fprintf(stream, "\t%sSHADOWSIZE %d %d\n", tab, label->shadowsizex, label->shadowsizey); - } - fprintf(stream, "\t%sWRAP %c\n", tab, label->wrap); - fprintf(stream, "%sEND\n", tab); -} - static void loadLabelString(mapObj *map, labelObj *label, char *value) { int red, green, blue; @@ -668,7 +651,7 @@ static void loadLabelString(mapObj *map, labelObj *label, char *value) if(getInteger(&(red)) == -1) return; if(getInteger(&(green)) == -1) return; if(getInteger(&(blue)) == -1) return; - label->color =msAddColor(map,red,green,blue); + label->color = msAddColor(map,red,green,blue); break; case(FONT): free(label->font); @@ -720,7 +703,7 @@ static void loadLabelString(mapObj *map, labelObj *label, char *value) if(getInteger(&(red)) == -1) return; if(getInteger(&(green)) == -1) return; if(getInteger(&(blue)) == -1) return; - label->outlinecolor =msAddColor(map,red,green,blue); + label->outlinecolor = msAddColor(map,red,green,blue); break; case(PARTIALS): msyystate = 2; msyystring = value; @@ -750,7 +733,8 @@ static void loadLabelString(mapObj *map, labelObj *label, char *value) label->size = msyynumber; #else if((label->size = getSymbol(5, MS_TINY,MS_SMALL,MS_MEDIUM,MS_LARGE,MS_GIANT)) == -1) return; -#endif +#endif + label->sizescaled = label->size; break; case(TYPE): msyystate = 2; msyystring = value; @@ -763,6 +747,45 @@ static void loadLabelString(mapObj *map, labelObj *label, char *value) } } +static void writeLabel(mapObj *map, labelObj *label, FILE *stream, char *tab) +{ + fprintf(stream, "%sLABEL\n", tab); + if(label->type == MS_BITMAP) { + fprintf(stream, " %sSIZE %s\n", tab, msBitmapFontSizes[label->size]); + fprintf(stream, " %sTYPE BITMAP\n", tab); + } else { + if(label->autoangle) + fprintf(stream, " %sANGLE AUTO\n", tab); + else + fprintf(stream, " %sANGLE %f\n", tab, label->angle*MS_RAD_TO_DEG); + if(label->antialias) fprintf(stream, " %sANTIALIAS\n", tab); + fprintf(stream, " %sFONT %s\n", tab, label->font); + fprintf(stream, " %sMAXSIZE %d\n", tab, label->maxsize); + fprintf(stream, " %sMINSIZE %d\n", tab, label->minsize); + fprintf(stream, " %sSIZE %d\n", tab, label->size); + fprintf(stream, " %sTYPE TRUETYPE\n", tab); + } + + fprintf(stream, " %sBUFFER %d\n", tab, label->buffer); + if(label->color > -1) fprintf(stream, " %sCOLOR %d %d %d\n", tab, map->palette.colors[label->color].red, map->palette.colors[label->color].green, map->palette.colors[label->color].blue); + fprintf(stream, " %sFORCE %s\n", tab, msTrueFalse[label->force]); + fprintf(stream, " %sMINDISTANCE %d\n", tab, label->mindistance); + if(label->autominfeaturesize) + fprintf(stream, " %sMINFEATURESIZE AUTO\n", tab); + else + fprintf(stream, " %sMINFEATURESIZE %d\n", tab, label->minfeaturesize); + fprintf(stream, " %sOFFSET %d %d\n", tab, label->offsetx, label->offsety); + if(label->outlinecolor > -1) fprintf(stream, " %sOUTLINECOLOR %d %d %d\n", tab, map->palette.colors[label->outlinecolor].red, map->palette.colors[label->outlinecolor].green, map->palette.colors[label->outlinecolor].blue); + fprintf(stream, " %sPARTIALS %s\n", tab, msTrueFalse[label->partials]); + fprintf(stream, " %sPOSITION %s\n", tab, msLabelPositions[label->position]); + if(label->shadowcolor > -1) { + fprintf(stream, " %sSHADOWCOLOR %d %d %d\n", tab, map->palette.colors[label->shadowcolor].red, map->palette.colors[label->shadowcolor].green, map->palette.colors[label->shadowcolor].blue); + fprintf(stream, " %sSHADOWSIZE %d %d\n", tab, label->shadowsizex, label->shadowsizey); + } + fprintf(stream, " %sWRAP %c\n", tab, label->wrap); + fprintf(stream, "%sEND\n", tab); +} + void initExpression(expressionObj *exp) { exp->type = MS_STRING; @@ -822,6 +845,21 @@ int loadExpressionString(expressionObj *exp, char *value) return(0); } +static void writeExpression(expressionObj *exp, FILE *stream) +{ + switch(exp->type) { + case(MS_REGEX): + fprintf(stream, "/%s/", exp->string); + break; + case(MS_STRING): + fprintf(stream, "\"%s\"", exp->string); + break; + case(MS_EXPRESSION): + fprintf(stream, "(%s)", exp->string); + break; + } +} + /* ** Initialize, load and free a single class */ @@ -832,7 +870,7 @@ int initClass(classObj *class) initExpression(&(class->text)); class->color = -1; /* must explictly set a color */ class->symbol = 0; - class->size = 1; /* one pixel */ + class->sizescaled = class->size = 1; /* one pixel */ class->minsize = MS_MINSYMBOLSIZE; class->maxsize = MS_MAXSYMBOLSIZE; class->backgroundcolor = -1; @@ -902,6 +940,7 @@ int loadClass(classObj *class, mapObj *map) break; case(SIZE): if(getInteger(&(class->size)) == -1) return(-1); + class->sizescaled = class->size; break; case(SYMBOL): if((state = getSymbol(2, MS_NUMBER,MS_STRING)) == -1) return(-1); @@ -970,6 +1009,7 @@ static void loadClassString(mapObj *map, classObj *class, char *value, int type) case(SIZE): msyystate = 2; msyystring = value; getInteger(&(class->size)); + class->sizescaled = class->size; break; case(SYMBOL): msyystate = 2; msyystring = value; @@ -1005,6 +1045,33 @@ static void loadClassString(mapObj *map, classObj *class, char *value, int type) return; } +static void writeClass(mapObj *map, classObj *class, FILE *stream) +{ + fprintf(stream, " CLASS\n"); + if(class->backgroundcolor > -1) fprintf(stream, " BACKGROUNDCOLOR %d %d %d\n", map->palette.colors[class->backgroundcolor].red, map->palette.colors[class->backgroundcolor].green, map->palette.colors[class->backgroundcolor].blue); + if(class->color > -1) fprintf(stream, " COLOR %d %d %d\n", map->palette.colors[class->color].red, map->palette.colors[class->color].green, map->palette.colors[class->color].blue); + if(class->expression.string) { + fprintf(stream, " EXPRESSION "); + writeExpression(&(class->expression), stream); + fprintf(stream, "\n"); + } + writeLabel(map, &(class->label), stream, " "); + if(class->maxsize > -1) fprintf(stream, " MAXSIZE %d\n", class->maxsize); + if(class->minsize > -1) fprintf(stream, " MINSIZE %d\n", class->minsize); + if(class->outlinecolor > -1) fprintf(stream, " OUTLINECOLOR %d %d %d\n", map->palette.colors[class->outlinecolor].red, map->palette.colors[class->outlinecolor].green, map->palette.colors[class->outlinecolor].blue); + fprintf(stream, " SIZE %d\n", class->size); + if(class->symbolname) + fprintf(stream, " SYMBOL \"%s\"\n", class->symbolname); + else + fprintf(stream, " SYMBOL %d\n", class->symbol); + if(class->text.string) { + fprintf(stream, " TEXT "); + writeExpression(&(class->text), stream); + fprintf(stream, "\n"); + } + fprintf(stream, " END\n"); +} + /* ** Initialize, load and free a single join */ @@ -1106,6 +1173,19 @@ int loadJoin(joinObj *join) } /* next token */ } +static void writeJoin(joinObj *join, FILE *stream) +{ + fprintf(stream, " JOIN\n"); + if(join->footer) fprintf(stream, " FOOTER \"%s\"\n", join->footer); + if(join->from) fprintf(stream, " FROM \"%s\"\n", join->from); + if(join->header) fprintf(stream, " HEADER \"%s\"\n", join->header); + if(join->name) fprintf(stream, " NAME \"%s\"\n", join->name); + if(join->table) fprintf(stream, " TABLE \"%s\"\n", join->table); + if(join->to) fprintf(stream, " TO \"%s\"\n", join->to); + fprintf(stream, " TYPE %s\n", msJoinType[join->type]); + fprintf(stream, " END\n"); +} + /* ** Initialize, load and free a single query */ @@ -1193,6 +1273,22 @@ void loadQueryString(queryObj *query, char *value) return; } +static void writeQuery(queryObj *query, FILE *stream) +{ + int i; + + fprintf(stream, " QUERY\n"); + if(query->expression.string) { + fprintf(stream, " EXPRESSION "); + writeExpression(&(query->expression), stream); + fprintf(stream, "\n"); + } + for(i=0; inumjoins; i++) + writeJoin(&(query->joins[i]), stream); + if(query->template) fprintf(stream, " TEMPATE \"%s\"\n", query->template); + fprintf(stream, " END\n"); +} + /* ** Initialize, load and free a single layer structure */ @@ -1231,7 +1327,6 @@ int initLayer(layerObj *layer) layer->header = NULL; layer->footer = NULL; - layer->annotate = MS_FALSE; layer->transform = MS_TRUE; layer->classitem = NULL; @@ -1306,7 +1401,6 @@ int loadLayer(layerObj *layer, mapObj *map) switch(msyylex()) { case(CLASS): if(loadClass(&(layer->class[c]), map) == -1) return(-1); - if(layer->class[c].text.string) layer->annotate = MS_TRUE; c++; break; case(CLASSITEM): @@ -1346,7 +1440,6 @@ int loadLayer(layerObj *layer, mapObj *map) if((layer->features = addFeature(layer->features)) == NULL) return(-1); /* add an empty feature */ } if(loadFeature(layer->features) == -1) return(-1); - if(layer->features->text) layer->annotate = MS_TRUE; break; case(FOOTER): if((layer->footer = getString()) == NULL) return(-1); @@ -1365,7 +1458,6 @@ int loadLayer(layerObj *layer, mapObj *map) break; case(LABELITEM): if((layer->labelitem = getString()) == NULL) return(-1); - layer->annotate = MS_TRUE; break; case(LABELMAXSCALE): if(getDouble(&(layer->labelmaxscale)) == -1) return(-1); @@ -1456,7 +1548,6 @@ static void loadLayerString(mapObj *map, layerObj *layer, char *value) break; } loadClassString(map, &(layer->class[i]), value, layer->type); - if(layer->class[i].text.string) layer->annotate = MS_TRUE; break; case(CLASSITEM): free(layer->classitem); @@ -1516,7 +1607,6 @@ static void loadLayerString(mapObj *map, layerObj *layer, char *value) layer->features->class = strdup(value); break; case(TEXT): - layer->annotate = MS_TRUE; layer->features->text = strdup(value); break; default: @@ -1548,7 +1638,6 @@ static void loadLayerString(mapObj *map, layerObj *layer, char *value) case(LABELITEM): free(layer->labelitem); layer->labelitem = strdup(value); - layer->annotate = MS_TRUE; break; case(LABELMAXSCALE): msyystate = 2; msyystring = value; @@ -1632,6 +1721,47 @@ static void loadLayerString(mapObj *map, layerObj *layer, char *value) return; } +static void writeLayer(mapObj *map, layerObj *layer, FILE *stream) +{ + int i; + struct featureObj *fptr=NULL; + + fprintf(stream, " LAYER\n"); + for(i=0; inumclasses; i++) writeClass(map, &(layer->class[i]), stream); + if(layer->classitem) fprintf(stream, " CLASSITEM \"%s\"\n", layer->classitem); + if(layer->data) fprintf(stream, " DATA \"%s\"\n", layer->data); + if(layer->description) fprintf(stream, " DESCRIPTION \"%s\"\n", layer->description); + for(fptr=layer->features; fptr; fptr=fptr->next) writeFeature(fptr, stream); + if(layer->footer) fprintf(stream, " FOOTER \"%s\"\n", layer->footer); + if(layer->group) fprintf(stream, " GROUP \"%s\"\n", layer->group); + if(layer->header) fprintf(stream, " HEADER \"%s\"\n", layer->header); + if(layer->labelangleitem) fprintf(stream, " LABELANGLEITEM \"%s\"\n", layer->labelangleitem); + if(!layer->labelcache) fprintf(stream, " LABELCACHE OFF\n"); + if(layer->labelitem) fprintf(stream, " LABELITEM \"%s\"\n", layer->labelitem); + if(layer->labelmaxscale > -1) fprintf(stream, " LABELMAXSCALE %g\n", layer->labelmaxscale); + if(layer->labelminscale > -1) fprintf(stream, " LABELMINSCALE %g\n", layer->labelminscale); + if(layer->labelsizeitem) fprintf(stream, " LABELSIZEITEM \"%s\"\n", layer->labelsizeitem); + if(layer->legend) fprintf(stream, " LEGEND \"%s\"\n", layer->legend); + if(layer->maxfeatures > 0) fprintf(stream, " MAXFEATURES %d\n", layer->maxfeatures); + if(layer->maxscale > -1) fprintf(stream, " MAXSCALE %g\n", layer->maxscale); + if(layer->minscale > -1) fprintf(stream, " MINSCALE %g\n", layer->minscale); + fprintf(stream, " NAME \"%s\"\n", layer->name); + if(layer->offsite > -1) fprintf(stream, " OFFSITE %d\n", layer->offsite); + if(layer->postlabelcache) fprintf(stream, " POSTLABELCACHE TRUE\n"); + writeProjection(&(layer->projection), stream, " "); + for(i=0; inumqueries; i++) writeQuery(&(layer->query[i]), stream); + if(layer->queryitem) fprintf(stream, " QUERYITEM \"%s\"\n", layer->queryitem); + fprintf(stream, " STATUS %s\n", msStatus[layer->status]); + if(layer->symbolscale > -1) fprintf(stream, " SYMBOLSCALE %g\n", layer->symbolscale); + if(layer->tileindex) fprintf(stream, " TILEINDEX \"%s\"\n", layer->tileindex); + if(layer->tileitem) fprintf(stream, " TILEITEM \"%s\"\n", layer->tileitem); + fprintf(stream, " TOLERANCE %g\n", layer->tolerance); + fprintf(stream, " TOLERANCEUNITS %s\n", msUnits[layer->toleranceunits]); + if(!layer->transform) fprintf(stream, " TRANSFORM FALSE\n"); + fprintf(stream, " TYPES %s\n", msLayerTypes[layer->type]); + fprintf(stream, " END\n"); +} + /* ** Initialize, load and free a referenceMapObj structure */ @@ -1659,9 +1789,17 @@ int loadReferenceMap(referenceMapObj *ref) for(;;) { switch(msyylex()) { case(EOF): - msSetError(MS_EOFERR, NULL, "loadReferenceMap()"); + msSetError(MS_EOFERR, NULL, "loadReferenceMap()"); return(-1); case(END): + if(!ref->image) { + msSetError(MS_MISCERR, "No image defined for the reference map.", "loadReferenceMap()"); + return(-1); + } + if(ref->width == 0 || ref->height == 0) { + msSetError(MS_MISCERR, "No image size defined for the reference map.", "loadReferenceMap()"); + return(-1); + } return(0); break; case(COLOR): @@ -1740,6 +1878,19 @@ static void loadReferenceMapString(mapObj *map, referenceMapObj *ref, char *valu return; } +static void writeReferenceMap(referenceMapObj *ref, FILE *stream) +{ + if(!ref->image) return; + + fprintf(stream, " REFERENCE\n"); + fprintf(stream, " COLOR %d %d %d\n", ref->color.red, ref->color.green, ref->color.blue); + fprintf(stream, " EXTENT %g %g %g %g\n", ref->extent.minx, ref->extent.miny, ref->extent.maxx, ref->extent.maxy); + fprintf(stream, " IMAGE %s\n", ref->image); + fprintf(stream, " OUTLINECOLOR %d %d %d\n", ref->outlinecolor.red, ref->outlinecolor.green, ref->outlinecolor.blue); + fprintf(stream, " SIZE %d %d\n", ref->width, ref->height); + fprintf(stream, " STATUS %s\n", msStatus[ref->status]); + fprintf(stream, " END\n"); +} /* ** Initialize, load and free a legendObj structure @@ -1805,7 +1956,7 @@ int loadLegend(legendObj *legend, mapObj *map) if(getInteger(&(red)) == -1) return(-1); if(getInteger(&(green)) == -1) return(-1); if(getInteger(&(blue)) == -1) return(-1); - legend->outlinecolor =msAddColor(map,red,green,blue); + legend->outlinecolor = msAddColor(map,red,green,blue); break; case(POSITION): if((legend->position = getSymbol(6, MS_UL,MS_UR,MS_LL,MS_LR,MS_UC,MS_LC)) == -1) return(-1); @@ -1878,6 +2029,22 @@ static void loadLegendString(mapObj *map, legendObj *legend, char *value) return; } +static void writeLegend(mapObj *map, legendObj *legend, FILE *stream) +{ + fprintf(stream, " LEGEND\n"); + fprintf(stream, " IMAGECOLOR %d %d %d\n", legend->imagecolor.red, legend->imagecolor.green, legend->imagecolor.blue); + fprintf(stream, " INTERLACE %s\n", msTrueFalse[legend->interlace]); + fprintf(stream, " KEYSIZE %d %d\n", legend->keysizex, legend->keysizey); + fprintf(stream, " KEYSPACING %d %d\n", legend->keyspacingx, legend->keyspacingy); + writeLabel(map, &(legend->label), stream, " "); + if(legend->outlinecolor > -1) fprintf(stream, " OUTLINECOLOR %d %d %d\n", map->palette.colors[legend->outlinecolor].red, map->palette.colors[legend->outlinecolor].green, map->palette.colors[legend->outlinecolor].blue); + fprintf(stream, " POSITION %s\n", msLabelPositions[legend->position]); + if(legend->postlabelcache) fprintf(stream, " POSTLABELCACHE TRUE\n"); + fprintf(stream, " STATUS %s\n", msStatus[legend->status]); + fprintf(stream, " TRANSPARENT %s\n", msTrueFalse[legend->transparent]); + fprintf(stream, " END\n"); +} + /* ** Initialize, load and free a scalebarObj structure */ @@ -1917,13 +2084,13 @@ int loadScalebar(scalebarObj *scalebar, mapObj *map) if(getInteger(&(red)) == -1) return(-1); if(getInteger(&(green)) == -1) return(-1); if(getInteger(&(blue)) == -1) return(-1); - scalebar->backgroundcolor =msAddColor(map,red,green,blue); + scalebar->backgroundcolor = msAddColor(map,red,green,blue); break; case(COLOR): if(getInteger(&(red)) == -1) return(-1); if(getInteger(&(green)) == -1) return(-1); if(getInteger(&(blue)) == -1) return(-1); - scalebar->color =msAddColor(map,red,green,blue); + scalebar->color = msAddColor(map,red,green,blue); break; case(EOF): msSetError(MS_EOFERR, NULL, "loadScalebar()"); @@ -2064,18 +2231,38 @@ static void loadScalebarString(mapObj *map, scalebarObj *scalebar, char *value) return; } +static void writeScalebar(mapObj *map, scalebarObj *scalebar, FILE *stream) +{ + fprintf(stream, " LEGEND\n"); + if(scalebar->backgroundcolor > -1) fprintf(stream, " BACKGROUNDCOLOR %d %d %d\n", map->palette.colors[scalebar->backgroundcolor].red, map->palette.colors[scalebar->backgroundcolor].green, map->palette.colors[scalebar->backgroundcolor].blue); + if(scalebar->color > -1) fprintf(stream, " COLOR %d %d %d\n", map->palette.colors[scalebar->color].red, map->palette.colors[scalebar->color].green, map->palette.colors[scalebar->color].blue); + fprintf(stream, " IMAGECOLOR %d %d %d\n", scalebar->imagecolor.red, scalebar->imagecolor.green, scalebar->imagecolor.blue); + fprintf(stream, " INTERLACE %s\n", msTrueFalse[scalebar->interlace]); + fprintf(stream, " INTERVALS %d\n", scalebar->intervals); + writeLabel(map, &(scalebar->label), stream, " "); + if(scalebar->outlinecolor > -1) fprintf(stream, " OUTLINECOLOR %d %d %d\n", map->palette.colors[scalebar->outlinecolor].red, map->palette.colors[scalebar->outlinecolor].green, map->palette.colors[scalebar->outlinecolor].blue); + fprintf(stream, " POSITION %s\n", msLabelPositions[scalebar->position]); + if(scalebar->postlabelcache) fprintf(stream, " POSTLABELCACHE TRUE\n"); + fprintf(stream, " SIZE %d %d\n", scalebar->width, scalebar->height); + fprintf(stream, " STATUS %s\n", msStatus[scalebar->status]); + fprintf(stream, " STYLE %d\n", scalebar->style); + fprintf(stream, " TRANSPARENT %s\n", msTrueFalse[scalebar->transparent]); + fprintf(stream, " UNITS %s\n", msUnits[scalebar->units]); + fprintf(stream, " END\n"); +} + /* ** Initialize a queryMapObj structure */ -void initQueryMap(queryMapObj *queryMap) +void initQueryMap(queryMapObj *querymap) { - queryMap->width = queryMap->height = -1; - queryMap->style = MS_HILITE; - queryMap->status = MS_OFF; - queryMap->color = -1; + querymap->width = querymap->height = -1; + querymap->style = MS_HILITE; + querymap->status = MS_OFF; + querymap->color = -1; } -int loadQueryMap(queryMapObj *queryMap, mapObj *map) +int loadQueryMap(queryMapObj *querymap, mapObj *map) { int red, green, blue; @@ -2085,29 +2272,39 @@ int loadQueryMap(queryMapObj *queryMap, mapObj *map) if(getInteger(&(red)) == -1) return(-1); if(getInteger(&(green)) == -1) return(-1); if(getInteger(&(blue)) == -1) return(-1); - queryMap->color = msAddColor(map,red,green,blue); + querymap->color = msAddColor(map,red,green,blue); break; case(EOF): msSetError(MS_EOFERR, NULL, "loadQueryMap()"); return(-1); case(END): - if(queryMap->color == -1) queryMap->color = msAddColor(map,255,255,0); /* default to yellow */ + if(querymap->color == -1) querymap->color = msAddColor(map,255,255,0); /* default to yellow */ return(0); break; case(SIZE): - if(getInteger(&(queryMap->width)) == -1) return(-1); - if(getInteger(&(queryMap->height)) == -1) return(-1); + if(getInteger(&(querymap->width)) == -1) return(-1); + if(getInteger(&(querymap->height)) == -1) return(-1); break; case(STATUS): - if((queryMap->status = getSymbol(2, MS_ON,MS_OFF)) == -1) return(-1); + if((querymap->status = getSymbol(2, MS_ON,MS_OFF)) == -1) return(-1); break; case(STYLE): - if((queryMap->style = getSymbol(3, MS_NORMAL,MS_HILITE,MS_SELECTED)) == -1) return(-1); + if((querymap->style = getSymbol(3, MS_NORMAL,MS_HILITE,MS_SELECTED)) == -1) return(-1); break; } } } +static void writeQueryMap(mapObj *map, queryMapObj *querymap, FILE *stream) +{ + fprintf(stream, " QUERYMAP\n"); + if(querymap->color > -1) fprintf(stream, " COLOR %d %d %d\n", map->palette.colors[querymap->color].red, map->palette.colors[querymap->color].green, map->palette.colors[querymap->color].blue); + fprintf(stream, " SIZE %d %d\n", querymap->width, querymap->height); + fprintf(stream, " STATUS %s\n", msStatus[querymap->status]); + fprintf(stream, " STYLE %s\n", msQueryMapStyles[querymap->style]); + fprintf(stream, " END\n"); +} + /* ** Initialize a webObj structure */ @@ -2139,6 +2336,24 @@ void freeWeb(webObj *web) free(web->empty); } +static void writeWeb(webObj *web, FILE *stream) +{ + fprintf(stream, " WEB\n"); + if(web->empty) fprintf(stream, " EMPTY \"%s\"\n", web->empty); + if(web->error) fprintf(stream, " ERROR \"%s\"\n", web->error); + if(web->footer) fprintf(stream, " FOOTER \"%s\"\n", web->footer); + if(web->header) fprintf(stream, " HEADER \"%s\"\n", web->header); + if(web->imagepath) fprintf(stream, " IMAGEPATH \"%s\"\n", web->imagepath); + if(web->imageurl) fprintf(stream, " IMAGEURL \"%s\"\n", web->imageurl); + if(web->log) fprintf(stream, " LOG \"%s\"\n", web->log); + if(web->maxscale > -1) fprintf(stream, " MAXSCALE %g", web->maxscale); + if(web->maxtemplate) fprintf(stream, " MAXTEMPLATE \"%s\"\n", web->maxtemplate); + if(web->minscale > -1) fprintf(stream, " MINSCALE %g", web->minscale); + if(web->mintemplate) fprintf(stream, " MINTEMPLATE \"%s\"\n", web->mintemplate); + if(web->template) fprintf(stream, " TEMPLATE \"%s\"\n", web->template); + fprintf(stream, " END\n"); +} + int loadWeb(webObj *web) { for(;;) { @@ -2270,7 +2485,6 @@ int initMap(mapObj *map) map->extent.minx = map->extent.miny = map->extent.maxx = map->extent.maxy = -1.0; map->scale = -1.0; - map->scaled = MS_FALSE; map->height = map->width = -1; @@ -2312,11 +2526,9 @@ int initMap(mapObj *map) map->shadeset.filename = NULL; map->shadeset.numsymbols = 0; -#ifdef USE_TTF map->fontset.filename = NULL; map->fontset.numfonts = 0; map->fontset.fonts = NULL; -#endif initLegend(&map->legend); initScalebar(&map->scalebar); @@ -2359,10 +2571,10 @@ void msFreeMap(mapObj *map) { } free(map->labelcache.markers); -#ifdef USE_TTF - free(map->fontset.filename); - msFreeHashTable(map->fontset.fonts); -#endif + if(map->fontset.filename) { + free(map->fontset.filename); + msFreeHashTable(map->fontset.fonts); + } freeWeb(&(map->web)); @@ -2377,6 +2589,55 @@ void msFreeMap(mapObj *map) { free(map); } +int msSaveMap(mapObj *map, char *filename) +{ + int i; + FILE *stream; + + if(!map) { + msSetError(MS_MISCERR, "Map is undefined.", "msSaveMap()"); + return(-1); + } + + if(!filename) { + msSetError(MS_MISCERR, "Filename is undefined.", "msSaveMap()"); + return(-1); + } + + stream = fopen(filename, "w"); + if(!stream) { + msSetError(MS_IOERR, NULL, "msSaveMap()"); + sprintf(ms_error.message, "(%s)", filename); + return(-1); + } + + fprintf(stream, "MAP\n"); + fprintf(stream, " EXTENT %g %g %g %g\n", map->extent.minx, map->extent.miny, map->extent.maxx, map->extent.maxy); + if(map->fontset.filename) fprintf(stream, " FONTSET \"%s\"\n", map->fontset.filename); + fprintf(stream, " IMAGECOLOR %d %d %d\n", map->imagecolor.red, map->imagecolor.green, map->imagecolor.blue); + fprintf(stream, " INTERLACE %s\n", msTrueFalse[map->interlace]); + for(i=0; inumlayers; i++) writeLayer(map, &(map->layers[i]), stream); + writeLegend(map, &(map->legend), stream); + if(map->lineset.filename) fprintf(stream, " LINESET \"%s\"\n", map->lineset.filename); + if(map->markerset.filename) fprintf(stream, " MARKERSET \"%s\"\n", map->markerset.filename); + fprintf(stream, " NAME \"%s\"\n", map->name); + writeProjection(&(map->projection), stream, " "); + writeQueryMap(map, &(map->querymap), stream); + writeReferenceMap(&(map->reference), stream); + writeScalebar(map, &(map->scalebar), stream); + if(map->shadeset.filename) fprintf(stream, " SHADESET \"%s\"\n", map->shadeset.filename); + if(map->shapepath) fprintf(stream, " SHAPEPATH \"%s\"\n", map->shapepath); + fprintf(stream, " SIZE %d %d\n", map->width, map->height); + fprintf(stream, " STATUS %s\n", msStatus[map->status]); + if(map->tile) fprintf(stream, " TILE \"%s\"\n", map->tile); + fprintf(stream, " TRANSPARENT %s\n", msTrueFalse[map->transparent]); + fprintf(stream, " UNITS %s\n", msUnits[map->units]); + writeWeb(&(map->web), stream); + fprintf(stream, "END\n"); + + return(0); +} + mapObj *msLoadMap(char *filename) { int n=0; @@ -2384,6 +2645,11 @@ mapObj *msLoadMap(char *filename) mapObj *map=NULL; char *map_path=NULL; int i,j; + + if(!filename) { + msSetError(MS_MISCERR, "Filename is undefined.", "msLoadMap()"); + return(NULL); + } /* ** Check map filename to make sure it's legal @@ -2483,19 +2749,16 @@ mapObj *msLoadMap(char *filename) if(getDouble(&(map->extent.maxy)) == -1) return(NULL); break; case(FONTSET): -#ifdef USE_TTF - free(map->fontset.filename); if((map->fontset.filename = getString()) == NULL) return(NULL); -#endif - break; - case(INTERLACE): - if((map->interlace = getSymbol(2, MS_ON,MS_OFF)) == -1) return(NULL); break; case(IMAGECOLOR): if(getInteger(&(map->imagecolor.red)) == -1) return(NULL); if(getInteger(&(map->imagecolor.green)) == -1) return(NULL); if(getInteger(&(map->imagecolor.blue)) == -1) return(NULL); break; + case(INTERLACE): + if((map->interlace = getSymbol(2, MS_ON,MS_OFF)) == -1) return(NULL); + break; case(LAYER): if(loadLayer(&(map->layers[n]), map) == -1) return(NULL); map->layers[n].index = n; /* save the index */ diff --git a/maplabel.c b/maplabel.c index efb2586f19..dd5f99daac 100644 --- a/maplabel.c +++ b/maplabel.c @@ -40,7 +40,7 @@ int msAddLabel(mapObj *map, int layer, int class, int tile, int shape, pointObj map->labelcache.labels[i].shapeidx = shape; map->labelcache.labels[i].point = point; map->labelcache.labels[i].string = strdup(string); - map->labelcache.labels[i].size = map->layers[layer].class[class].label.size; + map->labelcache.labels[i].size = map->layers[layer].class[class].label.sizescaled; map->labelcache.labels[i].angle = map->layers[layer].class[class].label.angle; map->labelcache.labels[i].featuresize = featuresize; @@ -165,7 +165,7 @@ int msGetLabelSize(char *string, labelObj *label, rectObj *rect, fontSetObj *fon return(-1); } - error = imageStringTTF(NULL, bbox, 0, font, label->size, 0, 0, 0, string, label->wrap); + error = imageStringTTF(NULL, bbox, 0, font, label->sizescaled, 0, 0, 0, string, label->wrap); if(error) { msSetError(MS_TTFERR, error, "msGetLabelSize()"); return(-1); @@ -352,25 +352,25 @@ static int draw_text(gdImagePtr img, pointObj labelPnt, char *string, labelObj * } if(label->outlinecolor >= 0) { /* handle the outline color */ - error = imageStringTTF(img, bbox, label->antialias*label->outlinecolor, font, label->size, label->angle, x-1, y-1, string, label->wrap); + error = imageStringTTF(img, bbox, label->antialias*label->outlinecolor, font, label->sizescaled, label->angle, x-1, y-1, string, label->wrap); if(error) { msSetError(MS_TTFERR, error, "draw_text()"); return(-1); } - imageStringTTF(img, bbox, label->antialias*label->outlinecolor, font, label->size, label->angle, x-1, y+1, string, label->wrap); - imageStringTTF(img, bbox, label->antialias*label->outlinecolor, font, label->size, label->angle, x+1, y+1, string, label->wrap); - imageStringTTF(img, bbox, label->antialias*label->outlinecolor, font, label->size, label->angle, x+1, y-1, string, label->wrap); + imageStringTTF(img, bbox, label->antialias*label->outlinecolor, font, label->sizescaled, label->angle, x-1, y+1, string, label->wrap); + imageStringTTF(img, bbox, label->antialias*label->outlinecolor, font, label->sizescaled, label->angle, x+1, y+1, string, label->wrap); + imageStringTTF(img, bbox, label->antialias*label->outlinecolor, font, label->sizescaled, label->angle, x+1, y-1, string, label->wrap); } if(label->shadowcolor >= 0) { /* handle the shadow color */ - error = imageStringTTF(img, bbox, label->antialias*label->shadowcolor, font, label->size, label->angle, x+label->shadowsizex, y+label->shadowsizey, string, label->wrap); + error = imageStringTTF(img, bbox, label->antialias*label->shadowcolor, font, label->sizescaled, label->angle, x+label->shadowsizex, y+label->shadowsizey, string, label->wrap); if(error) { msSetError(MS_TTFERR, error, "draw_text()"); return(-1); } } - imageStringTTF(img, bbox, label->antialias*label->color, font, label->size, label->angle, x, y, string, label->wrap); + imageStringTTF(img, bbox, label->antialias*label->color, font, label->sizescaled, label->angle, x, y, string, label->wrap); #else msSetError(MS_TTFERR, "TrueType font support is not available.", "draw_text()"); @@ -530,7 +530,7 @@ int msDrawLabelCache(gdImagePtr img, mapObj *map) continue; /* not an error, just don't want to do anything */ label = classPtr->label; - label.size = cachePtr->size; + label.sizescaled = label.size = cachePtr->size; label.angle = cachePtr->angle; if(msGetLabelSize(cachePtr->string, &label, &r, &(map->fontset)) == -1) diff --git a/maplegend.c b/maplegend.c index 6153b909b1..42e20e8070 100644 --- a/maplegend.c +++ b/maplegend.c @@ -25,8 +25,6 @@ gdImagePtr msDrawLegend(mapObj *map) map->cellsize = msAdjustExtent(&(map->extent), map->width, map->height); map->scale = msCalculateScale(map->extent, map->units, map->width, map->height); - msApplyScale(map); - /* Initialize the polygon/polyline */ p.line = (lineObj *)malloc(sizeof(lineObj)); p.numlines = 1; @@ -39,6 +37,13 @@ gdImagePtr msDrawLegend(mapObj *map) for(i=0; inumlayers; i++) { if((map->layers[i].status == MS_OFF) || (map->layers[i].status == MS_QUERY)) /* skip it */ continue; + + if(map->scale > 0) { + if((map->layers[i].maxscale > 0) && (map->scale > map->layers[i].maxscale)) + continue; + if((map->layers[i].minscale > 0) && (map->scale <= map->layers[i].minscale)) + continue; + } for(j=0;jlayers[i].numclasses;j++) { if(map->layers[i].class[j].name == NULL) @@ -104,6 +109,13 @@ gdImagePtr msDrawLegend(mapObj *map) if((lp->numclasses == 0) || (lp->status == MS_OFF) || (lp->status == MS_QUERY)) continue; /* skip this layer */ + if(map->scale > 0) { + if((lp->maxscale > 0) && (map->scale > lp->maxscale)) + continue; + if((lp->minscale > 0) && (map->scale <= lp->minscale)) + continue; + } + for(j=0; jnumclasses; j++) { /* always at least 1 class */ if(!lp->class[j].name) diff --git a/mapquery.c b/mapquery.c index 230c891ab5..8eed76ff5b 100644 --- a/mapquery.c +++ b/mapquery.c @@ -520,6 +520,13 @@ queryResultObj *msQueryUsingRect(mapObj *map, char *layer, rectObj *rect) { if((map->layers[l].status == MS_OFF) || (map->layers[l].numqueries == 0) || (map->layers[l].tileindex != NULL)) continue; + if(map->scale > 0) { + if((map->layers[l].maxscale > 0) && (map->scale > map->layers[l].maxscale)) + continue; + if((map->layers[l].minscale > 0) && (map->scale <= map->layers[l].minscale)) + continue; + } + if(msOpenSHPFile(&shpfile, map->shapepath, map->tile, map->layers[l].data) == -1) return(NULL); #ifdef USE_PROJ @@ -677,6 +684,13 @@ queryResultObj *msQueryUsingPoint(mapObj *map, char *layer, int mode, pointObj p if((map->layers[l].status == MS_OFF) || (map->layers[l].numqueries == 0) || (map->layers[l].tileindex != NULL)) continue; + if(map->scale > 0) { + if((map->layers[l].maxscale > 0) && (map->scale > map->layers[l].maxscale)) + continue; + if((map->layers[l].minscale > 0) && (map->scale <= map->layers[l].minscale)) + continue; + } + if(msOpenSHPFile(&shpfile, map->shapepath, map->tile, map->layers[l].data) == -1) return(NULL); if(buffer <= 0) { /* use layer tolerance */ @@ -825,6 +839,13 @@ int msQueryUsingFeatures(mapObj *map, char *layer, queryResultObj *results) if((l == search_layer) || (map->layers[l].status == MS_OFF) || (map->layers[l].numqueries == 0) || (map->layers[l].tileindex != NULL)) continue; + if(map->scale > 0) { + if((map->layers[l].maxscale > 0) && (map->scale > map->layers[l].maxscale)) + continue; + if((map->layers[l].minscale > 0) && (map->scale <= map->layers[l].minscale)) + continue; + } + if(msOpenSHPFile(&shpfile, map->shapepath, map->tile, map->layers[l].data) == -1) return(-1); if(initLayerResult(&results->layers[l], shpfile.numshapes) == -1) { @@ -1026,6 +1047,13 @@ queryResultObj *msQueryUsingShape(mapObj *map, char *layer, shapeObj *search_sha if((map->layers[l].status == MS_OFF) || (map->layers[l].numqueries == 0) || (map->layers[l].tileindex != NULL)) continue; + if(map->scale > 0) { + if((map->layers[l].maxscale > 0) && (map->scale > map->layers[l].maxscale)) + continue; + if((map->layers[l].minscale > 0) && (map->scale <= map->layers[l].minscale)) + continue; + } + if(msOpenSHPFile(&shpfile, map->shapepath, map->tile, map->layers[l].data) == -1) return(NULL); if(initLayerResult(&results->layers[l], shpfile.numshapes) == -1) { diff --git a/mapscript/mapscript.i b/mapscript/mapscript.i index f59bbba0d1..9281bf57e1 100644 --- a/mapscript/mapscript.i +++ b/mapscript/mapscript.i @@ -82,7 +82,6 @@ void prepareQuery() { self->scale = msCalculateScale(self->extent, self->units, self->width, self->height); - msApplyScale(self); } gdImagePtr prepareImage() { @@ -109,8 +108,6 @@ self->cellsize = msAdjustExtent(&(self->extent), self->width, self->height); self->scale = msCalculateScale(self->extent, self->units, self->width, self->height); - msApplyScale(self); - return img; } @@ -174,6 +171,10 @@ int setProjection(char *string) { return(loadProjectionString(&(self->projection), string)); } + + int save(char *filename) { + return msSaveMap(self, filename); + } } // @@ -312,13 +313,7 @@ } int setText(layerObj *layer, char *string) { - int status; - - status = loadExpressionString(&self->text, string); - if(status != -1) - layer->annotate = MS_TRUE; - - return status; + return loadExpressionString(&self->text, string); } } diff --git a/mapsde.c b/mapsde.c index 5fc5848dda..5669753940 100644 --- a/mapsde.c +++ b/mapsde.c @@ -127,6 +127,8 @@ int msDrawSDELayer(mapObj *map, layerObj *layer, gdImagePtr img) { #ifdef USE_SDE int i; + double scalefactor=1; + SE_CONNECTION connection=0; SE_STREAM stream=0; SE_ERROR error; @@ -142,6 +144,7 @@ int msDrawSDELayer(mapObj *map, layerObj *layer, gdImagePtr img) { SE_SQL_CONSTRUCT *sql; SE_FILTER filter; + short annotate=MS_TRUE; char *annotation=NULL; short annotation_is_null; @@ -157,6 +160,34 @@ int msDrawSDELayer(mapObj *map, layerObj *layer, gdImagePtr img) { if((layer->status != MS_ON) && (layer->status != MS_DEFAULT)) return(0); + if(map->scale > 0) { + if((layer->maxscale > 0) && (map->scale > layer->maxscale)) + return(0); + if((layer->minscale > 0) && (map->scale <= layer->minscale)) + return(0); + if((layer->labelmaxscale != -1) && (map->scale >= layer->labelmaxscale)) + annotate = MS_FALSE; + if((layer->labelminscale != -1) && (map->scale < layer->labelminscale)) + annotate = MS_FALSE; + } + + // apply scaling to symbols and fonts + if(layer->symbolscale > 0) { + scalefactor = layer->symbolscale/map->scale; + for(i=0; inumclasses; i++) { + layer->class[i].sizescaled = MS_NINT(layer->class[i].size * scalefactor); + layer->class[i].sizescaled = MS_MAX(layer->class[i].sizescaled, layer->class[i].minsize); + layer->class[i].sizescaled = MS_MIN(layer->class[i].sizescaled, layer->class[i].maxsize); +#ifdef USE_TTF + if(layer->class[i].label.type == MS_TRUETYPE) { + layer->class[i].label.sizescaled = MS_NINT(layer->class[i].label.size * scalefactor); + layer->class[i].label.sizescaled = MS_MAX(layer->class[i].label.sizescaled, layer->class[i].label.minsize); + layer->class[i].label.sizescaled = MS_MIN(layer->class[i].label.sizescaled, layer->class[i].label.maxsize); + } +#endif + } + } + /* Set clipping rectangle (used by certain layer types only) */ if(layer->transform && (layer->type == MS_POLYGON || layer->type == MS_POLYLINE)) { cliprect.minx = map->extent.minx - 2*map->cellsize; /* just a bit larger than the map extent */ diff --git a/mapserv.c b/mapserv.c index ceade6fa83..c8ab7851c9 100644 --- a/mapserv.c +++ b/mapserv.c @@ -1901,7 +1901,7 @@ int main(int argc, char *argv[]) { Map->width = ImgCols; Map->height = ImgRows; Map->scale = msCalculateScale(Map->extent, Map->units, Map->width, Map->height); - msApplyScale(Map); + if((QueryResults = msQueryUsingPoint(Map, QueryLayer, MS_SINGLE, MapPnt, 0)) == NULL) writeError(); break; @@ -1982,16 +1982,14 @@ int main(int argc, char *argv[]) { if(SearchMap) { // compute new extent, pan etc then search that extent setExtent(); - Map->scale = msCalculateScale(Map->extent, Map->units, Map->width, Map->height); - msApplyScale(Map); Map->cellsize = msAdjustExtent(&(Map->extent), Map->width, Map->height); + Map->scale = msCalculateScale(Map->extent, Map->units, Map->width, Map->height); if((QueryResults = msQueryUsingRect(Map, QueryLayer, &Map->extent)) == NULL) writeError(); } else { Map->extent = ImgExt; // use the existing image parameters Map->width = ImgCols; Map->height = ImgRows; Map->scale = msCalculateScale(Map->extent, Map->units, Map->width, Map->height); - msApplyScale(Map); if((QueryResults = msQueryUsingPoint(Map, QueryLayer, MS_MULTIPLE, MapPnt, 0)) == NULL) writeError(); } break; @@ -2001,7 +1999,6 @@ int main(int argc, char *argv[]) { if(SearchMap) { // compute new extent, pan etc then search that extent setExtent(); Map->scale = msCalculateScale(Map->extent, Map->units, Map->width, Map->height); - msApplyScale(Map); Map->cellsize = msAdjustExtent(&(Map->extent), Map->width, Map->height); if((QueryResults = msQueryUsingRect(Map, QueryLayer, &Map->extent)) == NULL) writeError(); } else { @@ -2011,7 +2008,6 @@ int main(int argc, char *argv[]) { Map->width = ImgCols; Map->height = ImgRows; Map->scale = msCalculateScale(Map->extent, Map->units, Map->width, Map->height); - msApplyScale(Map); cellx = (ImgExt.maxx-ImgExt.minx)/(ImgCols-1); // calculate the new search extent celly = (ImgExt.maxy-ImgExt.miny)/(ImgRows-1); @@ -2030,7 +2026,6 @@ int main(int argc, char *argv[]) { Map->height = ImgRows; Map->cellsize = msAdjustExtent(&(Map->extent), Map->width, Map->height); Map->scale = msCalculateScale(Map->extent, Map->units, Map->width, Map->height); - msApplyScale(Map); // convert from image to map coordinates here (see setCoordinate) for(i=0; icolor >= gdImageColorsTotal(img)) /* invalid color, -1 is valid */ return; - if(class->size < 1) /* size too small */ + if(class->sizescaled < 1) /* size too small */ return; if(p->numlines <= 0) @@ -360,7 +360,7 @@ void msDrawShadeSymbol(symbolSetObj *shadeset, gdImagePtr img, shapeObj *p, clas bc = class->backgroundcolor; fc = class->color; s = class->symbol; - sz = class->size; + sz = class->sizescaled; if(s == 0) { /* simply draw a single pixel of the specified color */ if(fc>-1) @@ -565,7 +565,7 @@ void msGetMarkerSize(symbolSetObj *markerset, classObj *class, int *width, int * font = msLookupHashTable(markerset->fontset.fonts, markerset->symbol[class->symbol].font); if(!font) return; - if(getCharacterSize(markerset->symbol[class->symbol].character, class->size, font, &rect) == -1) return; + if(getCharacterSize(markerset->symbol[class->symbol].character, class->sizescaled, font, &rect) == -1) return; *width = rect.maxx - rect.minx; *height = rect.maxy - rect.miny; @@ -580,9 +580,9 @@ void msGetMarkerSize(symbolSetObj *markerset, classObj *class, int *width, int * *height = markerset->symbol[class->symbol].img->sy; break; default: /* vector and ellipses, scalable */ - if(class->size > 0) { - *height = class->size; - *width = MS_NINT((class->size/markerset->symbol[class->symbol].sizey) * markerset->symbol[class->symbol].sizex); + if(class->sizescaled > 0) { + *height = class->sizescaled; + *width = MS_NINT((class->sizescaled/markerset->symbol[class->symbol].sizey) * markerset->symbol[class->symbol].sizex); } else { /* use symbol defaults */ *height = markerset->symbol[class->symbol].sizey; *width = markerset->symbol[class->symbol].sizex; @@ -620,13 +620,13 @@ void msDrawMarkerSymbol(symbolSetObj *markerset, gdImagePtr img, pointObj *p, cl if(class->color >= gdImageColorsTotal(img)) /* invalid color, -1 is valid */ return; - if(class->size < 1) /* size too small */ + if(class->sizescaled < 1) /* size too small */ return; oc = class->outlinecolor; fc = class->color; s = class->symbol; - sz = class->size; + sz = class->sizescaled; if(s == 0 && fc >= 0) { /* simply draw a single pixel of the specified color */ gdImageSetPixel(img, p->x, p->y, fc); @@ -766,12 +766,12 @@ void msDrawLineSymbol(symbolSetObj *lineset, gdImagePtr img, shapeObj *p, classO if((class->color < 0) || (class->color >= gdImageColorsTotal(img))) /* invalid color */ return; - if(class->size < 1) /* size too small */ + if(class->sizescaled < 1) /* size too small */ return; fc = class->color; bc = class->backgroundcolor; - size = class->size; + size = class->sizescaled; if(class->symbol == 0) { /* just draw a single width line */ msImagePolyline(img, p, fc); diff --git a/maputil.c b/maputil.c index 8f8fc918d0..023af06372 100644 --- a/maputil.c +++ b/maputil.c @@ -154,7 +154,6 @@ static int shpGetClassIndex(DBFHandle hDBF, layerObj *layer, int record, int ite found=MS_TRUE; break; case(MS_EXPRESSION): - tmpstr = strdup(layer->class[i].expression.string); if(!values) { @@ -167,7 +166,7 @@ static int shpGetClassIndex(DBFHandle hDBF, layerObj *layer, int record, int ite numitems = DBFGetFieldCount(hDBF); items = msGetDBFItems(hDBF); - + layer->class[i].expression.items = (char **)malloc(numitems); layer->class[i].expression.indexes = (int *)malloc(numitems); @@ -235,10 +234,10 @@ static char *shpGetAnnotation(DBFHandle hDBF, classObj *class, int record, int i numitems = DBFGetFieldCount(hDBF); items = msGetDBFItems(hDBF); - + class->text.items = (char **)malloc(numitems); class->text.indexes = (int *)malloc(numitems); - + for(i=0; itext.numitems++; } } - + msFreeCharArray(items,numitems); } - + for(i=0; itext.numitems; i++) - tmpstr = gsub(tmpstr, class->text.items[i], values[class->text.indexes[i]]); - + tmpstr = gsub(tmpstr, class->text.items[i], values[class->text.indexes[i]]); + msFreeCharArray(values,numitems); break; } } else { - if(item < 0) return(NULL); + if(item < 0) return(NULL); tmpstr = strdup(DBFReadStringAttribute(hDBF, record, item)); } @@ -306,61 +305,6 @@ double msAdjustExtent(rectObj *rect, int width, int height) return(cellsize); } -/* -** Does several things related to scaling. Turns layers OFF that fall outside scaling limits. -** Toggles an annotation flag based on scale. Applies scaling to symbols and fonts for layers -** with a symbol scale. -*/ -void msApplyScale(mapObj *map) -{ - int i,j; - double scalefactor; - layerObj *layer; - - if(map->scaled) return; - - if(map->scale == -1) return; - - for(i=0; inumlayers; i++) { - layer = &(map->layers[i]); - - // check status - if((layer->maxscale > 0) && (map->scale > layer->maxscale)) - layer->status = MS_OFF; - if((layer->minscale > 0) && (map->scale <= layer->minscale)) - layer->status = MS_OFF; - - // check annotation status - if(layer->annotate) { - if((layer->labelmaxscale != -1) && (map->scale >= layer->labelmaxscale)) - layer->annotate = MS_FALSE; - if((layer->labelminscale != -1) && (map->scale < layer->labelminscale)) - layer->annotate = MS_FALSE; - } - - // apply scaling to symbols and fonts - if(layer->symbolscale > 0) { - scalefactor = layer->symbolscale/map->scale; - for(j=0; jnumclasses; j++) { - layer->class[j].size = MS_NINT(layer->class[j].size * scalefactor); - layer->class[j].size = MS_MAX(layer->class[j].size, layer->class[j].minsize); - layer->class[j].size = MS_MIN(layer->class[j].size, layer->class[j].maxsize); - -#ifdef USE_TTF - if(layer->class[j].label.type == MS_TRUETYPE) { - layer->class[j].label.size = MS_NINT(layer->class[j].label.size * scalefactor); - layer->class[j].label.size = MS_MAX(layer->class[j].label.size, layer->class[j].label.minsize); - layer->class[j].label.size = MS_MIN(layer->class[j].label.size, layer->class[j].label.maxsize); - } -#endif - - } - } - } - - map->scaled = MS_TRUE; -} - gdImagePtr msDrawMap(mapObj *map) { int i; @@ -388,8 +332,6 @@ gdImagePtr msDrawMap(mapObj *map) map->cellsize = msAdjustExtent(&(map->extent), map->width, map->height); map->scale = msCalculateScale(map->extent, map->units, map->width, map->height); - msApplyScale(map); - for(i=0; inumlayers; i++) { /* for each layer */ lp = &(map->layers[i]); @@ -488,8 +430,6 @@ gdImagePtr msDrawQueryMap(mapObj *map, queryResultObj *results) map->cellsize = msAdjustExtent(&(map->extent), map->width, map->height); map->scale = msCalculateScale(map->extent, map->units, map->width, map->height); - msApplyScale(map); - for(i=0; inumlayers; i++) { /* for each layer */ lp = &(map->layers[i]); @@ -569,17 +509,32 @@ int msDrawPoint(mapObj *map, layerObj *layer, pointObj *point, gdImagePtr img, c { int c; char *text=NULL; + double scalefactor=1; + + if((c = getClassIndex(layer, class_string)) == -1) return(0); + + // apply scaling to symbols and fonts + if(layer->symbolscale > 0 && map->scale > 0) { + scalefactor = layer->symbolscale/map->scale; + layer->class[c].sizescaled = MS_NINT(layer->class[c].size * scalefactor); + layer->class[c].sizescaled = MS_MAX(layer->class[c].sizescaled, layer->class[c].minsize); + layer->class[c].sizescaled = MS_MIN(layer->class[c].sizescaled, layer->class[c].maxsize); +#ifdef USE_TTF + if(layer->class[c].label.type == MS_TRUETYPE) { + layer->class[c].label.sizescaled = MS_NINT(layer->class[c].label.size * scalefactor); + layer->class[c].label.sizescaled = MS_MAX(layer->class[c].label.sizescaled, layer->class[c].label.minsize); + layer->class[c].label.sizescaled = MS_MIN(layer->class[c].label.sizescaled, layer->class[c].label.maxsize); + } +#endif + } - switch(layer->type) { - case MS_ANNOTATION: - - if((c = getClassIndex(layer, class_string)) == -1) return(0); - #ifdef USE_PROJ if((layer->projection.numargs > 0) && (map->projection.numargs > 0)) msProjectPoint(layer->projection.proj, map->projection.proj, point); #endif - + + switch(layer->type) { + case MS_ANNOTATION: if(layer->transform) { if(!msPointInRect(point, &map->extent)) return(0); point->x = MS_NINT((point->x - map->extent.minx)/map->cellsize); @@ -601,14 +556,6 @@ int msDrawPoint(mapObj *map, layerObj *layer, pointObj *point, gdImagePtr img, c break; case MS_POINT: - - if((c = getClassIndex(layer, class_string)) == -1) return(0); /* next feature */ - -#ifdef USE_PROJ - if((layer->projection.numargs > 0) && (map->projection.numargs > 0)) - msProjectPoint(layer->projection.proj, map->projection.proj, point); -#endif - if(layer->transform) { if(!msPointInRect(point, &map->extent)) return(0); point->x = MS_NINT((point->x - map->extent.minx)/map->cellsize); @@ -649,6 +596,7 @@ int msDrawShape(mapObj *map, layerObj *layer, shapeObj *shape, gdImagePtr img, c double angle, length; char *text=NULL; pointObj *pnt; + double scalefactor=1; /* Set clipping rectangle (used by certain layer types only) */ if(layer->transform && (layer->type == MS_POLYGON || layer->type == MS_POLYLINE)) { @@ -657,17 +605,31 @@ int msDrawShape(mapObj *map, layerObj *layer, shapeObj *shape, gdImagePtr img, c cliprect.maxx = map->extent.maxx + 2*map->cellsize; cliprect.maxy = map->extent.maxy + 2*map->cellsize; } - - switch(layer->type) { - case MS_ANNOTATION: - - if((c = getClassIndex(layer, class_string)) == -1) return(0); - + + if((c = getClassIndex(layer, class_string)) == -1) return(0); + + // apply scaling to symbols and fonts + if(layer->symbolscale > 0 && map->scale > 0) { + scalefactor = layer->symbolscale/map->scale; + layer->class[c].sizescaled = MS_NINT(layer->class[c].size * scalefactor); + layer->class[c].sizescaled = MS_MAX(layer->class[c].sizescaled, layer->class[c].minsize); + layer->class[c].sizescaled = MS_MIN(layer->class[c].sizescaled, layer->class[c].maxsize); +#ifdef USE_TTF + if(layer->class[c].label.type == MS_TRUETYPE) { + layer->class[c].label.sizescaled = MS_NINT(layer->class[c].label.size * scalefactor); + layer->class[c].label.sizescaled = MS_MAX(layer->class[c].label.sizescaled, layer->class[c].label.minsize); + layer->class[c].label.sizescaled = MS_MIN(layer->class[c].label.sizescaled, layer->class[c].label.maxsize); + } +#endif + } + #ifdef USE_PROJ - if((layer->projection.numargs > 0) && (map->projection.numargs > 0)) - msProjectPolyline(layer->projection.proj, map->projection.proj, shape); + if((layer->projection.numargs > 0) && (map->projection.numargs > 0)) + msProjectPolyline(layer->projection.proj, map->projection.proj, shape); #endif - + + switch(layer->type) { + case MS_ANNOTATION: for(j=0; jnumlines;j++) { for(i=0; iline[j].numpoints;i++) { @@ -696,14 +658,6 @@ int msDrawShape(mapObj *map, layerObj *layer, shapeObj *shape, gdImagePtr img, c break; case MS_POINT: - - if((c = getClassIndex(layer, class_string)) == -1) return(0); /* next feature */ - -#ifdef USE_PROJ - if((layer->projection.numargs > 0) && (map->projection.numargs > 0)) - msProjectPolyline(layer->projection.proj, map->projection.proj, shape); -#endif - for(j=0; jnumlines;j++) { for(i=0; iline[j].numpoints;i++) { @@ -734,15 +688,7 @@ int msDrawShape(mapObj *map, layerObj *layer, shapeObj *shape, gdImagePtr img, c } break; - case MS_POLYLINE: - - if((c = getClassIndex(layer, class_string)) == -1) return(0); /* next feature */ - -#ifdef USE_PROJ - if((layer->projection.numargs > 0) && (map->projection.numargs > 0)) - msProjectPolyline(layer->projection.proj, map->projection.proj, shape); -#endif - + case MS_POLYLINE: if(layer->transform) { msClipPolygonRect(shape, cliprect, shape); if(shape->numlines == 0) return(0); @@ -765,16 +711,8 @@ int msDrawShape(mapObj *map, layerObj *layer, shapeObj *shape, gdImagePtr img, c } } break; - - case MS_LINE: - - if((c = getClassIndex(layer, class_string)) == -1) return(0); /* next feature */ -#ifdef USE_PROJ - if((layer->projection.numargs > 0) && (map->projection.numargs > 0)) - msProjectPolyline(layer->projection.proj, map->projection.proj, shape); -#endif - + case MS_LINE: if(layer->transform) { msClipPolylineRect(shape, map->extent, shape); if(shape->numlines == 0) return(0); @@ -801,15 +739,7 @@ int msDrawShape(mapObj *map, layerObj *layer, shapeObj *shape, gdImagePtr img, c } break; - case MS_POLYGON: - - if((c = getClassIndex(layer, class_string)) == -1) return(0); /* next feature */ - -#ifdef USE_PROJ - if((layer->projection.numargs > 0) && (map->projection.numargs > 0)) - msProjectPolyline(layer->projection.proj, map->projection.proj, shape); -#endif - + case MS_POLYGON: if(layer->transform) { msClipPolygonRect(shape, cliprect, shape); if(shape->numlines == 0) return(0); @@ -848,14 +778,44 @@ int msDrawInlineLayer(mapObj *map, layerObj *layer, gdImagePtr img) int i,j,c; struct featureObj *fptr=NULL; rectObj cliprect; + short annotate=MS_TRUE; pointObj annopnt; double angle, length; char *text; pointObj *pnt; + double scalefactor=1; if((layer->status != MS_ON) && (layer->status != MS_DEFAULT)) return(0); + if(map->scale > 0) { + if((layer->maxscale > 0) && (map->scale > layer->maxscale)) + return(0); + if((layer->minscale > 0) && (map->scale <= layer->minscale)) + return(0); + if((layer->labelmaxscale != -1) && (map->scale >= layer->labelmaxscale)) + annotate = MS_FALSE; + if((layer->labelminscale != -1) && (map->scale < layer->labelminscale)) + annotate = MS_FALSE; + } + + // apply scaling to symbols and fonts + if(layer->symbolscale > 0) { + scalefactor = layer->symbolscale/map->scale; + for(i=0; inumclasses; i++) { + layer->class[i].sizescaled = MS_NINT(layer->class[i].size * scalefactor); + layer->class[i].sizescaled = MS_MAX(layer->class[i].sizescaled, layer->class[i].minsize); + layer->class[i].sizescaled = MS_MIN(layer->class[i].sizescaled, layer->class[i].maxsize); +#ifdef USE_TTF + if(layer->class[i].label.type == MS_TRUETYPE) { + layer->class[i].label.sizescaled = MS_NINT(layer->class[i].label.size * scalefactor); + layer->class[i].label.sizescaled = MS_MAX(layer->class[i].label.sizescaled, layer->class[i].label.minsize); + layer->class[i].label.sizescaled = MS_MIN(layer->class[i].label.sizescaled, layer->class[i].label.maxsize); + } +#endif + } + } + /* Set clipping rectangle (used by certain layer types only) */ if(layer->transform && (layer->type == MS_POLYGON || layer->type == MS_POLYLINE)) { cliprect.minx = map->extent.minx - 2*map->cellsize; /* just a bit larger than the map extent */ @@ -866,7 +826,7 @@ int msDrawInlineLayer(mapObj *map, layerObj *layer, gdImagePtr img) switch(layer->type) { case MS_ANNOTATION: - if(!layer->annotate) break; + if(!annotate) break; for(fptr=layer->features; fptr; fptr=fptr->next) { @@ -929,9 +889,10 @@ int msDrawInlineLayer(mapObj *map, layerObj *layer, gdImagePtr img) msDrawMarkerSymbol(&map->markerset, img, pnt, &layer->class[c]); } - if(layer->annotate) { + if(annotate) { if(fptr->text) text = fptr->text; - else text = layer->class[c].text.string; + else if(layer->class[c].text.string) text = layer->class[c].text.string; + else continue; if(layer->labelcache) msAddLabel(map, layer->index, c, -1, -1, *pnt, text, -1); @@ -963,9 +924,10 @@ int msDrawInlineLayer(mapObj *map, layerObj *layer, gdImagePtr img) } msDrawLineSymbol(&map->lineset, img, &fptr->shape, &layer->class[c]); - if(layer->annotate) { + if(annotate) { if(fptr->text) text = fptr->text; - else text = layer->class[c].text.string; + else if(layer->class[c].text.string) text = layer->class[c].text.string; + else continue; if(msPolygonLabelPoint(&fptr->shape, &annopnt, layer->class[c].label.minfeaturesize) != -1) { if(layer->labelcache) { @@ -997,9 +959,10 @@ int msDrawInlineLayer(mapObj *map, layerObj *layer, gdImagePtr img) } msDrawLineSymbol(&map->lineset, img, &fptr->shape, &layer->class[c]); - if(layer->annotate) { + if(annotate) { if(fptr->text) text = fptr->text; - else text = layer->class[c].text.string; + else if(layer->class[c].text.string) text = layer->class[c].text.string; + else continue; if(msPolylineLabelPoint(&fptr->shape, &annopnt, layer->class[c].label.minfeaturesize, &angle, &length) != -1) { if(layer->class[c].label.autoangle) @@ -1034,9 +997,10 @@ int msDrawInlineLayer(mapObj *map, layerObj *layer, gdImagePtr img) } msDrawShadeSymbol(&map->shadeset, img, &fptr->shape, &layer->class[c]); - if(layer->annotate) { + if(annotate) { if(fptr->text) text = fptr->text; - else text = layer->class[c].text.string; + else if(layer->class[c].text.string) text = layer->class[c].text.string; + else continue; if(msPolygonLabelPoint(&fptr->shape, &annopnt, layer->class[c].label.minfeaturesize) != -1) { if(layer->labelcache) @@ -1072,7 +1036,6 @@ int msDrawShapefileLayer(mapObj *map, layerObj *layer, gdImagePtr img, char *que char *filename=NULL; - double sf=1.0; int c=-1; /* what class is a particular feature */ int start_feature; @@ -1081,6 +1044,7 @@ int msDrawShapefileLayer(mapObj *map, layerObj *layer, gdImagePtr img, char *que shapeObj shape={0,NULL,{-1,-1,-1,-1},MS_NULL}; pointObj *pnt; + short annotate=MS_TRUE; pointObj annopnt; char *annotxt=NULL; @@ -1095,12 +1059,42 @@ int msDrawShapefileLayer(mapObj *map, layerObj *layer, gdImagePtr img, char *que double angle, length; /* line labeling parameters */ + double scalefactor=1; + if(!layer->data && !layer->tileindex) return(0); if((layer->status != MS_ON) && (layer->status != MS_DEFAULT)) return(0); + if(map->scale > 0) { + if((layer->maxscale > 0) && (map->scale > layer->maxscale)) + return(0); + if((layer->minscale > 0) && (map->scale <= layer->minscale)) + return(0); + if((layer->labelmaxscale != -1) && (map->scale >= layer->labelmaxscale)) + annotate = MS_FALSE; + if((layer->labelminscale != -1) && (map->scale < layer->labelminscale)) + annotate = MS_FALSE; + } + + // apply scaling to symbols and fonts + if(layer->symbolscale > 0) { + scalefactor = layer->symbolscale/map->scale; + for(i=0; inumclasses; i++) { + layer->class[i].sizescaled = MS_NINT(layer->class[i].size * scalefactor); + layer->class[i].sizescaled = MS_MAX(layer->class[i].sizescaled, layer->class[i].minsize); + layer->class[i].sizescaled = MS_MIN(layer->class[i].sizescaled, layer->class[i].maxsize); +#ifdef USE_TTF + if(layer->class[i].label.type == MS_TRUETYPE) { + layer->class[i].label.sizescaled = MS_NINT(layer->class[i].label.size * scalefactor); + layer->class[i].label.sizescaled = MS_MAX(layer->class[i].label.sizescaled, layer->class[i].label.minsize); + layer->class[i].label.sizescaled = MS_MIN(layer->class[i].label.sizescaled, layer->class[i].label.maxsize); + } +#endif + } + } + /* Set clipping rectangle (used by certain layer types only) */ if(layer->transform && (layer->type == MS_POLYGON || layer->type == MS_POLYLINE)) { cliprect.minx = map->extent.minx - 2*map->cellsize; /* just a bit larger than the map extent */ @@ -1154,7 +1148,7 @@ int msDrawShapefileLayer(mapObj *map, layerObj *layer, gdImagePtr img, char *que return(-1); } - if(layer->labelitem && layer->annotate) { + if(layer->labelitem && annotate) { if((labelItemIndex = msGetItemIndex(shpfile.hDBF, layer->labelitem)) == -1) return(-1); labelAngleItemIndex = msGetItemIndex(shpfile.hDBF, layer->labelangleitem); /* not required */ @@ -1198,7 +1192,7 @@ int msDrawShapefileLayer(mapObj *map, layerObj *layer, gdImagePtr img, char *que switch(layer->type) { case MS_ANNOTATION: - if(!layer->annotate) break; + if(!annotate) break; switch(shpfile.type) { case MS_SHP_POINT: @@ -1217,6 +1211,7 @@ int msDrawShapefileLayer(mapObj *map, layerObj *layer, gdImagePtr img, char *que #endif annotxt = shpGetAnnotation(shpfile.hDBF, &(layer->class[c]), i, labelItemIndex); + if(!annotxt) continue; for(j=0; jclass[c].label.angle = DBFReadDoubleAttribute(shpfile.hDBF, i, labelAngleItemIndex)*MS_DEG_TO_RAD; if((labelSizeItemIndex != -1) && (layer->class[c].label.type == MS_TRUETYPE)) { - layer->class[c].label.size = DBFReadIntegerAttribute(shpfile.hDBF, i, labelSizeItemIndex)*sf; - layer->class[c].label.size = MS_MAX(layer->class[c].label.size, layer->class[c].label.minsize); - layer->class[c].label.size = MS_MIN(layer->class[c].label.size, layer->class[c].label.maxsize); + layer->class[c].label.sizescaled = DBFReadIntegerAttribute(shpfile.hDBF, i, labelSizeItemIndex)*scalefactor; + layer->class[c].label.sizescaled = MS_MAX(layer->class[c].label.sizescaled, layer->class[c].label.minsize); + layer->class[c].label.sizescaled = MS_MIN(layer->class[c].label.sizescaled, layer->class[c].label.maxsize); } if(layer->labelcache) @@ -1279,15 +1274,16 @@ int msDrawShapefileLayer(mapObj *map, layerObj *layer, gdImagePtr img, char *que layer->class[c].label.angle = atof(DBFReadStringAttribute(shpfile.hDBF, i, labelAngleItemIndex))*MS_DEG_TO_RAD; if((labelSizeItemIndex != -1) && (layer->class[c].label.type == MS_TRUETYPE)) { - layer->class[c].label.size = atoi(DBFReadStringAttribute(shpfile.hDBF, i, labelSizeItemIndex))*sf; - layer->class[c].label.size = MS_MAX(layer->class[c].label.size, layer->class[c].label.minsize); - layer->class[c].label.size = MS_MIN(layer->class[c].label.size, layer->class[c].label.maxsize); + layer->class[c].label.sizescaled = atoi(DBFReadStringAttribute(shpfile.hDBF, i, labelSizeItemIndex))*scalefactor; + layer->class[c].label.sizescaled = MS_MAX(layer->class[c].label.sizescaled, layer->class[c].label.minsize); + layer->class[c].label.sizescaled = MS_MIN(layer->class[c].label.sizescaled, layer->class[c].label.maxsize); } if(layer->class[c].label.autoangle) layer->class[c].label.angle = angle; annotxt = shpGetAnnotation(shpfile.hDBF, &(layer->class[c]), i, labelItemIndex); + if(!annotxt) continue; if(layer->labelcache) msAddLabel(map, layer->index, c, t, i, annopnt, annotxt, length); @@ -1332,13 +1328,14 @@ int msDrawShapefileLayer(mapObj *map, layerObj *layer, gdImagePtr img, char *que layer->class[c].label.angle = atof(DBFReadStringAttribute(shpfile.hDBF, i, labelAngleItemIndex))*MS_DEG_TO_RAD; if((labelSizeItemIndex != -1) && (layer->class[c].label.type == MS_TRUETYPE)) { - layer->class[c].label.size = atoi(DBFReadStringAttribute(shpfile.hDBF, i, labelSizeItemIndex))*sf; - layer->class[c].label.size = MS_MAX(layer->class[c].label.size, layer->class[c].label.minsize); - layer->class[c].label.size = MS_MIN(layer->class[c].label.size, layer->class[c].label.maxsize); + layer->class[c].label.sizescaled = atoi(DBFReadStringAttribute(shpfile.hDBF, i, labelSizeItemIndex))*scalefactor; + layer->class[c].label.sizescaled = MS_MAX(layer->class[c].label.sizescaled, layer->class[c].label.minsize); + layer->class[c].label.sizescaled = MS_MIN(layer->class[c].label.sizescaled, layer->class[c].label.maxsize); } annotxt = shpGetAnnotation(shpfile.hDBF, &(layer->class[c]), i, labelItemIndex); - + if(!annotxt) continue; + if(layer->labelcache) msAddLabel(map, layer->index, c, t, i, annopnt, annotxt, -1); else { @@ -1372,8 +1369,7 @@ int msDrawShapefileLayer(mapObj *map, layerObj *layer, gdImagePtr img, char *que SHPReadShape(shpfile.hSHP, i, &shape); #endif - if(layer->annotate) - annotxt = shpGetAnnotation(shpfile.hDBF, &(layer->class[c]), i, labelItemIndex); + if(annotate) annotxt = shpGetAnnotation(shpfile.hDBF, &(layer->class[c]), i, labelItemIndex); for(j=0; jmarkerset, img, pnt, &layer->class[c]); } - if(layer->annotate) { + if(annotate && annotxt) { + if(labelAngleItemIndex != -1) layer->class[c].label.angle = DBFReadDoubleAttribute(shpfile.hDBF, i, labelAngleItemIndex)*MS_DEG_TO_RAD; if((labelSizeItemIndex != -1) && (layer->class[c].label.type == MS_TRUETYPE)) { - layer->class[c].label.size = DBFReadIntegerAttribute(shpfile.hDBF, i, labelSizeItemIndex)*sf; - layer->class[c].label.size = MS_MAX(layer->class[c].label.size, layer->class[c].label.minsize); - layer->class[c].label.size = MS_MIN(layer->class[c].label.size, layer->class[c].label.maxsize); + layer->class[c].label.sizescaled = DBFReadIntegerAttribute(shpfile.hDBF, i, labelSizeItemIndex)*scalefactor; + layer->class[c].label.sizescaled = MS_MAX(layer->class[c].label.sizescaled, layer->class[c].label.minsize); + layer->class[c].label.sizescaled = MS_MIN(layer->class[c].label.sizescaled, layer->class[c].label.maxsize); } if(layer->labelcache) @@ -1409,7 +1406,7 @@ int msDrawShapefileLayer(mapObj *map, layerObj *layer, gdImagePtr img, char *que pnt = NULL; msFreeShape(&shape); - if(layer->annotate) + if(annotate) free(annotxt); } @@ -1444,19 +1441,17 @@ int msDrawShapefileLayer(mapObj *map, layerObj *layer, gdImagePtr img, char *que } msDrawLineSymbol(&map->lineset, img, &shape, &(layer->class[c])); - if(layer->annotate) { + if(annotate && (annotxt = shpGetAnnotation(shpfile.hDBF, &(layer->class[c]), i, labelItemIndex))) { if(msPolygonLabelPoint(&shape, &annopnt, layer->class[c].label.minfeaturesize) != -1) { if(labelAngleItemIndex != -1) layer->class[c].label.angle = atof(DBFReadStringAttribute(shpfile.hDBF, i, labelAngleItemIndex))*MS_DEG_TO_RAD; if((labelSizeItemIndex != -1) && (layer->class[c].label.type == MS_TRUETYPE)) { - layer->class[c].label.size = atoi(DBFReadStringAttribute(shpfile.hDBF, i, labelSizeItemIndex))*sf; - layer->class[c].label.size = MS_MAX(layer->class[c].label.size, layer->class[c].label.minsize); - layer->class[c].label.size = MS_MIN(layer->class[c].label.size, layer->class[c].label.maxsize); + layer->class[c].label.sizescaled = atoi(DBFReadStringAttribute(shpfile.hDBF, i, labelSizeItemIndex))*scalefactor; + layer->class[c].label.sizescaled = MS_MAX(layer->class[c].label.sizescaled, layer->class[c].label.minsize); + layer->class[c].label.sizescaled = MS_MIN(layer->class[c].label.sizescaled, layer->class[c].label.maxsize); } - annotxt = shpGetAnnotation(shpfile.hDBF, &(layer->class[c]), i, labelItemIndex); - if(layer->labelcache) msAddLabel(map, layer->index, c, t, i, annopnt, annotxt, -1); else @@ -1498,7 +1493,7 @@ int msDrawShapefileLayer(mapObj *map, layerObj *layer, gdImagePtr img, char *que } msDrawLineSymbol(&map->lineset, img, &shape, &(layer->class[c])); - if(layer->annotate) { + if(annotate && (annotxt = shpGetAnnotation(shpfile.hDBF, &(layer->class[c]), i, labelItemIndex))) { if(msPolylineLabelPoint(&shape, &annopnt, layer->class[c].label.minfeaturesize, &angle, &length) != -1) { if(layer->class[c].label.autoangle) @@ -1508,13 +1503,11 @@ int msDrawShapefileLayer(mapObj *map, layerObj *layer, gdImagePtr img, char *que layer->class[c].label.angle = atof(DBFReadStringAttribute(shpfile.hDBF, i, labelAngleItemIndex))*MS_DEG_TO_RAD; if((labelSizeItemIndex != -1) && (layer->class[c].label.type == MS_TRUETYPE)) { - layer->class[c].label.size = atoi(DBFReadStringAttribute(shpfile.hDBF, i, labelSizeItemIndex))*sf; - layer->class[c].label.size = MS_MAX(layer->class[c].label.size, layer->class[c].label.minsize); - layer->class[c].label.size = MS_MIN(layer->class[c].label.size, layer->class[c].label.maxsize); + layer->class[c].label.sizescaled = atoi(DBFReadStringAttribute(shpfile.hDBF, i, labelSizeItemIndex))*scalefactor; + layer->class[c].label.sizescaled = MS_MAX(layer->class[c].label.sizescaled, layer->class[c].label.minsize); + layer->class[c].label.sizescaled = MS_MIN(layer->class[c].label.sizescaled, layer->class[c].label.maxsize); } - annotxt = shpGetAnnotation(shpfile.hDBF, &(layer->class[c]), i, labelItemIndex); - if(layer->labelcache) msAddLabel(map, layer->index, c, t, i, annopnt, annotxt, length); else @@ -1558,19 +1551,17 @@ int msDrawShapefileLayer(mapObj *map, layerObj *layer, gdImagePtr img, char *que } msDrawShadeSymbol(&map->shadeset, img, &shape, &(layer->class[c])); - if(layer->annotate) { + if(annotate && (annotxt = shpGetAnnotation(shpfile.hDBF, &(layer->class[c]), i, labelItemIndex))) { if(msPolygonLabelPoint(&shape, &annopnt, layer->class[c].label.minfeaturesize) != -1) { if(labelAngleItemIndex != -1) layer->class[c].label.angle = atof(DBFReadStringAttribute(shpfile.hDBF, i, labelAngleItemIndex))*MS_DEG_TO_RAD; if((labelSizeItemIndex != -1) && (layer->class[c].label.type == MS_TRUETYPE)) { - layer->class[c].label.size = atoi(DBFReadStringAttribute(shpfile.hDBF, i, labelSizeItemIndex))*sf; - layer->class[c].label.size = MS_MAX(layer->class[c].label.size, layer->class[c].label.minsize); - layer->class[c].label.size = MS_MIN(layer->class[c].label.size, layer->class[c].label.maxsize); + layer->class[c].label.sizescaled = atoi(DBFReadStringAttribute(shpfile.hDBF, i, labelSizeItemIndex))*scalefactor; + layer->class[c].label.sizescaled = MS_MAX(layer->class[c].label.sizescaled, layer->class[c].label.minsize); + layer->class[c].label.sizescaled = MS_MIN(layer->class[c].label.sizescaled, layer->class[c].label.maxsize); } - annotxt = shpGetAnnotation(shpfile.hDBF, &(layer->class[c]), i, labelItemIndex); - if(layer->labelcache) msAddLabel(map, layer->index, c, t, i, annopnt, annotxt, -1); else