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

Add HOOK to "userLocation" plugin #1177

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ZasoGD
Copy link

@ZasoGD ZasoGD commented Jan 20, 2017

Add an 'pluginUserLocation' hook, so other plugins can use the user coordinates.

Events:

  • 'setup' is fired when the marker is initialized. Returns the marker
    location;
  • 'onLocationChange' is fired when the marker location is changed.
    Returns the new marker location;
  • 'onOrientationChange' is fired when the marker direction is change.
    Returns the new marker direction (deg);

Add an 'pluginUserLocation' hook.
Events:
- 'setup' is fired when the marker is initialized. Returns the marker
location;
- 'onLocationChange' is fired when the marker location is changed.
Returns the new marker location;
- 'onOrientationChange' is fired when the marker direction is change.
Returns the new marker direction (deg);
@@ -152,6 +160,9 @@ window.plugin.userLocation.onOrientationChange = function(direction) {
"transform": "rotate(" + direction + "deg)",
"webkitTransform": "rotate(" + direction + "deg)"
});

// HOOK: fired when the marker direction is changed
window.runHooks('pluginUserLocation', {event: 'onOrientationChange', data:{ direction:direction }});
Copy link

Choose a reason for hiding this comment

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

Can you add data: latlng here for parameter consistency?

Copy link
Author

Choose a reason for hiding this comment

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

Yes I can, but this function has not the latlng data, I'll must get coordinates from a layer of plugin e.g. window.plugin.userLocation.marker.getLatLng(); Leafletjs getLatLng() method

Copy link
Author

Choose a reason for hiding this comment

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

Or I can create a window.plugin.userLocation.user object with inside latlng and direction.
The data are updated in this object, the users/plugins can get the data from the object and the hook only serves to notify when the data are changed.

Copy link

Choose a reason for hiding this comment

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

That sounds sensible - although I'd pass the userLocation.user argument as an argument

- add an object contains user location and direction;
- add a simple function to get the user data (loc and dir);
- when the hook is fired return the user object;
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