[mapguide-commits] r9609 - in sandbox/jng/mvt_alt: . Common/Foundation/Data Common/MapGuideCommon/Services Common/Renderers Server/src/Services/Rendering

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Sat Sep 21 13:14:42 PDT 2019


Author: jng
Date: 2019-09-21 13:14:42 -0700 (Sat, 21 Sep 2019)
New Revision: 9609

Added:
   sandbox/jng/mvt_alt/Server/src/Services/Rendering/OpRenderTileMVT.cpp
   sandbox/jng/mvt_alt/Server/src/Services/Rendering/OpRenderTileMVT.h
Modified:
   sandbox/jng/mvt_alt/
   sandbox/jng/mvt_alt/Common/Foundation/Data/MimeType.cpp
   sandbox/jng/mvt_alt/Common/Foundation/Data/MimeType.h
   sandbox/jng/mvt_alt/Common/MapGuideCommon/Services/ProxyRenderingService.cpp
   sandbox/jng/mvt_alt/Common/MapGuideCommon/Services/ProxyRenderingService.h
   sandbox/jng/mvt_alt/Common/MapGuideCommon/Services/RenderingDefs.h
   sandbox/jng/mvt_alt/Common/MapGuideCommon/Services/RenderingService.h
   sandbox/jng/mvt_alt/Common/Renderers/MVTRenderer.cpp
   sandbox/jng/mvt_alt/Common/Renderers/MVTRenderer.h
   sandbox/jng/mvt_alt/Server/src/Services/Rendering/RenderingOperationFactory.cpp
   sandbox/jng/mvt_alt/Server/src/Services/Rendering/ServerRenderingService.cpp
   sandbox/jng/mvt_alt/Server/src/Services/Rendering/ServerRenderingService.h
   sandbox/jng/mvt_alt/Server/src/Services/Rendering/ServerRenderingService.vcxproj
   sandbox/jng/mvt_alt/Server/src/Services/Rendering/ServerRenderingService.vcxproj.filters
   sandbox/jng/mvt_alt/Server/src/Services/Rendering/ServerRenderingServiceBuild.cpp
Log:
Merged revision(s) 9527-9528 from sandbox/jng/mvt:
Add new RenderTileMVT to MgRenderingService. This API has the same XYZ access scheme as RenderTileXYZ and RenderTileUTFGrid.

The server implementation of this API is a near carbon-copy of RenderTileUTFGrid, with MVTRenderer in place of UTFGridRenderer.

Also add a new MVT mime type, which is the the mime type of the MgByteReader returned by this API.
........
Wire up actual RenderTileMVT operation on the server-side
........

Also fix up merged MVTRenderer usage wrt this particular branch.

Index: sandbox/jng/mvt_alt
===================================================================
--- sandbox/jng/mvt_alt	2019-09-21 19:49:17 UTC (rev 9608)
+++ sandbox/jng/mvt_alt	2019-09-21 20:14:42 UTC (rev 9609)

Property changes on: sandbox/jng/mvt_alt
___________________________________________________________________
Modified: svn:mergeinfo
## -19,6 +19,7 ##
 /sandbox/jng/fusion_entrypoint_refactor:9400-9406
 /sandbox/jng/geoprocessing:9205-9229
 /sandbox/jng/geos34x:8256-8259
+/sandbox/jng/mvt:9527-9528
 /sandbox/jng/ogc:9240-9255
 /sandbox/jng/php56x:8975-8985
 /sandbox/jng/querymapfeatures_selectionkey:9590-9591
Modified: sandbox/jng/mvt_alt/Common/Foundation/Data/MimeType.cpp
===================================================================
--- sandbox/jng/mvt_alt/Common/Foundation/Data/MimeType.cpp	2019-09-21 19:49:17 UTC (rev 9608)
+++ sandbox/jng/mvt_alt/Common/Foundation/Data/MimeType.cpp	2019-09-21 20:14:42 UTC (rev 9609)
@@ -37,3 +37,4 @@
 const STRING MgMimeType::Kml             = L"application/vnd.google-earth.kml+xml";
 const STRING MgMimeType::Kmz             = L"application/vnd.google-earth.kmz";
 const STRING MgMimeType::Meta            = L"application/metatile";
+const STRING MgMimeType::Mvt             = L"application/vnd.mapbox-vector-tile";
\ No newline at end of file

