[mapguide-commits] r8266 - in sandbox/jng/convenience_apis: Common/MapGuideCommon/MapLayer Server/src/UnitTesting

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Thu Jun 26 08:33:51 PDT 2014


Author: jng
Date: 2014-06-26 08:33:51 -0700 (Thu, 26 Jun 2014)
New Revision: 8266

Modified:
   sandbox/jng/convenience_apis/Common/MapGuideCommon/MapLayer/Layer.cpp
   sandbox/jng/convenience_apis/Common/MapGuideCommon/MapLayer/Layer.h
   sandbox/jng/convenience_apis/Server/src/UnitTesting/TestMappingService.cpp
   sandbox/jng/convenience_apis/Server/src/UnitTesting/TestMappingService.h
Log:
This submission adds a series of convenience APIs to MgLayer to simplify the theme icon generation process for a layer without having to do XML processing in .net/PHP/Java to determine the necessary parameters for GenerateLegendImage.

 * GetGeometryTypeStyles - Gets the list of geometry type styles for this layer at the specified scale. NULL of there are no applicable styles at this scale
 * GetThemeCategoryCount - Gets the number of theme categories for this layer at the specified scale. A number greater than 1 indicates a themed layer
 * GenerateLegendImage - Gets the legend image for the layer at the specified scale and geometry type
 * An overload of the above 3 methods is provided that takes no scale parameter and uses the map's scale instead.

Modified: sandbox/jng/convenience_apis/Common/MapGuideCommon/MapLayer/Layer.cpp
===================================================================
--- sandbox/jng/convenience_apis/Common/MapGuideCommon/MapLayer/Layer.cpp	2014-06-26 14:31:04 UTC (rev 8265)
+++ sandbox/jng/convenience_apis/Common/MapGuideCommon/MapLayer/Layer.cpp	2014-06-26 15:33:51 UTC (rev 8266)
@@ -17,6 +17,11 @@
 
 #include "MapGuideCommon.h"
 #include "FSDSAX2Parser.h"
+#include "AreaTypeStyle.h"
+#include "LineTypeStyle.h"
+#include "PointTypeStyle.h"
+#include "CompositeTypeStyle.h"
+#include <set>
 
 MG_IMPL_DYNCREATE(MgLayer)
 
@@ -542,3 +547,169 @@
 
     return deleted;
 }
