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!