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

Feature - Support Map handlers when component updated #452

Merged
merged 5 commits into from
Mar 13, 2018

Conversation

jwarykowski
Copy link
Contributor

Overview

Currently, if an end user changes any of the top level handler options in the Map component the associated Leaflet handlers aren't updated when the component updates.

In our own use case, we switch on and off the doubleClickZoom functionality when switching between various modes in our application. I noticed the other handlers were missing so I've included these.

@jwarykowski
Copy link
Contributor Author

jwarykowski commented Feb 28, 2018

Node 6 build failing on Travis CI with:

error @shellscape/[email protected]: The engine "node" is incompatible with this module. Expected version ">= 7.6.0".
error Found incompatible module

@PaulLeCam - don't know whether you've seen this before or whether its inconsistent, but if you can re-run that would be great.

Copy link
Owner

@PaulLeCam PaulLeCam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR, good idea!

Could you merge from master please? That should fix the failing Travis build.
Could you also update the documentation regarding the "dynamic properties" of the Map component please?

}

if (scrollWheelZoom !== fromProps.scrollWheelZoom) {
if (scrollWheelZoom === true || typeof scrollWheelZoom === 'string') {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why checking if scrollWheelZoom is a string?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scrollWheelZoom accepts a boolean value or a string in the latest leaflet documentation

}

if (touchZoom !== fromProps.touchZoom) {
if (touchZoom === true || typeof touchZoom === 'string') {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why checking if touchZoom is a string?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above - link

@jwarykowski jwarykowski force-pushed the feature/update-map-handlers branch 2 times, most recently from c1d2c14 to d18b5c9 Compare February 28, 2018 22:03
@jwarykowski
Copy link
Contributor Author

@PaulLeCam Updated as discussed. Just to note, I took another look at the Leaflet source code regarding the string value that can be passed for scrollWheelZoom and touchZoom and it appears to only check for the 'center' value so I've made the above conditionals stricter.

After looking at the leaflet source code it looks like you can only
pass a boolean value or the string 'center'. Therefore I've made these
conditionals stricter as it doesn't support any other string value.
@jwarykowski jwarykowski force-pushed the feature/update-map-handlers branch from d18b5c9 to 934442d Compare March 1, 2018 00:58
@PaulLeCam
Copy link
Owner

Thanks!
I think it might needs additional logic in the scrollWheelZoom and touchZoom, the behavior when setting the value to center would enable the handler, but as if the value provided was true rather than the expected center behavior, unless I'm missing something?

One way to achieve this could be to update the map.options Object in the Leaflet element to reflect the change, I don't think it needs to check for the center value specifically, checking for the string type is likely a better way to make sure the behavior will also work for other values that could be added by Leaflet later.

@jwarykowski
Copy link
Contributor Author

jwarykowski commented Mar 3, 2018

Hey @PaulLeCam, I've reset the conditional logic for scrollWheelZoom and touchZoom in the latest commit.

In terms of your first point, I'm not entirely sure what you mean. However, the logic checks whether the changed value is true OR a string type. In terms of the leaflet code, regardless of the value passed (true or center), we just need to enable/disable the handler.

It checks the value passed down when performing an action e.g. scrollWheelZoom's _performZoom

Let me know if you want me to update anything else.

@PaulLeCam
Copy link
Owner

Thanks for the changes!

Regarding enabling the handler when setting the value to center for scrollWheelZoom and touchZoom, I'm not sure it's enough to enter this condition for example. If I understand it correctly, if the map is created with scrollWheelZoom={false} and then updated to scrollWheelZoom="center", the handler would be enabled but not behaving as expected because map.options.scrollWheelZoom would still have the value false, so I think before enabling the handler, this.leafletElement.options.scrollWheelZoom should be set to the scrollWheelZoom value in updateLeafletElement(), does it make sense?

@jwarykowski
Copy link
Contributor Author

Hey @PaulLeCam, apologies, now I know what you mean. Thanks for the detailed explanation above. I've updated the functionality in the latest commit.

@jwarykowski
Copy link
Contributor Author

Hey @PaulLeCam, just checking (no rush) but is there anything else to add here?

@PaulLeCam
Copy link
Owner

Looks great, thanks!
Sorry I don't have much time to play with the branch at the moment but I'll try to get to it in the coming days.

@PaulLeCam PaulLeCam merged commit 2d24847 into PaulLeCam:master Mar 13, 2018
@jwarykowski jwarykowski deleted the feature/update-map-handlers branch March 13, 2018 10:02
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

Successfully merging this pull request may close these issues.

2 participants