Modified: sandbox/jng/mvt_alt/Common/Foundation/Data/MimeType.h
===================================================================
--- sandbox/jng/mvt_alt/Common/Foundation/Data/MimeType.h	2019-09-21 19:49:17 UTC (rev 9608)
+++ sandbox/jng/mvt_alt/Common/Foundation/Data/MimeType.h	2019-09-21 20:14:42 UTC (rev 9609)
@@ -87,6 +87,10 @@
     /// \brief
     /// application/metatile
     static const STRING Meta;      ///\if INTERNAL value("application/metatile") \endif
+
+    /// \brief
+    /// application/vnd.mapbox-vector-tile
+    static const STRING Mvt;       ///\if INTERNAL value("application/vnd.mapbox-vector-tile") \endif
 };
 /// \}
 

Modified: sandbox/jng/mvt_alt/Common/MapGuideCommon/Services/ProxyRenderingService.cpp
===================================================================
--- sandbox/jng/mvt_alt/Common/MapGuideCommon/Services/ProxyRenderingService.cpp	2019-09-21 19:49:17 UTC (rev 9608)
+++ sandbox/jng/mvt_alt/Common/MapGuideCommon/Services/ProxyRenderingService.cpp	2019-09-21 20:14:42 UTC (rev 9609)
@@ -282,6 +282,28 @@
     return (MgByteReader*)cmd.GetReturnValue().val.m_obj;
 }
 
+MgByteReader * MgProxyRenderingService::RenderTileMVT(MgMap * map, CREFSTRING baseMapLayerGroupName, INT32 x, INT32 y, INT32 z, INT32 dpi)
+{
+    MgCommand cmd;
+    cmd.ExecuteCommand(m_connProp,                      // Connection
+        MgCommand::knObject,                            // Return type expected
+        MgRenderingServiceOpId::RenderTileMVT,          // Command Code
+        7,                                              // No of arguments
+        Rendering_Service,                              // Service Id
+        BUILD_VERSION(4,0,0),                           // Operation version
+        MgCommand::knObject, map,                       // Argument#1
+        MgCommand::knString, &baseMapLayerGroupName,    // Argument#2
+        MgCommand::knInt32, x,                          // Argument#3
+        MgCommand::knInt32, y,                          // Argument#4
+        MgCommand::knInt32, z,                          // Argument#5
+        MgCommand::knInt32, dpi,                        // Argument#6
+        MgCommand::knNone);                             // End of arguments
+
+    SetWarning(cmd.GetWarningObject());
+
+    return (MgByteReader*)cmd.GetReturnValue().val.m_obj;
+}
+
 /////////////////////////////////////////////////////////////////
 /// <summary>
 /// Renders all dynamic layers in the specified MgMap to a dynamic overlay image

Modified: sandbox/jng/mvt_alt/Common/MapGuideCommon/Services/ProxyRenderingService.h
===================================================================
--- sandbox/jng/mvt_alt/Common/MapGuideCommon/Services/ProxyRenderingService.h	2019-09-21 19:49:17 UTC (rev 9608)
+++ sandbox/jng/mvt_alt/Common/MapGuideCommon/Services/ProxyRenderingService.h	2019-09-21 20:14:42 UTC (rev 9609)
@@ -322,6 +322,46 @@
 
     /////////////////////////////////////////////////////////////////
     /// \brief
+    /// Returns the specified MVT (Mapbox Vector Tile) for the given map. Tile structure is
+    /// based on the XYZ tiling scheme used by Google Maps, OpenStreetMap, and
+    /// others
+    ///
+    /// \param map
+    /// Input
+    /// map object containing current state of map.
+    /// \param baseMapLayerGroupName
+    /// Input
+    /// Specifies the name of the baseMapLayerGroup for which to render the tile.
+    /// \param x
+    /// Input
+    /// Specifies the row index of the tile to return.
+    /// \param y
+    /// Input
+    /// Specifies the column index of the tile to return.
+    /// \param z
+    /// Input
+    /// Specifies the zoom level of the tile to return.
+    /// \param dpi
+    /// Input
+    /// Specifies the dpi of the tile to return.
+    /// \param tileImageFormat
+    /// Input
+    /// Specifies the image format of the tile to return.
+    ///
+    /// \return
+    /// A byte reader containing the rendered tile image.
+    ///
+    /// \since 4.0
+    virtual MgByteReader* RenderTileMVT(
+        MgMap* map,
+        CREFSTRING baseMapLayerGroupName,
+        INT32 x,
+        INT32 y,
+        INT32 z,
+        INT32 dpi);
+
+    /////////////////////////////////////////////////////////////////
+    /// \brief
     /// Renders all dynamic layers in the specified MgMap to a dynamic overlay image
     /// with a transparent background. The center, scale, size, and layers to be
     /// rendered are defined by the specified map instance.  The format parameter

