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/show-popup/ below:

Show popup | ArcGIS Maps SDK for Qt

View on GitHub Sample viewer app

Show predefined popups from a web map.

Use case

Many web maps contain predefined popups which are used to display the attributes associated with each feature layer in the map, such as hiking trails, land values, or unemployment rates. You can display text, attachments, images, charts, and web links. Rather than creating new popups to display information, you can easily access and display the predefined popups.

How to use the sample

Tap on the features to prompt a popup that displays information about the feature.

How it works
  1. Create and load a Map using a URL.
  2. Set the map to a MapView and connect to the MapQuickView::mouseClicked signal.
  3. Use GeoView::identifyLayer(layer, x, y, tolerance, allowPopupsOnly, maximumResults) to identify features.
  4. Create a PopupManager for each of the result's Popups and append them to a list.
  5. Assign the list of popup managers to the PopupStackView.popupManagers property.
  6. Display the popup stack view.
Relevant API About the data

This sample uses a feature layer that displays reported incidents in San Francisco.

Additional information

In order to use the PopupManager with a QML UI, the PopupManager, PopupAttachmentManager, PopupAttachmentListModel, and PopupAttributeListModel classes must be registered as QML Types. For more information visit our developer site.

feature, feature layer, popup, web map

Sample Code

ShowPopup.cpp ShowPopup.cpp ShowPopup.h ShowPopup.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
// [WriteFile Name=ShowPopup, Category=DisplayInformation]
// [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 "ShowPopup.h"

// ArcGIS Maps SDK headers
#include "Error.h"
#include "Feature.h"
#include "FeatureLayer.h"
#include "IdentifyLayerResult.h"
#include "LayerListModel.h"
#include "Map.h"
#include "MapQuickView.h"
#include "MapTypes.h"
#include "Popup.h"

// Qt headers
#include <QUuid>

using namespace Esri::ArcGISRuntime;

ShowPopup::ShowPopup(QObject* parent /* = nullptr */):
  QObject(parent),
  m_map(new Map(QUrl("https://runtime.maps.arcgis.com/home/webmap/viewer.html?webmap=e4c6eb667e6c43b896691f10cc2f1580"), this))
{
}

ShowPopup::~ShowPopup() = default;

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

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

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

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

  // once map is set, connect to MapQuickView mouse clicked signal
  connect(m_mapView, &MapQuickView::mouseClicked, this, &ShowPopup::onMouseClicked);

  emit mapViewChanged();
}

void ShowPopup::onIdentifyLayerCompleted(const QUuid&, IdentifyLayerResult* rawIdentifyResult)
{
  emit taskRunningChanged();
  auto identifyResult = std::unique_ptr<IdentifyLayerResult>(rawIdentifyResult);

  // Invalid identify result
  if (!identifyResult)
    return;

  if (!identifyResult->error().isEmpty())
  {
    qDebug() << "Identify error occurred: " << identifyResult->error().message();
    return;
  }

  m_featureLayer->clearSelection();
  if (!identifyResult->popups().isEmpty())
  {
    GeoElement* geoElement = identifyResult->geoElements().first();
    Feature* feature = static_cast<Feature*>(geoElement);
    m_featureLayer->selectFeature(feature);

    m_popup = new Popup(geoElement, this);
    emit popupChanged();
  }
}

void ShowPopup::onMouseClicked(QMouseEvent& mouseEvent)
{
  if (m_map->loadStatus() != LoadStatus::Loaded)
    return;

  Layer* layer = m_map->operationalLayers()->at(0);
  if (layer->layerType() == LayerType::FeatureLayer)
  {
    m_featureLayer = static_cast<FeatureLayer*>(layer);
  }

  constexpr double tolerance = 12;
  constexpr bool returnPopupsOnly = false;
  constexpr int maximumResults = 10;

  m_future = m_mapView->identifyLayerAsync(m_featureLayer, mouseEvent.position(), tolerance, returnPopupsOnly, maximumResults);
  m_future.then(this, [this](IdentifyLayerResult* result)
  {
    onIdentifyLayerCompleted(QUuid(),result);
  });

  if (!m_future.isValid())
    qWarning() << "Future not valid.";

  emit taskRunningChanged();
}

bool ShowPopup::taskRunning() const
{
  return m_future.isRunning();
}

void ShowPopup::clearSelection() const
{
  m_featureLayer->clearSelection();
}

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