From 7ef2b2f1e2f4e1b3868012ab0049383daf052e21 Mon Sep 17 00:00:00 2001 From: nortren Date: Tue, 29 Apr 2025 16:25:56 +0300 Subject: [PATCH 01/14] TILES-7536 fix show copyright message --- src/DGAttribution/src/DGAttribution.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DGAttribution/src/DGAttribution.js b/src/DGAttribution/src/DGAttribution.js index aef45652..5d024dc8 100644 --- a/src/DGAttribution/src/DGAttribution.js +++ b/src/DGAttribution/src/DGAttribution.js @@ -207,7 +207,7 @@ DG.Control.Attribution.include({ return { 'logotype': isHideButton, 'work_on': this.t('work_on'), - 'has_no_key': this._isDefaultKey ? null : this.t('has_no_key'), + 'has_no_key': this._isDefaultKey ? this.t('has_no_key') : null, 'lang': lang, 'copyright_apilink': this._getLink('copyright_apilink'), 'copyright_license': this._getLink('copyright_license'), From e7214cc38e5672ca3df5f277213b451cab50cd14 Mon Sep 17 00:00:00 2001 From: nortren Date: Tue, 29 Apr 2025 17:14:33 +0300 Subject: [PATCH 02/14] TILES-7536 fix show message --- src/DGCustomization/src/DGMap.BaseLayer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DGCustomization/src/DGMap.BaseLayer.js b/src/DGCustomization/src/DGMap.BaseLayer.js index fc489230..45abe889 100644 --- a/src/DGCustomization/src/DGMap.BaseLayer.js +++ b/src/DGCustomization/src/DGMap.BaseLayer.js @@ -23,7 +23,7 @@ DG.Map.addInitHook(function() { if (!this.isErrorWasShown) { errorMessage.innerHTML = 'Your RasterJS API key is invalid. Please contact api@2gis.com to get RasterJS API key.'; - var mapContainer = this.map.getContainer(); + var mapContainer = this.map.getContainer() || this.map; if (mapContainer) { mapContainer.appendChild(errorMessage); From aab0fc5309651fcb92ddaa5a75e11dfd796b5883 Mon Sep 17 00:00:00 2001 From: nortren Date: Tue, 29 Apr 2025 17:25:00 +0300 Subject: [PATCH 03/14] TILES-7536 fix show message --- src/DGCustomization/src/DGMap.BaseLayer.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/DGCustomization/src/DGMap.BaseLayer.js b/src/DGCustomization/src/DGMap.BaseLayer.js index 45abe889..524f5574 100644 --- a/src/DGCustomization/src/DGMap.BaseLayer.js +++ b/src/DGCustomization/src/DGMap.BaseLayer.js @@ -23,7 +23,9 @@ DG.Map.addInitHook(function() { if (!this.isErrorWasShown) { errorMessage.innerHTML = 'Your RasterJS API key is invalid. Please contact api@2gis.com to get RasterJS API key.'; - var mapContainer = this.map.getContainer() || this.map; + // В дев режиме можно напрямую получить контейнер, но после build обращение к карте идёт через this + var containerIsAvailable = this.map.getContainer; + var mapContainer = containerIsAvailable ? this.map.getContainer() : this.map; if (mapContainer) { mapContainer.appendChild(errorMessage); From 02819ec75cb5cbcbfaaca9743480768253f2e740 Mon Sep 17 00:00:00 2001 From: nortren Date: Wed, 30 Apr 2025 13:58:51 +0300 Subject: [PATCH 04/14] TILES-7536 fix show message --- src/DGCustomization/src/DGMap.BaseLayer.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/DGCustomization/src/DGMap.BaseLayer.js b/src/DGCustomization/src/DGMap.BaseLayer.js index 524f5574..d5c109fd 100644 --- a/src/DGCustomization/src/DGMap.BaseLayer.js +++ b/src/DGCustomization/src/DGMap.BaseLayer.js @@ -23,9 +23,7 @@ DG.Map.addInitHook(function() { if (!this.isErrorWasShown) { errorMessage.innerHTML = 'Your RasterJS API key is invalid. Please contact api@2gis.com to get RasterJS API key.'; - // В дев режиме можно напрямую получить контейнер, но после build обращение к карте идёт через this - var containerIsAvailable = this.map.getContainer; - var mapContainer = containerIsAvailable ? this.map.getContainer() : this.map; + var mapContainer = this.map.getContainer() if (mapContainer) { mapContainer.appendChild(errorMessage); @@ -39,9 +37,9 @@ DG.Map.addInitHook(function() { 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); + handleTileError(); } - }); + }.bind(this)); var tileUrl = DG.config.secureProtocol + (DG.Browser.retina ? DG.config.retinaTileServer : DG.config.tileServer); var arabicTileUrl = DG.config.secureProtocol + From 732614f8c6d92dd0cf975e4161cce3547dbd76f5 Mon Sep 17 00:00:00 2001 From: nortren Date: Wed, 30 Apr 2025 14:22:45 +0300 Subject: [PATCH 05/14] TILES-7536 fix show message --- src/DGCustomization/src/DGMap.BaseLayer.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/DGCustomization/src/DGMap.BaseLayer.js b/src/DGCustomization/src/DGMap.BaseLayer.js index d5c109fd..f84f3494 100644 --- a/src/DGCustomization/src/DGMap.BaseLayer.js +++ b/src/DGCustomization/src/DGMap.BaseLayer.js @@ -23,7 +23,7 @@ DG.Map.addInitHook(function() { if (!this.isErrorWasShown) { errorMessage.innerHTML = 'Your RasterJS API key is invalid. Please contact api@2gis.com to get RasterJS API key.'; - var mapContainer = this.map.getContainer() + var mapContainer = this.getContainer(); if (mapContainer) { mapContainer.appendChild(errorMessage); @@ -37,7 +37,7 @@ DG.Map.addInitHook(function() { 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(); + handleTileError.bind(this)(); } }.bind(this)); From 1e294b83c7ed1c5a3deac6bdbf66196fc045b4d2 Mon Sep 17 00:00:00 2001 From: nortren Date: Wed, 30 Apr 2025 15:47:33 +0300 Subject: [PATCH 06/14] TILES-7536 fix show message --- app/loader.js | 2 +- package-lock.json | 2 +- package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/loader.js b/app/loader.js index 167fd0a3..8600c1f3 100644 --- a/app/loader.js +++ b/app/loader.js @@ -3,7 +3,7 @@ var isJSRequested = false; var rejects = []; - var version = 'v4.0.4'; + var version = 'v4.0.3'; var baseURL = '__BASE_URL__'; var query = __QUERY__; var isLazy = query.lazy === 'true'; diff --git a/package-lock.json b/package-lock.json index 4541a937..d83699f8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "2gis-maps", - "version": "4.0.4", + "version": "4.0.3", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index c3f19d2a..2a36c93d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "2gis-maps", - "version": "4.0.4", + "version": "4.0.3", "description": "Interactive 2GIS maps API, based on Leaflet", "license": "SEE LICENSE IN FILE", "keywords": [ From 0be8ec97c36aa78275690cc986e7252f6f85a750 Mon Sep 17 00:00:00 2001 From: nortren Date: Wed, 30 Apr 2025 21:56:00 +0300 Subject: [PATCH 07/14] TILES-7536 fix after review --- .../src/DGMap.ApiKeyValidator.js | 37 +++++++++++++++++++ src/DGCustomization/src/DGMap.BaseLayer.js | 23 +----------- 2 files changed, 38 insertions(+), 22 deletions(-) diff --git a/src/DGCustomization/src/DGMap.ApiKeyValidator.js b/src/DGCustomization/src/DGMap.ApiKeyValidator.js index da35f198..0c71c689 100644 --- a/src/DGCustomization/src/DGMap.ApiKeyValidator.js +++ b/src/DGCustomization/src/DGMap.ApiKeyValidator.js @@ -8,6 +8,7 @@ DG.ApiKeyValidator = DG.Class.extend({ this.request = null; this.MAX_ATTEMPTS = 4; this.keyRequestInterval = [0, 2, 2, 2]; + this.isErrorWasShown = false; }, validate: function(callback) { @@ -20,6 +21,15 @@ DG.ApiKeyValidator = DG.Class.extend({ this._makeAttempt(callback); }, + validateKeyResponse: function(map) { + this.map = map; + 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,6 +41,33 @@ DG.ApiKeyValidator = DG.Class.extend({ } }, + _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' + ) + ); + }, + + _showError: function() { + var errorMessage = DG.DomUtil.create('div', 'dg-error-message'); + if (!this.isErrorWasShown) { + errorMessage.innerHTML = 'Your RasterJS API key is invalid. Please contact api@2gis.com to get RasterJS API key.'; + + var mapContainer = this.getContainer(); + + if (mapContainer) { + mapContainer.appendChild(errorMessage); + } + + this.isErrorWasShown = true; + } + }, + _executeRequest: function(callback) { var xhr = new XMLHttpRequest(); xhr.open('GET', this.endpoint, true); diff --git a/src/DGCustomization/src/DGMap.BaseLayer.js b/src/DGCustomization/src/DGMap.BaseLayer.js index f84f3494..f5423d2a 100644 --- a/src/DGCustomization/src/DGMap.BaseLayer.js +++ b/src/DGCustomization/src/DGMap.BaseLayer.js @@ -17,29 +17,8 @@ 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 api@2gis.com to get RasterJS API key.'; - - var mapContainer = this.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.bind(this)(); - } - }.bind(this)); + validator.validateKeyResponse(this); var tileUrl = DG.config.secureProtocol + (DG.Browser.retina ? DG.config.retinaTileServer : DG.config.tileServer); var arabicTileUrl = DG.config.secureProtocol + From a7ab057672d18c09ebdc8d80df4925ea85aed8d1 Mon Sep 17 00:00:00 2001 From: nortren Date: Wed, 30 Apr 2025 22:13:03 +0300 Subject: [PATCH 08/14] TILES-7536 fix after review --- src/DGCustomization/src/DGMap.ApiKeyValidator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DGCustomization/src/DGMap.ApiKeyValidator.js b/src/DGCustomization/src/DGMap.ApiKeyValidator.js index 0c71c689..79d6d7a3 100644 --- a/src/DGCustomization/src/DGMap.ApiKeyValidator.js +++ b/src/DGCustomization/src/DGMap.ApiKeyValidator.js @@ -58,7 +58,7 @@ DG.ApiKeyValidator = DG.Class.extend({ if (!this.isErrorWasShown) { errorMessage.innerHTML = 'Your RasterJS API key is invalid. Please contact api@2gis.com to get RasterJS API key.'; - var mapContainer = this.getContainer(); + var mapContainer = this.map.getContainer(); if (mapContainer) { mapContainer.appendChild(errorMessage); From 1cece3903e0a3e7a8f22f6ddc2e22095a5ea5167 Mon Sep 17 00:00:00 2001 From: nortren Date: Wed, 30 Apr 2025 22:14:22 +0300 Subject: [PATCH 09/14] TILES-7536 fix after review --- app/loader.js | 2 +- package-lock.json | 2 +- package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/loader.js b/app/loader.js index 8600c1f3..167fd0a3 100644 --- a/app/loader.js +++ b/app/loader.js @@ -3,7 +3,7 @@ var isJSRequested = false; var rejects = []; - var version = 'v4.0.3'; + var version = 'v4.0.4'; var baseURL = '__BASE_URL__'; var query = __QUERY__; var isLazy = query.lazy === 'true'; diff --git a/package-lock.json b/package-lock.json index d83699f8..4541a937 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "2gis-maps", - "version": "4.0.3", + "version": "4.0.4", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 2a36c93d..c3f19d2a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "2gis-maps", - "version": "4.0.3", + "version": "4.0.4", "description": "Interactive 2GIS maps API, based on Leaflet", "license": "SEE LICENSE IN FILE", "keywords": [ From d3d9c1e0aeeaa4073f3b22cfe3e96e31b375181b Mon Sep 17 00:00:00 2001 From: nortren Date: Thu, 1 May 2025 15:05:49 +0300 Subject: [PATCH 10/14] TILES-7536 fix after review --- .../src/DGMap.ApiKeyValidator.js | 38 +++++++------------ 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/src/DGCustomization/src/DGMap.ApiKeyValidator.js b/src/DGCustomization/src/DGMap.ApiKeyValidator.js index 79d6d7a3..42c61ad5 100644 --- a/src/DGCustomization/src/DGMap.ApiKeyValidator.js +++ b/src/DGCustomization/src/DGMap.ApiKeyValidator.js @@ -69,30 +69,16 @@ DG.ApiKeyValidator = DG.Class.extend({ }, _executeRequest: function(callback) { - var xhr = new XMLHttpRequest(); - xhr.open('GET', this.endpoint, true); - - 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); - - xhr.onerror = function() { - this._handleError(callback, xhr.status); - }.bind(this); - - xhr.send(); + 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) { @@ -120,6 +106,10 @@ DG.ApiKeyValidator = DG.Class.extend({ destroy: function() { this._clearLastTimeout(); + if (this.request && this.request.abort) { + this.request.abort(); + this.request = null; + } this.isLoading = false; } }); From 27aff6f36379e3ad07b5180a3066cc431894b743 Mon Sep 17 00:00:00 2001 From: nortren Date: Thu, 1 May 2025 15:08:24 +0300 Subject: [PATCH 11/14] TILES-7536 fix after review --- src/DGCustomization/src/DGMap.ApiKeyValidator.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/DGCustomization/src/DGMap.ApiKeyValidator.js b/src/DGCustomization/src/DGMap.ApiKeyValidator.js index 42c61ad5..b6119532 100644 --- a/src/DGCustomization/src/DGMap.ApiKeyValidator.js +++ b/src/DGCustomization/src/DGMap.ApiKeyValidator.js @@ -106,10 +106,6 @@ DG.ApiKeyValidator = DG.Class.extend({ destroy: function() { this._clearLastTimeout(); - if (this.request && this.request.abort) { - this.request.abort(); - this.request = null; - } this.isLoading = false; } }); From e2abbd8422ed8aadb5e8281a6c7d2df88c78408b Mon Sep 17 00:00:00 2001 From: nortren Date: Thu, 1 May 2025 23:55:03 +0300 Subject: [PATCH 12/14] TILES-7536 fix after review --- src/DGCustomization/src/DGMap.ApiKeyValidator.js | 12 +++++------- src/DGCustomization/src/DGMap.BaseLayer.js | 6 +++--- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/DGCustomization/src/DGMap.ApiKeyValidator.js b/src/DGCustomization/src/DGMap.ApiKeyValidator.js index b6119532..9984952e 100644 --- a/src/DGCustomization/src/DGMap.ApiKeyValidator.js +++ b/src/DGCustomization/src/DGMap.ApiKeyValidator.js @@ -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; @@ -9,6 +9,7 @@ DG.ApiKeyValidator = DG.Class.extend({ this.MAX_ATTEMPTS = 4; this.keyRequestInterval = [0, 2, 2, 2]; this.isErrorWasShown = false; + this.mapContainer = mapContainer; }, validate: function(callback) { @@ -21,8 +22,7 @@ DG.ApiKeyValidator = DG.Class.extend({ this._makeAttempt(callback); }, - validateKeyResponse: function(map) { - this.map = map; + validateKeyResponse: function() { this.validate(function(response) { if (!response || this._isResponseInvalid(response)) { this._showError(); @@ -58,10 +58,8 @@ DG.ApiKeyValidator = DG.Class.extend({ if (!this.isErrorWasShown) { errorMessage.innerHTML = 'Your RasterJS API key is invalid. Please contact api@2gis.com to get RasterJS API key.'; - var mapContainer = this.map.getContainer(); - - if (mapContainer) { - mapContainer.appendChild(errorMessage); + if (this.mapContainer) { + this.mapContainer.appendChild(errorMessage); } this.isErrorWasShown = true; diff --git a/src/DGCustomization/src/DGMap.BaseLayer.js b/src/DGCustomization/src/DGMap.BaseLayer.js index f5423d2a..99285ab3 100644 --- a/src/DGCustomization/src/DGMap.BaseLayer.js +++ b/src/DGCustomization/src/DGMap.BaseLayer.js @@ -16,9 +16,9 @@ DG.Map.addInitHook(function() { }); var apiKey = this.options.key || DG.config.key; - - var validator = new DG.ApiKeyValidator(apiKey); - validator.validateKeyResponse(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 + From c5258c3f683bb3d48a15e4ad06c80b53403384f9 Mon Sep 17 00:00:00 2001 From: nortren Date: Fri, 2 May 2025 00:26:24 +0300 Subject: [PATCH 13/14] TILES-7536 fix after review --- src/DGCustomization/skin/basic/less/dg-customization.less | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/DGCustomization/skin/basic/less/dg-customization.less b/src/DGCustomization/skin/basic/less/dg-customization.less index 0fc02ea0..be9f7b69 100755 --- a/src/DGCustomization/skin/basic/less/dg-customization.less +++ b/src/DGCustomization/skin/basic/less/dg-customization.less @@ -100,5 +100,7 @@ font-family: Helvetica, Arial, sans-serif; font-weight: Bold; pointer-events: none; + box-sizing: border-box; + padding: 0 20px; } From bf83eecebcbafa8aab04171589b1942aa21103cd Mon Sep 17 00:00:00 2001 From: nortren Date: Mon, 5 May 2025 13:47:09 +0300 Subject: [PATCH 14/14] TILES-7536 fix after review --- src/DGCustomization/src/DGMap.ApiKeyValidator.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/DGCustomization/src/DGMap.ApiKeyValidator.js b/src/DGCustomization/src/DGMap.ApiKeyValidator.js index 9984952e..ebe4db17 100644 --- a/src/DGCustomization/src/DGMap.ApiKeyValidator.js +++ b/src/DGCustomization/src/DGMap.ApiKeyValidator.js @@ -54,14 +54,11 @@ DG.ApiKeyValidator = DG.Class.extend({ }, _showError: function() { - var errorMessage = DG.DomUtil.create('div', 'dg-error-message'); - if (!this.isErrorWasShown) { - errorMessage.innerHTML = 'Your RasterJS API key is invalid. Please contact api@2gis.com to get RasterJS API key.'; - - if (this.mapContainer) { - this.mapContainer.appendChild(errorMessage); - } + if (!this.isErrorWasShown && this.mapContainer) { + var errorMessage = DG.DomUtil.create('div', 'dg-error-message'); + errorMessage.innerHTML = 'Your RasterJS API key is invalid. Please contact api@2gis.com to get RasterJS API key.'; + this.mapContainer.appendChild(errorMessage); this.isErrorWasShown = true; } },