Adding wms dynamic map service layer in QT/QML

4443
8
04-22-2015 07:05 AM
KK2014
by
New Contributor III

I want to add wms service layer in map but caused error in layer create.I have give also correct user and password. How can I solve this problem? error is below :

ArcGIS.Runtime.Layer: void __cdecl QmlLayer::onLayerCreateError(const class QString &) QmlWmsDynamicMapServiceLayer "" "Authentication required."

Thanks

0 Kudos
8 Replies
ThomasDunn
Occasional Contributor

KK 2014,

Can you please send along the section of code you used for connecting to and authenticating with this service? Also, let us know which platform you are testing on. Thanks.

-- TAD

P.S. I probably don't need to mention this, but please obfuscate any credential information that may appear in your code.

0 Kudos
KK2014
by
New Contributor III

Here is my code below:

// Copyright 2015 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.

//

import QtQuick 2.0

import QtQuick.Controls 1.2

import QtQuick.Controls.Styles 1.2

import QtQuick.Dialogs 1.2

import QtQuick.Layouts 1.1

import QtQuick.Window 2.0

import ArcGIS.Extras 1.0

import ArcGIS.Runtime 10.25

import ArcGIS.Runtime.Toolkit.Dialogs 1.0

ApplicationWindow {

    id: appWindow

    width: 800

    height: 600

    title: "IslemMWC"

    property double scaleFactor: System.displayScaleFactor

    property var serviceLayer

    Map {

        id: mainMap

        anchors.fill: parent

        focus: true

        ArcGISTiledMapServiceLayer {

            url: "http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"

        }

    }

    Rectangle {

        anchors {

            fill: controlsColumn

            margins: -10 * scaleFactor

        }

        color: "lightgrey"

        radius: 5

        border.color: "black"

        opacity: 0.77

    }

    Column {

        id: controlsColumn

        anchors {

            left: parent.left

            top: parent.top

            margins: 20 * scaleFactor

        }

        spacing: 10

        Button {

            id: loadButton

            text: "Load Layer Service"

            style: ButtonStyle {

                label: Text {

                    text: control.text

                    color: "black"

                    horizontalAlignment: Text.AlignHCenter

                }

            }

            onClicked: {

                loadLayerColumn.visible = true

            }

        }

        Grid {

            columns: 2

            spacing: 10

            ExclusiveGroup {

                id: layersExclusiveGroup

            }

            RadioButton {

                id: dynamicRadioButton

                text: qsTr("Dynamic Layer")

                exclusiveGroup: layersExclusiveGroup

                checked: true

                style: RadioButtonStyle {

                    label: Text {

                        renderType: Text.NativeRendering

                        verticalAlignment: Text.AlignVCenter

                        horizontalAlignment: Text.AlignHCenter

                        font.pixelSize: 14 * scaleFactor

                        color: "black"

                        text: control.text

                    }

                }

            }

            RadioButton {

                id: featureRadioButton

                text: qsTr("Feature Layer")

                exclusiveGroup: layersExclusiveGroup

                checked: false

                style: dynamicRadioButton.style

            }

        }

    }

    Rectangle {

        color: "lightgrey"

        radius: 5

        border.color: "black"

        opacity: 0.77

        visible: loadLayerColumn.visible

        anchors {

            fill: loadLayerColumn

            margins: -10 * scaleFactor

        }

    }

    ColumnLayout {

        id: loadLayerColumn

        anchors {

            left: parent.left

            bottom: parent.bottom

            right: parent.right

            margins: 20 * scaleFactor

        }

        spacing: 10

        visible: false

        Text {

            text: "Enter the URL for the layer service:"

        }

        TextField {

            id: serviceTextField

            Layout.fillWidth: true

            visible: dynamicRadioButton.checked

            text: "http://sampleserver6.arcgisonline.com/arcgis/rest/services/SaveTheBay/MapServer"

            style: TextFieldStyle {

                textColor:"black"

            }

        }

        TextField {

            id: featureTextField

            Layout.fillWidth: true

            visible: !dynamicRadioButton.checked

            text: "http://sampleserver6.arcgisonline.com/arcgis/rest/services/SaveTheBay/FeatureServer/0"

            style: serviceTextField.style

        }

        Row {

            spacing: 10

            Button {

                id: okButton

                text: "Ok"

                style: loadButton.style

                onClicked: {

                    messageDialog.text = "";

                    loadLayerColumn.visible = false;

                    if (dynamicRadioButton.checked == true)

                    {

                        serviceLayer = ArcGISRuntime.createObject("WmsDynamicMapServiceLayer");

                        serviceLayer.url = serviceTextField.text;

                    } else {

                        var featureServiceTable = ArcGISRuntime.createObject("GeodatabaseFeatureServiceTable");

                        featureServiceTable.url = featureTextField.text;

                        serviceLayer = ArcGISRuntime.createObject("FeatureLayer");

                        serviceLayer.featureTable = featureServiceTable;

                    }

                    mainMap.addLayer(serviceLayer);

                }

                MessageDialog {

                    id: messageDialog

                    title: "Error"

                    icon: StandardIcon.Warning

                    modality: Qt.WindowModal

                    standardButtons: StandardButton.Ok

                }

                Connections {

                    target: serviceLayer

                    onStatusChanged: {

                        if (serviceLayer.status === Enums.LayerStatusErrored) {

                            messageDialog.text += serviceLayer.error;

                            messageDialog.text += " \n";

                            mainMap.removeLayer(serviceLayer);

                            messageDialog.visible = signInDialog.signIn;

                            loadButton.enabled = true;

                            dynamicRadioButton.enabled = true

                        }

                    }

                }

            }

            Button {

                text: "Cancel"

                style: loadButton.style

                onClicked: loadLayerColumn.visible = false

            }

        }

    }

    UserCredentialsDialog {

        id: signInDialog

        property bool signIn: false

        title: qsTr("Sign In")

        username: "user1"

        password: "user1"

        onAccepted: {

            signIn = true;

            busy = false;

            signInDialog.close()

            //taner

            loadButton.enabled = false;

            dynamicRadioButton.enabled = false

        }

        Component.onCompleted: {

            signInDialog.visible = false;

        }

    }

    Connections {

        target: ArcGISRuntime.identityManager

        onUserCredentialsRequired: {

            loadButton.enabled = true;

            dynamicRadioButton.enabled = true;

            signInDialog.signIn = false;

            credentials = UserCredentials

            signInDialog.visible = true;

            signInDialog.contentItem.height = Math.min(signInDialog.contentItem.screenHeight, signInDialog.contentItem.scaledHeight)

            signInDialog.contentItem.width = Math.min(signInDialog.contentItem.screenWidth, signInDialog.contentItem.scaledWidth)

            if(Qt.platform.os !== "ios" && Qt.platform.os != "android") {

                signInDialog.height = Math.min(signInDialog.contentItem.screenHeight, signInDialog.contentItem.scaledHeight)

                signInDialog.width = Math.min(signInDialog.contentItem.screenWidth, signInDialog.contentItem.scaledWidth)

            }

            // need to wait here for signInDialog to be accepted

            while (signInDialog.visible)

                System.wait(200)

            if (signInDialog.signIn){

                credentials.userName = signInDialog.username;

                credentials.password = signInDialog.password;

                loadButton.enabled = false;

                dynamicRadioButton.enabled = false;

            }

        }

        Component.onCompleted: {

            ArcGISRuntime.identityManager.ignoreSslErrors = true;

        }

    }

    Rectangle {

        anchors.fill: parent

        color: "transparent"

        border {

            width: 0.5 * scaleFactor

            color: "black"

        }

    }

}

