[mapguide-commits] r7580 - trunk/MgDev/Common/Stylization

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Fri Jun 7 07:33:04 PDT 2013


Author: jng
Date: 2013-06-07 07:33:04 -0700 (Fri, 07 Jun 2013)
New Revision: 7580

Modified:
   trunk/MgDev/Common/Stylization/StylizationUtil.cpp
Log:
#2284: Fix point style legend icons not considering rotation. Our first attempt we had to roll back due to un-desirable cropping for certain marker types. This revised submission applies necessary compensation for these marker types so that when rotated, the styled point still fits within the bounds of the icon we want to render. The test case we put in the previous submission now shows properly fitted rotated points for these problematic marker types.

Modified: trunk/MgDev/Common/Stylization/StylizationUtil.cpp
===================================================================
--- trunk/MgDev/Common/Stylization/StylizationUtil.cpp	2013-06-07 13:30:21 UTC (rev 7579)
+++ trunk/MgDev/Common/Stylization/StylizationUtil.cpp	2013-06-07 14:33:04 UTC (rev 7580)
@@ -230,7 +230,10 @@
     if (symbol)
     {
         SymbolVisitor::eSymbolType type = SymbolVisitor::DetermineSymbolType(symbol);
-
+        //Apply rotation if we can. Now there may be undesired cropping as a result of this, so we'll try
+        //to compensate for certain symbol types where we know compensation can eliminate cropping, namely
+        //certain markers
+        bool bAppliedRotation = StylizationUtil::ParseDouble(symbol->GetRotation(), mdef.rotation()) && mdef.rotation() != 0.0;
         switch (type)
         {
         case SymbolVisitor::stMark:
@@ -252,6 +255,28 @@
                     default: break;
                 }
 
+                // These are the marker types that could do with compensation
+                if (bAppliedRotation &&
+                    (mdef.markernum() == SLDType_Square ||
+                     mdef.markernum() == SLDType_X ||
+                     mdef.markernum() == SLDType_Triangle))
+                {
+                    // For preview purposes, SizeX and SizeY are not considered when rendering, thus we know we're dealing
+                    // with something whose bounding box has the same width and height.
+                    double rotRad = mdef.rotation() * M_PI / 180.0;
+                    double length = rs_min(mdef.width(), mdef.height());
+
+                    // http://stackoverflow.com/questions/6657479/aabb-of-rotated-sprite
+                    double rotatedLength = (length * std::sin(rotRad)) + (length * std::cos(rotRad));
+
+                    double normalizedLength = rs_max(length, rotatedLength);
+                    if (rotatedLength > length)
+                        normalizedLength = length * (length / rotatedLength);
+
+                    mdef.width() = normalizedLength;
+                    mdef.height() = normalizedLength;
+                }
+
                 // fill and edge colors
                 if (marksym->GetFill())
                     StylizationUtil::ParseColor(marksym->GetFill()->GetForegroundColor(), mdef.style().color());



More information about the mapguide-commits mailing list