Custom HTML Elements as Map Markers
This example demonstrates how you can use JavaScript Maps' API functions and events to easily add custom-styled HTML elements as map markers.
Each map marker is a separate <code><div></code> element with two child elements. Styled using CSS.
Markers are placed into map's container and globally-positioned using <code>top</code> and <code>left</code> style properties. The code uses JavaScript Maps' built-in API functions <a href="http://docs.amcharts.com/3/javascriptmaps/AmMap#longitudeToX"><code>longitudeToX()</code></a> and <a href="http://docs.amcharts.com/3/javascriptmaps/AmMap#latitudeToY"><code>latitudeToY()</code></a> to translate marker's longitude and latitude into screen coordinates.
by Rogério Saraceni
April 23, 2019
HTML
<script src="https://www.amcharts.com/lib/3/ammap.js"></script>
<script src="https://www.amcharts.com/lib/3/maps/js/worldLow.js"></script>
<script src="https://www.amcharts.com/lib/3/plugins/export/export.min.js"></script>
<link rel="stylesheet" href="https://www.amcharts.com/lib/3/plugins/export/export.css" type="text/css" media="all" />
<div id="chartdiv"></div>
CSS
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
}
#chartdiv {
width: 100%;
height: 500px;
}
.map-marker {
/* adjusting for the marker dimensions
so that it is centered on coordinates */
margin-left: -8px;
margin-top: -8px;
}
.map-marker.map-clickable {
cursor: pointer;
}
.pulse {
width: 10px;
height: 10px;
border: 5px solid #f7f14c;
-webkit-border-radius: 30px;
-moz-border-radius: 30px;
border-radius: 30px;
background-color: #716f42;
z-index: 10;
position: absolute;
}
.map-marker .dot {
border: 10px solid red;
background: transparent;
-webkit-border-radius: 60px;
-moz-border-radius: 60px;
border-radius: 60px;
height: 50px;
width: 50px;
-webkit-animation: pulse 3s ease-out;
-moz-animation: pulse 3s ease-out;
animation: pulse 3s ease-out;
-webkit-animation-iteration-count: infinite;
-moz-animation-iteration-count: infinite;
animation-iteration-count: infinite;
position: absolute;
top: -20px;
left: -20px;
z-index: 1;
opacity: 0;
}
@-moz-keyframes pulse {
0% {
-moz-transform: scale(0);
opacity: 0.0;
}
25% {
-moz-transform: scale(0);
opacity: 0.1;
}
50% {
-moz-transform: scale(0.1);
opacity: 0.3;
}
75% {
-moz-transform: scale(0.5);
opacity: 0.5;
}
100% {
-moz-transform: scale(1);
opacity: 0.0;
}
}
@-webkit-keyframes "pulse" {
0% {
-webkit-transform: scale(0);
opacity: 0.0;
}
25% {
-webkit-transform: scale(0);
opacity: 0.1;
}
50% {
-webkit-transform: scale(0.1);
opacity: 0.3;
}
75% {
-webkit-transform: scale(0.5);
opacity: 0.5;
}
100% {
-webkit-transform: scale(1);
opacity: 0.0;
}
}
JavaScript
/**
* This example uses pulsating circles CSS by Kevin Urrutia
* http://kevinurrutia.tumblr.com/post/16411271583/creating-a-css3-pulsating-circle
*/
var map = AmCharts.makeChart( "chartdiv", {
"type": "map",
"theme": "none",
"projection": "miller",
"imagesSettings": {
"rollOverColor": "#089282",
"rollOverScale": 3,
"selectedScale": 3,
"selectedColor": "#089282",
"color": "#13564e"
},
"areasSettings": {
"unlistedAreasColor": "#15A892"
},
"dataProvider": {
"map": "worldLow",
"images": [ {
"zoomLevel": 5,
"scale": 0.5,
"title": "Brussels",
"latitude": 50.8371,
"longitude": 4.3676
}, {
"zoomLevel": 5,
"scale": 0.5,
"title": "Copenhagen",
"latitude": 55.6763,
"longitude": 12.5681
}, {
"zoomLevel": 5,
"scale": 0.5,
"title": "Paris",
"latitude": 48.8567,
"longitude": 2.3510
}, {
"zoomLevel": 5,
"scale": 0.5,
"title": "Reykjavik",
"latitude": 64.1353,
"longitude": -21.8952
}, {
"zoomLevel": 5,
"scale": 0.5,
"title": "Moscow",
"latitude": 55.7558,
"longitude": 37.6176
}, {
"zoomLevel": 5,
"scale": 0.5,
"title": "Madrid",
"latitude": 40.4167,
"longitude": -3.7033
}, {
"zoomLevel": 5,
"scale": 0.5,
"title": "London",
"latitude": 51.5002,
"longitude": -0.1262,
"url": "http://www.google.co.uk"
}, {
"zoomLevel": 5,
"scale": 0.5,
"title": "Peking",
"latitude": 39.9056,
"longitude": 116.3958
}, {
"zoomLevel": 5,
"scale": 0.5,
"title": "New Delhi",
"latitude": 28.6353,
"longitude": 77.2250
}, {
"zoomLevel": 5,
"scale": 0.5,
"title": "Tokyo",
"latitude": 35.6785,
"longitude": 139.6823,
"url": "http://www.google.co.jp"
}, {
"zoomLevel": 5,
"scale": 0.5,
"title":...