Select to view content in your preferred language

How do I change the results label for the measurement dijit

2574
5
Jump to solution
01-15-2016 06:21 AM
AnthonyGiles
Honored Contributor

All,

Is it possible to change the default value for the measurement dijit from 'Measurement Result' to some other text in a single widget:

I tried changing the following localisation value within the widget:

esriBundle.widgets.measurement.NLS_resultLabel = "new value";

Which worked but it changed the values for all measurement result labels and I only want to change it in the one widget.

Regards

Anthony

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Anthony,

  In that case then direct dom manipulation is best:

Add 'dojo/query' require to the widget.js and then make these changes to the startup function (lines 20 - 23):

      startup: function() {
        if (this.measurement || this._pcDef) {
          return;
        }
        this.inherited(arguments);

        var json = this.config.measurement;
        json.map = this.map;
        if (json.lineSymbol) {
          json.lineSymbol = jsonUtils.fromJson(json.lineSymbol);
        }
        if (json.pointSymbol) {
          json.pointSymbol = jsonUtils.fromJson(json.pointSymbol);
        }

        this._processConfig(json).then(lang.hitch(this, function(measurementJson) {
          this.measurement = new Measurement(measurementJson, this.measurementDiv);
          this.own(aspect.after(this.measurement, 'setTool', lang.hitch(this, function() {
            if (this.measurement.activeTool) {
              var measLbl = query(".esriMeasurementResultLabel", this.domNode)[0];
              if(measLbl){
                measLbl.innerHTML = measLbl.innerText = "My Measurement Result";
              }
              this.disableWebMapPopup();
            } else {
              this.enableWebMapPopup();
            }
          })));

          this.measurement.startup();
        }), lang.hitch(this, function(err) {
          new Message({
            message: err.message || err
          });
        }));
      },

View solution in original post

5 Replies
RobertScheitlin__GISP
MVP Emeritus

Anthony,

   I would suggest doing the esriBundle.widgets.measurement.NLS_resultLabel = "new value"; in the onOpen function of the widget than reset it onClose (which means you need to save the original in a var). Esri does this in their Edit widget

AnthonyGiles
Honored Contributor

Cheers Robert,

That sort of works but doesn't seem to be an elegant solution in my opinion.

If you open a second widget that contains the measurement dijit before you close the first the label will be incorrect. Which means you need to add the code into the open and close of each potential widget.

Never mind if that,s the only work around

Reagrds

Anthony

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Anthony,

  In that case then direct dom manipulation is best:

Add 'dojo/query' require to the widget.js and then make these changes to the startup function (lines 20 - 23):

      startup: function() {
        if (this.measurement || this._pcDef) {
          return;
        }
        this.inherited(arguments);

        var json = this.config.measurement;
        json.map = this.map;
        if (json.lineSymbol) {
          json.lineSymbol = jsonUtils.fromJson(json.lineSymbol);
        }
        if (json.pointSymbol) {
          json.pointSymbol = jsonUtils.fromJson(json.pointSymbol);
        }

        this._processConfig(json).then(lang.hitch(this, function(measurementJson) {
          this.measurement = new Measurement(measurementJson, this.measurementDiv);
          this.own(aspect.after(this.measurement, 'setTool', lang.hitch(this, function() {
            if (this.measurement.activeTool) {
              var measLbl = query(".esriMeasurementResultLabel", this.domNode)[0];
              if(measLbl){
                measLbl.innerHTML = measLbl.innerText = "My Measurement Result";
              }
              this.disableWebMapPopup();
            } else {
              this.enableWebMapPopup();
            }
          })));

          this.measurement.startup();
        }), lang.hitch(this, function(err) {
          new Message({
            message: err.message || err
          });
        }));
      },
AnthonyGiles
Honored Contributor

Cheers Robert,

I've finished for the weekend I will have a look Monday and let you know how I get on.

thanks again

Anthony

0 Kudos
AnthonyGiles
Honored Contributor

Spot on Robert,

Thanks Again

0 Kudos