Modified: sandbox/jng/mvt_alt/Common/MapGuideCommon/Services/RenderingDefs.h
===================================================================
--- sandbox/jng/mvt_alt/Common/MapGuideCommon/Services/RenderingDefs.h	2019-09-21 19:49:17 UTC (rev 9608)
+++ sandbox/jng/mvt_alt/Common/MapGuideCommon/Services/RenderingDefs.h	2019-09-21 20:14:42 UTC (rev 9609)
@@ -50,6 +50,7 @@
     static const int RenderMetatile             = 0x1111E916;
     static const int RenderTileFromMetaTile     = 0x1111E917;
     static const int RenderMetatileXYZ          = 0x1111E918;
+    static const int RenderTileMVT              = 0x1111E919;
 };
 /// \endcond
 

Modified: sandbox/jng/mvt_alt/Common/MapGuideCommon/Services/RenderingService.h
===================================================================
--- sandbox/jng/mvt_alt/Common/MapGuideCommon/Services/RenderingService.h	2019-09-21 19:49:17 UTC (rev 9608)
+++ sandbox/jng/mvt_alt/Common/MapGuideCommon/Services/RenderingService.h	2019-09-21 20:14:42 UTC (rev 9609)
@@ -338,6 +338,46 @@
 
     /////////////////////////////////////////////////////////////////
     /// \brief
+    /// Returns the specified MVT (Mapbox Vector Tile) for the given map. Tile structure is
+    /// based on the XYZ tiling scheme used by Google Maps, OpenStreetMap, and
+    /// others
+    ///
+    /// \param map
+    /// Input
+    /// map object containing current state of map.
+    /// \param baseMapLayerGroupName
+    /// Input
+    /// Specifies the name of the baseMapLayerGroup for which to render the tile.
+    /// \param x
+    /// Input
+    /// Specifies the row index of the tile to return.
+    /// \param y
+    /// Input
+    /// Specifies the column index of the tile to return.
+    /// \param z
+    /// Input
+    /// Specifies the zoom level of the tile to return.
+    /// \param dpi
+    /// Input
+    /// Specifies the dpi of the tile to return.
+    /// \param tileImageFormat
+    /// Input
+    /// Specifies the image format of the tile to return.
+    ///
+    /// \return
+    /// A byte reader containing the rendered tile image.
+    ///
+    /// \since 4.0
+    virtual MgByteReader* RenderTileMVT(
+        MgMap* map,
+        CREFSTRING baseMapLayerGroupName,
+        INT32 x,
+        INT32 y,
+        INT32 z,
+        INT32 dpi) = 0;
+
+    /////////////////////////////////////////////////////////////////
+    /// \brief
     /// Renders all dynamic layers in the specified MgMap to a dynamic overlay image
     /// with a transparent background. The center, scale, size, and layers to be
     /// rendered are defined by the specified map instance.  The format parameter

Modified: sandbox/jng/mvt_alt/Common/Renderers/MVTRenderer.cpp
===================================================================
--- sandbox/jng/mvt_alt/Common/Renderers/MVTRenderer.cpp	2019-09-21 19:49:17 UTC (rev 9608)
+++ sandbox/jng/mvt_alt/Common/Renderers/MVTRenderer.cpp	2019-09-21 20:14:42 UTC (rev 9609)
@@ -436,9 +436,9 @@
         m_activeLayer->addFeature(feature);
     }
 
-    unsigned char* GetMVTContent()
+    unsigned char* GetMVTContent(size_t& size)
     {
-        auto size = m_tile.getSize();
+        size = m_tile.getSize();
         GByte* pabyBuffer = new GByte[size];
         m_tile.write(pabyBuffer);
         return pabyBuffer;
@@ -825,9 +825,9 @@
     //If this renderer does not render labels. This method can be left blank.
 }
 
