Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

Commit

Permalink
MAPSJS-2983 Write to the console if we need too many attempts getting…
Browse files Browse the repository at this point in the history
… the image from the cache

Some failed attempts is ok, because there are cases where the DataSource is attached and ready
and the map has started to render, but the theme isn't fully set.

There are other ways to fix the problem, but they are generally more invasive and could introduce
regressions, some options are:
- In the TileGeometryCreator::createAllGeometries method, await on the getTheme() Promise
- Don't allow new TextElements to be added while the theme is updating
- Investigate and remove all calls to update the mapview while the method `addDataSource` is called
  and see if this can be removed, because no update calls means we don't render and request new tiles
  which may contain references to POI's that don't yet exist on the cache.

But, for the sake of simplicity, this is the preferred method.

Change-Id: I6243e5fa5cd07ad33343396e2678b4a17d1c6705
Signed-off-by: Jonathan Stichbury <[email protected]>
  • Loading branch information
nzjony committed Aug 19, 2021
1 parent 79554fa commit 70907f7
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions @here/harp-mapview/lib/poi/PoiRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,7 @@ export class PoiBatchRegistry {
const { imageItem, imageTexture } = poiInfo;

if (!imageItem) {
// No image -> invisible -> ignore
poiInfo.isValid = false;
// No image found, therefore just return undefined. It will probably come in soon?
return undefined;
}

Expand Down Expand Up @@ -373,8 +372,10 @@ export class PoiBatchRegistry {
}
}

// keep track of the missing textures, but only warn once
const missingTextureName: Map<string, boolean> = new Map();
// keep track of the missing textures, we throw an error if the number of attempts goes over some
// threshold.
const missingTextureName: Map<string, number> = new Map();
const SEARCH_CACHE_ATTEMPTS = 2;

function findImageItem(
poiInfo: PoiInfo,
Expand All @@ -395,12 +396,14 @@ function findImageItem(
}

if (!imageItem) {
logger.error(`init: No imageItem found with name
'${imageTexture?.image ?? imageTextureName}'`);
poiInfo.isValid = false;
if (missingTextureName.get(imageTextureName) === undefined) {
missingTextureName.set(imageTextureName, true);
logger.error(`preparePoi: No imageTexture with name '${imageTextureName}' found`);
// There is a texture messing in the cache. We just warn, because it is possible that the
// theme is still loading and that the next request to
const missingTextureCount = missingTextureName.get(imageTextureName);
missingTextureName.set(imageTextureName, missingTextureCount ? missingTextureCount + 1 : 0);
if (missingTextureName.get(imageTextureName)! >= SEARCH_CACHE_ATTEMPTS) {
logger.error(`init: No imageItem found with name:
'${imageTexture?.image ?? imageTextureName}'
after ${SEARCH_CACHE_ATTEMPTS} attempts.`);
}
}
return imageItem;
Expand Down

0 comments on commit 70907f7

Please sign in to comment.