View on GitHub Sample viewer app

Add, remove, and reorder operational layers in a map.

Use case

Operational layers display the primary content of the map and usually provide dynamic content for the user to interact with (as opposed to basemap layers that provide context).

The order of operational layers in a map determines the visual hierarchy of layers in the view. You can bring attention to a specific layer by rendering above other layers.

How to use the sample

When the app starts, a list displays the operational layers that are currently displayed in the map. Select the menu option on the list item to remove or reorder the layer. The map will be updated automatically.

The second list shows layers that have been removed from the map. Select the menu option on the list item to add it to the map.

How it works

  1. Get the operational layers LayerListModel from the map using Map::operationalLayers.
  2. Add or remove layers using operationalLayers()->append(layer) and operationalLayers()->remove(layer) respectively. The last layer in the list will be rendered on top.

Relevant API

  • Map
  • ArcGISMapImageLayer
  • LayerListModel
  • LayerListModel::append
  • LayerListModel::move
  • LayerListModel::removeAt

Tags

add, delete, layer, map, remove

Sample Code

DrawOrderLayerListModel.cpp DrawOrderLayerListModel.cpp DrawOrderLayerListModel.h ManageOperationalLayers.cpp ManageOperationalLayers.h ManageOperationalLayers.qml main.cpp main.qml
// [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]
// sample headers
#include "DrawOrderLayerListModel.h"
DrawOrderLayerListModel::DrawOrderLayerListModel(QObject* parent):
QSortFilterProxyModel(parent)
{
sort(0);
}
DrawOrderLayerListModel::~DrawOrderLayerListModel()
{
}
void DrawOrderLayerListModel::setLayerListModel(QAbstractItemModel* layerListModel)
{
setSourceModel(layerListModel);
}
int DrawOrderLayerListModel::mappedIndex(int index) const
{
const QModelIndex sourceIndex = mapToSource(this->index(index, 0));
return sourceIndex.row();
}
bool DrawOrderLayerListModel::lessThan(const QModelIndex& sourceLeft, const QModelIndex& sourceRight) const
{
return sourceLeft.row() >= sourceRight.row();
}