Markers in EJ2 TypeScript Maps control
27 Apr 202324 minutes to read
Markers are notes that are used to leave a message on the Maps. It indicates or marks a specific location with desired symbols on the Maps. It can be enabled by setting the visible
property of the markerSettings
to true. To render Markers in Maps, Marker module must be injected into the Maps using Maps.Inject(Marker) method.
import { Maps, Marker } from '@syncfusion/ej2-maps';
Maps.Inject(Marker);
let map: Maps = new Maps({ });
Adding marker
The dataSource
property of the markerSettings
has a list of objects that contains the data for Markers. Using this property, any number of markers can be added to the shape layers. By default, it displays the markers based on the specified latitude and longitude in the given data source. Each data source object contains the following list of properties.
- label - Text that displays some information about the marker in text format.
- latitude - The latitude point which determines the X location of the marker.
- longitude - The longitude point which determines the Y location of the marker.
markerSettings is an Array property.
import { world_map } from './world-map.ts';
import { Maps, Marker} from '@syncfusion/ej2-maps';
Maps.Inject(Marker);
let map: Maps = new Maps({
layers: [{
shapeData: world_map,
markerSettings: [
{
visible: true,
height: 20,
width: 20,
dataSource: [
{ latitude: 49.95121990866204, longitude: 18.468749999999998 },
{ latitude: 59.88893689676585, longitude: -109.3359375 },
{ latitude: -6.64607562172573, longitude: -55.54687499999999 }
],
animationDuration: 0,
},
]
}]
});
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="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>
Adding marker template
The Marker can be added as a template in the Maps component. The template
property of the markerSettings
is used to set the Marker as a template. HTML element or id of an element can be added as the template in Markers.
import { world_map } from './world-map.ts';
import { Maps, Marker} from '@syncfusion/ej2-maps';
Maps.Inject(Marker);
let map: Maps = new Maps({
layers: [{
shapeData: world_map,
markerSettings: [{
visible: true,
template: '<div id="marker4" class="markerTemplate">Europe' + '</div>',
dataSource: [
{ latitude: 49.95121990866204, longitude: 18.468749999999998 }
],
animationDuration: 0,
},
{
visible: true,
template: '<div id="marker5" class="markerTemplate" style="width:50px">North America' + '</div>',
dataSource: [
{ latitude: 59.88893689676585, longitude: -109.3359375 }
],
animationDuration: 0
},
{
visible: true,
template: '<div id="marker6" class="markerTemplate" style="width:50px">South America' + '</div>',
dataSource: [
{ latitude: -6.64607562172573, longitude: -55.54687499999999 }
],
animationDuration: 0
}]
}]
});
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="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>
Customization
The following properties are available in markerSettings
to customize the Markers of the Maps component.
-
border
- To customize the color, width and opacity of the border for the markers in Maps. -
fill
- To apply the color for markers in Maps. -
dashArray
- To define the pattern of dashes and gaps that is applied to the outline of the markers in Maps. -
height
- To customize the height of the markers in Maps. -
width
- To customize the width of the markers in Maps. -
offset
- To customize the position of the markers in Maps. -
opacity
- To customize the transparency of the markers in Maps. -
animationDelay
- To change the time delay in the transition for markers. -
animationDuration
- To change the time duration of animation for markers. -
highlightSettings
- To customize the highlight settings for the marker in Maps. -
selectionSettings
- To customize the selection settings for the marker in Maps.
import { world_map } from './world-map.ts';
import { Maps, Marker} from '@syncfusion/ej2-maps';
Maps.Inject(Marker);
let map: Maps = new Maps({
layers: [{
shapeData: world_map,
markerSettings: [{
visible: true,
border: {
color: 'green',
width: 2
},
fill: 'red',
dashArray: '1',
height: 20,
width: 20,
opacity: 0.9,
animationDelay: 100,
animationDuration: 1000,
shape: 'Balloon',
dataSource: [
{ latitude: 37.0000, longitude: -120.0000, city: 'California' },
{ latitude: 40.7127, longitude: -74.0059, city: 'New York' },
{ latitude: 42, longitude: -93, city: 'Iowa' }
]
}]
}]
});
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="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>
Marker shapes
The Maps component supports the following marker shapes. To set the shape of the marker, the shape
property in markerSettings
is used.
- Balloon
- Circle
- Cross
- Diamond
- Image
- Rectangle
- Start
- Triangle
- VerticalLine
- HorizontalLine
Rendering marker shape as image
To render a marker as an image in Maps, set the shape
property of markerSettings
as Image and specify the path of the image to imageUrl
property. There is another way to render a marker as an image using the imageUrlValuePath
property of the markerSettings
. Bind the field name that contains the path of the image in the data source to the imageUrlValuePath
property.
import { world_map } from './world-map.ts';
import { Maps, Marker} from '@syncfusion/ej2-maps';
Maps.Inject(Marker);
let map: Maps = new Maps({
layers: [{
shapeData: world_map,
markerSettings: [{
visible: true,
shape: 'Image',
imageUrl: 'https://ej2.syncfusion.com/demos/src/maps/images/ballon.png',
height: 20,
width: 20,
dataSource: [
{ latitude: 37.0000, longitude: -120.0000, city: 'California' },
{ latitude: 40.7127, longitude: -74.0059, city: 'New York' },
{ latitude: 42, longitude: -93, city: 'Iowa' }
]
}]
}]
});
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="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>
Multiple marker groups
Multiple group of markers can be added to the Maps using the markerSettings
in which the properties of markers are added as an array. The customization for the markers can be done with the markerSettings
.
import { world_map } from './world-map.ts';
import { Maps, Marker} from '@syncfusion/ej2-maps';
Maps.Inject(Marker);
let map: Maps = new Maps({
layers: [{
shapeData: world_map,
markerSettings: [{
visible: true,
shape: 'Diamond',
height: 15,
fill: "green",
width: 15,
dataSource: [
{
latitude: 37.0000, longitude: -120.0000, name:'California',
},
{
latitude: 40.7127, longitude: -74.0059, name:"New York"
},
{
latitude: 42, longitude: -93, name:'Iowa'
}
]
},
{
visible: true,
dataSource: [{
latitude: 19.228825, longitude: 72.854118, name: "Mumbai"
}, {
latitude: 28.610001, longitude: 77.230003, name: "Delhi"
}, {
latitude: 13.067439, longitude: 80.237617, name: "Chennai"
}],
shape: 'Circle',
fill: "blue",
height: 10,
width: 10
}],
}]
});
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="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>
Customize marker shapes from data source
Bind different colors and shapes to the marker from data source
Using the shapeValuePath
and colorValuePath
properties, apply the color and shape of the marker from the given data source. Bind the data source to the dataSource
property of the markerSettings
and set the field names that contains the shape and color values in the data source to the shapeValuePath
and colorValuePath
properties. A default marker object is represented by a balloon shape. To set various shapes to the marker object by using the shape
property in markerSettings
.
The following shapes are used for the marker object.
- Circle
- Rectangle
- Balloon
- Cross
- Polyline
- Diamond
- Star
- Triangle
- HorizontalLine
- VerticalLine
- pentagon
import { world_map } from './world-map.ts';
import { Maps, Marker} from '@syncfusion/ej2-maps';
Maps.Inject(Marker);
let map: Maps = new Maps({
layers: [{
shapeData: world_map,
markerSettings: [{
visible: true,
shapeValuePath:'shape',
colorValuePath:'color',
dataSource: [
{ latitude: 49.95121990866204, longitude: 18.468749999999998, name:'Europe', color:'red', shape:'Triangle' },
{ latitude: 59.88893689676585, longitude: -109.3359375, name:'North America',
color:'blue', shape:'Pentagon' },
{ latitude: -6.64607562172573, longitude: -55.54687499999999, name:'South America',
color:'green', shape:'InvertedTriangle' }
]
}],
}]
});
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="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>
Setting value path from the data source
The latitude and longitude values are used to determine the location of each marker in the Maps. The latitudeValuePath
and longitudeValuePath
properties are used to specify the value path that presents in the data source of the marker. In the following example, the field name from the data source is set to the latitudeValuePath
and longitudeValuePath
properties.
import { world_map } from './world-map.ts';
import { Maps, Marker} from '@syncfusion/ej2-maps';
Maps.Inject(Marker);
let map: Maps = new Maps({
layers: [{
shapeData: world_map,
markerSettings: [{
visible: true,
latitudeValuePath: 'latitude',
longitudeValuePath: 'longitude',
dataSource: [
{ latitude: 49.95121990866204, longitude: 18.468749999999998 },
{ latitude: 59.88893689676585, longitude: -109.3359375},
{ latitude: -6.64607562172573, longitude: -55.54687499999999 }
]
}],
}]
});
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="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>
Repositioning the marker using drag and drop
The markers on the map can be dragged and dropped to change their position. To enable marker drag and drop, set the enableDrag property to true in the markerSettings property.
import { world_map } from './world-map.ts';
import { Maps, Marker, MapsTooltip } from '@syncfusion/ej2-maps';
Maps.Inject(Marker, MapsTooltip );
let map: Maps = new Maps({
layers: [{
shapeData: world_map,
shapeSettings: {
fill: '#C3E6ED'
},
markerSettings: [
{
enableDrag: true,
dataSource: [
{ latitude: 49.95121990866204, longitude: 18.468749999999998, name:'MarkerOne' },
{ latitude: 59.88893689676585, longitude: -109.3359375, name:'MarkerTwo'},
{ latitude: -6.64607562172573, longitude: -55.54687499999999 , name:'MarkerThree'},
{ latitude: 23.644385824912135, longitude: 77.83189239539234 , name:'MarkerFour'},
{ latitude: 63.66569332894224, longitude: 98.2225173953924 , name:'MarkerFive'}
],
visible: true,
animationDuration: 0,
shape: 'Balloon',
width: 20,
height: 20,
border: { width: 2, color: '#285255' },
tooltipSettings: {
visible: true,
valuePath: 'name',
}
},
]
}]
});
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="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>
The data of the drag and dropped marker in the marker data source can be customized using the markerDragStart and markerDragEnd events. When you change the appropriate marker data, the tooltip and legend item text of that marker are automatically updated. The following properties are available in the event argument of the marker drag events.
Argument Name | Description |
---|---|
dataIndex | It represents the index of the data of the dragged marker in the marker data source. |
latitude | It represents the latitude coordinate point of the dragged marker. |
longitude | It represents the longitude coordinate point for the dragged marker. |
markerIndex | It represents the index of the marker setting. |
layerIndex | It represents the index of the layer in which the marker belongs. |
name | It represents the name of the event. |
x | It represents the horizontal location of the mouse pointer on the map when the drag action is performed. |
y | It represents the vertical location of the mouse pointer on the map when the drag action is performed. |
The following example shows how to use marker drag events to customize the data of the drag and dropped marker in the marker data source.
import { world_map } from './world-map.ts';
import { Maps, Marker, Legend, MapsTooltip } from '@syncfusion/ej2-maps';
Maps.Inject(Marker, Legend, MapsTooltip );
let map: Maps = new Maps({
legendSettings:{
visible:true,
type:'Markers',
shape:'Circle',
shapeWidth:10,
shapeHeight:10,
fill:'#FF471A',
shapeBorder: { width: 2, color: '#285255' },
},
markerDragStart: function(args){
// When the marker begins to move on the map, the event is triggered.
},
markerDragEnd: function(args) {
// When the marker on the map stops dragging, the event is triggered.
let mapsInstance = document.getElementById('element').ej2_instances[0];
mapsInstance.layers[args.layerIndex].markerSettings[args.markerIndex].dataSource[args.dataIndex].name = 'Dragged Marker ' + (args.dataIndex + 1);
mapsInstance.refresh();
},
layers: [{
shapeData: world_map,
shapeSettings: {
fill: '#C3E6ED'
},
markerSettings: [
{
enableDrag: true,
legendText:'name',
dataSource: [
{ latitude: 49.95121990866204, longitude: 18.468749999999998, name:'MarkerOne' },
{ latitude: 59.88893689676585, longitude: -109.3359375, name:'MarkerTwo'},
{ latitude: -6.64607562172573, longitude: -55.54687499999999 , name:'MarkerThree'},
{ latitude: 23.644385824912135, longitude: 77.83189239539234 , name:'MarkerFour'},
{ latitude: 63.66569332894224, longitude: 98.2225173953924 , name:'MarkerFive'}
],
visible: true,
animationDuration: 0,
shape: 'Balloon',
width: 20,
height: 20,
border: { width: 2, color: '#285255' },
tooltipSettings: {
visible: true,
valuePath: 'name',
}
},
]
}]
});
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="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>
Marker zooming
The Maps is initially scaled to the center value based on the marker distance. This can be achieved by setting the shouldZoomInitially
property in zoomSettings
as true.
import { world_map } from './world-map.ts';
import { Maps, Marker, Zoom} from '@syncfusion/ej2-maps';
Maps.Inject(Marker, Zoom);
let map: Maps = new Maps({
zoomSettings: {
enable: true,
shouldZoomInitially: true,
toolbarSettings: {
horizontalAlignment: 'Near'
}
},
layers: [{
shapeData: world_map,
markerSettings: [{
visible: true,
dataSource: [
{ latitude: 49.95121990866204, longitude: 18.468749999999998, name:'Europe' },
{ latitude: 59.88893689676585, longitude: -109.3359375, name:'North America' },
{ latitude: -6.64607562172573, longitude: -55.54687499999999, name:'South America'}
]
}],
}]
});
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="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>
Marker clustering
Maps provide support to hide and cluster markers when they overlap each other. The number on a cluster indicates how many overlapped markers it contains. If zooming any of the cluster locations in Maps, the number on the cluster will decrease and begin to see the individual markers on the map. When zooming out, the overlapping marker will increase so that it can cluster again and increase the count over the cluster.
To enable clustering in markers, set the allowClustering
property of markerClusterSettings
as true and customization of clustering can be done with the markerClusterSettings
.
import { world_map } from './world-map.ts';
import { cluster } from './cluster.ts'
import { Maps , Marker,MapsTooltip, MarkerSettings } from '@syncfusion/ej2-maps';
Maps.Inject(Marker,MapsTooltip);
// initialize Maps component
let map: Maps = new Maps({
useGroupingSeparator: true,
format: 'n',
zoomSettings: {
enable: true
},
titleSettings: {
text: 'Top 13 largest cities in the World',
textStyle: {
size: '16px'
}
},
layers: [
{
shapeData: world_map,
shapeSettings: {
fill: '#C1DFF5'
},
markerClusterSettings: {
allowClustering: true,
shape: 'Circle',
height: 40,
width: 40,
labelStyle : { color: 'white'},
},
markerSettings: [
{
visible: true,
dataSource: cluster,
shape: 'Balloon',
tooltipSettings: {
format: 'City: ${city} <br> Area: ${area}',
visible: true,
valuePath: 'area',
},
height: 20,
width: 20,
animationDuration: 0
},
]
}
]
});
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="cluster.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>
Customization of marker cluster
The following properties are available to customize the marker clustering in the Maps component.
-
border
- To customize the color, width and opacity of the border of cluster in Maps. -
connectorLineSettings
- To customize the connector line in cluster separating the markers. -
dashArray
- To customize the dash array for the marker cluster in Maps. -
fill
- Applies the color of the cluster in Maps. -
height
- To customize the height of the marker cluster in Maps. -
imageUrl
- To customize the URL path for the marker cluster when the cluster shape is set as image in Maps. -
labelStyle
- To customize the text in marker cluster. -
offset
- To customize the offset position for the marker cluster in Maps. -
opacity
- To customize the opacity of the marker cluster. -
shape
- To customize the shape for the cluster of markers. -
width
- To customize the width of the marker cluster in Maps.
import { world_map } from './world-map.ts';
import { cluster } from './cluster.ts'
import { Maps , Marker,MapsTooltip, Point } from '@syncfusion/ej2-maps';
Maps.Inject(Marker,MapsTooltip);
// initialize Maps component
let map: Maps = new Maps({
zoomSettings: {
enable: true
},
layers: [{
shapeData: world_map,
shapeSettings: {
fill: '#C1DFF5'
},
markerClusterSettings: {
allowClustering: true,
allowClusterExpand: true,
shape: 'Circle',
height: 40,
width: 40,
labelStyle : { color: 'white'},
offset: new Point(10, 20),
opacity: 0.9,
fill: 'green',
connectorLineSettings: {
color: 'orange',
opacity: 0.8,
width: 2
}
},
markerSettings: [{
visible: true,
dataSource: cluster,
shape: 'Balloon',
tooltipSettings: {
format: 'City: ${city} <br> Area: ${area}',
visible: true,
valuePath: 'area',
},
height: 20,
width: 20,
animationDuration: 0
}]
}]
});
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="cluster.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>
Marker cluster expand
The cluster is formed by grouping an identical and non-identical marker from the surrounding area. By clicking on the cluster and setting the allowClusterExpand
property in markerClusterSettings
as true to expand the identical markers. If zoom in any of the locations of the cluster, the number on the cluster will decrease and the overlapping marker will be split into an individual marker on the map. When performing zoom out, it will increase the marker count and then cluster it again.
import { world_map } from './world-map.ts';
import { Maps, Marker, Zoom} from '@syncfusion/ej2-maps';
Maps.Inject(Marker, Zoom);
let map: Maps = new Maps({
zoomSettings: {
enable: true,
mouseWheelZoom : true,
},
layers: [{
shapeData: world_map,
markerClusterSettings: {
allowClustering: true,
allowClusterExpand: true,
shape: 'Circle',
height: 40,
width: 40,
labelStyle : { color: 'white'},
},
markerSettings: [{
visible: true,
dataSource: [
{ latitude: 49.95121990866204, longitude: 18.468749999999998, name:'Europe' },
{ latitude: 49.95121990866204, longitude: 18.468749999999998, name:'Europe' },
{ latitude: 49.95121990866204, longitude: 18.468749999999998, name:'Europe' },
{ latitude: 49.95121990866204, longitude: 18.468749999999998, name:'Europe' },
{ latitude: 49.95121990866204, longitude: 18.468749999999998, name:'Europe' },
{ latitude: 49.95121990866204, longitude: 18.468749999999998, name:'Europe' },
{ latitude: 49.95121990866204, longitude: 18.468749999999998, name:'Europe' },
{ latitude: 59.88893689676585, longitude: -109.3359375, name:'North America' },
{ latitude: -6.64607562172573, longitude: -55.54687499999999, name:'South America'}
]
}],
}]
});
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="cluster.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>
Tooltip for marker
Tooltip is used to display more information about a marker on mouse over or touch end event. This can be enabled separately for marker by setting the visible
property of tooltipSettings
to true. The valuePath
property in the tooltipSettings
takes the field name that presents in data source and displays that value as tooltip text.
import { usa_map } from './usa.ts';
import { Maps , Marker,MapsTooltip, MarkerSettings } from '@syncfusion/ej2-maps';
Maps.Inject(Marker, MapsTooltip);
// initialize Maps component
let map: Maps = new Maps({
layers: [
{
shapeData: usa_map,
markerSettings: [
{
dataSource: [
{ latitude: 40.7424509, longitude: -74.0081468, city: 'New York' }
],
visible:true,
shape:'Circle',
fill:'white',
width:3,
animationDuration:0,
border: { width:2, color:'green'},
tooltipSettings: {
visible: true,
valuePath:'city'
}
}
]
}
],
height: '450px',
width: '700px'
});
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="usa.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>