[mapguide-commits] r7488 - sandbox/jng/createruntimemap/Web/src/HttpHandler

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Thu May 9 06:41:59 PDT 2013


Author: jng
Date: 2013-05-09 06:41:59 -0700 (Thu, 09 May 2013)
New Revision: 7488

Added:
   sandbox/jng/createruntimemap/Web/src/HttpHandler/HttpCreateRuntimeMap.cpp
   sandbox/jng/createruntimemap/Web/src/HttpHandler/HttpCreateRuntimeMap.h
Log:
Derp! Forgot to add the actual operation files.

Added: sandbox/jng/createruntimemap/Web/src/HttpHandler/HttpCreateRuntimeMap.cpp
===================================================================
--- sandbox/jng/createruntimemap/Web/src/HttpHandler/HttpCreateRuntimeMap.cpp	                        (rev 0)
+++ sandbox/jng/createruntimemap/Web/src/HttpHandler/HttpCreateRuntimeMap.cpp	2013-05-09 13:41:59 UTC (rev 7488)
@@ -0,0 +1,263 @@
+//
+//  Copyright (C) 2004-2013 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 "HttpHandler.h"
+#include "HttpCreateRuntimeMap.h"
+
+HTTP_IMPLEMENT_CREATE_OBJECT(MgHttpCreateRuntimeMap)
+
+/// <summary>
+/// Initializes the common parameters and parameters specific to this request.
+/// </summary>
+/// <param name="name">Input
+/// MgHttpRequest
+/// This contains all the parameters of the request.
+/// </param>
+/// <returns>
+/// nothing
+/// </returns>
+MgHttpCreateRuntimeMap::MgHttpCreateRuntimeMap(MgHttpRequest *hRequest)
+{
+    InitializeCommonParameters(hRequest);
+
+    Ptr<MgHttpRequestParam> params = hRequest->GetRequestParam();
+    m_mapDefinition = params->GetParameterValue(MgHttpResourceStrings::reqMappingMapDefinition);
+}
+
+/// <summary>
+/// Executes the specific request.
+/// </summary>
+/// <returns>
+/// MgHttpResponse
+/// This contains the response (including MgHttpResult and StatusCode) from the server.
+/// </returns>
+void MgHttpCreateRuntimeMap::Execute(MgHttpResponse& hResponse)
+{
+    Ptr<MgHttpResult> hResult = hResponse.GetResult();
+
+    MG_HTTP_HANDLER_TRY()
+
+    // Check common parameters
+    ValidateCommonParameters();
+
+    Ptr<MgByteReader> byteReader;
+
+    Ptr<MgResourceIdentifier> mdfId = new MgResourceIdentifier(m_mapDefinition);
+    STRING mapName = mdfId->GetName();
+
+    byteReader = BuildRuntimeMapXml(mdfId, mapName);
+    // Convert to requested response format, if necessary
+    ProcessFormatConversion(byteReader);
+
+    hResult->SetResultObject(byteReader, byteReader->GetMimeType());
+
+    MG_HTTP_HANDLER_CATCH_AND_THROW_EX(L"MgHttpCreateRuntimeMap.Execute")
+}
+
+MgByteReader* MgHttpCreateRuntimeMap::BuildRuntimeMapXml(MgResourceIdentifier* mdfId, CREFSTRING mapName)
+{
+    Ptr<MgByteReader> byteReader;
+    MG_HTTP_HANDLER_TRY()
+
+    Ptr<MgMap> map = new MgMap();
+    Ptr<MgResourceService> resourceService = (MgResourceService*)CreateService(MgServiceType::ResourceService);
+
+    // Create a new session id if we don't have one
+    STRING sessionId = m_userInfo->GetMgSessionId();
+    if (sessionId.empty())
+    {
+        // Get the site
+        Ptr<MgSite> mgSite = m_siteConn->GetSite();
+        // Run API command
+        sessionId = mgSite->CreateSession();
+        m_userInfo->SetMgSessionId(sessionId);
+    }
+
+    // NOTE: We're sticking with the un-written spec of the map name being the name of the map definition id
+    map->Create(resourceService, mdfId, mapName);
+    STRING sStateId = L"Session:";
+    sStateId += sessionId;
+    sStateId += L"//";
+    sStateId += mapName;
+    sStateId += L".";
+    sStateId += MgResourceType::Map;
+
+    Ptr<MgResourceIdentifier> mapStateId = new MgResourceIdentifier(sStateId);
+    Ptr<MgSelection> sel = new MgSelection(map);
+    sel->Save(resourceService, mapName);
+    map->Save(resourceService, mapStateId);
+
+    std::string xml;
+    xml.append("<RuntimeMap>\n");
+    // ------------------------------ Site Version ----------------------------------//
+    xml.append("<SiteVersion>");
+    Ptr<MgServerAdmin> serverAdmin = new MgServerAdmin();
+    serverAdmin->Open(m_userInfo);
+    xml.append(MgUtil::WideCharToMultiByte(serverAdmin->GetSiteVersion()));
+    xml.append("</SiteVersion>\n");
+    // ------------------------------ Session ID --------------------------------- //
+    xml.append("<SessionId>");
+    xml.append(MgUtil::WideCharToMultiByte(sessionId));
+    xml.append("</SessionId>\n");
+    // ------------------------------ Map Name --------------------------------- //
+    xml.append("<Name>");
+    xml.append(MgUtil::WideCharToMultiByte(mapName));
+    xml.append("</Name>\n");
+    // ------------------------------ Map Definition ID --------------------------------- //
+    xml.append("<MapDefinition>");
+    xml.append(MgUtil::WideCharToMultiByte(mdfId->ToString()));
+    xml.append("</MapDefinition>\n");
+    // ------------------------------ Coordinate System --------------------------------- //
+    xml.append("<CoordinateSystem>\n");
+    xml.append("<Wkt>");
+    STRING srs = map->GetMapSRS();
+    xml.append(MgUtil::WideCharToMultiByte(MgUtil::ReplaceEscapeCharInXml(srs)));
+    xml.append("</Wkt>\n");
+    Ptr<MgCoordinateSystemFactory> fact = new MgCoordinateSystemFactory();
+    std::string sEpsg;
+    std::string sMentor;
+    std::string sMpu;
+    try
+    {
+        Ptr<MgCoordinateSystem> cs = fact->Create(srs);
+        if (!srs.empty())
+            MgUtil::DoubleToString(cs->ConvertCoordinateSystemUnitsToMeters(1.0), sMpu);
+        else
+            sMpu = "1.0";
+        sMentor = MgUtil::WideCharToMultiByte(cs->GetCsCode());
+        INT32 epsg = cs->GetEpsgCode();
+        MgUtil::Int32ToString(epsg, sEpsg);
+    }
+    catch (MgException* ex)
+    {
+        SAFE_RELEASE(ex);
+    }
+    xml.append("<MentorCode>");
+    xml.append(sMentor);
+    xml.append("</MentorCode>\n");
+    xml.append("<EpsgCode>");
+    xml.append(sEpsg);
+    xml.append("</EpsgCode>\n");
+    xml.append("<MetersPerUnit>");
+    xml.append(sMpu);
+    xml.append("</MetersPerUnit>\n");
+    xml.append("</CoordinateSystem>");
+    // ------------------------------ Extents --------------------------------- //
+    std::string sExtents;
+    Ptr<MgEnvelope> extents = map->GetMapExtent();
+    extents->ToXml(sExtents);
+    xml.append("<Extents>\n");
+    xml.append(sExtents);
+    xml.append("</Extents>");
+    // ------------------------------ Groups ---------------------------------- //
+    xml.append("<Groups>\n");
+    Ptr<MgLayerGroupCollection> groups = map->GetLayerGroups();
+    for (INT32 i = 0; i < groups->GetCount(); i++)
+    {
+        Ptr<MgLayerGroup> group = groups->GetItem(i);
+        //We'll deal with you later
+        if (group->GetLayerGroupType() == MgLayerGroupType::BaseMap)
+            continue;
+
+        xml.append("<Group>\n");
+        xml.append("<Name>");
+        xml.append(MgUtil::WideCharToMultiByte(group->GetName()));
+        xml.append("</Name>\n");
+        xml.append("<LegendLabel>");
+        xml.append(MgUtil::WideCharToMultiByte(group->GetLegendLabel()));
+        xml.append("</LegendLabel>\n");
+        xml.append("<ObjectId>");
+        xml.append(MgUtil::WideCharToMultiByte(group->GetObjectId()));
+        xml.append("</ObjectId>\n");
+        xml.append("<DisplayInLegend>");
+        xml.append(group->GetDisplayInLegend() ? "true" : "false");
+        xml.append("</DisplayInLegend>\n");
+        xml.append("<ExpandInLegend>");
+        xml.append(group->GetExpandInLegend() ? "true" : "false");
+        xml.append("</ExpandInLegend>\n");
+        xml.append("<Visible>");
+        xml.append(group->GetVisible() ? "true" : "false");
+        xml.append("</Visible>\n");
+        xml.append("<ActuallyVisible>");
+        xml.append(group->IsVisible() ? "true" : "false");
+        xml.append("</ActuallyVisible>\n");
+        Ptr<MgLayerGroup> parent = group->GetGroup();
+        if (NULL != parent.p)
+        {
+            xml.append("<ParentGroupId>");
+            xml.append(MgUtil::WideCharToMultiByte(parent->GetObjectId()));
+            xml.append("</ParentGroupId>\n");
+        }
+        xml.append("</Group>");
+    }
+    xml.append("</Groups>");
+    // ------------------------------ Layers ---------------------------------- //
+    xml.append("<Layers>\n");
+    Ptr<MgLayerCollection> layers = map->GetLayers();
+    for (INT32 i = 0; i < layers->GetCount(); i++)
+    {
+        Ptr<MgLayerBase> layer = layers->GetItem(i);
+        Ptr<MgLayerGroup> parent = layer->GetGroup();
+        //We'll deal with you later
+        if (NULL != parent.p && parent->GetLayerGroupType() == MgLayerGroupType::BaseMap)
+            continue;
+
+        xml.append("<Layer>\n");
+        xml.append("<Name>");
+        xml.append(MgUtil::WideCharToMultiByte(layer->GetName()));
+        xml.append("</Name>\n");
+        xml.append("<LegendLabel>");
+        xml.append(MgUtil::WideCharToMultiByte(layer->GetLegendLabel()));
+        xml.append("</LegendLabel>\n");
+        xml.append("<ObjectId>");
+        xml.append(MgUtil::WideCharToMultiByte(layer->GetObjectId()));
+        xml.append("</ObjectId>\n");
+        xml.append("<DisplayInLegend>");
+        xml.append(layer->GetDisplayInLegend() ? "true" : "false");
+        xml.append("</DisplayInLegend>\n");
+        xml.append("<ExpandInLegend>");
+        xml.append(layer->GetExpandInLegend() ? "true" : "false");
+        xml.append("</ExpandInLegend>\n");
+        xml.append("<Visible>");
+        xml.append(layer->GetVisible() ? "true" : "false");
+        xml.append("</Visible>\n");
+        xml.append("<ActuallyVisible>");
+        xml.append(layer->IsVisible() ? "true" : "false");
+        xml.append("</ActuallyVisible>\n");
+        if (NULL != parent.p)
+        {
+            xml.append("<ParentGroupId>");
+            xml.append(MgUtil::WideCharToMultiByte(parent->GetObjectId()));
+            xml.append("</ParentGroupId>\n");
+        }
+        xml.append("</Layer>");
+    }
+    xml.append("</Layers>");
+    // ------------------------------ Tiled Groups ---------------------------------- //
+    xml.append("<BaseMapGroups>\n");
+    xml.append("</BaseMapGroups>");
+
+    xml.append("</RuntimeMap>");
+
+    Ptr<MgByteSource> byteSource = new MgByteSource((BYTE_ARRAY_IN)xml.c_str(), (INT32)xml.length());
+    byteSource->SetMimeType(MgMimeType::Xml);
+    byteReader = byteSource->GetReader();
+
+    MG_HTTP_HANDLER_CATCH_AND_THROW(L"MgHttpCreateRuntimeMap.BuildRuntimeMapXml")
+
+    return byteReader.Detach();
+}
\ No newline at end of file

