Drilldown in EJ2 TypeScript Maps control
27 Apr 20235 minutes to read
By clicking a continent, all the countries available in that continent can be viewed using the drill-down feature. For example, the countries in the Africa
continent have been showcased here. To showcase all the countries in Africa
continent by clicking the shapeSelected
event as mentioned in the following example.
import { world_map } from './world-map.ts';
import { Africa_Continent } from './Africa_Continent.ts';
import { default_data } from './data.ts';
import { Maps,Highlight,IShapeSelectedEventArgs,shapeSelected,Marker} from '@syncfusion/ej2-maps';
Maps.Inject(Highlight,Marker );
export interface ShapeData {
continent?: string;
}
// Initialize Maps component.
let map: Maps = new Maps({
shapeSelected: (args: IShapeSelectedEventArgs): void => {
let shape: string = (args.shapeData as ShapeData).continent;
if (shape === 'Africa') {
map.baseLayerIndex = 1;
map.refresh();
}
},
layers: [
{
shapeData: world_map,
shapePropertyPath: 'continent',
shapeDataPath: 'continent',
dataSource:default_data,
shapeSettings: {
colorValuePath: 'drillColor'
},
markerSettings: [{
visible: true,
template: '<div id="marker3" class="markerTemplate">Africa' +
'</div>',
dataSource: [
{ latitude: 10.97274101999902, longitude: 16.390625 }
],
animationDuration: 0
}]
},
{
shapeData: Africa_Continent,
shapeSettings: {
fill: '#80306A'
},
highlightSettings: {
enable: true,
fill: '#80306A'
}
}
]
});
map.appendTo('#element');
<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Maps</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Typescript UI Controls" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="world-map.js"></script>
<script src="africa_continent.js"></script>
<script src="data.js"></script>
<script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container' style="height: 500px; width: 700px">
<div id='element'></div>
</div>
</body>
</html>
<div id="mapdrilldown"></div>
<style>
.markerTemplate {
font-size: 12px;
color: white;
text-shadow: 0px 1px 1px black;
font-weight: 500
}
.markerTemplate {
height: 30px;
width: 30px;
display: block;
margin: auto;
}
</style>