1

The ArcGIS Server JavaScript API has a Measurement widget, which reports the area or length of a shape drawn on the map.

The default metric labels use the American spelling of "Sq Kilometers" and "Kilometers", etc.

enter image description here

var measurement = new Measurement({
        map: map,
        defaultAreaUnit: units.SQUARE_KILOMETERS,
        defaultLengthUnit: units.KILOMETERS
}, dom.byId("measurementDiv"));


measurement.startup();

Is it possible to change the default text "Square Kilometers" shown by default to a custom text (like "km2")?

The Measurement widget doesn't seem to have any customisation options which would accomplish this.

  • What version of the ArcGIS API for JavaScript are you using? – PolyGeo Jun 5 '17 at 21:21
  • It will most likely be 3.x or 4.x. 10.2 may be your Server version. – PolyGeo Jun 6 '17 at 19:48
  • @PolyGeo yeah, you're right. Api is v 3.13 – user3357358 Jun 6 '17 at 19:54
  • @StephenLead i think the same.I have no idea about building my own measuring widget. Could you suggest some reading materials? thanks. – user3357358 Jun 7 '17 at 19:00
2

You can change this string, like many other strings in the ArcGIS API for JavaScript, by taking advantage/overwriting the localizable strings.

This is documented at the bottom of the localization doc - https://developers.arcgis.com/javascript/3/jshelp/localization.html

require([..., "dojo/i18n!esri/nls/jsapi", ... ],
  function(..., bundle, ...) {
    bundle.widgets.measurement.NLS_area_sq_kilometers = "km<sup>2</sup>";
    // or bundle.widgets.measurement.NLS_area_sq_kilometers = "km2";
  }
);
  • Well, i would have preferred to have a nice "setText" method or something in that vein. But your solution does it. Thank you very much. – user3357358 Jun 8 '17 at 21:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.