-
Notifications
You must be signed in to change notification settings - Fork 81
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
Resolve #556: Improve geometry editing UI #720
Conversation
Note: I am not 100% satisfied with this PR because I prefer to hide the edit/delete buttons from the map toolbar when the existing geometry is being edited. But this makes things a bit messier for a couple of reasons:
|
874eb23
to
de221df
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree on your comments about hiding the edit button. I'm not sure how to proceed here. A part of me says, it works and it makes the workflow much simpler but then I think this could be better. I think, we have already reached the limits of what we can do with leaflet-draw. It's a very simple library; leaflet-editable for instance is much more flexible and allows us to make the editing process more intuitive, but it probably requires some work to integrate it with django-leaflet. Maybe we should just stick with it for the time being. @wonderchook @ian-ross Any opinions about this>
function enableMapEditMode() { | ||
var editButton = $('.leaflet-draw-edit-edit')[0]; | ||
if (!editButton) { | ||
setTimeout(enableMapEditMode, 500); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I generally don't like timeouts to check whether elements are present on the page, but I assume Leaflet-draw does not fire an event when it's ready?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I agree that that's bad. The only legitimate use for setTimeout
in JS code (unless you're using it to schedule tasks) is with a timeout of zero to defer processing until next time round the event loop. Putting actual timeouts in there is a recipe for disaster and very unpredictable bugs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I'm probably not the right person to ask about this. I find Leaflet.draw to be pretty nice, myself, and I don't find the workflow at all unintuitive. But I'm not the target audience.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, there's no event to indicate that the Leaflet.draw toolbar is ready. There's a core Leaflet event to say that the map itself is ready but none for the draw toolbar. I am very, very open to suggestions on a better way to check whether the draw toolbar is present.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there an element you can check for? If so, you can poll for it every 100 ms or so until it's there. (That's a legitimate use of setTimeout
!) But a one-shot timer that may or may not leave enough time for things to get set up isn't a good idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ian-ross, that is actually what I'm doing. I'm polling the presence of the edit button. enableMapEditMode
calls itself with a setTimeout
if the element is still not present.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
D'oh. I didn't notice that. In that case, I think this use of setTimeout
is fine! Very good! Sorry for the confusion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think at some point we are going to have to prioritize making the mapping much more friendly. (And add some requested features to make the geometry drawing more accurate). So I think this is fine for the time being. If any other requests come through related to the drawing we'll need to think through making it a larger feature to improve things.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds reasonable, I'm going to merge this.
de221df
to
c8678c0
Compare
This reverts commit 25ff256.
Proposed changes in this pull request
enableMapEditMode
andsaveOnMapEditMode
functions to core/static/js/map_utils.js. These take care of two behaviors described above respectively.When should this PR be merged
Anytime.
Risks
No risks foreseen.
Follow up actions
Since a static JavaScript file was modified, people need to clear their browser cache.