提交 119b91d3d653356c98aac2f2217cad44a1f0c6fd

作者 qingxiongf
2 个父辈 436203fe 4d0c0f98

在线配图

@@ -26,6 +26,7 @@ @@ -26,6 +26,7 @@
26 #include <boost/format.hpp> 26 #include <boost/format.hpp>
27 #include "dmpapplication.h" 27 #include "dmpapplication.h"
28 28
  29 +using namespace boost::placeholders;
29 namespace logging = boost::log; 30 namespace logging = boost::log;
30 namespace src = boost::log::sources; 31 namespace src = boost::log::sources;
31 namespace expr = boost::log::expressions; 32 namespace expr = boost::log::expressions;
1 -/**************************************************************************  
2 -* file: dmpmanagerapihandler.cpp  
3 -  
4 -* Author: wanzhongping  
5 -* Date: 2021-07-15 14:46:40  
6 -* Email: zhongpingw@chinadci.com  
7 -* copyright: 广州城市信息研究所有限公司  
8 -***************************************************************************/  
9 -#include <iostream>  
10 -#include <boost/json.hpp>  
11 -#include <boost/property_tree/ptree.hpp>  
12 -#include <boost/property_tree/json_parser.hpp>  
13 -#include <boost/property_tree/xml_parser.hpp>  
14 -#include <boost/foreach.hpp>  
15 -#include <boost/lexical_cast.hpp>  
16 -#include <boost/algorithm/string.hpp>  
17 -#include <boost/date_time.hpp>  
18 -  
19 -#include "dmpmanagerapihandler.h"  
20 -#include "dmpserverrequest.h"  
21 -#include "dmpserverresponse.h"  
22 -#include "dmpapiparameters.h"  
23 -#include "dmplogger.h"  
24 -#include "dmpapiutils.h"  
25 -#include "dmpservermanager.h"  
26 -#include "dmpserverutils.h"  
27 -  
28 -DmpManagerApiHandler::DmpManagerApiHandler()  
29 -{  
30 -  
31 -}  
32 -  
33 -void DmpManagerApiHandler::HandleRequest(const DmpServerApiContext &context) const  
34 -{  
35 - if (OperationId().compare("regservice") == 0) {  
36 - regService(context);  
37 - }  
38 - else if (OperationId().compare("startservice") == 0) {  
39 - startService(context);  
40 - }  
41 - else if (OperationId().compare("stopservice") == 0) {  
42 - stopService(context);  
43 - }  
44 - else if(OperationId().compare("regtileservice") == 0) {  
45 - RegTileService(context);  
46 - }  
47 - else if(OperationId().compare("getservicelist") == 0) {  
48 - GetServiceList(context);  
49 - }  
50 - else if(OperationId().compare("getservicedetail") == 0) {  
51 - GetServiceDetail(context);  
52 - }  
53 - else if(OperationId().compare("getcapabilities") == 0) {  
54 - getCapabilities(context);  
55 - }  
56 - else if(OperationId().compare("updateservice") == 0) {  
57 - UpdateService(context);  
58 - }  
59 - else if(OperationId().compare("deleteservice") == 0) {  
60 - deleteService(context);  
61 - }  
62 - else if(OperationId().compare("gettileserviceinfo") == 0) {  
63 - GetTileServiceInfo(context);  
64 - }  
65 - else if(OperationId().compare("addcatalog") == 0) {  
66 - AddCatalog(context);  
67 - }  
68 - else if(OperationId().compare("deletecatalog") == 0) {  
69 - DeleteCatalog(context);  
70 - }  
71 - else if(OperationId().compare("getservicesmatrixsets") == 0) {  
72 - GetServicesMatrixSets(context);  
73 - }  
74 - else if(OperationId().compare("deletecache") == 0) {  
75 - DeleteCache(context);  
76 - }  
77 - else if(OperationId().compare("updatecache") == 0) {  
78 - UpdateCache(context);  
79 - }  
80 - else if(OperationId().compare("reloadservices") == 0) {  
81 - reloadServices(context);  
82 - }  
83 - else {  
84 - context.response()->write("not find oparation: " + OperationId());  
85 - }  
86 -}  
87 -void DmpManagerApiHandler::regService(const DmpServerApiContext &context) const  
88 -{  
89 - switch (context.request()->method())  
90 - {  
91 - case DmpServerRequest::Method::GET_METHOD:  
92 - {  
93 - context.response()->write("{\"status\":\"true\",\"message\":\"服务发布测试——————GET\"}");  
94 - break;  
95 - }  
96 - case DmpServerRequest::Method::POST_METHOD:  
97 - {  
98 - std::string name;  
99 - std::string title;  
100 - int capabilities;  
101 - std::string serverType;  
102 - std::string project;  
103 - const char* data = (char*)(context.request()->GetData());  
104 - if(data && *data != '\0')  
105 - {  
106 - try  
107 - {  
108 - std::stringstream stream(data);  
109 - boost::property_tree::ptree pt;  
110 - boost::property_tree::read_json(stream, pt);  
111 -  
112 - name = pt.get<std::string>("name");  
113 - title = pt.get<std::string>("title");  
114 - capabilities = pt.get<int>("capabilities");  
115 - serverType = pt.get<std::string>("type");  
116 - project = pt.get<std::string>("project");  
117 - }  
118 - catch (boost::property_tree::ptree_bad_path& e) {  
119 - LOGGER_ERROR(e.what());  
120 - context.response()->write("{\"status\":\"false\",\"message\":\"服务发布失败\"}");  
121 - return;  
122 - }  
123 - catch (boost::property_tree::ptree_bad_data& e) {  
124 - LOGGER_ERROR(e.what());  
125 - context.response()->write("{\"status\":\"false\",\"message\":\"服务发布失败\"}");  
126 - return;  
127 - }  
128 - if(context.manager()->publish(serverType, name, title, capabilities, project)) {  
129 - LOGGER_INFO("服务发布成功");  
130 - context.response()->write("{\"status\":\"true\",\"message\":\"Pulish service successful!\"}");  
131 - // std::string projData;  
132 - // DmpServerUtils::Base64Decode(project, &projData);  
133 - // context.response()->removeHeader("Content-Type");  
134 - // context.response()->setHeader("Content-Type", "text/xml;charset=utf-8");  
135 - // context.response()->write(projData);  
136 - }  
137 - else  
138 - {  
139 - LOGGER_ERROR("服务发布失败");  
140 - context.response()->write("{\"status\":\"false\",\"message\":\"Pulish service fail!\"}");  
141 - }  
142 - }  
143 - else  
144 - {  
145 - LOGGER_ERROR("POST数据为空");  
146 - context.response()->write("{\"status\":\"false\",\"message\":\"Pulish service fail!\"}");  
147 - return;  
148 - }  
149 - break;  
150 -  
151 - }  
152 - default:  
153 - {  
154 -  
155 - }  
156 - }  
157 -}  
158 -  
159 -void DmpManagerApiHandler::startService(const DmpServerApiContext &context) const  
160 -{  
161 - switch (context.request()->method())  
162 - {  
163 - case DmpServerRequest::Method::GET_METHOD:  
164 - {  
165 - DmpServerParameters params = context.request()->serverParameters();  
166 - std::string serverName;  
167 - params.getValue("servername", serverName);  
168 - std::string serviceName;  
169 - params.getValue("servicename",serviceName);  
170 - context.manager()->startService(serverName, serviceName);  
171 - break;  
172 - }  
173 - case DmpServerRequest::Method::POST_METHOD:  
174 - {  
175 - context.response()->write("{\"status\":\"true\",\"message\":\"服务删除——————POST\"}");  
176 - break;  
177 - }  
178 - default:  
179 - {  
180 -  
181 - }  
182 - }  
183 -}  
184 -void DmpManagerApiHandler::stopService(const DmpServerApiContext &context) const  
185 -{  
186 - switch (context.request()->method())  
187 - {  
188 - case DmpServerRequest::Method::GET_METHOD:  
189 - {  
190 - DmpServerParameters params = context.request()->serverParameters();  
191 - std::string serverName;  
192 - params.getValue("servername", serverName);  
193 - std::string serviceName;  
194 - params.getValue("servicename",serviceName);  
195 - context.manager()->stopService(serverName, serviceName);  
196 - break;  
197 - }  
198 - case DmpServerRequest::Method::POST_METHOD:  
199 - {  
200 - context.response()->write("{\"status\":\"true\",\"message\":\"服务删除——————POST\"}");  
201 - break;  
202 - }  
203 - default:  
204 - {  
205 -  
206 - }  
207 - }  
208 -}  
209 -void DmpManagerApiHandler::RegTileService(const DmpServerApiContext &context) const  
210 -{  
211 - switch (context.request()->method())  
212 - {  
213 - case DmpServerRequest::Method::GET_METHOD:  
214 - {  
215 - context.response()->write("{\"status\":\"true\",\"message\":\"切片服务发布测试——————GET\"}");  
216 - break;  
217 - }  
218 - case DmpServerRequest::Method::POST_METHOD:  
219 - {  
220 - context.response()->write("{\"status\":\"true\",\"message\":\"切片服务发布测试——————POST\"}");  
221 - break;  
222 - }  
223 - default:  
224 - {  
225 -  
226 - }  
227 - }  
228 -}  
229 -void DmpManagerApiHandler::GetServiceList(const DmpServerApiContext &context) const  
230 -{  
231 -}  
232 -  
233 -void DmpManagerApiHandler::GetServiceDetail(const DmpServerApiContext &context) const  
234 -{  
235 -}  
236 -  
237 -void DmpManagerApiHandler::UpdateService(const DmpServerApiContext &context) const  
238 -{  
239 - switch (context.request()->method())  
240 - {  
241 - case DmpServerRequest::Method::GET_METHOD:  
242 - {  
243 - context.response()->write("{\"status\":\"true\",\"message\":\"更新服务信息——————GET\"}");  
244 - break;  
245 - }  
246 - case DmpServerRequest::Method::POST_METHOD:  
247 - {  
248 - context.response()->write("{\"status\":\"true\",\"message\":\"更新服务信息——————POST\"}");  
249 - break;  
250 - }  
251 - default:  
252 - {  
253 -  
254 - }  
255 - }  
256 -}  
257 -  
258 -void DmpManagerApiHandler::deleteService(const DmpServerApiContext &context) const  
259 -{  
260 - switch (context.request()->method())  
261 - {  
262 - case DmpServerRequest::Method::GET_METHOD:  
263 - {  
264 - DmpServerParameters params = context.request()->serverParameters();  
265 - std::string serverName;  
266 - params.getValue("servername", serverName);  
267 - std::string serviceName;  
268 - params.getValue("servicename",serviceName);  
269 - if(context.manager()->deleteService(serverName, serviceName)) {  
270 - context.response()->write("{\"status\":\"true\",\"message\":\"删除服务成功\"}");  
271 - }else{  
272 - context.response()->write("{\"status\":\"false\",\"message\":\"删除服务失败\"}");  
273 - }  
274 - break;  
275 - }  
276 - case DmpServerRequest::Method::POST_METHOD:  
277 - {  
278 - context.response()->write("{\"status\":\"true\",\"message\":\"服务删除——————POST\"}");  
279 - break;  
280 - }  
281 - default:  
282 - {  
283 -  
284 - }  
285 - }  
286 -}  
287 -  
288 -//获取配置文件切片信息  
289 -void DmpManagerApiHandler::GetTileServiceInfo(const DmpServerApiContext &context) const  
290 -{  
291 - switch (context.request()->method())  
292 - {  
293 - case DmpServerRequest::Method::GET_METHOD:  
294 - {  
295 - context.response()->write("{\"status\":\"true\",\"message\":\"获取切片配置信息——————GET\"}");  
296 - break;  
297 - }  
298 - case DmpServerRequest::Method::POST_METHOD:  
299 - {  
300 - std::string path;  
301 - std::string strExtent;  
302 - const char* data = (char*)(context.request()->GetData());  
303 - if(data && *data != '\0')  
304 - {  
305 - try  
306 - {  
307 - std::stringstream stream(data);  
308 - boost::property_tree::ptree pt;  
309 - boost::property_tree::ptree pt_json;  
310 - std::string confcdipath;  
311 - std::string confxmlpath;  
312 -  
313 - boost::property_tree::read_json(stream, pt);  
314 - path= pt.get<std::string>("projectlayers.maplayer.datasource");  
315 - confcdipath=path+"/conf.cdi";  
316 - confxmlpath=path+"/conf.xml";  
317 - //读取切片配置文件conf.cdi  
318 - boost::property_tree::ptree pt_confcdi;  
319 - boost::property_tree::read_xml(confcdipath,pt_confcdi);  
320 - //boost::property_tree::ptree pt_base=pt.get_child("base");  
321 - std::string xmin=pt_confcdi.get<std::string>("EnvelopeN.XMin");  
322 - std::string ymin=pt_confcdi.get<std::string>("EnvelopeN.YMin");  
323 - std::string xmax=pt_confcdi.get<std::string>("EnvelopeN.XMax");  
324 - std::string ymax=pt_confcdi.get<std::string>("EnvelopeN.YMax");  
325 - pt.put("projectlayers.maplayer.extent.xmin",xmin);  
326 - pt.put("projectlayers.maplayer.extent.ymin",ymin);  
327 - pt.put("projectlayers.maplayer.extent.xmax",xmax);  
328 - pt.put("projectlayers.maplayer.extent.ymax",ymax);  
329 - //读取配置文件conf.xml  
330 - boost::property_tree::ptree pt_confxml;  
331 - boost::property_tree::read_xml(confxmlpath,pt_confxml);  
332 - std::string strWKT=pt_confxml.get<std::string>("CacheInfo.TileCacheInfo.SpatialReference.WKT");  
333 - std::string wkid=pt_confxml.get<std::string>("CacheInfo.TileCacheInfo.SpatialReference.WKID");  
334 - std::string top=pt_confxml.get<std::string>("CacheInfo.TileCacheInfo.TileOrigin.X");  
335 - std::string left=pt_confxml.get<std::string>("CacheInfo.TileCacheInfo.TileOrigin.Y");  
336 - std::string tileCols=pt_confxml.get<std::string>("CacheInfo.TileCacheInfo.TileCols");  
337 - std::string tileRows=pt_confxml.get<std::string>("CacheInfo.TileCacheInfo.TileRows");  
338 - std::string dpi=pt_confxml.get<std::string>("CacheInfo.TileCacheInfo.DPI");  
339 - pt.put("projectCrs.spatialrefsys.wkt",strWKT);  
340 - pt.put("projectCrs.spatialrefsys.srid",wkid);  
341 -  
342 - boost::property_tree::ptree pt_tileMatrixSets=pt.get_child("tileMatrixSets");  
343 - BOOST_FOREACH(boost::property_tree::ptree::value_type &v1,pt_tileMatrixSets)  
344 - {  
345 - //conf.xml中读取tileinfo  
346 - boost::property_tree::ptree pt_levels,pt_tileMatrixSet;  
347 - boost::property_tree::ptree pt_tileArry=pt_confxml.get_child("CacheInfo.TileCacheInfo.LODInfos");  
348 - BOOST_FOREACH(boost::property_tree::ptree::value_type &v2,pt_tileArry)  
349 - {  
350 - boost::property_tree::ptree pt_level;  
351 - if(v2.first=="LODInfo")  
352 - {  
353 - std::string level=v2.second.get<std::string>("LevelID");  
354 - std::string scale=v2.second.get<std::string>("Scale");  
355 - std::string resolution=v2.second.get<std::string>("Resolution");  
356 - pt_level.add("level.id",level);  
357 - pt_level.add("level.scaleDenominator",scale);  
358 - pt_level.add("level.resolution",resolution);  
359 - pt_levels.push_back(std::make_pair("", pt_level));  
360 - }  
361 - }  
362 - std::string id_=v1.second.get<std::string>("tileMatrixSet.id");  
363 - pt_tileMatrixSet.add("id",id_);  
364 - pt_tileMatrixSet.add("crs","EPSG::"+wkid);  
365 - pt_tileMatrixSet.add("tileCols",tileCols);  
366 - pt_tileMatrixSet.add("tileRows",tileRows);  
367 - pt_tileMatrixSet.add("dpi",dpi);  
368 - pt_tileMatrixSet.add("tileOrigin.X",top);  
369 - pt_tileMatrixSet.add("tileOrigin.Y",left);  
370 - pt_tileMatrixSet.add_child("levels",pt_levels);  
371 - //pt_tilelist.add_child("tileMatrixList",pt_tiles);  
372 - v1.second.put_child("tileMatrixSet",pt_tileMatrixSet);  
373 - //v1.second.put("id","EPSG::"+wkid);  
374 - }  
375 -  
376 - pt.put_child("tileMatrixSets",pt_tileMatrixSets);  
377 - std::stringstream ss;  
378 - boost::property_tree::write_json(ss,pt);  
379 - strExtent=ss.str();  
380 - }  
381 - catch (boost::property_tree::ptree_bad_path& e) {  
382 - LOGGER_ERROR(e.what());  
383 - context.response()->write("{\"status\":\"false\",\"message\":\"获取切片配置信息失败\"}");  
384 - return;  
385 - }  
386 - catch (boost::property_tree::ptree_bad_data& e) {  
387 - LOGGER_ERROR(e.what());  
388 - context.response()->write("{\"status\":\"false\",\"message\":\"获取切片配置信息失败\"}");  
389 - return;  
390 - }  
391 - context.response()->write(strExtent);  
392 - }  
393 - break;  
394 - }  
395 - default:  
396 - {  
397 -  
398 - }  
399 - }  
400 -}  
401 -  
402 -//判断服务是否存在  
403 -void DmpManagerApiHandler::IsExistServiceName(const DmpServerApiContext &context) const  
404 -{  
405 - switch (context.request()->method())  
406 - {  
407 - case DmpServerRequest::Method::GET_METHOD:  
408 - {  
409 - context.response()->write("{\"status\":\"true\",\"message\":\"——————GET\"}");  
410 - break;  
411 - }  
412 - case DmpServerRequest::Method::POST_METHOD:  
413 - {  
414 - context.response()->write("{\"status\":\"true\",\"message\":\"——————POST\"}");  
415 - break;  
416 - }  
417 - default:  
418 - {  
419 -  
420 - }  
421 - }  
422 -}  
423 -  
424 -//新增目录  
425 -void DmpManagerApiHandler::AddCatalog(const DmpServerApiContext &context) const  
426 -{  
427 - switch (context.request()->method())  
428 - {  
429 - case DmpServerRequest::Method::GET_METHOD:  
430 - {  
431 - context.response()->write("{\"status\":\"true\",\"message\":\"新增目录——————GET\"}");  
432 - break;  
433 - }  
434 - case DmpServerRequest::Method::POST_METHOD:  
435 - {  
436 - context.response()->write("{\"status\":\"true\",\"message\":\"新增目录——————POST\"}");  
437 - break;  
438 - }  
439 - default:  
440 - {  
441 -  
442 - }  
443 - }  
444 -}  
445 -  
446 -//删除目录  
447 -void DmpManagerApiHandler::DeleteCatalog(const DmpServerApiContext &context) const  
448 -{  
449 - switch (context.request()->method())  
450 - {  
451 - case DmpServerRequest::Method::GET_METHOD:  
452 - {  
453 - context.response()->write("{\"status\":\"true\",\"message\":\"删除目录——————GET\"}");  
454 - break;  
455 - }  
456 - case DmpServerRequest::Method::POST_METHOD:  
457 - {  
458 - context.response()->write("{\"status\":\"true\",\"message\":\"删除目录——————POST\"}");  
459 - break;  
460 - }  
461 - default:  
462 - {  
463 -  
464 - }  
465 - }  
466 -}  
467 -  
468 -void DmpManagerApiHandler::GetServicesMatrixSets(const DmpServerApiContext &context) const  
469 -{  
470 - switch (context.request()->method())  
471 - {  
472 - case DmpServerRequest::Method::GET_METHOD:  
473 - {  
474 - context.response()->write("{\"status\":\"true\",\"message\":\"删除目录——————GET\"}");  
475 - break;  
476 - }  
477 - case DmpServerRequest::Method::POST_METHOD:  
478 - {  
479 - context.response()->write("{\"status\":\"true\",\"message\":\"删除目录——————POST\"}");  
480 - break;  
481 - }  
482 - default:  
483 - {  
484 -  
485 - }  
486 - }  
487 -}  
488 -void DmpManagerApiHandler::GetCatalogList(const DmpServerApiContext &context) const  
489 -{  
490 - switch (context.request()->method())  
491 - {  
492 - case DmpServerRequest::Method::GET_METHOD:  
493 - {  
494 - context.response()->write("{\"status\":\"true\",\"message\":\"获取目录列表——————GET\"}");  
495 - break;  
496 - }  
497 - case DmpServerRequest::Method::POST_METHOD:  
498 - {  
499 - context.response()->write("{\"status\":\"true\",\"message\":\"获取目录列表——————POST\"}");  
500 - break;  
501 - }  
502 - default:  
503 - {  
504 -  
505 - }  
506 - }  
507 -}  
508 -void DmpManagerApiHandler::UpdateCache(const DmpServerApiContext &context)const  
509 -{  
510 - switch (context.request()->method())  
511 - {  
512 - case DmpServerRequest::Method::GET_METHOD:  
513 - {  
514 - std::string serviceName_;  
515 - const DmpServerParameters params_ (context.request()->serverParameters());  
516 - CIMap paramsMap=params_.parameters();  
517 - std::map<std::string, std::string>::const_iterator iter;  
518 - iter =paramsMap.find("SERVICENAME");  
519 - if (iter != paramsMap.end())  
520 - {  
521 - try  
522 - {  
523 - serviceName_ = boost::lexical_cast<std::string>(iter->second);  
524 - }  
525 - catch (boost::bad_lexical_cast &e)  
526 - {  
527 - LOGGER_ERROR(e.what());  
528 - context.response()->write("{\"status\":\"true\",\"message\":\"获取参数信息错误——————GET\"}");  
529 - return;  
530 - }  
531 - }  
532 -  
533 - break;  
534 - }  
535 - case DmpServerRequest::Method::POST_METHOD:  
536 - {  
537 - context.response()->write("{\"status\":\"true\",\"message\":\"更新缓存——————POST\"}");  
538 - break;  
539 - }  
540 - default:  
541 - {  
542 -  
543 - }  
544 - }  
545 -}  
546 -void DmpManagerApiHandler::DeleteCache(const DmpServerApiContext &context)const  
547 -{  
548 - switch (context.request()->method())  
549 - {  
550 - case DmpServerRequest::Method::GET_METHOD:  
551 - {  
552 - std::string serviceName_;  
553 - const DmpServerParameters params_ (context.request()->serverParameters());  
554 - CIMap paramsMap=params_.parameters();  
555 - std::map<std::string, std::string>::const_iterator iter;  
556 - iter =paramsMap.find("SERVICENAME");  
557 - if (iter != paramsMap.end())  
558 - {  
559 - try  
560 - {  
561 - serviceName_ = boost::lexical_cast<std::string>(iter->second);  
562 - }  
563 - catch (boost::bad_lexical_cast &e)  
564 - {  
565 - LOGGER_ERROR(e.what());  
566 - context.response()->write("{\"status\":\"true\",\"message\":\"获取参数信息错误——————GET\"}");  
567 - return;  
568 - }  
569 - }  
570 -  
571 - break;  
572 - }  
573 - case DmpServerRequest::Method::POST_METHOD:  
574 - {  
575 - context.response()->write("{\"status\":\"true\",\"message\":\"删除缓存——————POST\"}");  
576 - break;  
577 - }  
578 - default:  
579 - {  
580 -  
581 - }  
582 - }  
583 -}  
584 -  
585 -void DmpManagerApiHandler::getCapabilities(const DmpServerApiContext &context) const  
586 -{  
587 - std::string strJson = context.manager()->getCapabilities();  
588 - context.response()->write(strJson);  
589 -}  
590 -void DmpManagerApiHandler::reloadServices(const DmpServerApiContext &context) const  
591 -{  
592 - switch (context.request()->method())  
593 - {  
594 - case DmpServerRequest::Method::GET_METHOD:  
595 - {  
596 - if(context.manager()->loadServices()) {  
597 - context.response()->write("{\"status\":\"true\",\"message\":\"重载服务成功\"}");  
598 - }else{  
599 - context.response()->write("{\"status\":\"false\",\"message\":\"重载服务失败\"}");  
600 - }  
601 - break;  
602 -  
603 - }  
604 - case DmpServerRequest::Method::POST_METHOD:  
605 - {  
606 - context.response()->write("{\"status\":\"true\",\"message\":\"服务重载——————POST\"}");  
607 - break;  
608 - }  
609 - default:  
610 - {  
611 -  
612 - }  
613 - }  
614 -}  
@@ -102,8 +102,38 @@ void DmpManagerApiHandler::regService(const DmpServerApiContext &context) const @@ -102,8 +102,38 @@ void DmpManagerApiHandler::regService(const DmpServerApiContext &context) const
102 LOGGER_INFO("服务发布成功"); 102 LOGGER_INFO("服务发布成功");
103 std::string url; 103 std::string url;
104 std::string http="http://"+context.request()->domain()+":"+context.request()->port(); 104 std::string http="http://"+context.request()->domain()+":"+context.request()->port();
105 -  
106 - url=http+"/DMap/Services/"+name+"/TileServer/tmsService?REQUEST=GetThumbnail"; 105 + switch (capabilities)
  106 + {
  107 + case 1:
  108 + {
  109 + url=http+"/DMap/Services/"+name+"/"+serverType+"/WmtsService?REQUEST=GetThumbnail";
  110 + break;
  111 + }
  112 + case 2:
  113 + {
  114 + url=http+"/DMap/Services/"+name+"/"+serverType+"/WmsService?REQUEST=GetThumbnail";
  115 + break;
  116 + }
  117 + case 4:
  118 + {
  119 + url=http+"/DMap/Services/"+name+"/"+serverType+"/WfsService?REQUEST=GetThumbnail";
  120 + break;
  121 + }
  122 + case 8:
  123 + {
  124 + url=http+"/DMap/Services/"+name+"/"+serverType+"/WpsService?REQUEST=GetThumbnail";
  125 + break;
  126 + }
  127 + case 16:
  128 + {
  129 + url=http+"/DMap/Services/"+name+"/"+serverType+"/tmsService?REQUEST=GetThumbnail";
  130 + break;
  131 + }
  132 +
  133 + default:
  134 + break;
  135 + }
  136 +
