提交 40a02d82519e10e0d94f7f356701032bc0bbbc21

作者 LJH 李佳桓
2 个父辈 27511003 678abfd9

ljh

@@ -14,4 +14,14 @@ bool DmpCoordinateReferenceSystem::readXml(const boost::property_tree::ptree pNo @@ -14,4 +14,14 @@ bool DmpCoordinateReferenceSystem::readXml(const boost::property_tree::ptree pNo
14 proj4_ = pNode.get<std::string>("proj4"); 14 proj4_ = pNode.get<std::string>("proj4");
15 srid_ = pNode.get<long>("srid"); 15 srid_ = pNode.get<long>("srid");
16 return true; 16 return true;
  17 +}
  18 +
  19 +bool DmpCoordinateReferenceSystem::write( boost::property_tree::ptree& pNode)
  20 +{
  21 + boost::property_tree::ptree ptSpatialrefsys;
  22 + ptSpatialrefsys.add("wkt", wkt_);
  23 + ptSpatialrefsys.add("proj4", proj4_);
  24 + ptSpatialrefsys.add("srid", srid_);
  25 + pNode.add_child("spatialrefsys",ptSpatialrefsys);
  26 + return true;
17 } 27 }
@@ -17,6 +17,7 @@ class CORE_EXPORT DmpCoordinateReferenceSystem @@ -17,6 +17,7 @@ class CORE_EXPORT DmpCoordinateReferenceSystem
17 { 17 {
18 public: 18 public:
19 bool readXml(const boost::property_tree::ptree pNode); 19 bool readXml(const boost::property_tree::ptree pNode);
  20 + bool write(boost::property_tree::ptree& pNode);
20 long srid(){return srid_;} 21 long srid(){return srid_;}
21 private: 22 private:
22 long srid_; 23 long srid_;
@@ -11,6 +11,7 @@ @@ -11,6 +11,7 @@
11 #include <boost/algorithm/string/case_conv.hpp> 11 #include <boost/algorithm/string/case_conv.hpp>
12 #include <boost/property_tree/ptree.hpp> 12 #include <boost/property_tree/ptree.hpp>
13 #include <boost/property_tree/xml_parser.hpp> 13 #include <boost/property_tree/xml_parser.hpp>
  14 +#include <boost/property_tree/json_parser.hpp>
14 #include <boost/typeof/typeof.hpp> 15 #include <boost/typeof/typeof.hpp>
15 #include "dmpproject.h" 16 #include "dmpproject.h"
16 #include "dmptilelayer.h" 17 #include "dmptilelayer.h"
@@ -124,6 +125,60 @@ bool DmpProject::Write(const std::string &filename, const std::string &data) @@ -124,6 +125,60 @@ bool DmpProject::Write(const std::string &filename, const std::string &data)
124 return true; 125 return true;
125 } 126 }
126 127
  128 +bool DmpProject::WritePtree(boost::property_tree::ptree& ptDoc)
  129 +{
  130 + //目前还未完善 只支持 矢量图层
  131 + boost::property_tree::ptree ptDmap;
  132 +
  133 + ptDmap.add("<xmlattr>.projectname",projectName_);
  134 + ptDmap.add("<xmlattr>.version",version_);
  135 +
  136 + boost::property_tree::ptree ptProjectCrs;
  137 + crs_.write(ptProjectCrs);
  138 + ptDmap.add_child("projectCrs",ptProjectCrs);
  139 +
  140 + boost::property_tree::ptree ptProjectlayers;
  141 +
  142 + std::map<std::string, DmpMapLayer *>::iterator iter = mapLayers_.begin();
  143 + for (; iter != mapLayers_.end(); ++iter)
  144 + {
  145 + DmpMapLayer *mapLayer = iter->second;
  146 + if (mapLayer && mapLayer->type() == DmpMapLayerType::VectorLayer)
  147 + {
  148 + boost::property_tree::ptree ptlayer;
  149 + ptlayer.add("<xmlattr>.type", "1");
  150 + DmpVectorLayer *vectorMapLayer =(DmpVectorLayer *) mapLayer;
  151 + vectorMapLayer->writeXml(ptlayer);
  152 + ptProjectlayers.add_child("maplayer",ptlayer);
  153 + }
  154 + }
  155 +
  156 + ptDmap.add_child("projectlayers", ptProjectlayers);
  157 + ptDoc.add_child("dmap",ptDmap);
  158 +
  159 + return true;
  160 +}
  161 +
  162 +std::string DmpProject::WriteJson()
  163 +{
  164 + boost::property_tree::ptree ptDoc;
  165 + WritePtree(ptDoc);
  166 + std::stringstream stream;
  167 + write_json(stream, ptDoc);
  168 + std::string data = stream.str();
  169 + return data;
  170 +}
  171 +
  172 +std::string DmpProject::WriteXml()
  173 +{
  174 + boost::property_tree::ptree ptDoc;
  175 + WritePtree(ptDoc);
  176 + std::stringstream stream;
  177 + write_xml(stream, ptDoc);
  178 + std::string data = stream.str();
  179 + return data;
  180 +}
  181 +
127 DmpCoordinateReferenceSystem DmpProject::crs() const 182 DmpCoordinateReferenceSystem DmpProject::crs() const
128 { 183 {
129 return crs_; 184 return crs_;
@@ -26,6 +26,9 @@ class CORE_EXPORT DmpProject @@ -26,6 +26,9 @@ class CORE_EXPORT DmpProject
26 ~DmpProject(); 26 ~DmpProject();
27 bool Read(const std::string &data); 27 bool Read(const std::string &data);
28 bool Write(const std::string &filename, const std::string &data); 28 bool Write(const std::string &filename, const std::string &data);
  29 + bool WritePtree(boost::property_tree::ptree& ptDoc);
  30 + std::string WriteXml();
  31 + std::string WriteJson();
29 DmpCoordinateReferenceSystem crs() const; 32 DmpCoordinateReferenceSystem crs() const;
30 std::map<std::string, DmpMapLayer*> mapLayers() const; 33 std::map<std::string, DmpMapLayer*> mapLayers() const;
31 DmpMapLayer* getLayer(const std::string &layerName) const; 34 DmpMapLayer* getLayer(const std::string &layerName) const;
@@ -75,6 +75,7 @@ bool DmpVectorLayer::writeXml(boost::property_tree::ptree &layerNode) @@ -75,6 +75,7 @@ bool DmpVectorLayer::writeXml(boost::property_tree::ptree &layerNode)
75 layerNode.add("<xmlattr>.name", name_); 75 layerNode.add("<xmlattr>.name", name_);
76 layerNode.add("<xmlattr>.alias", title_); 76 layerNode.add("<xmlattr>.alias", title_);
77 77
  78 +
78 boost::property_tree::ptree ptExtent; 79 boost::property_tree::ptree ptExtent;
79 ptExtent.add("xmin", extent_.xmin()); 80 ptExtent.add("xmin", extent_.xmin());
80 ptExtent.add("ymin", extent_.ymin()); 81 ptExtent.add("ymin", extent_.ymin());
@@ -83,12 +84,12 @@ bool DmpVectorLayer::writeXml(boost::property_tree::ptree &layerNode) @@ -83,12 +84,12 @@ bool DmpVectorLayer::writeXml(boost::property_tree::ptree &layerNode)
83 layerNode.add_child("extent", ptExtent); 84 layerNode.add_child("extent", ptExtent);
84 85
85 layerNode.add("datasource", dataSource_); 86 layerNode.add("datasource", dataSource_);
86 - 87 + boost::property_tree::ptree ptRenderer;
87 if(this->renderer_30_) 88 if(this->renderer_30_)
88 { 89 {
89 - boost::property_tree::ptree ptRenderer;  
90 this->renderer_30_->ParsePtree(ptRenderer); 90 this->renderer_30_->ParsePtree(ptRenderer);
91 } 91 }
  92 + layerNode.add_child("renderer",ptRenderer);
92 93
93 return true; 94 return true;
94 } 95 }
@@ -117,15 +117,15 @@ namespace DmapCore_30 @@ -117,15 +117,15 @@ namespace DmapCore_30
117 sprintf(buff_minscale,"%.0f", this->m_dLower); 117 sprintf(buff_minscale,"%.0f", this->m_dLower);
118 } 118 }
119 119
120 - ptRenderer.add("maxscale",buff_maxscale);  
121 - ptRenderer.add("minscale",buff_minscale);  
122 - ptRenderer.add("alwaysShow", m_alwaysShow?"true":"false"); 120 + ptRenderer.add("<xmlattr>.maxscale",buff_maxscale);
  121 + ptRenderer.add("<xmlattr>.minscale",buff_minscale);
  122 + ptRenderer.add("<xmlattr>.alwaysShow", m_alwaysShow?"true":"false");
