question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Polyline tooltips seem inconsistent

See original GitHub issue

Here are a bunch of polylines with tooltips bound to them: https://www.dropbox.com/s/1bwladr9kmr128e/leaflet-polyline-tooltip.mov

Note that the tooltips appear at the top-left of rectangular polylines, but at the center-left-ish? of non-rectangular ones.

I was trying to set the offset of tooltips to be the center of the polylines, but since the offset added to the default position of the tooltip, and that default position seems inconsistent, it’s hard to add to.

Related, it looks like the tooltip.offset option is meant to be in pixels, but that means you need to change it after every pan/zoom? Seems like it should be a lat/long instead, then it could be set once per layer.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
endquotecommented, Sep 4, 2017

I decided I’d rather have the tooltip at the mouse position, and follow the mouse. I was able to get that working. https://www.dropbox.com/s/ph7i6aiy6u3rezu/leaflet-polyline-tooltip-follow.mov

So really this bug should be “how do I position a tooltip with absolute coordinates?”, and the answer is “use openTooltip(<LatLng> latlng?)”. It just took a while to figure it out.

if (!this.tooltip) {
  if (this.defaultZoneLayer) {
    this.tooltip = this.defaultZoneLayer.bindTooltip('', { direction: 'right' });
  }
}

if (this.tooltip) {
  if (hits.length) {
    this.tooltip.setTooltipContent(hits.join('<br>'));
    const pos = { clientX: e.clientX + 10, clientY: e.clientY };
    this.defaultZoneLayer.openTooltip(this.map.mouseEventToLatLng(pos));
  } else {
    this.defaultZoneLayer.closeTooltip();
  }
}
0reactions
ghybscommented, Sep 7, 2017

Hi @endquote,

For the use case where you want the Tooltip to follow the mouse, it seems to me that the sticky option might be what you need: http://playground-leaflet.rhcloud.com/wele/1/edit?html,output

myShape.bindTooltip('tooltipText', {
  sticky: true // If true, the tooltip will follow the mouse.
});

You may also use it in combination with offset and direction options.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Polyline mouseover event to display some sort of message ...
I have a map in which the polylines for any given vehicle route is displayed. These polylines can all display at once. I...
Read more >
Read Leaflet Tips and Tricks | Leanpub
This might seem slightly confusing, but it's just a simple hierarchy which we can flesh out by doing the same thing for each...
Read more >
3D slice BUG - Autodesk Community - AutoCAD
This inconsistency is what I referred to, loosely, as a "bug" and that it would seem more desirable to be consistent in operation....
Read more >
Flyspray::QCAD Bugtracker: Tasklist
1865, QCAD (main), Bug Report, Low, Scaling polyline with width by negative factor removes . ... dark theme / invisible shortcuts in tool...
Read more >
Issues · Inkscape / Inbox - GitLab
New Page margins field needs a good tooltip, concept is inconsistent in itself, comma doesn't work ... Implement poly-line connectors connecting to vertices....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found