[mapguide-commits] r8191 - sandbox/jng/tiling/Server/src/Services/Tile

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Mon Jun 9 15:57:56 PDT 2014


Author: jng
Date: 2014-06-09 15:57:56 -0700 (Mon, 09 Jun 2014)
New Revision: 8191

Added:
   sandbox/jng/tiling/Server/src/Services/Tile/TileCacheXYZProvider.cpp
   sandbox/jng/tiling/Server/src/Services/Tile/TileCacheXYZProvider.h
Modified:
   sandbox/jng/tiling/Server/src/Services/Tile/TileCacheDefault.h
Log:
Add missing XYZ tile provider source from previous submission and use a cleaner directory structure for XYZ tiles, which is <basepath>/<group>/<z>/<x>/<y>.<format>

Modified: sandbox/jng/tiling/Server/src/Services/Tile/TileCacheDefault.h
===================================================================
--- sandbox/jng/tiling/Server/src/Services/Tile/TileCacheDefault.h	2014-06-09 22:32:06 UTC (rev 8190)
+++ sandbox/jng/tiling/Server/src/Services/Tile/TileCacheDefault.h	2014-06-09 22:57:56 UTC (rev 8191)
@@ -65,6 +65,8 @@
 
     virtual MgByteReader* RenderAndCacheTile(CREFSTRING tilePathname, MgMap* map, INT32 scaleIndex, CREFSTRING baseMapLayerGroupName, INT32 tileColumn, INT32 tileRow);
 
