提交 87f25d1f04fc2a9f1e4aedc1884d67cf5c3a5449

作者 LJH 李佳桓
1 个父辈 8478d518

ljh

... ... @@ -102,8 +102,8 @@ void DmpManagerApiHandler::regService(const DmpServerApiContext &context) const
102 102 LOGGER_INFO("服务发布成功");
103 103 std::string url;
104 104 std::string http="http://"+context.request()->domain()+":"+context.request()->port();
105   -
106   - url=http+"/DMap/Services/"+name+"/TileServer/tmsService?REQUEST=GetThumbnail";
  105 +
  106 + url=http+"/DMap/Services/"+name+"/"+serverType+"/tmsService?REQUEST=GetThumbnail";
107 107 context.response()->write("{\"status\":\""+std::to_string(flag)+"\",\"url\":\""+url+"\",\"message\":\"Pulish service successful!\"}");
108 108 // std::string projData;
109 109 // DmpServerUtils::Base64Decode(project, &projData);
... ...
... ... @@ -72,7 +72,7 @@ namespace DmpTms
72 72 cairo_surface_t* image = cairo_image_surface_create_from_png( filepath.c_str());
73 73 this->BufferCopy(image,surface,cr,i*256,j*256);
74 74 //cairo_surface_write_to_png (surface, "./tms.png");
75   - LOGGER_DEBUG(filepath);
  75 + //LOGGER_DEBUG(filepath);
76 76 }
77 77 }
78 78 //cairo_surface_write_to_png (surface, "./tms.png");
... ...
... ... @@ -53,7 +53,7 @@ namespace DmpWmts
53 53 }
54 54 }
55 55 c = "C" + c;
56   -
  56 +
57 57 string bundlePath = rootPath_ + "/"+l+"/"+r+c;
58 58 return bundlePath;
59 59 }
... ...
... ... @@ -103,12 +103,34 @@ namespace DmpWmts
103 103 response.sendError(500, "缩略图范围错误:(");
104 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 136 bool DmpEsriBundleV1Provider::GetTile(int row, int col, int level,std::string& refbuff,int& length )
... ... @@ -157,14 +179,14 @@ namespace DmpWmts
157 179 + (long)(buff[3]&0xff) * 16777216;
158 180 delete[] buff;
159 181 char *imgBuffer = new char[length];
160   - fread.read(imgBuffer, length);
  182 + fread.read(imgBuffer, length);
161 183 fread.close();
  184 + refbuff.append(imgBuffer,length);
  185 + // const char* test=refbuff.c_str();
162 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 191 // TileProviderFactory::BufferCopy(image,surface,cr,0,0);
170 192 // cairo_surface_write_to_png (surface, "./wmts.png");
... ... @@ -174,11 +196,11 @@ namespace DmpWmts
174 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 }
\ No newline at end of file
... ...
... ... @@ -22,13 +22,13 @@ namespace DmpWmts
22 22 DmpEsriBundleV1Provider(const std::string& rootPath);
23 23 void WriteTile(const int row, const int col, const int level, const std::string& format, DmpServerResponse& response) override;
24 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 34 #endif //__dmpesribundlev1provider_h__
... ...
... ... @@ -31,7 +31,7 @@ namespace DmpWmts
31 31 {
32 32 std::string tileVersion= dmpTileLayer->getVendor();
33 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 35 //std::string tileVersion_ = "ESRI_V1";
36 36 int iver=StringToVector(tileVersion);
37 37 Vendor version = (Vendor)boost::lexical_cast<int>(iver);
... ... @@ -151,4 +151,11 @@ namespace DmpWmts
151 151 cairo_paint(cr);
152 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 }
\ No newline at end of file
... ...
... ... @@ -42,11 +42,12 @@ namespace DmpWmts
42 42 static int screenTileMatrix(DmpPoint& min,DmpPoint& max,std::vector<DmpTileMatrixSet*>& tileMatrixSets,double& resolution,DmpPoint& origin);
43 43 static void PointToRowCol(DmpPoint& point,DmpPoint& origin,double resolution,int& xTile,int& yTile);
44 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 47 private:
47 48 TileProviderFactory();
48 49 };
49   -
  50 +
50 51
51 52 }
52 53 #endif //__dmptileproviderfactory_h__
... ...
注册登录 后发表评论