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

Deleting/Adding to DrawControl Doesn't Render on Map #1013

Closed
CF-FHB-X opened this issue Jul 5, 2022 · 3 comments
Closed

Deleting/Adding to DrawControl Doesn't Render on Map #1013

CF-FHB-X opened this issue Jul 5, 2022 · 3 comments

Comments

@CF-FHB-X
Copy link

CF-FHB-X commented Jul 5, 2022

Hi there!

Just trying to understand how the relationship works between the Map and DrawControl. Our use case allows for users to create/edit/delete polygons by using the DrawControl tool. Each polygon gets a new ipywidgets.Tab (for adding attribute data) in an ipywidgets.VBox below the map.

What I'd like to do is also allow for creating/editing/deleting those polygons from the VBox (each Tab gets a "Delete" button, for example). Or I would like to programmatically add a polygon to the DrawControl when the user adds clicks something like a "Add Polygon" button.

Where I'm running into problems is that I can create/edit/delete the GeoJSON in the DrawControl.data list, but the map never changes. Am I missing a refresh option for either the Map or the DrawControl widget?

Thanks in advance!

@giswqs
Copy link
Contributor

giswqs commented Jul 5, 2022

Relevant issue: #849

@davidbrochart
Copy link
Member

@CF-FHB-X I'm suspecting you modify DrawControl.data in-place, for instance if you have:

dc.data = [{'type': 'Feature',
  'properties': {'style': {'stroke': True,
    'color': '#0000FF',
    'weight': 4,
    'opacity': 0.5,
    'fill': True,
    'fillColor': None,
    'fillOpacity': 0.2,
    'clickable': True}},
  'geometry': {'type': 'Polygon',
   'coordinates': [[[-78.290075, 34.622152],
     [-78.290075, 34.709432],
     [-78.111588, 34.709432],
     [-78.111588, 34.622152],
     [-78.290075, 34.622152]]]}}]

Then dc.data[0]["geometry"]["coordinates"][0][0][0] = -78.5 will not do anything. You need to assign to dc.data as a whole:

dc.data = [{'type': 'Feature',
  'properties': {'style': {'stroke': True,
    'color': '#0000FF',
    'weight': 4,
    'opacity': 0.5,
    'fill': True,
    'fillColor': None,
    'fillOpacity': 0.2,
    'clickable': True}},
  'geometry': {'type': 'Polygon',
   'coordinates': [[[-78.5, 34.622152],
     [-78.290075, 34.709432],
     [-78.111588, 34.709432],
     [-78.111588, 34.622152],
     [-78.290075, 34.622152]]]}}]

This is a limitation of traitlets.

@CF-FHB-X
Copy link
Author

CF-FHB-X commented Jul 5, 2022

Ah-ha! That did it - thanks!

@CF-FHB-X CF-FHB-X closed this as completed Jul 5, 2022
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