Update fields dropdown when layers dropdown is changed

1309
2
Jump to solution
05-02-2017 10:12 AM
RoySP
by
New Contributor III

Newbie question here.

I have a LayerChooserFromMapWithDropbox added to my widget.

I am trying to make the "selection-change" event to work so that when a layer is changed, a dijit/form/Select box gets updated with fields from the selected layer.

This should be pretty simple but my limited experience is making this take longer than it should.

This is what I have so far...

      postCreate: function() {
        this.inherited(arguments);
        var layerChooser = new LayerChooserFromMap({
          createMapResponse: this.map.webMapResponse
        });
        _layerChooserDropBox = new LayerChooserFromMapWithDropbox({
          layerChooser:layerChooser
        }, this.layerChooserDropBoxDiv);
    
        on(_layerChooserDropBox, "selection-change", lang.hitch(this, function(){

          if (_layerChooserDropBox.getSelectedItem()){
            _layerObject = _layerChooserDropBox.getSelectedItem().layerInfo.layerObject;
            array.forEach(_layerObject.fields, lang.hitch(this, function(fldObj){
              // update fieldSelectDiv
            }));          
          }

        }));


      }
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Esteemed Contributor

Roy,

  Something like this then:

      postCreate: function() {
        this.inherited(arguments);
        var layerChooser = new LayerChooserFromMap({
          createMapResponse: this.map.webMapResponse
        });

        _layerChooserDropBox = new LayerChooserFromMapWithDropbox({
          layerChooser:layerChooser
        }, this.layerChooserDropBoxDiv);
    
        on(_layerChooserDropBox, "selection-change", lang.hitch(this, function(){
          if (_layerChooserDropBox.getSelectedItem()){
            //Clear old values first
            var i;
            for (i = this.fieldSelectDiv.options.length - 1; i >= 0; i--) {
               this.fieldSelectDiv.remove(i);
            }
            _layerObject = _layerChooserDropBox.getSelectedItem().layerInfo.layerObject;
            array.forEach(_layerObject.fields, lang.hitch(this, function(fldObj){
              var option = domConstruct.create("option");
              option.text = fldObj.name;
              this.fieldSelectDiv.add(option);
            }));          
          }
        }));
      }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

View solution in original post

2 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Roy,

  Something like this then:

      postCreate: function() {
        this.inherited(arguments);
        var layerChooser = new LayerChooserFromMap({
          createMapResponse: this.map.webMapResponse
        });

        _layerChooserDropBox = new LayerChooserFromMapWithDropbox({
          layerChooser:layerChooser
        }, this.layerChooserDropBoxDiv);
    
        on(_layerChooserDropBox, "selection-change", lang.hitch(this, function(){
          if (_layerChooserDropBox.getSelectedItem()){
            //Clear old values first
            var i;
            for (i = this.fieldSelectDiv.options.length - 1; i >= 0; i--) {
               this.fieldSelectDiv.remove(i);
            }
            _layerObject = _layerChooserDropBox.getSelectedItem().layerInfo.layerObject;
            array.forEach(_layerObject.fields, lang.hitch(this, function(fldObj){
              var option = domConstruct.create("option");
              option.text = fldObj.name;
              this.fieldSelectDiv.add(option);
            }));          
          }
        }));
      }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
RoySP
by
New Contributor III

Perfect Robert! Thank you!

0 Kudos