Skip to content

Commit

Permalink
Andrewbladon/fix ogc feature service crash (#1273)
Browse files Browse the repository at this point in the history
* Disable load buttons while loading in c++ sample

* Disable load buttons while loading in Qml sample

* Tan11389/ab/ogc feature service fix (#1275)

* Update loading handlers in C++

* loading logic cleanup

* remove unused member variable

* Change name of loading QPROPERTY in c++ sample

Co-authored-by: Tanner Yould <[email protected]>
  • Loading branch information
AndrewBladon and tanneryould authored Aug 11, 2021
1 parent a880b05 commit d9b2173
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ void BrowseOGCAPIFeatureService::handleError(const Esri::ArcGISRuntime::Error& e

void BrowseOGCAPIFeatureService::loadFeatureService(const QUrl& url)
{
if (m_featureService && m_featureService->loadStatus() == LoadStatus::Loading)
return;

clearExistingFeatureService();

// Instantiate new OGCFeatureService object using url
Expand All @@ -109,6 +112,9 @@ void BrowseOGCAPIFeatureService::loadFeatureService(const QUrl& url)
// Connect errorOccurred to handleError()
connect(m_featureService, &OgcFeatureService::errorOccurred, this, &BrowseOGCAPIFeatureService::handleError);

// Connect to loadingChanged() to enable and disable UI buttons
connect(m_featureService, &OgcFeatureService::loadStatusChanged, this, &BrowseOGCAPIFeatureService::serviceOrFeatureLoadingChanged);

m_featureService->load();
}

Expand All @@ -125,6 +131,7 @@ void BrowseOGCAPIFeatureService::clearExistingFeatureService()
delete m_featureService;
m_featureService = nullptr;
}

m_featureCollectionList.clear();
emit featureCollectionListChanged();
}
Expand Down Expand Up @@ -187,6 +194,11 @@ void BrowseOGCAPIFeatureService::loadFeatureCollection(int selectedFeature)

// Connect errorOccurred to handleError()
connect(m_featureLayer, &FeatureLayer::errorOccurred, this, &BrowseOGCAPIFeatureService::handleError);

// Connect to loadingChanged() to enable and disable UI buttons
connect(m_featureLayer, &FeatureLayer::loadStatusChanged, this, &BrowseOGCAPIFeatureService::serviceOrFeatureLoadingChanged);

m_featureLayer->load();
}

void BrowseOGCAPIFeatureService::clearExistingFeatureLayer()
Expand All @@ -213,3 +225,14 @@ void BrowseOGCAPIFeatureService::addFeatureLayerToMap()
m_map->operationalLayers()->clear();
m_map->operationalLayers()->append(m_featureLayer);
}

bool BrowseOGCAPIFeatureService::serviceOrFeatureLoading() const
{
if (m_featureService && m_featureService->loadStatus() == LoadStatus::Loading)
return true;

else if (m_featureLayer && m_featureLayer->loadStatus() == LoadStatus::Loading)
return true;

return false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class BrowseOGCAPIFeatureService : public QObject
Q_PROPERTY(QString errorMessage READ errorMessage WRITE setErrorMessage NOTIFY errorMessageChanged)
Q_PROPERTY(QUrl featureServiceUrl READ featureServiceUrl NOTIFY urlChanged)
Q_PROPERTY(QStringList featureCollectionList READ featureCollectionList NOTIFY featureCollectionListChanged)
Q_PROPERTY(bool serviceOrFeatureLoading READ serviceOrFeatureLoading NOTIFY serviceOrFeatureLoadingChanged)

public:
explicit BrowseOGCAPIFeatureService(QObject* parent = nullptr);
Expand All @@ -58,6 +59,7 @@ class BrowseOGCAPIFeatureService : public QObject
void errorMessageChanged();
void urlChanged();
void featureCollectionListChanged();
void serviceOrFeatureLoadingChanged();

private:
Esri::ArcGISRuntime::MapQuickView* mapView() const;
Expand All @@ -73,6 +75,7 @@ class BrowseOGCAPIFeatureService : public QObject
void createFeatureCollectionList();
void clearExistingFeatureLayer();
void addFeatureLayerToMap();
bool serviceOrFeatureLoading() const;

Esri::ArcGISRuntime::Map* m_map = nullptr;
Esri::ArcGISRuntime::MapQuickView* m_mapView = nullptr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Item {
Button {
id: connectButton
text: "Load service"
enabled: !model.serviceOrFeatureLoading
onClicked: model.loadService(serviceURLBox.text);

}
Expand All @@ -78,6 +79,7 @@ Item {
Button {
id: loadLayerButton
text: "Load selected layer"
enabled: !model.serviceOrFeatureLoading
onClicked: model.loadFeatureCollection(featureList.currentIndex);
Layout.columnSpan: 2
Layout.fillWidth: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ Rectangle {
Button {
id: connectButton
text: "Load service"
enabled: featureService.loadStatus !== Enums.LoadStatusLoading
onClicked: {
serviceURL = serviceURLBox.text;
loadFeatureService(serviceURL);
Expand All @@ -94,6 +95,7 @@ Rectangle {
Button {
id: loadLayerButton
text: "Load selected layer"
enabled: featureLayer.loadStatus !== Enums.LoadStatusLoading
onClicked: loadFeatureCollection(featureCollectionListComboBox.currentIndex);
Layout.columnSpan: 2
Layout.fillWidth: true
Expand Down

0 comments on commit d9b2173

Please sign in to comment.