Modify number of decimal places the location tool returns in the Measurement widget?

985
7
Jump to solution
01-29-2019 12:52 PM
AndrewHayden1
Occasional Contributor

What might be the best way to modify the number of decimal places returned by the location tool in the measurement widget?  Struggling more so with where to do it as opposed to how to do it.  I've stepped through widget.js and don't understand where the values get added back to the measurement result table when either panning or clicking with the location tool enabled.  Any direction pointing or examples would be appreciated.

  

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Andrew,

   OK, I see the issue now. The _updateClickLocation function does call the _updateMouseLocation but will not adjust the values. So you have to override the _updateClickLocation function too.

this.measurement._updateClickLocation = this.myupdateClickLocation;

      myupdateClickLocation: function(lon, lat) {
        this.myupdateMouseLocation(lon, lat);
        this.measurement.markerLongitude.innerHTML = lon;
        this.measurement.markerLatitude.innerHTML = lat
      },‍‍‍‍‍‍‍

View solution in original post

7 Replies
RobertScheitlin__GISP
MVP Emeritus

Andrew,

   The issue is that the Measurement widget just uses the esri/dijit/Measurement so you are not going to find the code in the widget.js as the actual code is inside the JS API. You will have to override the _updateMouseLocation function of the measurment dijit. Add line 32 and 44 - 48. This will give you access to the values, since this is all you asked for.

      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);
        }

        //add snap tips
        this._addSnappingTips();

        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) {
              this.disableWebMapPopup();
            } else {
              this.enableWebMapPopup();
            }
          })));
          this.own(on(this.measurement, 'tool-change', lang.hitch(this, this._toolChange)));
          this.own(on(this.measurement, 'measure-start', lang.hitch(this, this._onMeasureStart)));
          this.own(on(this.measurement, 'measure-end', lang.hitch(this, this._onMeasureEnd)));
          this.measurement.startup();
          this.measurement._updateMouseLocation = this.myupdateMouseLocation;

          this._initGraphicsLayers();

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

      myupdateMouseLocation: function(lon, lat) {
        console.info(lon, lat);
        this.mouseLongitude.innerHTML = lon;
        this.mouseLatitude.innerHTML = lat
      },‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
AndrewHayden1
Occasional Contributor

Thank you Robert.  That works perfectly when hovering.  I'm still struggling with the coordinates when you click on the map though.  I'm able to modify "value" and "graphic" _onMeasureEnd and have tried figuring out how to access markerLatitude/Longitude.innerHTML but have not had any success.  Might you have a suggestion to get me on track with that?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Andrew,

  The Measurement dijit calls 

_updateMouseLocation 

When you move the mouse and it is also called on mouse click. So it should work for both if you change the values in that function.

0 Kudos
AndrewHayden1
Occasional Contributor

I included a screen shot above.  It worked for the hover (the first line), but not the click (the second).

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Can I see your code?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Andrew,

   OK, I see the issue now. The _updateClickLocation function does call the _updateMouseLocation but will not adjust the values. So you have to override the _updateClickLocation function too.

this.measurement._updateClickLocation = this.myupdateClickLocation;

      myupdateClickLocation: function(lon, lat) {
        this.myupdateMouseLocation(lon, lat);
        this.measurement.markerLongitude.innerHTML = lon;
        this.measurement.markerLatitude.innerHTML = lat
      },‍‍‍‍‍‍‍
AndrewHayden1
Occasional Contributor

Thank you Robert...that's exactly where I was trying to go.  This seems to be working fine for 2 digits.

myupdateMouseLocation: function(lon, lat) {
        console.info(parseFloat(lon).toFixed(2), parseFloat(lat).toFixed(2));
        this.mouseLongitude.innerHTML = parseFloat(lon).toFixed(2);
        this.mouseLatitude.innerHTML = parseFloat(lat).toFixed(2);
      },
	  
	  myupdateClickLocation: function(lon, lat) {
        console.info(parseFloat(lon).toFixed(2), parseFloat(lat).toFixed(2));
		this.mouseLongitude.innerHTML = parseFloat(lon).toFixed(2);
        this.mouseLatitude.innerHTML = parseFloat(lat).toFixed(2);
        this.markerLongitude.innerHTML = parseFloat(lon).toFixed(2);
		this.markerLatitude.innerHTML = parseFloat(lat).toFixed(2);
      },
0 Kudos