Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

114
Views
LeafLet adding/linking a marker to a line or multiple tooltips for a line

I have the following:

var gcdLines = []; //Geodesic lines
var markers = [];

When I click on my map I add a new line:

var line = new L.Geodesic([gcdLastPoint, [e.latlng.lat, e.latlng.lng]], geodesicOptions);
                line.bindTooltip("brng and rng", { permanent: true }).addTo(mymap).openTooltip();
gcdLines.push(line);

If I press a button and click on the map I get a marker displayed:

        mymap.on('click', function (e) {                    
            if (showLLToggle == true) {
                var latlongstr = DegToDms(e.latlng);
                var marker1 = L.marker([e.latlng.lat, e.latlng.lng], {
                    draggable: false, 
                    title: "Location",
                    riseOnHover: true,
                }).on('click', removeMarker).addTo(markerGroup).bindTooltip(latlongstr, tooltipOptions).openTooltip();

So my markers are in a marker group and my lines are in a separate array/list.

My problem is that when I remove (through a button) the last line added from the gcdLines, the line is removed but the marker is not, and I cannot work out how to link them together so when the line removes the correct marker is also removed. As the last marker added may not be matching marker for the line i cannot just pop() the last marker.

I tried to add the marker information as a 2nd tooltip at the end of the new L.Geodesic line, which worked nicely but when I went to remove the last line it only removed one tool tip (the 2nd one I added). So I assume that I can't have 2 tooltips? Please tell me that I can, if so how do I remove the old tool tip which seems to have be lost in space.

Any ideas on how to link marker to line or have 2 tool tips would be appreciated, or any better ideas.

Thank you!

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!