提交 eb7a673b01e8a43cc21bf1819a4b7a32857515e4

作者 LJH 李佳桓
1 个父辈 482512c7

ljh

... ... @@ -14,6 +14,7 @@ SET (TILESERVER_SRCS
14 14 # dmpwmtsservice.cpp
15 15 wmts/dmpwmtsutils.cpp
16 16 tms/dmptms.cpp
  17 + tms/dmptmstileprovider.cpp
17 18 )
18 19
19 20 SET (TILESERVER_HDRS
... ... @@ -30,6 +31,7 @@ SET (TILESERVER_HDRS
30 31 # dmpwmtsservice.h
31 32 wmts/dmpwmtsutils.h
32 33 tms/dmptms.h
  34 + tms/dmptmstileprovider.h
33 35 )
34 36 ########################################################
35 37 # Build
... ...
... ... @@ -6,10 +6,16 @@
6 6 * Email: zhongpingw@chinadci.com
7 7 * copyright: 广州城市信息研究所有限公司
8 8 ***************************************************************************/
  9 +#include <map>
9 10 #include "dmptms.h"
10 11 #include "dmptilelayer.h"
  12 +#include "dmpserverrequest.h"
  13 +#include "dmpserverresponse.h"
11 14 #include "dmpservercontext.h"
12 15 #include "dmplogger.h"
  16 +#include "dmptilelayer.h"
  17 +#include "dmpproject.h"
  18 +#include "dmptmstileprovider.h"
13 19
14 20 namespace DmpTms
15 21 {
... ... @@ -26,5 +32,54 @@ namespace DmpTms
26 32
27 33 void DmpTMSService::executeRequest(const DmpServerContext &context)
28 34 {
  35 +
  36 + if(context.request()->isRestful())
  37 + {
  38 + std::string path_=context.request()->path();
  39 + std::vector<std::string> vec_;
  40 + boost::split(vec_,context.request()->path(),boost::is_any_of("/"),boost::token_compress_on);
  41 + int isize_=vec_.size();
  42 + if(isize_<4)
  43 + {
  44 + context.response()->write("Tms,Operation is null");
  45 + return;
  46 + }
  47 + std::string::size_type idx0_,idx1_;
  48 + idx0_=vec_[isize_-1].find("png");
  49 + idx1_=vec_[isize_-1].find("jpg");
  50 +
  51 + if((idx0_!=std::string::npos)||(idx1_!=std::string::npos))
  52 + {
  53 + std::vector<std::string> vec0_;
  54 + boost::split(vec0_,vec_[isize_-1],boost::is_any_of("."),boost::token_compress_on);
  55 + int tileCol_=atoi(vec0_[0].c_str());
  56 + int tileRow_=atoi(vec_[isize_-2].c_str());
  57 + int tileMatrix_=atoi(vec_[isize_-3].c_str());
  58 + const DmpProject *project = context.project();
  59 + DmpTileLayer *tileLayer = static_cast<DmpTileLayer *>(project->getLayer("layer"));
  60 + std::string format_=tileLayer->getFormat();
  61 + std::string filePath_=tileLayer->getDataSource();
  62 + if(filePath_.empty())
  63 + {
  64 + context.response()->write("Tms,Operation is null");
  65 + }
  66 + else
  67 + {
  68 + DmpTmsTileProvider provider_=DmpTmsTileProvider(filePath_);
  69 + provider_.WriteTile(tileRow_, tileCol_, tileMatrix_, format_, *context.response());
  70 + }
  71 + }
  72 + else
  73 + {
  74 + context.response()->write("Tms,Operation is null");
  75 + return;
  76 + }
  77 + }
  78 + else
  79 + {
  80 + context.response()->write("非TMS请求");
  81 + }
  82 +
29 83 }
  84 +
30 85 } // namespace DmpTms
\ No newline at end of file
... ...
... ... @@ -15,7 +15,7 @@
15 15
16 16 namespace DmpTms
17 17 {
18   - class DmpTMSService : public DmpService
  18 + class DmpTMSService : public DmpService
19 19 {
20 20 public:
21 21 DmpTMSService();
... ...
1   -/**************************************************************************
2   -* file: dmpserverparameters.cpp
3   -
4   -* Author: lijiahuan
5   -* Date: 2021-12-09 17:41:00
6   -* Email: jiahuanl@chinadci.com
7   -* copyright: 广州城市信息研究所有限公司
8   -***************************************************************************/
9   -#include <iostream>
10   -#include <boost/lexical_cast.hpp>
11   -#include <boost/algorithm/string.hpp>
12   -#include "dmplogger.h"
13   -#include "dmpserverutils.h"
14   -#include "dmptmsparameters.h"
15   -
16   -
17   -namespace DmpTms
18   -{
19   - DmpTmsParameters::DmpTmsParameters(const DmpServerParameters &parameters)
20   - {
21   - params_ = parameters.Parameters();
22   - }
23   - DmpTmsParameters::DmpTmsParameters() : DmpServerParameters()
24   - {
25   -
26   - }
27   - int DmpTmsParameters::TileMatrix() const
28   - {
29   - std::map<std::string, std::string>::const_iterator iter;
30   - iter = params_.find("TILEMATRIX");
31   - if (iter != params_.end())
32   - {
33   - try
34   - {
35   - int num_tile_atrix = boost::lexical_cast<int>(iter->second);
36   - return num_tile_atrix;
37   - }
38   - catch (boost::bad_lexical_cast &e)
39   - {
40   - LOGGER_ERROR(e.what());
41   - }
42   - }
43   - return -1;
44   - }
45   - int DmpTmsParameters::TileRow() const
46   - {
47   - std::map<std::string, std::string>::const_iterator iter;
48   - iter = params_.find("TILEROW");
49   - if (iter != params_.end())
50   - {
51   - try
52   - {
53   - int num_tile_row = boost::lexical_cast<int>(iter->second);
54   - return num_tile_row;
55   - }
56   - catch (boost::bad_lexical_cast &e)
57   - {
58   - LOGGER_ERROR(e.what());
59   - }
60   - }
61   - return -1;
62   - }
63   - int DmpTmsParameters::TileCol() const
64   - {
65   - std::map<std::string, std::string>::const_iterator iter;
66   - iter = params_.find("TILECOL");
67   - if (iter != params_.end())
68   - {
69   - try
70   - {
71   - int num_tile_col = boost::lexical_cast<int>(iter->second);
72   - return num_tile_col;
73   - }
74   - catch (boost::bad_lexical_cast &e)
75   - {
76   - LOGGER_ERROR(e.what());
77   - }
78   - }
79   - return -1;
80   - }
81   -
82   - std::string DmpTmsParameters::TileMatrixSet() const
83   - {
84   - std::string tile_matrix_set;
85   - std::map<std::string, std::string>::const_iterator iter;
86   - iter = params_.find("TILEMATRIXSET");
87   - if (iter != params_.end())
88   - {
89   - tile_matrix_set = iter->second;
90   - }
91   - return tile_matrix_set;
92   - }
93   - std::string DmpTmsParameters::Layer() const
94   - {
95   - std::string layer;
96   - std::map<std::string, std::string>::const_iterator iter;
97   - iter = params_.find("LAYER");
98   - if (iter != params_.end())
99   - {
100   - layer = iter->second;
101   - }
102   - return layer;
103   - }
104   -
105   - DmpTmsParameters::Format DmpTmsParameters::ImageFormat() const
106   - {
107   - std::string frm;
108   - std::map<std::string, std::string>::const_iterator iter;
109   - iter = params_.find("format");
110   - if (iter != params_.end())
111   - {
112   - frm = iter->second;
113   - if (frm.empty()) {
114   - return Format::NONE;
115   - }
116   - Format f = Format::PNG;
117   - boost::to_lower(frm);
118   - if (frm.compare("jpg") == 0 || frm.compare("jpeg") == 0 || frm.compare("image/jpeg") == 0 ) {
119   - f = Format::JPG;
120   - }
121   - return f;
122   - }
123   - return Format::NONE;
124   - }
125   -}
\ No newline at end of file
1   -/**************************************************************************
2   -* file: dmpserverparameters.h
3   -
4   -* Author: lijiahuan
5   -* Date: 2021-12-09 17:41:00
6   -* Email: jiahuanl@chinadci.com
7   -* copyright: 广州城市信息研究所有限公司
8   -***************************************************************************/
9   -#ifndef __dmptmsparameters_h__
10   -#define __dmptmsparameters_h__
11   -
12   -#include "dmpserverparameters.h"
13   -namespace DmpTms
14   -{
15   - class DmpTmsParameters : public DmpServerParameters
16   - {
17   - public:
18   - enum class Format
19   - {
20   - NONE,
21   - JPG,
22   - PNG
23   - };
24   - DmpTmsParameters(const DmpServerParameters &parameters);
25   - DmpTmsParameters();
26   - virtual ~DmpTmsParameters() = default;
27   - std::string Layer() const;
28   - Format ImageFormat() const;
29   - std::string TileMatrixSet() const;
30   - int TileMatrix() const;
31   - int TileRow() const;
32   - int TileCol() const;
33   - };
34   -}
35   -#endif //__dmptmsparameters_h__
\ No newline at end of file
... ... @@ -19,8 +19,7 @@ namespace DmpTms
19 19 std::string tile_path = file_rootPath+"/"+std::to_string(level)+"/"+std::to_string(row)+"/"+std::to_string(col)+"."+format;
20 20 std::ifstream fread(tile_path, std::ifstream::binary);
21 21 if(!fread)
22   - {
23   -
  22 + {
24 23 response.sendError(500, "找不到瓦片:(");
25 24 return;
26 25 }
... ...
... ... @@ -16,11 +16,13 @@ namespace DmpTms
16 16 {
17 17 class DmpTmsTileProvider
18 18 {
19   - public:
  19 + public:
  20 + std::string ImageFormat() const;
20 21 DmpTmsTileProvider(const std::string& root_path);
21 22 void WriteTile(const int row, const int col, const int level, const std::string& format, DmpServerResponse& response) ;
22   - protected:
  23 + protected:
23 24 std::string file_rootPath;
24 25 };
25 26 }
  27 +
26 28 #endif
\ No newline at end of file
... ...
注册登录 后发表评论