Select to view content in your preferred language

Limit number of decimals in CoordinateConversion widget

136
1
a month ago
calin_gi
New Contributor II

What would be the best way to limit the number of decimals in coordinates shown in the CoordinateConversion widget.

I can achieve this by building my own Formats, but is it possible to use the existing format definitions?

0 Kudos
1 Reply
calin_gi
New Contributor II

I am not sure if this is optimal, but I solved it like this:

const coordConversion = new CoordinateConversion({
	view,
	id: 'coordinate-container',
	storageType: 'local',
	visibleElements: {
		settingsButton: false,
	}
});
// @ts-ignore: The JS API can autocast this
coordConversion.conversions = ["mgrs"];
const toRemove = coordConversion.formats.filter(format => format.name == "basemap" || format.name == "usng");
coordConversion.formats.removeMany(toRemove);
// Format "dd" to 3 decimals
const ddFormat = coordConversion.formats.find(format => format.name == "dd");
ddFormat.conversionInfo = {
	convert: function (point) {
		const returnPoint = point.spatialReference.isWGS84 ?
			point :
			webMercatorUtils.webMercatorToGeographic(point) as Point;
		const formattedCoordinates = coordinateFormatter.toLatitudeLongitude(returnPoint, "dd", 3);

		return {
			location: point,
			coordinate: formattedCoordinates
		};
	}
};
	
	view.ui.add(coordConversion, 'bottom-left');
0 Kudos