I am currently utilizing the canvas tag to generate circles on a world map image. My objective is to link these multiple circles with lines using the Canvas tag. Although I have successfully drawn the circles, I am facing difficulty in drawing the connecting lines.
HTML
<img src="http://educypedia.karadimov.info/library/worldoutlinemap.gif" width="500"/>
<canvas id="myCanvas1" width="200" height="200"></canvas>
<canvas id="myCanvas2" width="200" height="200"></canvas>
<canvas id="myCanvas3" width="200" height="200"></canvas>
<canvas id="myCanvas4" width="200" height="200"></canvas>
CSS
#myCanvas1
{
position: absolute;
top: 20px;
left: 245px;
z-index: 3;
}
#myCanvas2
{
position: absolute;
top: 20px;
left: 25px;
z-index: 3;
}
#myCanvas3
{
position: absolute;
top: 200px;
left: 60px;
z-index: 3;
}
#myCanvas4
{
position: absolute;
top: 150px;
left: 200px;
z-index: 3;
}
Javascript
/* circle1 */
var canvas = document.getElementById('myCanvas1');
var context = canvas.getContext('2d');
var centerX = canvas.width / 2;
var centerY = canvas.height / 2;
var radius = 10;
context.beginPath();
context.arc(centerX, centerY, radius, 0, 2 * Math.PI, false);
context.fillStyle = 'grey';
context.fill();
context.stroke();
/* circle1 */
/* circle2 */
var canvas = document.getElementById('myCanvas2');
var context = canvas.getContext('2d');
var centerX = canvas.width / 2;
var centerY = canvas.height / 2;
var radius = 10;
context.beginPath();
context.arc(centerX, centerY, radius, 0, 2 * Math.PI, false);
context.fillStyle = 'grey';
context.fill();
context.stroke();
/* circle2 */
/* circle3 */
var canvas = document.getElementById('myCanvas3');
var context = canvas.getContext('2d');
var centerX = canvas.width / 2;
var centerY = canvas.height / 2;
var radius = 10;
context.beginPath();
context.arc(centerX, centerY, radius, 0, 2 * Math.PI, false);
context.fillStyle = 'grey';
context.fill();
context.stroke();
/* circle3 */
/* circle4 */
var canvas = document.getElementById('myCanvas4');
var context = canvas.getContext('2d');
var centerX = canvas.width / 2;
var centerY = canvas.height / 2;
var radius = 10;
context.beginPath();
context.arc(centerX, centerY, radius, 0, 2 * Math.PI, false);
context.fillStyle = 'grey';
context.fill();
context.stroke();
/* circle4 */