Articles in this section
Category / Section

How to render the detailed US map with labels

2 mins read

How to render the detailed US map with labels?

Data labels provide information to the user about the shapes. You can add text to the shapes of maps component using dataLabelSettings and bind the field name in the data source to the labelPath property in dataLabelSettings. The following code renders the names of all the shapes in USA.

import { Maps, DataLabel } from '@syncfusion/ej2-maps';
import { usa } from './usa_map';
Maps.Inject(DataLabel);
let maps: Maps = new Maps({
    layers: [
        {
            shapeData: usa,
               dataLabelSettings: {
                    visible: true,
                    labelPath: 'name'
                },
                shapeSettings: {
                    autofill: true
                }
            //..
        }
    ]
});
maps.appendTo('#container');

A close up of a map

Description generated with high confidence

 

Sample link - Maps Labels

The overlapping labels can be customized using the below properties.

  • SmartLabelMode
  • IntersectionAction

SmartLabelMode

The labels which crosses the boundary on its shape can be handled in this. You can use the smartLabelMode property with the following options.

  • Trim
  • Hide
  • None

The below code snippet shows the labels with smartLabelMode as Trim.

import { Maps, DataLabel } from '@syncfusion/ej2-maps';
import { usa } from './usa_map';
Maps.Inject(DataLabel);
let maps: Maps = new Maps({
    layers: [
        {
                shapeData: usa,
                dataLabelSettings: {
                    visible: true,
                    labelPath: 'name',
                    smartLabelMode: 'Trim'
                },
                shapeSettings: {
                    autofill: true
                }
            //..
        }
    ]
});
maps.appendTo('#container');

 

A close up of a map

Description generated with high confidence

Sample link - Smart label

IntersectionAction

The labels which are intersected with other labels can be handled in this. You can use the intersectionAction property with the following options.

  • Trim
  • Hide
  • None

The below code snippet shows the labels with intersectionAction as Hide.

import { Maps, DataLabel } from '@syncfusion/ej2-maps';
import { usa } from './usa_map';
Maps.Inject(DataLabel);
let maps: Maps = new Maps({
layers: [{
                shapeData: usMap,
                dataLabelSettings: {
                    visible: true,
                    labelPath: 'name',
                    intersectionAction: 'Trim'
                },
                shapeSettings: {
                    autofill: true
                }
                //..
         }]
});
maps.appendTo('#element');

 

A close up of a map

Description generated with high confidence

Sample link - Label intersection action

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied