[mapserver-commits] r9142 - sandbox/davidK

svn at osgeo.org svn at osgeo.org
Tue Jul 7 01:57:47 EDT 2009


Author: davidK
Date: 2009-07-07 01:57:46 -0400 (Tue, 07 Jul 2009)
New Revision: 9142

Modified:
   sandbox/davidK/mapkml.cpp
   sandbox/davidK/mapkml.h
   sandbox/davidK/mapkmlrenderer.cpp
   sandbox/davidK/mapkmlrenderer.h
Log:
Added ground overlay support

Modified: sandbox/davidK/mapkml.cpp
===================================================================
--- sandbox/davidK/mapkml.cpp	2009-07-06 20:27:43 UTC (rev 9141)
+++ sandbox/davidK/mapkml.cpp	2009-07-07 05:57:46 UTC (rev 9142)
@@ -1,6 +1,8 @@
 #include "mapserver.h"
 #include "mapkmlrenderer.h"
 
+#include "mapkml.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -108,7 +110,7 @@
 	return NULL;
 }
 
-void msRenderTileKml(imageObj *img, imageObj *tile, double x, double y)
+void msRenderTileKml(imageObj *img, imageObj *tile, double x, double y, double angle)
 {
 }
 
@@ -145,6 +147,12 @@
 
 void msFreeImageKml(imageObj *image)
 {
+	KmlRenderer* renderer = getKmlRenderer(image);
+	if (renderer)
+	{
+		delete renderer;
+	}
+	image->img.plugin=NULL;
 }
 
 void msFreeTileKml(void *tile)

Modified: sandbox/davidK/mapkml.h
===================================================================
--- sandbox/davidK/mapkml.h	2009-07-06 20:27:43 UTC (rev 9141)
+++ sandbox/davidK/mapkml.h	2009-07-07 05:57:46 UTC (rev 9142)
@@ -50,8 +50,8 @@
 int msGetTruetypeTextBBoxKml(imageObj *img,char *font, double size, char *string,
 		rectObj *rect, double **advances);
 
-void msStartNewLayerKml(imageObj *img, double opacity);
-void msCloseNewLayerKml(imageObj *img, double opacity);
+void msStartNewLayerKml(imageObj *img, layerObj *layer);
+void msCloseNewLayerKml(imageObj *img, layerObj *layer);
 void msTransformShapeKml(shapeObj *shape, rectObj extend, double cellsize);
 void msFreeImageKml(imageObj *image);
 void msFreeTileKml(void *tile);

Modified: sandbox/davidK/mapkmlrenderer.cpp
===================================================================
--- sandbox/davidK/mapkmlrenderer.cpp	2009-07-06 20:27:43 UTC (rev 9141)
+++ sandbox/davidK/mapkmlrenderer.cpp	2009-07-07 05:57:46 UTC (rev 9142)
@@ -9,8 +9,9 @@
 #define	LAYER_FOLDER_STYLE_URL	"#LayerFolder"
 
 KmlRenderer::KmlRenderer(int width, int height, colorObj* color/*=NULL*/) 
-	:	XmlDoc(NULL), LayerNode(NULL), FirstLayer(true), RasterizerOutputFormat(NULL),
-		UseInternalRasterizer(false)
+	:	XmlDoc(NULL), LayerNode(NULL), Width(width), Height(height),
+		FirstLayer(true), RasterizerOutputFormat(NULL),
+		VectorMode(true), RasterMode(false), MapCellsize(1.0)
 {
 	//	Create document.
     XmlDoc = xmlNewDoc(BAD_CAST "1.0");
@@ -46,6 +47,14 @@
 		msFreeOutputFormat(RasterizerOutputFormat);
 }
 
+imageObj* KmlRenderer::createInternalImage()
+{
+	renderObj *r = RasterizerOutputFormat->r;
+	imageObj *img = r->createImage(Width, Height, RasterizerOutputFormat, NULL);
+
+	return img;
+}
+
 imageObj* KmlRenderer::createImage(int width, int height, outputFormatObj *format, colorObj* bg)
 {
 	return NULL;
@@ -53,6 +62,13 @@
 
 int KmlRenderer::saveImage(imageObj *img, FILE *fp, outputFormatObj *format)
 {
+	// 
+	if (InternalImg)
+	{
+		//sprintf(mapserv->Id, "%ld%d", (long)time(NULL), (int)getpid());
+		createGroundOverlayNode();
+	}
+
 	/* -------------------------------------------------------------------- */
 	/*      Write out the document.                                         */
 	/* -------------------------------------------------------------------- */
@@ -165,6 +181,10 @@
 	{
 		FirstLayer = false;
 
+		// map rect for ground overlay
+		MapExtent = layer->map->extent;
+		MapCellsize = layer->map->cellsize;
+
 		if (layer->map->name)
 			xmlNewChild(DocNode, NULL, BAD_CAST "name", BAD_CAST layer->map->name);
 
@@ -177,6 +197,7 @@
 			if(!strcasecmp(iFormat->driver,"cairo/png"))
 			{
 				RasterizerOutputFormat = msCloneOutputFormat(iFormat);
+				InternalImg = createInternalImage();
 			}
 		}
 	}
@@ -197,7 +218,7 @@
 	return placemarkNode;
 }
 
