Select to view content in your preferred language

Measurement Widget Customization

372
1
01-31-2023 09:51 PM
Acharya
Occasional Contributor

Hello Everyone,

I am trying to customize the dropdown menu from the measurement widget. I want to keep only the metric units and remove other units from the drop down menu. 

Is it possible in 4.25 version? 

Acharya_0-1675230662286.png

Thank you so much in advance. 

0 Kudos
1 Reply
JoelBennett
MVP Regular Contributor

This appears to work:

const measurement = new Measurement({
	areaUnit: "hectares",
	linearUnit: "kilometers"
});

measurement.viewModel.watch("activeViewModel", function(newValue, oldValue, propertyName, target) {
	if (newValue) {
		switch (newValue.declaredClass) {
			case "esri.widgets.AreaMeasurement3D.AreaMeasurement3DViewModel":
			case "esri.widgets.AreaMeasurement2D.AreaMeasurement2DViewModel":
				newValue.unitOptions = ["square-millimeters","square-centimeters","square-decimeters","square-meters","square-kilometers","ares","hectares"];
				break;

			case "esri.widgets.DirectLineMeasurement3D.DirectLineMeasurement3DViewModel":
			case "esri.widgets.DistanceMeasurement2D.DistanceMeasurement2DViewModel":
				newValue.unitOptions = ["millimeters","centimeters","decimeters","meters","kilometers"];
				break;
		}
	}
});
0 Kudos