有没有一种简单的方法可以缩短 GeoJSON 图层上的线条?
我有一条线,它从 A 点到 B 点。我希望这条线在标记的半径附近停止。那可能吗?有点像从线路终点/起点的偏移量。
这是一个例子:
我有 50 x 50 的图标,但半透明(参见图片),并且有通往图标纬度/经度的线条,但我想在线条进入图标之前尝试裁剪或偏移线条,这样您就可以看不到图标下方的线。这可能吗?
如果这个问题不清楚,请评论。
![enter image description here](https://i.stack.imgur.com/YGH3E.png)
这可以使用dashArray
and dashOffset
选项:
var map = new L.Map('leaflet', {
center: [0, 0],
zoom: 0
});
new L.CircleMarker([0, 90], {radius: 30}).addTo(map);
new L.CircleMarker([0, -90], {radius: 30}).addTo(map);
var polyline = new L.Polyline([[0, -90], [0, 90]]).addTo(map);
// Get length of the line
var totalLength = polyline.getElement().getTotalLength();
polyline.setStyle({
// Set dashArray to the length of the line minus radius * 2
dashArray: totalLength - 60,
// Offset by radius
dashOffset: -30
});
body {
margin: 0;
}
html, body, #leaflet {
height: 100%;
}
<!DOCTYPE html>
<html>
<head>
<title>Leaflet 1.2.0</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link type="text/css" rel="stylesheet" href="//unpkg.com/[email protected]/dist/leaflet.css" />
</head>
<body>
<div id="leaflet"></div>
<script src="//unpkg.com/[email protected]/dist/leaflet.js"></script>
</body>
</html>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)