Falke-Design / PMOrtho

Leaflet PMOrtho: Adds Ortho mode (45° steps) to Polyline, Polygon and Rectangle while shift holding
7 stars 2 forks source link

Creating multiple instances of PMOrtho results in errors #5

Closed etjenkins closed 3 years ago

etjenkins commented 3 years ago

First of all thanks for this really good extension for Geoman / Leaflet, I'm trying to use it in multiple components in an Angular website. Leaflet has no issue with having multiple maps instantiated across different components (note not displayed at the same time, they are on different screens). However adding in

let pmOrtho = new L.PMOrtho(map);

The first component containing a map loads with no issues and you can draw lines or polygons with the expected behaviour. However any further components that are loaded containing a map whenever you draw a line or polygon it results in the following errors:

Uncaught RangeError: Maximum call stack size exceeded at i.L.PM.Draw.Line.enable [as enableOrg] (index.js:190) at i.L.PM.Draw.Line.enable [as enableOrg] (index.js:190) at i.L.PM.Draw.Line.enable [as enableOrg] (index.js:190) at i.L.PM.Draw.Line.enable [as enableOrg] (index.js:190) at i.L.PM.Draw.Line.enable [as enableOrg] (index.js:190) at i.L.PM.Draw.Line.enable [as enableOrg] (index.js:190) at i.L.PM.Draw.Line.enable [as enableOrg] (index.js:190) at i.L.PM.Draw.Line.enable [as enableOrg] (index.js:190) at i.L.PM.Draw.Line.enable [as enableOrg] (index.js:190) at i.L.PM.Draw.Line.enable [as enableOrg] (index.js:190)

To prove if it was an issue with what I am doing I recreated this downloading your repository and simply by having 2 instantiations of the PMOrtho, like so:

let pmOrtho = new L.PMOrtho(map); let pmOrtho2 = new L.PMOrtho(map)

That results in the exact same issue. Is there a way to prevent this from happening? If PMOrtho can only be instantiated once that isn't a problem if there is a way to update the map component part of it, is that possible? It looks like there is an initialize method but I don't know if it is possible to access it as it only shows up in the objects __proto__

Any help would be greatly appreciated :)

Falke-Design commented 3 years ago

Thx for reporting, should be fixed now

etjenkins commented 3 years ago

That works now, thank you for fixing it, especially so fast 👍