bpelchat

LayerList Widget Popup Menu Info Customization Part 2

Blog Post created by bpelchat on Dec 27, 2017

In  Part1 we added a menu item to layer list widget popup menu. In this blog we'll finish by receiving the layer list object sent to the eSearch widget.

In the snippet below only pre-configured search layers are listed....

Pre-Configured AHC Search Layer

 

After selecting the "Add To NHSearch" item from the Layer List widget popup menu items, the layer list object will be sent to search widget and added the drop down list of searchable layers.

 

 

 

 

In the esearch widget we receive the message sent from the Layer List widget by hooking the onReceiveData function, and filtering on the data.target value. If it's from the layer list will then call the function _insertLayerFromLayerList with the data.layerinfo object received from the Layer List widget.

postCreate: function () {
        lang.hitch(this, 'onReceiveData');//get messages from layerlist popupmenuinfo.js



onReceiveData: function(name, widgetId, data, historyData) {
        if(String(data.target) != "NHSEARCH") return;
        //console.log("onReceiveData-GotAMessage:" + data.message +"::From:" + name);
        this._insertLayerFromLayerList(data.layerinfo);
},

Then combining the new functions with those that were available in the widget we can insert this layer into the Search List.

      _insertLayerFromLayerList: function(layerInfo){
            this.tmpLayerInfo=layerInfo;
            var success=true;
            this._getLayerInfoWithRelationships(layerInfo.layerObject.url).then(lang.hitch(this, function(val){
              var linkArr=[];
              var fieldArray=[];
              for (var f=0; f < val.value.fields.length; f++) {
                item = val.value.fields[f];
                var fieldItem={alias:item.alias,name:item.name}
                fieldArray.push(fieldItem);
              }//val.value.fields is array of fields from service , alias, name , domain, and type are propeties of each.
              var oBF=[];
              var layerObj = {
                addToAttrib:true,
                definitionexpression:"",
                existObjectId:true,
                export2Csv:true,
                export2FC:false,
                export2Geo:false,
                fields:{all:true,field:fieldArray},
                forceZoomScale:false,
                layersymbolfrom:"server",
                links:{link:linkArr},
                name:val.value.name,
                objectIdField:"OBJECTID",
                orderByFields:oBF,
                popupfrom:"webmap",
                shareResult:true,
                spatialsearchlayer:false,
                titlefield:null,
                titleIdField:null,
                url:this.tmpLayerInfo.layerObject.url,
                zoomScale:10000
              };
              var urlStr="";
              urlStr = this.tmpLayerInfo.layerObject.url;
              urlStrUC=urlStr.toUpperCase();
              if(this.addedFromLayerList.indexOf(urlStrUC) >= 0){
                return;
              }else{
                this.addedFromLayerList.push(urlStrUC);
              }
              var newLayerIndex = this.config.layers.length;
              this.config.layers.push(layerObj)
              var options = [];
              var option = {
                value: newLayerIndex,
                label: val.value.name
              };
              options.push(option);
              this.selectLayerGraphical.addOption(options);//before modifying the layerInfo.name
              this.selectLayerGraphical.set("value", newLayerIndex);
              var layerInfo = val.value;//layerinfo from service
              var layerConfig = this.config.layers[newLayerIndex];
              layerConfig.objectIdField = "OBJECTID";//expecting objectid!
              layerConfig.typeIdField = layerInfo.typeIdField;
              if (!layerInfo.drawingInfo) {
                layerInfo.drawingInfo = {};
              }
              layerInfo.name = this.nls.search + ' ' + this.nls.results + ': ' + layerConfig.name;
              layerInfo._titleForLegend = layerInfo.name;
              layerInfo.minScale = 0;
              layerInfo.maxScale = 0;
              layerInfo.effectiveMinScale = 0;
              layerInfo.effectiveMaxScale = 0;
              layerInfo.defaultVisibility = true;
              this.resultLayers.push(layerInfo);
            }), function(err){
              console.log('_insertLayerFromLayerList_getLayerInfoWithRelationships-err-incomplete');
            });

      },

Outcomes