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.

DrawControl: edit layers button not working (again)

See original GitHub issue

This is very similar to #218, and happened after leaflet got updated to version 1.5.1 few days back. The error is in the leaflet-draw library, it’s passing undefined to setStyle function in leaflet and this breaks inside leaflet library.

Downgrading leaflet to 1.4.0 fixes this problem. Fixing it in leaflet-draw is probably not too hard, but there seems to be a backlog of 55 PRs in leaflet-draw library and no sign of activity for about 8 months, so not too sure on how quickly this will be addressed.

There is a different drawing plugin for leaflet https://github.com/codeofsumit/leaflet.pm it seems to provide same functionality, more in fact, and is more actively maintained, at least right now.

I’m willing to prototype a DrawControl based off leaflet.pm backend, I see three possible approaches:

  1. Replace leaflet-draw with pm.leaflet
  2. Add new control DrawControlPM to this extension
  3. Separate extension designed to work with this one and a compatible interface on python side.

Error Log

[Error] TypeError: undefined is not an object (evaluating 'style.hasOwnProperty')
	setStyle (vendors~main.c7481366bd1204a26e11.js:27357)
	addHooks (vendors~main.c7481366bd1204a26e11.js:87593:25906)
	(anonymous function) (vendors~main.c7481366bd1204a26e11.js:87593:24345)
	_eachVertexHandler (vendors~main.c7481366bd1204a26e11.js:87593:24229)
	addHooks (vendors~main.c7481366bd1204a26e11.js:87593:24322)
	enable (vendors~main.c7481366bd1204a26e11.js:25238)
	_enableLayerEdit (vendors~main.c7481366bd1204a26e11.js:87594:31731)
	eachLayer (vendors~main.c7481366bd1204a26e11.js:26386)
	addHooks (vendors~main.c7481366bd1204a26e11.js:87594:28799)
	enable (vendors~main.c7481366bd1204a26e11.js:25238)
	enable (vendors~main.c7481366bd1204a26e11.js:87594:28305)

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Kirill888commented, Jun 1, 2019

@martinRenou I have started a leaflet.pm version here: https://github.com/Kirill888/ipyleaflet/commit/b4078cb295bd3fe02db5dd1c63087b02c11db2a0

But there are few things that are different between leaflet-draw and leaflet-pm

  • no circlemarker in leaflet-pm
  • no cancel/save for edit/delete, things just happen immediately (no undo)
  • I haven’t done styling customization yet, but it should be possible
  • Controls position is fixed to topleft (for now at least)

On a plus side:

  • Dragging of polygons/polylines
  • Polygons with holes via pm:cut

Test notebook

import ipyleaflet as L
from ipywidgets import widgets as w

def mk_clear_button(target, action_name):
    b = w.Button(description=action_name.replace('_', ' '))
    action = getattr(target, action_name)
    b.on_click(lambda *a: action())
    return b

out = w.Output(layout=w.Layout(width='50%', 
                               height='400px', 
                               overflow_y='scroll'))
m = L.Map(zoom=2)
draw = L.DrawControl(
    edit=True,
    remove=True,
    circlemarker={'shapeOptions': {}},
    marker={'shapeOptions': {}},
    circle={'shapeOptions': {}},    
    polyline={'shapeOptions': {}},
    rectangle={'shapeOptions': {}},
    polygon = {'shapeOptions': {}})

def on_draw_handler(draw, action, geo_json):
    with out:
        print(action, geo_json)

btns = [mk_clear_button(draw, s) for s in dir(draw) if s.startswith('clear')]
btns.append(mk_clear_button(out, 'clear_output'))
draw.on_draw(on_draw_handler)
m.add_control(draw)
w.VBox([w.HBox(btns), 
        w.HBox([m, out])])
0reactions
martinRenoucommented, Jun 3, 2019

Thanks for looking at it @Kirill888 !

  • no circlemarker in leaflet-pm
  • no cancel/save for edit/delete, things just happen immediately (no undo)

I suppose we can just make a backward incompatible release of ipyleaflet with your changes, and open feature requests upstream?

  • Controls position is fixed to topleft (for now at least)

This is a known issue for most some of the controls https://github.com/jupyter-widgets/ipyleaflet/issues/367. We should also open feature requests upstream, or maybe even fix it ourselves opening PRs upstream.

Thanks again for looking into it. Don’t hesitate to open a PR when you are happy with what you have 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Leaflet.Draw edit and delete button not working - Stack Overflow
I've (re)used working code from other projects to create the draw control and pass it a FeatureGroup and editable layers. // My draw...
Read more >
FeatureGroup polygon and polyline cannot be edited with ...
Leaflet-draw plugin can work only with basic vector layers, which means that members of drawnItems layer can only be basic vector layers ......
Read more >
Leaflet Draw Documentation - UNPKG
The following disables drawing polygons and markers. It also turns off the ability to edit layers. var drawControl = new L.Control.Draw({ draw: {...
Read more >
Leaflet Draw Documentation
map.on('draw:edited', function (e) { var layers = e.layers; layers.eachLayer(function (layer) { //do whatever you want; most likely save back to db }); }); ......
Read more >
leaflet-draw-with-touch - npm package - Snyk
To use the edit toolbar you must initialise the Leaflet.draw control and manually ... map.on('draw:edited', function (e) { var layers = e.layers; layers....
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