コード例 #1
0
/* assumes an angle of 0 regardless of what's in the label object */
int msGetLabelSize(mapObj *map, labelObj *label, char *string, double size, rectObj *rect, double **advances)
{
  rendererVTableObj *renderer = NULL;

  if (map)
    renderer =MS_MAP_RENDERER(map);

  if(!renderer) {
    msSetError(MS_MISCERR, "cannot compute label size without valid map and renderer", "msGetLabelSize()");
    return MS_FAILURE;
  }

  if(label->type == MS_TRUETYPE) {
    if(!label->font) {
      msSetError(MS_MISCERR, "label has no true type font", "msGetLabelSize()");
      return MS_FAILURE;
    }
    return msGetTruetypeTextBBox(renderer,label->font,&(map->fontset),size,string,rect,advances,1);
  } else if(label->type == MS_BITMAP) {
    if(renderer->supports_bitmap_fonts)
      return msGetRasterTextBBox(renderer,MS_NINT(label->size),string,rect);
    else {
      msSetError(MS_MISCERR, "renderer does not support bitmap fonts", "msGetLabelSize()");
      return MS_FAILURE;
    }
  } else {
    msSetError(MS_MISCERR, "unknown label type", "msGetLabelSize()");
    return MS_FAILURE;
  }
}
コード例 #2
0
ファイル: maplegend.c プロジェクト: AsgerPetersen/mapserver
  }

  free(box.line[0].point);
  free(box.line);

  return MS_SUCCESS;
}


