-
Notifications
You must be signed in to change notification settings - Fork 201
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
Changes from 20 commits
39988ec
4009a8b
edd0551
71acdd2
479515d
50c5414
0379821
d9783d2
3783d68
a9a465c
f64922c
1769e6d
8d3364e
41e07ec
5d36cdf
9f52d51
0b36d5b
cd68518
c4d12b1
0860c3d
7a6a3f5
dbc50f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,106 @@ | ||||||||||
// [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 "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), | ||||||||||
m_map(new Map(SpatialReference::webMercator())), | ||||||||||
m_basemapStyleParameters(new BasemapStyleParameters(this)) | ||||||||||
{ | ||||||||||
} | ||||||||||
|
||||||||||
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(SpatialReference::webMercator()); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is already done in the constructor. |
||||||||||
|
||||||||||
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 | ||||||||||
void ConfigureBasemapStyleLanguage::setNewBasemapLanguage(bool global, const QString& language) | ||||||||||
{ | ||||||||||
m_basemapStyleParameters->setLanguageStrategy(global ? BasemapStyleLanguageStrategy::Global : BasemapStyleLanguageStrategy::Local); | ||||||||||
|
||||||||||
// A SpecificLanguage setting overrides the LanguageStrategy settings | ||||||||||
if (language == "none") | ||||||||||
{ | ||||||||||
m_basemapStyleParameters->setSpecificLanguage(""); | ||||||||||
} | ||||||||||
else if (language == "Bulgarian") | ||||||||||
{ | ||||||||||
m_basemapStyleParameters->setSpecificLanguage("bg"); | ||||||||||
} | ||||||||||
else if (language == "Greek") | ||||||||||
{ | ||||||||||
m_basemapStyleParameters->setSpecificLanguage("el"); | ||||||||||
} | ||||||||||
else if (language == "Turkish") | ||||||||||
{ | ||||||||||
m_basemapStyleParameters->setSpecificLanguage("tr"); | ||||||||||
} | ||||||||||
|
||||||||||
if (m_basemap) | ||||||||||
delete m_basemap; | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I think your code works fine, but conceptually it feels wrong to delete the map's basemap while it's still displayed. We could write a bunch of extra code to change the order, but deleteLater does the same thing with less code. |
||||||||||
|
||||||||||
m_basemap = new Basemap(BasemapStyle::OsmLightGray, m_basemapStyleParameters, this); | ||||||||||
m_map->setBasemap(m_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* m_basemapStyleParameters = nullptr; | ||
Esri::ArcGISRuntime::Basemap* m_basemap = nullptr; | ||
}; | ||
|
||
#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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
memory leak
Also, does the map initially launch empty until users press a button? That doesn't seem optimal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, the map initially launches with
local
language strategy