def doViewInGoogleMaps(self): """Open the selected map in Google Maps viewer.""" token = oauth2_utils.getToken() url = ('https://mapsengine.google.com/' '%s-4/mapview/?' 'access_token=%s') currentLayer = self.iface.mapCanvas().currentLayer() gmeMap, unused_gmeLayers = self.getAssetsFromLayer(currentLayer) mapId = gmeMap.id gmapUrl = url % (mapId, token.access_token) webbrowser.open(gmapUrl)
def doSignInOrOut(self, checked): """Show the sign-in dialog and manage authentication status. Args: checked: bool, whether the sign-in action was checked. """ if checked: # check if client_id and client_secret exist client_id = settings.read('gmeconnector/CLIENT_ID') client_secret = settings.read('gmeconnector/CLIENT_SECRET') if client_id and client_secret: token = oauth2_utils.getToken() if token: self.token = token self.handleAuthChange(True, token, '') else: # The sign-in dialog is initialized when the plugin is loaded. # We need to have setInitialUrl outside the dialog constructor to make # sure it's called everytime the sign-in button is clicked. self.signInDlg.setInitialUrl() result = self.signInDlg.exec_() if not result: self.handleAuthChange(False, None, '') else: self.signIn.setChecked(False) warnText = ('You must enter valid OAuth2.0 Client ID ' 'and Client secret in Advanced Settings.') QMessageBox.warning(self.iface.mainWindow(), 'Warning', warnText) self.doShowMore() else: self.token = None self.signIn.setText('Logged out. Click to log in.') self.signIn.setChecked(False) self.disableAllTools() # Revoke the token oauth2_utils.revokeToken() # Remove the access credientials from settings settings.clear()