imageObj *msCreateLegendIcon(mapObj* map, layerObj* lp, classObj* class, int width, int height)
{
  imageObj *image;
  outputFormatObj *format = NULL;
  int i = 0;

  rendererVTableObj *renderer = MS_MAP_RENDERER(map);

  if( !renderer ) {
    msSetError(MS_MISCERR, "invalid map outputformat", "msCreateLegendIcon()");
    return(NULL);
  }

  /* ensure we have an image format representing the options for the legend */
  msApplyOutputFormat(&format, map->outputformat, map->legend.transparent, map->legend.interlace, MS_NOOVERRIDE);

  image = msImageCreate(width,height,format,map->web.imagepath, map->web.imageurl,
                        map->resolution, map->defresolution, &(map->legend.imagecolor));

  /* drop this reference to output format */
  msApplyOutputFormat( &format, NULL, MS_NOOVERRIDE, MS_NOOVERRIDE, MS_NOOVERRIDE );
コード例 #3
0
ファイル: mapscale.c プロジェクト: havatv/mapserver
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) {
コード例 #4
0
ファイル: mapscale.c プロジェクト: havatv/mapserver
/* TODO : the will be msDrawScalebarGD */
imageObj *msDrawScalebar(mapObj *map)
{
    int status;
    char label[32];
    double i, msx;
    int j;
    int isx, sx, sy, ox, oy, state, dsx;
    pointObj p;
    rectObj r;
    imageObj      *image = NULL;
    double fontWidth, fontHeight;
    outputFormatObj *format = NULL;
    strokeStyleObj strokeStyle;
    shapeObj shape;
    lineObj line;
    pointObj points[5];
    rendererVTableObj *renderer;

    strokeStyle.patternlength=0;

    if(map->units == -1) {
        msSetError(MS_MISCERR, "Map units not set.", "msDrawScalebar()");
        return(NULL);
    }

    renderer = MS_MAP_RENDERER(map);
    if(!renderer || !MS_MAP_RENDERER(map)->supports_pixel_buffer) {
        msSetError(MS_MISCERR, "Outputformat not supported for scalebar", "msDrawScalebar()");
        return(NULL);
    }

    /*
     *  A string containing the ten decimal digits is rendered to compute an average cell size
     *  for each number, which is used later to place labels on the scalebar.
     */

    if(msGetLabelSize(map,&map->scalebar.label,"0123456789",map->scalebar.label.size,&r,NULL) != MS_SUCCESS) {
        return NULL;
    }
    fontWidth = (r.maxx-r.minx)/10.0;
    fontHeight = r.maxy -r.miny;

    map->cellsize = msAdjustExtent(&(map->extent), map->width, map->height);
    status = msCalculateScale(map->extent, map->units, map->width, map->height, map->resolution, &map->scaledenom);
    if(status != MS_SUCCESS) {
        return(NULL);
    }
    dsx = map->scalebar.width - 2*HMARGIN;
    do {
        msx = (map->cellsize * dsx)/(msInchesPerUnit(map->scalebar.units,0)/msInchesPerUnit(map->units,0));
        i = roundInterval(msx/map->scalebar.intervals);
        snprintf(label, sizeof(label), "%g", map->scalebar.intervals*i); /* last label */
        isx = MS_NINT((i/(msInchesPerUnit(map->units,0)/msInchesPerUnit(map->scalebar.units,0)))/map->cellsize);
        sx = (map->scalebar.intervals*isx) + MS_NINT((1.5 + strlen(label)/2.0 + strlen(unitText[map->scalebar.units]))*fontWidth);

        if(sx <= (map->scalebar.width - 2*HMARGIN)) break; /* it will fit */

        dsx -= X_STEP_SIZE; /* change the desired size in hopes that it will fit in user supplied width */
    } while(1);

    sy = (2*VMARGIN) + MS_NINT(VSPACING*fontHeight) + fontHeight + map->scalebar.height - VSLOP;

    /*Ensure we have an image format representing the options for the scalebar.*/
    msApplyOutputFormat( &format, map->outputformat,
                         map->scalebar.transparent,
                         map->scalebar.interlace,
                         MS_NOOVERRIDE );

    if(map->scalebar.transparent == MS_OFF) {
        if(!MS_VALID_COLOR(map->scalebar.imagecolor))
            MS_INIT_COLOR(map->scalebar.imagecolor,255,255,255,255);
    }
    image = msImageCreate(map->scalebar.width, sy, format,
                          map->web.imagepath, map->web.imageurl, map->resolution, map->defresolution, &map->scalebar.imagecolor);

    /* drop this reference to output format */
    msApplyOutputFormat( &format, NULL,
                         MS_NOOVERRIDE, MS_NOOVERRIDE, MS_NOOVERRIDE );

    /* did we succeed in creating the image? */
    if(!image) {
        msSetError(MS_MISCERR, "Unable to initialize image.", "msDrawScalebar()");
        return NULL;
    }

    switch(map->scalebar.align) {
    case(MS_ALIGN_LEFT):
        ox = HMARGIN;
        break;
    case(MS_ALIGN_RIGHT):
        ox = MS_NINT((map->scalebar.width - sx) + fontWidth);
        break;
    default:
        ox = MS_NINT((map->scalebar.width - sx)/2.0 + fontWidth/2.0); /* center the computed scalebar */
    }
    oy = VMARGIN;

    switch(map->scalebar.style) {
    case(0): {

        line.numpoints = 5;
        line.point = points;
        shape.line = &line;
        shape.numlines = 1;
        if(MS_VALID_COLOR(map->scalebar.color)) {
            INIT_STROKE_STYLE(strokeStyle);
            strokeStyle.color = &map->scalebar.outlinecolor;
            strokeStyle.color->alpha = 255;
            strokeStyle.width = 1;
        }
        map->scalebar.backgroundcolor.alpha = 255;
        map->scalebar.color.alpha = 255;
        state = 1; /* 1 means filled */
        for(j=0; j<map->scalebar.intervals; j++) {
            points[0].x = points[4].x = points[3].x = ox + j*isx + 0.5;
            points[0].y = points[4].y = points[1].y = oy + 0.5;
            points[1].x = points[2].x = ox + (j+1)*isx + 0.5;
            points[2].y = points[3].y = oy + map->scalebar.height + 0.5;
            if(state == 1 && MS_VALID_COLOR(map->scalebar.color))
                renderer->renderPolygon(image,&shape,&map->scalebar.color);
            else if(MS_VALID_COLOR(map->scalebar.backgroundcolor))
                renderer->renderPolygon(image,&shape,&map->scalebar.backgroundcolor);

            if(strokeStyle.color)
                renderer->renderLine(image,&shape,&strokeStyle);

            sprintf(label, "%g", j*i);
            map->scalebar.label.position = MS_CC;
            p.x = ox + j*isx; /* + MS_NINT(fontPtr->w/2); */
            p.y = oy + map->scalebar.height + MS_NINT(VSPACING*fontHeight);
            msDrawLabel(map,image,p,label,&map->scalebar.label,1.0);
            state = -state;
        }
        sprintf(label, "%g", j*i);
        ox = ox + j*isx - MS_NINT((strlen(label)*fontWidth)/2.0);
        sprintf(label, "%g %s", j*i, unitText[map->scalebar.units]);
        map->scalebar.label.position = MS_CR;
        p.x = ox; /* + MS_NINT(fontPtr->w/2); */
        p.y = oy + map->scalebar.height + MS_NINT(VSPACING*fontHeight);
        msDrawLabel(map,image,p,label,&map->scalebar.label,1.0);

        break;
    }
    case(1): {
        line.numpoints = 2;
        line.point = points;
        shape.line = &line;
        shape.numlines = 1;
        if(MS_VALID_COLOR(map->scalebar.color)) {
            strokeStyle.width = 1;
            strokeStyle.color = &map->scalebar.color;
        }

        points[0].y = points[1].y = oy;
        points[0].x = ox;
        points[1].x = ox + isx*map->scalebar.intervals;
        renderer->renderLine(image,&shape,&strokeStyle);

        points[0].y = oy;
        points[1].y = oy + map->scalebar.height;
        p.y = oy + map->scalebar.height + MS_NINT(VSPACING*fontHeight);
        for(j=0; j<=map->scalebar.intervals; j++) {
            points[0].x = points[1].x = ox + j*isx;
            renderer->renderLine(image,&shape,&strokeStyle);

            sprintf(label, "%g", j*i);
            if(j!=map->scalebar.intervals) {
                map->scalebar.label.position = MS_CC;
                p.x = ox + j*isx; /* + MS_NINT(fontPtr->w/2); */
            } else {
                sprintf(label, "%g %s", j*i, unitText[map->scalebar.units]);
                map->scalebar.label.position = MS_CR;
                p.x = ox + j*isx - MS_NINT((strlen(label)*fontWidth)/2.0);
            }
            msDrawLabel(map,image,p,label,&map->scalebar.label,1.0);
        }
        break;
    }
    default:
        msSetError(MS_MISCERR, "Unsupported scalebar style.", "msDrawScalebar()");
        return(NULL);
    }
    return(image);

}
コード例 #5
0
ファイル: maptile.c プロジェクト: msilex/mapserver
/************************************************************************
 *                            msTileExtractSubTile                      *
 *                                                                      * 
 ************************************************************************/
static imageObj* msTileExtractSubTile(const mapservObj *msObj, const imageObj *img) {
 
  int width, height, mini, minj, maxi, maxj;
  int zoom = 2;
  imageObj* imgOut = NULL;
  tileParams params;
  rendererVTableObj *renderer;
  rasterBufferObj imgBuffer;
  
  if( !MS_RENDERER_PLUGIN(msObj->map->outputformat) 
		  || msObj->map->outputformat->renderer != img->format->renderer ||
		  ! MS_MAP_RENDERER(msObj->map)->supports_pixel_buffer ) {
	  msSetError(MS_MISCERR,"unsupported or mixed renderers","msTileExtractSubTile()");
	  return NULL;
  }
  renderer = MS_MAP_RENDERER(msObj->map);
  
  if (renderer->getRasterBufferHandle((imageObj*)img,&imgBuffer) != MS_SUCCESS) {
	  return NULL;
  }
  

  /*
  ** Load the metatiling information from the map file.
  */
  msTileGetParams(msObj->map, &params);

  /*
  ** Initialize values for the metatile clip area.
  */
  width = img->width - 2*params.map_edge_buffer;
  height = img->height - 2*params.map_edge_buffer;
  mini = params.map_edge_buffer;
  minj = params.map_edge_buffer;
  maxi = img->width - params.map_edge_buffer - 1;
  maxj = img->height - params.map_edge_buffer - 1;

  if( msObj->TileMode == TILE_GMAP ) {
    int x, y, zoom;
    
    if( msObj->TileCoords ) {
      if( msTileGetGMapCoords(msObj->TileCoords, &x, &y, &zoom) == MS_FAILURE )
        return NULL;
    } 
    else {
      msSetError(MS_WEBERR, "Tile parameter not set.", "msTileSetup()");
      return NULL;
    }    

    if(msObj->map->debug)
      msDebug("msTileExtractSubTile(): gmaps coords (x: %d, y: %d)\n",x,y);

    /*
    ** The bottom N bits of the coordinates give us the subtile
    ** location relative to the metatile.
    */
    x = (0xffff ^ (0xffff << params.metatile_level)) & x;
    y = (0xffff ^ (0xffff << params.metatile_level)) & y;

    if(msObj->map->debug)
      msDebug("msTileExtractSubTile(): gmaps image coords (x: %d, y: %d)\n",x,y);
    
    mini = mini + x * params.tile_size;
    minj = minj + y * params.tile_size;

  }
  else if( msObj->TileMode == TILE_VE ) {
    int tsize;
    int i = 0;
    char j = 0;
  
    if( strlen( msObj->TileCoords ) - params.metatile_level < 0 ) {
      return(NULL);
    }
  
    /* 
    ** Process the last elements of the VE coordinate string to place the
    ** requested tile in the context of the metatile
    */
    for( i = strlen( msObj->TileCoords ) - params.metatile_level; 
         i < strlen( msObj->TileCoords ); 
         i++ ) 
    {
      j = msObj->TileCoords[i];
      tsize = width / zoom;
      if( j == '1' || j == '3' ) mini += tsize;
      if( j == '2' || j == '3' ) minj += tsize;
      zoom *= 2;
    }
  }
  else {
    return(NULL); /* Huh? Should have a mode. */
  }
  
  imgOut = msImageCreate(params.tile_size, params.tile_size, msObj->map->outputformat, NULL, NULL, msObj->map->resolution, msObj->map->defresolution, NULL);
  
  if( imgOut == NULL ) {
    return NULL;
  }
  
  if(msObj->map->debug)
    msDebug("msTileExtractSubTile(): extracting (%d x %d) tile, top corner (%d, %d)\n",params.tile_size,params.tile_size,mini,minj);
  
  
  
  renderer->mergeRasterBuffer(imgOut,&imgBuffer,1.0,mini, minj,0, 0,params.tile_size, params.tile_size);

  return imgOut;
}
コード例 #6
0
ファイル: mapsymbol.c プロジェクト: aboudreault/mapserver
/*
** Returns the size, in pixels, of a marker symbol defined by a specific style and scalefactor. Used for annotation
** layer collision avoidance. A marker is made up of a number of styles so the calling code must either do the looping
** itself or call this function for the bottom style which should be the largest.
*/
int msGetMarkerSize(symbolSetObj *symbolset, styleObj *style, double *width, double *height, double scalefactor)
{
  rectObj rect;
  int size;
  symbolObj *symbol;
  *width = *height = 0; /* set a starting value */

  if(style->symbol > symbolset->numsymbols || style->symbol < 0) return(MS_FAILURE); /* no such symbol, 0 is OK */

  if(style->symbol == 0) { /* single point */
    *width = 1;
    *height = 1;
    return(MS_SUCCESS);
  }

  symbol = symbolset->symbol[style->symbol];
  if (symbol->type == MS_SYMBOL_PIXMAP && !symbol->pixmap_buffer) {
    if (MS_SUCCESS != msPreloadImageSymbol(MS_MAP_RENDERER(symbolset->map), symbol))
      return MS_FAILURE;
  }
  if(symbol->type == MS_SYMBOL_SVG && !symbol->renderer_cache) {
#ifdef USE_SVG_CAIRO
    if(MS_SUCCESS != msPreloadSVGSymbol(symbol))
      return MS_FAILURE;
#else
    msSetError(MS_SYMERR, "SVG symbol support is not enabled.", "msGetMarkerSize()");
    return MS_FAILURE;
#endif
  }
  if(style->size == -1) {
    size = ( msSymbolGetDefaultSize(symbol) * scalefactor );
  } else
    size = (style->size*scalefactor);
  size = MS_MAX(size, style->minsize);
  size = MS_MIN(size, style->maxsize);

  switch(symbol->type) {

    case(MS_SYMBOL_TRUETYPE):
      if(msGetTruetypeTextBBox(MS_MAP_RENDERER(symbolset->map),symbol->font,symbolset->fontset,size,symbol->character,&rect,NULL,0) != MS_SUCCESS)
        return(MS_FAILURE);

      *width = MS_MAX(*width, rect.maxx - rect.minx);
      *height = MS_MAX(*height, rect.maxy - rect.miny);

      break;

    case(MS_SYMBOL_PIXMAP):
      if(size == 1) {
        *width = MS_MAX(*width, symbol->pixmap_buffer->width);
        *height = MS_MAX(*height, symbol->pixmap_buffer->height);
      } else {
        *width = MS_MAX(*width, (((double)size/(double)symbol->pixmap_buffer->height) * symbol->pixmap_buffer->width));
        *height = MS_MAX(*height, size);
      }
      break;
    default: /* vector and ellipses, scalable */
      if(style->size > 0) {
        *width = MS_MAX(*width, ((size/symbol->sizey) * symbol->sizex));
        *height = MS_MAX(*height, size);
      } else { /* use symbol defaults */
        *width = MS_MAX(*width, symbol->sizex);
        *height = MS_MAX(*height, symbol->sizey);
      }
      break;
  }

  return(MS_SUCCESS);
}