-
Notifications
You must be signed in to change notification settings - Fork 552
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
base: master
Are you sure you want to change the base?
Conversation
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 }}); |
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.
Can you add data: latlng here for parameter consistency?
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.
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
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.
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.
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 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;
Add an 'pluginUserLocation' hook, so other plugins can use the user coordinates.
Events:
location;
Returns the new marker location;
Returns the new marker direction (deg);