0 Kudos
KK2014
by
New Contributor III

I solved authenticating problem. I give in credential's username, password. And give  url in WmsDynamicMapServiceLayer .

I solved authenticating problem but any layer doesn't apear in map.

Here is output  console  below :

Starting C:\Users\tkoka\Documents\build-IslemTKGM-Desktop_Qt_5_4_0_MSVC2013_OpenGL_64bit-Debug\debug\IslemTKGM.exe...

Cannot retrieve debugging output.

QML debugging is enabled. Only use this in a safe environment.

Initializing application

ArcGIS.Runtime.Plugin: void __cdecl ArcGISRuntimePlugin::registerTypes(const char *) ArcGIS.Runtime

ArcGIS.Runtime.Plugin: void __cdecl ArcGISRuntimePlugin::initializeEngine(class QQmlEngine *,const char *) ArcGIS.Runtime

ArcGIS.Runtime.Plugin: void __cdecl ArcGISRuntimePlugin::initializeLicense(void) Invalid clientId QVariant(QString, "") status 1

ArcGIS.Runtime.Plugin: void __cdecl ArcGISRuntimePlugin::initializeEngine(class QQmlEngine *,const char *) Setting global image provider QVariant(void*, 0x3bffe70)

ArcGIS.Extras.Plugin: void __cdecl ArcGISExtrasPlugin::registerTypes(const char *) ArcGIS.Extras