107 context.response()->write("{\"status\":\""+std::to_string(flag)+"\",\"url\":\""+url+"\",\"message\":\"Pulish service successful!\"}"); 137 context.response()->write("{\"status\":\""+std::to_string(flag)+"\",\"url\":\""+url+"\",\"message\":\"Pulish service successful!\"}");
108 // std::string projData; 138 // std::string projData;
109 // DmpServerUtils::Base64Decode(project, &projData); 139 // DmpServerUtils::Base64Decode(project, &projData);
@@ -43,4 +43,105 @@ namespace DmpTms @@ -43,4 +43,105 @@ namespace DmpTms
43 } 43 }
44 fread.close(); 44 fread.close();
45 } 45 }
  46 +
  47 + void DmpTmsTileProvider::GetTileThumbnail(DmpTileLayer* dmpTileLayer,DmpServerResponse& respons)
  48 + {
  49 + int tilematrix=0;
  50 + std::string tilePath=dmpTileLayer->getDataSource();
  51 +
  52 + //tilePath="/mnt/d/Code/tiles/qgis";
  53 + DmpRectangle rectangle=dmpTileLayer->extent();
  54 +
  55 + DmpPoint min=DmpPoint(rectangle.xmin(),rectangle.ymin());
  56 + DmpPoint max=DmpPoint(rectangle.xmax(),rectangle.ymax());
  57 + tilematrix=this->screenMatrixSet(min,max);
  58 + int xMinTile, yMinTile,xMaxTile,yMaxTile;
  59 + this->degToNum(tilematrix,min.x(),min.y(),xMinTile,yMinTile);
  60 + this->degToNum(tilematrix,max.x(),max.y(),xMaxTile,yMaxTile);
  61 + int heigth=abs(yMaxTile-yMinTile);
  62 + int width=abs(xMaxTile-xMinTile);
  63 +
  64 + cairo_surface_t *surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 256*(width+1), 256*(heigth+1));
  65 + cairo_t *cr =cairo_create (surface);
  66 + for( int i = 0 ; i <= width ; i++ )
  67 + {
  68 + for(int j=0;j<=heigth;j++)
  69 + {
  70 + std::string filepath=tilePath+"/"+std::to_string(tilematrix)+"/"+std::to_string(xMinTile+i)+"/"+std::to_string(yMaxTile+j)+".png";
  71 + cairo_surface_t* image = cairo_image_surface_create_from_png( filepath.c_str());
  72 + this->BufferCopy(image,surface,cr,i*256,j*256);
  73 + //cairo_surface_write_to_png (surface, "./tms.png");
  74 + //LOGGER_DEBUG(filepath);
  75 + }
  76 + }
  77 + //cairo_surface_write_to_png (surface, "./tms.png");
  78 + std::string responseData;
  79 + cairo_surface_write_to_png_stream(surface, cairo_write_func, &responseData);
  80 + respons.removeHeader("Content-Type");
  81 + respons.setHeader("Content-Type", "image/png");
  82 + respons.write(responseData);
  83 + cairo_destroy (cr);
  84 + cairo_surface_destroy (surface);
  85 + }
  86 + //经纬度到瓦片
  87 + void DmpTmsTileProvider::degToNum(int zoom, double lon_deg, double lat_deg,int& x,int& y)
  88 + {
  89 + double n = pow(2.0, zoom);
  90 + double xtile = n * ((lon_deg + 180) / 360);
  91 + //角度转弧度
  92 + double lat_rad = lat_deg * RAD2DEG;
  93 + double ytile = n * (1 - (log(tan(lat_rad) + (1 / cos(lat_rad))) / pi)) / 2;
  94 +
  95 + x = (int)floor(xtile);
  96 + y = (int)floor(ytile);
  97 + }
  98 + //瓦片到经纬度
  99 + // double* DmpTmsTileProvider::numToDeg(int zoom, int xtile, int ytile)
  100 + // {
  101 + // double n = pow(2.0, zoom);
  102 + // double lon_deg = double(xtile) / n * 360.0 - 180.0;
  103 + // double lat_rad = atan(sinh(pi * (1 - 2 * ytile / n)));
  104 + // double lat_deg = lat_rad * 180.0 / pi;
  105 + // double lonlat[2] = {};
  106 + // lonlat[0] = lon_deg;
  107 + // lonlat[1] = lat_deg;
  108 + // return lonlat;
  109 + // }
  110 + bool DmpTmsTileProvider::BufferCopy(cairo_surface_t *pClsCSFrom, cairo_surface_t *pClsCSTo, cairo_t *cr,int x,int y)
  111 + {
  112 + if (pClsCSFrom == NULL||pClsCSTo == NULL)
  113 + {
  114 + return false;
  115 + }
  116 + if(cr==NULL)
  117 + {
  118 + cr = cairo_create (pClsCSTo);
  119 + }
  120 + cairo_set_source_surface(cr, pClsCSFrom, x, y);
  121 + cairo_paint(cr);
  122 + return true;
  123 + }
  124 + cairo_status_t DmpTmsTileProvider::cairo_write_func(void *pbuff, const unsigned char *data, unsigned int length)
  125 + {
  126 + std::string *responseData = (std::string *)pbuff;
  127 + responseData->append((char *)data, length);
  128 + return CAIRO_STATUS_SUCCESS;
  129 + }
  130 + int DmpTmsTileProvider::screenMatrixSet(DmpPoint min,DmpPoint max)
  131 + {
  132 + int iMatrixSet=4;
  133 + for( ; iMatrixSet<=20 ; iMatrixSet++ )
  134 + {
  135 + int xMinTile, yMinTile,xMaxTile,yMaxTile;
  136 + this->degToNum(iMatrixSet,min.x(),min.y(),xMinTile,yMinTile);
  137 + this->degToNum(iMatrixSet,max.x(),max.y(),xMaxTile,yMaxTile);
  138 + int heigth=abs(yMaxTile-yMinTile);
  139 + int width=abs(xMaxTile-xMinTile);
  140 + if((heigth+1)*(width+1)<9 && (heigth+2)*(width+2)>10)
  141 + {
  142 + break;
  143 + }
  144 + }
  145 + return iMatrixSet;
  146 + }
