Select to view content in your preferred language

Convert button click event (Coordinate conversion)

240
1
05-17-2023 01:12 PM
MaicollDavidArizaCoronado
New Contributor II

I am using the CoordinateConversion widget and I want to take the click event of the button that converts the coordinates. I plan to use this event to add other independent functionalities to the widget, for example to prevent the view from changing if it has entered incorrect coordinates, does anyone know what the event is or know of an alternative to this?

0 Kudos
1 Reply
JoelBennett
MVP Regular Contributor

This is another one that cannot be done with documented means.  However, it is easily done by replacing the _processUserInput method:

const ccWidget = new CoordinateConversion({
	view: view
});

ccWidget._processUserInput = function() {
	alert("Convert clicked...");
};

view.ui.add(ccWidget, "bottom-left");

 

However, that will disconnect it from its default logic, and it would be entirely up to your custom code to handle the event.  If you want to keep the existing default logic, then you would do something like this:

const ccWidget = new CoordinateConversion({
	view: view
});

ccWidget._defaultProcessUserInput = ccWidget._processUserInput;

ccWidget._processUserInput = function() {
	var useDefault = false;

	//custom code

	if (useDefault)
		this._defaultProcessUserInput();
};

view.ui.add(ccWidget, "bottom-left");

 

Note also that typing in the textbox will also cause this same handler to execute.

Also...with all these hacks, my unsolicited opinion is that you may be better off creating your own widget/user interface, and leveraging the SDK's internal logic via an instance of CoordinateConversionViewModel.

0 Kudos