mapkml.cpp 7.84 KB
Newer Older
1
/******************************************************************************
2
 * $Id$
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
 *
 * Project:  MapServer
 * Purpose:  Headers for mapkml.cpp Google Earth KML output
 * Author:   David Kana and the MapServer team
 *
 ******************************************************************************
 * Copyright (c) 1996-2009 Regents of the University of Minnesota.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
18
 * The above copyright notice and this permission notice shall be included in
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
 * all copies of this Software or works derived from this Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 *****************************************************************************/
#include "mapserver.h"

#ifdef USE_KML

#include "mapkmlrenderer.h"

#ifdef __cplusplus
extern "C" {
#endif

39 40
  KmlRenderer* getKmlRenderer(imageObj* img)
  {
41
    return (KmlRenderer*) img->img.plugin;
42
  }
43

44 45
  imageObj* msCreateImageKml(int width, int height, outputFormatObj *format, colorObj* bg)
  {
46 47 48 49 50 51 52 53 54 55
    imageObj *image = NULL;

    image = (imageObj*)malloc(sizeof(imageObj));
    MS_CHECK_ALLOC(image, sizeof(imageObj), NULL);
    memset(image, 0, sizeof(imageObj));

    KmlRenderer *ren = new KmlRenderer(width, height, format, bg);
    image->img.plugin = (void *) ren;

    return image;
56
  }
57

58 59
  int msSaveImageKml(imageObj *img, mapObj* map, FILE *fp, outputFormatObj *format)
  {
60 61
    KmlRenderer* renderer = getKmlRenderer(img);
    return renderer->saveImage(img, fp, format);
62
  }
63

64 65
  int msRenderLineKml(imageObj *img, shapeObj *p, strokeStyleObj *style)
  {
66 67 68
    KmlRenderer* renderer = getKmlRenderer(img);
    renderer->renderLine(img, p, style);
    return MS_SUCCESS;
69
  }
70

71 72
  int msRenderPolygonKml(imageObj *img, shapeObj *p, colorObj *color)
  {
73 74 75
    KmlRenderer* renderer = getKmlRenderer(img);
    renderer->renderPolygon(img, p, color);
    return MS_SUCCESS;
76
  }
77

78 79
  int msRenderPolygonTiledKml(imageObj *img, shapeObj *p,  imageObj *tile)
  {
80 81
    /*KmlRenderer* renderer = getKmlRenderer(img);*/
    return MS_SUCCESS;
82
  }
83

84 85
  int msRenderLineTiledKml(imageObj *img, shapeObj *p, imageObj *tile)
  {
86
    return MS_SUCCESS;
87
  }
88

89
  int msRenderGlyphsKml(imageObj *img, pointObj *labelpnt, char *text, double angle, colorObj *clr, colorObj *olcolor, int olwidth)
90
  {
91
    KmlRenderer* renderer = getKmlRenderer(img);
92
    renderer->renderGlyphs(img, labelpnt, text, angle, clr, olcolor, olwidth);
93
    return MS_SUCCESS;
94
  }
95

96 97 98
  int msRenderVectorSymbolKml(imageObj *img, double x, double y,
                              symbolObj *symbol, symbolStyleObj *style)
  {
99 100 101
    KmlRenderer* renderer = getKmlRenderer(img);
    renderer->renderVectorSymbol(img, x, y, symbol, style);
    return MS_SUCCESS;
102
  }
103

104 105 106
  int msRenderPixmapSymbolKml(imageObj *img, double x, double y,
                              symbolObj *symbol, symbolStyleObj *style)
  {
107 108 109
    KmlRenderer* renderer = getKmlRenderer(img);
    renderer->renderPixmapSymbol(img, x, y, symbol, style);
    return MS_SUCCESS;
110
  }
111

112 113 114
  int msRenderEllipseSymbolKml(imageObj *image, double x, double y,
                               symbolObj *symbol, symbolStyleObj *style)
  {
115 116 117
    KmlRenderer* renderer = getKmlRenderer(image);
    renderer->renderEllipseSymbol(image, x, y, symbol, style);
    return MS_SUCCESS;
118
  }
119

120 121 122
  int msRenderTruetypeSymbolKml(imageObj *image, double x, double y,
                                symbolObj *symbol, symbolStyleObj *style)
  {
123 124 125
    KmlRenderer* renderer = getKmlRenderer(image);
    renderer->renderTruetypeSymbol(image, x, y, symbol, style);
    return MS_SUCCESS;
126
  }
127 128


129 130
  int msRenderTileKml(imageObj *img, imageObj *tile, double x, double y)
  {
131
    return MS_SUCCESS;
132
  }
133

134 135
  int msGetRasterBufferKml(imageObj *img,rasterBufferObj *rb)
  {
136
    return MS_FAILURE; //not supported for kml
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
  }


  int msGetTruetypeTextBBoxKml(rendererVTableObj *r,char** fonts, int numfonts, double size, char *string,
                               rectObj *rect, double **advances, int bAdjustBaseline)
  {
    rect->minx=0.0;
    rect->maxx=0.0;
    rect->miny=0.0;
    rect->maxy=0.0;
    if (advances) {
      int numglyphs = msGetNumGlyphs(string);
      *advances = (double*) msSmallMalloc(numglyphs * sizeof (double));
      for(int i=0; i<numglyphs; i++) {
        (*advances)[i] = size;
      }
    }
    return MS_SUCCESS;
  }
156

157 158
  int msStartNewLayerKml(imageObj *img, mapObj *map, layerObj *layer)
  {
159 160
    KmlRenderer* renderer = getKmlRenderer(img);
    return renderer->startNewLayer(img, layer);
161
  }
162

163 164
  int msCloseNewLayerKml(imageObj *img, mapObj *map, layerObj *layer)
  {
165 166
    KmlRenderer* renderer = getKmlRenderer(img);
    return renderer->closeNewLayer(img, layer);
167
  }
168

169 170
  int msFreeImageKml(imageObj *image)
  {
171
    KmlRenderer* renderer = getKmlRenderer(image);
172 173
    if (renderer) {
      delete renderer;
174 175 176
    }
    image->img.plugin=NULL;
    return MS_SUCCESS;
177
  }
178

179 180
  int msFreeSymbolKml(symbolObj *symbol)
  {
181
    return MS_SUCCESS;
182
  }
183

184 185
  int msStartShapeKml(imageObj *img, shapeObj *shape)
  {
186 187 188
    KmlRenderer* renderer = getKmlRenderer(img);
    renderer->startShape(img, shape);
    return MS_SUCCESS;
189
  }
190

191 192
  int msEndShapeKml(imageObj *img, shapeObj *shape)
  {
193 194 195
    KmlRenderer* renderer = getKmlRenderer(img);
    renderer->endShape(img, shape);
    return MS_SUCCESS;
196
  }
197

198 199 200
  int msMergeRasterBufferKml(imageObj *dest, rasterBufferObj *overlay, double opacity, int srcX,
                             int srcY, int dstX, int dstY, int width, int height)
  {
201 202
    KmlRenderer* renderer = getKmlRenderer(dest);
    return renderer->mergeRasterBuffer(dest,overlay);
203
  }
204 205 206 207 208 209 210 211 212 213 214 215 216

#ifdef __cplusplus
}
#endif


