A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developers.arcgis.com/qt/cpp/sample-code/display-layer-view-draw-state/ below:

Display layer view draw state | ArcGIS Maps SDK for Qt

View on GitHub Sample viewer app

Determine if a layer is currently being viewed.

Use case

The view status includes information on the loading state of layers and whether layers are visible at a given scale. You might change how a layer is displayed in a layer list to communicate whether it is being viewed in the map. For example, you could show a loading spinner next to its name when the view status is Loading, grey out the name when NotVisible or OutOfScale, show the name normally when Active, or with a warning or error icon when the status is Warning or Error.

How to use the sample

Tap the Load layer button to add a feature layer to the map. The current view status of the layer will display on the map. Zoom in and out of the map and note the layer disappears when the map is scaled outside of its min and max scale range. Control the layer's visibility with the Hide layer button. If you disconnect your device from the network and pan around the map, a warning will display. Reconnect to the network to remove the warning. The layer's current view status will update accordingly as you carry out these actions.

How it works
  1. Create a Map with some operational layers.
  2. Set the map on a MapView.
  3. Connect to the layerViewStateChanged signal from the map view.
  4. Display the LayerViewStatus flag for the FeatureLayer.
Relevant API About the data

The Satellite (MODIS) Thermal Hotspots and Fire Activity layer presents detectable thermal activity from MODIS satellites for the last 48 hours. MODIS Global Fires is a product of NASA’s Earth Observing System Data and Information System (EOSDIS), part of NASA's Earth Science Data. EOSDIS integrates remote sensing and GIS technologies to deliver global MODIS hotspot/fire locations to natural resource managers and other stakeholders around the World.

Additional information

The following are members of the LayerViewStatus enum:

If your device supports airplane mode, you can toggle this on and pan around the map to see layers display the WARNING status when they cannot online fetch data. Toggle airplane mode back off to see the warning disappear.

layer, load, map, status, view, visibility

Sample Code

DisplayLayerViewDrawState.cpp DisplayLayerViewDrawState.cpp DisplayLayerViewDrawState.h DisplayLayerViewDrawState.qml

Use dark colors for code blocks Copy

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// [WriteFile Name=DisplayLayerViewDrawState, Category=Maps]
// [Legal]
// Copyright 2020 Esri.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// [Legal]

#ifdef PCH_BUILD
#include "pch.hpp"
#endif // PCH_BUILD

// sample headers
#include "DisplayLayerViewDrawState.h"

// ArcGIS Maps SDK headers
#include "Error.h"
#include "FeatureLayer.h"
#include "LayerListModel.h"
#include "LayerViewState.h"
#include "Map.h"
#include "MapQuickView.h"
#include "MapTypes.h"
#include "Point.h"
#include "Portal.h"
#include "PortalItem.h"
#include "SpatialReference.h"
#include "Viewpoint.h"

// Qt headers
#include <QFuture>

using namespace Esri::ArcGISRuntime;

DisplayLayerViewDrawState::DisplayLayerViewDrawState(QObject* parent /* = nullptr */):
  QObject(parent),
  m_map(new Map(BasemapStyle::ArcGISTopographic, this))
{
}

DisplayLayerViewDrawState::~DisplayLayerViewDrawState() = default;

void DisplayLayerViewDrawState::init()
{
  // Register the map view for QML
  qmlRegisterType<MapQuickView>("Esri.Samples", 1, 0, "MapView");
  qmlRegisterType<DisplayLayerViewDrawState>("Esri.Samples", 1, 0, "DisplayLayerViewDrawStateSample");
}

MapQuickView* DisplayLayerViewDrawState::mapView() const
{
  return m_mapView;
}

// Set the view (created in QML)
void DisplayLayerViewDrawState::setMapView(MapQuickView* mapView)
{
  if (!mapView || mapView == m_mapView)
    return;

  m_mapView = mapView;
  m_mapView->setMap(m_map);

  connect(m_mapView, &MapQuickView::layerViewStateChanged, this, &DisplayLayerViewDrawState::onLayerViewStateCompleted);

  emit mapViewChanged();
}

void DisplayLayerViewDrawState::loadLayer()
{
  // load a feature layer from a portal item
  Portal* portal = new Portal(this);
  m_portalItem = new PortalItem(portal, "b8f4033069f141729ffb298b7418b653", this);
  m_featureLayer = new FeatureLayer(m_portalItem, 0, this);

  connect(m_featureLayer, &FeatureLayer::loadStatusChanged, this, [this] (LoadStatus loadStatus)
  {
    m_loading = (loadStatus == LoadStatus::Loading) ? true : false;
    emit loadingChanged();
  });

  // load feature layer and set the viewpoint
  connect(m_featureLayer, &FeatureLayer::doneLoading, this, [this](const Error& e)
  {
    if (!e.isEmpty())
      return;

    const Point point{-11000000, 4500000, SpatialReference::webMercator()};
    const Viewpoint vp{point, 40000000.0};
    m_mapView->setViewpointAsync(vp);
  });

  // set min/max scale to demonstrate different view states.
  m_featureLayer->setMinScale(400000000.0);
  m_featureLayer->setMaxScale(400000000.0 / 10);
  m_map->operationalLayers()->append(m_featureLayer);
}

void DisplayLayerViewDrawState::changeFeatureLayerVisibility(bool visible)
{
  if (m_featureLayer->loadStatus() == LoadStatus::Loaded)
    m_featureLayer->setVisible(visible);
}

void DisplayLayerViewDrawState::onLayerViewStateCompleted(Layer* layer, LayerViewState layerViewState)
{
  // check if feature layer has been created otherwise do nothing.
  if (!m_featureLayer)
    return;

  // only update the QStringList if the layer is the feature layer.
  if (layer->name() != m_featureLayer->name())
    return;

  // clear string list for new view state(s).
  m_viewStatuses.clear();

  if (layerViewState.statusFlags() & Esri::ArcGISRuntime::LayerViewStatus::Active)
    m_viewStatuses.append("Active");
  if (layerViewState.statusFlags() & Esri::ArcGISRuntime::LayerViewStatus::NotVisible)
    m_viewStatuses.append("NotVisible");
  if (layerViewState.statusFlags() & Esri::ArcGISRuntime::LayerViewStatus::OutOfScale)
    m_viewStatuses.append("OutOfScale");
  if (layerViewState.statusFlags() & Esri::ArcGISRuntime::LayerViewStatus::Loading)
    m_viewStatuses.append("Loading");
  if (layerViewState.statusFlags() & Esri::ArcGISRuntime::LayerViewStatus::Error)
    m_viewStatuses.append("Error");
  if (layerViewState.statusFlags() & Esri::ArcGISRuntime::LayerViewStatus::Warning)
  {
    m_viewStatuses.append("Warning");
    if (!layerViewState.error().isEmpty())
    {
      const QString warningMessage = QString("Warning message: %1").arg(layerViewState.error().message());
      m_warningMessage = warningMessage;
      emit warningMessageChanged();
    }
  }
  emit viewStatusChanged();
}

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4