-
Notifications
You must be signed in to change notification settings - Fork 34
TILES-7536 fix show copyright message #590
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
7ef2b2f
TILES-7536 fix show copyright message
Nortren e7214cc
TILES-7536 fix show message
Nortren aab0fc5
TILES-7536 fix show message
Nortren 02819ec
TILES-7536 fix show message
Nortren 732614f
TILES-7536 fix show message
Nortren 1e294b8
TILES-7536 fix show message
Nortren 0be8ec9
TILES-7536 fix after review
Nortren a7ab057
TILES-7536 fix after review
Nortren 1cece39
TILES-7536 fix after review
Nortren d3d9c1e
TILES-7536 fix after review
Nortren 27aff6f
TILES-7536 fix after review
Nortren e2abbd8
TILES-7536 fix after review
Nortren c5258c3
TILES-7536 fix after review
Nortren bf83eec
TILES-7536 fix after review
Nortren File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| DG.ApiKeyValidator = DG.Class.extend({ | ||
| initialize: function(apiKey) { | ||
| initialize: function(apiKey, mapContainer) { | ||
| this.apiKey = apiKey; | ||
| this.endpoint = DG.config.keyServer + apiKey + DG.config.keyServices; | ||
| this.isLoading = false; | ||
|
|
@@ -8,6 +8,8 @@ DG.ApiKeyValidator = DG.Class.extend({ | |
| this.request = null; | ||
| this.MAX_ATTEMPTS = 4; | ||
| this.keyRequestInterval = [0, 2, 2, 2]; | ||
| this.isErrorWasShown = false; | ||
| this.mapContainer = mapContainer; | ||
| }, | ||
|
|
||
| validate: function(callback) { | ||
|
|
@@ -20,6 +22,14 @@ DG.ApiKeyValidator = DG.Class.extend({ | |
| this._makeAttempt(callback); | ||
| }, | ||
|
|
||
| validateKeyResponse: function() { | ||
| this.validate(function(response) { | ||
| if (!response || this._isResponseInvalid(response)) { | ||
| this._showError(); | ||
| } | ||
| }.bind(this)); | ||
| }, | ||
|
|
||
| _makeAttempt: function(callback) { | ||
| if (this.attempts > 0) { | ||
| this.lastTimeout = window.setTimeout(function() { | ||
|
|
@@ -31,31 +41,39 @@ DG.ApiKeyValidator = DG.Class.extend({ | |
| } | ||
| }, | ||
|
|
||
| _executeRequest: function(callback) { | ||
| var xhr = new XMLHttpRequest(); | ||
| xhr.open('GET', this.endpoint, true); | ||
| _isResponseInvalid: function(response) { | ||
| return ( | ||
| response.meta.code === 400 || | ||
| response.meta.code === 404 || | ||
| response.result && | ||
| (!response.result.service.is_active || | ||
| !response.result.is_active || | ||
| response.result.service.status.code !== 'ok' | ||
| ) | ||
| ); | ||
| }, | ||
|
|
||
| xhr.onreadystatechange = function() { | ||
| if (xhr.readyState === 4) { | ||
| if (xhr.status === 200) { | ||
| try { | ||
| var response = JSON.parse(xhr.responseText); | ||
| this.isLoading = false; | ||
| callback(response); | ||
| } catch (e) { | ||
| this._handleError(callback, xhr.status); | ||
| } | ||
| } else { | ||
| this._handleError(callback, xhr.status); | ||
| } | ||
| } | ||
| }.bind(this); | ||
| _showError: function() { | ||
|
|
||
| xhr.onerror = function() { | ||
| this._handleError(callback, xhr.status); | ||
| }.bind(this); | ||
| if (!this.isErrorWasShown && this.mapContainer) { | ||
| var errorMessage = DG.DomUtil.create('div', 'dg-error-message'); | ||
| errorMessage.innerHTML = 'Your RasterJS API key is invalid. Please contact [email protected] to get RasterJS API key.'; | ||
| this.mapContainer.appendChild(errorMessage); | ||
| this.isErrorWasShown = true; | ||
| } | ||
| }, | ||
|
|
||
| xhr.send(); | ||
| _executeRequest: function(callback) { | ||
| this.request = DG.ajax(this.endpoint, { | ||
| type: 'GET', | ||
| success: function(response) { | ||
| this.isLoading = false; | ||
| callback(response); | ||
| }.bind(this), | ||
| error: function(xhr) { | ||
| this._handleError(callback, xhr.status); | ||
| }.bind(this) | ||
| }); | ||
| }, | ||
|
|
||
| _handleError: function(callback, status) { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,30 +16,9 @@ DG.Map.addInitHook(function() { | |
| }); | ||
|
|
||
| var apiKey = this.options.key || DG.config.key; | ||
|
|
||
| this.isErrorWasShown = false; | ||
| function handleTileError() { | ||
| var errorMessage = DG.DomUtil.create('div', 'dg-error-message'); | ||
| if (!this.isErrorWasShown) { | ||
| errorMessage.innerHTML = 'Your RasterJS API key is invalid. Please contact [email protected] to get RasterJS API key.'; | ||
|
|
||
| var mapContainer = this.map.getContainer(); | ||
|
|
||
| if (mapContainer) { | ||
| mapContainer.appendChild(errorMessage); | ||
| } | ||
|
|
||
| this.isErrorWasShown = true; | ||
| } | ||
| } | ||
|
|
||
| var validator = new DG.ApiKeyValidator(apiKey); | ||
| validator.validate(function(response) { | ||
|
|
||
| if (response.meta.code === 400 || response.meta.code === 404 || response.result && (!response.result.service.is_active || !response.result.is_active || response.result.service.status.code !== 'ok')) { | ||
| handleTileError.call(this); | ||
| } | ||
| }); | ||
| var mapContainer = this.getContainer(); | ||
| var validator = new DG.ApiKeyValidator(apiKey, mapContainer); | ||
| validator.validateKeyResponse(); | ||
|
|
||
| var tileUrl = DG.config.secureProtocol + (DG.Browser.retina ? DG.config.retinaTileServer : DG.config.tileServer); | ||
| var arabicTileUrl = DG.config.secureProtocol + | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.