Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Configure basemap style language sample #1688

Merged
merged 22 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
39988ec
Adding configure basemap style language sample
har13205 Mar 1, 2024
4009a8b
Initializing basemapStyleParameters
har13205 Mar 2, 2024
edd0551
Update ArcGISRuntimeSDKQt_CppSamples/Maps/ConfigureBasemapStyleLangua…
har13205 Mar 4, 2024
71acdd2
Update ArcGISRuntimeSDKQt_CppSamples/Maps/ConfigureBasemapStyleLangua…
har13205 Mar 4, 2024
479515d
Update ArcGISRuntimeSDKQt_CppSamples/Maps/ConfigureBasemapStyleLangua…
har13205 Mar 4, 2024
50c5414
Update ArcGISRuntimeSDKQt_CppSamples/Maps/ConfigureBasemapStyleLangua…
har13205 Mar 4, 2024
0379821
Update ArcGISRuntimeSDKQt_CppSamples/Maps/ConfigureBasemapStyleLangua…
har13205 Mar 4, 2024
d9783d2
Update ArcGISRuntimeSDKQt_CppSamples/Maps/ConfigureBasemapStyleLangua…
har13205 Mar 4, 2024
3783d68
Update ArcGISRuntimeSDKQt_CppSamples/Maps/ConfigureBasemapStyleLangua…
har13205 Mar 4, 2024
a9a465c
Update ArcGISRuntimeSDKQt_CppSamples/Maps/ConfigureBasemapStyleLangua…
har13205 Mar 4, 2024
f64922c
Update ArcGISRuntimeSDKQt_CppSamples/Maps/ConfigureBasemapStyleLangua…
har13205 Mar 4, 2024
1769e6d
Changes as per PR comments
har13205 Mar 4, 2024
8d3364e
Update ArcGISRuntimeSDKQt_CppSamples/Maps/ConfigureBasemapStyleLangua…
har13205 Mar 5, 2024
41e07ec
Update ArcGISRuntimeSDKQt_CppSamples/Maps/ConfigureBasemapStyleLangua…
har13205 Mar 5, 2024
5d36cdf
Changes as per PR comments
har13205 Mar 5, 2024
9f52d51
Update ArcGISRuntimeSDKQt_CppSamples/Maps/ConfigureBasemapStyleLangua…
har13205 Mar 5, 2024
0b36d5b
Update ArcGISRuntimeSDKQt_CppSamples/Maps/ConfigureBasemapStyleLangua…
har13205 Mar 5, 2024
cd68518
Update ArcGISRuntimeSDKQt_CppSamples/Maps/ConfigureBasemapStyleLangua…
har13205 Mar 5, 2024
c4d12b1
Update ArcGISRuntimeSDKQt_CppSamples/Maps/ConfigureBasemapStyleLangua…
har13205 Mar 5, 2024
0860c3d
Changes as per PR comments
har13205 Mar 5, 2024
7a6a3f5
Changes as per PR comments
har13205 Mar 5, 2024
dbc50f4
Adding comment for onCurrentTextChanged
har13205 Mar 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// [WriteFile Name=ConfigureBasemapStyleLanguage, Category=Maps]
// [Legal]
// Copyright 2024 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

#include "Basemap.h"
#include "BasemapStyleParameters.h"
#include "ConfigureBasemapStyleLanguage.h"
#include "Error.h"
#include "Map.h"
#include "MapQuickView.h"
#include "MapTypes.h"
#include "Point.h"
#include "SpatialReference.h"
#include "Viewpoint.h"

#include <QFuture>

using namespace Esri::ArcGISRuntime;

ConfigureBasemapStyleLanguage::ConfigureBasemapStyleLanguage(QObject* parent /* = nullptr */) :
QObject(parent)
{
}

ConfigureBasemapStyleLanguage::~ConfigureBasemapStyleLanguage() = default;

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

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