-void KmlRenderer::renderLine(imageObj *img, shapeObj *p, strokeStyleObj *style)
+void KmlRenderer::renderLineVector(imageObj *img, shapeObj *p, strokeStyleObj *style)
 {
 	xmlNodePtr placemarkNode = createPlacemarkNode(LayerNode, lookupLineStyle(style));
 
@@ -219,8 +240,30 @@
 	}
 }
 
-void KmlRenderer::renderPolygon(imageObj *img, shapeObj *p, colorObj *color)
+void KmlRenderer::renderLine(imageObj *img, shapeObj *p, strokeStyleObj *style)
 {
+	if (VectorMode)
+		renderLineVector(img, p, style);
+
+	if (RasterMode)
+	{
+		shapeObj rasShape;
+
+		// internal renderer used for rasterizing
+		renderObj *r = RasterizerOutputFormat->r;
+
+		msInitShape(&rasShape);
+		msCopyShape(p,&rasShape);
+
+		r->transformShape(&rasShape, MapExtent, MapCellsize);
+
+		r->renderLine(InternalImg, &rasShape, style);
+		msFreeShape(&rasShape);
+	}
+}
+
+void KmlRenderer::renderPolygonVector(imageObj *img, shapeObj *p, colorObj *color)
+{
 	xmlNodePtr placemarkNode = createPlacemarkNode(LayerNode, lookupPolyStyle(color));
 	xmlNodePtr polygonNode = xmlNewChild(placemarkNode, NULL, BAD_CAST "Polygon", NULL);
 
@@ -239,6 +282,28 @@
 	}
 }
 
+void KmlRenderer::renderPolygon(imageObj *img, shapeObj *p, colorObj *color)
+{
+	if (VectorMode)
+		renderPolygonVector(img, p, color);
+
+	if (RasterMode)
+	{
+		shapeObj rasShape;
+
+		// internal renderer used for rasterizing
+		renderObj *r = RasterizerOutputFormat->r;
+
+		msInitShape(&rasShape);
+		msCopyShape(p,&rasShape);
+
+		r->transformShape(&rasShape, MapExtent, MapCellsize);
+
+		r->renderPolygon(InternalImg, rasShape, color);
+		msFreeShape(&rasShape);
+	}
+}
+
 void KmlRenderer::addCoordsNode(xmlNodePtr parentNode, pointObj *pts, int numPts)
 {
 	char lineBuf[128];
@@ -353,7 +418,7 @@
 	return NULL;
 }
 
-void KmlRenderer::renderGlyphs(imageObj *img, double x, double y, labelStyleObj *style, char *text)
+void KmlRenderer::renderGlyphsVector(imageObj *img, double x, double y, labelStyleObj *style, char *text)
 {
 	xmlNodePtr placemarkNode = createPlacemarkNode(LayerNode, lookupPointStyle(&style->color));
 	xmlNewChild(placemarkNode, NULL, BAD_CAST "name", BAD_CAST text);
@@ -366,14 +431,37 @@
 	addCoordsNode(pointNode, &pt, 1);
 }
 
+void KmlRenderer::renderGlyphs(imageObj *img, double x, double y, labelStyleObj *style, char *text)
+{
+	if (VectorMode)
+		renderGlyphsVector(img, x, y, style, text);
+
+	if (RasterMode)
+	{
+		// internal renderer used for rasterizing
+		renderObj *r = RasterizerOutputFormat->r;
+		r->renderGlyphs(InternalImg, x, y, style, text);
+	}
+}
+
 int KmlRenderer::getTruetypeTextBBox(imageObj *img,char *font, double size, char *string,
 		rectObj *rect, double **advances)
 {
-    rect->minx=0.0;
-    rect->maxx=0.0;
-    rect->miny=0.0;
-    rect->maxy=0.0;
+	if (VectorMode)
+	{
+		// TODO
+		rect->minx=0.0;
+		rect->maxx=0.0;
+		rect->miny=0.0;
+		rect->maxy=0.0;
+	}
 
+	if (RasterMode)
+	{
+		renderObj *r = RasterizerOutputFormat->r;
+		r->getTruetypeTextBBox(InternalImg, font, size, string, rect, advances);
+	}
+
 	return true;
 }
 
