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/map-reference-scale/ below:

Map reference scale | ArcGIS Maps SDK for Qt

View on GitHub Sample viewer app

Set the map's reference scale and which feature layers should honor the reference scale.

Use case

Setting a reference scale on a Map fixes the size of symbols and text to the desired height and width at that scale. As you zoom in and out, symbols and text will increase or decrease in size accordingly. When no reference scale is set, symbol and text sizes remain the same size relative to the MapView.

Map annotations are typically only relevant at certain scales. For instance, annotations to a map showing a construction site are only relevant at that construction site's scale. So, when the map is zoomed out that information shouldn't scale with the MapView, but should instead remain scaled with the Map.

How to use the sample How it works
  1. Get and set the reference scale property on the Map object.
  2. Get and set the scale symbols property on each individual FeatureLayer object.
Relevant API Additional information

The map reference scale should normally be set by the map's author and not exposed to the end user like it is in this sample.

map, reference scale, scene

Sample Code

MapReferenceScale.cpp MapReferenceScale.cpp MapReferenceScale.h MapReferenceScale.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
// [WriteFile Name=MapReferenceScale, Category=Maps]
// [Legal]
// Copyright 2019 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 "MapReferenceScale.h"

// ArcGIS Maps SDK headers
#include "Error.h"
#include "FeatureLayer.h"
#include "Layer.h"
#include "LayerListModel.h"
#include "Map.h"
#include "MapQuickView.h"
#include "Portal.h"
#include "PortalItem.h"

// Qt headers
#include <QFuture>

using namespace Esri::ArcGISRuntime;

MapReferenceScale::MapReferenceScale(QObject* parent /* = nullptr */):
  QObject(parent),
  m_portal(new Portal(this)),
  m_portalItem(new PortalItem(m_portal, "3953413f3bd34e53a42bf70f2937a408", this))
{
  m_map = new Map(m_portalItem, this);

  // Once map is loaded set FeatureLayer list model
  connect(m_map, &Map::doneLoading, this, [this](const Error& loadError)
  {
    if (!loadError.isEmpty())
      return;

    m_layerInfoListModel = m_map->operationalLayers();
    emit layerInfoListModelChanged();
    emit currentMapScaleChanged();

    connect(m_mapView, &MapQuickView::mapScaleChanged, this, [this]()
    {
      emit currentMapScaleChanged();
    });
  });
}

MapReferenceScale::~MapReferenceScale() = default;

void MapReferenceScale::init()
{
  // Register the map view for QML
  qmlRegisterType<MapQuickView>("Esri.Samples", 1, 0, "MapView");
  qmlRegisterType<MapReferenceScale>("Esri.Samples", 1, 0, "MapReferenceScaleSample");
  qmlRegisterUncreatableType<QAbstractListModel>("Esri.Samples", 1, 0, "AbstractListModel", "AbstractListModel is uncreateable");
}

double MapReferenceScale::currentMapScale() const
{
  if (!m_mapView)
    return 0.0;

  return m_mapView->mapScale();
}

void MapReferenceScale::setCurrentMapScale(double scale)
{
  if(!m_map)
    return;

  m_map->setReferenceScale(scale);
}

void MapReferenceScale::setMapScaleToReferenceScale(double scale)
{
  if(m_mapView)
    m_mapView->setViewpointScaleAsync(scale);
}

void MapReferenceScale::featureLayerScaleSymbols(const QString& layerName, bool checkedStatus)
{
  if(m_layerInfoListModel)
  {
    for(Layer* layer : *static_cast<LayerListModel*>(m_layerInfoListModel))
    {
      if(layer->name() == layerName)
      {
        FeatureLayer* featureLayer = static_cast<FeatureLayer*>(layer);
        if(featureLayer)
          featureLayer->setScaleSymbols(checkedStatus);
      }
    }
  }
}

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

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

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

  emit mapViewChanged();
}

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