Options
All
  • Public
  • Public/Protected
  • All
Menu

Namespace MapViewUtils

MapView utilities: View transformations, camera setup, view bounds computation...

Index

Variables

Const MAX_TILT_DEG

MAX_TILT_DEG: 89 = 89

Const MAX_TILT_RAD

MAX_TILT_RAD: number = MAX_TILT_DEG * THREE.MathUtils.DEG2RAD

Const calculateScreenSizeByFocalLength

calculateScreenSizeByFocalLength: convertWorldToScreenSize = CameraUtils.convertWorldToScreenSize

Const calculateWorldSizeByFocalLength

calculateWorldSizeByFocalLength: convertScreenToWorldSize = CameraUtils.convertScreenToWorldSize

Const estimateObject3dSize

estimateObject3dSize: estimateSize = Object3DUtils.estimateSize
deprecated

Const getBrowserLanguages

getBrowserLanguages: getBrowserLanguages = DOMUtils.getBrowserLanguages
deprecated

Use {@link @here/harp-utils#DOMUtils.getBrowserLanguages}

Functions

calculateDepthFromClipDistance

  • calculateDepthFromClipDistance(clipDistance: number, camera: Camera): number
  • deprecated

    Translates a linear clip-space distance value to the actual value stored in the depth buffer. This is useful as the depth values are not stored in the depth buffer linearly, and this can lead into confusing behavior when not taken into account.

    Parameters

    • clipDistance: number

      Distance from the camera in clip space (range: [0, 1]).

    • camera: Camera

      Camera applying the perspective projection.

    Returns number

calculateDistanceFromZoomLevel

  • calculateDistanceFromZoomLevel(options: { focalLength: number }, zoomLevel: number): number
  • Calculates and returns the distance to the target point.

    Parameters

    • options: { focalLength: number }

      Necessary subset of MapView properties to compute the distance.

      • focalLength: number
    • zoomLevel: number

      The zoom level to get the equivalent height to.

    Returns number

calculateDistanceToGroundFromZoomLevel

  • calculateDistanceToGroundFromZoomLevel(mapView: { camera: PerspectiveCamera; focalLength: number; projection: Projection }, zoomLevel: number): number
  • Calculates and returns the distance from the ground, which is needed to put the camera to this height, to see the size of the area that would be covered by one tile for the given zoom level.

    Parameters

    • mapView: { camera: PerspectiveCamera; focalLength: number; projection: Projection }

      Instance of MapView.

      • camera: PerspectiveCamera
      • focalLength: number
      • projection: Projection
    • zoomLevel: number

    Returns number

calculateFocalLengthByVerticalFov

  • calculateFocalLengthByVerticalFov(vFov: number, height: number): number

calculateFovByFocalLength

  • calculateFovByFocalLength(focalLength: number, height: number): number

calculateHorizontalFovByVerticalFov

  • calculateHorizontalFovByVerticalFov(vFov: number, aspect: number): number

calculateVerticalFovByHorizontalFov

  • calculateVerticalFovByHorizontalFov(hFov: number, aspect: number): number

calculateZoomLevelFromDistance

  • calculateZoomLevelFromDistance(options: { focalLength: number; maxZoomLevel: number; minZoomLevel: number }, distance: number): number
  • Calculates the zoom level, which corresponds to the current distance from camera to lookAt point. Therefore the zoom level is a float and not an int. The height of the camera can be in between zoom levels. By setting the zoom level, you change the height position of the camera in away that the field of view of the camera should be able to cover one tile for the given zoom level.

    As an example for this, when you have a tile of zoom level 14 in front of the camera and you set the zoom level of the camera to 14, then you are able to see the whole tile in front of you.

    Parameters

    • options: { focalLength: number; maxZoomLevel: number; minZoomLevel: number }

      Subset of necessary MapView properties.

      • focalLength: number
      • maxZoomLevel: number
      • minZoomLevel: number
    • distance: number

      The distance in meters, which are scene units in MapView.

    Returns number

cameraToWorldDistance

  • cameraToWorldDistance(distance: number, camera: Camera): number
  • deprecated

    Translates a linear distance value [0..1], where 1 is the distance to the far plane, into [0..cameraFar].

    Parameters

    • distance: number

      Distance from the camera (range: [0, 1]).

    • camera: Camera

      Camera applying the perspective projection.

    Returns number

closeToFrustum

  • closeToFrustum(point: Vector3, camera: Camera, eps?: number): boolean

constrainTargetAndDistanceToViewBounds

  • constrainTargetAndDistanceToViewBounds(target: Vector3, distance: number, mapView: MapView): { distance: number; target: Vector3 }
  • Constrains given camera target and distance to {@link MapView.maxBounds}.

    remarks

    The resulting target and distance will keep the view within the maximum bounds for a camera with tilt and yaw set to 0.

    Parameters

    • target: Vector3

      The camera target.

    • distance: number

      The camera distance.

    • mapView: MapView

      The map view whose maximum bounds will be used as constraints.

    Returns { distance: number; target: Vector3 }

    constrained target and distance, or the unchanged input arguments if the view does not have maximum bounds set.

    • distance: number
    • target: Vector3

extractAttitude

extractCameraTilt

  • extractCameraTilt(camera: Camera, projection: Projection): number
  • Extracts current camera tilt angle in radians.

    deprecated

    Use MapView.tilt

    Parameters

    • camera: Camera

      The [[Camera]] in use.

    • projection: Projection

      The {@link @here/harp-geoutils#Projection} used to convert between geo and world coordinates.

    Returns number

extractSphericalCoordinatesFromLocation

  • Gets the spherical coordinates in radian of the object to the coordinates of point.

    Note: this method can be used to get the direction that an object points to, when location is the target of that object, by adding PI to it. Otherwise it only returns the spherical coordinates of object in the tangent space of location.

    Parameters

    Returns { azimuth: number; tilt: number }

    • azimuth: number
    • tilt: number

extractTiltAngleFromLocation

  • Gets the tilt angle (in radians) of the object relative to the coordinates of location.

    Note: this method can be used to get the direction that an object points to, when location is the target of that object, by adding PI to it. Otherwise it only returns the tilt angle (in radians) of object in the tangent space of location.

    Parameters

    • projection: Projection

      The {@link @here/harp-geoutils#Projection} used when converting from geo to world coordinates.

    • object: Object3D

      The object to get the coordinates from.

    • location: GeoCoordinates | Vector3Like

      The reference point.

    • Optional tiltAxis: THREE.Vector3

      Optional axis used to define the rotation about which the object's tilt occurs, the direction vector to the location from the camera is projected on the plane with the given angle.

    Returns number

getCameraCoordinatesFromTargetCoordinates

getCameraFrustumPlanes

  • getCameraFrustumPlanes(camera: PerspectiveCamera): { bottom: number; far: number; left: number; near: number; right: number; top: number }
  • Get perspective camera frustum planes distances.

    deprecated

    Parameters

    • camera: PerspectiveCamera

    Returns { bottom: number; far: number; left: number; near: number; right: number; top: number }

    all plane distances in helper object.

    • bottom: number
    • far: number
    • left: number
    • near: number
    • right: number
    • top: number

getCameraPositionFromTargetCoordinates

  • getCameraPositionFromTargetCoordinates(targetCoordinates: GeoCoordinates, distance: number, yawDeg: number, pitchDeg: number, projection: Projection, result?: Vector3): Vector3
  • Returns the {@link @here/harp-geoutils#GeoCoordinates} of the camera, given its target coordinates on the map and its zoom, yaw and pitch.

    Parameters

    • targetCoordinates: GeoCoordinates

      Coordinates of the center of the view.

    • distance: number

      Distance to the target in meters.

    • yawDeg: number

      Camera yaw in degrees.

    • pitchDeg: number

      Camera pitch in degrees.

    • projection: Projection

      Active MapView, needed to get the camera fov and map projection.

    • Default value result: Vector3 = new THREE.Vector3()

      Optional output vector.

    Returns Vector3

    Camera position in world space.

getCameraRotationAtTarget

  • getCameraRotationAtTarget(projection: Projection, target: GeoCoordinates, yawDeg: number, pitchDeg: number, result?: Quaternion): Quaternion
  • Computes the rotation of the camera according to yaw and pitch in degrees. The computations hinge on the current projection and target, because yaw and pitch are defined in tangent space of the target point.

    Note: yaw == 0 && pitch == 0 will north up the map and you will look downwards onto the map.

    Parameters

    • projection: Projection

      Current projection.

    • target: GeoCoordinates

      The camera target.

    • yawDeg: number

      Yaw in degrees, counter-clockwise (as opposed to azimuth), starting north.

    • pitchDeg: number

      Pitch in degrees.

    • Default value result: Quaternion = new THREE.Quaternion()

    Returns Quaternion

getGeoTargetFromCamera

  • Calculate target (focus) point geo-coordinates for given camera.

    see

    getTargetPositionFromCamera

    deprecated

    This function is for internal use only and will be removed in the future. Use MapView.worldTarget instead.

    Parameters

    • camera: Camera

      The camera looking on target point.

    • projection: Projection

      The geo-projection used.

    • Optional elevation: undefined | number

      Optional elevation above (or below) sea level measured in world units.

    Returns GeoCoordinates | null

getTargetAndDistance

  • getTargetAndDistance(projection: Projection, camera: Camera, elevationProvider?: ElevationProvider): { distance: number; final: boolean; target: Vector3 }
  • internal

    Computes the target for a given camera and the distance between them.

    Parameters

    • projection: Projection

      The world space projection.

    • camera: Camera

      The camera whose target will be computed.

    • Optional elevationProvider: ElevationProvider

      If provided, elevation at the camera position will be used.

    Returns { distance: number; final: boolean; target: Vector3 }

    The target, the distance to it and a boolean flag set to false in case an elevation provider was passed but the elevation was not available yet.

    • distance: number
    • final: boolean
    • target: Vector3

getWorldTargetFromCamera

  • getWorldTargetFromCamera(camera: Camera, projection: Projection, elevation?: undefined | number): Vector3 | null
  • Calculate target (focus) point world coordinates for given camera position and orientation.

    deprecated

    This function is for internal use only and will be removed in the future.

    Parameters

    • camera: Camera

      The camera looking on target point.

    • projection: Projection

      The geo-projection used.

    • Optional elevation: undefined | number

      Optional elevation above (or below) sea level in world units.

    Returns Vector3 | null

mapViewIsLoading

  • mapViewIsLoading(mapView: MapView): boolean
  • Check if tiles or other content is currently being loaded.

    This method can be removed once HARP-7932 is implemented.

    Parameters

    Returns boolean

    true if MapView has visible tiles or other content that is being loaded.

orbitAroundScreenPoint

  • orbitAroundScreenPoint(mapView: MapView, offsetX: number, offsetY: number, deltaAzimuth: number, deltaTilt: number, maxTiltAngle: number): void
  • orbitAroundScreenPoint(mapView: MapView, orbitParams: OrbitParams): void
  • Orbits the camera around a given point on the screen.

    deprecated

    Use overload with OrbitParams object parameter.

    Parameters

    • mapView: MapView

      The MapView instance to manipulate.

    • offsetX: number

      Orbit point in NDC space.

    • offsetY: number

      Orbit point in NDC space.

    • deltaAzimuth: number

      Delta azimuth in radians.

    • deltaTilt: number

      Delta tilt in radians.

    • maxTiltAngle: number

      The maximum tilt between the camera and its target in radian.

    Returns void

  • Orbits the camera around a given point on the screen.

    Parameters

    Returns void

panCameraAboveFlatMap

  • panCameraAboveFlatMap(mapView: MapView, offsetX: number, offsetY: number): void

panCameraAroundGlobe

  • panCameraAroundGlobe(mapView: MapView, fromWorld: Vector3, toWorld: Vector3): void
  • The function doing a pan in the spherical space when MapView's active ProjectionType is spherical. In other words, the function that rotates the camera around the globe.

    Parameters

    • mapView: MapView

      MapView instance.

    • fromWorld: Vector3

      Start vector representing the scene position of a geolocation.

    • toWorld: Vector3

      End vector representing the scene position of a geolocation.

    Returns void

rayCastGeoCoordinates

  • rayCastGeoCoordinates(mapView: MapView, pointOnScreenXinNDC: number, pointOnScreenYinNDC: number): GeoCoordinates | null
  • Casts a ray in NDC space from the current view of the camera and returns the intersection point of that ray against the map in geo coordinates. The return value can be null when the raycast is above the horizon.

    Parameters

    • mapView: MapView

      Instance of MapView.

    • pointOnScreenXinNDC: number
    • pointOnScreenYinNDC: number

    Returns GeoCoordinates | null

    Intersection geo coordinates, or null if raycast is above the horizon.

rayCastWorldCoordinates

  • rayCastWorldCoordinates(mapView: MapView | { camera: Camera; projection: Projection }, pointOnScreenXinNDC: number, pointOnScreenYinNDC: number, elevation?: undefined | number): Vector3 | null
  • Casts a ray in NDC space from the current map view and returns the intersection point of that ray wih the map in world space.

    Parameters

    • mapView: MapView | { camera: Camera; projection: Projection }

      Instance of MapView.

    • pointOnScreenXinNDC: number

      X coordinate in NDC space.

    • pointOnScreenYinNDC: number

      Y coordinate in NDC space.

    • Optional elevation: undefined | number

      Optional param used to offset the ground plane. Used when wanting to pan based on a plane at some altitude. Necessary for example when panning with terrain.

    Returns Vector3 | null

    Intersection coordinates, or null if raycast failed.

rotate

  • rotate(mapView: { camera: PerspectiveCamera; projection: Projection }, deltaYawDeg: number, deltaPitchDeg?: number, maxTiltAngleRad?: number): void
  • Rotates the camera by the given delta yaw and delta pitch. The pitch will be clamped to the maximum possible tilt to the new target, and under the horizon in sphere projection.

    Parameters

    • mapView: { camera: PerspectiveCamera; projection: Projection }

      The MapView instance in use.

      • camera: PerspectiveCamera
      • projection: Projection
    • deltaYawDeg: number

      Delta yaw in degrees.

    • Default value deltaPitchDeg: number = 0

      Delta pitch in degrees.

    • Default value maxTiltAngleRad: number = Math.PI / 4

      Max tilt angle in radians.

    Returns void

setRotation

  • setRotation(mapView: MapView, yawDeg: number, pitchDeg: number): void
  • Sets the rotation of the camera according to yaw and pitch in degrees. The computations hinge on the current projection and geoCenter, because yaw and pitch are defined in tangent space. In particular, MapView#geoCenter needs to be set before calling setRotation.

    Note: yaw == 0 && pitch == 0 will north up the map and you will look downwards onto the map.

    Parameters

    • mapView: MapView

      Instance of MapView.

    • yawDeg: number

      Yaw in degrees, counter-clockwise (as opposed to azimuth), starting north.

    • pitchDeg: number

      Pitch in degrees.

    Returns void

zoomOnTargetPosition

  • zoomOnTargetPosition(mapView: MapView, targetNDCx: number, targetNDCy: number, zoomLevel: number, maxTiltAngle?: number): boolean
  • Zooms and moves the map in such a way that the given target position remains at the same position after the zoom.

    Parameters

    • mapView: MapView

      Instance of MapView.

    • targetNDCx: number

      Target x position in NDC space.

    • targetNDCy: number

      Target y position in NDC space.

    • zoomLevel: number

      The desired zoom level.

    • Default value maxTiltAngle: number = MAX_TILT_RAD

      The maximum tilt angle to comply by, in globe projection, in radian.

    Returns boolean

    false if requested zoom cannot be achieved due to the map view's maximum bounds MapView.geoMaxBounds,true otherwise.

Generated using TypeDoc