javascript - Label for Leaflet Polylines - Stack Overflow

I want to show labelText with polylines, Here is my codefunction displayDottedLine(latA, longA, latB,

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 badges
Add a ment  | 

1 Answer 1

Reset to default 5

You 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: '&copy; <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>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744863088a4597818.html

相关推荐

  • javascript - Label for Leaflet Polylines - Stack Overflow

    I want to show labelText with polylines, Here is my codefunction displayDottedLine(latA, longA, latB,

    1天前
    50

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信