46 } 147 }
@@ -53,7 +53,7 @@ namespace DmpWmts @@ -53,7 +53,7 @@ namespace DmpWmts
53 } 53 }
54 } 54 }
55 c = "C" + c; 55 c = "C" + c;
56 - 56 +
57 string bundlePath = rootPath_ + "/"+l+"/"+r+c; 57 string bundlePath = rootPath_ + "/"+l+"/"+r+c;
58 return bundlePath; 58 return bundlePath;
59 } 59 }
@@ -103,12 +103,34 @@ namespace DmpWmts @@ -103,12 +103,34 @@ namespace DmpWmts
103 response.sendError(500, "缩略图范围错误:("); 103 response.sendError(500, "缩略图范围错误:(");
104 return; 104 return;
105 } 105 }
106 - std::string buff;  
107 - GetTile(yMinTile,xMinTile,iLevel,buff,buffLen);  
108 - response.removeHeader("Content-Type");  
109 - std::string f = (format == "jpg") ? "image/jpg" : "image/png";  
110 - response.setHeader("Content-Type", f);  
111 - response.write(buff); 106 +
  107 +
  108 + int heigth=abs(yMaxTile-yMinTile);
  109 + int width=abs(xMaxTile-xMinTile);
  110 + cairo_surface_t *surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 256*(width+1), 256*(heigth+1));
  111 + cairo_t *cr =cairo_create (surface);
  112 + for( int i = 0 ; i <= width ; i++ )
  113 + {
  114 + for(int j=0;j<=heigth;j++)
  115 + {
  116 + std::string strBuff;
  117 + GetTile(yMaxTile+j,xMinTile+i,iLevel,strBuff,buffLen);
  118 + const char* buff=strBuff.c_str();
  119 + st_png_data pngData = {(unsigned char*)buff, 0};
  120 + cairo_surface_t *image = cairo_image_surface_create_from_png_stream(cairo_read_func,&pngData);
  121 + TileProviderFactory::BufferCopy(image,surface,cr,i*256,j*256);
  122 + //cairo_surface_write_to_png (surface, "./wmts.png");
  123 + }
  124 + }
  125 + std::string responseData;
  126 + cairo_surface_write_to_png_stream(surface, TileProviderFactory::cairo_write_func, &responseData);
  127 +
  128 + response.removeHeader("Content-Type");
  129 + std::string f = (format == "jpg") ? "image/jpg" : "image/png";
  130 + response.setHeader("Content-Type", f);
  131 + response.write(responseData);
  132 + cairo_destroy (cr);
  133 + cairo_surface_destroy (surface);
