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

Commit

Permalink
HARP-6194 Adding run time change to projection (#579)
Browse files Browse the repository at this point in the history
Signed-off-by: Jonathan Stichbury <2533428+nzjony@users.noreply.github.com>
  • Loading branch information
nzjony committed Jun 26, 2019
1 parent 405081c commit 3f1a1c3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
22 changes: 21 additions & 1 deletion @here/harp-mapview/lib/MapView.ts
Expand Up @@ -1234,6 +1234,26 @@ export class MapView extends THREE.EventDispatcher {
return this.m_visibleTileSetOptions.projection;
}

/**
* Changes the projection at run time.
*
* TODO: There seems to be some issue with the sphere projection, when changing from this
* projection to a planar projection, the map is rotated. This needs to be fixed.
*/
set projection(projection: Projection) {
// The geo center must be reset when changing the projection, because the
// camera's position is based on the projected geo center.
const geoCenter = this.geoCenter;
this.m_visibleTileSetOptions.projection = projection;
this.clearTileCache();
// We reset the theme, this has the affect of ensuring all caches are cleared.
this.theme = this.theme;
this.geoCenter = geoCenter;
// Necessary for the sphereProjection, however this also resets the camera position, so it
// should be fixed.
//this.setupCamera();
}

/**
* The distance (in pixels) between the screen and the camera.
*/
Expand Down Expand Up @@ -2560,7 +2580,7 @@ export class MapView extends THREE.EventDispatcher {
sky.groundColor = getOptionValue(clearColor, "#000000");
}
if (this.m_skyBackground !== undefined) {
this.m_skyBackground.updateTexture(sky);
this.m_skyBackground.updateTexture(sky, this.projection.type);
}
}

Expand Down
10 changes: 7 additions & 3 deletions @here/harp-mapview/lib/SkyBackground.ts
Expand Up @@ -70,15 +70,18 @@ export class SkyBackground {
* Updates the sky texture with new parameters.
*
* @param params New sky configuration parameters.
* @param projectionType Which projection is used, this may also change (in which case the
* textures should be recreated).
*/
updateTexture(params: GradientSky | CubemapSky) {
const isSameSkyType = this.m_sky.type === params.type;
updateTexture(params: GradientSky | CubemapSky, projectionType: ProjectionType) {
const isSameSkyType =
this.m_sky.type === params.type && this.m_projectionType === projectionType;
switch (params.type) {
case "gradient":
if (isSameSkyType) {
(this.m_skyTexture! as SkyGradientTexture).updateTexture(params);
} else {
this.m_skyTexture = new SkyGradientTexture(params, this.m_projectionType);
this.m_skyTexture = new SkyGradientTexture(params, projectionType);
}
break;
case "cubemap": {
Expand All @@ -90,6 +93,7 @@ export class SkyBackground {
break;
}
}
this.m_projectionType = projectionType;
this.m_sky = params;
}
}

0 comments on commit 3f1a1c3

Please sign in to comment.