@@ -399,31 +487,6 @@
 		xmlNewChild(node, NULL, BAD_CAST "altitudeMode", BAD_CAST "clampToGround");
 }
 
-void KmlRenderer::renderPixmapSymbol(imageObj *img, double x, double y, symbolObj *symbol, symbolStyleObj *style)
-{
-	if (RasterizerOutputFormat)
-	{
-		if (UseInternalRasterizer)
-		{
-			
-		}
-		else
-		{
-			char *symbolUrl = lookupSymbolStyle(symbol, style);
-
-			xmlNodePtr placemarkNode = createPlacemarkNode(LayerNode, symbolUrl);
-			xmlNewChild(placemarkNode, NULL, BAD_CAST "name", NULL);
-			xmlNodePtr pointNode = xmlNewChild(placemarkNode, NULL, BAD_CAST "Point", NULL);
-
-			addAddRenderingSpecifications(pointNode);
-
-			pointObj pt;
-			pt.x = x; pt.y = y;
-			addCoordsNode(pointNode, &pt, 1);
-		}
-	}
-}
-
 char* KmlRenderer::lookupSymbolStyle(symbolObj *symbol, symbolStyleObj *style)
 {
 	/*	
@@ -461,7 +524,7 @@
 		xmlNewChild(iconStyleNode, NULL, BAD_CAST "scale", BAD_CAST scale);
 
 		char iconFileName[512];
-		sprintf(iconFileName, "symbol_%s_%.1f", symbol->name, style->scale); // __TODO__ add WEB IMAGEURL path
+		sprintf(iconFileName, "symbol_%s_%.1f.%s", symbol->name, style->scale, MS_IMAGE_EXTENSION(RasterizerOutputFormat)); // __TODO__ add WEB IMAGEURL path
 		if (createIconImage(iconFileName, symbol, style) != MS_SUCCESS)
 		{
 			char errMsg[512];
@@ -534,4 +597,117 @@
 	return status;
 }
 
+void KmlRenderer::createSymbolPlacemark(imageObj *img, double x, double y, symbolObj *symbol, symbolStyleObj *style)
+{
+	char *symbolUrl = lookupSymbolStyle(symbol, style);
+
+	xmlNodePtr placemarkNode = createPlacemarkNode(LayerNode, symbolUrl);
+	xmlNewChild(placemarkNode, NULL, BAD_CAST "name", NULL);
+	xmlNodePtr pointNode = xmlNewChild(placemarkNode, NULL, BAD_CAST "Point", NULL);
+
+	addAddRenderingSpecifications(pointNode);
+
+	pointObj pt;
+	pt.x = x; pt.y = y;
+	addCoordsNode(pointNode, &pt, 1);
+}
+
+void KmlRenderer::renderPixmapSymbol(imageObj *img, double x, double y, symbolObj *symbol, symbolStyleObj *style)
+{
+	if (VectorMode)
+		createSymbolPlacemark(img, x, y, symbol, style);
+
+	if (RasterMode)
+	{
+		renderObj *r = RasterizerOutputFormat->r;
+		r->renderPixmapSymbol(InternalImg, x, y, symbol, style);
+	}
+}
+
+void KmlRenderer::renderVectorSymbol(imageObj *img, double x, double y, symbolObj *symbol, symbolStyleObj *style)
+{
+	if (VectorMode)
+		createSymbolPlacemark(img, x, y, symbol, style);
+
+	if (RasterMode)
+	{
+		renderObj *r = RasterizerOutputFormat->r;
+		r->renderVectorSymbol(InternalImg, x, y, symbol, style);
+	}
+}
+
+void KmlRenderer::renderEllipseSymbol(imageObj *img, double x, double y, symbolObj *symbol, symbolStyleObj *style)
+{
+	if (VectorMode)
+		createSymbolPlacemark(img, x, y, symbol, style);
+
+	if (RasterMode)
+	{
+		renderObj *r = RasterizerOutputFormat->r;
+		r->renderEllipseSymbol(InternalImg, x, y, symbol, style);
+	}
+}
+
+void KmlRenderer::renderTruetypeSymbol(imageObj *img, double x, double y, symbolObj *symbol, symbolStyleObj *style)
+{
+	if (VectorMode)
+		createSymbolPlacemark(img, x, y, symbol, style);
+
+	if (RasterMode)
+	{
+		renderObj *r = RasterizerOutputFormat->r;
+		r->renderTruetypeSymbol(InternalImg, x, y, symbol, style);
+	}
+}
+
+void KmlRenderer::createGroundOverlayNode(char *imageHref)
+{
+	/*
+	<?xml version="1.0" encoding="UTF-8"?>
+	<kml xmlns="http://www.opengis.net/kml/2.2">
+	<GroundOverlay>
+	   <name>GroundOverlay.kml</name>
+	   <color>7fffffff</color>
+	   <drawOrder>1</drawOrder>
+	   <Icon>
+		  <href>http://www.google.com/intl/en/images/logo.gif</href>
+		  <refreshMode>onInterval</refreshMode>
+		  <refreshInterval>86400</refreshInterval>
+		  <viewBoundScale>0.75</viewBoundScale>
+	   </Icon>
+	   <LatLonBox>
+		  <north>37.83234</north>
+		  <south>37.832122</south>
+		  <east>-122.373033</east>
+		  <west>-122.373724</west>
+		  <rotation>45</rotation>
+	   </LatLonBox>
+	</GroundOverlay>
+	</kml>
+	*/
+
+	xmlNodePtr groundOverlayNode = xmlNewChild(DocNode, NULL, BAD_CAST "GroundOverlay", NULL);
+	xmlNewChild(groundOverlayNode, NULL, BAD_CAST "color", BAD_CAST "ffffffff");
+	xmlNewChild(groundOverlayNode, NULL, BAD_CAST "drawOrder", BAD_CAST "1");
+
+	xmlNodePtr iconNode = xmlNewChild(groundOverlayNode, NULL, BAD_CAST "Icon", NULL);
+	xmlNewChild(iconNode, NULL, BAD_CAST "href", BAD_CAST imageHref);
+
+	char crdStr[64];
+	xmlNodePtr latLonBoxNode = xmlNewChild(groundOverlayNode, NULL, BAD_CAST "LatLonBox", NULL);
+	sprintf(crdStr, "%.8f", MapExtent.maxy);
+	xmlNewChild(latLonBoxNode, NULL, BAD_CAST "north", BAD_CAST crdStr);
+
+	sprintf(crdStr, "%.8f", MapExtent.miny);
+	xmlNewChild(latLonBoxNode, NULL, BAD_CAST "south", BAD_CAST crdStr);
+
+	sprintf(crdStr, "%.8f", MapExtent.minx);
+	xmlNewChild(latLonBoxNode, NULL, BAD_CAST "west", BAD_CAST crdStr);
+
+	sprintf(crdStr, "%.8f", MapExtent.maxx);
+	xmlNewChild(latLonBoxNode, NULL, BAD_CAST "east", BAD_CAST crdStr);
+
+	xmlNewChild(latLonBoxNode, NULL, BAD_CAST "rotation", BAD_CAST "0.0");
+}
+
 #endif