// Set the view (created in QML)
void ConfigureBasemapStyleLanguage::setMapView(MapQuickView* mapView)
{
m_map = new Map(this);
har13205 marked this conversation as resolved.
Show resolved Hide resolved
connect(m_map, &Map::doneLoading, this, [](const Error& e)
{
if (!e.isEmpty())
{
qWarning() << e.message() << e.additionalMessage();
return;
}
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably unnecessary to include checking in this logging for the map load status. I suggest removing it


if (!mapView || mapView == m_mapView)
return;

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

const Point point(3144804, 4904598);

// Create a Viewpoint object with the created Point and a scale of 10000000
const Viewpoint viewpoint(point, 10000000);

// Set the viewpoint for the mapView
mapView->setViewpointAsync(viewpoint);
emit mapViewChanged();
}

//Set new basemap language based on the parameters selected
har13205 marked this conversation as resolved.
Show resolved Hide resolved
void ConfigureBasemapStyleLanguage::setNewBasemapLanguage(bool global, const QString& language)
{
if (!basemapStyleParameters)
{
basemapStyleParameters = new BasemapStyleParameters(this);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this is always needed. If so, consider creating it in the constructor.

}

basemapStyleParameters->setLanguageStrategy(global ? BasemapStyleLanguageStrategy::Global : BasemapStyleLanguageStrategy::Local);

// A SpecificLanguage setting overrides the LanguageStrategy settings
if (language == "none")
{
basemapStyleParameters->setSpecificLanguage("");
} else if (language == "Bulgarian")
{
basemapStyleParameters->setSpecificLanguage("bg");
} else if (language == "Greek")
{
basemapStyleParameters->setSpecificLanguage("el");
} else if (language == "Turkish")
{
har13205 marked this conversation as resolved.
Show resolved Hide resolved
basemapStyleParameters->setSpecificLanguage("tr");
}

basemap = new Basemap(BasemapStyle::OsmLightGray, basemapStyleParameters, this);
har13205 marked this conversation as resolved.
Show resolved Hide resolved
m_map->setBasemap(basemap);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// [WriteFile Name=ConfigureBasemapStyleLanguage, Category=Maps]
// [Legal]
// Copyright 2024 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]

#ifndef CONFIGUREBASEMAPSTYLELANGUAGE_H
#define CONFIGUREBASEMAPSTYLELANGUAGE_H

namespace Esri::ArcGISRuntime {
class Basemap;
class BasemapStyleParameters;
class Map;
class MapQuickView;
}

#include <QObject>

Q_MOC_INCLUDE("MapQuickView.h");

class ConfigureBasemapStyleLanguage : public QObject
{
Q_OBJECT

Q_PROPERTY(Esri::ArcGISRuntime::MapQuickView* mapView READ mapView WRITE setMapView NOTIFY mapViewChanged)

public:
explicit ConfigureBasemapStyleLanguage(QObject* parent = nullptr);
~ConfigureBasemapStyleLanguage() override;

static void init();
Q_INVOKABLE void setNewBasemapLanguage(bool global, const QString& language);

signals:
void mapViewChanged();

private:
Esri::ArcGISRuntime::MapQuickView* mapView() const;
void setMapView(Esri::ArcGISRuntime::MapQuickView* mapView);

Esri::ArcGISRuntime::Map* m_map = nullptr;
Esri::ArcGISRuntime::MapQuickView* m_mapView = nullptr;
Esri::ArcGISRuntime::BasemapStyleParameters* basemapStyleParameters = nullptr;
Esri::ArcGISRuntime::Basemap* basemap = nullptr;
har13205 marked this conversation as resolved.
Show resolved Hide resolved
};

#endif // CONFIGUREBASEMAPSTYLELANGUAGE_H
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#-------------------------------------------------
# Copyright 2024 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.
#-------------------------------------------------

mac {
cache()
}

#-------------------------------------------------------------------------------

CONFIG += c++17

# additional modules are pulled in via arcgisruntime.pri
QT += opengl qml quick

TEMPLATE = app
TARGET = ConfigureBasemapStyleLanguage

ARCGIS_RUNTIME_VERSION = 200.4.0
include($$PWD/arcgisruntime.pri)

#-------------------------------------------------------------------------------

HEADERS += \
ConfigureBasemapStyleLanguage.h

SOURCES += \
main.cpp \
ConfigureBasemapStyleLanguage.cpp

RESOURCES += ConfigureBasemapStyleLanguage.qrc

#-------------------------------------------------------------------------------

win32 {
LIBS += \
Ole32.lib
}

ios {
INCLUDEPATH += $$PWD
DEPENDPATH += $$PWD

OTHER_FILES += \
$$PWD/Info.plist

QMAKE_INFO_PLIST = $$PWD/Info.plist
}

android {
INCLUDEPATH += $$PWD
DEPENDPATH += $$PWD
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
// [WriteFile Name=ConfigureBasemapStyleLanguage, Category=Maps]
// [Legal]
// Copyright 2024 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]

import QtQuick
import QtQuick.Controls
import Esri.Samples

Item {

// add a mapView component
MapView {
id: view
anchors.fill: parent

Component.onCompleted: {
// Set the focus on MapView to initially enable keyboard navigation
forceActiveFocus();
}
}

// Declare the C++ instance which creates the map etc. and supply the view
ConfigureBasemapStyleLanguageSample {
id: model
mapView: view
}

Rectangle {
id: rectangle
anchors {
right: parent.right
top: parent.top
margins: 15
}
width: column.width
height: column.height
color: Qt.rgba(0, 0, 0, 0.5)
border {
color: "black"
width: 1
}
opacity: 0.9

Column {
id: column
padding: 10
spacing: 5
width: 300

Column {
id:languageStrategy
spacing: 5

Text {
text: "Set Language Strategy:"
font.bold: true
color: "white"
}

Row {
RadioButton {
id: globalButton
onCheckedChanged: {
model.setNewBasemapLanguage(globalButton.checked, comboBox.currentText);
localButton.checked = !globalButton.checked
}
enabled: comboBox.currentText == "none"
}

Text {
id: globalText
text: "Global"
height: globalButton.height
verticalAlignment: Text.AlignVCenter
color: "white"
}
}

Row {
RadioButton {
id: localButton
checked: true
onCheckedChanged: {
model.setNewBasemapLanguage(globalButton.checked, comboBox.currentText);
globalButton.checked = !localButton.checked
}
enabled: comboBox.currentText == "none"
}
Text {
id: localText
text: "Local"
height: localButton.height
verticalAlignment: Text.AlignVCenter
color: "white"
}
}

}

Column {
id:specificLanguage

Text {
text: "Set Specific Language:"
font.bold: true
color: "white"
}

ComboBox {
id: comboBox
model: ["none" , "Bulgarian", "Greek", "Turkish"]
onCurrentTextChanged: model.setNewBasemapLanguage(globalButton.checked, comboBox.currentText);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per our offline discussion, I think this should be more intentional. It seems this executes when the code first loads, but it's unclear from looking at the c++ code how any basemap was loaded. I think the code should be more intentional about how the initial basemap is being set.

When I reviewed the latest code, I assumed no basemap at all was set, because that's what is happening on the C++ side via the constructor.

}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<RCC>
<qresource prefix="/Samples/Maps/ConfigureBasemapStyleLanguage">
<file alias="sample.json">README.metadata.json</file>
<file>ConfigureBasemapStyleLanguage.qml</file>
<file>ConfigureBasemapStyleLanguage.h</file>
<file>ConfigureBasemapStyleLanguage.cpp</file>
<file>main.qml</file>
<file>screenshot.png</file>
<file>README.md</file>
</qresource>
</RCC>
Loading
Loading