[mapserver-commits] r9116 - sandbox/davidK
svn at osgeo.org
svn at osgeo.org
Sun Jun 21 19:08:13 EDT 2009
Author: davidK
Date: 2009-06-21 19:08:13 -0400 (Sun, 21 Jun 2009)
New Revision: 9116
Modified:
sandbox/davidK/mapkml.cpp
sandbox/davidK/mapkmlrenderer.cpp
sandbox/davidK/mapkmlrenderer.h
Log:
added support for symbol rendering
Modified: sandbox/davidK/mapkml.cpp
===================================================================
--- sandbox/davidK/mapkml.cpp 2009-06-21 18:47:46 UTC (rev 9115)
+++ sandbox/davidK/mapkml.cpp 2009-06-21 23:08:13 UTC (rev 9116)
@@ -76,6 +76,8 @@
void msRenderPixmapSymbolKml(imageObj *img, double x, double y,
symbolObj *symbol, symbolStyleObj *style)
{
+ KmlRenderer* renderer = getKmlRenderer(img);
+ renderer->renderPixmapSymbol(img, x, y, symbol, style);
}
void* msCreatePixmapSymbolTileKml(int width, int height,
Modified: sandbox/davidK/mapkmlrenderer.cpp
===================================================================
--- sandbox/davidK/mapkmlrenderer.cpp 2009-06-21 18:47:46 UTC (rev 9115)
+++ sandbox/davidK/mapkmlrenderer.cpp 2009-06-21 23:08:13 UTC (rev 9116)
@@ -9,7 +9,8 @@
#define LAYER_FOLDER_STYLE_URL "#LayerFolder"
KmlRenderer::KmlRenderer(int width, int height, colorObj* color/*=NULL*/)
- : XmlDoc(NULL), LayerNode(NULL), FirstLayer(true)
+ : XmlDoc(NULL), LayerNode(NULL), FirstLayer(true), RasterizerOutputFormat(NULL),
+ UseInternalRasterizer(false)
{
// Create document.
XmlDoc = xmlNewDoc(BAD_CAST "1.0");
@@ -40,6 +41,9 @@
msFreeHashTable(StyleHashTable);
xmlCleanupParser();
+
+ if (RasterizerOutputFormat)
+ msFreeOutputFormat(RasterizerOutputFormat);
}
imageObj* KmlRenderer::createImage(int width, int height, outputFormatObj *format, colorObj* bg)
@@ -159,12 +163,22 @@
if (FirstLayer)
{
+ FirstLayer = false;
+
if (layer->map->name)
xmlNewChild(DocNode, NULL, BAD_CAST "name", BAD_CAST layer->map->name);
// First rendered layer - check mapfile projection
checkProjection(&layer->map->projection);
- FirstLayer = false;
+
+ for (int i=0; i<layer->map->numoutputformats; i++)
+ {
+ outputFormatObj *iFormat = layer->map->outputformatlist[i];
+ if(!strcasecmp(iFormat->driver,"cairo/png"))
+ {
+ RasterizerOutputFormat = msCloneOutputFormat(iFormat);
+ }
+ }
}
}
@@ -385,5 +399,139 @@
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)
+{
+ /*
+ <Style id="randomColorIcon">
+ <IconStyle>
+ <color>ff00ff00</color>
+ <colorMode>random</colorMode>
+ <scale>1.1</scale>
+ <Icon>
+ <href>http://maps.google.com/mapfiles/kml/pal3/icon21.png</href>
+ </Icon>
+ </IconStyle>
+ </Style>
+ */
+
+ char styleName[128];
+ sprintf(styleName, "symbol_%s_%.1f", symbol->name, style->scale);
+
+ char *styleUrl = msLookupHashTable(StyleHashTable, styleName);
+ if (!styleUrl)
+ {
+ char styleValue[32];
+ sprintf(styleValue, "#%s", styleName);
+
+ hashObj *hash = msInsertHashTable(StyleHashTable, styleName, styleValue);
+ styleUrl = hash->data;
+
+ // Insert new IconStyle node into Document node
+ xmlNodePtr styleNode = xmlNewChild(DocNode, NULL, BAD_CAST "Style", NULL);
+ xmlNewProp(styleNode, BAD_CAST "id", BAD_CAST styleName);
+
+ xmlNodePtr iconStyleNode = xmlNewChild(styleNode, NULL, BAD_CAST "IconStyle", NULL);
+ char scale[16];
+ sprintf(scale, "%.1f", style->scale);
+ 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
+ if (createIconImage(iconFileName, symbol, style) != MS_SUCCESS)
+ {
+ char errMsg[512];
+ sprintf(errMsg, "Error creating icon file '%s'", iconFileName);
+ msSetError(MS_IOERR, errMsg, "KmlRenderer::lookupSymbolStyle()" );
+ return NULL;
+ }
+
+ xmlNodePtr iconNode = xmlNewChild(iconStyleNode, NULL, BAD_CAST "Icon", NULL);
+ xmlNewChild(iconNode, NULL, BAD_CAST "href", BAD_CAST iconFileName);
+ }
+
+ return styleUrl;
+}
+
+int KmlRenderer::createIconImage(char *fileName, symbolObj *symbol, symbolStyleObj *style)
+{
+ // internal renderer used for rasterizing
+ renderObj *r = RasterizerOutputFormat->r;
+
+ RasterizerOutputFormat->imagemode = MS_IMAGEMODE_RGBA;
+ imageObj *tmpImg = r->createImage(symbol->sizex, symbol->sizey, RasterizerOutputFormat, NULL);
+
+ double scale = style->scale; // save symbol scale
+ style->scale = 1.0; // render symbol in default size
+
+ double cx = symbol->sizex / 2;
+ double cy = symbol->sizey / 2;
+
+ switch(symbol->type)
+ {
+ case (MS_SYMBOL_TRUETYPE):
+ r->renderTruetypeSymbol(tmpImg, cx, cy, symbol, style);
+ break;
+ case (MS_SYMBOL_PIXMAP):
+ r->renderPixmapSymbol(tmpImg, cx, cy, symbol, style);
+ break;
+ case (MS_SYMBOL_ELLIPSE):
+ r->renderEllipseSymbol(tmpImg, cx, cy, symbol, style);
+ break;
+ case (MS_SYMBOL_VECTOR):
+ r->renderVectorSymbol(tmpImg, cx, cy, symbol, style);
+ break;
+ default:
+ break;
+ }
+
+ style->scale = scale; // restore symbol scale
+
+ FILE *fOut = fopen(fileName, "wb");
+ if (!fOut)
+ return MS_FAILURE;
+
+ tmpImg->format = RasterizerOutputFormat;
+
+ int status = MS_FAILURE;
+ if(r->supports_pixel_buffer)
+ {
+ rasterBufferObj data;
+ r->getRasterBuffer(tmpImg,&data);
+ status = msSaveRasterBuffer(&data, fOut, RasterizerOutputFormat );
+ }
+ else
+ {
+ status = r->saveImage(tmpImg, fOut, RasterizerOutputFormat);
+ }
+
+ fclose(fOut);
+
+ return status;
+}
+
#endif
\ No newline at end of file
Modified: sandbox/davidK/mapkmlrenderer.h
===================================================================
--- sandbox/davidK/mapkmlrenderer.h 2009-06-21 18:47:46 UTC (rev 9115)
+++ sandbox/davidK/mapkmlrenderer.h 2009-06-21 23:08:13 UTC (rev 9116)
@@ -23,6 +23,12 @@
int FirstLayer;
+ // internal output format containing cairo renderer used for rasterizing and rendering symbols
+ outputFormatObj *RasterizerOutputFormat;
+
+ // true - features are rasterized, false - features are written directly in kml
+ int UseInternalRasterizer;
+
enum altitudeModeEnum { undefined, clampToGround, relativeToGround, absolute };
protected:
@@ -33,6 +39,8 @@
char* lookupLineStyle(strokeStyleObj *strokeStyle);
char* lookupPolyStyle(colorObj *color);
+ char* lookupSymbolStyle(symbolObj *symbol, symbolStyleObj *style);
+
void addCoordsNode(xmlNodePtr parentNode, pointObj *pts, int numPts);
void setupRenderingParams(hashTableObj *layerMetadata);
@@ -40,6 +48,8 @@
int checkProjection(projectionObj *projection);
+ int createIconImage(char *fileName, symbolObj *symbol, symbolStyleObj *style);
+
public:
KmlRenderer(int width, int height, colorObj* color = NULL);
@@ -57,6 +67,8 @@
void renderGlyphs(imageObj *img, double x, double y, labelStyleObj *style, char *text);
+ void renderPixmapSymbol(imageObj *img, double x, double y, symbolObj *symbol, symbolStyleObj *style);
+
int getTruetypeTextBBox(imageObj *img,char *font, double size, char *string,
rectObj *rect, double **advances);
};
More information about the mapserver-commits
mailing list