-
Notifications
You must be signed in to change notification settings - Fork 23
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 permissionStatus
property
#32
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,8 @@ | |
"location", | ||
"position", | ||
"navigation", | ||
"api", | ||
"permission", | ||
"coordinates", | ||
"latitude", | ||
"longitude", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,10 +7,16 @@ | |
<!-- | ||
Geolocation API Polymer web component. | ||
|
||
Example to get the device geolocation values: | ||
Get once and display the device geolocation values and continuous update the Geolocation API permission status: | ||
|
||
```html | ||
<geo-location latitude="{{latitude}}" longitude="{{longitude}}"></geo-location> | ||
<geo-location permission-status="{{permissionStatus}}" latitude="{{latitude}}" longitude="{{longitude}}"></geo-location> | ||
|
||
<ul> | ||
<li>Permission status: [[permissionStatus]]</li> | ||
<li>Latitude: [[latitude]]</li> | ||
<li>Longitude: [[longitude]]</li> | ||
</ul> | ||
``` | ||
|
||
Continuous update the device geolocation values with high accuracy, and center Google Maps map and marker to the current location: | ||
|
@@ -85,15 +91,15 @@ | |
}, | ||
|
||
/** | ||
* The maximumAge option in the Gelocation API. | ||
* The maximumAge option in the Geolocation API. | ||
*/ | ||
maximumAge: { | ||
type: Number, | ||
value: 0 | ||
}, | ||
|
||
/** | ||
* The timeout option in the Gelocation API. | ||
* The timeout option in the Geolocation API. | ||
*/ | ||
timeout: { | ||
type: Number, | ||
|
@@ -108,6 +114,15 @@ | |
notify: true, | ||
readOnly: true, | ||
value: null | ||
}, | ||
|
||
/** | ||
* [Status](https://w3c.github.io/permissions/#status-of-a-permission) of Geolocation API permission. | ||
*/ | ||
permissionStatus: { | ||
type: String, | ||
readOnly: true, | ||
notify: true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. needs a default state. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ebidel Is not the default value optional? Should I use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean that if we do not specify a default value at all, it is equivalent to |
||
} | ||
|
||
}, | ||
|
@@ -134,6 +149,19 @@ | |
* @param {Number} detail.longitude Longitude of the current position. | ||
*/ | ||
|
||
attached: function() { | ||
if ('permissions' in navigator) { | ||
navigator.permissions.query({ | ||
name: 'geolocation' | ||
}).then(function(permissionStatus) { | ||
this._setPermissionStatus(permissionStatus.state); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need to handle the permissions api not being available. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ebidel What should we do if Permissions API is not available? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably fail silently, but the |
||
permissionStatus.onchange = function() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens if this element gets attached/detached/attached from the DOM? Does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ebidel I don't know. Could you please help me do this in a better way? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As the author of this PR, I was hoping you could do that research. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ebidel BTW, what about placing this code inside |
||
this._setPermissionStatus(permissionStatus.state); | ||
}.bind(this); | ||
}.bind(this)); | ||
} | ||
}, | ||
|
||
detached: function () { | ||
this._clearWatch(this._watch); | ||
}, | ||
|
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.
don't think we need these. they're vague
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.
@ebidel I've removed the
permission
keyword. But IMO we should keep theapi
keyword.<geo-location>
web component is a part of my progressive-elements collection that is a set of web components for modern web APIs such as Payment Request API, Media Session API, etc. People can find these web components by theapi
keyword.