112 } 134 }
113 135
114 bool DmpEsriBundleV1Provider::GetTile(int row, int col, int level,std::string& refbuff,int& length ) 136 bool DmpEsriBundleV1Provider::GetTile(int row, int col, int level,std::string& refbuff,int& length )
@@ -118,7 +140,7 @@ namespace DmpWmts @@ -118,7 +140,7 @@ namespace DmpWmts
118 rGroup = rGroup * packSize; 140 rGroup = rGroup * packSize;
119 int cGroup = (int)col/packSize; 141 int cGroup = (int)col/packSize;
120 cGroup = cGroup*packSize; 142 cGroup = cGroup*packSize;
121 - rootPath_="/mnt/d/Code/tiles/gdmap/_alllayers"; 143 + //rootPath_="/mnt/d/Code/tiles/gdmap/_alllayers";
122 std::string bundleBase =GetBundlePath(level,rGroup,cGroup); 144 std::string bundleBase =GetBundlePath(level,rGroup,cGroup);
123 std::string bundleFilePath = bundleBase + ".bundle"; 145 std::string bundleFilePath = bundleBase + ".bundle";
124 std::string bundlxFilePath = bundleBase + ".bundlx"; 146 std::string bundlxFilePath = bundleBase + ".bundlx";
@@ -157,14 +179,14 @@ namespace DmpWmts @@ -157,14 +179,14 @@ namespace DmpWmts
157 + (long)(buff[3]&0xff) * 16777216; 179 + (long)(buff[3]&0xff) * 16777216;
158 delete[] buff; 180 delete[] buff;
159 char *imgBuffer = new char[length]; 181 char *imgBuffer = new char[length];
160 - fread.read(imgBuffer, length); 182 + fread.read(imgBuffer, length);
161 fread.close(); 183 fread.close();
  184 + refbuff.append(imgBuffer,length);
  185 + // const char* test=refbuff.c_str();