-unsigned char* MVTRenderer::GetMVTContent()
+unsigned char* MVTRenderer::GetMVTContent(size_t& size)
 {
-    return m_impl->GetMVTContent();
+    return m_impl->GetMVTContent(size);
 }
 
 void MVTRenderer::ReleaseMVTContent(unsigned char* buf)

Modified: sandbox/jng/mvt_alt/Common/Renderers/MVTRenderer.h
===================================================================
--- sandbox/jng/mvt_alt/Common/Renderers/MVTRenderer.h	2019-09-21 19:49:17 UTC (rev 9608)
+++ sandbox/jng/mvt_alt/Common/Renderers/MVTRenderer.h	2019-09-21 20:14:42 UTC (rev 9609)
@@ -73,7 +73,7 @@
 
     //MVT-specific. Caller responsible for calling ReleaseMVTContent() on the returned
     //pointer once done
-    RENDERERS_API unsigned char* GetMVTContent();
+    RENDERERS_API unsigned char* GetMVTContent(size_t& size);
     RENDERERS_API void ReleaseMVTContent(unsigned char* buf);
 
 private:

Copied: sandbox/jng/mvt_alt/Server/src/Services/Rendering/OpRenderTileMVT.cpp (from rev 9528, sandbox/jng/mvt/Server/src/Services/Rendering/OpRenderTileMVT.cpp)
===================================================================
--- sandbox/jng/mvt_alt/Server/src/Services/Rendering/OpRenderTileMVT.cpp	                        (rev 0)
+++ sandbox/jng/mvt_alt/Server/src/Services/Rendering/OpRenderTileMVT.cpp	2019-09-21 20:14:42 UTC (rev 9609)
@@ -0,0 +1,111 @@
+//
+//  Copyright (C) 2004-2019 by Autodesk, Inc.
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of version 2.1 of the GNU Lesser
+//  General Public License as published by the Free Software Foundation.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+//
+
+#include "OpRenderTileMVT.h"
+#include "LogManager.h"
+
+MgOpRenderTileMVT::MgOpRenderTileMVT()
+{
+}
+
+MgOpRenderTileMVT::~MgOpRenderTileMVT()
+{
+}
+
+void MgOpRenderTileMVT::Execute()
+{
+    ACE_DEBUG((LM_DEBUG, ACE_TEXT("  (%t) MgOpRenderTileMVT::Execute()\n")));
+
+    MG_LOG_OPERATION_MESSAGE(L"MgOpRenderTileMVT");
+
+    MG_TRY()
+
+        MG_LOG_OPERATION_MESSAGE_INIT(m_packet.m_OperationVersion, m_packet.m_NumArguments);
+
+    ACE_ASSERT(m_stream != NULL);
+
+    if (6 == m_packet.m_NumArguments)
+    {
+        Ptr<MgMap> map = (MgMap*)m_stream->GetObject();
+        Ptr<MgResourceIdentifier> resource = map->GetResourceId();
+        map->SetDelayedLoadResourceService(m_resourceService);
+
+        STRING baseMapLayerGroupName;
+        m_stream->GetString(baseMapLayerGroupName);
+
+        INT32 x = 0;
+        m_stream->GetInt32(x);
+
+        INT32 y = 0;
+        m_stream->GetInt32(y);
+
+        INT32 z = 0;
+        m_stream->GetInt32(z);
+
+        INT32 tileDpi = 0;
+        m_stream->GetInt32(tileDpi);
+
+        BeginExecution();
+
+        MG_LOG_OPERATION_MESSAGE_PARAMETERS_START();
+        MG_LOG_OPERATION_MESSAGE_ADD_STRING((NULL == resource) ? L"MgResourceIdentifier" : resource->ToString().c_str());
+        MG_LOG_OPERATION_MESSAGE_ADD_SEPARATOR();
+        MG_LOG_OPERATION_MESSAGE_ADD_STRING(baseMapLayerGroupName.c_str());
+        MG_LOG_OPERATION_MESSAGE_ADD_SEPARATOR();
+        MG_LOG_OPERATION_MESSAGE_ADD_INT32(x);
+        MG_LOG_OPERATION_MESSAGE_ADD_SEPARATOR();
+        MG_LOG_OPERATION_MESSAGE_ADD_INT32(y);
+        MG_LOG_OPERATION_MESSAGE_ADD_SEPARATOR();
+        MG_LOG_OPERATION_MESSAGE_ADD_INT32(z);
+        MG_LOG_OPERATION_MESSAGE_ADD_SEPARATOR();
+        MG_LOG_OPERATION_MESSAGE_ADD_INT32(tileDpi);
+        MG_LOG_OPERATION_MESSAGE_PARAMETERS_END();
+
+        Validate();
+
+        Ptr<MgByteReader> byteReader = m_service->RenderTileMVT(map, baseMapLayerGroupName, x, y, z, tileDpi);
+
+        EndExecution(byteReader);
+    }
+    else
+    {
+        MG_LOG_OPERATION_MESSAGE_PARAMETERS_START();
+        MG_LOG_OPERATION_MESSAGE_PARAMETERS_END();
+    }
+
+    if (!m_argsRead)
+    {
+        throw new MgOperationProcessingException(L"MgOpRenderTileMVT.Execute",
+            __LINE__, __WFILE__, NULL, L"", NULL);
+    }
+
+    // Successful operation
+    MG_LOG_OPERATION_MESSAGE_ADD_STRING(MgResources::Success.c_str());
+
+    MG_CATCH(L"MgOpRenderTileMVT.Execute")
+
+        if (mgException != NULL)
+        {
+            // Failed operation
+            MG_LOG_OPERATION_MESSAGE_ADD_STRING(MgResources::Failure.c_str());
+        }
+
+    // Add access log entry for operation
+    MG_LOG_OPERATION_MESSAGE_ACCESS_ENTRY();
+
+    MG_THROW()
+}

