[mapguide-commits] r8398 - trunk/MgDev/Desktop/MgDesktop/MapLayer

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Thu Oct 9 07:00:51 PDT 2014


Author: jng
Date: 2014-10-09 07:00:51 -0700 (Thu, 09 Oct 2014)
New Revision: 8398

Modified:
   trunk/MgDev/Desktop/MgDesktop/MapLayer/Layer.cpp
   trunk/MgDev/Desktop/MgDesktop/MapLayer/Layer.h
Log:
mg-desktop: Port over legend icon convenience APIs

Modified: trunk/MgDev/Desktop/MgDesktop/MapLayer/Layer.cpp
===================================================================
--- trunk/MgDev/Desktop/MgDesktop/MapLayer/Layer.cpp	2014-10-08 01:53:06 UTC (rev 8397)
+++ trunk/MgDev/Desktop/MgDesktop/MapLayer/Layer.cpp	2014-10-09 14:00:51 UTC (rev 8398)
@@ -17,6 +17,12 @@
 
 #include "Layer.h"
 #include "FSDSAX2Parser.h"
+#include "AreaTypeStyle.h"
+#include "LineTypeStyle.h"
+#include "PointTypeStyle.h"
+#include "CompositeTypeStyle.h"
+#include "VectorScaleRange.h"
+#include "VectorLayerDefinition.h"
 #include "Services/ServiceFactory.h"
 #include "Services/ScrollableFeatureReader.h"
 
@@ -616,6 +622,216 @@
     return false;
 }
 
+MgIntCollection* MgdLayer::GetGeometryTypeStyles()
+{
+    Ptr<MgIntCollection> ret;
+
+    MG_TRY()
+
+    ret = GetGeometryTypeStyles(GetMap()->GetViewScale());
+
+    MG_CATCH_AND_THROW(L"MgdLayer.GetGeometryTypeStyles");
+
+    return ret.Detach();
+}
+
+INT32 MgdLayer::GetThemeCategoryCount(INT32 geomType)
+{
+    return GetThemeCategoryCount(GetMap()->GetViewScale(), geomType);
+}
+
+MgByteReader* MgdLayer::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"MgdLayer.GenerateLegendImage");
+
+    return ret.Detach();
+}
+
+MgIntCollection* MgdLayer::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)
+                            {
+                                ret->Add(4);
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    MG_CATCH_AND_THROW(L"MgdLayer.GenerateLegendImage");
+
+    return ret.Detach();
+}
+
+INT32 MgdLayer::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;
+}
+
+INT32 MgdLayer::GetCompositeThemeCategoryCount(INT32 compositeOffset)
+{
+    return GetCompositeThemeCategoryCount(GetMap()->GetViewScale(), compositeOffset);
+}
+
+INT32 MgdLayer::GetCompositeThemeCategoryCount(double scale, INT32 compositeOffset)
+{
+    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();
+                        //NOTE: If a Layer Definition has basic and composite types, then this offset will probably be wrong
+                        //but such layers are technically illegal and we shouldn't try to be catering to such layers
+                        if (compositeOffset < ftsc->GetCount())
+                        {
+                            MdfModel::CompositeTypeStyle* cts = dynamic_cast<MdfModel::CompositeTypeStyle*>(ftsc->GetAt(compositeOffset));
+                            if (cts != NULL)
+                            {
+                                ret = cts->GetRules()->GetCount();
+                                break;
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+    
+    return ret;
+}
+
+MgByteReader* MgdLayer::GenerateLegendImage(double scale, INT32 width, INT32 height, CREFSTRING format, INT32 geomType, INT32 themeCategory)
+{
+    Ptr<MgByteReader> ret;
+
+    MG_TRY()
+
+    Ptr<MgdMappingService> svcMapping = dynamic_cast<MgdMappingService*>(GetMap()->GetService(MgServiceType::MappingService));
+    ret = svcMapping->GenerateLegendImage(m_definition, scale, width, height, format, geomType, themeCategory);
+
+    MG_CATCH_AND_THROW(L"MgdLayer.GenerateLegendImage");
+
+    return ret.Detach();
+}
+
 bool MgdLayer::HasTooltips()
 {
     return MgLayerBase::HasTooltips();

Modified: trunk/MgDev/Desktop/MgDesktop/MapLayer/Layer.h
===================================================================
--- trunk/MgDev/Desktop/MgDesktop/MapLayer/Layer.h	2014-10-08 01:53:06 UTC (rev 8397)
+++ trunk/MgDev/Desktop/MgDesktop/MapLayer/Layer.h	2014-10-09 14:00:51 UTC (rev 8398)
@@ -47,6 +47,276 @@
 
 	virtual MgSpatialContextReader* GetSpatialContexts(bool active);
 
+    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+    /// \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.
+    /// For a scale range with multiple composite styles, multiple instances of (4 = composite) will be in the resulting collection
+    ///
+    /// \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.
+    /// When geomType = 4, it will only count the number of the theme categories for the first composite style it finds. For a scale range
+    /// with multiple composite type styles, you should use GetCompositeThemeCategoryCount() instead
+    ///
+    /// \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
+    /// Gets the number of composite theme categories for this layer at the map's current scale for the given composite 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 compositeOffset (int)
+    /// The zero-based index denoting the particular composite style to count from. 0 = 1st composite style, 1 = 2nd composite style
+    ///
+    /// \return
+    /// The number of theme categories for this layer at the map's current scale for the given composite 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 GetCompositeThemeCategoryCount(INT32 compositeOffset);
+
+    ////////////////////////////////////////////////////////////////////////////////
+    /// \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
+    ///
+    /// \remarks
+    /// For a scale range with multiple composite styles, multiple instances of (4 = composite) will be in the resulting collection
+    ///
+    /// \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
+    ///
+    /// \remarks
+    /// When geomType = 4, it will only count the number of the theme categories for the first composite style it finds. For a scale range
+    /// with multiple composite type styles, you should use GetCompositeThemeCategoryCount() instead
+    ///
+    /// \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
+    /// Gets the number of composite theme categories for this layer at the map's current scale for the given composite 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 compositeOffset (int)
+    /// The zero-based index denoting the particular composite style to count from. 0 = 1st composite style, 1 = 2nd composite style
+    ///
+    /// \return
+    /// The number of theme categories for this layer at the map's current scale for the given composite 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 GetCompositeThemeCategoryCount(double scale, INT32 compositeOffset);
+
+    ////////////////////////////////////////////////////////////////////////////////
+    /// \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:
 
     //////////////////////////////////////////////////////////////////



More information about the mapguide-commits mailing list