Exemple #1
0
/**********************************************************************
 * class extensions for layerObj, always within the context of a map
 **********************************************************************/
layerObj *layerObj_new(mapObj *map) {
    if(msGrowMapLayers(map) == NULL)
      return(NULL);

    if(initLayer((map->layers[map->numlayers]), map) == -1)
      return(NULL);

    map->layers[map->numlayers]->index = map->numlayers;
    //Update the layer order list with the layer's index.
    map->layerorder[map->numlayers] = map->numlayers;

    map->numlayers++;

    return (map->layers[map->numlayers-1]);
  }
Exemple #2
0
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) {
Exemple #3
0
int msInsertLayer(mapObj *map, layerObj *layer, int nIndex)
{
  if (!layer) {
    msSetError(MS_CHILDERR, "Can't insert a NULL Layer", "msInsertLayer()");
    return -1;
  }

  /* Ensure there is room for a new layer */
  if (map->numlayers == map->maxlayers) {
    if (msGrowMapLayers(map) == NULL)
      return -1;
  }

  /* msGrowMapLayers allocates the new layer which we don't need to do since we have 1 that we are inserting
                  not sure if it is possible for this to be non null otherwise, but better to check since this function
                  replaces the value */
  if (map->layers[map->numlayers]!=NULL)
    free(map->layers[map->numlayers]);

  /* Catch attempt to insert past end of layers array */
  if (nIndex >= map->numlayers) {
    msSetError(MS_CHILDERR, "Cannot insert layer beyond index %d",
               "msInsertLayer()", map->numlayers-1);
    return -1;
  } else if (nIndex < 0) { /* Insert at the end by default */
    map->layerorder[map->numlayers] = map->numlayers;
    GET_LAYER(map, map->numlayers) = layer;
    GET_LAYER(map, map->numlayers)->index = map->numlayers;
    GET_LAYER(map, map->numlayers)->map = map;
    MS_REFCNT_INCR(layer);
    map->numlayers++;
    return map->numlayers-1;
  } else if (nIndex >= 0 && nIndex < map->numlayers) {
    /* Move existing layers at the specified nIndex or greater */
    /* to an index one higher */
    int i;
    for (i=map->numlayers; i>nIndex; i--) {
      GET_LAYER(map, i)=GET_LAYER(map, i-1);
      GET_LAYER(map, i)->index = i;
    }

    /* assign new layer to specified index */
    GET_LAYER(map, nIndex)=layer;
    GET_LAYER(map, nIndex)->index = nIndex;
    GET_LAYER(map, nIndex)->map = map;

    /* adjust layers drawing order */
    for (i=map->numlayers; i>nIndex; i--) {
      map->layerorder[i] = map->layerorder[i-1];
      if (map->layerorder[i] >= nIndex) map->layerorder[i]++;
    }
    for (i=0; i<nIndex; i++) {
      if (map->layerorder[i] >= nIndex) map->layerorder[i]++;
    }
    map->layerorder[nIndex] = nIndex;

    /* increment number of layers and return */
    MS_REFCNT_INCR(layer);
    map->numlayers++;
    return nIndex;
  } else {
    msSetError(MS_CHILDERR, "Invalid index", "msInsertLayer()");
    return -1;
  }
}