mapkmlrenderer.h 6.09 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 mapkmlrenderer.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
 * 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.
 *****************************************************************************/


#ifndef MAPKMLRENDERER_H
#define MAPKMLRENDERER_H

34
#include "mapserver-config.h"
35 36 37 38 39 40 41 42
#if defined(USE_KML)

#include "mapserver.h"
#include "maplibxml2.h"


class KmlRenderer
{
43 44 45 46 47 48 49
private:
  const char *pszLayerDescMetadata; /*if the kml_description is set*/
  char **papszLayerIncludeItems;
  int nIncludeItems;
  char **papszLayerExcludeItems;
  int nExcludeItems;
  char *pszLayerNameAttributeMetadata;
50

51
protected:
52

53 54 55 56 57 58
  // map properties
  int       Width, Height;
  rectObj     MapExtent;
  double      MapCellsize;
  colorObj    BgColor;
  char      MapPath[MS_MAXPATHLEN];
59

60 61 62 63 64
  // xml nodes pointers
  xmlDocPtr XmlDoc;
  xmlNodePtr  DocNode;
  xmlNodePtr  LayerNode;
  xmlNodePtr  GroundOverlayNode;
65

66 67 68
  xmlNodePtr  PlacemarkNode;
  xmlNodePtr  GeomNode;
  xmlNodePtr  DescriptionNode;
69

70 71 72 73 74 75
  int         CurrentShapeIndex;
  int         CurrentDrawnShapeIndex;
  char            *CurrentShapeName;
  char    **Items;
  int     NumItems;
  int     DumpAttributes;
76

77 78
  // placemark symbology
  hashTableObj  *StyleHashTable;
79

80 81 82 83
  labelStyleObj         LabelStyle;
  strokeStyleObj          *LineStyle;
  int                     numLineStyle;
  colorObj    PolygonColor;
84

85 86
  char      SymbolName[128];
  char      SymbolUrl[128];
87

88 89
  enum      { NumSymbologyFlag = 4};
  char      SymbologyFlag[NumSymbologyFlag];
90

91
  enum      symbFlagsEnum { Label, Line, Polygon, Symbol };
92

93
  int       FirstLayer;
94

95 96
  mapObj                  *map;
  layerObj                *currentLayer;
97

98 99 100
  int       AltitudeMode;
  int       Tessellate;
  int       Extrude;
101

102 103 104 105 106 107
  enum altitudeModeEnum { undefined, clampToGround, relativeToGround, absolute };
  /**True if elevation is taken from a feature attribute*/
  bool mElevationFromAttribute;
  /**Attribute index of elevation (or -1 if elevation is not attribute driven*/
  int mElevationAttributeIndex;
  double mCurrentElevationValue;
108 109


110
  outputFormatObj *aggFormat;
111

112
protected:
113

114 115 116 117
  imageObj* createInternalImage();
  xmlNodePtr createPlacemarkNode(xmlNodePtr parentNode, char *styleUrl);
  xmlNodePtr createGroundOverlayNode(xmlNodePtr parentNode, char *imageHref, layerObj *layer);
  xmlNodePtr createDescriptionNode(shapeObj *shape);
118

119
  char* lookupSymbolUrl(imageObj *img, symbolObj *symbol, symbolStyleObj *style);
120

121
  void addCoordsNode(xmlNodePtr parentNode, pointObj *pts, int numPts);
122

123 124
  void setupRenderingParams(hashTableObj *layerMetadata);
  void addAddRenderingSpecifications(xmlNodePtr node);
125

126
  int checkProjection(mapObj *map);
127

128
  int createIconImage(char *fileName, symbolObj *symbol, symbolStyleObj *style);
129

130
  void renderSymbol(imageObj *img, double x, double y, symbolObj *symbol, symbolStyleObj *style);
131

132
  //////////////////////////////////////////////////////////////////////////////
133

134 135 136
  void renderLineVector(imageObj *img, shapeObj *p, strokeStyleObj *style);
  void renderPolygonVector(imageObj *img, shapeObj *p, colorObj *color);
  void renderGlyphsVector(imageObj *img, double x, double y, labelStyleObj *style, char *text);
137

138 139 140 141 142 143 144
  char* lookupPlacemarkStyle();
  void flushPlacemark();
  xmlNodePtr getGeomParentNode(const char *geomName);
  char* getLayerName(layerObj *layer);
  void processLayer(layerObj *layer, outputFormatObj *format);
  void addLineStyleToList(strokeStyleObj *style);
  const char *getAliasName(layerObj *lp, char *pszItemName, const char *namespaces);
145

146
public:
147

148 149
  KmlRenderer(int width, int height, outputFormatObj *format, colorObj* color = NULL);
  virtual ~KmlRenderer();
150

151 152
  imageObj* createImage(int width, int height, outputFormatObj *format, colorObj* bg);
  int saveImage(imageObj *img, FILE *fp, outputFormatObj *format);
153

154 155
  int startNewLayer(imageObj *img, layerObj *layer);
  int closeNewLayer(imageObj *img, layerObj *layer);
156

157 158
  void startShape(imageObj *img, shapeObj *shape);
  void endShape(imageObj *img, shapeObj *shape);
159

160 161 162 163 164 165 166 167 168 169 170 171 172
  void renderLine(imageObj *img, shapeObj *p, strokeStyleObj *style);
  void renderPolygon(imageObj *img, shapeObj *p, colorObj *color);

  void renderGlyphs(imageObj *img, double x, double y, labelStyleObj *style, char *text);

  // Symbols
  void renderPixmapSymbol(imageObj *img, double x, double y, symbolObj *symbol, symbolStyleObj *style);
  void renderVectorSymbol(imageObj *img, double x, double y, symbolObj *symbol, symbolStyleObj *style);
  void renderEllipseSymbol(imageObj *img, double x, double y, symbolObj *symbol, symbolStyleObj *style);
  void renderTruetypeSymbol(imageObj *img, double x, double y, symbolObj *symbol, symbolStyleObj *style);

  int getTruetypeTextBBox(imageObj *img,char **fonts, int numfonts, double size, char *string, rectObj *rect, double **advances);
  int mergeRasterBuffer(imageObj *image, rasterBufferObj *rb);
173 174 175 176
};

#endif /* USE_KML */
#endif