Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SVGOverlay supports getLatLng/setLatLng methods for Tooltip/Popup bound. #7773

Closed
zxh19890103 opened this issue Nov 13, 2021 · 4 comments
Closed
Labels

Comments

@zxh19890103
Copy link

In my actual project, I use SVGOverlay to display an object needing tooltip support. But I found that tooltip tries accessing SVGOverlay method getLatLng which is not there. There is just getLatLngBounds method for those layers owning a region on map. But I hope even these layers would have getLatLng method which returns the center coordinates, or top/bottom/left/right border line's middle coordinates by an option given by users.

For setLatLng, it's function is to move the layer without changing the size of it.

@johnd0e
Copy link
Collaborator

johnd0e commented Nov 13, 2021

Thanks for taking the time to open an issue!
Please provide a general summary of the issue in the title above .

  • I've looked at the documentation to make sure the behavior is documented and expected
  • I'm sure this is a Leaflet code issue, not an issue with my own code nor with the framework I'm using (Cordova, Ionic, Angular, React…)
  • I've searched through the issues to make sure it's not yet reported

Steps to reproduce
Steps to reproduce the behavior:

  • step 1
  • step 2
  • ...

Expected behavior

Current behavior

Environment

  • Leaflet version:
  • Browser (with version):
  • OS/Platform (with version):

Additional context

Minimal example reproducing the issue

Please create an example using https://leafletjs.com/edit.html or any other jsfiddle-like site.

  • this example is as simple as possible
  • this example does not rely on any third party code

@zxh19890103
Copy link
Author

zxh19890103 commented Dec 9, 2021

const svg = new L.SVGOverlay(bounds).bindPopup('some words');

// later

svg.openPopup(); // This will throw an error.

svg.openPopup(L.latlng(0, 0)); // This works well.

bingTooltip is similar with popup.

My solution:

const MySvgOverlay = L.SVGOverlay.extend({
  getLatLng() {
    return computesCenterLatLng();
  }
}) as any;

@Falke-Design
Copy link
Member

Sample: https://plnkr.co/edit/KIHCpqTs1JDRyTZZ

Stacktrace:

Uncaught Error: Unable to get source layer LatLng.
    _prepareOpen DivOverlay.js:181
    openPopup Popup.js:421

@Falke-Design
Copy link
Member

This is already fixed by #7306 and #7540 in the newest master. But I created the PR #7848 to add getCenter function to the ImageOverlay and SVGOverlay.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants