Change sublayer renderer

View inQMLC++
View on GitHub
Sample viewer app

Apply a renderer to a sublayer.

screenshot

Use case

A layer showing animal populations contains sublayers for different species. A renderer could be applied which gives each sublayer a different color, so that populations of each species can be compared visually.

How to use the sample

Wait for the map image layer to load. Click the 'Change Sublayer Renderer' button to apply a unique value renderer to see different population ranges in the counties sub-layer data.

How it works

  1. Create an ArcGISMapImageLayer from its URL.
  2. After it is done loading, get its ArcGISSublayerListModel with imageLayer::mapImageSublayers().
  3. Cast the sublayer you want to change to the appropriate type: dynamic_cast<ArcGISMapImageSublayer>(ArcGISSublayer).
  4. Create a ClassBreaksRenderer with a collection of ClassBreaks for different population ranges.
  5. Set the renderer of the sublayer with sublayer::setRenderer(renderer).

Relevant API

  • ArcGISMapImageLayer
  • ArcGISMapImageSubLayer
  • ClassBreaksRenderer
  • ClassBreaksRenderer::classBreak

About the data

This application displays census data from an ArcGIS Server map service. It contains various population statistics, including total population for each county in 2007.

Additional information

The service hosting the layer must support dynamic layers to be able to change the rendering of sublayers.

Tags

class breaks, dynamic layer, dynamic rendering, renderer, sublayer, symbology, visualization

Sample Code

ChangeSublayerRenderer.qmlChangeSublayerRenderer.cppChangeSublayerRenderer.h
                                                                 
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
// [WriteFile Name=ChangeSublayerRenderer, Category=Layers]
// [Legal]
// Copyright 2018 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 2.6
import QtQuick.Window 2.3
import QtQuick.Controls 2.2
import Esri.Samples 1.0

ChangeSublayerRendererSample {
    id: rootRectangle
    clip: true
    width: 800
    height: 600



    // add a mapView component
    MapView {
        anchors.fill: parent
        objectName: "mapView"
    }

    onSublayerLoaded: {
        applyRendererButton.enabled = true;
        resetRendererButton.enabled = true;
    }

    Column {
        anchors {
            left: parent.left
            top: parent.top
            margins: 5
        }
        spacing: 5

        Button {
            id: applyRendererButton
            width: 200
            enabled: false
            text: "Apply Renderer"
            onClicked: applyRenderer();
        }

        Button {
            id: resetRendererButton
            width: 200
            enabled: false
            text: "Reset"
            onClicked: resetRenderer();
        }
    }
}

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.