0

I am using a map with CRS.Simple. In order to draw polygons, I chose the SVG option. I know it's not the best way. And most likely it is not true. But please tell me how to bind SVG - popup Leaflet to polygons? Or, how to make unproject using GeoJSON so that the coordinates are displayed correctly.

var popup = L.popup()
  .setContent('<p>Hello world!<br />This is a nice popup.</p>');

var svgElementBounds = [ [ 0, h ], [w, 0] ];
var svgElement = document.createElementNS("http://www.w3.org/2000/svg", "svg");
    svgElement.setAttribute('xmlns', "http://www.w3.org/2000/svg");
    svgElement.setAttribute('viewBox', "0 0 1200 1200");
    svgElement.innerHTML = polygons
L.svgOverlay(svgElement, svgElementBounds, {
  interactive: true
}
  ).addTo(map).bindPopup(popup);

Polygon example from SVG

<polygon id="_361" class="fil1 str0" points="975.1,185 976.5,222 1038.4,220 1036,186.6 986.8,187.7 "/>

If I use .bindPopup(popup); for svgOverlay - popup works, however it works across the entire SVG. I want to bind it to polygons

2
  • Popups can't be bound to SVG overlay to work only for polygons. As for the other question "how to make unproject using GeoJSON so that the coordinates are displayed correctly", this is separate question and should be published as such.
    – TomazicM
    Jul 19 at 6:47
  • @TomazicM Thank you very much for the answer. I'm going to ask this question then. Jul 19 at 7:22

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.