1 /******************************************************************************
2  * $Id$
3  *
4  * Project:  MapServer
5  * Purpose:  Headers for mapkmlrenderer.cpp Google Earth KML output
6  * Author:   David Kana and the MapServer team
7  *
8  ******************************************************************************
9  * Copyright (c) 1996-2009 Regents of the University of Minnesota.
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining a
12  * copy of this software and associated documentation files (the "Software"),
13  * to deal in the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15  * and/or sell copies of the Software, and to permit persons to whom the
16  * Software is furnished to do so, subject to the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be included in
19  * all copies of this Software or works derived from this Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  * DEALINGS IN THE SOFTWARE.
28  *****************************************************************************/
29 
30 
31 #ifndef MAPKMLRENDERER_H
32 #define MAPKMLRENDERER_H
33 
34 #include "mapserver-config.h"
35 #if defined(USE_KML)
36 
37 #include "mapserver.h"
38 #include "maplibxml2.h"
39 
40 
41 class KmlRenderer
42 {
43 private:
44   const char *pszLayerDescMetadata; /*if the kml_description is set*/
45   char **papszLayerIncludeItems;
46   int nIncludeItems;
47   char **papszLayerExcludeItems;
48   int nExcludeItems;
49   const char *pszLayerNameAttributeMetadata;
50 
51 protected:
52 
53   // map properties
54   int       Width, Height;
55   rectObj     MapExtent;
56   double      MapCellsize;
57   colorObj    BgColor;
58   char      MapPath[MS_MAXPATHLEN];
59 
60   // xml nodes pointers
61   xmlDocPtr XmlDoc;
62   xmlNodePtr  DocNode;
63   xmlNodePtr  LayerNode;
64   xmlNodePtr  GroundOverlayNode;
65 
66   xmlNodePtr  PlacemarkNode;
67   xmlNodePtr  GeomNode;
68   xmlNodePtr  DescriptionNode;
69 
70   int         CurrentShapeIndex;
71   int         CurrentDrawnShapeIndex;
72   char            *CurrentShapeName;
73   char    **Items;
74   int     NumItems;
75   int     DumpAttributes;
76 
77   // placemark symbology
78   hashTableObj  *StyleHashTable;
79 
80   colorObj                LabelColor;
81   strokeStyleObj          *LineStyle;
82   int                     numLineStyle;
83   colorObj    PolygonColor;
84 
85   char      SymbolName[128];
86   char      SymbolUrl[128];
87 
88   enum      { NumSymbologyFlag = 4};
89   char      SymbologyFlag[NumSymbologyFlag];
90 
91   enum      symbFlagsEnum { Label, Line, Polygon, Symbol };
92 
93   int       FirstLayer;
94 
95   mapObj                  *map;
96   layerObj                *currentLayer;
97 
98   int       AltitudeMode;
99   int       Tessellate;
100   int       Extrude;
101 
102   enum altitudeModeEnum { undefined, clampToGround, relativeToGround, absolute };
103   /**True if elevation is taken from a feature attribute*/
104   bool mElevationFromAttribute;
105   /**Attribute index of elevation (or -1 if elevation is not attribute driven*/
106   int mElevationAttributeIndex;
107   double mCurrentElevationValue;
108 
109 
110   outputFormatObj *aggFormat;
111 
112 protected:
113 
114   imageObj* createInternalImage();
115   xmlNodePtr createPlacemarkNode(xmlNodePtr parentNode, char *styleUrl);
116   xmlNodePtr createGroundOverlayNode(xmlNodePtr parentNode, char *imageHref, layerObj *layer);
117   xmlNodePtr createDescriptionNode(shapeObj *shape);
118 
119   const char* lookupSymbolUrl(imageObj *img, symbolObj *symbol, symbolStyleObj *style);
120 
121   void addCoordsNode(xmlNodePtr parentNode, pointObj *pts, int numPts);
122 
123   void setupRenderingParams(hashTableObj *layerMetadata);
124   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   void renderLineVector(imageObj *img, shapeObj *p, strokeStyleObj *style);
135   void renderPolygonVector(imageObj *img, shapeObj *p, colorObj *color);
136   void renderGlyphsVector(imageObj *img, double x, double y, labelStyleObj *style, char *text);
137 
138   const char* lookupPlacemarkStyle();
139   void flushPlacemark();
140   xmlNodePtr getGeomParentNode(const char *geomName);
141   char* getLayerName(layerObj *layer);
142   void processLayer(layerObj *layer, outputFormatObj *format);
143   void addLineStyleToList(strokeStyleObj *style);
144   const char *getAliasName(layerObj *lp, char *pszItemName, const char *namespaces);
145 
146 public:
147 
148   KmlRenderer(int width, int height, outputFormatObj *format, colorObj* color = NULL);
149   virtual ~KmlRenderer();
150 
151   imageObj* createImage(int width, int height, outputFormatObj *format, colorObj* bg);
152   int saveImage(imageObj *img, FILE *fp, outputFormatObj *format);
153 
154   int startNewLayer(imageObj *img, layerObj *layer);
155   int closeNewLayer(imageObj *img, layerObj *layer);
156 
157   void startShape(imageObj *img, shapeObj *shape);
158   void endShape(imageObj *img, shapeObj *shape);
159 
160   void renderLine(imageObj *img, shapeObj *p, strokeStyleObj *style);
161   void renderPolygon(imageObj *img, shapeObj *p, colorObj *color);
162 
163   void renderGlyphs(imageObj *img, pointObj *labelpnt, char *text, double angle, colorObj *clr, colorObj *olcolor, int olwidth);
164 
165   // Symbols
166   void renderPixmapSymbol(imageObj *img, double x, double y, symbolObj *symbol, symbolStyleObj *style);
167   void renderVectorSymbol(imageObj *img, double x, double y, symbolObj *symbol, symbolStyleObj *style);
168   void renderEllipseSymbol(imageObj *img, double x, double y, symbolObj *symbol, symbolStyleObj *style);
169   void renderTruetypeSymbol(imageObj *img, double x, double y, symbolObj *symbol, symbolStyleObj *style);
170 
171   int getTruetypeTextBBox(imageObj *img,char **fonts, int numfonts, double size, char *string, rectObj *rect, double **advances);
172   int mergeRasterBuffer(imageObj *image, rasterBufferObj *rb);
173 };
174 
175 #endif /* USE_KML */
176 #endif
177