#endif /*USE_KML*/

int aggInitializeRasterBuffer(rasterBufferObj *rb, int width, int height, int mode);

int msPopulateRendererVTableKML( rendererVTableObj *renderer )
{
#ifdef USE_KML
217 218 219 220 221 222 223 224 225 226 227
  renderer->supports_pixel_buffer = 0;
  renderer->supports_clipping = 0;
  renderer->use_imagecache = 0;
  renderer->default_transform_mode = MS_TRANSFORM_NONE;

  renderer->startLayer = msStartNewLayerKml;
  renderer->endLayer = msCloseNewLayerKml;
  renderer->renderLine=&msRenderLineKml;
  renderer->createImage=&msCreateImageKml;
  renderer->saveImage=&msSaveImageKml;
  renderer->renderPolygon=&msRenderPolygonKml;
228
  renderer->renderText=&msRenderGlyphsKml;
229 230 231 232 233 234 235 236 237 238 239 240
  renderer->renderEllipseSymbol = &msRenderEllipseSymbolKml;
  renderer->renderVectorSymbol = &msRenderVectorSymbolKml;
  renderer->renderPixmapSymbol = &msRenderPixmapSymbolKml;
  renderer->mergeRasterBuffer = &msMergeRasterBufferKml;
  renderer->loadImageFromFile = msLoadMSRasterBufferFromFile;
  renderer->initializeRasterBuffer = aggInitializeRasterBuffer;
  renderer->renderTile = &msRenderTileKml;
  renderer->renderPolygonTiled = &msRenderPolygonTiledKml;
  renderer->renderLineTiled = NULL;
  renderer->freeSymbol = &msFreeSymbolKml;
  renderer->freeImage=&msFreeImageKml;
  renderer->mergeRasterBuffer = msMergeRasterBufferKml;
241
  renderer->compositeRasterBuffer = NULL;
242 243 244 245 246

  renderer->startShape=&msStartShapeKml;
  renderer->endShape=&msEndShapeKml;

  return MS_SUCCESS;
247
#else
248 249 250
  msSetError(MS_MISCERR, "KML Driver requested but is not built in",
             "msPopulateRendererVTableKML()");
  return MS_FAILURE;
251 252 253
#endif
}