Editor Widget - Sannping Layers are not loaded

289
0
12-07-2022 05:22 AM
mohammaddmohammadii
New Contributor

Hi ExB community,
I am using version 4.24.

1- I am using MapImageLayer and FeatureLayer layers in my project at the same time.
When I set the ListMode value to 'hide', layers are not loaded in SanappingLayer.
I don't want layers to be displayed in LayerList but SnappingLayer is active.

2- Is the simultaneous use of MapImageLayer and FetureLayer layers in the project
Is it the right thing to do?
What should I do to not override the layer?

 

 var strProxyUrl = "../../ProxyConfig/proxy.ashx";
    strUrl = "https://192.168.0.104:6443/arcgis/rest/services/SINARPIM/TehranCST_BaseMap/MapServer";
    strUrl2 = "https://192.168.0.104:6443/arcgis/rest/services/SINARPIM/TehranCST_BaseMap/FeatureServer";
    function rdBtnList_onchange() {

        if (document.getElementById('rdBtnList_1').checked) {
            strUrl = "https://192.168.0.104:6443/arcgis/rest/services/SINARPIM/FarsProvince_SwereTransDistributionMap/MapServer";
            strUrl2 = "https://192.168.0.104:6443/arcgis/rest/services/SINARPIM/FarsProvince_SwereTransDistributionMap/FeatureServer";
        }
        else if (document.getElementById('rdBtnList_2').checked) {
            strUrl = "https://192.168.0.104:6443/arcgis/rest/services/SINARPIM/TehranCST_BaseMap/MapServer";
            strUrl2 = "https://192.168.0.104:6443/arcgis/rest/services/SINARPIM/TehranCST_BaseMap/FeatureServer";
        }
        InitMap();
        return false;
    }

    var identifyTask;
    var params;
    var arrMapLayers = [];
    var objFeatureLayer = null;
    var view = null;
    function InitMap() {
        require([
             "esri/Map",
            "esri/WebMap",
            "esri/views/MapView",
            "esri/widgets/Editor",
            "esri/layers/MapImageLayer",
            "esri/request",
            "esri/layers/FeatureLayer",
            "esri/config", "esri/request", "esri/widgets/LayerList"
        ],
        function (Map, WebMap, MapView, Editor, MapImageLayer, esriRequest, FeatureLayer, esriConfig, esriRequest, LayerList) {
            esriConfig.request.proxyUrl = strProxyUrl;

            if (document.getElementById('rdBtnList_0').checked) {

                esriConfig.request.proxyUrl = strProxyUrl;
                const webmap = new WebMap({
                    portalItem: {
                        id: "459a495fc16d4d4caa35e92e895694c8"
                    }
                });

                var view = new MapView({
                    container: "viewDiv",
                    map: webmap
                });

            } else {

                var objMapImageLayer = new MapImageLayer({
                    url: strUrl,
                    proxyUrl: strProxyUrl
                });
                objmap = new Map();
                objmap.add(objMapImageLayer);
                view = new MapView({
                    container: "viewDiv",
                    map: objmap
                });
            }
            let layerList = new LayerList({
                view: view
            });
            view.ui.add(layerList, {
                position: "top-left"
            });
            view.when(function () {
                DoEsriRequest_GetMapLayers(esriRequest, Editor, view);
                DoEsriRequest_GetFeatureLayers(esriRequest, FeatureLayer);

            }).catch(function (err) {
                console.error("objMapView rejected:", err);
            });

        });
    }
    function DoEsriRequest_GetMapLayers(esriRequest, Editor, view) {
        var options = {
            query: {
                f: "json"
            },
            responseType: "json"
        };
        esriRequest(strUrl + "/legend", options).then(function (response) {
            if (response == null)
                return;

            if (response.data == null)
                return;

            let responseJSON = JSON.stringify(response, null, 2);
            let arrResponseJSON = JSON.parse(responseJSON);

            for (let i = arrResponseJSON.data.layers.length - 1; i >= 0; i--) {
                arrMapLayers.push(arrResponseJSON.data.layers[i]);
            }
            Make_Editor(Editor, view);
        });
    }

    function Make_Editor(Editor, view) {
        const editor = new Editor({
            view: view,
            snappingControlsElements: {
                featureEnabledToggle: false, // removes "Feature to feature" toggle
                layerList: false // removes Snapping layers list
            }
        });
        view.ui.add(editor, "top-right");
    }
    function DoEsriRequest_GetFeatureLayers(esriRequest, FeatureLayer) {
        var options = {
            query: {
                f: "json"
            },
            responseType: "json"
        };
        var strUrlFeature = strUrl.replace('MapServer', 'FeatureServer');

        esriRequest(strUrlFeature, options).then(function (response) {
            try {

                if (response == null)
                    return;

                if (response.data == null)
                    return;

                let responseJSON = JSON.stringify(response, null, 2);
                let arrResponseJSON = JSON.parse(responseJSON);

                for (let i = arrResponseJSON.data.layers.length - 1; i >= 0; i--) {
                    var objFeatureLayer = new FeatureLayer({
                        url: strUrlFeature + "/" + arrResponseJSON.data.layers[i].id,
                        listMode: 'show',
                        editingEnabled: true,
                        labelsVisible: false,
                        hasM: true,
                        gdbVersion: 'DEFAULT',
                        title: arrResponseJSON.data.layers[i].name,
                        opacity: 1
                    });

                    objmap.add(objFeatureLayer);
                }

            } catch (e) {

            }
        });
    }
    InitMap();

 

0 Kudos
0 Replies