admin管理员组文章数量:1404924
I want to show label/Text with polylines, Here is my code
function displayDottedLine(latA, longA, latB, longB, label) {
var pointA = new L.LatLng(latA, longA);
var pointB = new L.LatLng(latB, longB);
var pointList = [pointA, pointB];
var firstpolyline = new L.Polyline(pointList, {
color: 'white',
weight: 1.5,
opacity: 0.5,
dashArray: "10 10",
smoothFactor: 1
});
firstpolyline.addTo(map);
}
there is label parameter in the function, i need to attach this label with polylines.
Thanks in advance.
I want to show label/Text with polylines, Here is my code
function displayDottedLine(latA, longA, latB, longB, label) {
var pointA = new L.LatLng(latA, longA);
var pointB = new L.LatLng(latB, longB);
var pointList = [pointA, pointB];
var firstpolyline = new L.Polyline(pointList, {
color: 'white',
weight: 1.5,
opacity: 0.5,
dashArray: "10 10",
smoothFactor: 1
});
firstpolyline.addTo(map);
}
there is label parameter in the function, i need to attach this label with polylines.
Thanks in advance.
Share asked Mar 21, 2019 at 4:57 Muhammad WaqarMuhammad Waqar 1151 silver badge11 bronze badges1 Answer
Reset to default 5You can try leaflet.textpath.js plugin
window.addEventListener('load', function() {
var map = L.map('map').setView([51.328125, 42.2935], 18);
L.tileLayer('https://{s}.tile.openstreetmap/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.openstreetmap/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
var plane = L.polyline([
[3.33984375, 46.6795944656402],
[29.53125, 46.55886030311719],
[51.328125, 42.293564192170095],
]).addTo(map);
map.fitBounds(plane.getBounds());
plane.setText('SAMPLE TEXT', {center: true});
});
#map {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%
}
<link rel="stylesheet" href="https://unpkg./[email protected]/dist/leaflet.css" />
<script src="https://unpkg./[email protected]/dist/leaflet.js"></script>
<script src="https://cdn.jsdelivr/npm/[email protected]/leaflet.textpath.min.js"></script>
<div id="map"></div>
本文标签: javascriptLabel for Leaflet PolylinesStack Overflow
版权声明:本文标题:javascript - Label for Leaflet Polylines - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744863088a2629186.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论