ArcGIS Runtime SDK for Qt

Local Server feature layer

Loading

Code

#include "LocalServerFeatureLayer.h"

#include "Basemap.h"
#include "MapQuickView.h"
#include "Map.h"
#include "LocalServer.h"
#include "LocalFeatureService.h"
#include "ServiceFeatureTable.h"
#include "FeatureLayer.h"
#include "Viewpoint.h"

#include <QDir>

using namespace Esri::ArcGISRuntime;

LocalServerFeatureLayer::LocalServerFeatureLayer(QQuickItem* parent) :
  QQuickItem(parent)
{
}

LocalServerFeatureLayer::~LocalServerFeatureLayer()
{
}

void LocalServerFeatureLayer::init()
{
  qmlRegisterType<MapQuickView>("Esri.Samples", 1, 0, "MapView");
  qmlRegisterType<LocalServerFeatureLayer>("Esri.Samples", 1, 0, "LocalServerFeatureLayerSample");
}

void LocalServerFeatureLayer::componentComplete()
{
  QQuickItem::componentComplete();

  // find QML MapView component
  m_mapView = findChild<MapQuickView*>("mapView");
  m_mapView->setWrapAroundMode(WrapAroundMode::Disabled);

  // Create a map using the topographic BaseMap
  m_map = new Map(Basemap::topographic(this), this);

  // Set map to map view
  m_mapView->setMap(m_map);

  QString dataPath = QDir::homePath() + "/ArcGIS/Runtime/Data";

  // create a feature service
  m_localFeatureService = new LocalFeatureService(dataPath + "/mpk/PointsofInterest.mpk", this);

  if (LocalServer::instance()->isInstallValid())
  {
    connectSignals();
    if (LocalServer::status() == LocalServerStatus::Started)
      m_localFeatureService->start();
    else
      LocalServer::start();
  }
}

void LocalServerFeatureLayer::connectSignals()
{
  // local server status
  connect(LocalServer::instance(), &LocalServer::statusChanged, this, [this]()
  {
    if (LocalServer::status() == LocalServerStatus::Started)
    {
      qDebug() << "Local server started";
      m_localFeatureService->start();
    }
  });

  // local feature service status
  connect(m_localFeatureService, &LocalFeatureService::statusChanged, this, [this]()
  {
    if (m_localFeatureService->status() == LocalServerStatus::Started)
    {
      ServiceFeatureTable* svt = new ServiceFeatureTable(QUrl(m_localFeatureService->url().toString() + "/0"), this);
      FeatureLayer* featureLayer = new FeatureLayer(svt, this);
      connect(featureLayer, &FeatureLayer::loadStatusChanged, this, [this, featureLayer](LoadStatus status)
      {
        if (status == LoadStatus::Loaded)
        {
          m_mapView->setViewpoint(Viewpoint(featureLayer->fullExtent()));
        }
      });
      m_map->operationalLayers()->append(featureLayer);
    }
  });
}


In this topic
  1. Code