ArcGIS.Extras.Plugin: void __cdecl ArcGISExtrasPlugin::registerTypes(const char *) Registering Singleton Types

ArcGIS.Extras.Core: void __cdecl TkTypes::registerTypes(const char *) ArcGIS.Extras

ArcGIS.Extras.Plugin: void __cdecl ArcGISExtrasPlugin::initializeEngine(class QQmlEngine *,const char *) ArcGIS.Extras

Rendering engine : OpenGL

ArcGIS.Runtime.Map: void __cdecl QmlMap::classBegin(void)

ArcGIS.Extras.Plugin: class QObject *__cdecl ArcGISExtrasPlugin::systemProvider(class QQmlEngine *,class QJSEngine *) QObject(0x0)

ArcGIS.Extras.Core: __cdecl TkSystem::TkSystem(class QObject *) devicePixelRatio 1

ArcGIS.Extras.Core: __cdecl TkSystem::TkSystem(class QObject *) primaryScreen.physicalDotsPerInch 72.0177

ArcGIS.Extras.Core: __cdecl TkSystem::TkSystem(class QObject *) primaryScreen.logicalDotsPerInch 96

ArcGIS.Extras.Core: __cdecl TkSystem::TkSystem(class QObject *) referenceDotsPerInch 96

ArcGIS.Runtime.Plugin: class QObject *__cdecl ArcGISRuntimePlugin::arcGISRuntimeProvider(class QQmlEngine *,class QJSEngine *) QObject(0x0)

ArcGIS.Runtime.Core: __cdecl QmlIdentityManager::QmlIdentityManager(class QObject *)

QSslSocket: cannot resolve TLSv1_1_client_method

QSslSocket: cannot resolve TLSv1_2_client_method

QSslSocket: cannot resolve TLSv1_1_server_method

QSslSocket: cannot resolve TLSv1_2_server_method

QSslSocket: cannot resolve SSL_select_next_proto

QSslSocket: cannot resolve SSL_CTX_set_next_proto_select_cb

QSslSocket: cannot resolve SSL_get0_next_proto_negotiated

ArcGIS.Runtime.Map: void __cdecl QmlMap::componentComplete(void)

ArcGIS.Runtime.Map: void __cdecl QmlMap::componentComplete(void) Adding 2 declared layer(s)

int __cdecl main(int,char *[]) ApplicationWindow_QMLTYPE_51_QML_108(0x40b7b00)

0 Kudos
LucasDanzinger
Esri Frequent Contributor

KK -

It looks like the URL you are using for your WMS Service is actually coming from an ArcGIS Dynamic Map Service (ending in "MapServer"). The WmsDynamicMapServiceLayer expects the url to a map service that has the WMS capability enabled on it. If you are using a WMS Service coming from ArcGIS Server, it should end in "WMSServer".

Thanks,

Luke

0 Kudos
KK2014
by
New Contributor III

Lucas,

I have wms service like http://......./...../wms? Can I use this service in Qt/QML ? İf I can use wms service how can I get layers (Can I get subleyers with  using GroupLayerBase and add to the map).

Can I change visibility  wms service layer's sublayers ?

Thanks

0 Kudos
LucasDanzinger
Esri Frequent Contributor

KK-

Please see the class API help - ArcGIS Runtime SDK for Qt (QML API): WmsDynamicMapServiceLayer

Only the URL property for QML is exposed at this point, so doing things like getting to the individual sublayers and turning them on and off will not be supported.

Thanks,

Luke

0 Kudos
CeyhunYilmaz
New Contributor III

Hi Lucas,

İ have a question for u,

i work on wms/wfs too.But wms service like Group layer (as i think ) Just KK 2014​ said mine wms layer structure below

WMS Service

-->WMS Service Name

------->WMS Service Name

------------->layer1

------------->layer2

------------->layer:layer3

...

All layers there in 'layer:layer3' (for show). I want to show on map layer:layer3. Even I have tried many may many tried ways i could't show it. According to your words i started QT/C++ coding instead of QT/QML. İ can see sublayers and other properties while i debugging but i cannot show them. Please help me !

İ have worked for two weeks

0 Kudos
LucasDanzinger
Esri Frequent Contributor

We are currently looking into this, as I'm not sure how this works with this structure.

0 Kudos