Azure Maps: How to Prevent Text from Wrapping

Ken Bowman 231 Reputation points
2024-09-13T22:14:50.3966667+00:00

Hi,

I'm using a Symbol Layer's textOptions to display labels on a map. How can I prevent the labels from wrapping?

User's image

Thanks,

Ken

Azure Maps
Azure Maps
An Azure service that provides geospatial APIs to add maps, spatial analytics, and mobility solutions to apps.
723 questions
0 comments No comments
{count} votes

Accepted answer
  1. rbrundritt 18,266 Reputation points Microsoft Employee
    2024-09-14T00:08:54.5966667+00:00

    There isn't a documented way to do this yet in Azure Maps, however, there is a way to achieve this by accessing the underlying MapLibre API that the Azure Maps SDK is built on top of.

    First off you will need the ID of your layer. You can simply do something like var myLayerId = myLayer.getId()

    From there you can set the text-max-width layout option of the layer like this:

    map._getMap().setLayoutProperty(myLayerId, 'text-max-width', 15);

    The default setting for this is 10, I tried 15 with my test string and that worked well. Experiment and find what works best for you.


1 additional answer

Sort by: Most helpful
  1. hossein jalilian 7,285 Reputation points
    2024-09-13T23:02:39.27+00:00

    Thanks for posting your question in the Microsoft Q&A forum.

    You can use the textWrapping property in the TextOptions of your SymbolLayerOptions.

    Set the textWrapping property to "none" in your TextOptions

    var symbolLayer = new atlas.layer.SymbolLayer(dataSource, null, {
      textOptions: {
        textField: ['get', 'name'], // Assuming 'name' is the property containing your label text
        textWrapping: 'none',
        // Other text options...
      }
    });
    
    

    Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.