+    virtual STRING GetTileName(int tileRow, int tileColumn);
+
     MgByteReader* GetTileForResource(MgResourceIdentifier* resource,
                                      CREFSTRING baseMapLayerGroupName,
                                      INT32 tileColumn,
@@ -95,7 +97,6 @@
     STRING GetColumnFolder(int tileColumn);
     STRING GetFolder(STRING prefix, int tileIndex, int tilesPerFolder);
 
-    STRING GetTileName(int tileRow, int tileColumn);
     STRING GetTileIndexString(int tileIndex, int tilesPerFolder);
 
     MgResourceService* GetResourceServiceForMapDef(MgResourceIdentifier* mapDefinition, CREFSTRING funcName);

Added: sandbox/jng/tiling/Server/src/Services/Tile/TileCacheXYZProvider.cpp
===================================================================
--- sandbox/jng/tiling/Server/src/Services/Tile/TileCacheXYZProvider.cpp	                        (rev 0)
+++ sandbox/jng/tiling/Server/src/Services/Tile/TileCacheXYZProvider.cpp	2014-06-09 22:57:56 UTC (rev 8191)
@@ -0,0 +1,165 @@
+//
+//  Copyright (C) 2004-2014 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 "MapGuideCommon.h"
+#include "TileCacheXYZProvider.h"
+
+MgTileCacheXYZProvider::MgTileCacheXYZProvider(MgResourceIdentifier* tileSetId, CREFSTRING path, CREFSTRING format, bool bRenderOnly)
+{
+    m_tilesetId = SAFE_ADDREF(tileSetId);
+    m_path = path;
+    m_format = format;
+    m_renderOnly = bRenderOnly;
+}
+
+MgTileCacheXYZProvider::~MgTileCacheXYZProvider()
+{
+
+}
+
+MgByteReader* MgTileCacheXYZProvider::GetTile(CREFSTRING baseMapLayerGroupName,
+                                                  INT32 tileColumn,
+                                                  INT32 tileRow,
+                                                  INT32 scaleIndex)
+{
+    Ptr<MgByteReader> ret;
+    MG_TRY()
+
+    ret = GetTileForResource(m_tilesetId, baseMapLayerGroupName, tileColumn, tileRow, scaleIndex);
+
+    MG_CATCH_AND_THROW(L"MgTileCacheXYZProvider.GetTile")
+    return ret.Detach();
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// render a tile and store it in the cache
+MgByteReader* MgTileCacheXYZProvider::RenderAndCacheTile(CREFSTRING tilePathname, MgMap* map, INT32 scaleIndex,
+    CREFSTRING baseMapLayerGroupName, INT32 tileColumn, INT32 tileRow)
+{
+    Ptr<MgByteReader> img;
+
+    // get a rendering service instance
+    MgServiceManager* serviceMan = MgServiceManager::GetInstance();
+    assert(NULL != serviceMan);
+    Ptr<MgRenderingService> svcRendering = dynamic_cast<MgRenderingService*>(
+        serviceMan->RequestService(MgServiceType::RenderingService));
+    assert(NULL != svcRendering);
+
+    if (svcRendering != NULL)
+    {
+        // generate the tile
+        img = svcRendering->RenderTileXYZ(map, baseMapLayerGroupName, tileRow, tileColumn, scaleIndex, map->GetDisplayDpi(), m_format);
+
+        // cache the tile
+        if (!m_renderOnly)
+        {
+            Set(img, tilePathname);
+
+            // rewind the reader since setting the tile advances it to the end
+            if (img)
+            {
+                img->Rewind();
+            }
+        }
+    }
+
+    return img.Detach();
+}
+
+INT32 MgTileCacheXYZProvider::GetDefaultTileSizeX()
+{
+    return 256; //Always
+}
+
+INT32 MgTileCacheXYZProvider::GetDefaultTileSizeY()
+{
+    return 256; //Always
+}
+
+STRING MgTileCacheXYZProvider::GetTileFormat()
+{
+    return m_format;
+}
+
+STRING MgTileCacheXYZProvider::GetBasePath()
+{
+    return GetBasePathFromResourceId(m_tilesetId, m_path);
+}
+
+STRING MgTileCacheXYZProvider::CreateFullPath(CREFSTRING basePath, int scaleIndex, CREFSTRING group, int tileColumn, int tileRow)
+{
+    assert(!basePath.empty());
+    STRING fullPath = basePath;
+
+    // Create base directory if it does not exist.
+    MgFileUtil::CreateDirectory(fullPath, false);
+
+    // Create group directory if it does not exist.
+    fullPath += L"/";
+    fullPath += group;
+    MgFileUtil::CreateDirectory(fullPath, false);
+
+    // Create z directory if it does not exist.
+    fullPath += L"/";
+    STRING sZ;
+    MgUtil::Int32ToString(scaleIndex, sZ);
+    fullPath += sZ;
+    MgFileUtil::CreateDirectory(fullPath, false);
+
+    // Create x directory if it does not exist.
+    fullPath += L"/";
+    STRING sX;
+    MgUtil::Int32ToString(tileRow, sX);
+    fullPath += sX;
+    MgFileUtil::CreateDirectory(fullPath, false);
+
+    return fullPath;
+}
+
+// gets the full path to use with the tile cache for the given base path / scale index / group
+STRING MgTileCacheXYZProvider::GetFullPath(CREFSTRING basePath, int scaleIndex, CREFSTRING group, int tileColumn, int tileRow)
+{
+    // Build full path
+    //     <fullPath> = <basePath>/<group>/<z>/<x>/<y>.<format>
+    assert(!basePath.empty());
+    STRING fullPath = basePath;
+
+    fullPath += L"/";
+    fullPath += group;
+
+    fullPath += L"/";
+    STRING sZ;
+    MgUtil::Int32ToString(scaleIndex, sZ);
+    fullPath += sZ;
+
+    fullPath += L"/";
+    STRING sX;
+    MgUtil::Int32ToString(tileRow, sX);
+    fullPath += sX;
+
+    return fullPath;
+}
+
+// Get the filename corresponding to the specified row and column.
+// No file extension is added.
+STRING MgTileCacheXYZProvider::GetTileName(int tileRow, int tileColumn)
+{
+    //row (x) is already part of the parent directory, so column (y) is the tile name
+    STRING ret;
+    MgUtil::Int32ToString(tileColumn, ret);
+    return ret;
+}
\ No newline at end of file

Added: sandbox/jng/tiling/Server/src/Services/Tile/TileCacheXYZProvider.h
===================================================================
--- sandbox/jng/tiling/Server/src/Services/Tile/TileCacheXYZProvider.h	                        (rev 0)
+++ sandbox/jng/tiling/Server/src/Services/Tile/TileCacheXYZProvider.h	2014-06-09 22:57:56 UTC (rev 8191)
@@ -0,0 +1,61 @@
+//
+//  Copyright (C) 2004-2014 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_TILE_CACHE_XYZ_PROVIDER_H_
+#define _MG_TILE_CACHE_XYZ_PROVIDER_H_
+
+#include "TileCacheDefault.h"
+
+class MG_SERVER_TILE_API MgTileCacheXYZProvider : public MgTileCacheDefault
+{
+public:
+    MgTileCacheXYZProvider(MgResourceIdentifier* tileSetId, CREFSTRING path, CREFSTRING format, bool bRenderOnly);
+    virtual ~MgTileCacheXYZProvider();
+
+    virtual MgByteReader* GetTile(CREFSTRING baseMapLayerGroupName,
+                                  INT32 tileColumn,
+                                  INT32 tileRow,
+                                  INT32 scaleIndex);
+
+    virtual MgByteReader* RenderAndCacheTile(CREFSTRING tilePathname, MgMap* map, INT32 scaleIndex, CREFSTRING baseMapLayerGroupName, INT32 tileColumn, INT32 tileRow);
+
+    virtual INT32 GetDefaultTileSizeX();
+
+    virtual INT32 GetDefaultTileSizeY();
+
+    virtual STRING GetTileFormat();
+
+    //Overriding these as we want to use a cleaner directory structure for XYZ tiles
+    virtual STRING GetFullPath(CREFSTRING basePath, int scaleIndex, CREFSTRING group, int tileColumn, int tileRow);
+    virtual STRING CreateFullPath(CREFSTRING basePath, int scaleIndex, CREFSTRING group, int tileColumn, int tileRow);
+    virtual STRING GetTileName(int tileRow, int tileColumn);
+
+protected:
+    virtual void Dispose()
+    {
+        delete this;
+    }
+
+    virtual STRING GetBasePath();
+
+private:
+    Ptr<MgResourceIdentifier> m_tilesetId;
+    STRING m_path;
+    STRING m_format;
+    bool m_renderOnly;
+};
+
+#endif
\ No newline at end of file



More information about the mapguide-commits mailing list