Copied: sandbox/jng/mvt_alt/Server/src/Services/Rendering/OpRenderTileMVT.h (from rev 9528, sandbox/jng/mvt/Server/src/Services/Rendering/OpRenderTileMVT.h)
===================================================================
--- sandbox/jng/mvt_alt/Server/src/Services/Rendering/OpRenderTileMVT.h	                        (rev 0)
+++ sandbox/jng/mvt_alt/Server/src/Services/Rendering/OpRenderTileMVT.h	2019-09-21 20:14:42 UTC (rev 9609)
@@ -0,0 +1,33 @@
+//
+//  Copyright (C) 2004-2019 by Autodesk, Inc.
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of version 2.1 of the GNU Lesser
+//  General Public License as published by the Free Software Foundation.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+//
+
+#ifndef MG_OP_RENDER_TILE_MVT_H
+#define MG_OP_RENDER_TILE_MVT_H
+
+#include "RenderingOperation.h"
+
+class MgOpRenderTileMVT : public MgRenderingOperation
+{
+public:
+    MgOpRenderTileMVT();
+    virtual ~MgOpRenderTileMVT();
+
+public:
+    virtual void Execute();
+};
+
+#endif
\ No newline at end of file

Modified: sandbox/jng/mvt_alt/Server/src/Services/Rendering/RenderingOperationFactory.cpp
===================================================================
--- sandbox/jng/mvt_alt/Server/src/Services/Rendering/RenderingOperationFactory.cpp	2019-09-21 19:49:17 UTC (rev 9608)
+++ sandbox/jng/mvt_alt/Server/src/Services/Rendering/RenderingOperationFactory.cpp	2019-09-21 20:14:42 UTC (rev 9609)
@@ -153,7 +153,17 @@
                 L"MgRenderingOperationFactory.GetOperation", __LINE__, __WFILE__, NULL, L"", NULL);
         }
         break;
