Local Server map image layer

Loading

Code

#include "LocalServerMapImageLayer.h"

#include "Basemap.h"
#include "MapQuickView.h"
#include "Map.h"
#include "LocalServer.h"
#include "LocalMapService.h"
#include "ArcGISMapImageLayer.h"
#include "Viewpoint.h"

#include <QDir>

using namespace Esri::ArcGISRuntime;

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

LocalServerMapImageLayer::~LocalServerMapImageLayer()
{
}

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

void LocalServerMapImageLayer::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 map service
  m_localMapService = new LocalMapService(dataPath + "/mpk/RelationshipID.mpk", this);

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

void LocalServerMapImageLayer::connectSignals()
{
  // local server status
  connect(LocalServer::instance(), &LocalServer::statusChanged, this, [this]()
  {
    if (LocalServer::status() == LocalServerStatus::Started)
    {
      m_localMapService->start();
    }
  });

  // local map service status
  connect(m_localMapService, &LocalMapService::statusChanged, this, [this]()
  {
    if (m_localMapService->status() == LocalServerStatus::Started)
    {
      ArcGISMapImageLayer* mapImageLayer = new ArcGISMapImageLayer(QUrl(m_localMapService->url()), this);

      connect(mapImageLayer, &ArcGISMapImageLayer::loadStatusChanged, this, [this, mapImageLayer](LoadStatus status)
      {
        if (status == LoadStatus::Loaded)
        {
          m_mapView->setViewpoint(Viewpoint(mapImageLayer->fullExtent()));
        }
      });
      m_map->operationalLayers()->append(mapImageLayer);
    }
  });
}


In this topic
  1. Code