[mapserver-commits] r9100 - sandbox/davidK
svn at osgeo.org
svn at osgeo.org
Wed Jun 10 20:06:02 EDT 2009
Author: davidK
Date: 2009-06-10 20:06:01 -0400 (Wed, 10 Jun 2009)
New Revision: 9100
Modified:
sandbox/davidK/mapkml.cpp
sandbox/davidK/mapkml.h
sandbox/davidK/mapkmlrenderer.cpp
sandbox/davidK/mapkmlrenderer.h
Log:
added basic styles support
Modified: sandbox/davidK/mapkml.cpp
===================================================================
--- sandbox/davidK/mapkml.cpp 2009-06-09 03:39:18 UTC (rev 9099)
+++ sandbox/davidK/mapkml.cpp 2009-06-11 00:06:01 UTC (rev 9100)
@@ -53,6 +53,8 @@
void msRenderGlyphsKml(imageObj *img, double x, double y,
labelStyleObj *style, char *text)
{
+ KmlRenderer* renderer = getKmlRenderer(img);
+ renderer->renderGlyphs(img, x, y, style, text);
}
void msRenderGlyphsLineKml(imageObj *img,labelPathObj *labelpath,
@@ -104,7 +106,7 @@
return NULL;
}
-void msRenderTileKml(imageObj *img, void *tile, double x, double y, double angle)
+void msRenderTileKml(imageObj *img, imageObj *tile, double x, double y)
{
}
@@ -119,7 +121,8 @@
int msGetTruetypeTextBBoxKml(imageObj *img,char *font, double size, char *string,
rectObj *rect, double **advances)
{
- return MS_FALSE;
+ KmlRenderer* renderer = getKmlRenderer(img);
+ return renderer->getTruetypeTextBBox(img, font, size, string, rect, advances);
}
void msStartNewLayerKml(imageObj *img, layerObj *layer)
Modified: sandbox/davidK/mapkml.h
===================================================================
--- sandbox/davidK/mapkml.h 2009-06-09 03:39:18 UTC (rev 9099)
+++ sandbox/davidK/mapkml.h 2009-06-11 00:06:01 UTC (rev 9100)
@@ -43,7 +43,7 @@
void* msCreateTruetypeSymbolTileKml(int width, int height,
symbolObj *symbol, symbolStyleObj *style);
-void msRenderTileKml(imageObj *img, void *tile, double x, double y, double angle);
+void msRenderTileKml(imageObj *img, imageObj *tile, double x, double y, double angle);
void msGetRasterBufferKml(imageObj *img,rasterBufferObj *rb);
void msMergeRasterBufferKml(imageObj *dest, rasterBufferObj *overlay, double opacity, int dstX, int dstY);
Modified: sandbox/davidK/mapkmlrenderer.cpp
===================================================================
--- sandbox/davidK/mapkmlrenderer.cpp 2009-06-09 03:39:18 UTC (rev 9099)
+++ sandbox/davidK/mapkmlrenderer.cpp 2009-06-11 00:06:01 UTC (rev 9100)
@@ -19,6 +19,8 @@
xmlDocSetRootElement(XmlDoc, rootNode);
DocNode = xmlNewChild(rootNode, NULL, BAD_CAST "Document", NULL);
+
+ StyleHashTable = msCreateHashTable();
}
KmlRenderer::~KmlRenderer()
@@ -26,6 +28,9 @@
if (XmlDoc)
xmlFreeDoc(XmlDoc);
+ if (StyleHashTable)
+ msFreeHashTable(StyleHashTable);
+
xmlCleanupParser();
}
@@ -81,7 +86,6 @@
void KmlRenderer::startNewLayer(imageObj *img, layerObj *layer)
{
LayerNode = xmlNewChild(DocNode, NULL, BAD_CAST "Folder", NULL);
- //xmlAddChild(RootNode, LayerNode);
xmlNodePtr layerNameNode = xmlNewChild(LayerNode, NULL, BAD_CAST "name", NULL);
xmlNodeAddContent(layerNameNode, BAD_CAST layer->name);
@@ -95,19 +99,26 @@
}
+xmlNodePtr KmlRenderer::createPlacemarkNode(xmlNodePtr parentNode, char *styleUrl)
+{
+ xmlNodePtr placemarkNode = xmlNewChild(parentNode, NULL, BAD_CAST "Placemark", NULL);
+
+ if (styleUrl)
+ xmlNewChild(placemarkNode, NULL, BAD_CAST "styleUrl", BAD_CAST styleUrl);
+
+ return placemarkNode;
+}
+
void KmlRenderer::renderLine(imageObj *img, shapeObj *p, strokeStyleObj *style)
{
- xmlNodePtr placemarkNode = xmlNewChild(LayerNode, NULL, BAD_CAST "Placemark", NULL);
+ xmlNodePtr placemarkNode = createPlacemarkNode(LayerNode, lookupLineStyle(style));
- xmlNodePtr styleUrlNode = xmlNewChild(placemarkNode, NULL, BAD_CAST "styleUrl", NULL);
- xmlNodeAddContent(styleUrlNode, BAD_CAST "#");
-
int includeZ = 0;
if (p->numlines == 1)
{
xmlNodePtr geomNode = xmlNewChild(placemarkNode, NULL, BAD_CAST "LineString", NULL);
- addCoordsNode(geomNode, &p->line[0], includeZ);
+ addCoordsNode(geomNode, p->line[0].point, p->line[0].numpoints, includeZ);
}
else
{
@@ -115,16 +126,14 @@
for (int i=0; i<p->numlines; i++)
{
xmlNodePtr lineStringNode = xmlNewChild(multiGeomNode, NULL, BAD_CAST "LineString", NULL);
- addCoordsNode(lineStringNode, &p->line[i], includeZ);
+ addCoordsNode(lineStringNode, p->line[i].point, p->line[i].numpoints, includeZ);
}
}
}
void KmlRenderer::renderPolygon(imageObj *img, shapeObj *p, colorObj *color)
{
- xmlNodePtr placemarkNode = xmlNewChild(LayerNode, NULL, BAD_CAST "Placemark", NULL);
-
- xmlNodePtr styleUrlNode = xmlNewChild(placemarkNode, NULL, BAD_CAST "styleUrl", BAD_CAST "#");
+ xmlNodePtr placemarkNode = createPlacemarkNode(LayerNode, lookupPolyStyle(color));
xmlNodePtr polygonNode = xmlNewChild(placemarkNode, NULL, BAD_CAST "Polygon", NULL);
int includeZ = 0;
@@ -139,27 +148,146 @@
bdryNode = xmlNewChild(polygonNode, NULL, BAD_CAST "innerBoundaryIs", NULL);
xmlNodePtr ringNode = xmlNewChild(bdryNode, NULL, BAD_CAST "LinearRing", NULL);
- addCoordsNode(ringNode, &p->line[i], includeZ);
+ addCoordsNode(ringNode, p->line[i].point, p->line[i].numpoints, includeZ);
}
}
-void KmlRenderer::addCoordsNode(xmlNodePtr node, lineObj *line, int includeZ)
+void KmlRenderer::addCoordsNode(xmlNodePtr parentNode, pointObj *pts, int numPts, int includeZ)
{
char lineBuf[128];
- xmlNodePtr coordsNode = xmlNewChild(node, NULL, BAD_CAST "coordinates", NULL);
+ xmlNodePtr coordsNode = xmlNewChild(parentNode, NULL, BAD_CAST "coordinates", NULL);
xmlNodeAddContent(coordsNode, BAD_CAST "\n");
- for (int i=0; i<line->numpoints; i++)
+ for (int i=0; i<numPts; i++)
{
if (includeZ)
- sprintf(lineBuf, "\t%.8f,%.8f,%.8f\n", line->point[i].x, line->point[i].y,line->point[i].z);
+ {
+#ifdef USE_POINT_Z_M
+ sprintf(lineBuf, "\t%.8f,%.8f,%.8f\n", pts[i].x, pts[i].y, pts[i].z);
+#else
+ msSetError(MS_QUERYERR, "Z coordinates support not available (mapserver not compiled with USE_POINT_Z_M option)", "KmlRenderer::addCoordsNode");
+#endif
+ }
else
- sprintf(lineBuf, "\t%.8f,%.8f\n", line->point[i].x, line->point[i].y);
+ sprintf(lineBuf, "\t%.8f,%.8f\n", pts[i].x, pts[i].y);
xmlNodeAddContent(coordsNode, BAD_CAST lineBuf);
}
xmlNodeAddContent(coordsNode, BAD_CAST "\t");
}
+char* KmlRenderer::lookupLineStyle(strokeStyleObj *strokeStyle)
+{
+ /*
+ <LineStyle id="ID">
+ <!-- inherited from ColorStyle -->
+ <color>ffffffff</color> <!-- kml:color -->
+ <colorMode>normal</colorMode> <!-- colorModeEnum: normal or random -->
+
+ <!-- specific to LineStyle -->
+ <width>1</width> <!-- float -->
+ </LineStyle>
+ */
+
+ char hexColor[16];
+ sprintf(hexColor,"%02x%02x%02x%02x", strokeStyle->color.alpha, strokeStyle->color.blue,
+ strokeStyle->color.green, strokeStyle->color.red);
+
+ char styleName[32];
+ sprintf(styleName, "lineStyle%s_w%.1f", hexColor, strokeStyle->width);
+
+ 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 PolyStyle node into Document node
+ xmlNodePtr styleNode = xmlNewChild(DocNode, NULL, BAD_CAST "Style", NULL);
+ xmlNewProp(styleNode, BAD_CAST "id", BAD_CAST styleName);
+
+ xmlNodePtr lineStyleNode = xmlNewChild(styleNode, NULL, BAD_CAST "LineStyle", NULL);
+ xmlNewChild(lineStyleNode, NULL, BAD_CAST "color", BAD_CAST hexColor);
+
+ char width[16];
+ sprintf(width, "%.1f", strokeStyle->width);
+ xmlNewChild(lineStyleNode, NULL, BAD_CAST "width", BAD_CAST width);
+ }
+
+ return styleUrl;
+}
+
+char* KmlRenderer::lookupPolyStyle(colorObj *color)
+{
+ /*
+ <PolyStyle id="ID">
+ <!-- inherited from ColorStyle -->
+ <color>ffffffff</color> <!-- kml:color -->
+ <colorMode>normal</colorMode> <!-- kml:colorModeEnum: normal or random -->
+
+ <!-- specific to PolyStyle -->
+ <fill>1</fill> <!-- boolean -->
+ <outline>1</outline> <!-- boolean -->
+ </PolyStyle>
+ */
+
+ char hexColor[16];
+ sprintf(hexColor,"%02x%02x%02x%02x", color->alpha, color->blue, color->green, color->red);
+
+ char styleName[32];
+ sprintf(styleName, "polyStyle%s", hexColor);
+
+ 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 PolyStyle node into Document node
+ xmlNodePtr styleNode = xmlNewChild(DocNode, NULL, BAD_CAST "Style", NULL);
+ xmlNewProp(styleNode, BAD_CAST "id", BAD_CAST styleName);
+
+ xmlNodePtr polyStyleNode = xmlNewChild(styleNode, NULL, BAD_CAST "PolyStyle", NULL);
+ xmlNewChild(polyStyleNode, NULL, BAD_CAST "color", BAD_CAST hexColor);
+ }
+
+ return styleUrl;
+}
+
+char* KmlRenderer::lookupPointStyle(colorObj *color)
+{
+ return NULL;
+}
+
+void KmlRenderer::renderGlyphs(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);
+ xmlNodePtr pointNode = xmlNewChild(placemarkNode, NULL, BAD_CAST "Point", NULL);
+
+ int includeZ = false;
+
+ pointObj pt;
+ pt.x = x; pt.y = y;
+ addCoordsNode(pointNode, &pt, 1, includeZ);
+}
+
+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;
+
+ return true;
+}
+
#endif
\ No newline at end of file
Modified: sandbox/davidK/mapkmlrenderer.h
===================================================================
--- sandbox/davidK/mapkmlrenderer.h 2009-06-09 03:39:18 UTC (rev 9099)
+++ sandbox/davidK/mapkmlrenderer.h 2009-06-11 00:06:01 UTC (rev 9100)
@@ -15,10 +15,18 @@
xmlNodePtr DocNode;
xmlNodePtr LayerNode;
+ hashTableObj *StyleHashTable;
+
protected:
- void addCoordsNode(xmlNodePtr node, lineObj *line, int includeZ);
+ xmlNodePtr createPlacemarkNode(xmlNodePtr parentNode, char *styleUrl);
+ char* lookupPointStyle(colorObj *color);
+ char* lookupLineStyle(strokeStyleObj *strokeStyle);
+ char* lookupPolyStyle(colorObj *color);
+
+ void addCoordsNode(xmlNodePtr parentNode, pointObj *pts, int numPts, int includeZ);
+
public:
KmlRenderer(int width, int height, colorObj* color = NULL);
@@ -33,6 +41,11 @@
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);
+
+ 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