-
+    case MgRenderingServiceOpId::RenderTileMVT:
+        switch (VERSION_NO_PHASE(operationVersion))
+        {
+        case VERSION_SUPPORTED(4, 0):
+            handler.reset(new MgOpRenderTileMVT());
+            break;
+        default:
+            throw new MgInvalidOperationVersionException(
+                L"MgRenderingOperationFactory.GetOperation", __LINE__, __WFILE__, NULL, L"", NULL);
+        }
+        break;
     case MgRenderingServiceOpId::RenderDynamicOverlay:
         switch (VERSION_NO_PHASE(operationVersion))
         {

Modified: sandbox/jng/mvt_alt/Server/src/Services/Rendering/ServerRenderingService.cpp
===================================================================
--- sandbox/jng/mvt_alt/Server/src/Services/Rendering/ServerRenderingService.cpp	2019-09-21 19:49:17 UTC (rev 9608)
+++ sandbox/jng/mvt_alt/Server/src/Services/Rendering/ServerRenderingService.cpp	2019-09-21 20:14:42 UTC (rev 9609)
@@ -20,6 +20,7 @@
 #include "DefaultStylizer.h"
 #include "AGGRenderer.h"
 #include "UTFGridRenderer.h"
+#include "MVTRenderer.h"
 #include "RSMgSymbolManager.h"
 #include "RSMgFeatureReader.h"
 #include "FeatureInfoRenderer.h"
@@ -38,6 +39,9 @@
 #define XYZ_TILE_WIDTH 256
 #define XYZ_TILE_HEIGHT 256
 
+#define MVT_TILE_WIDTH 4096
+#define MVT_TILE_HEIGHT 4096
+
 // the maximum number of allowed pixels for rendered images
 static const INT32 MAX_PIXELS = 16384*16384;
 static const INT32 FILTER_VISIBLE = 1;
@@ -339,7 +343,7 @@
 
     // sanity check - number of image pixels cannot exceed MAX_PIXELS
     if (drawWidth * drawHeight > MAX_PIXELS)
-        throw new MgOutOfRangeException(L"MgServerRenderingService.RenderMap", __LINE__, __WFILE__, NULL, L"MgInvalidImageSizeTooBig", NULL);
+        throw new MgOutOfRangeException(L"MgServerRenderingService.RenderTileUTFGrid", __LINE__, __WFILE__, NULL, L"MgInvalidImageSizeTooBig", NULL);
 
     // create a temporary collection containing all the layers for the base group
     Ptr<MgLayerCollection> layers = map->GetLayers();
@@ -428,6 +432,146 @@
     return ret.Detach();
 }
 
