diff --git a/CppSamples/DisplayInformation/DisplayGrid/DisplayGrid.cpp b/CppSamples/DisplayInformation/DisplayGrid/DisplayGrid.cpp deleted file mode 100644 index 6a05c39cae..0000000000 --- a/CppSamples/DisplayInformation/DisplayGrid/DisplayGrid.cpp +++ /dev/null @@ -1,315 +0,0 @@ -// [WriteFile Name=DisplayGrid, Category=DisplayInformation] -// [Legal] -// Copyright 2016 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 "DisplayGrid.h" - -// ArcGIS Maps SDK headers -#include "Grid.h" -#include "LatitudeLongitudeGrid.h" -#include "MGRSGrid.h" -#include "Map.h" -#include "MapQuickView.h" -#include "MapTypes.h" -#include "MapViewTypes.h" -#include "Point.h" -#include "SimpleLineSymbol.h" -#include "SpatialReference.h" -#include "SymbolTypes.h" -#include "TextSymbol.h" -#include "USNGGrid.h" -#include "UTMGrid.h" -#include "Viewpoint.h" - -using namespace Esri::ArcGISRuntime; - -const QString DisplayGrid::s_utmGrid = QStringLiteral("UTM"); -const QString DisplayGrid::s_usngGrid = QStringLiteral("USNG"); -const QString DisplayGrid::s_latlonGrid = QStringLiteral("LatLon"); -const QString DisplayGrid::s_mgrsGrid = QStringLiteral("MGRS"); -const QString DisplayGrid::s_ddFormat = QStringLiteral("Decimal degrees"); -const QString DisplayGrid::s_dmsFormat = QStringLiteral( "Degrees minutes seconds"); -const QString DisplayGrid::s_geographicPosition = QStringLiteral("Geographic"); -const QString DisplayGrid::s_bottomLeftPosition = QStringLiteral("Bottom left"); -const QString DisplayGrid::s_bottomRightPosition = QStringLiteral("Bottom right"); -const QString DisplayGrid::s_topLeftPosition = QStringLiteral("Top left"); -const QString DisplayGrid::s_topRightPosition = QStringLiteral("Top right"); -const QString DisplayGrid::s_centerPosition = QStringLiteral("Center"); -const QString DisplayGrid::s_allSidesPosition = QStringLiteral("All sides"); - -DisplayGrid::DisplayGrid(QQuickItem* parent /* = nullptr */): - QQuickItem(parent) -{ -} - -DisplayGrid::~DisplayGrid() = default; - -void DisplayGrid::init() -{ - qmlRegisterType("Esri.Samples", 1, 0, "MapView"); - qmlRegisterType("Esri.Samples", 1, 0, "DisplayGridSample"); -} - -void DisplayGrid::componentComplete() -{ - QQuickItem::componentComplete(); - - // find QML MapView component - m_mapView->setWrapAroundMode(WrapAroundMode::Disabled); - - // Create a map using the imagery basemap - m_map = new Map(BasemapStyle::ArcGISImageryStandard, this); - double targetScale = 6450785; - m_map->setInitialViewpoint(Viewpoint(Point(-10336141.70018318, 5418213.05332071, SpatialReference::webMercator()), targetScale)); - - // Set map to map view - m_mapView->setMap(m_map); -} - -// change the grid type -void DisplayGrid::changeGrid(const QString& gridType) -{ - if (gridType == latlonGrid()) - { - //! [DisplayGrid Set_LatLon_Grid_Cpp] - // create a grid for showing Latitude and Longitude (Meridians and Parallels) - LatitudeLongitudeGrid* latlonGrid = new LatitudeLongitudeGrid(this); - m_mapView->setGrid(latlonGrid); - //! [DisplayGrid Set_LatLon_Grid_Cpp] - } - else if (gridType == utmGrid()) - { - UTMGrid* utmGrid = new UTMGrid(this); - m_mapView->setGrid(utmGrid); - } - else if (gridType == usngGrid()) - { - USNGGrid* utmGrid = new USNGGrid(this); - m_mapView->setGrid(utmGrid); - } - else if (gridType == mgrsGrid()) - { - MGRSGrid* utmGrid = new MGRSGrid(this); - m_mapView->setGrid(utmGrid); - } - - // apply any styling that has been set - changeGridColor(currentGridColor()); - changeLabelColor(currentLabelColor()); - changeLabelFormat(currentLabelFormat()); - changeLabelPosition(currentLabelPosition()); - setGridLabelVisibility(gridVisibility()); - setGridVisibility(gridVisibility()); -} - -// change the grid color -void DisplayGrid::changeGridColor(const QString& color) -{ - if (m_mapView->grid()) - { - // find the number of resolution levels in the grid - int gridLevels = m_mapView->grid()->levelCount(); - - //! [DisplayGrid Set_Grid_Lines_Cpp] - for (int level = 0; level < gridLevels; level++) - { - const float width = 1 + level; - SimpleLineSymbol* lineSym = new SimpleLineSymbol(SimpleLineSymbolStyle::Solid, QColor(color), width, this); - m_mapView->grid()->setLineSymbol(level, lineSym); - } - //! [DisplayGrid Set_Grid_Lines_Cpp] - } -} - -// change the grid label color -void DisplayGrid::changeLabelColor(const QString& color) -{ - if (m_mapView->grid()) - { - //! [DisplayGrid Grid_Levels_Cpp] - // find the number of resolution levels in the grid - int gridLevels = m_mapView->grid()->levelCount(); - //! [DisplayGrid Grid_Levels_Cpp] - - //! [DisplayGrid Set_Grid_Labels_Cpp] - for (int level = 0; level < gridLevels; level++) - { - constexpr float size = 14.0f; - TextSymbol* textSym = new TextSymbol("text", QColor(color), size, HorizontalAlignment::Left, VerticalAlignment::Bottom, this); - textSym->setHaloColor(QColor("white")); - textSym->setHaloWidth(2.0f + level); - m_mapView->grid()->setTextSymbol(level, textSym); - } - //! [DisplayGrid Set_Grid_Labels_Cpp] - } -} - -// change the grid label format -void DisplayGrid::changeLabelFormat(const QString& format) -{ - if (m_mapView->grid()) - { - if (m_mapView->grid()->gridType() == GridType::LatitudeLongitudeGrid) - { - if (format == ddFormat()) - { - // format the labels to display in decimal degrees - static_cast(m_mapView->grid())->setLabelFormat(LatitudeLongitudeGridLabelFormat::DecimalDegrees); - } - else if (format == dmsFormat()) - { - //! [DisplayGrid Set_Label_Format_Cpp] - // format the labels to display in degrees, minutes and seconds - static_cast(m_mapView->grid())->setLabelFormat(LatitudeLongitudeGridLabelFormat::DegreesMinutesSeconds); - //! [DisplayGrid Set_Label_Format_Cpp] - } - } - } -} - -// change the grid label placement -void DisplayGrid::changeLabelPosition(const QString& position) -{ - if (m_mapView->grid()) - { - if (position == geographicPosition()) - { - //! [DisplayGrid Set_Label_Placement_Geographic_Cpp] - // update the label positioning to geographic - m_mapView->grid()->setLabelPosition(GridLabelPosition::Geographic); - //! [DisplayGrid Set_Label_Placement_Geographic_Cpp] - } - else if (position == bottomLeftPosition()) - { - // update the label positioning to bottom left - m_mapView->grid()->setLabelPosition(GridLabelPosition::BottomLeft); - } - else if (position == bottomRightPosition()) - { - // update the label positioning to bottom right - m_mapView->grid()->setLabelPosition(GridLabelPosition::BottomRight); - } - else if (position == topLeftPosition()) - { - // update the label positioning to top left - m_mapView->grid()->setLabelPosition(GridLabelPosition::TopLeft); - } - else if (position == topRightPosition()) - { - //! [DisplayGrid Set_Label_Placement_Top_Right_Cpp] - // update the label positioning to top right - m_mapView->grid()->setLabelPosition(GridLabelPosition::TopRight); - //! [DisplayGrid Set_Label_Placement_Top_Right_Cpp] - } - else if (position == centerPosition()) - { - // update the label positioning to center - m_mapView->grid()->setLabelPosition(GridLabelPosition::Center); - } - else if (position == allSidesPosition()) - { - // update the label positioning to all sides - m_mapView->grid()->setLabelPosition(GridLabelPosition::AllSides); - } - } -} - -MapQuickView* DisplayGrid::mapQuickView() const -{ - return m_mapView; -} - -void DisplayGrid::setMapQuickView(MapQuickView* mapView) -{ - m_mapView = mapView; - emit mapQuickViewChanged(); -} - -QString DisplayGrid::currentGridColor() const -{ - return m_currentGridColor; -} - -void DisplayGrid::setCurrentGridColor(const QString& gridColor) -{ - m_currentGridColor = gridColor; - changeGridColor(m_currentGridColor); -} - -QString DisplayGrid::currentLabelColor() const -{ - return m_currentLabelColor; -} - -void DisplayGrid::setCurrentLabelColor(const QString& labelColor) -{ - m_currentLabelColor = labelColor; - changeLabelColor(m_currentLabelColor); -} - -QString DisplayGrid::currentLabelFormat() const -{ - return m_currentLabelFormat; -} - -void DisplayGrid::setCurrentLabelFormat(const QString& labelFormat) -{ - m_currentLabelFormat = labelFormat; - changeLabelFormat(m_currentLabelFormat); -} - -QString DisplayGrid::currentLabelPosition() const -{ - return m_currentLabelPosition; -} - -void DisplayGrid::setCurrentLabelPosition(const QString& labelPosition) -{ - m_currentLabelPosition = labelPosition; - changeLabelPosition(m_currentLabelPosition); -} - -bool DisplayGrid::gridVisibility() -{ - return m_gridVisibility; -} - -void DisplayGrid::setGridVisibility(bool visible) -{ - m_gridVisibility = visible; - - //! [DisplayGrid Grid_Visible_Cpp] - m_mapView->grid()->setVisible(m_gridVisibility); - //! [DisplayGrid Grid_Visible_Cpp] -} - -bool DisplayGrid::gridLabelVisibility() -{ - return m_gridLabelVisibility; -} - -void DisplayGrid::setGridLabelVisibility(bool visible) -{ - m_gridLabelVisibility = visible; - - //! [DisplayGrid Label_Visible_Cpp] - m_mapView->grid()->setLabelsVisible(m_gridLabelVisibility); - //! [DisplayGrid Label_Visible_Cpp] -} diff --git a/CppSamples/DisplayInformation/DisplayGrid/DisplayGrid.h b/CppSamples/DisplayInformation/DisplayGrid/DisplayGrid.h deleted file mode 100644 index 4d282da385..0000000000 --- a/CppSamples/DisplayInformation/DisplayGrid/DisplayGrid.h +++ /dev/null @@ -1,144 +0,0 @@ -// [WriteFile Name=DisplayGrid, Category=DisplayInformation] -// [Legal] -// Copyright 2016 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 DISPLAYGRID_H -#define DISPLAYGRID_H - -// Qt headers -#include - -namespace Esri::ArcGISRuntime -{ - class Map; - class MapQuickView; -} - -Q_MOC_INCLUDE("MapQuickView.h") - -class DisplayGrid : public QQuickItem -{ - Q_OBJECT - - Q_PROPERTY(Esri::ArcGISRuntime::MapQuickView* mapView READ mapQuickView WRITE setMapQuickView NOTIFY mapQuickViewChanged) - - Q_PROPERTY(QString utmGrid READ utmGrid NOTIFY utmGridChanged) - Q_PROPERTY(QString usngGrid READ usngGrid NOTIFY usngGridChanged) - Q_PROPERTY(QString latlonGrid READ latlonGrid NOTIFY latlonGridChanged) - Q_PROPERTY(QString mgrsGrid READ mgrsGrid NOTIFY mgrsGridChanged) - Q_PROPERTY(QString ddFormat READ ddFormat NOTIFY ddFormatChanged) - Q_PROPERTY(QString dmsFormat READ dmsFormat NOTIFY dmsFormatChanged) - Q_PROPERTY(QString geographicPosition READ geographicPosition NOTIFY geographicPositionChanged) - Q_PROPERTY(QString bottomLeftPosition READ bottomLeftPosition NOTIFY bottomLeftPositionChanged) - Q_PROPERTY(QString bottomRightPosition READ bottomRightPosition NOTIFY bottomRightPositionChanged) - Q_PROPERTY(QString topLeftPosition READ topLeftPosition NOTIFY topLeftPositionChanged) - Q_PROPERTY(QString topRightPosition READ topRightPosition NOTIFY topRightPositionChanged) - Q_PROPERTY(QString centerPosition READ centerPosition NOTIFY centerPositionChanged) - Q_PROPERTY(QString allSidesPosition READ allSidesPosition NOTIFY allSidesPositionChanged) - Q_PROPERTY(QString currentGridColor READ currentGridColor WRITE setCurrentGridColor NOTIFY currentGridColorChanged) - Q_PROPERTY(QString currentLabelColor READ currentLabelColor WRITE setCurrentLabelColor NOTIFY currentLabelColorChanged) - Q_PROPERTY(QString currentLabelFormat READ currentLabelFormat WRITE setCurrentLabelFormat NOTIFY currentLabelFormatChanged) - Q_PROPERTY(QString currentLabelPosition READ currentLabelPosition WRITE setCurrentLabelPosition NOTIFY currentLabelPositionChanged) - Q_PROPERTY(bool gridVisibility READ gridVisibility WRITE setGridVisibility NOTIFY gridVisibilityChanged) - Q_PROPERTY(bool gridLabelVisibility READ gridLabelVisibility WRITE setGridLabelVisibility NOTIFY gridLabelVisibilityChanged) - -public: - explicit DisplayGrid(QQuickItem* parent = nullptr); - ~DisplayGrid() override; - - void componentComplete() override; - static void init(); - Q_INVOKABLE void changeGrid(const QString& gridType); - Q_INVOKABLE void changeGridColor(const QString& color); - Q_INVOKABLE void changeLabelColor(const QString& color); - Q_INVOKABLE void changeLabelFormat(const QString& format); - Q_INVOKABLE void changeLabelPosition(const QString& position); - -signals: - void utmGridChanged(); - void usngGridChanged(); - void latlonGridChanged(); - void mgrsGridChanged(); - void ddFormatChanged(); - void dmsFormatChanged(); - void geographicPositionChanged(); - void bottomLeftPositionChanged(); - void bottomRightPositionChanged(); - void topLeftPositionChanged(); - void topRightPositionChanged(); - void centerPositionChanged(); - void allSidesPositionChanged(); - void currentGridColorChanged(); - void currentLabelColorChanged(); - void currentLabelFormatChanged(); - void currentLabelPositionChanged(); - void gridVisibilityChanged(); - void gridLabelVisibilityChanged(); - void mapQuickViewChanged(); - -private: - static const QString utmGrid() { return s_utmGrid; } - static const QString usngGrid() { return s_usngGrid; } - static const QString latlonGrid() { return s_latlonGrid; } - static const QString mgrsGrid() { return s_mgrsGrid; } - static const QString ddFormat() { return s_ddFormat; } - static const QString dmsFormat() { return s_dmsFormat; } - static const QString geographicPosition() { return s_geographicPosition; } - static const QString bottomLeftPosition() { return s_bottomLeftPosition; } - static const QString bottomRightPosition() { return s_bottomRightPosition; } - static const QString topLeftPosition() { return s_topLeftPosition; } - static const QString topRightPosition() { return s_topRightPosition; } - static const QString centerPosition() { return s_centerPosition; } - static const QString allSidesPosition() { return s_allSidesPosition; } - Esri::ArcGISRuntime::MapQuickView* mapQuickView() const; - void setMapQuickView(Esri::ArcGISRuntime::MapQuickView* mapView); - QString currentGridColor() const; - void setCurrentGridColor(const QString& gridColor); - QString currentLabelColor() const; - void setCurrentLabelColor(const QString& labelColor); - QString currentLabelFormat() const; - void setCurrentLabelFormat(const QString& labelFormat); - QString currentLabelPosition() const; - void setCurrentLabelPosition(const QString& labelPosition); - bool gridVisibility(); - void setGridVisibility(bool visible); - bool gridLabelVisibility(); - void setGridLabelVisibility(bool visible); - -private: - Esri::ArcGISRuntime::Map* m_map = nullptr; - Esri::ArcGISRuntime::MapQuickView* m_mapView = nullptr; - static const QString s_utmGrid; - static const QString s_usngGrid; - static const QString s_latlonGrid; - static const QString s_mgrsGrid; - static const QString s_ddFormat; - static const QString s_dmsFormat; - static const QString s_geographicPosition; - static const QString s_bottomLeftPosition; - static const QString s_bottomRightPosition; - static const QString s_topLeftPosition; - static const QString s_topRightPosition; - static const QString s_centerPosition; - static const QString s_allSidesPosition; - QString m_currentGridColor = QStringLiteral("red"); - QString m_currentLabelColor = QStringLiteral("black"); - QString m_currentLabelFormat; - QString m_currentLabelPosition; - bool m_gridVisibility = true; - bool m_gridLabelVisibility = true; -}; - -#endif // DISPLAYGRID_H diff --git a/CppSamples/DisplayInformation/DisplayGrid/DisplayGrid.qrc b/CppSamples/DisplayInformation/DisplayGrid/DisplayGrid.qrc deleted file mode 100644 index 4c03c49b27..0000000000 --- a/CppSamples/DisplayInformation/DisplayGrid/DisplayGrid.qrc +++ /dev/null @@ -1,10 +0,0 @@ - - - README.metadata.json - screenshot.png - DisplayGrid.qml - DisplayGrid.h - DisplayGrid.cpp - README.md - - diff --git a/CppSamples/DisplayInformation/DisplayGrid/README.md b/CppSamples/DisplayInformation/DisplayGrid/README.md deleted file mode 100644 index dc0eccbda6..0000000000 --- a/CppSamples/DisplayInformation/DisplayGrid/README.md +++ /dev/null @@ -1,38 +0,0 @@ -# Display a grid - -Display coordinate system grids including Latitude/Longitude, MGRS, UTM and USNG on a map view. Also, toggle label visibility and change the color of grid lines and grid labels. - -![](screenshot.png) - -## Use case - -Grids are often used on printed maps, but can also be helpful on digital maps, to identify locations on a map. - -## How to use the sample - -Tap on the `Change Grid` button in the toolbar to open a settings view. You can select type of grid from `Grid Type` (LatLong, MGRS, UTM and USNG) and modify its properties like label visibility, grid line color, and grid label color. - -## How it works - -1. Create an instance of one of the `Grid` types. -1. Grid lines and labels can be styled per grid level with `setLineSymbol(gridLevel, lineSymbol)` and `setTextSymbol(gridLevel, textSymbol)` methods on the grid. -1. The label position can be set with `setLabelPosition(labelPosition)` method on the grid. -1. For the `LatitudeLongitudeGrid` type, you can specify a label format of `DecimalDegrees` or `DegreesMinutesSeconds`. -1. To set the grid, use the `setGrid(grid)` method on the map view. - -## Relevant API - -* ArcGISGrid -* LatitudeLongitudeGrid -* LatitudeLongitudeGridLabelFormat::DecimalDegrees -* LatitudeLongitudeGridLabelFormat::DegreesMinutesSeconds -* MapView -* MGRSGrid -* SimpleLineSymbol -* TextSymbol -* USNGGrid -* UTMGrid - -## Tags - -coordinates, degrees, graticule, grid, latitude, longitude, MGRS, minutes, seconds, USNG, UTM diff --git a/CppSamples/DisplayInformation/DisplayGrid/arcgisruntime.pri b/CppSamples/DisplayInformation/DisplayGrid/arcgisruntime.pri deleted file mode 100644 index 0a3989e404..0000000000 --- a/CppSamples/DisplayInformation/DisplayGrid/arcgisruntime.pri +++ /dev/null @@ -1,27 +0,0 @@ -#------------------------------------------------- -# Copyright 2017 ESRI -# -# All rights reserved under the copyright laws of the United States -# and applicable international laws, treaties, and conventions. -# -# You may freely redistribute and use this sample code, with or -# without modification, provided you include the original copyright -# notice and use restrictions. -# -# See the Sample code usage restrictions document for further information. -#------------------------------------------------- - -contains(QMAKE_HOST.os, Windows):{ - iniPath = $$(ALLUSERSPROFILE)\\EsriRuntimeQt\\ArcGIS Runtime SDK for Qt $${ARCGIS_RUNTIME_VERSION}.ini -} -else { - userHome = $$system(echo $HOME) - iniPath = $${userHome}/.config/EsriRuntimeQt/ArcGIS Runtime SDK for Qt $${ARCGIS_RUNTIME_VERSION}.ini -} -iniLine = $$cat($${iniPath}, "lines") -dirPath = $$find(iniLine, "InstallDir") -cleanDirPath = $$replace(dirPath, "InstallDir=", "") -priLocation = $$replace(cleanDirPath, '"', "") -!include($$priLocation/sdk/ideintegration/arcgis_runtime_qml_cpp.pri) { - message("Error. Cannot locate ArcGIS Runtime PRI file") -} diff --git a/CppSamples/DisplayInformation/DisplayGrid/screenshot.png b/CppSamples/DisplayInformation/DisplayGrid/screenshot.png deleted file mode 100644 index f6b2d7c04d..0000000000 Binary files a/CppSamples/DisplayInformation/DisplayGrid/screenshot.png and /dev/null differ diff --git a/CppSamples/DisplayInformation/DisplayGrid/Info.plist b/CppSamples/DisplayInformation/ShowGrid/Info.plist similarity index 92% rename from CppSamples/DisplayInformation/DisplayGrid/Info.plist rename to CppSamples/DisplayInformation/ShowGrid/Info.plist index 5e8b024576..d2ddec78f1 100644 --- a/CppSamples/DisplayInformation/DisplayGrid/Info.plist +++ b/CppSamples/DisplayInformation/ShowGrid/Info.plist @@ -3,9 +3,9 @@ CFBundleDisplayName - DisplayGrid + ShowGrid CFBundleExecutable - DisplayGrid + ShowGrid CFBundleGetInfoString ArcGIS CFBundleIcons~ipad @@ -48,8 +48,8 @@ UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight - UILaunchStoryboardName - LaunchScreen + UILaunchStoryboardName + LaunchScreen diff --git a/CppSamples/DisplayInformation/ShowGrid/README.md b/CppSamples/DisplayInformation/ShowGrid/README.md new file mode 100644 index 0000000000..18568020a2 --- /dev/null +++ b/CppSamples/DisplayInformation/ShowGrid/README.md @@ -0,0 +1,40 @@ +# Show grid + +Display and customize coordinate system grids including Latitude/Longitude, MGRS, UTM and USNG on a map view or scene view. + +![](screenshot.png) + +## Use case + +Grids are often used on printed maps, but can also be helpful on digital 2D maps or 3D scenes, to identify locations. + +## How to use the sample + +Tap on the `Change Grid` button in the toolbar to open a settings view. You can change the view from 2D or 3D, select the type of grid from `Grid Type` (LatLong, MGRS, UTM, and USNG) and modify its properties like label visibility, grid line color, grid label color, and label formatting. + +## How it works + +1. Create an instance of one of the `Grid` types. +2. Grid lines and labels can be styled per grid level with `setLineSymbol(gridLevel, lineSymbol)` and `setTextSymbol(gridLevel, textSymbol)` methods on the grid. +3. The label position can be set with `setLabelPosition(labelPosition)` method on the grid. + * Note that as of 200.6, MGRS, UTM, and USNG grids in a SceneView only support the `Geographic` label position. +4. For the `LatitudeLongitudeGrid` type, you can specify a label format of `DECIMAL_DEGREES` or `DEGREES_MINUTES_SECONDS`. +5. To set the grid, use the `setGrid(grid)` method on the map view or scene view. + +## Relevant API + +* ArcGISGrid +* LatitudeLongitudeGrid +* LatitudeLongitudeGridLabelFormat::DecimalDegrees +* LatitudeLongitudeGridLabelFormat::DegreesMinutesSeconds +* MapView +* MGRSGrid +* SceneView +* SimpleLineSymbol +* TextSymbol +* USNGGrid +* UTMGrid + +## Tags + +coordinates, degrees, graticule, grid, latitude, longitude, MGRS, minutes, seconds, USNG, UTM diff --git a/CppSamples/DisplayInformation/DisplayGrid/README.metadata.json b/CppSamples/DisplayInformation/ShowGrid/README.metadata.json similarity index 78% rename from CppSamples/DisplayInformation/DisplayGrid/README.metadata.json rename to CppSamples/DisplayInformation/ShowGrid/README.metadata.json index bb372c6023..b0cdd37438 100644 --- a/CppSamples/DisplayInformation/DisplayGrid/README.metadata.json +++ b/CppSamples/DisplayInformation/ShowGrid/README.metadata.json @@ -1,6 +1,6 @@ { "category": "Display information", - "description": "Display coordinate system grids including Latitude/Longitude, MGRS, UTM and USNG on a map view. Also, toggle label visibility and change the color of grid lines and grid labels.", + "description": "Display and customize coordinate system grids including Latitude/Longitude, MGRS, UTM and USNG on a map view or scene view.", "featured": false, "ignore": false, "images": [ @@ -25,6 +25,7 @@ "MGRSGrid", "MapView", "SimpleLineSymbol", + "SceneView", "TextSymbol", "USNGGrid", "UTMGrid" @@ -40,14 +41,15 @@ "MGRSGrid", "MapView", "SimpleLineSymbol", + "SceneView", "TextSymbol", "USNGGrid", "UTMGrid" ], "snippets": [ - "DisplayGrid.cpp", - "DisplayGrid.h", - "DisplayGrid.qml" + "ShowGrid.cpp", + "ShowGrid.h", + "ShowGrid.qml" ], - "title": "Display a grid" + "title": "Show grid" } diff --git a/CppSamples/DisplayInformation/ShowGrid/ShowGrid.cpp b/CppSamples/DisplayInformation/ShowGrid/ShowGrid.cpp new file mode 100644 index 0000000000..73d86ad5e7 --- /dev/null +++ b/CppSamples/DisplayInformation/ShowGrid/ShowGrid.cpp @@ -0,0 +1,266 @@ +// [WriteFile Name=ShowGrid, Category=DisplayInformation] +// [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 "ShowGrid.h" + +#include "ArcGISTiledElevationSource.h" +#include "ElevationSourceListModel.h" +#include "LatitudeLongitudeGrid.h" +#include "Map.h" +#include "MapTypes.h" +#include "MapQuickView.h" +#include "MapViewTypes.h" +#include "MGRSGrid.h" +#include "Point.h" +#include "Scene.h" +#include "SceneQuickView.h" +#include "SimpleLineSymbol.h" +#include "SpatialReference.h" +#include "Surface.h" +#include "TextSymbol.h" +#include "USNGGrid.h" +#include "UTMGrid.h" +#include "Viewpoint.h" + +#include + +using namespace Esri::ArcGISRuntime; + +ShowGrid::ShowGrid(QObject* parent /* = nullptr */): + QObject(parent), + m_map(new Map(BasemapStyle::ArcGISImagery, this)), + m_scene(new Scene(BasemapStyle::ArcGISImagery, this)) +{ + // create a new elevation source from Terrain3D REST service + ArcGISTiledElevationSource* elevationSource = new ArcGISTiledElevationSource( + QUrl("https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer"), this); + + // add the elevation source to the scene to display elevation + m_scene->baseSurface()->elevationSources()->append(elevationSource); + + // Set the sample's initial GeoView type to MapView + m_currentViewType = s_mapView; + + // Set the initial viewpoint of the map + constexpr double targetScale = 6450785; + m_map->setInitialViewpoint(Viewpoint(Point(-10336141.70018318, 5418213.05332071, SpatialReference::webMercator()), targetScale)); + + // Set the intial grid to LatitudeLongitudeGrid + m_grid = new LatitudeLongitudeGrid(this); +} + +ShowGrid::~ShowGrid() = default; + +void ShowGrid::init() +{ + // Register classes for QML + qmlRegisterType("Esri.Samples", 1, 0, "MapView"); + qmlRegisterType("Esri.Samples", 1, 0, "SceneView"); + qmlRegisterType("Esri.Samples", 1, 0, "ShowGridSample"); +} + +MapQuickView* ShowGrid::mapView() const +{ + return m_mapView; +} + +// Set the view (created in QML) +void ShowGrid::setMapView(MapQuickView* mapView) +{ + if (!mapView || mapView == m_mapView) + return; + + m_mapView = mapView; + m_mapView->setMap(m_map); + + m_mapView->setGrid(m_grid); + + emit mapViewChanged(); +} + +SceneQuickView* ShowGrid::sceneView() const +{ + return m_sceneView; +} + +// Set the view (created in QML) +void ShowGrid::setSceneView(SceneQuickView* sceneView) +{ + if (!sceneView || sceneView == m_sceneView) + return; + + m_sceneView = sceneView; + m_sceneView->setArcGISScene(m_scene); + + // Set the SceneView initially to be invisible + m_sceneView->setVisible(false); + + emit sceneViewChanged(); +} + + +void ShowGrid::setViewType(const QString& viewType) +{ + if (m_currentViewType == viewType) + return; + + m_currentViewType = viewType; + + // MapView and SceneView share the same inherited class GeoView + GeoView* newGeoView = viewType == s_mapView ? dynamic_cast(m_mapView) : dynamic_cast(m_sceneView); + GeoView* oldGeoView = viewType != s_mapView ? dynamic_cast(m_mapView) : dynamic_cast(m_sceneView); + + // Set the viewpoint of the new view to the current viewpoint of the old view + newGeoView->setViewpointAsync(oldGeoView->currentViewpoint(ViewpointType::BoundingGeometry), 0); + + // The Grid cannot be shared between a MapView and a SceneView so we need to unset it first + oldGeoView->setGrid(nullptr); + newGeoView->setGrid(m_grid); + + emit viewTypeChanged(); +} + +void ShowGrid::setGridType(const QString& gridType) +{ + if (m_currentGridType == gridType) + return; + + m_currentGridType = gridType; + + if (m_grid) + { + delete m_grid; + m_grid = nullptr; + } + + // Create a new Grid of the selected type + if (gridType == s_latLong) + m_grid = new LatitudeLongitudeGrid(this); + else if (gridType == s_mgrs) + m_grid = new MGRSGrid(this); + else if (gridType == s_utm) + m_grid = new UTMGrid(this); + else if (gridType == s_usng) + m_grid = new USNGGrid(this); + + // Set the grid on the current view + if (m_currentViewType == s_mapView) + m_mapView->setGrid(m_grid); + else + m_sceneView->setGrid(m_grid); + + // Set properties from current UI values + setGridVisible(m_gridVisible); + setLabelsVisible(m_labelsVisible); + setLineColor(m_currentLineColor); + setLabelColor(m_currentLabelColor); + setLabelPosition(m_currentLabelPosition); + setLabelFormat(m_currentLabelFormat); + + emit gridTypeChanged(); +} + +void ShowGrid::setGridVisible(bool visible) +{ + if (m_grid->isVisible() == visible) + return; + + m_gridVisible = visible; + m_grid->setVisible(visible); + + emit gridVisibleChanged(); +} + +void ShowGrid::setLabelsVisible(bool visible) +{ + if (m_grid->isLabelsVisible() == visible) + return; + + m_labelsVisible = visible; + m_grid->setLabelsVisible(visible); + + emit labelsVisibleChanged(); +} + +void ShowGrid::setLineColor(const QString& lineColor) +{ + m_currentLineColor = lineColor; + + SimpleLineSymbol* lineSymbol = static_cast(m_grid->lineSymbol(0)); + lineSymbol->setColor(lineColor.toLower()); + + // Some grids have multiple levels, in this sample we set the same symbol for all levels + for (int level = 0; level < m_grid->levelCount(); ++level) + m_grid->setLineSymbol(level, lineSymbol); + + emit lineColorChanged(); +} + +void ShowGrid::setLabelColor(const QString& labelColor) +{ + m_currentLabelColor = labelColor; + + TextSymbol* labelSymbol = static_cast(m_grid->textSymbol(0)); + labelSymbol->setColor(labelColor.toLower()); + + // Some grids have multiple levels, in this sample we set the same symbol for all levels + for (int level = 0; level < m_grid->levelCount(); ++level) + m_grid->setTextSymbol(level, labelSymbol); + + emit labelColorChanged(); +} + +void ShowGrid::setLabelPosition(const QString& labelPosition) +{ + m_currentLabelPosition = labelPosition; + + if (labelPosition == s_geographic) + m_grid->setLabelPosition(GridLabelPosition::Geographic); + else if (labelPosition == s_bottomLeft) + m_grid->setLabelPosition(GridLabelPosition::BottomLeft); + else if (labelPosition == s_bottomRight) + m_grid->setLabelPosition(GridLabelPosition::BottomRight); + else if (labelPosition == s_topLeft) + m_grid->setLabelPosition(GridLabelPosition::TopLeft); + else if (labelPosition == s_topRight) + m_grid->setLabelPosition(GridLabelPosition::TopRight); + else if (labelPosition == s_center) + m_grid->setLabelPosition(GridLabelPosition::Center); + else if (labelPosition == s_allSides) + m_grid->setLabelPosition(GridLabelPosition::AllSides); + + emit labelPositionChanged(); +} + +void ShowGrid::setLabelFormat(const QString& labelFormat) +{ + m_currentLabelFormat = labelFormat; + + // Only LatitudeLongitudeGrid supports label formats + if (m_grid->gridType() != GridType::LatitudeLongitudeGrid) + return; + + if (labelFormat == s_decimalDegrees) + static_cast(m_grid)->setLabelFormat(LatitudeLongitudeGridLabelFormat::DecimalDegrees); + else if (labelFormat == s_degreesMinutesSeconds) + static_cast(m_grid)->setLabelFormat(LatitudeLongitudeGridLabelFormat::DegreesMinutesSeconds); + + emit labelFormatChanged(); +} diff --git a/CppSamples/DisplayInformation/ShowGrid/ShowGrid.h b/CppSamples/DisplayInformation/ShowGrid/ShowGrid.h new file mode 100644 index 0000000000..8e9a86d1e4 --- /dev/null +++ b/CppSamples/DisplayInformation/ShowGrid/ShowGrid.h @@ -0,0 +1,140 @@ +// [WriteFile Name=ShowGrid, Category=DisplayInformation] +// [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 SHOWGRID_H +#define SHOWGRID_H + +#include + +namespace Esri::ArcGISRuntime +{ +class Grid; +class Map; +class MapQuickView; +class Scene; +class SceneQuickView; +class SimpleLineSymbol; +class TextSymbol; +} + +Q_MOC_INCLUDE("MapQuickView.h"); +Q_MOC_INCLUDE("SceneQuickView.h"); + +class ShowGrid : public QObject +{ + Q_OBJECT + + Q_PROPERTY(Esri::ArcGISRuntime::MapQuickView* mapView READ mapView WRITE setMapView NOTIFY mapViewChanged) + Q_PROPERTY(Esri::ArcGISRuntime::SceneQuickView* sceneView READ sceneView WRITE setSceneView NOTIFY sceneViewChanged) + Q_PROPERTY(QString currentViewType MEMBER m_currentViewType NOTIFY viewTypeChanged) + Q_PROPERTY(QStringList viewTypes MEMBER m_viewTypes CONSTANT) + Q_PROPERTY(QString currentGridType MEMBER m_currentGridType NOTIFY gridTypeChanged) + Q_PROPERTY(QStringList gridTypes MEMBER m_gridTypes CONSTANT) + Q_PROPERTY(bool gridVisible MEMBER m_gridVisible NOTIFY gridVisibleChanged) + Q_PROPERTY(bool labelsVisible MEMBER m_labelsVisible NOTIFY labelsVisibleChanged) + Q_PROPERTY(QString currentLineColor MEMBER m_currentLineColor NOTIFY lineColorChanged) + Q_PROPERTY(QStringList lineColors MEMBER m_lineColors CONSTANT) + Q_PROPERTY(QString currentLabelColor MEMBER m_currentLabelColor NOTIFY labelColorChanged) + Q_PROPERTY(QStringList labelColors MEMBER m_labelColors CONSTANT) + Q_PROPERTY(QString currentLabelPosition MEMBER m_currentLabelPosition NOTIFY labelPositionChanged) + Q_PROPERTY(QStringList labelFormats MEMBER m_labelFormats CONSTANT) + Q_PROPERTY(QString currentLabelFormat MEMBER m_currentLabelFormat NOTIFY labelFormatChanged) + Q_PROPERTY(QStringList labelPositions MEMBER m_labelPositions CONSTANT) + +public: + explicit ShowGrid(QObject* parent = nullptr); + ~ShowGrid() override; + + static void init(); + + Q_INVOKABLE void setGridVisible(bool visible); + Q_INVOKABLE void setLabelsVisible(bool visible); + Q_INVOKABLE void setViewType(const QString& viewType); + Q_INVOKABLE void setGridType(const QString& gridType); + Q_INVOKABLE void setLineColor(const QString& lineColor); + Q_INVOKABLE void setLabelColor(const QString& labelColor); + Q_INVOKABLE void setLabelPosition(const QString& labelPosition); + Q_INVOKABLE void setLabelFormat(const QString& labelFormat); + +signals: + void mapViewChanged(); + void sceneViewChanged(); + void viewTypeChanged(); + void gridTypeChanged(); + void gridVisibleChanged(); + void labelsVisibleChanged(); + void lineColorChanged(); + void labelColorChanged(); + void labelPositionChanged(); + void labelFormatChanged(); + +private: + // Declare private methods + Esri::ArcGISRuntime::MapQuickView* mapView() const; + void setMapView(Esri::ArcGISRuntime::MapQuickView* mapView); + Esri::ArcGISRuntime::SceneQuickView* sceneView() const; + void setSceneView(Esri::ArcGISRuntime::SceneQuickView* sceneView); + + // Declare private members + Esri::ArcGISRuntime::Grid* m_grid = nullptr; + Esri::ArcGISRuntime::Map* m_map = nullptr; + Esri::ArcGISRuntime::MapQuickView* m_mapView = nullptr; + Esri::ArcGISRuntime::Scene* m_scene = nullptr; + Esri::ArcGISRuntime::SceneQuickView* m_sceneView = nullptr; + + // Properties + QString m_currentViewType; + QString m_currentGridType; + bool m_gridVisible = true; + bool m_labelsVisible = true; + QString m_currentLineColor; + QString m_currentLabelColor; + QString m_currentLabelPosition; + QString m_currentLabelFormat; + + // Constants + const QString s_mapView = QStringLiteral("MapView"); + const QString s_sceneView = QStringLiteral("SceneView"); + const QStringList m_viewTypes = {s_mapView, s_sceneView}; + + const QString s_latLong = QStringLiteral("LatLong"); + const QString s_mgrs = QStringLiteral("MGRS"); + const QString s_utm = QStringLiteral("UTM"); + const QString s_usng = QStringLiteral("USNG"); + const QStringList m_gridTypes = {s_latLong, s_mgrs, s_utm, s_usng}; + + const QString s_white = QStringLiteral("White"); + const QString s_red = QStringLiteral("Red"); + const QString s_blue = QStringLiteral("Blue"); + const QString s_black = QStringLiteral("Black"); + const QStringList m_lineColors = {s_white, s_red, s_blue}; + const QStringList m_labelColors = {s_black, s_red, s_blue}; + + const QString s_geographic = QStringLiteral("Geographic"); + const QString s_topLeft = QStringLiteral("Top Left"); + const QString s_topRight = QStringLiteral("Top Right"); + const QString s_bottomLeft = QStringLiteral("Bottom Left"); + const QString s_bottomRight = QStringLiteral("Bottom Right"); + const QString s_center = QStringLiteral("Center"); + const QString s_allSides = QStringLiteral("All sides"); + const QStringList m_labelPositions = {s_geographic, s_topLeft, s_topRight, s_bottomLeft, s_bottomRight, s_center, s_allSides}; + + const QString s_decimalDegrees = QStringLiteral("Decimal Degrees"); + const QString s_degreesMinutesSeconds = QStringLiteral("Degrees Minutes Seconds"); + const QStringList m_labelFormats = {s_decimalDegrees, s_degreesMinutesSeconds}; +}; + +#endif // SHOWGRID_H diff --git a/CppSamples/DisplayInformation/DisplayGrid/DisplayGrid.pro b/CppSamples/DisplayInformation/ShowGrid/ShowGrid.pro similarity index 81% rename from CppSamples/DisplayInformation/DisplayGrid/DisplayGrid.pro rename to CppSamples/DisplayInformation/ShowGrid/ShowGrid.pro index c7111cdc43..3f4851e29e 100644 --- a/CppSamples/DisplayInformation/DisplayGrid/DisplayGrid.pro +++ b/CppSamples/DisplayInformation/ShowGrid/ShowGrid.pro @@ -1,5 +1,5 @@ #------------------------------------------------- -# Copyright 2015 Esri. +# 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. @@ -28,27 +28,35 @@ ARCGIS_RUNTIME_VERSION = 200.6.0 include($$PWD/arcgisruntime.pri) TEMPLATE = app -TARGET = DisplayGrid +TARGET = ShowGrid + +ARCGIS_RUNTIME_VERSION = 200.6.0 +include($$PWD/arcgisruntime.pri) #------------------------------------------------------------------------------- -HEADERS += DisplayGrid.h +HEADERS += \ + ShowGrid.h -SOURCES += main.cpp DisplayGrid.cpp +SOURCES += \ + main.cpp \ + ShowGrid.cpp -RESOURCES += DisplayGrid.qrc +RESOURCES += ShowGrid.qrc #------------------------------------------------------------------------------- win32 { - LIBS += Ole32.lib + LIBS += \ + Ole32.lib } ios { INCLUDEPATH += $$PWD DEPENDPATH += $$PWD - OTHER_FILES += $$PWD/Info.plist + OTHER_FILES += \ + $$PWD/Info.plist QMAKE_INFO_PLIST = $$PWD/Info.plist } @@ -57,4 +65,3 @@ android { INCLUDEPATH += $$PWD DEPENDPATH += $$PWD } - diff --git a/CppSamples/DisplayInformation/DisplayGrid/DisplayGrid.qml b/CppSamples/DisplayInformation/ShowGrid/ShowGrid.qml similarity index 66% rename from CppSamples/DisplayInformation/DisplayGrid/DisplayGrid.qml rename to CppSamples/DisplayInformation/ShowGrid/ShowGrid.qml index e895db9e21..e468633a3e 100644 --- a/CppSamples/DisplayInformation/DisplayGrid/DisplayGrid.qml +++ b/CppSamples/DisplayInformation/ShowGrid/ShowGrid.qml @@ -1,6 +1,6 @@ -// [WriteFile Name=DisplayGrid, Category=DisplayInformation] +// [WriteFile Name=ShowGrid, Category=DisplayInformation] // [Legal] -// Copyright 2016 Esri. +// 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. @@ -19,24 +19,115 @@ import QtQuick.Controls import QtQuick.Layouts import Esri.Samples -DisplayGridSample { - id: displayGrid - clip: true - width: 800 - height: 600 - - property real centerWindowY: (displayGrid.height / 2) - (styleWindow.height / 2) +Item { + id: root + property real centerWindowY: (root.height / 2) - (styleWindow.height / 2) MapView { id: mapQuickView anchors.fill: parent - + visible: gridSample.currentViewType == "MapView" Component.onCompleted: { - // Set the focus on MapView to initially enable keyboard navigation + // Set and keep the focus on SceneView to enable keyboard navigation forceActiveFocus(); } } - mapView: mapQuickView + + SceneView { + id: sceneQuickView + anchors.fill: parent + visible: gridSample.currentViewType == "SceneView" + } + + // Declare the C++ instance which creates the map, scene etc. and supply the views + ShowGridSample { + id: gridSample + mapView: mapQuickView + sceneView: sceneQuickView + + onCurrentViewTypeChanged: { + if (gridSample.currentViewType === "MapView") + mapQuickView.forceActiveFocus(); + else + sceneQuickView.forceActiveFocus(); + } + } + + Row { + id: viewButtonsRow + anchors { + top: parent.top + horizontalCenter: parent.horizontalCenter + topMargin: 5 + } + + spacing: 2 + + Rectangle { + id: mapViewButton + property bool selected: gridSample.currentViewType === "MapView" + + width: 100 + height: 30 + + color: selected ? "#959595" : "#D6D6D6" + radius: 8 + border { + color: selected ? "#7938b6" : "#585858" + width: selected ? 2 : 1 + } + + Text { + anchors.centerIn: parent + text: "Map View" + font.pixelSize: 14 + color: "#474747" + } + + MouseArea { + anchors.fill: parent + onClicked: { + gridSample.setViewType("MapView"); + positionCombo.enabled = true; + } + } + } + + Rectangle { + id: sceneViewButton + property bool selected: gridSample.currentViewType === "SceneView" + + width: 100 + height: 30 + + color: selected ? "#959595" : "#D6D6D6" + radius: 8 + border { + color: selected ? "#7938b6" : "#585858" + width: selected ? 2 : 1 + } + + Text { + anchors.centerIn: parent + text: "Scene View" + font.pixelSize: 14 + color: "#474747" + } + + MouseArea { + anchors.fill: parent + onClicked: { + gridSample.setViewType("SceneView"); + if (gridTypeComboBox.currentText !== "LatLong") { + positionCombo.currentIndex = 0; + positionCombo.enabled = false; + } else { + positionCombo.enabled = true; + } + } + } + } + } // Button to view the styling window Rectangle { @@ -95,7 +186,9 @@ DisplayGridSample { Rectangle { id: styleWindow - anchors.horizontalCenter: parent.horizontalCenter + anchors { + horizontalCenter: parent.horizontalCenter + } y: parent.height // initially display below the page height: childrenRect.height width: childrenRect.width @@ -114,7 +207,7 @@ DisplayGridSample { SequentialAnimation { id: hideAnimation - NumberAnimation { target: styleWindow; property: "y"; to: displayGrid.height; duration: 200 } + NumberAnimation { target: styleWindow; property: "y"; to: root.height; duration: 200 } } GridLayout { @@ -132,8 +225,16 @@ DisplayGridSample { Layout.minimumWidth: modelWidth + leftPadding + rightPadding + (indicator ? indicator.width : 10) Layout.rightMargin: 10 Layout.fillWidth: true - model: [latlonGrid, mgrsGrid, utmGrid, usngGrid] - onCurrentTextChanged: changeGrid(currentText) + model: gridSample.gridTypes + onCurrentTextChanged: { + gridSample.setGridType(currentText) + if (currentText !== "LatLong" && gridSample.currentViewType === "SceneView") { + positionCombo.currentIndex = 0; + positionCombo.enabled = false; + } else { + positionCombo.enabled = true; + } + } Component.onCompleted : { for (let i = 0; i < model.length; ++i) { metricsGridTypeComboBox.text = model[i]; @@ -147,30 +248,30 @@ DisplayGridSample { } Text { - text: "Labels visible" Layout.leftMargin: 10 - enabled: gridVisibleSwitch.checked - color: enabled ? "black" : "gray" + text: "Grid visible" } Switch { - id: labelVisibleSwitch + id: gridVisibleSwitch Layout.rightMargin: 10 - checked: true - enabled: gridVisibleSwitch.checked - onCheckedChanged: gridLabelVisibility = checked + checked: gridSample.gridVisible + onCheckedChanged: gridSample.setGridVisible(checked); } Text { + text: "Labels visible" Layout.leftMargin: 10 - text: "Grid visible" + enabled: gridVisibleSwitch.checked + color: enabled ? "black" : "gray" } Switch { - id: gridVisibleSwitch + id: labelVisibleSwitch Layout.rightMargin: 10 - checked: true - onCheckedChanged: gridVisibility = checked + checked: gridSample.labelsVisible + enabled: gridVisibleSwitch.checked + onCheckedChanged: gridSample.setLabelsVisible(checked); } Text { @@ -184,8 +285,8 @@ DisplayGridSample { Layout.minimumWidth: modelWidth + leftPadding + rightPadding + (indicator ? indicator.width : 10) Layout.rightMargin: 10 Layout.fillWidth: true - model: ["red", "white", "blue"] - onCurrentTextChanged: currentGridColor = currentText + model: gridSample.lineColors + onCurrentTextChanged: gridSample.setLineColor(currentText); Component.onCompleted : { for (let i = 0; i < model.length; ++i) { colorComboMetrics.text = model[i]; @@ -209,8 +310,8 @@ DisplayGridSample { Layout.minimumWidth: modelWidth + leftPadding + rightPadding + (indicator ? indicator.width : 10) Layout.rightMargin: 10 Layout.fillWidth: true - model: ["red", "black", "blue"] - onCurrentTextChanged: currentLabelColor = currentText; + model: gridSample.labelColors + onCurrentTextChanged: gridSample.setLabelColor(currentText); Component.onCompleted : { for (let i = 0; i < model.length; ++i) { colorCombo2Metrics.text = model[i]; @@ -226,6 +327,7 @@ DisplayGridSample { Text { Layout.leftMargin: 10 text: "Label position" + enabled: positionCombo.enabled color: enabled ? "black" : "gray" } @@ -235,8 +337,8 @@ DisplayGridSample { Layout.minimumWidth: modelWidth + leftPadding + rightPadding + (indicator ? indicator.width : 10) Layout.rightMargin: 10 Layout.fillWidth: true - model: [geographicPosition, bottomLeftPosition, bottomRightPosition, topLeftPosition, topRightPosition, centerPosition, allSidesPosition] - onCurrentTextChanged: currentLabelPosition = currentText; + model: gridSample.labelPositions + onCurrentTextChanged: gridSample.setLabelPosition(currentText); Component.onCompleted : { for (let i = 0; i < model.length; ++i) { positionComboMetrics.text = model[i]; @@ -252,7 +354,7 @@ DisplayGridSample { Text { Layout.leftMargin: 10 text: "Label format" - enabled: gridTypeComboBox.currentText == latlonGrid + enabled: formatCombo.enabled color: enabled ? "black" : "gray" } @@ -262,9 +364,9 @@ DisplayGridSample { Layout.minimumWidth: modelWidth + leftPadding + rightPadding + (indicator ? indicator.width : 10) Layout.rightMargin: 10 Layout.fillWidth: true - model: [ddFormat, dmsFormat] - enabled: gridTypeComboBox.currentText == latlonGrid - onCurrentTextChanged: currentLabelFormat = currentText; + model: gridSample.labelFormats + enabled: gridSample.currentGridType === "LatLong" + onCurrentTextChanged: gridSample.setLabelFormat(currentText); Component.onCompleted : { for (let i = 0; i < model.length; ++i) { formatComboMetrics.text = model[i]; @@ -307,7 +409,7 @@ DisplayGridSample { onReleased: hideButton.pressed = false onClicked: { background.visible = false; - hideAnimation.restart() + hideAnimation.restart(); } } } diff --git a/CppSamples/DisplayInformation/ShowGrid/ShowGrid.qrc b/CppSamples/DisplayInformation/ShowGrid/ShowGrid.qrc new file mode 100644 index 0000000000..91524ad8ed --- /dev/null +++ b/CppSamples/DisplayInformation/ShowGrid/ShowGrid.qrc @@ -0,0 +1,11 @@ + + + README.metadata.json + ShowGrid.qml + ShowGrid.h + ShowGrid.cpp + main.qml + screenshot.png + README.md + + diff --git a/CppSamples/DisplayInformation/ShowGrid/arcgisruntime.pri b/CppSamples/DisplayInformation/ShowGrid/arcgisruntime.pri new file mode 100644 index 0000000000..23b71ebbe0 --- /dev/null +++ b/CppSamples/DisplayInformation/ShowGrid/arcgisruntime.pri @@ -0,0 +1,29 @@ +#------------------------------------------------- +# 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. +#------------------------------------------------- + +contains(QMAKE_HOST.os, Windows):{ + iniPath = $$(ALLUSERSPROFILE)\EsriRuntimeQt\ArcGIS Runtime SDK for Qt $${ARCGIS_RUNTIME_VERSION}.ini +} +else { + userHome = $$system(echo $HOME) + iniPath = $${userHome}/.config/EsriRuntimeQt/ArcGIS Runtime SDK for Qt $${ARCGIS_RUNTIME_VERSION}.ini +} +iniLine = $$cat($${iniPath}, "lines") +dirPath = $$find(iniLine, "InstallDir") +cleanDirPath = $$replace(dirPath, "InstallDir=", "") +priLocation = $$replace(cleanDirPath, '"', "") +!include($$priLocation/sdk/ideintegration/arcgis_runtime_qml_cpp.pri) { + message("Error. Cannot locate ArcGIS Runtime PRI file") +} diff --git a/CppSamples/DisplayInformation/DisplayGrid/main.cpp b/CppSamples/DisplayInformation/ShowGrid/main.cpp similarity index 56% rename from CppSamples/DisplayInformation/DisplayGrid/main.cpp rename to CppSamples/DisplayInformation/ShowGrid/main.cpp index faaad0fdbb..65b0deae27 100644 --- a/CppSamples/DisplayInformation/DisplayGrid/main.cpp +++ b/CppSamples/DisplayInformation/ShowGrid/main.cpp @@ -1,5 +1,4 @@ -// [Legal] -// Copyright 2015 Esri. +// 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. @@ -11,33 +10,24 @@ // 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] -// sample headers -#include "DisplayGrid.h" +#include "ShowGrid.h" -// ArcGIS Maps SDK headers #include "ArcGISRuntimeEnvironment.h" -// Qt headers #include #include #include -#include -#include +#include -// Platform specific headers #ifdef Q_OS_WIN #include #endif -#define STRINGIZE(x) #x -#define QUOTE(x) STRINGIZE(x) - int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); - app.setApplicationName(QString("Display Grid")); + app.setApplicationName(QString("ShowGrid")); // Use of ArcGIS location services, such as basemap styles, geocoding, and routing services, // requires an access token. For more information see @@ -57,40 +47,28 @@ int main(int argc, char *argv[]) if (accessToken.isEmpty()) { - qWarning() << "Use of ArcGIS location services, such as the basemap styles service, requires" << - "you to authenticate with an ArcGIS account or set the API Key property."; + qWarning() << "Use of ArcGIS location services, such as the basemap styles service, requires" << + "you to authenticate with an ArcGIS account or set the API Key property."; } else { - Esri::ArcGISRuntime::ArcGISRuntimeEnvironment::setApiKey(accessToken); + Esri::ArcGISRuntime::ArcGISRuntimeEnvironment::setApiKey(accessToken); } // Initialize the sample - DisplayGrid::init(); + ShowGrid::init(); // Initialize application view - QQuickView view; - view.setResizeMode(QQuickView::SizeRootObjectToView); - + QQmlApplicationEngine engine; // Add the import Path - view.engine()->addImportPath(QDir(QCoreApplication::applicationDirPath()).filePath("qml")); - - QString arcGISRuntimeImportPath = QUOTE(ARCGIS_RUNTIME_IMPORT_PATH); + engine.addImportPath(QDir(QCoreApplication::applicationDirPath()).filePath("qml")); - #if defined(LINUX_PLATFORM_REPLACEMENT) - // on some linux platforms the string 'linux' is replaced with 1 - // fix the replacement paths which were created - QString replaceString = QUOTE(LINUX_PLATFORM_REPLACEMENT); - arcGISRuntimeImportPath = arcGISRuntimeImportPath.replace(replaceString, "linux", Qt::CaseSensitive); - #endif - - // Add the Runtime and Extras path - view.engine()->addImportPath(arcGISRuntimeImportPath); +#ifdef ARCGIS_RUNTIME_IMPORT_PATH_2 + engine.addImportPath(ARCGIS_RUNTIME_IMPORT_PATH_2); +#endif // Set the source - view.setSource(QUrl("qrc:/Samples/DisplayInformation/DisplayGrid/DisplayGrid.qml")); - - view.show(); + engine.load(QUrl("qrc:/Samples/DisplayInformation/ShowGrid/main.qml")); return app.exec(); } diff --git a/CppSamples/DisplayInformation/ShowGrid/main.qml b/CppSamples/DisplayInformation/ShowGrid/main.qml new file mode 100644 index 0000000000..8f64dc79b6 --- /dev/null +++ b/CppSamples/DisplayInformation/ShowGrid/main.qml @@ -0,0 +1,25 @@ +// 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. + +import QtQuick.Controls +import Esri.Samples + +ApplicationWindow { + visible: true + width: 800 + height: 600 + + ShowGrid { + anchors.fill: parent + } +} diff --git a/CppSamples/DisplayInformation/ShowGrid/screenshot.png b/CppSamples/DisplayInformation/ShowGrid/screenshot.png new file mode 100644 index 0000000000..16b138835b Binary files /dev/null and b/CppSamples/DisplayInformation/ShowGrid/screenshot.png differ