Data labels provide information to users about the shapes of the Maps component. It can be enabled by setting the visible
property of the dataLabelSettings
to true.
To display data labels in the Maps, the labelPath
property of dataLabelSettings
must be used. The value of the labelPath
property can be taken from the field name in the shape data or data source. In the following example, the value of the labelPath
property is the field name in the shape data of the Maps layer.
<template>
<div id="app">
<div class='wrapper'>
<ejs-maps >
<e-layers>
<e-layer :shapeData='shapeData' :shapeSettings='shapeSettings'
:dataLabelSettings='dataLabelSettings'></e-layer>
</e-layers>
</ejs-maps>
</div>
</div>
</template>
<script>
import Vue from 'vue';
import { MapsPlugin, DataLabel } from '@syncfusion/ej2-vue-maps';
import { usMap } from './usa.js';
Vue.use(MapsPlugin);
export default {
data () {
return {
shapeData: usMap,
shapeSettings: {
autofill:true
},
dataLabelSettings: {
visible: true,
labelPath: 'name'
}
}
},
provide: {
maps: [DataLabel]
},
}
</script>
<style>
.wrapper {
max-width: 400px;
margin: 0 auto;
}
</style>
In the following example, the value of labelPath
property is set from the field name in the data source of the layer settings.
<template>
<div id="app">
<div class='wrapper'>
<ejs-maps >
<e-layers>
<e-layer :shapeData='shapeData' :shapeSettings='shapeSettings'
:dataLabelSettings='dataLabelSettings'></e-layer>
</e-layers>
</ejs-maps>
</div>
</div>
</template>
<script>
import Vue from 'vue';
import { MapsPlugin, DataLabel } from '@syncfusion/ej2-vue-maps';
import { world_map } from './world-map.js';
Vue.use(MapsPlugin);
export default {
data () {
return{
shapeData: world_map,
shapePropertyPath: 'name',
shapeDataPath: 'name',
dataLabelSettings: {
visible: true,
labelPath: "continent",
smartLabelMode: 'Trim'
},
dataSource: [
{"name": "Afghanistan", "value": 53, "countryCode": "AF", "population": "29863010", "color": "red", "density": "119", "continent": "Asia"},
{"name": "Albania", "value": 117, "countryCode": "AL", "population": "3195000", "color": "Blue", "density": "111", "continent": "Europe"},
{"name": "Algeria", "value": 15, "countryCode": "DZ", "population": "34895000", "color": "Green", "density": "15", "continent": "Africa"}
],
shapeSettings: {
autofill: true
}
}
},
provide: {
maps: [DataLabel]
},
}
</script>
<style>
.wrapper {
max-width: 400px;
margin: 0 auto;
}
</style>
The following properties are available in the dataLabelSettings
to customize the data label of the Maps component.
border
- To customize the color, width and opacity for the border of the data labels in Maps.fill
- To apply the color of the data labels in Maps.opacity
- To customize the transparency of the data labels in Maps.textStyle
- To customize the text style of the data labels in Maps.<template>
<div id="app">
<div class='wrapper'>
<ejs-maps >
<e-layers>
<e-layer :shapeData='shapeData' :shapeSettings='shapeSettings'
:dataLabelSettings='dataLabelSettings'></e-layer>
</e-layers>
</ejs-maps>
</div>
</div>
</template>
<script>
import Vue from 'vue';
import { MapsPlugin, DataLabel } from '@syncfusion/ej2-vue-maps';
import { usMap } from './usa.js';
Vue.use(MapsPlugin);
export default {
data () {
return {
shapeData: usMap,
shapeSettings: {
autofill:true
},
dataLabelSettings: {
visible: true,
labelPath: 'name',
border: {
color: 'green',
width: 2
},
fill: 'red',
opacity: 0.9,
textStyle: {
color: 'blue',
size: '10px',
fontStyle: 'Sans-serif',
fontWeight: 'normal'
}
}
}
},
provide: {
maps: [DataLabel]
},
}
</script>
<style>
.wrapper {
max-width: 400px;
margin: 0 auto;
}
</style>
The Maps component provides an option to handle the labels when they intersect with the corresponding shape borders using the smartLabelMode
property. The following options are available in the smartLabelMode
property.
<template>
<div id="app">
<div class='wrapper'>
<ejs-maps >
<e-layers>
<e-layer :shapeData='shapeData' :shapeSettings='shapeSettings'
:dataLabelSettings='dataLabelSettings'></e-layer>
</e-layers>
</ejs-maps>
</div>
</div>
</template>
<script>
import Vue from 'vue';
import { MapsPlugin, DataLabel } from '@syncfusion/ej2-vue-maps';
import { usMap } from './usa.js';
Vue.use(MapsPlugin);
export default {
data () {
return {
shapeData: usMap,
shapeSettings: {
autofill:true
},
dataLabelSettings: {
visible: true,
labelPath: 'name',
smartLabelMode:'Hide'
}
}
},
provide: {
maps: [DataLabel]
},
}
</script>
<style>
.wrapper {
max-width: 400px;
margin: 0 auto;
}
</style>
The Maps component provides an option to handle the labels when a label intersects with another label using the intersectionAction
property. The following options are available in the intersectionAction
property.
<template>
<div id="app">
<div class='wrapper'>
<ejs-maps >
<e-layers>
<e-layer :shapeData='shapeData' :shapeSettings='shapeSettings'
:dataLabelSettings='dataLabelSettings'></e-layer>
</e-layers>
</ejs-maps>
</div>
</div>
</template>
<script>
import Vue from 'vue';
import { MapsPlugin, DataLabel } from '@syncfusion/ej2-vue-maps';
import { usMap } from './usa.js';
Vue.use(MapsPlugin);
export default {
data () {
return {
shapeData: usMap,
shapeSettings: {
autofill:true
},
dataLabelSettings: {
visible: true,
labelPath: 'name',
intersectionAction:'Trim'
}
}
},
provide: {
maps: [DataLabel]
},
}
</script>
<style>
.wrapper {
max-width: 400px;
margin: 0 auto;
}
</style>
The data label can be added as a template in the Maps component. The template
property of dataLabelSettings
is used to set the data label as a template. Any text or HTML element can be added as the template in data labels.
The customization properties of data label,
smartLabelMode
andintersectionAction
properties are not applicable totemplate
property. The styles can be applied to the label template using the CSS styles of the template element.
<template>
<div id="template">
<div class='wrapper'>
<ejs-maps >
<e-layers>
<e-layer :shapeData='shapeData' :shapeSettings='shapeSettings'
:dataLabelSettings='dataLabelSettings'></e-layer>
</e-layers>
</ejs-maps>
</div>
</div>
</template>
<script>
import Vue from 'vue';
import { MapsPlugin, DataLabel } from '@syncfusion/ej2-vue-maps';
import { usMap } from './usa.js';
Vue.use(MapsPlugin);
let contentVue = Vue.component("contentTemplate", {
template: '<div>Label</div>',
data() {
return {
data: {}
};
}
});
let contentTemplate = function() {
return { template: contentVue };
};
export default {
data () {
return {
shapeData: usMap,
shapeSettings: {
autofill:true
},
dataLabelSettings: {
visible: true,
labelPath: 'name',
template: contentTemplate
}
}
},
provide: {
maps: [DataLabel]
},
}
</script>
<style>
.wrapper {
max-width: 400px;
margin: 0 auto;
}
</style>