+
+MgIntCollection* MgLayer::GetGeometryTypeStyles()
+{
+    Ptr<MgIntCollection> ret;
+
+    MG_TRY()
+
+    ret = GetGeometryTypeStyles(GetMap()->GetViewScale());
+
+    MG_CATCH_AND_THROW(L"MgLayer.GetGeometryTypeStyles");
+
+    return ret.Detach();
+}
+
+INT32 MgLayer::GetThemeCategoryCount(INT32 geomType)
+{
+    return GetThemeCategoryCount(GetMap()->GetViewScale(), geomType);
+}
+
+MgByteReader* MgLayer::GenerateLegendImage(INT32 width, INT32 height, CREFSTRING format, INT32 geomType, INT32 themeCategory)
+{
+    Ptr<MgByteReader> ret;
+
+    MG_TRY()
+
+    ret = GenerateLegendImage(GetMap()->GetViewScale(), width, height, format, geomType, themeCategory);
+
+    MG_CATCH_AND_THROW(L"MgLayer.GenerateLegendImage");
+
+    return ret.Detach();
+}
+
+MgIntCollection* MgLayer::GetGeometryTypeStyles(double scale)
+{
+    Ptr<MgIntCollection> ret;
+
+    MG_TRY()
+
+    Ptr<MgResourceService> resSvc = dynamic_cast<MgResourceService*>(GetMap()->GetService(MgServiceType::ResourceService));
+    std::auto_ptr<MdfModel::LayerDefinition> ldf(MgLayerBase::GetLayerDefinition(resSvc, m_definition));
+    if (ldf.get() != NULL)
+    {
+        MdfModel::VectorLayerDefinition* vl = dynamic_cast<MdfModel::VectorLayerDefinition*>(ldf.get());
+        if(vl != NULL)
+        {
+            MdfModel::VectorScaleRangeCollection* scaleRanges = vl->GetScaleRanges();
+            if (scaleRanges != NULL)
+            {
+                for (INT32 i = 0; i < scaleRanges->GetCount(); i++)
+                {
+                    MdfModel::VectorScaleRange* vsr = scaleRanges->GetAt(i);
+                    if (scale >= vsr->GetMinScale() && scale < vsr->GetMaxScale())
+                    {
+                        MdfModel::FeatureTypeStyleCollection* ftsc = vsr->GetFeatureTypeStyles();
+
+                        ret = new MgIntCollection();
+
+                        for (INT32 j = 0; j < ftsc->GetCount(); j++)
+                        {
+                            MdfModel::PointTypeStyle* pts = dynamic_cast<MdfModel::PointTypeStyle*>(ftsc->GetAt(j));
+                            MdfModel::LineTypeStyle* lts = dynamic_cast<MdfModel::LineTypeStyle*>(ftsc->GetAt(j));
+                            MdfModel::AreaTypeStyle* ats = dynamic_cast<MdfModel::AreaTypeStyle*>(ftsc->GetAt(j));
+                            MdfModel::CompositeTypeStyle* cts = dynamic_cast<MdfModel::CompositeTypeStyle*>(ftsc->GetAt(j));
+
+                            if (pts != NULL)
+                            {
+                                if (ret->IndexOf(1) < 0)
+                                    ret->Add(1);
+                            }
+                            else if (lts != NULL)
+                            {
+                                if (ret->IndexOf(2) < 0)
+                                    ret->Add(2);
+                            }
+                            else if (ats != NULL)
+                            {
+                                if (ret->IndexOf(3) < 0)
+                                    ret->Add(3);
+                            }
+                            else if (cts != NULL)
+                            {
+                                if (ret->IndexOf(4) < 0)
+                                    ret->Add(4);
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    MG_CATCH_AND_THROW(L"MgLayer.GenerateLegendImage");
+
+    return ret.Detach();
+}
+
+INT32 MgLayer::GetThemeCategoryCount(double scale, INT32 geomType)
+{
+    INT32 ret = -1;
+
+    Ptr<MgResourceService> resSvc = dynamic_cast<MgResourceService*>(GetMap()->GetService(MgServiceType::ResourceService));
+    std::auto_ptr<MdfModel::LayerDefinition> ldf(MgLayerBase::GetLayerDefinition(resSvc, m_definition));
+    if (ldf.get() != NULL)
+    {
+        MdfModel::VectorLayerDefinition* vl = dynamic_cast<MdfModel::VectorLayerDefinition*>(ldf.get());
+        if(vl != NULL)
+        {
+            MdfModel::VectorScaleRangeCollection* scaleRanges = vl->GetScaleRanges();
+            if (scaleRanges != NULL)
+            {
+                for (INT32 i = 0; i < scaleRanges->GetCount(); i++)
+                {
+                    MdfModel::VectorScaleRange* vsr = scaleRanges->GetAt(i);
+                    if (scale >= vsr->GetMinScale() && scale < vsr->GetMaxScale())
+                    {
+                        MdfModel::FeatureTypeStyleCollection* ftsc = vsr->GetFeatureTypeStyles();
+                        for (INT32 j = 0; j < ftsc->GetCount(); j++)
+                        {
+                            MdfModel::PointTypeStyle* pts = dynamic_cast<MdfModel::PointTypeStyle*>(ftsc->GetAt(j));
+                            MdfModel::LineTypeStyle* lts = dynamic_cast<MdfModel::LineTypeStyle*>(ftsc->GetAt(j));
+                            MdfModel::AreaTypeStyle* ats = dynamic_cast<MdfModel::AreaTypeStyle*>(ftsc->GetAt(j));
+                            MdfModel::CompositeTypeStyle* cts = dynamic_cast<MdfModel::CompositeTypeStyle*>(ftsc->GetAt(j));
+
+                            if (pts != NULL && geomType == 1)
+                            {
+                                ret = pts->GetRules()->GetCount();
+                                break;
+                            }
+                            else if (lts != NULL && geomType == 2)
+                            {
+                                ret = lts->GetRules()->GetCount();
+                                break;
+                            }
+                            else if (ats != NULL && geomType == 3)
+                            {
+                                ret = ats->GetRules()->GetCount();
+                                break;
+                            }
+                            else if (cts != NULL && geomType == 4)
+                            {
+                                ret = cts->GetRules()->GetCount();
+                                break;
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+    
+    return ret;
+}
+
+MgByteReader* MgLayer::GenerateLegendImage(double scale, INT32 width, INT32 height, CREFSTRING format, INT32 geomType, INT32 themeCategory)
+{
+    Ptr<MgByteReader> ret;
+
+    MG_TRY()
+
+    Ptr<MgMappingService> svcMapping = dynamic_cast<MgMappingService*>(GetMap()->GetService(MgServiceType::MappingService));
+    ret = svcMapping->GenerateLegendImage(m_definition, scale, width, height, format, geomType, themeCategory);
+
+    MG_CATCH_AND_THROW(L"MgLayer.GenerateLegendImage");
+
+    return ret.Detach();
+}
\ No newline at end of file

Modified: sandbox/jng/convenience_apis/Common/MapGuideCommon/MapLayer/Layer.h
===================================================================
--- sandbox/jng/convenience_apis/Common/MapGuideCommon/MapLayer/Layer.h	2014-06-26 14:31:04 UTC (rev 8265)
+++ sandbox/jng/convenience_apis/Common/MapGuideCommon/MapLayer/Layer.h	2014-06-26 15:33:51 UTC (rev 8266)
@@ -361,6 +361,216 @@
     /// \since 3.0
     virtual INT32 DeleteFeatures(CREFSTRING filter);
 
+    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+    /// \brief
+    /// Gets the list of geometry type styles for this layer at the map's current scale. Returns NULL if there are no applicable geometry types
+    ///
+    /// <!-- Syntax in .Net, Java, and PHP -->
+    /// \htmlinclude DotNetSyntaxTop.html
+    /// virtual MgIntCollection GetGeometryTypeStyles();
+    /// \htmlinclude SyntaxBottom.html
+    /// \htmlinclude JavaSyntaxTop.html
+    /// virtual MgIntCollection GetGeometryTypeStyles();
+    /// \htmlinclude SyntaxBottom.html
+    /// \htmlinclude PHPSyntaxTop.html
+    /// virtual MgIntCollection GetGeometryTypeStyles();
+    /// \htmlinclude SyntaxBottom.html
+    ///
+    /// \remarks
+    /// The map's current scale is used to determine what scale range in the layer definition to search for
+    ///
+    /// \return
+    /// The list of geometry type styles for this layer at the map's current scale. Returns NULL if there are no applicable geometry types
+    ///
+    /// \since 3.0
+    MgIntCollection* GetGeometryTypeStyles();
+
+    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+    /// \brief
+    /// Gets the number of theme categories for this layer at the map's current scale for the given geometry type style. A count greater than 1 indicates a themed layer. Returns -1 if there are no applicable styles at the current scale
+    ///
+    /// <!-- Syntax in .Net, Java, and PHP -->
+    /// \htmlinclude DotNetSyntaxTop.html
+    /// virtual int GetThemeCategoryCount(int geomType);
+    /// \htmlinclude SyntaxBottom.html
+    /// \htmlinclude JavaSyntaxTop.html
+    /// virtual int GetThemeCategoryCount(int geomType);
+    /// \htmlinclude SyntaxBottom.html
+    /// \htmlinclude PHPSyntaxTop.html
+    /// virtual int GetThemeCategoryCount(int geomType);
+    /// \htmlinclude SyntaxBottom.html
+    ///
+    /// \param geomType (int)
+    /// The geometry type
+    ///
+    /// \remarks
+    /// The map's current scale is used to determine what scale range in the layer definition to search for
+    ///
+    /// \return
+    /// The number of theme categories for this layer at the map's current scale for the given geometry type style. A count greater than 1 indicates a themed layer. Returns -1 if there are no applicable styles at the current scale
+    ///
+    /// \since 3.0
+    INT32 GetThemeCategoryCount(INT32 geomType);
+
+    ////////////////////////////////////////////////////////////////////////////////
+    /// \brief
+    /// Returns the legend image for the specified geometry type and theme category
+    ///
+    /// <!-- Syntax in .Net, Java, and PHP -->
+    /// \htmlinclude DotNetSyntaxTop.html
+    /// virtual MgByteReader GenerateLegendImage(int width, int height, string format, int geomType, int themeCategory);
+    /// \htmlinclude SyntaxBottom.html
+    /// \htmlinclude JavaSyntaxTop.html
+    /// virtual MgByteReader GenerateLegendImage(int width, int height, String format, int geomType, int themeCategory);
+    /// \htmlinclude SyntaxBottom.html
+    /// \htmlinclude PHPSyntaxTop.html
+    /// virtual MgByteReader GenerateLegendImage(int width, int height, string format, int geomType, int themeCategory);
+    /// \htmlinclude SyntaxBottom.html
+    ///
+    /// \param resource (MgResourceIdentifier)
+    /// Input
+    /// MgResourceIdentifier object identifying the layer definition resource.
+    /// \param scale (double)
+    /// Input
+    /// The scale at which the symbolization is requested.
+    /// \param width (int)
+    /// Input
+    /// The requested image width in pixels.
+    /// \param height (int)
+    /// Input
+    /// The requested image height in pixels.
+    /// \param format (String/string)
+    /// Input
+    /// Image format, from MgImageFormats. Example: PNG, JPG, PNG8, etc 
+    /// \param geomType (int)
+    /// Input
+    /// The type of symbolization required: 1=Point, 2=Line, 3=Area, 4=Composite
+    /// \param themeCategory (int)
+    /// Input
+    /// The value indicating which theme category swatch to return.
+    /// Used when there is a theme defined at this scale. An exception will be
+    /// thrown if a requested them category doesn't exist.
+    ///
+    /// \remarks
+    /// The map's current scale is used to determine what scale range in the layer definition to search for
+    ///
+    /// \return
+    /// Returns a stream representing the legend image.
+    /// The default returned image format will be PNG8 unless a different supported
+    /// format is requested. An exception will be thrown if an unsupported image
+    /// format is requested.
+    ///
+    /// \exception MgArgumentOutOfRangeException
+    /// \exception MgInvalidResourceTypeException
+    /// \exception MgNullArgumentException
+    /// \exception MgInvalidImageFormatException
+    ///
+    /// \since 3.0
+    MgByteReader* GenerateLegendImage(INT32 width, INT32 height, CREFSTRING format, INT32 geomType, INT32 themeCategory);
+
+    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+    /// \brief
+    /// Gets the list of geometry type styles for this layer at the map's current scale. Returns NULL if there are no applicable geometry types
+    ///
+    /// <!-- Syntax in .Net, Java, and PHP -->
+    /// \htmlinclude DotNetSyntaxTop.html
+    /// virtual MgIntCollection GetGeometryTypeStyles(double scale);
+    /// \htmlinclude SyntaxBottom.html
+    /// \htmlinclude JavaSyntaxTop.html
+    /// virtual MgIntCollection GetGeometryTypeStyles(double scale);
+    /// \htmlinclude SyntaxBottom.html
+    /// \htmlinclude PHPSyntaxTop.html
+    /// virtual MgIntCollection GetGeometryTypeStyles(double scale);
+    /// \htmlinclude SyntaxBottom.html
+    ///
+    /// \param scale (double)
+    /// The scale at which to retrive the list of applicable geometry types
+    ///
+    /// \return
+    /// The list of geometry type styles for this layer at the map's current scale. Returns NULL if there are no applicable geometry types
+    ///
+    /// \since 3.0
+    MgIntCollection* GetGeometryTypeStyles(double scale);
+
+    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+    /// \brief
+    /// Gets the number of theme categories for this layer at the map's current scale for the given geometry type style. A count greater than 1 indicates a themed layer. Returns -1 if there are no applicable styles at the current scale
+    ///
+    /// <!-- Syntax in .Net, Java, and PHP -->
+    /// \htmlinclude DotNetSyntaxTop.html
+    /// virtual int GetThemeCategoryCount(double scale, int geomType);
+    /// \htmlinclude SyntaxBottom.html
+    /// \htmlinclude JavaSyntaxTop.html
+    /// virtual int GetThemeCategoryCount(double scale, int geomType);
+    /// \htmlinclude SyntaxBottom.html
+    /// \htmlinclude PHPSyntaxTop.html
+    /// virtual int GetThemeCategoryCount(double scale, int geomType);
+    /// \htmlinclude SyntaxBottom.html
+    ///
+    /// \param scale (double)
+    /// The scale at which to count the number of applicable theme categories
+    /// \param geomType (int)
+    /// The geometry type
+    ///
+    /// \return
+    /// The number of theme categories for this layer at the map's current scale for the given geometry type style. A count greater than 1 indicates a themed layer. Returns -1 if there are no applicable styles at the current scale
+    ///
+    /// \since 3.0
+    INT32 GetThemeCategoryCount(double scale, INT32 geomType);
+
+    ////////////////////////////////////////////////////////////////////////////////
+    /// \brief
+    /// Returns the legend image for the specified geometry type and theme category
+    ///
+    /// <!-- Syntax in .Net, Java, and PHP -->
+    /// \htmlinclude DotNetSyntaxTop.html
+    /// virtual MgByteReader GenerateLegendImage(double scale, int width, int height, string format, int geomType, int themeCategory);
+    /// \htmlinclude SyntaxBottom.html
+    /// \htmlinclude JavaSyntaxTop.html
+    /// virtual MgByteReader GenerateLegendImage(double scale, int width, int height, String format, int geomType, int themeCategory);
+    /// \htmlinclude SyntaxBottom.html
+    /// \htmlinclude PHPSyntaxTop.html
+    /// virtual MgByteReader GenerateLegendImage(double scale, int width, int height, string format, int geomType, int themeCategory);
+    /// \htmlinclude SyntaxBottom.html
+    ///
+    /// \param resource (MgResourceIdentifier)
+    /// Input
+    /// MgResourceIdentifier object identifying the layer definition resource.
+    /// \param scale (double)
+    /// Input
+    /// The scale at which the symbolization is requested.
+    /// \param width (int)
+    /// Input
+    /// The requested image width in pixels.
+    /// \param height (int)
+    /// Input
+    /// The requested image height in pixels.
+    /// \param format (String/string)
+    /// Input
+    /// Image format, from MgImageFormats. Example: PNG, JPG, PNG8, etc 
+    /// \param geomType (int)
+    /// Input
+    /// The type of symbolization required: 1=Point, 2=Line, 3=Area, 4=Composite
+    /// \param themeCategory (int)
+    /// Input
+    /// The value indicating which theme category swatch to return.
+    /// Used when there is a theme defined at this scale. An exception will be
+    /// thrown if a requested them category doesn't exist.
+    ///
+    /// \return
+    /// Returns a stream representing the legend image.
+    /// The default returned image format will be PNG8 unless a different supported
+    /// format is requested. An exception will be thrown if an unsupported image
+    /// format is requested.
+    ///
+    /// \exception MgArgumentOutOfRangeException
+    /// \exception MgInvalidResourceTypeException
+    /// \exception MgNullArgumentException
+    /// \exception MgInvalidImageFormatException
+    ///
+    /// \since 3.0
+    MgByteReader* GenerateLegendImage(double scale, INT32 width, INT32 height, CREFSTRING format, INT32 geomType, INT32 themeCategory);
+
 INTERNAL_API:
 
     //////////////////////////////////////////////////////////////////

Modified: sandbox/jng/convenience_apis/Server/src/UnitTesting/TestMappingService.cpp
===================================================================
--- sandbox/jng/convenience_apis/Server/src/UnitTesting/TestMappingService.cpp	2014-06-26 14:31:04 UTC (rev 8265)
+++ sandbox/jng/convenience_apis/Server/src/UnitTesting/TestMappingService.cpp	2014-06-26 15:33:51 UTC (rev 8266)
@@ -1021,6 +1021,229 @@
     }
 }
 
+void TestMappingService::TestCase_GetLegendImageConvenience()
+{
+    try
+    {
+        Ptr<MgResourceIdentifier> mapres = new MgResourceIdentifier(L"Library://UnitTests/Maps/Sheboygan.MapDefinition");
+        Ptr<MgMap> map = new MgMap(m_siteConnection);
+        map->Create(mapres, L"TestCase_GetLegendImageConvenience");
+
+        Ptr<MgResourceIdentifier> ldf = new MgResourceIdentifier(L"Library://UnitTests/Layers/Parcels.LayerDefinition");
+        Ptr<MgLayer> layer = new MgLayer(ldf, m_svcResource);
+        layer->SetName(L"TestCase_GetLegendImageConvenience");
+        Ptr<MgLayerCollection> layers = map->GetLayers();
+        layers->Insert(0, layer);
+
+        Ptr<MgIntCollection> types = layer->GetGeometryTypeStyles(10000.0);
+        CPPUNIT_ASSERT(1 == types->GetCount());
+        CPPUNIT_ASSERT(types->IndexOf(1) < 0);
+        CPPUNIT_ASSERT(types->IndexOf(2) < 0);
+        CPPUNIT_ASSERT(types->IndexOf(3) >= 0);
+        CPPUNIT_ASSERT(types->IndexOf(4) < 0);
+
+        CPPUNIT_ASSERT(8 == layer->GetThemeCategoryCount(10000.0, 3));
+        CPPUNIT_ASSERT(-1 == layer->GetThemeCategoryCount(10000.0, 1));
+        CPPUNIT_ASSERT(-1 == layer->GetThemeCategoryCount(10000.0, 2));
+        CPPUNIT_ASSERT(-1 == layer->GetThemeCategoryCount(10000.0, 4));
+
+        types = layer->GetGeometryTypeStyles(14000.0);
+        CPPUNIT_ASSERT(NULL == types.p);
+        CPPUNIT_ASSERT(-1 == layer->GetThemeCategoryCount(14000.0, 3));
+        CPPUNIT_ASSERT(-1 == layer->GetThemeCategoryCount(14000.0, 1));
+        CPPUNIT_ASSERT(-1 == layer->GetThemeCategoryCount(14000.0, 2));
+        CPPUNIT_ASSERT(-1 == layer->GetThemeCategoryCount(14000.0, 4));
+
+        Ptr<MgByteReader> rdr = layer->GenerateLegendImage(10000.0, 16, 16, MgImageFormats::Png, 3, 0);
+        Ptr<MgByteSink> sink = new MgByteSink(rdr);
+        sink->ToFile(L"../UnitTestFiles/GenerateLegendImageConvenience_Parcels_16x16_PNG.png");
+
+        rdr = layer->GenerateLegendImage(10000.0, 16, 16, MgImageFormats::Png8, 3, 0);
+        sink = new MgByteSink(rdr);
+        sink->ToFile(L"../UnitTestFiles/GenerateLegendImageConvenience_Parcels_16x16_PNG8.png");
+
+        rdr = layer->GenerateLegendImage(10000.0, 16, 16, MgImageFormats::Jpeg, 3, 0);
+        sink = new MgByteSink(rdr);
+        sink->ToFile(L"../UnitTestFiles/GenerateLegendImageConvenience_Parcels_16x16_JPG.jpg");
+
+        rdr = layer->GenerateLegendImage(10000.0, 16, 16, MgImageFormats::Gif, 3, 0);
+        sink = new MgByteSink(rdr);
+        sink->ToFile(L"../UnitTestFiles/GenerateLegendImageConvenience_Parcels_16x16_GIF.gif");
+    }
+    catch (MgException* e)
+    {
+        STRING message = e->GetDetails(TEST_LOCALE);
+        SAFE_RELEASE(e);
+        CPPUNIT_FAIL(MG_WCHAR_TO_CHAR(message.c_str()));
+    }
+    catch (...)
+    {
+        throw;
+    }
+}
+
+void TestMappingService::TestCase_GetLegendImagePointStyleWithConstRotationsConvenience()
+{
+    try
+    {
+        Ptr<MgResourceIdentifier> mapres = new MgResourceIdentifier(L"Library://UnitTests/Maps/Sheboygan.MapDefinition");
+        Ptr<MgMap> map = new MgMap(m_siteConnection);
+        map->Create(mapres, L"TestCase_GetLegendImageConvenience");
+
+        Ptr<MgResourceIdentifier> ldfId = new MgResourceIdentifier(L"Library://UnitTests/Layers/RotatedPointStyles.LayerDefinition");
+        Ptr<MgLayer> layer = new MgLayer(ldfId, m_svcResource);
+        layer->SetName(L"TestCase_GetLegendImagePointStyleWithConstRotationsConvenience");
+        Ptr<MgLayerCollection> layers = map->GetLayers();
+        layers->Insert(0, layer);
+
+        Ptr<MgIntCollection> types = layer->GetGeometryTypeStyles(1000.0);
+        CPPUNIT_ASSERT(1 == types->GetCount());
+        CPPUNIT_ASSERT(types->IndexOf(1) >= 0);
+        CPPUNIT_ASSERT(types->IndexOf(2) < 0);
+        CPPUNIT_ASSERT(types->IndexOf(3) < 0);
+        CPPUNIT_ASSERT(types->IndexOf(4) < 0);
+
+        CPPUNIT_ASSERT(15 == layer->GetThemeCategoryCount(1000.0, 1));
+        CPPUNIT_ASSERT(-1 == layer->GetThemeCategoryCount(1000.0, 2));
+        CPPUNIT_ASSERT(-1 == layer->GetThemeCategoryCount(1000.0, 3));
+        CPPUNIT_ASSERT(-1 == layer->GetThemeCategoryCount(1000.0, 4));
+        
+        //Do 16x16 icons first. Our common scenario.
+
+        Ptr<MgByteReader> rdr = layer->GenerateLegendImage(1000.0, 16, 16, MgImageFormats::Png, 1, 0);
+        Ptr<MgByteSink> sink = new MgByteSink(rdr);
+        sink->ToFile(L"../UnitTestFiles/RotatedPointConvenience_Square_0_16x16.png");
+        
+        rdr = layer->GenerateLegendImage(1000.0, 16, 16, MgImageFormats::Png, 1, 1);
+        sink = new MgByteSink(rdr);
+        sink->ToFile(L"../UnitTestFiles/RotatedPointConvenience_Square_45_16x16.png");
+
+        rdr = layer->GenerateLegendImage(1000.0, 16, 16, MgImageFormats::Png, 1, 2);
+        sink = new MgByteSink(rdr);
+        sink->ToFile(L"../UnitTestFiles/RotatedPointConvenience_Square_25_16x16.png");
+
+        rdr = layer->GenerateLegendImage(1000.0, 16, 16, MgImageFormats::Png, 1, 3);
+        sink = new MgByteSink(rdr);
+        sink->ToFile(L"../UnitTestFiles/RotatedPointConvenience_Star_0_16x16.png");
+
+        rdr = layer->GenerateLegendImage(1000.0, 16, 16, MgImageFormats::Png, 1, 4);
+        sink = new MgByteSink(rdr);
+        sink->ToFile(L"../UnitTestFiles/RotatedPointConvenience_Star_45_16x16.png");
+
+        rdr = layer->GenerateLegendImage(1000.0, 16, 16, MgImageFormats::Png, 1, 5);
+        sink = new MgByteSink(rdr);
+        sink->ToFile(L"../UnitTestFiles/RotatedPointConvenience_Star_25_16x16.png");
+
+        rdr = layer->GenerateLegendImage(1000.0, 16, 16, MgImageFormats::Png, 1, 6);
+        sink = new MgByteSink(rdr);
+        sink->ToFile(L"../UnitTestFiles/RotatedPointConvenience_Triangle_0_16x16.png");
+
+        rdr = layer->GenerateLegendImage(1000.0, 16, 16, MgImageFormats::Png, 1, 7);
+        sink = new MgByteSink(rdr);
+        sink->ToFile(L"../UnitTestFiles/RotatedPointConvenience_Triangle_45_16x16.png");
+
+        rdr = layer->GenerateLegendImage(1000.0, 16, 16, MgImageFormats::Png, 1, 8);
+        sink = new MgByteSink(rdr);
+        sink->ToFile(L"../UnitTestFiles/RotatedPointConvenience_Triangle_25_16x16.png");
+
+        rdr = layer->GenerateLegendImage(1000.0, 16, 16, MgImageFormats::Png, 1, 9);
+        sink = new MgByteSink(rdr);
+        sink->ToFile(L"../UnitTestFiles/RotatedPointConvenience_Cross_0_16x16.png");
+
+        rdr = layer->GenerateLegendImage(1000.0, 16, 16, MgImageFormats::Png, 1, 10);
+        sink = new MgByteSink(rdr);
+        sink->ToFile(L"../UnitTestFiles/RotatedPointConvenience_Cross_45_16x16.png");
+
+        rdr = layer->GenerateLegendImage(1000.0, 16, 16, MgImageFormats::Png, 1, 11);
+        sink = new MgByteSink(rdr);
+        sink->ToFile(L"../UnitTestFiles/RotatedPointConvenience_Cross_25_16x16.png");
+
+        rdr = layer->GenerateLegendImage(1000.0, 16, 16, MgImageFormats::Png, 1, 12);
+        sink = new MgByteSink(rdr);
+        sink->ToFile(L"../UnitTestFiles/RotatedPointConvenience_XMark_0_16x16.png");
+
+        rdr = layer->GenerateLegendImage(1000.0, 16, 16, MgImageFormats::Png, 1, 13);
+        sink = new MgByteSink(rdr);
+        sink->ToFile(L"../UnitTestFiles/RotatedPointConvenience_XMark_45_16x16.png");
+
+        rdr = layer->GenerateLegendImage(1000.0, 16, 16, MgImageFormats::Png, 1, 14);
+        sink = new MgByteSink(rdr);
+        sink->ToFile(L"../UnitTestFiles/RotatedPointConvenience_XMark_25_16x16.png");
+
+        //Now try 32x16 to see if the rotation handling is acceptable with non-square sizes
+
+        rdr = layer->GenerateLegendImage(1000.0, 32, 16, MgImageFormats::Png, 1, 0);
+        sink = new MgByteSink(rdr);
+        sink->ToFile(L"../UnitTestFiles/RotatedPointConvenience_Square_0_32x16.png");
+
+        rdr = layer->GenerateLegendImage(1000.0, 32, 16, MgImageFormats::Png, 1, 1);
+        sink = new MgByteSink(rdr);
+        sink->ToFile(L"../UnitTestFiles/RotatedPointConvenience_Square_45_32x16.png");
+        
+        rdr = layer->GenerateLegendImage(1000.0, 32, 16, MgImageFormats::Png, 1, 2);
+        sink = new MgByteSink(rdr);
+        sink->ToFile(L"../UnitTestFiles/RotatedPointConvenience_Square_25_32x16.png");
+
+        rdr = layer->GenerateLegendImage(1000.0, 32, 16, MgImageFormats::Png, 1, 3);
+        sink = new MgByteSink(rdr);
+        sink->ToFile(L"../UnitTestFiles/RotatedPointConvenience_Star_0_32x16.png");
+
+        rdr = layer->GenerateLegendImage(1000.0, 32, 16, MgImageFormats::Png, 1, 4);
+        sink = new MgByteSink(rdr);
+        sink->ToFile(L"../UnitTestFiles/RotatedPointConvenience_Star_45_32x16.png");
+
+        rdr = layer->GenerateLegendImage(1000.0, 32, 16, MgImageFormats::Png, 1, 5);
+        sink = new MgByteSink(rdr);
+        sink->ToFile(L"../UnitTestFiles/RotatedPointConvenience_Star_25_32x16.png");
+
+        rdr = layer->GenerateLegendImage(1000.0, 32, 16, MgImageFormats::Png, 1, 6);
+        sink = new MgByteSink(rdr);
+        sink->ToFile(L"../UnitTestFiles/RotatedPointConvenience_Triangle_0_32x16.png");
+
+        rdr = layer->GenerateLegendImage(1000.0, 32, 16, MgImageFormats::Png, 1, 7);
+        sink = new MgByteSink(rdr);
+        sink->ToFile(L"../UnitTestFiles/RotatedPointConvenience_Triangle_45_32x16.png");
+
+        rdr = layer->GenerateLegendImage(1000.0, 32, 16, MgImageFormats::Png, 1, 8);
+        sink = new MgByteSink(rdr);
+        sink->ToFile(L"../UnitTestFiles/RotatedPointConvenience_Triangle_25_32x16.png");
+
+        rdr = layer->GenerateLegendImage(1000.0, 32, 16, MgImageFormats::Png, 1, 9);
+        sink = new MgByteSink(rdr);
+        sink->ToFile(L"../UnitTestFiles/RotatedPointConvenience_Cross_0_32x16.png");
+
+        rdr = layer->GenerateLegendImage(1000.0, 32, 16, MgImageFormats::Png, 1, 10);
+        sink = new MgByteSink(rdr);
+        sink->ToFile(L"../UnitTestFiles/RotatedPointConvenience_Cross_45_32x16.png");
+
+        rdr = layer->GenerateLegendImage(1000.0, 32, 16, MgImageFormats::Png, 1, 11);
+        sink = new MgByteSink(rdr);
+        sink->ToFile(L"../UnitTestFiles/RotatedPointConvenience_Cross_25_32x16.png");
+
+        rdr = layer->GenerateLegendImage(1000.0, 32, 16, MgImageFormats::Png, 1, 12);
+        sink = new MgByteSink(rdr);
+        sink->ToFile(L"../UnitTestFiles/RotatedPointConvenience_XMark_0_32x16.png");
+
+        rdr = layer->GenerateLegendImage(1000.0, 32, 16, MgImageFormats::Png, 1, 13);
+        sink = new MgByteSink(rdr);
+        sink->ToFile(L"../UnitTestFiles/RotatedPointConvenience_XMark_45_32x16.png");
+
+        rdr = layer->GenerateLegendImage(1000.0, 32, 16, MgImageFormats::Png, 1, 14);
+        sink = new MgByteSink(rdr);
+        sink->ToFile(L"../UnitTestFiles/RotatedPointConvenience_XMark_25_32x16.png");
+    }
+    catch (MgException* e)
+    {
+        STRING message = e->GetDetails(TEST_LOCALE);
+        SAFE_RELEASE(e);
+        CPPUNIT_FAIL(MG_WCHAR_TO_CHAR(message.c_str()));
+    }
+    catch (...)
+    {
+        throw;
+    }
+}
+
 void TestMappingService::TestCase_QueryFeaturesImageMap()
 {
     try

Modified: sandbox/jng/convenience_apis/Server/src/UnitTesting/TestMappingService.h
===================================================================
--- sandbox/jng/convenience_apis/Server/src/UnitTesting/TestMappingService.h	2014-06-26 14:31:04 UTC (rev 8265)
+++ sandbox/jng/convenience_apis/Server/src/UnitTesting/TestMappingService.h	2014-06-26 15:33:51 UTC (rev 8266)
@@ -36,6 +36,8 @@
     CPPUNIT_TEST(TestCase_GetLegendPlot);
     CPPUNIT_TEST(TestCase_GetLegendImage);
     CPPUNIT_TEST(TestCase_GetLegendImagePointStyleWithConstRotations);
+    CPPUNIT_TEST(TestCase_GetLegendImageConvenience);
+    CPPUNIT_TEST(TestCase_GetLegendImagePointStyleWithConstRotationsConvenience);
     CPPUNIT_TEST(TestCase_CreateRuntimeMap);
     CPPUNIT_TEST(TestCase_DescribeRuntimeMap);
     //CPPUNIT_TEST(TestCase_QueryFeaturesImageMap);
@@ -67,6 +69,8 @@
     void TestCase_GetLegendPlot();
     void TestCase_GetLegendImage();
     void TestCase_GetLegendImagePointStyleWithConstRotations();
+    void TestCase_GetLegendImageConvenience();
+    void TestCase_GetLegendImagePointStyleWithConstRotationsConvenience();
     void TestCase_QueryFeaturesImageMap();
 
 private:



More information about the mapguide-commits mailing list