[mapguide-commits] r9143 - in trunk/MgDev: Common/MapGuideCommon/MapLayer Common/PlatformBase/MapLayer Server/src/UnitTesting UnitTest/WebTier/DotNet/MgTestRunner UnitTest/WebTier/DotNet/TestCommon UnitTest/WebTier/DotNet/TestMapGuideApi UnitTest/WebTier/DotNet/TestMapGuideApi/ExternalTests
svn_mapguide at osgeo.org
svn_mapguide at osgeo.org
Tue Apr 11 08:00:00 PDT 2017
Author: jng
Date: 2017-04-11 08:00:00 -0700 (Tue, 11 Apr 2017)
New Revision: 9143
Added:
trunk/MgDev/UnitTest/WebTier/DotNet/TestMapGuideApi/ExternalTests/StatelessMapTests.cs
trunk/MgDev/UnitTest/WebTier/DotNet/TestMapGuideApi/ExternalTests/Utils.cs
Modified:
trunk/MgDev/Common/MapGuideCommon/MapLayer/Map.cpp
trunk/MgDev/Common/MapGuideCommon/MapLayer/Map.h
trunk/MgDev/Common/PlatformBase/MapLayer/SelectionBase.h
trunk/MgDev/Server/src/UnitTesting/TestMisc.cpp
trunk/MgDev/Server/src/UnitTesting/TestMisc.h
trunk/MgDev/UnitTest/WebTier/DotNet/MgTestRunner/Program.cs
trunk/MgDev/UnitTest/WebTier/DotNet/TestCommon/CommonTests.cs
trunk/MgDev/UnitTest/WebTier/DotNet/TestMapGuideApi/ExternalTests/RenderingServiceTests.cs
trunk/MgDev/UnitTest/WebTier/DotNet/TestMapGuideApi/TestMapGuideApi.csproj
Log:
Implement RFC 157
This adds a new overload of MgMap::Create that accepts:
- map definition id
- map name
- image width
- image height
- view center X
- view center Y
- view scale
- dpi
With this overload, the created MgMap instance can be used on the following APIs statelessly without needing to open it first from a session repository (via a session id and map name pair)
- MgRenderingService::QueryFeatures
- MgRenderingService::QueryFeatureProperties
- MgRenderingService::RenderMapLegend
- MgRenderingService::RenderDynamicOverlay
With this change, there is enough APIs in place from which to build a stateless map viewer that can perform selections and does not require creating or interacting with a session repository or resources inside it.
As an addendum to the original RFC, the MgSelectionBase::SetMap method has also been promoted to EXTERNAL_API to allow selections from an MgFeatureInformation to be interrogated without throwing.
A server unit test has been added to verify these new MgMap::Create parameters stick on the map.
A series of .net unit tests have been added to exercise the aforementioned rendering service APIs using the statelessly-created MgMap.
Fixes #2766
Modified: trunk/MgDev/Common/MapGuideCommon/MapLayer/Map.cpp
===================================================================
--- trunk/MgDev/Common/MapGuideCommon/MapLayer/Map.cpp 2017-04-07 12:03:09 UTC (rev 9142)
+++ trunk/MgDev/Common/MapGuideCommon/MapLayer/Map.cpp 2017-04-11 15:00:00 UTC (rev 9143)
@@ -129,6 +129,19 @@
Create(NULL, mapDefinition, mapName);
}
+void MgMap::Create(MgResourceIdentifier* mapDefinition, CREFSTRING mapName, INT32 displayWidth, INT32 displayHeight, double x, double y, double scale, INT32 dpi)
+{
+ Create(NULL, mapDefinition, mapName);
+ m_displayWidth = displayWidth;
+ m_displayHeight = displayHeight;
+ MgGeometryFactory gf;
+ Ptr<MgCoordinate> coord = gf.CreateCoordinateXY(x, y);
+ Ptr<MgPoint> pt = gf.CreatePoint(coord);
+ SetViewCenter(pt);
+ m_scale = scale;
+ m_displayDpi = dpi;
+}
+
void MgMap::CreateFromMapDefinition(MgResourceService* resourceService, MgResourceIdentifier* mapDefinition, CREFSTRING mapName)
{
MG_TRY()
Modified: trunk/MgDev/Common/MapGuideCommon/MapLayer/Map.h
===================================================================
--- trunk/MgDev/Common/MapGuideCommon/MapLayer/Map.h 2017-04-07 12:03:09 UTC (rev 9142)
+++ trunk/MgDev/Common/MapGuideCommon/MapLayer/Map.h 2017-04-11 15:00:00 UTC (rev 9143)
@@ -353,6 +353,63 @@
//////////////////////////////////////////////////////////////////
/// \brief
+ /// Initializes a new MgMap object given a map definition or tile set
+ /// definition and a name for the map with initial display parameters set.
+ /// This method is used for MapGuide Viewers or for offline map production.
+ ///
+ /// \remarks
+ /// If creating a MgMap object from a tile set definition, only "Default" is the
+ /// acceptable tile provider. Any other provider will cause this method to
+ /// throw a MgUnsupportedTileProviderException
+ ///
+ /// <!-- Syntax in .Net, Java, and PHP -->
+ /// \htmlinclude DotNetSyntaxTop.html
+ /// void Create(MgResourceIdentifier mapDefinition, string mapName, int displayWidth, int displayHeight, double x, double y, double scale, int dpi);
+ /// \htmlinclude SyntaxBottom.html
+ /// \htmlinclude JavaSyntaxTop.html
+ /// void Create(MgResourceIdentifier mapDefinition, String mapName, int displayWidth, int displayHeight, double x, double y, double scale, int dpi);
+ /// \htmlinclude SyntaxBottom.html
+ /// \htmlinclude PHPSyntaxTop.html
+ /// void Create(MgResourceIdentifier mapDefinition, string mapName, int displayWidth, int displayHeight, double x, double y, double scale, int dpi);
+ /// \htmlinclude SyntaxBottom.html
+ ///
+ /// \param resource
+ /// An MgResourceIdentifier that specifies the
+ /// location of the map definition in a resource
+ /// repository.
+ /// \param mapName
+ /// A string that specifies the name of the map.
+ /// \param displayWidth
+ /// The display width to initially set for the map
+ /// \param displayHeight
+ /// The display height to initially set for the map
+ /// \param x
+ /// The view center X coordinate to initially set for the map
+ /// \param y
+ /// The view center Y coordinate to initially set for the map
+ /// \param scale
+ /// The view scale to initially set for the map
+ /// \param dpi
+ /// The display DPI to initially set for the map
+ ///
+ /// \return
+ /// Returns nothing.
+ ///
+ /// <!-- Example (PHP) -->
+ /// \htmlinclude PHPExampleTop.html
+ /// \code
+ /// // Assuming the site connection has already been intialized
+ /// $resourceID = new MgResourceIdentifier('Library://Calgary/Maps/Calgary.MapDefinition');
+ /// $map = new MgMap($site);
+ /// // Initializes the map to be centered on the Calgary CBD at 1:5000 scale with a DPI of 96
+ /// $map->Create($resourceID, 'Calgary', 640, 480, -114.054565, 51.068369, 5000.0, 96);
+ /// \endcode
+ /// \htmlinclude ExampleBottom.html
+ ///
+ virtual void Create(MgResourceIdentifier* resource, CREFSTRING mapName, INT32 displayWidth, INT32 displayheight, double x, double y, double scale, INT32 dpi);
+
+ //////////////////////////////////////////////////////////////////
+ /// \brief
/// Loads the map object from a session repository.
///
/// \remarks
Modified: trunk/MgDev/Common/PlatformBase/MapLayer/SelectionBase.h
===================================================================
--- trunk/MgDev/Common/PlatformBase/MapLayer/SelectionBase.h 2017-04-07 12:03:09 UTC (rev 9142)
+++ trunk/MgDev/Common/PlatformBase/MapLayer/SelectionBase.h 2017-04-11 15:00:00 UTC (rev 9143)
@@ -538,6 +538,12 @@
///
STRING GetResourceName(CREFSTRING sessionId, CREFSTRING mapName);
+EXTERNAL_API:
+ /////////////////////////////////////////
+ /// Set the map object. To be used ONLY for deserialization
+ //
+ void SetMap(MgMapBase* map);
+
INTERNAL_API:
@@ -579,11 +585,6 @@
virtual bool CanSetName();
/////////////////////////////////////////
- /// Set the map object. To be used ONLY for deserialization
- //
- void SetMap(MgMapBase* map);
-
- /////////////////////////////////////////
/// Write selection as XML document
//
STRING ToXml(bool withXmlDecl);
Modified: trunk/MgDev/Server/src/UnitTesting/TestMisc.cpp
===================================================================
--- trunk/MgDev/Server/src/UnitTesting/TestMisc.cpp 2017-04-07 12:03:09 UTC (rev 9142)
+++ trunk/MgDev/Server/src/UnitTesting/TestMisc.cpp 2017-04-11 15:00:00 UTC (rev 9143)
@@ -564,6 +564,35 @@
}
}
+void TestMisc::TestCase_CreateMapWithInitialDisplayParams()
+{
+ try
+ {
+ Ptr<MgResourceIdentifier> mapRes1 = new MgResourceIdentifier(L"Library://UnitTests/Maps/Sheboygan.MapDefinition");
+ Ptr<MgMap> map = new MgMap(m_siteConnection);
+ map->Create(mapRes1, L"TestCase_CreateMapWithInitialDisplayParams", 800, 600, -87.45, 43.32, 8000.0, 256);
+
+ CPPUNIT_ASSERT_MESSAGE("Expected width of 800", map->GetDisplayWidth() == 800);
+ CPPUNIT_ASSERT_MESSAGE("Expected height of 600", map->GetDisplayHeight() == 600);
+ Ptr<MgPoint> pt = map->GetViewCenter();
+ Ptr<MgCoordinate> coord = pt->GetCoordinate();
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(coord->GetX(), -87.45, 0.001);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(coord->GetY(), 43.32, 0.001);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(map->GetViewScale(), 8000.0, 0.0001);
+ CPPUNIT_ASSERT_MESSAGE("Expected DPI of 256", map->GetDisplayDpi(), 256);
+ }
+ catch (MgException* e)
+ {
+ STRING message = e->GetDetails(TEST_LOCALE);
+ SAFE_RELEASE(e);
+ CPPUNIT_FAIL(MG_WCHAR_TO_CHAR(message.c_str()));
+ }
+ catch (...)
+ {
+ throw;
+ }
+}
+
void TestMisc::TestCase_MapLayerCollections()
{
try
Modified: trunk/MgDev/Server/src/UnitTesting/TestMisc.h
===================================================================
--- trunk/MgDev/Server/src/UnitTesting/TestMisc.h 2017-04-07 12:03:09 UTC (rev 9142)
+++ trunk/MgDev/Server/src/UnitTesting/TestMisc.h 2017-04-11 15:00:00 UTC (rev 9143)
@@ -48,6 +48,7 @@
void TestCase_833();
void TestCase_1304();
void TestCase_MapLayerCollections();
+ void TestCase_CreateMapWithInitialDisplayParams();
private:
Ptr<MgSiteConnection> m_siteConnection;
Modified: trunk/MgDev/UnitTest/WebTier/DotNet/MgTestRunner/Program.cs
===================================================================
--- trunk/MgDev/UnitTest/WebTier/DotNet/MgTestRunner/Program.cs 2017-04-07 12:03:09 UTC (rev 9142)
+++ trunk/MgDev/UnitTest/WebTier/DotNet/MgTestRunner/Program.cs 2017-04-11 15:00:00 UTC (rev 9143)
@@ -44,6 +44,13 @@
return map;
}
+ public MgMapBase CreateMap(MgResourceIdentifier mapDefinition, string mapName, int width, int height, double x, double y, double scale, int dpi)
+ {
+ var map = new MgMap(_siteConn);
+ map.Create(mapDefinition, mapName, width, height, x, y, scale, dpi);
+ return map;
+ }
+
public MgLayerBase CreateLayer(MgResourceIdentifier resId)
{
MgResourceService resSvc = (MgResourceService)_siteConn.CreateService(MgServiceType.ResourceService);
Modified: trunk/MgDev/UnitTest/WebTier/DotNet/TestCommon/CommonTests.cs
===================================================================
--- trunk/MgDev/UnitTest/WebTier/DotNet/TestCommon/CommonTests.cs 2017-04-07 12:03:09 UTC (rev 9142)
+++ trunk/MgDev/UnitTest/WebTier/DotNet/TestCommon/CommonTests.cs 2017-04-11 15:00:00 UTC (rev 9143)
@@ -19,6 +19,7 @@
{
MgService CreateService(int serviceType);
MgMapBase CreateMap(MgResourceIdentifier mapDefinition);
+ MgMapBase CreateMap(MgResourceIdentifier mapDefinition, string mapName, int width, int height, double x, double y, double scale, int dpi);
MgMapBase CreateMap(string coordSys, MgEnvelope env, string name);
MgLayerBase CreateLayer(MgResourceIdentifier resId);
}
Modified: trunk/MgDev/UnitTest/WebTier/DotNet/TestMapGuideApi/ExternalTests/RenderingServiceTests.cs
===================================================================
--- trunk/MgDev/UnitTest/WebTier/DotNet/TestMapGuideApi/ExternalTests/RenderingServiceTests.cs 2017-04-07 12:03:09 UTC (rev 9142)
+++ trunk/MgDev/UnitTest/WebTier/DotNet/TestMapGuideApi/ExternalTests/RenderingServiceTests.cs 2017-04-11 15:00:00 UTC (rev 9143)
@@ -12,116 +12,47 @@
{
public class RenderTileTest : IExternalTest
{
- private static void LoadResource(MgResourceService resSvc, string resIdStr, string path)
- {
- MgResourceIdentifier resId = new MgResourceIdentifier(resIdStr);
- MgByteSource bs = new MgByteSource(path);
- MgByteReader br = bs.GetReader();
- resSvc.SetResource(resId, br, null);
- }
-
- private static void LoadResourceData(MgResourceService resSvc, string resIdStr, string dataName, string dataType, string path)
- {
- MgResourceIdentifier resId = new MgResourceIdentifier(resIdStr);
- MgByteSource bs = new MgByteSource(path);
- MgByteReader br = bs.GetReader();
- resSvc.SetResourceData(resId, dataName, dataType, br);
- }
-
public void Execute(IPlatformFactory factory, ITestLogger logger)
{
var resSvc = (MgResourceService)factory.CreateService(MgServiceType.ResourceService);
var renderSvc = (MgRenderingService)factory.CreateService(MgServiceType.RenderingService);
var root = "../../TestData/TileService/";
- LoadResource(resSvc, "Library://UnitTests/Data/RoadCenterLines.FeatureSource", root + "UT_RoadCenterLines.fs");
- LoadResourceData(resSvc, "Library://UnitTests/Data/RoadCenterLines.FeatureSource", "UT_RoadCenterLines.sdf", MgResourceDataType.File, root + "UT_RoadCenterLines.sdf");
- LoadResource(resSvc, "Library://UnitTests/Layers/RoadCenterLines.LayerDefinition", root + "UT_RoadCenterLines.ldf");
+ Utils.LoadResource(resSvc, "Library://UnitTests/Data/RoadCenterLines.FeatureSource", root + "UT_RoadCenterLines.fs");
+ Utils.LoadResourceData(resSvc, "Library://UnitTests/Data/RoadCenterLines.FeatureSource", "UT_RoadCenterLines.sdf", MgResourceDataType.File, root + "UT_RoadCenterLines.sdf");
+ Utils.LoadResource(resSvc, "Library://UnitTests/Layers/RoadCenterLines.LayerDefinition", root + "UT_RoadCenterLines.ldf");
- LoadResource(resSvc, "Library://UnitTests/Data/VotingDistricts.FeatureSource", root + "UT_VotingDistricts.fs");
- LoadResourceData(resSvc, "Library://UnitTests/Data/VotingDistricts.FeatureSource", "UT_VotingDistricts.sdf", MgResourceDataType.File, root + "UT_VotingDistricts.sdf");
- LoadResource(resSvc, "Library://UnitTests/Layers/VotingDistricts.LayerDefinition", root + "UT_VotingDistricts.ldf");
+ Utils.LoadResource(resSvc, "Library://UnitTests/Data/VotingDistricts.FeatureSource", root + "UT_VotingDistricts.fs");
+ Utils.LoadResourceData(resSvc, "Library://UnitTests/Data/VotingDistricts.FeatureSource", "UT_VotingDistricts.sdf", MgResourceDataType.File, root + "UT_VotingDistricts.sdf");
+ Utils.LoadResource(resSvc, "Library://UnitTests/Layers/VotingDistricts.LayerDefinition", root + "UT_VotingDistricts.ldf");
- LoadResource(resSvc, "Library://UnitTests/Data/Parcels.FeatureSource", root + "UT_Parcels.fs");
- LoadResourceData(resSvc, "Library://UnitTests/Data/Parcels.FeatureSource", "UT_Parcels.sdf", MgResourceDataType.File, root + "UT_Parcels.sdf");
- LoadResource(resSvc, "Library://UnitTests/Layers/Parcels.LayerDefinition", root + "UT_Parcels.ldf");
+ Utils.LoadResource(resSvc, "Library://UnitTests/Data/Parcels.FeatureSource", root + "UT_Parcels.fs");
+ Utils.LoadResourceData(resSvc, "Library://UnitTests/Data/Parcels.FeatureSource", "UT_Parcels.sdf", MgResourceDataType.File, root + "UT_Parcels.sdf");
+ Utils.LoadResource(resSvc, "Library://UnitTests/Layers/Parcels.LayerDefinition", root + "UT_Parcels.ldf");
- LoadResource(resSvc, "Library://UnitTests/Maps/BaseMap.MapDefinition", root + "UT_BaseMap.mdf");
+ Utils.LoadResource(resSvc, "Library://UnitTests/Maps/BaseMap.MapDefinition", root + "UT_BaseMap.mdf");
var map = (MgMap)factory.CreateMap(new MgResourceIdentifier("Library://UnitTests/Maps/BaseMap.MapDefinition"));
var img = renderSvc.RenderTile(map, "BaseLayers", 0, 0);
- CheckValidImage(img);
+ Utils.CheckValidImage(img);
img = renderSvc.RenderTile(map, "BaseLayers", 0, 0, 256, 256, 96, MgImageFormats.Png);
- CheckValidImage(img, 256, 256, MgImageFormats.Png);
+ Utils.CheckValidImage(img, 256, 256, MgImageFormats.Png);
img = renderSvc.RenderTile(map, "BaseLayers", 0, 0, 256, 256, 96, MgImageFormats.Gif);
- CheckValidImage(img, 256, 256, MgImageFormats.Gif);
+ Utils.CheckValidImage(img, 256, 256, MgImageFormats.Gif);
img = renderSvc.RenderTile(map, "BaseLayers", 0, 0, 256, 256, 96, MgImageFormats.Jpeg);
- CheckValidImage(img, 256, 256, MgImageFormats.Jpeg);
+ Utils.CheckValidImage(img, 256, 256, MgImageFormats.Jpeg);
img = renderSvc.RenderTile(map, "BaseLayers", 0, 0, 256, 256, 96, MgImageFormats.Png8);
- CheckValidImage(img, 256, 256, MgImageFormats.Png8);
+ Utils.CheckValidImage(img, 256, 256, MgImageFormats.Png8);
img = renderSvc.RenderTileXYZ(map, "BaseLayers", 2099, 2985, 13);
- CheckValidImage(img, 256, 256);
+ Utils.CheckValidImage(img, 256, 256);
img = renderSvc.RenderTileXYZ(map, "BaseLayers", 2099, 2985, 13, 96, MgImageFormats.Png);
- CheckValidImage(img, 256, 256, MgImageFormats.Png);
+ Utils.CheckValidImage(img, 256, 256, MgImageFormats.Png);
img = renderSvc.RenderTileXYZ(map, "BaseLayers", 2099, 2985, 13, 96, MgImageFormats.Png8);
- CheckValidImage(img, 256, 256, MgImageFormats.Png8);
+ Utils.CheckValidImage(img, 256, 256, MgImageFormats.Png8);
img = renderSvc.RenderTileXYZ(map, "BaseLayers", 2099, 2985, 13, 96, MgImageFormats.Gif);
- CheckValidImage(img, 256, 256, MgImageFormats.Gif);
+ Utils.CheckValidImage(img, 256, 256, MgImageFormats.Gif);
img = renderSvc.RenderTileXYZ(map, "BaseLayers", 2099, 2985, 13, 96, MgImageFormats.Jpeg);
- CheckValidImage(img, 256, 256, MgImageFormats.Jpeg);
+ Utils.CheckValidImage(img, 256, 256, MgImageFormats.Jpeg);
}
-
- private void CheckValidImage(MgByteReader img, int? imageWidth = null, int? imageHeight = null, string format = null)
- {
- try
- {
- MgByteSink sink = new MgByteSink(img);
- sink.ToFile("tile.img");
- using (Image image = Image.FromFile("tile.img"))
- {
- Assert.IsNotNull(image);
- if (imageWidth != null)
- Assert.Equals(image.Width, imageWidth.Value);
- if (imageHeight != null)
- Assert.Equals(image.Height, imageHeight.Value);
-
- if (format != null)
- {
- switch(format)
- {
- case MgImageFormats.Gif:
- Assert.Equals(image.RawFormat, ImageFormat.Gif);
- break;
- case MgImageFormats.Jpeg:
- Assert.Equals(image.RawFormat, ImageFormat.Jpeg);
- break;
- case MgImageFormats.Png:
- case MgImageFormats.Png8:
- Assert.Equals(image.RawFormat, ImageFormat.Png);
- break;
- case MgImageFormats.Tiff:
- Assert.Equals(image.RawFormat, ImageFormat.Tiff);
- break;
- }
- }
- }
- }
- catch (Exception ex)
- {
- throw new AssertException("Invalid image found: " + ex.Message);
- }
- finally
- {
- if (File.Exists("tile.img"))
- {
- try
- {
- File.Delete("tile.img");
- }
- catch { }
- }
- }
- }
}
-
}
Added: trunk/MgDev/UnitTest/WebTier/DotNet/TestMapGuideApi/ExternalTests/StatelessMapTests.cs
===================================================================
--- trunk/MgDev/UnitTest/WebTier/DotNet/TestMapGuideApi/ExternalTests/StatelessMapTests.cs (rev 0)
+++ trunk/MgDev/UnitTest/WebTier/DotNet/TestMapGuideApi/ExternalTests/StatelessMapTests.cs 2017-04-11 15:00:00 UTC (rev 9143)
@@ -0,0 +1,189 @@
+using OSGeo.MapGuide.Test.Common;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OSGeo.MapGuide.Test.Web.ExternalTests
+{
+ public class QueryFeatureStatelessTest : IExternalTest
+ {
+ public void Execute(IPlatformFactory factory, ITestLogger logger)
+ {
+ var resSvc = (MgResourceService)factory.CreateService(MgServiceType.ResourceService);
+ var renderSvc = (MgRenderingService)factory.CreateService(MgServiceType.RenderingService);
+ var root = "../../TestData/TileService/";
+
+ Utils.LoadResource(resSvc, "Library://UnitTests/Data/RoadCenterLines.FeatureSource", root + "UT_RoadCenterLines.fs");
+ Utils.LoadResourceData(resSvc, "Library://UnitTests/Data/RoadCenterLines.FeatureSource", "UT_RoadCenterLines.sdf", MgResourceDataType.File, root + "UT_RoadCenterLines.sdf");
+ Utils.LoadResource(resSvc, "Library://UnitTests/Layers/RoadCenterLines.LayerDefinition", root + "UT_RoadCenterLines.ldf");
+
+ Utils.LoadResource(resSvc, "Library://UnitTests/Data/VotingDistricts.FeatureSource", root + "UT_VotingDistricts.fs");
+ Utils.LoadResourceData(resSvc, "Library://UnitTests/Data/VotingDistricts.FeatureSource", "UT_VotingDistricts.sdf", MgResourceDataType.File, root + "UT_VotingDistricts.sdf");
+ Utils.LoadResource(resSvc, "Library://UnitTests/Layers/VotingDistricts.LayerDefinition", root + "UT_VotingDistricts.ldf");
+
+ Utils.LoadResource(resSvc, "Library://UnitTests/Data/Parcels.FeatureSource", root + "UT_Parcels.fs");
+ Utils.LoadResourceData(resSvc, "Library://UnitTests/Data/Parcels.FeatureSource", "UT_Parcels.sdf", MgResourceDataType.File, root + "UT_Parcels.sdf");
+ Utils.LoadResource(resSvc, "Library://UnitTests/Layers/Parcels.LayerDefinition", root + "UT_Parcels.ldf");
+
+ Utils.LoadResource(resSvc, "Library://UnitTests/Maps/BaseMap.MapDefinition", root + "UT_BaseMap.mdf");
+
+ var mdfId = new MgResourceIdentifier("Library://UnitTests/Maps/BaseMap.MapDefinition");
+
+ //This is a sample request from the AJAX viewer. It selected 7 features. It should do the same here.
+ var dpi = 96;
+ var width = 773;
+ var height = 696;
+ var scale = 4345.697945713148;
+ var x = -87.72117757411266;
+ var y = 43.7527161153258;
+ var wkt = "POLYGON((-87.72250482778884 43.75497812742761, -87.72134799968197 43.75497812742761, -87.72134799968197 43.75358373640595, -87.72250482778884 43.75358373640595, -87.72250482778884 43.75497812742761))";
+ var map = (MgMap)factory.CreateMap(mdfId, mdfId.Name, width, height, x, y, scale, dpi);
+
+ var wktRw = new MgWktReaderWriter();
+ var geom = wktRw.Read(wkt);
+ var layerNames = new MgStringCollection();
+ layerNames.Add("Parcels");
+
+ var result = renderSvc.QueryFeatures(map, layerNames, geom, MgFeatureSpatialOperations.Intersects, -1);
+ var sel = result.GetSelection();
+ sel.SetMap(map);
+
+ var total = 0;
+ var selLayers = sel.GetLayers();
+
+ foreach (var sl in selLayers)
+ {
+ total += sel.GetSelectedFeaturesCount(sl, sl.FeatureClassName);
+ }
+
+ Assert.AreEqual(7, total);
+ }
+ }
+
+ public class QueryFeaturePropertiesStatelessTest : IExternalTest
+ {
+ public void Execute(IPlatformFactory factory, ITestLogger logger)
+ {
+ var resSvc = (MgResourceService)factory.CreateService(MgServiceType.ResourceService);
+ var renderSvc = (MgRenderingService)factory.CreateService(MgServiceType.RenderingService);
+ var root = "../../TestData/TileService/";
+
+ Utils.LoadResource(resSvc, "Library://UnitTests/Data/RoadCenterLines.FeatureSource", root + "UT_RoadCenterLines.fs");
+ Utils.LoadResourceData(resSvc, "Library://UnitTests/Data/RoadCenterLines.FeatureSource", "UT_RoadCenterLines.sdf", MgResourceDataType.File, root + "UT_RoadCenterLines.sdf");
+ Utils.LoadResource(resSvc, "Library://UnitTests/Layers/RoadCenterLines.LayerDefinition", root + "UT_RoadCenterLines.ldf");
+
+ Utils.LoadResource(resSvc, "Library://UnitTests/Data/VotingDistricts.FeatureSource", root + "UT_VotingDistricts.fs");
+ Utils.LoadResourceData(resSvc, "Library://UnitTests/Data/VotingDistricts.FeatureSource", "UT_VotingDistricts.sdf", MgResourceDataType.File, root + "UT_VotingDistricts.sdf");
+ Utils.LoadResource(resSvc, "Library://UnitTests/Layers/VotingDistricts.LayerDefinition", root + "UT_VotingDistricts.ldf");
+
+ Utils.LoadResource(resSvc, "Library://UnitTests/Data/Parcels.FeatureSource", root + "UT_Parcels.fs");
+ Utils.LoadResourceData(resSvc, "Library://UnitTests/Data/Parcels.FeatureSource", "UT_Parcels.sdf", MgResourceDataType.File, root + "UT_Parcels.sdf");
+ Utils.LoadResource(resSvc, "Library://UnitTests/Layers/Parcels.LayerDefinition", root + "UT_Parcels.ldf");
+
+ Utils.LoadResource(resSvc, "Library://UnitTests/Maps/BaseMap.MapDefinition", root + "UT_BaseMap.mdf");
+
+ var mdfId = new MgResourceIdentifier("Library://UnitTests/Maps/BaseMap.MapDefinition");
+
+ //This is a sample request from the AJAX viewer. It selected 7 features. It should do the same here.
+ var dpi = 96;
+ var width = 773;
+ var height = 696;
+ var scale = 4345.697945713148;
+ var x = -87.72117757411266;
+ var y = 43.7527161153258;
+ var wkt = "POLYGON((-87.72250482778884 43.75497812742761, -87.72134799968197 43.75497812742761, -87.72134799968197 43.75358373640595, -87.72250482778884 43.75358373640595, -87.72250482778884 43.75497812742761))";
+ var map = (MgMap)factory.CreateMap(mdfId, mdfId.Name, width, height, x, y, scale, dpi);
+
+ var wktRw = new MgWktReaderWriter();
+ var geom = wktRw.Read(wkt);
+ var layerNames = new MgStringCollection();
+ layerNames.Add("Parcels");
+
+ var result = renderSvc.QueryFeatureProperties(map, layerNames, geom, MgFeatureSpatialOperations.Intersects, -1);
+ Assert.AreEqual(7, result.Count);
+ }
+ }
+
+ public class RenderDynamicOverlayStatelessTest : IExternalTest
+ {
+ public void Execute(IPlatformFactory factory, ITestLogger logger)
+ {
+ var resSvc = (MgResourceService)factory.CreateService(MgServiceType.ResourceService);
+ var renderSvc = (MgRenderingService)factory.CreateService(MgServiceType.RenderingService);
+ var root = "../../TestData/TileService/";
+
+ Utils.LoadResource(resSvc, "Library://UnitTests/Data/RoadCenterLines.FeatureSource", root + "UT_RoadCenterLines.fs");
+ Utils.LoadResourceData(resSvc, "Library://UnitTests/Data/RoadCenterLines.FeatureSource", "UT_RoadCenterLines.sdf", MgResourceDataType.File, root + "UT_RoadCenterLines.sdf");
+ Utils.LoadResource(resSvc, "Library://UnitTests/Layers/RoadCenterLines.LayerDefinition", root + "UT_RoadCenterLines.ldf");
+
+ Utils.LoadResource(resSvc, "Library://UnitTests/Data/VotingDistricts.FeatureSource", root + "UT_VotingDistricts.fs");
+ Utils.LoadResourceData(resSvc, "Library://UnitTests/Data/VotingDistricts.FeatureSource", "UT_VotingDistricts.sdf", MgResourceDataType.File, root + "UT_VotingDistricts.sdf");
+ Utils.LoadResource(resSvc, "Library://UnitTests/Layers/VotingDistricts.LayerDefinition", root + "UT_VotingDistricts.ldf");
+
+ Utils.LoadResource(resSvc, "Library://UnitTests/Data/Parcels.FeatureSource", root + "UT_Parcels.fs");
+ Utils.LoadResourceData(resSvc, "Library://UnitTests/Data/Parcels.FeatureSource", "UT_Parcels.sdf", MgResourceDataType.File, root + "UT_Parcels.sdf");
+ Utils.LoadResource(resSvc, "Library://UnitTests/Layers/Parcels.LayerDefinition", root + "UT_Parcels.ldf");
+
+ Utils.LoadResource(resSvc, "Library://UnitTests/Maps/BaseMap.MapDefinition", root + "UT_BaseMap.mdf");
+
+ var mdfId = new MgResourceIdentifier("Library://UnitTests/Maps/BaseMap.MapDefinition");
+
+ //This is a sample request from the AJAX viewer. It selected 7 features. It should do the same here.
+ var dpi = 96;
+ var width = 773;
+ var height = 696;
+ var scale = 4345.697945713148;
+ var x = -87.72117757411266;
+ var y = 43.7527161153258;
+ var wkt = "POLYGON((-87.72250482778884 43.75497812742761, -87.72134799968197 43.75497812742761, -87.72134799968197 43.75358373640595, -87.72250482778884 43.75358373640595, -87.72250482778884 43.75497812742761))";
+ var map = (MgMap)factory.CreateMap(mdfId, mdfId.Name, width, height, x, y, scale, dpi);
+
+ var selColor = new MgColor(0, 0, 255);
+ var renderOpts = new MgRenderingOptions(MgImageFormats.Png, 1 | 2 | 4 | 8, selColor);
+ var result = renderSvc.RenderDynamicOverlay(map, null, renderOpts);
+
+ Utils.CheckValidImage(result, width, height, MgImageFormats.Png);
+ }
+ }
+
+ public class RenderMapLegendStatelessTest : IExternalTest
+ {
+ public void Execute(IPlatformFactory factory, ITestLogger logger)
+ {
+ var resSvc = (MgResourceService)factory.CreateService(MgServiceType.ResourceService);
+ var renderSvc = (MgRenderingService)factory.CreateService(MgServiceType.RenderingService);
+ var root = "../../TestData/TileService/";
+
+ Utils.LoadResource(resSvc, "Library://UnitTests/Data/RoadCenterLines.FeatureSource", root + "UT_RoadCenterLines.fs");
+ Utils.LoadResourceData(resSvc, "Library://UnitTests/Data/RoadCenterLines.FeatureSource", "UT_RoadCenterLines.sdf", MgResourceDataType.File, root + "UT_RoadCenterLines.sdf");
+ Utils.LoadResource(resSvc, "Library://UnitTests/Layers/RoadCenterLines.LayerDefinition", root + "UT_RoadCenterLines.ldf");
+
+ Utils.LoadResource(resSvc, "Library://UnitTests/Data/VotingDistricts.FeatureSource", root + "UT_VotingDistricts.fs");
+ Utils.LoadResourceData(resSvc, "Library://UnitTests/Data/VotingDistricts.FeatureSource", "UT_VotingDistricts.sdf", MgResourceDataType.File, root + "UT_VotingDistricts.sdf");
+ Utils.LoadResource(resSvc, "Library://UnitTests/Layers/VotingDistricts.LayerDefinition", root + "UT_VotingDistricts.ldf");
+
+ Utils.LoadResource(resSvc, "Library://UnitTests/Data/Parcels.FeatureSource", root + "UT_Parcels.fs");
+ Utils.LoadResourceData(resSvc, "Library://UnitTests/Data/Parcels.FeatureSource", "UT_Parcels.sdf", MgResourceDataType.File, root + "UT_Parcels.sdf");
+ Utils.LoadResource(resSvc, "Library://UnitTests/Layers/Parcels.LayerDefinition", root + "UT_Parcels.ldf");
+
+ Utils.LoadResource(resSvc, "Library://UnitTests/Maps/BaseMap.MapDefinition", root + "UT_BaseMap.mdf");
+
+ var mdfId = new MgResourceIdentifier("Library://UnitTests/Maps/BaseMap.MapDefinition");
+
+ var dpi = 96;
+ var width = 773;
+ var height = 696;
+ var scale = 4345.697945713148;
+ var x = -87.72117757411266;
+ var y = 43.7527161153258;
+ var wkt = "POLYGON((-87.72250482778884 43.75497812742761, -87.72134799968197 43.75497812742761, -87.72134799968197 43.75358373640595, -87.72250482778884 43.75358373640595, -87.72250482778884 43.75497812742761))";
+ var map = (MgMap)factory.CreateMap(mdfId, mdfId.Name, width, height, x, y, scale, dpi);
+
+ var bgColor = new MgColor(255, 255, 255);
+ var result = renderSvc.RenderMapLegend(map, 200, 600, bgColor, MgImageFormats.Png);
+ Utils.CheckValidImage(result, 200, 600, MgImageFormats.Png);
+ }
+ }
+}
Added: trunk/MgDev/UnitTest/WebTier/DotNet/TestMapGuideApi/ExternalTests/Utils.cs
===================================================================
--- trunk/MgDev/UnitTest/WebTier/DotNet/TestMapGuideApi/ExternalTests/Utils.cs (rev 0)
+++ trunk/MgDev/UnitTest/WebTier/DotNet/TestMapGuideApi/ExternalTests/Utils.cs 2017-04-11 15:00:00 UTC (rev 9143)
@@ -0,0 +1,83 @@
+using OSGeo.MapGuide.Test.Common;
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Drawing.Imaging;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OSGeo.MapGuide.Test.Web.ExternalTests
+{
+ class Utils
+ {
+ internal static void LoadResource(MgResourceService resSvc, string resIdStr, string path)
+ {
+ MgResourceIdentifier resId = new MgResourceIdentifier(resIdStr);
+ MgByteSource bs = new MgByteSource(path);
+ MgByteReader br = bs.GetReader();
+ resSvc.SetResource(resId, br, null);
+ }
+
+ internal static void LoadResourceData(MgResourceService resSvc, string resIdStr, string dataName, string dataType, string path)
+ {
+ MgResourceIdentifier resId = new MgResourceIdentifier(resIdStr);
+ MgByteSource bs = new MgByteSource(path);
+ MgByteReader br = bs.GetReader();
+ resSvc.SetResourceData(resId, dataName, dataType, br);
+ }
+
+ internal static void CheckValidImage(MgByteReader img, int? imageWidth = null, int? imageHeight = null, string format = null)
+ {
+ try
+ {
+ MgByteSink sink = new MgByteSink(img);
+ sink.ToFile("tile.img");
+ using (Image image = Image.FromFile("tile.img"))
+ {
+ Assert.IsNotNull(image);
+ if (imageWidth != null)
+ Assert.Equals(image.Width, imageWidth.Value);
+ if (imageHeight != null)
+ Assert.Equals(image.Height, imageHeight.Value);
+
+ if (format != null)
+ {
+ switch (format)
+ {
+ case MgImageFormats.Gif:
+ Assert.Equals(image.RawFormat, ImageFormat.Gif);
+ break;
+ case MgImageFormats.Jpeg:
+ Assert.Equals(image.RawFormat, ImageFormat.Jpeg);
+ break;
+ case MgImageFormats.Png:
+ case MgImageFormats.Png8:
+ Assert.Equals(image.RawFormat, ImageFormat.Png);
+ break;
+ case MgImageFormats.Tiff:
+ Assert.Equals(image.RawFormat, ImageFormat.Tiff);
+ break;
+ }
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ throw new AssertException("Invalid image found: " + ex.Message);
+ }
+ finally
+ {
+ if (File.Exists("tile.img"))
+ {
+ try
+ {
+ File.Delete("tile.img");
+ }
+ catch { }
+ }
+ }
+ }
+ }
+}
Modified: trunk/MgDev/UnitTest/WebTier/DotNet/TestMapGuideApi/TestMapGuideApi.csproj
===================================================================
--- trunk/MgDev/UnitTest/WebTier/DotNet/TestMapGuideApi/TestMapGuideApi.csproj 2017-04-07 12:03:09 UTC (rev 9142)
+++ trunk/MgDev/UnitTest/WebTier/DotNet/TestMapGuideApi/TestMapGuideApi.csproj 2017-04-11 15:00:00 UTC (rev 9143)
@@ -99,6 +99,8 @@
<Compile Include="ExternalTests\MapTests.cs" />
<Compile Include="ExternalTests\RenderingServiceTests.cs" />
<Compile Include="ExternalTests\ResourceServiceTests.cs" />
+ <Compile Include="ExternalTests\StatelessMapTests.cs" />
+ <Compile Include="ExternalTests\Utils.cs" />
<Compile Include="MapGuideTests.cs" />
<Compile Include="MappingService\MappingServiceOperationExecutor.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
More information about the mapguide-commits
mailing list