162 // cairo_surface_t *surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 256, 256); 186 // cairo_surface_t *surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 256, 256);
163 - // cairo_t *cr =cairo_create (surface);  
164 - // st_png_data* pPngData;  
165 - // pPngData->pdata=(unsigned char*)buff;  
166 - // pPngData->length=length;  
167 - // cairo_surface_t *image = cairo_image_surface_create_from_png_stream (cairo_read_func,&pPngData); 187 + // cairo_t *cr =cairo_create (surface);
  188 + // st_png_data pngData = {(unsigned char*)test, 0};
  189 + // cairo_surface_t *image = cairo_image_surface_create_from_png_stream(cairo_read_func,&pngData);
168 190
169 // TileProviderFactory::BufferCopy(image,surface,cr,0,0); 191 // TileProviderFactory::BufferCopy(image,surface,cr,0,0);
170 // cairo_surface_write_to_png (surface, "./wmts.png"); 192 // cairo_surface_write_to_png (surface, "./wmts.png");
@@ -174,11 +196,11 @@ namespace DmpWmts @@ -174,11 +196,11 @@ namespace DmpWmts
174 return true; 196 return true;
175 197
176 } 198 }
177 - // cairo_status_t cairo_read_func (void *closure, unsigned char *data, unsigned int length,DmpServerResponse& response)  
178 - // {  
179 - // st_png_data* pPngData = (st_png_data*)closure;  
180 - // memcpy(data, pPngData->pdata + pPngData->length, length);  
181 - // pPngData->length += length;  
182 - // return CAIRO_STATUS_SUCCESS;  
183 - // } 199 + cairo_status_t DmpEsriBundleV1Provider::cairo_read_func (void *closure, unsigned char *data, unsigned int length)
  200 + {
  201 + st_png_data* pPngData = (st_png_data*)closure;
  202 + memcpy(data, pPngData->pdata + pPngData->length, length);
  203 + pPngData->length += length;
  204 + return CAIRO_STATUS_SUCCESS;
  205 + }
