提交 d1767cf8f28e4177a7d850a99a9d4ea6ebfdcdd7

作者 LJH 李佳桓
1 个父辈 1ed8f78c

add

  1 +/**************************************************************************
  2 +* file: dmpesritileprovider.cpp
  3 +
  4 +* Author: wanzhongping
  5 +* Date: 2021-05-28 14:24:01
  6 +* Email: zhongpingw@chinadci.com
  7 +* copyright: 广州城市信息研究所有限公司
  8 +***************************************************************************/
  9 +#include "dmpesritileprovider.h"
  10 +#include "dmpwmtsutils.h"
  11 +#include <string>
  12 +
  13 +namespace DmpWmts
  14 +{
  15 + DmpEsriTileProvider::DmpEsriTileProvider()
  16 + {
  17 + this->_rootPath ="/mnt/d/Data/tile/ShareMap2014/Layers/_alllayers/";
  18 + }
  19 +
  20 + std::string DmpEsriTileProvider::IntToHex8Str(const int num)
  21 + {
  22 + char* buffer = new char[8];
  23 + sprintf(buffer,"%08x",num);
  24 + std::string str = std::string(buffer, 8);
  25 + delete[] buffer;
  26 + return str;
  27 + }
  28 + void DmpEsriTileProvider::WriteTile(const int row, const int col, const int level, const std::string& format, DmpServerResponse& response)
  29 + {
  30 + std::string level_str = "L" + IntToFormatStr(level);
  31 + std::string row_str = "R" + IntToHex8Str(row);
  32 + std::string col_str = "C" + IntToHex8Str(col);
  33 +
  34 + std::string tile_path = _rootPath + level_str + "/"+ row_str+"/"+ col_str + "." + format;
  35 +
  36 + std::ifstream fread(tile_path, std::ifstream::binary);
  37 + if(!fread)
  38 + {
  39 + response.SendError(500, "找不到瓦片:(");
  40 + return;
  41 + }
  42 + fread.seekg(0,fread.end);
  43 + int length = fread.tellg();
  44 + if(length > 0)
  45 + {
  46 + fread.seekg(0,fread.beg);
  47 + char* buff = new char[length];
  48 + fread.read(buff,length);
  49 +
  50 + std::string f = (format == "jpg") ? "image/jpg" : "image/png";
  51 + response.SetHeader("Content-Type", f);
  52 + response.WriteContent(buff, length);
  53 +
  54 + delete buff;
  55 + }
  56 + else
  57 + {
  58 + response.SendError(500, "找不到瓦片:(");
  59 + }
  60 + fread.close();
  61 + }
  62 +}
\ No newline at end of file
... ...
注册登录 后发表评论