dmptilelayer.cpp 2.6 KB
/**************************************************************************
* file:              dmptilelayer.cpp

* Author:            wanzhongping
* Date:              2021-11-13 16:49:00
* Email:             zhongpingw@chinadci.com
* copyright:         广州城市信息研究所有限公司
***************************************************************************/
#include "dmptilelayer.h"
#include "dmpxmlutils.h"
#include <iostream>
#include <boost/property_tree/xml_parser.hpp>
#include <boost/typeof/typeof.hpp>

DmpTileLayer::DmpTileLayer(const std::string &path, const std::string &baseName)
    : DmpMapLayer(DmpMapLayerType::TileLayer, baseName, path)
{
}

DmpTileLayer::~DmpTileLayer()
{
  std::vector<DmpTileMatrixSet *>::iterator iter = tileMatrixSets_.begin();
  for (; iter != tileMatrixSets_.end(); ++iter)
  {
    if (*iter != NULL)
    {
      delete *iter;
      *iter = NULL;
    }
  }
  tileMatrixSets_.clear();
}

bool DmpTileLayer::readXml(const boost::property_tree::ptree &layerNode)
{
  try
  {
    name_ = layerNode.get<std::string>("<xmlattr>.name");
    title_ = layerNode.get<std::string>("<xmlattr>.alias");
    boost::property_tree::ptree pExtent = layerNode.get_child("extent");
    extent_ = DmpXmlUtils::readRectangle(pExtent);
    style_ = layerNode.get<std::string>("style");
    format_ = layerNode.get<std::string>("format");
    vendor_ = layerNode.get<std::string>("vendor");
    datasource_ = layerNode.get<std::string>("datasource");
    if(strcmp(vendor_.c_str(),"QGIS")==0)return true;
    boost::property_tree::ptree pMatrixSets = layerNode.get_child("tileMatrixSets");
    for (BOOST_AUTO(pos, pMatrixSets.begin()); pos != pMatrixSets.end(); ++pos)
    {
      boost::property_tree::ptree pTileMatrixSet = pos->second;
      DmpTileMatrixSet *tileMatrixSet = new DmpTileMatrixSet();
      if (tileMatrixSet->readXml(pTileMatrixSet))
      {
        tileMatrixSets_.push_back(tileMatrixSet);
      }
      else
      {
        delete tileMatrixSet;
        return false;
      }
    }
  }
  catch (const std::exception &e)
  {
    std::cerr << e.what() << '\n';
    return false;
  }
  return true;
}

bool DmpTileLayer::writeXml(boost::property_tree::ptree &layerNode)
{
  return false;
}
std::string DmpTileLayer::getVendor()
{
  return vendor_;
}
std::string DmpTileLayer::getDataSource()
{
  return datasource_;
}
void DmpTileLayer::getTileMatrixSets(std::vector<DmpTileMatrixSet*>& tileMatrixSets )
{
  tileMatrixSets=tileMatrixSets_;
}
std::string DmpTileLayer::getFormat()
{
  return format_;
}
std::string DmpTileLayer::getStyle()
{
  return style_;
}