184 } 206 }
@@ -22,13 +22,13 @@ namespace DmpWmts @@ -22,13 +22,13 @@ namespace DmpWmts
22 DmpEsriBundleV1Provider(const std::string& rootPath); 22 DmpEsriBundleV1Provider(const std::string& rootPath);
23 void WriteTile(const int row, const int col, const int level, const std::string& format, DmpServerResponse& response) override; 23 void WriteTile(const int row, const int col, const int level, const std::string& format, DmpServerResponse& response) override;
24 void GetTileThumbnail(DmpTileLayer* dmpTileLayer,DmpServerResponse& response) override; 24 void GetTileThumbnail(DmpTileLayer* dmpTileLayer,DmpServerResponse& response) override;
25 - bool GetTile(const int row,const int col,const int level,std::string& refbuff,int& length);  
26 - //static cairo_status_t cairo_read_func (void *closure, unsigned char *data, unsigned int length); 25 + bool GetTile(const int row,const int col,const int level,std::string& rebuff,int& length);
  26 + static cairo_status_t cairo_read_func (void *closure, unsigned char *data, unsigned int length);
27 }; 27 };
28 - // struct st_png_data  
29 - // {  
30 - // unsigned char* pdata;  
31 - // unsigned int length;  
32 - // }; 28 + struct st_png_data
  29 + {
  30 + unsigned char* pdata;
  31 + unsigned int length;
  32 + };
