AzureMapsCodeSamples icon indicating copy to clipboard operation
AzureMapsCodeSamples copied to clipboard

Choosing popup locale for formatting data

Open Jxlle opened this issue 2 years ago • 3 comments

Is it possible to choose the locale of the number and date formatter through a popup template? Right now, you can choose the number and date format through the numberFormat and dateFormat property on the PopupTemplate respectively. However, these objects are of type Intl.NumberFormatOptions and Intl.DateTimeFormatOptions, which do not include a locale property. These options are then sent to Number.toLocaleString or Date.toLocaleString, but the locale is not given, presumably then chosen by the application as the system default. (see screenshot)

image

Is there a way to change the popup locales, so I can, for example, see an English number format even though my system default is Dutch?

Jxlle avatar Nov 28 '23 11:11 Jxlle

The screenshot you provided of the source code shows that there is no way to set the local as its value is hard coded to undefined which would mean it uses the user's browsers settings. One way around this would be to create a new property or override it, on your shape and to convert it to a string ahead of time. This could even be done when creating the popup since you pass in an object of the shapes properties into the template. For example:

function showPopup(e) {
	if (e.shapes && e.shapes.length > 0) {
		var properties = e.shapes[0].getProperties();
		
		//Convert number property to a string ahead of time.
		properties.myNumVal = properties.myNumVal.toLocalString('fr', {
                                maximumFractionDigits: 2
                            });

		popup.setOptions({
			//Update the content of the popup.
			content: atlas.PopupTemplate.applyTemplate(properties),

			//Update the position of the popup with the pins coordinate.
			position: e.shapes[0].getCoordinates()
		});

		//Open the popup.
		popup.open(map);
	}
}
```

Note that popup templates are mainly a low code convivence feature, and a good simple option, but not usually used in most production applications where more advanced styling is often desired.

rbrundritt avatar Nov 28 '23 18:11 rbrundritt

Thanks, your proposed solution is actually the way I was thinking of implementing it. Indeed, the usage of the Azure Maps popup is currently a temporary solution for our application as it is going to be replaced with a custom non-popup gui to show the results in the future. We accidently stumbled upon this locale issue because one of the users had a different locale enabled on the browser.

So just to be clear; the localization of popup properties is never going to be supported in the future for Azure Maps? Maybe it would help some new users if this behaviour is described in the documentation.

Jxlle avatar Nov 28 '23 22:11 Jxlle

I'm not on the Azure Maps team, but I doubt this would be added anytime soon. The popup template feature has been out there for over 5 years and this is the first time anyone asked to change the locale setting. S, not demand for this compared to other feature requests..

rbrundritt avatar Nov 28 '23 23:11 rbrundritt