Added: sandbox/jng/createruntimemap/Web/src/HttpHandler/HttpCreateRuntimeMap.h
===================================================================
--- sandbox/jng/createruntimemap/Web/src/HttpHandler/HttpCreateRuntimeMap.h	                        (rev 0)
+++ sandbox/jng/createruntimemap/Web/src/HttpHandler/HttpCreateRuntimeMap.h	2013-05-09 13:41:59 UTC (rev 7488)
@@ -0,0 +1,60 @@
+//
+//  Copyright (C) 2004-2013 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 _HTTP_CREATE_RUNTIME_MAP_
+#define _HTTP_CREATE_RUNTIME_MAP_
+
+class MgHttpCreateRuntimeMap : public MgHttpRequestResponseHandler
+{
+HTTP_DECLARE_CREATE_OBJECT()
+
+public:
+    /// <summary>
+    /// Initializes the common parameters of the request.
+    /// </summary>
+    /// <param name="name">Input
+    /// MgHttpRequest
+    /// This contains all the parameters of the request.
+    /// </param>
+    /// <returns>
+    /// nothing
+    /// </returns>
+    MgHttpCreateRuntimeMap(MgHttpRequest *hRequest);
+
+    /// <summary>
+    /// Executes the specific request.
+    /// </summary>
+    /// <param name="hResponse">Input
+    /// This contains the response (including MgHttpResult and StatusCode) from the server.
+    /// </param>
+    void Execute(MgHttpResponse& hResponse);
+
+    /// <summary>
+    /// Returns the classification of this request/response handler
+    /// </summary>
+    /// <returns>
+    /// Classification of handler
+    /// </returns>
+    MgRequestClassification GetRequestClassification() { return MgHttpRequestResponseHandler::mrcViewer; }
+
+private:
+    MgByteReader* BuildRuntimeMapXml(MgResourceIdentifier* mdfId, CREFSTRING mapName);
+
+    STRING m_mapDefinition;
+};
+
+#endif  // _HTTP_CREATE_RUNTIME_MAP_



More information about the mapguide-commits mailing list