33 } 33 }
34 #endif //__dmpesribundlev1provider_h__ 34 #endif //__dmpesribundlev1provider_h__
@@ -31,7 +31,7 @@ namespace DmpWmts @@ -31,7 +31,7 @@ namespace DmpWmts
31 { 31 {
32 std::string tileVersion= dmpTileLayer->getVendor(); 32 std::string tileVersion= dmpTileLayer->getVendor();
33 std::string tilePath=dmpTileLayer->getDataSource(); 33 std::string tilePath=dmpTileLayer->getDataSource();
34 - //std::string tilePath_ = "/mnt/d/Code/tiles/gdmap/_alllayers"; 34 + //tilePath = "/mnt/d/Code/tiles/gdmap/_alllayers";
35 //std::string tileVersion_ = "ESRI_V1"; 35 //std::string tileVersion_ = "ESRI_V1";
36 int iver=StringToVector(tileVersion); 36 int iver=StringToVector(tileVersion);
37 Vendor version = (Vendor)boost::lexical_cast<int>(iver); 37 Vendor version = (Vendor)boost::lexical_cast<int>(iver);
@@ -151,4 +151,11 @@ namespace DmpWmts @@ -151,4 +151,11 @@ namespace DmpWmts
151 cairo_paint(cr); 151 cairo_paint(cr);
152 return true; 152 return true;
153 } 153 }
  154 + cairo_status_t TileProviderFactory::cairo_write_func(void *pbuff, const unsigned char *data, unsigned int length)
  155 + {
  156 + std::string *responseData = (std::string *)pbuff;
  157 + responseData->append((char *)data, length);
  158 + return CAIRO_STATUS_SUCCESS;
  159 + }
  160 +