123 123
124 if(this->m_pRen) 124 if(this->m_pRen)
125 { 125 {
126 this->m_pRen->ParsePtree(ptRenderer); 126 this->m_pRen->ParsePtree(ptRenderer);
127 } 127 }
128 - pt.add_child("TEXTSYMBOL",ptRenderer); 128 + pt.add_child("SIMPLERENDERER",ptRenderer);
129 return true; 129 return true;
130 } 130 }
131 131
@@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
3 #include "clsJson.h" 3 #include "clsJson.h"
4 #include <stdarg.h> 4 #include <stdarg.h>
5 #include <string.h> 5 #include <string.h>
6 - 6 +#include "clsUtil.h"
7 namespace DmapCore_30 7 namespace DmapCore_30
8 { 8 {
9 void clsJson::ParseEnum(const char *name, char *resultbuff, char* buff, int v, string a1, string a2 , string a3, string a4, string a5, string a6, string a7, string a8, string a9, string a10, string a11, string a12, string a13, string a14, string a15, string a16) 9 void clsJson::ParseEnum(const char *name, char *resultbuff, char* buff, int v, string a1, string a2 , string a3, string a4, string a5, string a6, string a7, string a8, string a9, string a10, string a11, string a12, string a13, string a14, string a15, string a16)
@@ -78,10 +78,19 @@ namespace DmapCore_30 @@ -78,10 +78,19 @@ namespace DmapCore_30
78 } 78 }
79 79
80 80
81 - void clsJson::JsonAttrParseColor(const char* name,const char*name2,char* resultbuff,char* buff,unsigned int& value) 81 + void clsJson::JsonAttrParseColor(const char* name,const char*name2,char* resultbuff,char* buff,unsigned int& iColor)
82 { 82 {
83 string sColor = "", sTransparency = ""; 83 string sColor = "", sTransparency = "";
84 - //StringHelp::ColorToString(value, sColor, sTransparency); 84 + int a = (int)(((unsigned char*)(&iColor))[3]);
  85 + int r = (int)(((unsigned char*)(&iColor))[2]);
  86 + int g = (int)(((unsigned char*)(&iColor))[1]);
  87 + int b = (int)(((unsigned char*)(&iColor))[0]);
  88 + //char s1[500], s2[500];
  89 + //StringHelp::fmt(s1, "%d,%d,%d", r, g, b);
  90 + //StringHelp::fmt(s2, "%lf", a / 255.0);
  91 + sColor = clsUtil::fmt("%d,%d,%d", r, g, b);
  92 + sTransparency = clsUtil::fmt("%.2f", a / 255.0);
  93 +
85 94
86 sprintf(buff, "\"%s\":\"%s\",\"%s\":\"%s\",", name, sColor.c_str(),name2,sTransparency.c_str()); 95 sprintf(buff, "\"%s\":\"%s\",\"%s\":\"%s\",", name, sColor.c_str(),name2,sTransparency.c_str());
87 strcat(resultbuff, buff); 96 strcat(resultbuff, buff);
@@ -11,6 +11,7 @@ @@ -11,6 +11,7 @@
11 #include "clsPtree.h" 11 #include "clsPtree.h"
12 #include <stdarg.h> 12 #include <stdarg.h>
13 #include <string.h> 13 #include <string.h>
  14 +#include "clsUtil.h"
14 15
15 namespace DmapCore_30 16 namespace DmapCore_30
16 { 17 {
@@ -78,16 +79,22 @@ namespace DmapCore_30 @@ -78,16 +79,22 @@ namespace DmapCore_30
78 pt.add(ptname, v); 79 pt.add(ptname, v);
79 } 80 }
80 81
81 -  
82 - 82 + void clsPtree::PtreeAttrParseColor(const char *name, const char *name2, boost::property_tree::ptree &pt, unsigned int &iColor)
  83 + {
  84 + string sColor = "", sTransparency = "";
  85 + int a = (int)(((unsigned char *)(&iColor))[3]);
  86 + int r = (int)(((unsigned char *)(&iColor))[2]);
  87 + int g = (int)(((unsigned char *)(&iColor))[1]);
  88 + int b = (int)(((unsigned char *)(&iColor))[0]);
  89 + //char s1[500], s2[500];
  90 + //StringHelp::fmt(s1, "%d,%d,%d", r, g, b);
  91 + //StringHelp::fmt(s2, "%lf", a / 255.0);
  92 + sColor = clsUtil::fmt("%d,%d,%d", r, g, b);
  93 + sTransparency = clsUtil::fmt("%.2f", a / 255.0);
83 94
84 - void clsPtree::PtreeAttrParseColor(const char* name,const char*name2, boost::property_tree::ptree& pt,unsigned int& value)  
85 - {  
86 - string sColor = "", sTransparency = "";  
87 - std::string ptname = "<xmlattr>."; 95 + std::string ptname = "<xmlattr>.";
88 pt.add(ptname + name, sColor); 96 pt.add(ptname + name, sColor);
89 pt.add(ptname + name2, sTransparency); 97 pt.add(ptname + name2, sTransparency);
90 -  
91 - } 98 + }
92 99
93 } // namespace DmapDll 100 } // namespace DmapDll
  1 +<<<<<<< HEAD
1 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -o -lfcgi++ -lfcgi") 2 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -o -lfcgi++ -lfcgi")
2 3
3 INCLUDE_DIRECTORIES( 4 INCLUDE_DIRECTORIES(
@@ -188,4 +189,196 @@ INSTALL(TARGETS dmap_serv @@ -188,4 +189,196 @@ INSTALL(TARGETS dmap_serv
188 189
189 INSTALL(TARGETS dmap_spserv 190 INSTALL(TARGETS dmap_spserv
190 DESTINATION ${DMAP_BIN_DIR} 191 DESTINATION ${DMAP_BIN_DIR}
  192 +=======
  193 +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -o -lfcgi++ -lfcgi")
  194 +
  195 +INCLUDE_DIRECTORIES(
  196 + ${CMAKE_SOURCE_DIR}/src/server/spserver
  197 +)
  198 +
  199 +
  200 +ADD_SUBDIRECTORY(spserver)
  201 +ADD_SUBDIRECTORY(services)
  202 +
  203 +
  204 +
  205 +########################################################
  206 +# Files
  207 +SET (DMAP_SERVER_SRCS
  208 + dmpfilterresponsedecorator.cpp
  209 + dmpmainserver.cpp
  210 + dmprequesthandler.cpp
  211 + dmpserver.cpp
  212 + dmpserverapi.cpp
  213 + dmpserverconfig.cpp
  214 + dmpservercontext.cpp
  215 + dmpserverapicontext.cpp
  216 + dmpserverapihandler.cpp
  217 + dmpserverfilter.cpp
  218 + dmpserverinterface.cpp
  219 + dmpserverinterfaceimpl.cpp
  220 + dmpservermanager.cpp
  221 + dmpservermanagerapi.cpp
  222 + dmpserverresponse.cpp
  223 + dmpserverrequest.cpp
  224 + dmpserverparameters.cpp
  225 + dmpserverplugins.cpp
  226 + dmpserverutils.cpp
  227 + dmpserverloader.cpp
  228 + dmpserverproject.cpp
  229 + dmpserverregistry.cpp
  230 + python/dmppythonutils.cpp
  231 + python/dmpserverwrapper.cpp
  232 + dmphttpbase.cpp
  233 + dmphttputils.cpp
  234 +
  235 +)
  236 +
  237 +SET (DMAP_SERVER_HDRS
  238 + dmpfilterresponsedecorator.h
  239 + dmpmainserver.h
  240 + dmprequesthandler.h
  241 + dmpserver.h
  242 + dmpserverapi.h
  243 + dmpserverapihandler.h
  244 + dmpserverapicontext.h
  245 + dmpservercontext.h
  246 + dmpserverconfig.h
  247 + dmpserverentity.h
  248 + dmpserverfilter.h
  249 + dmpserverinterface.h
  250 + dmpserverinterfaceimpl.h
  251 + dmpservermanager.h
  252 + dmpservermanagerapi.h
  253 + dmpserverrequest.h
  254 + dmpserverresponse.h
  255 + dmpserverparameters.h
  256 + dmpserverplugins.h
  257 + dmpserverutils.h
  258 + dmpservice.h
  259 + dmpservermodule.h
  260 + dmpserverloader.h
  261 + dmpserverproject.h
  262 + dmpserverregistry.h
  263 + python/dmppythonutils.h
  264 + dmphttpbase.h
  265 + dmphttputils.h
  266 +
  267 +)
  268 +
  269 +#############################################################
  270 +# dmap_server library
  271 +
  272 +
  273 +
  274 +INCLUDE_DIRECTORIES(
  275 + ${CMAKE_SOURCE_DIR}/src/core
  276 + ${CMAKE_SOURCE_DIR}/src/core/geometry
  277 + ${CMAKE_SOURCE_DIR}/src/core/symbology
  278 +)
  279 +
  280 +INCLUDE_DIRECTORIES(SYSTEM
  281 + ${PYTHON_INCLUDE_PATH}
  282 +)
  283 +ADD_LIBRARY(dmap_server SHARED ${DMAP_SERVER_SRCS} ${DMAP_SERVER_HDRS})
  284 +
  285 +target_link_libraries(dmap_server
  286 + dmap_core
  287 + ${Boost_LIBRARIES}
  288 + Boost::regex
  289 + ${PYTHON_LIBRARIES}
  290 + dl)
  291 +
  292 +IF (WITH_BINDINGS)
  293 + TARGET_LINK_LIBRARIES(dmap_server
  294 + Boost::${DMAP_BOOST_PYTHON_FOUND}
  295 + )
  296 +ENDIF(WITH_BINDINGS)
  297 +
  298 +set_target_properties(dmap_server
  299 + PROPERTIES
  300 + POSITION_INDEPENDENT_CODE 1
  301 + CXX_VISIBILITY_PRESET hidden
  302 + VISIBILITY_INLINES_HIDDEN 1
  303 + #VERSION ${COMPLETE_VERSION}
  304 + #SOVERSION ${COMPLETE_VERSION}
  305 + )
  306 +
  307 +generate_export_header(
  308 + dmap_server
  309 + BASE_NAME SERVER
  310 + EXPORT_FILE_NAME "${CMAKE_BINARY_DIR}/${INSTALL_INCLUDEDIR}/dmap_server.h"
  311 +)
  312 +
  313 +
  314 +target_include_directories(dmap_server
  315 + PUBLIC
  316 + ${CMAKE_BINARY_DIR}/${INSTALL_INCLUDEDIR}
  317 + )
  318 + MESSAGE(STATUS "dmap_server path: ${CMAKE_BINARY_DIR}/${INSTALL_INCLUDEDIR}")
  319 +
  320 +
  321 +add_executable(dmap_spserv
  322 + dmap_spserv.cpp
  323 + dmpspserverrequest.h
  324 + dmpspserverresponse.h
  325 + dmpspserverrequest.cpp
  326 + dmpspserverresponse.cpp
  327 +)
  328 +
  329 +add_executable(dmap_serv
  330 + dmap_serv.cpp
  331 + dmpapacheserverrequest.h
  332 + dmpapacheserverresponse.h
  333 + dmpapacheserverrequest.cpp
  334 + dmpapacheserverresponse.cpp
  335 +)
  336 +
  337 +target_link_libraries(dmap_spserv
  338 + spserver
  339 + dmap_server
  340 + )
  341 +
  342 +target_link_libraries(dmap_serv
  343 + dmap_server
  344 +)
  345 +
  346 +INCLUDE_DIRECTORIES(
  347 + ${CMAKE_SOURCE_DIR}/pgsql/include
  348 +)
  349 +LINK_DIRECTORIES(dmap_server ${CMAKE_SOURCE_DIR}/pgsql/lib)
  350 +TARGET_LINK_LIBRARIES(dmap_server ${CMAKE_SOURCE_DIR}/pgsql/lib/libpq.so)
  351 +
  352 +find_package(Fcgi REQUIRED)
  353 +if (NOT FCGI_FOUND)
  354 + message (SEND_ERROR "Fast CGI dependency was not found!")
  355 +endif()
  356 +
  357 +target_include_directories(dmap_serv SYSTEM PRIVATE
  358 + ${FCGI_INCLUDE_DIR}
  359 +)
  360 +target_link_libraries(dmap_serv
  361 + ${FCGI_LIBRARY}
  362 +)
  363 +########################################################
  364 +# Install
  365 +INSTALL(FILES
  366 + dmpserver.ini
  367 + DESTINATION ${DMAP_LIBEXEC_SUBDIR}
  368 +)
  369 +
  370 +INSTALL(TARGETS dmap_server
  371 + RUNTIME DESTINATION ${DMAP_BIN_DIR}
  372 + LIBRARY DESTINATION ${DMAP_LIB_DIR}
  373 + ARCHIVE DESTINATION ${DMAP_LIB_DIR}
  374 + PUBLIC_HEADER DESTINATION ${DMAP_INCLUDE_DIR}
  375 +)
  376 +
  377 +INSTALL(TARGETS dmap_serv
  378 + DESTINATION ${DMAP_BIN_DIR}
  379 +)
  380 +
  381 +INSTALL(TARGETS dmap_spserv
  382 + DESTINATION ${DMAP_BIN_DIR}
  383 +>>>>>>> 678abfd93ad90c860e277df725c22d74ff408a82
191 ) 384 )
1 -/**************************************************************************  
2 -* file: dmpservermanager.cpp  
3 -  
4 -* Author: wanzhongping  
5 -* Date: 2021-07-27 21:59:46  
6 -* Email: zhongpingw@chinadci.com  
7 -* copyright: 广州城市信息研究所有限公司  
8 -***************************************************************************/  
9 -#include "dmpservermanager.h"  
10 -#include "dmpserver.h"  
11 -#include "dmphttputils.h"  
12 -#include "dmpserverConfig.h"  
13 -#include <memory>  
14 -#include <boost/property_tree/ptree.hpp>  
15 -#include <boost/property_tree/json_parser.hpp>  
16 -#include <boost/property_tree/xml_parser.hpp>  
17 -#include <sstream>  
18 -#include <fstream>  
19 -#include <math.h>  
20 -#include "dmptilelayer.h"  
21 -#include <iostream>  
22 -#include "dmplogger.h"  
23 -#include "dmptilelayer.h"  
24 -  
25 -DmpServerManager::DmpServerManager()  
26 -{  
27 - serverRegistry_ = new DmpServerRegistry();  
28 -}  
29 -  
30 -DmpServerManager::~DmpServerManager()  
31 -{  
32 - if (serverRegistry_)  
33 - {  
34 - delete serverRegistry_;  
35 - serverRegistry_ = NULL;  
36 - }  
37 -  
38 - ProjectMap::iterator iter = projects_.begin();  
39 - for (; iter != projects_.end(); ++iter)  
40 - {  
41 - DmpProject *mapProject = iter->second;  
42 - if (mapProject)  
43 - {  
44 - delete mapProject;  
45 - mapProject = nullptr;  
46 - }  
47 - }  
48 - projects_.clear();  
49 -}  
50 -  
51 -void DmpServerManager::init(const boost::filesystem::path &modulePath)  
52 -{  
53 - serverRegistry_->init(modulePath);  
54 - if(!loadServices())  
55 - {  
56 - std::cout << "加载服务失败!" << std::endl;  
57 - LOGGER_ERROR("加载服务失败!");  
58 - }  
59 - //LoadDmpServices();  
60 -}  
61 -  
62 -std::string DmpServerManager::getCapabilities()  
63 -{  
64 - return serverRegistry_->getCapabilities();  
65 -}  
66 -  
67 -std::shared_ptr<DmpServer> DmpServerManager::serverForRequest(const DmpServerRequest &request)  
68 -{  
69 - return serverRegistry_->getServerForRequest(request);  
70 -}  
71 -  
72 -std::shared_ptr<DmpServerApi> DmpServerManager::apiForRequest(const DmpServerRequest &request)  
73 -{  
74 - return serverRegistry_->getApiForRequest(request);  
75 -}  
76 -  
77 -DmpProject *DmpServerManager::getProject(const std::string &serviceName)  
78 -{  
79 - std::map<std::string, DmpProject *>::iterator iter = projects_.find(serviceName);  
80 - if (iter != projects_.end())  
81 - {  
82 - return iter->second;  
83 - }  
84 - else  
85 - {  
86 - return nullptr;  
87 - }  
88 -}  
89 -  
90 -bool DmpServerManager::removeProject(const std::string &serviceName)  
91 -{  
92 - try  
93 - {  
94 - std::map<std::string, DmpProject *>::iterator iter = projects_.find(serviceName);  
95 - if (iter != projects_.end())  
96 - {  
97 - delete iter->second;  
98 - projects_.erase(iter);  
99 - }  
100 - }  
101 - catch (const std::exception &e)  
102 - {  
103 - std::cerr << e.what() << '\n';  
104 - return false;  
105 - }  
106 - return true;  
107 -}  
108 -  
109 -bool DmpServerManager::publish(const std::string& serverName, const std::string& serviceName, const std::string& title, int capabilities, const std::string& projectData)  
110 -{  
111 - //project  
112 - std::string projData;  
113 - if (!DmpServerUtils::Base64Decode(projectData, &projData))  
114 - {  
115 - return false;  
116 - }  
117 - DmpProject *project = new DmpProject();  
118 - if (!project->Read(projData))  
119 - {  
120 - delete project;  
121 - return false;  
122 - }  
123 -  
124 - if (!serverRegistry_->getServer(serverName)->publish(serviceName, title, capabilities, *project))  
125 - {  
126 - delete project;  
127 - return false;  
128 - }  
129 - projects_[serviceName] = project;  
130 - return true;  
131 -}  
132 -  
133 -bool DmpServerManager::deleteService(const std::string &serverName, const std::string &serviceName)  
134 -{  
135 - if (serverRegistry_->getServer(serverName)->remove(serviceName) && removeProject(serviceName))  
136 - {  
137 - return true;  
138 - }  
139 - else  
140 - {  
141 - return false;  
142 - }  
143 -}  
144 -  
145 -bool DmpServerManager::startService(const std::string &serverName, const std::string &serviceName)  
146 -{  
147 - return serverRegistry_->getServer(serverName)->start(serviceName);  
148 -}  
149 -  
150 -bool DmpServerManager::stopService(const std::string &serverName, const std::string &serviceName)  
151 -{  
152 - return serverRegistry_->getServer(serverName)->stop(serviceName);  
153 -}  
154 -bool DmpServerManager::loadServices()  
155 -{  
156 - boost::property_tree::ptree pt,ptList;  
157 - std::string conn = DmpServerConfig::Instance()->getMetaUrl();  
158 - const std::string url= conn + URI_RELOAD;  
159 - std::string strContent=DmpHttp::get(url);  
160 - if(strContent.length()==0)  
161 - {  
162 - return false;  
163 - }  
164 - std::stringstream ssData;  
165 - ssData<<strContent.c_str();  
166 - boost::property_tree::read_json(ssData, pt);  
167 - int iCount = std::atoi(pt.get<std::string>("data.count").c_str());  
168 - if(iCount>0)  
169 - {  
170 - ptList=pt.get_child("data.list");  
171 - for (auto& e : ptList)  
172 - {  
173 - std::string name = e.second.get<std::string>("name");  
174 - std::string title = e.second.get<std::string>("title");  
175 - std::string type = e.second.get<std::string>("type");  
176 - int capabilities =e.second.get<int>("capabilities");  
177 - std::string project = e.second.get<std::string>("project");  
178 - this->initServices(type,name,title,capabilities,project);  
179 - }  
180 - }  
181 - return true;  
182 -}  
183 -bool DmpServerManager::initServices(const std::string& serverName, const std::string& serviceName, const std::string& title, int capabilities, const std::string& projectData)  
184 -{  
185 - //project  
186 - std::string projData;  
187 - if (!DmpServerUtils::Base64Decode(projectData, &projData))  
188 - {  
189 - return false;  
190 - }  
191 - DmpProject *project = new DmpProject();  
192 - if (!project->Read(projData))  
193 - {  
194 - delete project;  
195 - return false;  
196 - }  
197 -  
198 - if (!serverRegistry_->getServer(serverName)->publish(serviceName, title, capabilities, *project))  
199 - {  
200 - delete project;  
201 - return false;  
202 - }  
203 - projects_[serviceName] = project;  
204 - return true; 1 +/**************************************************************************
  2 +* file: dmpservermanager.cpp
  3 +
  4 +* Author: wanzhongping
  5 +* Date: 2021-07-27 21:59:46
  6 +* Email: zhongpingw@chinadci.com
  7 +* copyright: 广州城市信息研究所有限公司
  8 +***************************************************************************/
  9 +#include "dmpservermanager.h"
  10 +#include "dmpserver.h"
  11 +#include "dmphttputils.h"
  12 +#include "dmpserverConfig.h"
  13 +#include <memory>
  14 +#include <boost/property_tree/ptree.hpp>
  15 +#include <boost/property_tree/json_parser.hpp>
  16 +#include <boost/property_tree/xml_parser.hpp>
  17 +#include <sstream>
  18 +#include <fstream>
  19 +#include <math.h>
  20 +#include "dmptilelayer.h"
  21 +#include <iostream>
  22 +#include "dmplogger.h"
  23 +#include "dmptilelayer.h"
  24 +
  25 +DmpServerManager::DmpServerManager()
  26 +{
  27 + serverRegistry_ = new DmpServerRegistry();
  28 +}
  29 +
  30 +DmpServerManager::~DmpServerManager()
  31 +{
  32 + if (serverRegistry_)
  33 + {
  34 + delete serverRegistry_;
  35 + serverRegistry_ = NULL;
  36 + }
  37 +
  38 + ProjectMap::iterator iter = projects_.begin();
  39 + for (; iter != projects_.end(); ++iter)
  40 + {
  41 + DmpProject *mapProject = iter->second;
  42 + if (mapProject)
  43 + {
  44 + delete mapProject;
  45 + mapProject = nullptr;
  46 + }
  47 + }
  48 + projects_.clear();
  49 +}
  50 +
  51 +void DmpServerManager::init(const boost::filesystem::path &modulePath)
  52 +{
  53 + serverRegistry_->init(modulePath);
  54 + if(!loadServices())
  55 + {
  56 + std::cout << "加载服务失败!" << std::endl;
  57 + LOGGER_ERROR("加载服务失败!");
  58 + }
  59 + //LoadDmpServices();
  60 +}
  61 +
  62 +std::string DmpServerManager::getCapabilities()
  63 +{
  64 + return serverRegistry_->getCapabilities();
  65 +}
  66 +
  67 +std::shared_ptr<DmpServer> DmpServerManager::serverForRequest(const DmpServerRequest &request)
  68 +{
  69 + return serverRegistry_->getServerForRequest(request);
  70 +}
  71 +
  72 +std::shared_ptr<DmpServerApi> DmpServerManager::apiForRequest(const DmpServerRequest &request)
  73 +{
  74 + return serverRegistry_->getApiForRequest(request);
  75 +}
  76 +
  77 +DmpProject *DmpServerManager::getProject(const std::string &serviceName)
  78 +{
  79 + std::map<std::string, DmpProject *>::iterator iter = projects_.find(serviceName);
  80 + if (iter != projects_.end())
  81 + {
  82 + return iter->second;
  83 + }
  84 + else
  85 + {
  86 + return nullptr;
  87 + }
  88 +}
  89 +
  90 +bool DmpServerManager::removeProject(const std::string &serviceName)
  91 +{
  92 + try
  93 + {
  94 + std::map<std::string, DmpProject *>::iterator iter = projects_.find(serviceName);
  95 + if (iter != projects_.end())
  96 + {
  97 + delete iter->second;
  98 + projects_.erase(iter);
  99 + }
  100 + }
  101 + catch (const std::exception &e)
  102 + {
  103 + std::cerr << e.what() << '\n';
  104 + return false;
  105 + }
  106 + return true;
  107 +}
  108 +
  109 +bool DmpServerManager::publish(const std::string& serverName, const std::string& serviceName, const std::string& title, int capabilities, const std::string& projectData)
  110 +{
  111 + //project
  112 + std::string projData;
  113 + if (!DmpServerUtils::Base64Decode(projectData, &projData))
  114 + {
  115 + return false;
  116 + }
  117 + DmpProject *project = new DmpProject();
  118 + if (!project->Read(projData))
  119 + {
  120 + delete project;
  121 + return false;
  122 + }
  123 +
  124 + if (!serverRegistry_->getServer(serverName)->publish(serviceName, title, capabilities, *project))
  125 + {
  126 + delete project;
  127 + return false;
  128 + }
  129 + projects_[serviceName] = project;
  130 + return true;
  131 +}
  132 +
  133 +bool DmpServerManager::deleteService(const std::string &serverName, const std::string &serviceName)
  134 +{
  135 + if (serverRegistry_->getServer(serverName)->remove(serviceName) && removeProject(serviceName))
  136 + {
  137 + return true;
  138 + }
  139 + else
  140 + {
  141 + return false;
  142 + }
  143 +}
  144 +
  145 +bool DmpServerManager::startService(const std::string &serverName, const std::string &serviceName)
  146 +{
  147 + return serverRegistry_->getServer(serverName)->start(serviceName);
  148 +}
  149 +
  150 +bool DmpServerManager::stopService(const std::string &serverName, const std::string &serviceName)
  151 +{
  152 + return serverRegistry_->getServer(serverName)->stop(serviceName);
  153 +}
  154 +bool DmpServerManager::loadServices()
  155 +{
  156 + boost::property_tree::ptree pt,ptList;
  157 + std::string conn = DmpServerConfig::Instance()->getMetaUrl();
  158 + const std::string url= conn + URI_RELOAD;
  159 + std::string strContent=DmpHttp::get(url);
  160 + if(strContent.length()==0)
  161 + {
  162 + return false;
  163 + }
  164 + std::stringstream ssData;
  165 + ssData<<strContent.c_str();
  166 + boost::property_tree::read_json(ssData, pt);
  167 + int iCount = std::atoi(pt.get<std::string>("data.count").c_str());
  168 + if(iCount>0)
  169 + {
  170 + ptList=pt.get_child("data.list");
  171 + for (auto& e : ptList)
  172 + {
  173 + std::string name = e.second.get<std::string>("name");
  174 + std::string title = e.second.get<std::string>("title");
  175 + std::string type = e.second.get<std::string>("type");
  176 + int capabilities =e.second.get<int>("capabilities");
  177 + std::string project = e.second.get<std::string>("project");
  178 + this->initServices(type,name,title,capabilities,project);
  179 + }
  180 + }
  181 + return true;
  182 +}
  183 +bool DmpServerManager::initServices(const std::string& serverName, const std::string& serviceName, const std::string& title, int capabilities, const std::string& projectData)
  184 +{
  185 + //project
  186 + std::string projData;
  187 + if (!DmpServerUtils::Base64Decode(projectData, &projData))
  188 + {
  189 + return false;
  190 + }
  191 + DmpProject *project = new DmpProject();
  192 + if (!project->Read(projData))
  193 + {
  194 + delete project;
  195 + return false;
  196 + }
  197 +
  198 + if (!serverRegistry_->getServer(serverName)->publish(serviceName, title, capabilities, *project))
  199 + {
  200 + delete project;
  201 + return false;
  202 + }
  203 + projects_[serviceName] = project;
  204 + return true;
  205 +=======
  206 +/**************************************************************************
  207 +* file: dmpservermanager.cpp
  208 +
  209 +* Author: wanzhongping
  210 +* Date: 2021-07-27 21:59:46
  211 +* Email: zhongpingw@chinadci.com
  212 +* copyright: 广州城市信息研究所有限公司
  213 +***************************************************************************/
  214 +#include "dmpservermanager.h"
  215 +#include "dmpserver.h"
  216 +#include "dmphttputils.h"
  217 +#include "dmpserverConfig.h"
  218 +#include <memory>
  219 +#include <boost/property_tree/ptree.hpp>
  220 +#include <boost/property_tree/json_parser.hpp>
  221 +#include <boost/property_tree/xml_parser.hpp>
  222 +#include <sstream>
  223 +#include <fstream>
  224 +#include <math.h>
  225 +#include "dmptilelayer.h"
  226 +#include <iostream>
  227 +#include "dmplogger.h"
  228 +#include "dmptilelayer.h"
  229 +
  230 +DmpServerManager::DmpServerManager()
  231 +{
  232 + serverRegistry_ = new DmpServerRegistry();
  233 +}
  234 +
  235 +DmpServerManager::~DmpServerManager()
  236 +{
  237 + if (serverRegistry_)
  238 + {
  239 + delete serverRegistry_;
  240 + serverRegistry_ = NULL;
  241 + }
  242 +
  243 + ProjectMap::iterator iter = projects_.begin();
  244 + for (; iter != projects_.end(); ++iter)
  245 + {
  246 + DmpProject *mapProject = iter->second;
  247 + if (mapProject)
  248 + {
  249 + delete mapProject;
  250 + mapProject = nullptr;
  251 + }
  252 + }
  253 + projects_.clear();
  254 +}
  255 +
  256 +void DmpServerManager::init(const boost::filesystem::path &modulePath)
  257 +{
  258 + serverRegistry_->init(modulePath);
  259 + if(!loadServices())
  260 + {
  261 + std::cout << "加载服务失败!" << std::endl;
  262 + LOGGER_ERROR("加载服务失败!");
  263 + }
  264 + //LoadDmpServices();
  265 +}
  266 +
  267 +std::string DmpServerManager::getCapabilities()
  268 +{
  269 + return serverRegistry_->getCapabilities();
  270 +}
  271 +
  272 +std::shared_ptr<DmpServer> DmpServerManager::serverForRequest(const DmpServerRequest &request)
  273 +{
  274 + return serverRegistry_->getServerForRequest(request);
  275 +}
  276 +
  277 +std::shared_ptr<DmpServerApi> DmpServerManager::apiForRequest(const DmpServerRequest &request)
  278 +{
  279 + return serverRegistry_->getApiForRequest(request);
  280 +}
  281 +
  282 +DmpProject *DmpServerManager::getProject(const std::string &serviceName)
  283 +{
  284 + std::map<std::string, DmpProject *>::iterator iter = projects_.find(serviceName);
  285 + if (iter != projects_.end())
  286 + {
  287 + return iter->second;
  288 + }
  289 + else
  290 + {
  291 + return nullptr;
  292 + }
  293 +}
  294 +
  295 +bool DmpServerManager::removeProject(const std::string &serviceName)
  296 +{
  297 + try
  298 + {
  299 + std::map<std::string, DmpProject *>::iterator iter = projects_.find(serviceName);
  300 + if (iter != projects_.end())
  301 + {
  302 + delete iter->second;
  303 + projects_.erase(iter);
  304 + }
  305 + }
  306 + catch (const std::exception &e)
  307 + {
  308 + std::cerr << e.what() << '\n';
  309 + return false;
  310 + }
  311 + return true;
  312 +}
  313 +
  314 +bool DmpServerManager::publish(const std::string& serverName, const std::string& serviceName, const std::string& title, int capabilities, const std::string& projectData)
  315 +{
  316 + //project
  317 + std::string projData;
  318 + if (!DmpServerUtils::Base64Decode(projectData, &projData))
  319 + {
  320 + return false;
  321 + }
  322 + DmpProject *project = new DmpProject();
  323 + if (!project->Read(projData))
  324 + {
  325 + delete project;
  326 + return false;
  327 + }
  328 +
  329 + if (!serverRegistry_->getServer(serverName)->publish(serviceName, title, capabilities, *project))
  330 + {
  331 + delete project;
  332 + return false;
  333 + }
  334 + projects_[serviceName] = project;
  335 +
  336 + return true;
  337 +}
  338 +
  339 +bool DmpServerManager::deleteService(const std::string &serverName, const std::string &serviceName)
  340 +{
  341 + if (serverRegistry_->getServer(serverName)->remove(serviceName) && removeProject(serviceName))
  342 + {
  343 + return true;
  344 + }
  345 + else
  346 + {
  347 + return false;
  348 + }
  349 +}
  350 +
  351 +bool DmpServerManager::startService(const std::string &serverName, const std::string &serviceName)
  352 +{
  353 + return serverRegistry_->getServer(serverName)->start(serviceName);
  354 +}
  355 +
  356 +bool DmpServerManager::stopService(const std::string &serverName, const std::string &serviceName)
  357 +{
  358 + return serverRegistry_->getServer(serverName)->stop(serviceName);
  359 +}
  360 +bool DmpServerManager::loadServices()
  361 +{
  362 + boost::property_tree::ptree pt,ptList;
  363 + std::string conn = DmpServerConfig::Instance()->getMetaUrl();
  364 + const std::string url= conn + URI_RELOAD;
  365 + std::string strContent=DmpHttp::get(url);
  366 + if(strContent.length()==0)
  367 + {
  368 + return false;
  369 + }
  370 + std::stringstream ssData;
  371 + ssData<<strContent.c_str();
  372 + boost::property_tree::read_json(ssData, pt);
  373 + int iCount = std::atoi(pt.get<std::string>("data.count").c_str());
  374 + if(iCount>0)
  375 + {
  376 + ptList=pt.get_child("data.list");
  377 + for (auto& e : ptList)
  378 + {
  379 + std::string name = e.second.get<std::string>("name");
  380 + std::string title = e.second.get<std::string>("title");
  381 + std::string type = e.second.get<std::string>("type");
  382 + int capabilities =e.second.get<int>("capabilities");
  383 + std::string project = e.second.get<std::string>("project");
  384 + this->initServices(type,name,title,capabilities,project);
  385 + }
  386 + }
  387 + return true;
  388 +}
  389 +bool DmpServerManager::initServices(const std::string& serverName, const std::string& serviceName, const std::string& title, int capabilities, const std::string& projectData)
  390 +{
  391 + //project
  392 + std::string projData;
  393 + if (!DmpServerUtils::Base64Decode(projectData, &projData))
  394 + {
  395 + return false;
  396 + }
  397 + DmpProject *project = new DmpProject();
  398 + if (!project->Read(projData))
  399 + {
  400 + delete project;
  401 + return false;
  402 + }
  403 +
  404 + if (!serverRegistry_->getServer(serverName)->publish(serviceName, title, capabilities, *project))
  405 + {
  406 + delete project;
  407 + return false;
  408 + }
  409 + projects_[serviceName] = project;
  410 + return true;
  411 +
205 } 412 }
@@ -20,6 +20,7 @@ SET (MAPSERVER_SRCS @@ -20,6 +20,7 @@ SET (MAPSERVER_SRCS
20 wms/dmpwmsgetfeatureinfo.cpp 20 wms/dmpwmsgetfeatureinfo.cpp
21 mapping/dmpmapping.cpp 21 mapping/dmpmapping.cpp
22 mapping/dmpeditservice.cpp 22 mapping/dmpeditservice.cpp
  23 + mapping/dmpmappingparameters.cpp
23 ) 24 )
24 25
25 SET (MAPSERVER_HDRS 26 SET (MAPSERVER_HDRS
@@ -40,6 +41,7 @@ SET (MAPSERVER_HDRS @@ -40,6 +41,7 @@ SET (MAPSERVER_HDRS
40 wms/dmpwmsgetfeatureinfo.h 41 wms/dmpwmsgetfeatureinfo.h
41 mapping/dmpmapping.h 42 mapping/dmpmapping.h
42 mapping/dmpeditservice.h 43 mapping/dmpeditservice.h
  44 + mapping/dmpmappingparameters.h
43 ) 45 )
44 46
45 ######################################################## 47 ########################################################
@@ -10,25 +10,28 @@ @@ -10,25 +10,28 @@
10 #include "dmplogger.h" 10 #include "dmplogger.h"
11 #include "dmpserverresponse.h" 11 #include "dmpserverresponse.h"
12 #include "dmpserverrequest.h" 12 #include "dmpserverrequest.h"
  13 +#include "dmpproject.h"
  14 +#include "dmpserverproject.h"
13 #include <boost/property_tree/ptree.hpp> 15 #include <boost/property_tree/ptree.hpp>
14 #include <boost/property_tree/json_parser.hpp> 16 #include <boost/property_tree/json_parser.hpp>
15 #include <boost/typeof/typeof.hpp> 17 #include <boost/typeof/typeof.hpp>
16 18
17 namespace DmpMapping 19 namespace DmpMapping
18 { 20 {
19 - bool loadService(const DmpServerContext &context, ProjectMap& vectorMappingProjects, const char* data) 21 + bool loadService(const DmpServerContext &context, ProjectMap& vectorMappingProjects)
20 { 22 {
  23 + const char *data = (char *)(context.request()->GetData());
21 if(data== nullptr || *data == '\0') 24 if(data== nullptr || *data == '\0')
22 { 25 {
23 LOGGER_ERROR("post 参数错误"); 26 LOGGER_ERROR("post 参数错误");
24 - context.response()->write("{\"status\":\"false\",\"message\":\"post 参数错误!\"}"); 27 + context.response()->writeJson("{\"status\":\"false\",\"message\":\"post 参数错误!\"}");
25 return false; 28 return false;
26 } 29 }
27 30
28 if(!context.serverProject()) 31 if(!context.serverProject())
29 { 32 {
30 LOGGER_ERROR("加载服务信息失败,服务名称是否错误"); 33 LOGGER_ERROR("加载服务信息失败,服务名称是否错误");
31 - context.response()->write("{\"status\":\"false\",\"message\":\"加载服务信息失败,服务名称是否错误!\"}"); 34 + context.response()->writeJson("{\"status\":\"false\",\"message\":\"加载服务信息失败,服务名称是否错误!\"}");
32 return false; 35 return false;
33 } 36 }
34 37
@@ -39,26 +42,27 @@ namespace DmpMapping @@ -39,26 +42,27 @@ namespace DmpMapping
39 boost::property_tree::read_json(stream, pt); 42 boost::property_tree::read_json(stream, pt);
40 43
41 std::string guid = pt.get<std::string>("guid"); 44 std::string guid = pt.get<std::string>("guid");
42 - std::string project = pt.get<std::string>("project");  
43 - if(!guid.empty() && !project.empty()) 45 +
  46 + DmpProject* project = (DmpProject*)context.serverProject()->project();
  47 + std::string projectData = project->WriteXml();
  48 + if(!guid.empty() && !projectData.empty())
44 { 49 {
45 - std::string projData;  
46 - if (!DmpServerUtils::Base64Decode(project, &projData))  
47 - {  
48 - return false;  
49 - } 50 +
50 shared_ptr<DmpProject> project(new DmpProject()); 51 shared_ptr<DmpProject> project(new DmpProject());
51 - if (!project->Read(projData)) 52 + if (!project->Read(projectData))
52 { 53 {
53 return false; 54 return false;
54 } 55 }
55 vectorMappingProjects[guid] = project; 56 vectorMappingProjects[guid] = project;
56 - context.response()->write("{\"status\":\"true\",\"message\":\"创建编辑服务工作空间成功!\"}"); 57 + context.response()->removeHeader("Content-Type");
  58 + context.response()->setHeader("Content-Type", "text/xml;charset=utf-8");
  59 + context.response()->write(projectData);
  60 + return true;
57 } 61 }
58 else 62 else
59 { 63 {
60 LOGGER_ERROR("post 参数错误"); 64 LOGGER_ERROR("post 参数错误");
61 - context.response()->write("{\"status\":\"false\",\"message\":\"post 参数错误!\"}"); 65 + context.response()->writeJson("{\"status\":\"false\",\"message\":\"post 参数错误!\"}");
62 return false; 66 return false;
63 } 67 }
64 68
@@ -66,31 +70,32 @@ namespace DmpMapping @@ -66,31 +70,32 @@ namespace DmpMapping
66 catch (boost::property_tree::ptree_bad_path &e) 70 catch (boost::property_tree::ptree_bad_path &e)
67 { 71 {
68 LOGGER_ERROR(e.what()); 72 LOGGER_ERROR(e.what());
69 - context.response()->write("{\"status\":\"false\",\"message\":\"post 参数错误\"}"); 73 + context.response()->writeJson("{\"status\":\"false\",\"message\":\"post 参数错误\"}");
70 return false; 74 return false;
71 } 75 }
72 catch (boost::property_tree::ptree_bad_data &e) 76 catch (boost::property_tree::ptree_bad_data &e)
73 { 77 {
74 LOGGER_ERROR(e.what()); 78 LOGGER_ERROR(e.what());
75 - context.response()->write("{\"status\":\"false\",\"message\":\"post 参数错误\"}"); 79 + context.response()->writeJson("{\"status\":\"false\",\"message\":\"post 参数错误\"}");
76 return false; 80 return false;
77 } 81 }
78 return false; 82 return false;
79 } 83 }
80 84
81 - bool editService(const DmpServerContext &context,ProjectMap& vectorMappingProjects, const char* data) 85 + bool editService(const DmpServerContext &context,ProjectMap& vectorMappingProjects)
82 { 86 {
  87 + const char *data = (char *)(context.request()->GetData());
83 if(data== nullptr || *data == '\0') 88 if(data== nullptr || *data == '\0')
84 { 89 {
85 LOGGER_ERROR("post 参数错误"); 90 LOGGER_ERROR("post 参数错误");
86 - context.response()->write("{\"status\":\"false\",\"message\":\"post 参数错误!\"}"); 91 + context.response()->writeJson("{\"status\":\"false\",\"message\":\"post 参数错误!\"}");
87 return false; 92 return false;
88 } 93 }
89 94
90 if(!context.serverProject()) 95 if(!context.serverProject())
91 { 96 {
92 LOGGER_ERROR("加载服务信息失败,服务名称是否错误"); 97 LOGGER_ERROR("加载服务信息失败,服务名称是否错误");
93 - context.response()->write("{\"status\":\"false\",\"message\":\"加载服务信息失败,服务名称是否错误!\"}"); 98 + context.response()->writeJson("{\"status\":\"false\",\"message\":\"加载服务信息失败,服务名称是否错误!\"}");
94 return false; 99 return false;
95 } 100 }
96 101
@@ -115,12 +120,12 @@ namespace DmpMapping @@ -115,12 +120,12 @@ namespace DmpMapping
115 return false; 120 return false;
116 } 121 }
117 vectorMappingProjects[guid] = project; 122 vectorMappingProjects[guid] = project;
118 - context.response()->write("{\"status\":\"true\",\"message\":\"创建编辑服务工作空间成功!\"}"); 123 + context.response()->writeJson("{\"status\":\"true\",\"message\":\"创建编辑服务工作空间成功!\"}");
119 } 124 }
120 else 125 else
121 { 126 {
122 LOGGER_ERROR("post 参数错误"); 127 LOGGER_ERROR("post 参数错误");
123 - context.response()->write("{\"status\":\"false\",\"message\":\"post 参数错误!\"}"); 128 + context.response()->writeJson("{\"status\":\"false\",\"message\":\"post 参数错误!\"}");
124 return false; 129 return false;
125 } 130 }
126 131
@@ -128,13 +133,13 @@ namespace DmpMapping @@ -128,13 +133,13 @@ namespace DmpMapping
128 catch (boost::property_tree::ptree_bad_path &e) 133 catch (boost::property_tree::ptree_bad_path &e)
129 { 134 {
130 LOGGER_ERROR(e.what()); 135 LOGGER_ERROR(e.what());
131 - context.response()->write("{\"status\":\"false\",\"message\":\"post 参数错误\"}"); 136 + context.response()->writeJson("{\"status\":\"false\",\"message\":\"post 参数错误\"}");
132 return false; 137 return false;
133 } 138 }
134 catch (boost::property_tree::ptree_bad_data &e) 139 catch (boost::property_tree::ptree_bad_data &e)
135 { 140 {
136 LOGGER_ERROR(e.what()); 141 LOGGER_ERROR(e.what());
137 - context.response()->write("{\"status\":\"false\",\"message\":\"post 参数错误\"}"); 142 + context.response()->writeJson("{\"status\":\"false\",\"message\":\"post 参数错误\"}");
138 return false; 143 return false;
139 } 144 }
140 return false; 145 return false;
@@ -20,10 +20,10 @@ namespace DmpMapping @@ -20,10 +20,10 @@ namespace DmpMapping
20 { 20 {
21 typedef std::map<std::string, std::shared_ptr<DmpProject>> ProjectMap; 21 typedef std::map<std::string, std::shared_ptr<DmpProject>> ProjectMap;
22 22
23 - bool loadService(const DmpServerContext &context,ProjectMap& vectorMappingProjects, const char* data); 23 + bool loadService(const DmpServerContext &context,ProjectMap& vectorMappingProjects);
24 24
25 25
26 - bool editService(const DmpServerContext &context,ProjectMap& vectorMappingProjects, const char* data); 26 + bool editService(const DmpServerContext &context,ProjectMap& vectorMappingProjects);
27 27
28 } 28 }
29 29
@@ -18,6 +18,7 @@ @@ -18,6 +18,7 @@
18 #include "dmplogger.h" 18 #include "dmplogger.h"
19 #include "../wms/dmpwmsgetmap.h" 19 #include "../wms/dmpwmsgetmap.h"
20 #include "dmpmapping.h" 20 #include "dmpmapping.h"
  21 +#include "dmpmappingparameters.h"
21 using namespace std; 22 using namespace std;
22 23
23 namespace DmpMapping 24 namespace DmpMapping
@@ -32,14 +33,24 @@ namespace DmpMapping @@ -32,14 +33,24 @@ namespace DmpMapping
32 LOGGER_DEBUG("Destructing WmsService"); 33 LOGGER_DEBUG("Destructing WmsService");
33 } 34 }
34 35
35 - void DmpMappingService::executeRequest(const DmpServerContext &context) 36 + void DmpMappingService::executeRequest(const DmpServerContext &context)
36 { 37 {
37 - LOGGER_DEBUG("Destructing WmsService");  
38 -  
39 - const char* data = (char*)(context.request()->GetData());  
40 -  
41 -  
42 - 38 + const DmpMappingParameters params(context.request()->serverParameters());
  39 + //const DmpProject *project = context.serverProject()->project();
  40 + //
  41 + const std::string request = params.Request();
  42 + if (request.empty())
  43 + {
  44 + context.response()->writeHtml("wms,Operation is null");
  45 + }
  46 + else if (boost::iequals(request, "loadService"))
  47 + {
  48 + loadService(context, vectorMappingProjects_);
  49 + }
  50 + else if (boost::iequals(request, "getmap"))
  51 + {
  52 + DmpWms::writeGetMap(context, params, nullptr);
  53 + }
43 } 54 }
44 } 55 }
45 56
  1 +/**************************************************************************
  2 +* file: dmpmappingparameters.cpp
  3 +
  4 +* Author: qingxiongf
  5 +* Date: 2021-12-30 15:58:05
  6 +* Email: qingxiongf@chinadci.com
  7 +* copyright: 广州城市信息研究所有限公司
  8 +***************************************************************************/
  9 +#include <iostream>
  10 +#include "dmpmappingparameters.h"
  11 +#include <boost/lexical_cast.hpp>
  12 +#include <boost/algorithm/string.hpp>
  13 +#include "dmplogger.h"
  14 +#include "dmpserverutils.h"
  15 +
  16 +namespace DmpMapping
  17 +{
  18 + DmpMappingParameters::DmpMappingParameters()
  19 + : DmpServerParameters()
  20 + {
  21 + }
  22 +
  23 + DmpMappingParameters::DmpMappingParameters(const DmpServerParameters &params)
  24 + {
  25 + params_ = params.parameters();
  26 + }
  27 +
  28 + bool DmpMappingParameters::GetStringParameter(const char* key, std::string &value) const
  29 + {
  30 + std::map<std::string, std::string>::const_iterator iter;
  31 + iter = params_.find(key);
  32 + if (iter != params_.end())
  33 + {
  34 + try
  35 + {
  36 + value = boost::lexical_cast<std::string>(iter->second);
  37 + return true;
  38 + }
  39 + catch (boost::bad_lexical_cast &e)
  40 + {
  41 + LOGGER_ERROR(e.what());
  42 + }
  43 + }
  44 + return false;
  45 + }
  46 +
  47 + bool DmpMappingParameters::GetIntParameter(const char* key, int& value) const
  48 + {
  49 + std::map<std::string, std::string>::const_iterator iter;
  50 + iter = params_.find(key);
  51 + if (iter != params_.end())
  52 + {
  53 + try
  54 + {
  55 + value= boost::lexical_cast<int>(iter->second);
  56 + return true;
  57 + }
  58 + catch (boost::bad_lexical_cast &e)
  59 + {
  60 + LOGGER_ERROR(e.what());
  61 + }
  62 + }
  63 + return false;
  64 + }
  65 +
  66 +
  67 + std::string DmpMappingParameters::Service() const
  68 + {
  69 + std::string value = "WMS";
  70 + this->GetStringParameter("SERVICE", value);
  71 + return value;
  72 + }
  73 +
  74 + //必须 值为GetMap GetCapabilities GetFeatureInfo GetFeatureInfo GetLegendGraphic
  75 + std::string DmpMappingParameters::Request() const
  76 + {
  77 + std::string value = "";
  78 + GetStringParameter("REQUEST",value);
  79 + return value;
  80 + }
  81 +
  82 +
  83 + std::string DmpMappingParameters::Version() const
  84 + {
  85 + std::string value = "";
  86 + GetStringParameter("VERSION",value);
  87 + return value;
  88 + }
  89 +
  90 +} // namespace DmpWms
  1 +/**************************************************************************
  2 +* file: dmpmappingparameters.h
  3 +
  4 +* Author: qingxiongf
  5 +* Date: 2021-12-30 15:58:01
  6 +* Email: qingxiongf@chinadci.com
  7 +* copyright: 广州城市信息研究所有限公司
  8 +***************************************************************************/
  9 +
  10 +#ifndef __dmpmappingparameters_h__
  11 +#define __dmpmappingparameters_h__
  12 +#include "dmpserverparameters.h"
  13 +
  14 +namespace DmpMapping
  15 +{
  16 + class DmpMappingParameters : public DmpServerParameters
  17 + {
  18 + public:
  19 + DmpMappingParameters(const DmpServerParameters &parameters);
  20 + DmpMappingParameters();
  21 + virtual ~DmpMappingParameters() = default;
  22 + std::string Service() const; //必须 值为WMS
  23 + std::string Request() const; //必须 值为GetMap GetCapabilities GetFeatureInfo GetFeatureInfo GetLegendGraphic
  24 + std::string Version() const; //必须 服务版本, 值为 1.0.0, 1.1.0, 1.1.1, 1.3
  25 +
  26 + private:
  27 + bool GetStringParameter(const char* key, std::string &value) const;
  28 + bool GetIntParameter(const char* key, int& value) const;
  29 +
  30 +
  31 +
  32 + };
  33 +}
  34 +
  35 +#endif // __dmpmappingparameters_h__
注册登录 后发表评论