\ No newline at end of file

Modified: sandbox/davidK/mapkmlrenderer.h
===================================================================
--- sandbox/davidK/mapkmlrenderer.h	2009-07-06 20:27:43 UTC (rev 9141)
+++ sandbox/davidK/mapkmlrenderer.h	2009-07-07 05:57:46 UTC (rev 9142)
@@ -15,6 +15,8 @@
 	xmlNodePtr	DocNode;
 	xmlNodePtr	LayerNode;
 
+	int			Width, Height;
+
 	hashTableObj *StyleHashTable;
 
 	int			AltitudeMode;
@@ -25,15 +27,24 @@
 
 	// internal output format containing cairo renderer used for rasterizing and rendering symbols
 	outputFormatObj	*RasterizerOutputFormat;
+	imageObj		*InternalImg;
 
-	// true - features are rasterized, false - features are written directly in kml
-	int			UseInternalRasterizer;
+	rectObj			MapExtent;
+	double			MapCellsize;
 
+	// if true - features are rasterized
+	int	VectorMode;
+
+	// if true - features are written directly in kml
+	int	RasterMode;
+
 	enum altitudeModeEnum { undefined, clampToGround, relativeToGround, absolute };
 
 protected:
 
+	imageObj* createInternalImage();
 	xmlNodePtr createPlacemarkNode(xmlNodePtr parentNode, char *styleUrl);
+	void createGroundOverlayNode(char *imageHref);
 
 	char* lookupPointStyle(colorObj *color);
 	char* lookupLineStyle(strokeStyleObj *strokeStyle);
@@ -50,6 +61,14 @@
 
 	int createIconImage(char *fileName, symbolObj *symbol, symbolStyleObj *style);
 
+	void createSymbolPlacemark(imageObj *img, double x, double y, symbolObj *symbol, symbolStyleObj *style);
+
+	//////////////////////////////////////////////////////////////////////////////
+
+	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);
+
 public:
 
 	KmlRenderer(int width, int height, colorObj* color = NULL);
@@ -67,10 +86,13 @@
 
 	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 *font, double size, char *string,
-		rectObj *rect, double **advances);
+	int getTruetypeTextBBox(imageObj *img,char *font, double size, char *string, rectObj *rect, double **advances);
 };
 
 #endif /* USE_KML && USE_LIBXML2*/



More information about the mapserver-commits mailing list