+MgByteReader* MgServerRenderingService::RenderTileMVT(MgMap * map, 
+                                                      CREFSTRING baseMapLayerGroupName, 
+                                                      INT32 x,
+                                                      INT32 y, 
+                                                      INT32 z, 
+                                                      INT32 dpi)
+{
+    Ptr<MgByteReader> ret;
+
+    MG_TRY()
+
+    CHECKARGUMENTNULL(map, L"MgServerRenderingService.RenderTileMVT");
+    CHECKARGUMENTEMPTYSTRING(baseMapLayerGroupName, L"MgServerRenderingService.RenderTileMVT");
+
+    // get the layer group associated with the name
+    Ptr<MgLayerGroupCollection> layerGroups = map->GetLayerGroups();
+    Ptr<MgLayerGroup> baseGroup = layerGroups->GetItem(baseMapLayerGroupName);
+    if (baseGroup == NULL)
+    {
+        MgStringCollection arguments;
+        arguments.Add(L"2");
+        arguments.Add(baseMapLayerGroupName);
+
+        throw new MgInvalidArgumentException(L"MgServerRenderingService.RenderTileMVT",
+            __LINE__, __WFILE__, &arguments, L"MgMapLayerGroupNameNotFound", NULL);
+    }
+
+    //Set the dpi
+    map->SetDisplayDpi(dpi);
+
+    int width = MVT_TILE_WIDTH;
+    int height = MVT_TILE_HEIGHT;
+
+    // Inlining same logic from RenderTile() overload below as we want the same logic, but we want to pass scale
+    // instead of scale index
+
+    // get map extent that corresponds to tile extent
+    RS_Bounds extent;
+    ComputeXYZTileExtents(map, x, y, z, extent);
+
+    INT32 drawWidth = width;
+    INT32 drawHeight = height;
+    double scale = 0.0;
+    ComputeScaledDimensions(extent, width, height, dpi, map->GetMetersPerUnit(), drawWidth, drawHeight, scale);
+
+    //printf("XYZ(%d, %d, %d) -> [%f, %f] [%f, %f] at %f -- (w: %d, h: %d, mpu: %f)\n", x, y, z, mcsMinX, mcsMinY, mcsMaxX, mcsMaxY, scale, width, height, map->GetMetersPerUnit());
+
+    // sanity check - number of image pixels cannot exceed MAX_PIXELS
+    if (drawWidth * drawHeight > MAX_PIXELS)
+        throw new MgOutOfRangeException(L"MgServerRenderingService.RenderTileMVT", __LINE__, __WFILE__, NULL, L"MgInvalidImageSizeTooBig", NULL);
+
+    // create a temporary collection containing all the layers for the base group
+    Ptr<MgLayerCollection> layers = map->GetLayers();
+    Ptr<MgReadOnlyLayerCollection> roLayers = new MgReadOnlyLayerCollection();
+    for (int i = 0; i<layers->GetCount(); i++)
+    {
+        Ptr<MgLayerBase> layer = layers->GetItem(i);
+        Ptr<MgLayerGroup> parentGroup = layer->GetGroup();
+        if (parentGroup == baseGroup)
+            roLayers->Add(layer);
+    }
+
+    // of course the group has to also be visible
+    bool groupVisible = baseGroup->GetVisible();
+    baseGroup->SetVisible(true);
+
+    // We'd like to re-use RenderMapInternal, but its design is biased towards image-based SE_Renderers (that expect to
+    // save to some RS_ByteData that an MgByteReader is returned from.
+    //
+    // Our MVTRenderer is not such a renderer, so we have to inline the pertinent bits here
+    
+    // set the map scale to the requested scale
+    map->SetViewScale(scale);
+
+    // convert the map coordinate system from srs wkt to a mentor cs structure
+    STRING srs = map->GetMapSRS();
+    Ptr<MgCoordinateSystem> dstCs;
+    if (!srs.empty())
+    {
+        // let's not fail here if coord sys conversion fails for the map's
+        // coordinate system. Instead we will fail per layer at a later stage
+        try
+        {
+            dstCs = m_pCSFactory->Create(srs);
+        }
+        catch (MgInvalidCoordinateSystemException* e)
+        {
+            e->Release();
+        }
+    }
+
+    RS_String units = dstCs.p ? dstCs->GetUnits() : L"";
+
+    // get the session ID
+    STRING sessionId;
+    Ptr<MgUserInformation> userInfo = MgUserInformation::GetCurrentUserInfo();
+    if (userInfo != NULL)
+        sessionId = userInfo->GetMgSessionId();
+
+    MVTRenderer dr(x, y, z);
+
+    RSMgSymbolManager mgr(m_svcResource);
+    dr.SetSymbolManager(&mgr);
+
+    SEMgSymbolManager semgr(m_svcResource);
+    DefaultStylizer ds(&semgr);
+
+    RS_Color bgcolor(0, 0, 0, 255); //Not used by MVTRenderer
+
+    Ptr<MgPoint> ptCenter = map->GetViewCenter();
+    Ptr<MgCoordinate> coord = ptCenter->GetCoordinate();
+    RS_MapUIInfo mapInfo(sessionId, map->GetName(), map->GetObjectId(), srs, units, bgcolor, coord->GetX(), coord->GetY(), scale);
+
+    // begin map stylization
+    dr.StartMap(&mapInfo, extent, scale, map->GetDisplayDpi(), map->GetMetersPerUnit(), NULL);
+
+    // We can't use RenderMapInternal, but we can use RenderLayers, which is all we really need
+    RenderLayers(map, roLayers, &ds, &dr, dstCs, true, scale, L"UTFGRID", NULL);
+
+    dr.EndMap();
+
+    // restore the base group's visibility
+    baseGroup->SetVisible(groupVisible);
+
+    // Now extract the encoded MVT tile and pack it into a MgByteReader
+    size_t size;
+    auto buf = dr.GetMVTContent(size);
+    Ptr<MgByte> mvtBytes = new MgByte(buf, size);
+    dr.ReleaseMVTContent(buf);
+    Ptr<MgByteSource> bs = new MgByteSource(mvtBytes);
+
+    bs->SetMimeType(MgMimeType::Mvt);
+
+    ret = bs->GetReader();
+
+    MG_CATCH_AND_THROW(L"MgServerRenderingService.RenderTileMVT")
+
+    return ret.Detach();
+}
+
 ///////////////////////////////////////////////////////////////////////////////
 /// render a map using all layers from the baseGroup
 MgByteReader* MgServerRenderingService::RenderTileInternal(MgMap* map,

Modified: sandbox/jng/mvt_alt/Server/src/Services/Rendering/ServerRenderingService.h
===================================================================
--- sandbox/jng/mvt_alt/Server/src/Services/Rendering/ServerRenderingService.h	2019-09-21 19:49:17 UTC (rev 9608)
+++ sandbox/jng/mvt_alt/Server/src/Services/Rendering/ServerRenderingService.h	2019-09-21 20:14:42 UTC (rev 9609)
@@ -100,6 +100,13 @@
                                             INT32 z,
                                             INT32 dpi);
 
