index.html
<!DOCTYPE html>
<html>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Geometry - Connector Lines</title>
<style type="text/css">
html,body{margin:0px;height:100%;width:100%}
.container{width:100%;height:100%}
</style>
<link rel="stylesheet" href="https://unpkg.com/maptalks/dist/maptalks.css">
<script type="text/javascript" src="https://unpkg.com/maptalks/dist/maptalks.min.js"></script>
<body>
<div id="map" class="container"></div>
<script>
var map = new maptalks.Map('map', {
center: [-0.113049,51.498568],
zoom: 14,
baseLayer: new maptalks.TileLayer('base', {
urlTemplate: 'https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png',
subdomains: ["a","b","c","d"],
attribution: '© <a href="http://osm.org">OpenStreetMap</a> contributors, © <a href="https://carto.com/">CARTO</a>'
})
});
var layer = new maptalks.VectorLayer('vector').addTo(map);
// blue circle
var src = new maptalks.Marker(
[-0.128449,51.503568],
{
symbol: {
'markerType' : 'ellipse',
'markerFill' : 'rgb(135,196,240)',
'markerFillOpacity' : 0.8,
'markerLineColor' : '#fff',
'markerLineWidth' : 3,
'markerWidth' : 120,
'markerHeight' : 120
}
}
);
// red circle
var dst = new maptalks.Marker(
[-0.102149,51.503568],
{
'draggable' : true,
'symbol': [
{
'markerType' : 'ellipse',
'markerFill' : 'rgb(216,115,149)',
'markerFillOpacity' : 0.8,
'markerLineColor' : '#fff',
'markerLineWidth' : 3,
'markerWidth' : 70,
'markerHeight' : 70
},
{
'textName' : 'Drag\nMe',
'textSize' : 18,
'textFill' : '#fff',
'textWrapCharacter' : '\n'
}
]
}
);
// connector line
var line = new maptalks.ConnectorLine(src, dst, {
showOn : 'always', //'moving', 'click', 'mouseover', 'always'
arrowStyle : 'classic',
arrowPlacement : 'vertex-last',// 'vertex-last', //vertex-first, vertex-last, vertex-firstlast, point
symbol: {
lineColor: '#34495e',
lineWidth: 2
}
});
layer.addGeometry(src, dst, line);
var src2 = src.copy().translate(0, -0.01);
var dst2 = dst.copy().translate(0, -0.01);
// Arc Connector Line
var line2 = new maptalks.ArcConnectorLine(src2, dst2, {
arcDegree : 90,
showOn : 'always',
symbol: {
lineColor: '#34495e',
lineWidth: 2
}
});
layer.addGeometry(src2, dst2, line2);
</script>
</body>
</html>