Ich benutze Canvas-Tag, um Kreise auf der Weltkarte Bild zu erstellen. Ich möchte mehrere Kreise mit Linien verbinden, indem ich das Canvas-Tag verwende. Ab jetzt kann ich Kreise zeichnen, konnte aber keine Linien zeichnen.So verbinden Sie Kreise mit Linien mit Leinwand
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 */
Sie wissen, dass Sie alle vier Kreise in einer Leinwand ziehen kann? Dann können Sie einfach die Mittelpunktkoordinaten der Kreise als Quelle und Ursprung für die Linien verwenden. –
danke @ThomasAltmann – Sjay