+    virtual MgByteReader* RenderTileMVT(MgMap* map,
+                                        CREFSTRING baseMapLayerGroupName,
+                                        INT32 x,
+                                        INT32 y,
+                                        INT32 z,
+                                        INT32 dpi);
+
     virtual MgByteReader* RenderDynamicOverlay(MgMap* map,
                                                MgSelection* selection,
                                                CREFSTRING format);

Modified: sandbox/jng/mvt_alt/Server/src/Services/Rendering/ServerRenderingService.vcxproj
===================================================================
--- sandbox/jng/mvt_alt/Server/src/Services/Rendering/ServerRenderingService.vcxproj	2019-09-21 19:49:17 UTC (rev 9608)
+++ sandbox/jng/mvt_alt/Server/src/Services/Rendering/ServerRenderingService.vcxproj	2019-09-21 20:14:42 UTC (rev 9609)
@@ -252,6 +252,12 @@
       <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
       <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
     </ClCompile>
+    <ClCompile Include="OpRenderTileMVT.cpp">
+      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
+      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
+      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
+      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
+    </ClCompile>
     <ClCompile Include="OpRenderTileXYZ.cpp">
       <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
       <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
@@ -318,6 +324,7 @@
     <ClInclude Include="OpRenderMetatileXYZ.h" />
     <ClInclude Include="OpRenderTile.h" />
     <ClInclude Include="OpRenderTileFromMetatile.h" />
+    <ClInclude Include="OpRenderTileMVT.h" />
     <ClInclude Include="OpRenderTileXYZ.h" />
     <ClInclude Include="OpRenderTileUTFGrid.h" />
     <ClInclude Include="RenderingOperation.h" />

Modified: sandbox/jng/mvt_alt/Server/src/Services/Rendering/ServerRenderingService.vcxproj.filters
===================================================================
--- sandbox/jng/mvt_alt/Server/src/Services/Rendering/ServerRenderingService.vcxproj.filters	2019-09-21 19:49:17 UTC (rev 9608)
+++ sandbox/jng/mvt_alt/Server/src/Services/Rendering/ServerRenderingService.vcxproj.filters	2019-09-21 20:14:42 UTC (rev 9609)
@@ -51,6 +51,9 @@
     <ClCompile Include="OpRenderTileFromMetatile.cpp">
       <Filter>Ops</Filter>
     </ClCompile>
+    <ClCompile Include="OpRenderTileMVT.cpp">
+      <Filter>Ops</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="OpQueryFeatureProperties.h">
@@ -98,6 +101,9 @@
     <ClInclude Include="OpRenderTileFromMetatile.h">
       <Filter>Ops</Filter>
     </ClInclude>
+    <ClInclude Include="OpRenderTileMVT.h">
+      <Filter>Ops</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ResourceCompile Include="ServerRenderingService.rc" />

Modified: sandbox/jng/mvt_alt/Server/src/Services/Rendering/ServerRenderingServiceBuild.cpp
===================================================================
--- sandbox/jng/mvt_alt/Server/src/Services/Rendering/ServerRenderingServiceBuild.cpp	2019-09-21 19:49:17 UTC (rev 9608)
+++ sandbox/jng/mvt_alt/Server/src/Services/Rendering/ServerRenderingServiceBuild.cpp	2019-09-21 20:14:42 UTC (rev 9609)
@@ -29,6 +29,7 @@
 #include "OpRenderTile.cpp"
 #include "OpRenderTileXYZ.cpp"
 #include "OpRenderTileUTFGrid.cpp"
+#include "OpRenderTileMVT.cpp"
 #include "OpQueryFeatures.cpp"
 #include "OpQueryFeatureProperties.cpp"
 #include "RenderingOperation.cpp"



More information about the mapguide-commits mailing list