-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[Maps] fix vector tile load errors not displayed in legend #130395
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
12 commits
Select commit
Hold shift + click to select a range
d1d53d7
[Maps] fix vector tile load errors not displayed in legend
nreese 6379b8f
revert unneeded change
nreese 5eb5788
update API docs
nreese c512571
add error integration test
nreese 4744a39
Merge branch 'main' into issue_130199
kibanamachine 8511b5e
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine e698be0
eslint and fix jest test
nreese c936c06
Merge branch 'issue_130199' of github.com:nreese/kibana into issue_13…
nreese 3c2c30d
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine 3dc31b6
merge with main and add unit test
nreese 15aceab
Merge branch 'issue_130199' of github.com:nreese/kibana into issue_13…
nreese 21c19fb
cleanup
nreese 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
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
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
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 |
|---|---|---|
|
|
@@ -7,14 +7,21 @@ | |
|
|
||
| import type { Map as MapboxMap, MapSourceDataEvent } from '@kbn/mapbox-gl'; | ||
| import _ from 'lodash'; | ||
| import { i18n } from '@kbn/i18n'; | ||
| import { ILayer } from '../../classes/layers/layer'; | ||
| import { SPATIAL_FILTERS_LAYER_ID } from '../../../common/constants'; | ||
| import { getTileKey } from '../../classes/util/geo_tile_utils'; | ||
|
|
||
| interface MbTile { | ||
| // references internal object from mapbox | ||
| aborted?: boolean; | ||
| } | ||
|
|
||
| type TileError = Error & { | ||
| status: number; | ||
| tileZXYKey: string; // format zoom/x/y | ||
| }; | ||
|
|
||
| interface Tile { | ||
| mbKey: string; | ||
| mbSourceId: string; | ||
|
|
@@ -23,9 +30,16 @@ interface Tile { | |
|
|
||
| export class TileStatusTracker { | ||
| private _tileCache: Tile[]; | ||
| private _tileErrorCache: Record<string, TileError[]>; | ||
| private _prevCenterTileKey?: string; | ||
| private readonly _mbMap: MapboxMap; | ||
| private readonly _updateTileStatus: (layer: ILayer, areTilesLoaded: boolean) => void; | ||
| private readonly _updateTileStatus: ( | ||
| layer: ILayer, | ||
| areTilesLoaded: boolean, | ||
| errorMessage?: string | ||
| ) => void; | ||
| private readonly _getCurrentLayerList: () => ILayer[]; | ||
|
|
||
| private readonly _onSourceDataLoading = (e: MapSourceDataEvent) => { | ||
| if ( | ||
| e.sourceId && | ||
|
|
@@ -51,16 +65,29 @@ export class TileStatusTracker { | |
| } | ||
| }; | ||
|
|
||
| private readonly _onError = (e: MapSourceDataEvent) => { | ||
| private readonly _onError = (e: MapSourceDataEvent & { error: Error & { status: number } }) => { | ||
| if ( | ||
| e.sourceId && | ||
| e.sourceId !== SPATIAL_FILTERS_LAYER_ID && | ||
| e.tile && | ||
| (e.source.type === 'vector' || e.source.type === 'raster') | ||
| ) { | ||
| const targetLayer = this._getCurrentLayerList().find((layer) => { | ||
| return layer.ownsMbSourceId(e.sourceId); | ||
| }); | ||
| const layerId = targetLayer ? targetLayer.getId() : undefined; | ||
| if (layerId) { | ||
| const layerErrors = this._tileErrorCache[layerId] ? this._tileErrorCache[layerId] : []; | ||
| layerErrors.push({ | ||
| ...e.error, | ||
| tileZXYKey: `${e.tile.tileID.canonical.z}/${e.tile.tileID.canonical.x}/${e.tile.tileID.canonical.y}`, | ||
| } as TileError); | ||
| this._tileErrorCache[layerId] = layerErrors; | ||
| } | ||
| this._removeTileFromCache(e.sourceId, e.tile.tileID.key as unknown as string); | ||
| } | ||
| }; | ||
|
|
||
| private readonly _onSourceData = (e: MapSourceDataEvent) => { | ||
| if ( | ||
| e.sourceId && | ||
|
|
@@ -73,23 +100,43 @@ export class TileStatusTracker { | |
| } | ||
| }; | ||
|
|
||
| /* | ||
| * Clear errors when center tile changes. | ||
| * Tracking center tile provides the cleanest way to know when a new data fetching cycle is beginning | ||
| */ | ||
|
Comment on lines
+104
to
+106
Contributor
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. This is clever! |
||
| private readonly _onMove = () => { | ||
| const center = this._mbMap.getCenter(); | ||
| // Maplibre rounds zoom when 'source.roundZoom' is true and floors zoom when 'source.roundZoom' is false | ||
| // 'source.roundZoom' is true for raster and video layers | ||
| // 'source.roundZoom' is false for vector layers | ||
| // Always floor zoom to keep logic as simple as possible and not have to track center tile by source. | ||
| // We are mainly concerned with showing errors from Elasticsearch vector tile requests (which are vector sources) | ||
| const centerTileKey = getTileKey(center.lat, center.lng, Math.floor(this._mbMap.getZoom())); | ||
| if (this._prevCenterTileKey !== centerTileKey) { | ||
| this._prevCenterTileKey = centerTileKey; | ||
| this._tileErrorCache = {}; | ||
| } | ||
| }; | ||
|
|
||
| constructor({ | ||
| mbMap, | ||
| updateTileStatus, | ||
| getCurrentLayerList, | ||
| }: { | ||
| mbMap: MapboxMap; | ||
| updateTileStatus: (layer: ILayer, areTilesLoaded: boolean) => void; | ||
| updateTileStatus: (layer: ILayer, areTilesLoaded: boolean, errorMessage?: string) => void; | ||
| getCurrentLayerList: () => ILayer[]; | ||
| }) { | ||
| this._tileCache = []; | ||
| this._tileErrorCache = {}; | ||
| this._updateTileStatus = updateTileStatus; | ||
| this._getCurrentLayerList = getCurrentLayerList; | ||
|
|
||
| this._mbMap = mbMap; | ||
| this._mbMap.on('sourcedataloading', this._onSourceDataLoading); | ||
| this._mbMap.on('error', this._onError); | ||
| this._mbMap.on('sourcedata', this._onSourceData); | ||
| this._mbMap.on('move', this._onMove); | ||
| } | ||
|
|
||
| _updateTileStatusForAllLayers = _.debounce(() => { | ||
|
|
@@ -107,7 +154,31 @@ export class TileStatusTracker { | |
| break; | ||
| } | ||
| } | ||
| this._updateTileStatus(layer, !atLeastOnePendingTile); | ||
| const tileErrorMessages = this._tileErrorCache[layer.getId()] | ||
| ? this._tileErrorCache[layer.getId()].map((tileError) => { | ||
| return i18n.translate('xpack.maps.tileStatusTracker.tileErrorMsg', { | ||
| defaultMessage: `tile '{tileZXYKey}' failed to load: '{status} {message}'`, | ||
| values: { | ||
| tileZXYKey: tileError.tileZXYKey, | ||
| status: tileError.status, | ||
| message: tileError.message, | ||
| }, | ||
| }); | ||
| }) | ||
| : []; | ||
| this._updateTileStatus( | ||
| layer, | ||
| !atLeastOnePendingTile, | ||
| tileErrorMessages.length | ||
| ? i18n.translate('xpack.maps.tileStatusTracker.layerErrorMsg', { | ||
| defaultMessage: `Unable to load {count} tiles: {tileErrors}`, | ||
| values: { | ||
| count: tileErrorMessages.length, | ||
| tileErrors: tileErrorMessages.join(', '), | ||
| }, | ||
| }) | ||
| : undefined | ||
| ); | ||
| } | ||
| }, 100); | ||
|
|
||
|
|
@@ -126,6 +197,7 @@ export class TileStatusTracker { | |
| this._mbMap.off('error', this._onError); | ||
| this._mbMap.off('sourcedata', this._onSourceData); | ||
| this._mbMap.off('sourcedataloading', this._onSourceDataLoading); | ||
| this._mbMap.off('move', this._onMove); | ||
| this._tileCache.length = 0; | ||
| } | ||
| } | ||
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
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.
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.
Looks ok to me, although as a nit, it would probably be good to add a note that explains the implications of using a Buffer or Stream as a
customErrorThere 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 more details about what to add?