154 } 161 }
@@ -42,11 +42,12 @@ namespace DmpWmts @@ -42,11 +42,12 @@ namespace DmpWmts
42 static int screenTileMatrix(DmpPoint& min,DmpPoint& max,std::vector<DmpTileMatrixSet*>& tileMatrixSets,double& resolution,DmpPoint& origin); 42 static int screenTileMatrix(DmpPoint& min,DmpPoint& max,std::vector<DmpTileMatrixSet*>& tileMatrixSets,double& resolution,DmpPoint& origin);
43 static void PointToRowCol(DmpPoint& point,DmpPoint& origin,double resolution,int& xTile,int& yTile); 43 static void PointToRowCol(DmpPoint& point,DmpPoint& origin,double resolution,int& xTile,int& yTile);
44 static bool GetTileScale(DmpTileLayer* dmpTileLayer,int& iLevel,int& xMinTile,int& yMinTile,int& xMaxTile,int& yMaxTile); 44 static bool GetTileScale(DmpTileLayer* dmpTileLayer,int& iLevel,int& xMinTile,int& yMinTile,int& xMaxTile,int& yMaxTile);
  45 + static cairo_status_t cairo_write_func(void *pbuff, const unsigned char *data, unsigned int length);
45 46
46 private: 47 private:
47 TileProviderFactory(); 48 TileProviderFactory();
48 }; 49 };
49 - 50 +
50 51
51 } 52 }
52 #endif //__dmptileproviderfactory_h__ 53 #endif //__dmptileproviderfactory_h__
注册登录 后发表评论