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

leaflet draw not working with latest angular version 10 #1005

Open
3 tasks done
archanatiwari opened this issue Dec 22, 2020 · 3 comments
Open
3 tasks done

leaflet draw not working with latest angular version 10 #1005

archanatiwari opened this issue Dec 22, 2020 · 3 comments

Comments

@archanatiwari
Copy link

archanatiwari commented Dec 22, 2020

  • I'm reporting a bug, asking for help.
  • I'm not sure this is a Leaflet Draw code issue, but angular upgrade to version 10, facing issue in library.
  • I've searched through the issues to make sure it's not yet reported

How to reproduce

  • Leaflet version I'm using: "@asymmetrik/ngx-leaflet": "^8.1.0",
  • Leaflet Draw version I'm using: "@asymmetrik/ngx-leaflet-draw": "^7.0.0",
  • Browser (with version) I'm using: Chrome (Version 87.0.4280.88 (Official Build) (64-bit))
  • OS/Platform (with version) I'm using: Windows 10

What behaviour I'm expecting and which behaviour I'm seeing

Steps:

  • while drawing the polygen or rectangle, first time it allowing to draw and second time throwing error in console. Please find the error message.
  • core.js:4442 ERROR ReferenceError: type is not defined
    at Object.readableArea (leaflet.draw.js:9)
    at NewClass._getMeasurementString (leaflet.draw.js:8)
    at NewClass._getTooltipText (leaflet.draw.js:8)
    at NewClass._updateTooltip (leaflet.draw.js:8)
    at NewClass._vertexChanged (leaflet.draw.js:8)
    at NewClass._vertexChanged (leaflet.draw.js:8)
    at NewClass.addVertex (leaflet.draw.js:8)
    at NewClass._endPoint (leaflet.draw.js:8)
    at NewClass._onTouch (leaflet.draw.js:8)
    at NewClass.fire (leaflet-src.js:588)

image

@kragoth
Copy link

kragoth commented Jan 4, 2021

@archanatiwari this issue is occurring for me as well when I upgraded from angular 9 to 11.

I think I know the problem too.

The readableArea function is using an undefined variable. It seems that in the upgrade to ng10/11 "strict" mode has been turned on. Thus, the use of an undeclared variable is not allowed.

Fixing this should be a matter of adding the "type" variable to the list of variable declarations in the readableArea function.

It looks like someone has already raised a PR to fix this issue here.

@kragoth
Copy link

kragoth commented Jan 4, 2021

It seems quite a few people have raised PRs to fix this issue but, there's no approvals going on it seems.
Not sure what we need to do to get them merged so this issue can be resolved.

In the meantime my current "hack" to get around this issue is to do this:

    // This is a hack due to a bug in leaflet.draw
    // https://github.com/Leaflet/Leaflet.draw/issues/1005
    (window as any).type = undefined;

I reset the value of the variable on component destroy (in angular) so... hopefully no leaking will occur.

@matkoniecz
Copy link

Not sure what we need to do to get them merged so this issue can be resolved.

It is pretty clear that this plugin is abandoned, see https://github.com/Leaflet/Leaflet.draw/graphs/contributors

Not sure is there a viable replacement - alternative project or a maintained fork

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

No branches or pull requests

3 participants