Class MapView

The core class of the library to call in order to create a map visualization. It needs to be linked to datasources.

Hierarchy

Constructors

Properties

Accessors

Methods

Constructors

Properties

mapRenderingManager: IMapRenderingManager

The instance of MapRenderingManager managing the rendering of the map. It is a public property to allow access and modification of some parameters of the rendering process at runtime.

Accessors

  • get camera(): PerspectiveCamera
  • The THREE.js camera used by this MapView to render the main scene.

    Returns PerspectiveCamera

    Remarks

    When modifying the camera all derived properties like:

    • target
    • zoomLevel
    • tilt
    • heading could change. These properties are cached internally and will only be updated in the next animation frame. FIXME: Unfortunately THREE.js is not dispatching any events when camera properties change so we should have an API for enforcing update of cached values.
  • get delayLabelsUntilMovementFinished(): boolean
  • Returns boolean

    Whether adding of new labels during interaction is enabled.

  • set delayLabelsUntilMovementFinished(value): void
  • Enables or disables adding of new labels during interaction. Has no influence on already placed labels

    Parameters

    • value: boolean

      true to enable adding false to disable them.

    Returns void

  • get dynamicPixelRatio(): undefined | number
  • Returns undefined | number

  • set dynamicPixelRatio(ratio): void
  • PixelRatio ratio for rendering when the camera is moving or an animation is running.

    Parameters

    • ratio: undefined | number

    Returns void

    Remarks

    Useful when rendering on high resolution displays with low performance GPUs that may be fill-rate-limited.

    If a value is specified, a low resolution render pass is used to render the scene into a low resolution render target, before it is copied to the screen.

    A value of undefined disables the low res render pass. Values between 0.5 and window.devicePixelRatio can be tried to give good results. The value should not be larger than window.devicePixelRatio.

    Note

    Since no anti-aliasing is applied during dynamic rendering with dynamicPixelRatio defined, visual artifacts may occur, especially with thin lines..

    Note

    The resolution of icons and text labels is not affected.

    Default

    undefined

  • get forceCameraAspect(): undefined | number
  • Gets the value of the forced custom camera aspect. Every time a frame is rendered, MapView resets the camera aspect.

    You can disable this behavior by setting the value to undefined.

    Returns undefined | number

  • set forceCameraAspect(aspect): void
  • Sets the custom forced camera aspect ratio to use while rendering.

    Parameters

    • aspect: undefined | number

    Returns void

  • get geoCenter(): GeoCoordinates
  • Internal

    The position in geo coordinates of the center of the scene.

    Returns GeoCoordinates

  • set geoCenter(geoCenter): void
  • The position in geo coordinates of the center of the scene.

    Parameters

    • geoCenter: GeoCoordinates

    Returns void

    Remarks

    Longitude values outside of -180 and +180 are acceptable.

  • get geoMaxBounds(): undefined | GeoBox
  • The view's maximum bounds in geo coordinates if any.

    Returns undefined | GeoBox

  • set geoMaxBounds(bounds): void
  • Sets or clears the view's maximum bounds in geo coordinates.

    Parameters

    • bounds: undefined | GeoBox

    Returns void

    Remarks

    If set, the view will be constrained to the given geo bounds.

  • get imageCache(): MapViewImageCache
  • Internal

    Get the ImageCache that belongs to this MapView.

    Images stored in this cache are primarily used for POIs (icons) and they are used with the current theme. Although images can be explicitly added and removed from the cache, it is advised not to remove images from this cache. If an image that is part of client code should be removed at any point other than changing the theme, the useImageCache should be used instead.

    Returns MapViewImageCache

  • get isDynamicFrame(): boolean
  • Returns true if the current frame will immediately be followed by another frame.

    Returns boolean

    Deprecated

    This should only be used for the internal handling of the render loop, if you use your own RenderLoop use ::renderSync in combination with FrameComplete

  • get lights(): Light[]
  • Returns Light[]

    The lights configured by the theme, this is just a convenience method, because the lights can still be accessed by traversing the children of the [[scene]].

  • get mapAnchors(): MapAnchors
  • The node in this MapView's scene containing the user MapAnchors.

    Returns MapAnchors

    Remarks

    All (first level) children of this node will be positioned in world space according to the [[MapAnchor.geoPosition]]. Deeper level children can be used to position custom objects relative to the anchor node.

  • get maxFps(): number
  • Returns number

  • set maxFps(value): void
  • Maximum FPS (Frames Per Second).

    Parameters

    • value: number

    Returns void

    Remarks

    If VSync in enabled, the specified number may not be reached, but instead the next smaller number than maxFps that is equal to the refresh rate divided by an integer number.

    E.g.: If the monitors refresh rate is set to 60hz, and if maxFps is set to a value of 40 (60hz/1.5), the actual used FPS may be 30 (60hz/2). For displays that have a refresh rate of 60hz, good values for maxFps are 30, 20, 15, 12, 10, 6, 3 and 1. A value of 0 is ignored.

  • get nativeWebglAntialiasEnabled(): boolean
  • Returns true if the native WebGL antialiasing is enabled.

    Returns boolean

    Default

    true for pixelRatio < 2.0, false otherwise.

  • get pixelRatio(): number
  • Returns number

  • set pixelRatio(pixelRatio): void
  • PixelRatio in the WebGlRenderer. May contain values > 1.0 for high resolution screens (HiDPI).

    Parameters

    • pixelRatio: number

    Returns void

    Remarks

    A value of undefined will make the getter return window.devicePixelRatio, setting a value of 1.0 will disable the use of HiDPI on all devices.

    Note

    Since the current pixelRatio may have been used in some calculations (e.g. the icons) they may appear in the wrong size now. To ensure proper display of data, a call to clearTileCache() is required if the pixelRatio is changed after tiles have been loaded.

    Memberof

    MapView

  • get pixelToWorld(): number
  • Returns the ratio between a pixel and a world unit for the current camera (in the center of the camera projection).

    Returns number

  • get politicalView(): undefined | string
  • Get currently presented political point of view - the country code.

    Returns undefined | string

    Country code or undefined if default (majorly accepted) point of view is used.

    Note

    Country code is stored in lower-case ISO 3166-1 alpha-2 standard.

  • set politicalView(pov): void
  • Set the political view (country code) to be used when rendering disputed features (borders).

    Parameters

    • pov: undefined | string

      The code of the country which point of view should be presented, if undefined or empty string is set then "defacto" or most widely accepted point of view will be presented.

    Returns void

    Note

    Country code should be encoded in lower-case ISO 3166-1 alpha-2 standard.

  • get target(): GeoCoordinates
  • Get geo coordinates of camera focus (target) point.

    Returns GeoCoordinates

    geo coordinates of the camera focus point.

    Remarks

    This point is not necessarily on the ground, i.e.:

    • if the tilt is high and projection is @xyzmaps/harp-geoutils#sphereProjection`
    • if the camera was modified directly and is not pointing to the ground. In any case the projection of the target point will be in the center of the screen.
  • get targetDistance(): number
  • Internal

    Get distance from camera to the point of focus in world units.

    Returns number

    Last known focus point distance.

    Note

    If camera does not point to any ground anymore the last focus point distance is then returned.

  • get tileGeometryManager(): undefined | TileGeometryManager
  • The [[TileGeometryManager]] manages geometry during loading and handles hiding geometry of specified [[GeometryKind]]s.

    Returns undefined | TileGeometryManager

    Deprecated

  • get updatePending(): boolean
  • Returns true if an update has already been requested, such that after a currently rendering frame, the next frame will be rendered immediately.

    Returns boolean

  • get viewRanges(): ViewRanges
  • Internal

    Get object describing frustum planes distances and min/max visibility range for actual camera setup.

    Returns ViewRanges

    Remarks

    Near and far plane distance are self explanatory while minimum and maximum visibility range describes the extreme near/far planes distances that may be achieved with current camera settings, meaning at current zoom level (ground distance) and any possible orientation.

    Note

    Visibility is directly related to camera [[ClipPlaneEvaluator]] used and determines the maximum possible distance of camera far clipping plane regardless of tilt, but may change whenever zoom level changes. Distance is measured in world units which may be approximately equal to meters, but this depends on the distortion related to projection type used.

  • get worldTarget(): Vector3
  • Internal

    Get world coordinates of camera focus point.

    Returns Vector3

    world coordinates of the camera focus point.

    Remarks

    Note

    The focus point coordinates are updated with each camera update so you don't need to re-calculate it, although if the camera started looking to the void, the last focus point is stored.

  • get worldToPixel(): number
  • Returns the ratio between a world and a pixel unit for the current camera (in the center of the camera projection).

    Returns number

Methods

  • Adds an event listener. There are various events that are sent before or after a new frame is rendered.

    Parameters

    • type: MapViewEventNames

      One of the [[MapViewEventNames]] strings.

    • listener: ((event) => void)

      The callback invoked when the MapView needs to render a new frame.

        • (event): void
        • Parameters

          Returns void

    Returns void

    See

    [[MapViewEventNames]].

    Example

    let frameCount = 0;
    mapView.addEventListener(MapViewEventNames.Render, () => {
    ++frameCount;
    });
  • Clear the tile cache.

    Parameters

    • Optional dataSourceName: string

      The name of the DataSource.

    • Optional filter: ((tile) => boolean)

      Optional tile filter

        • (tile): boolean
        • Parameters

          Returns boolean

    Returns void

    Remarks

    Remove the Tile objects created by cacheable DataSources. If a DataSource name is provided, this method restricts the eviction the DataSource with the given name.

  • Disposes this MapView.

    Parameters

    • freeContext: boolean = true

      true to force ThreeJS to loose the context. Supply false to keep the context for further use.

    Returns void

    Remarks

    This function cleans the resources that are managed manually including those that exist in shared caches.

    Note: This function does not try to clean objects that can be disposed off easily by TypeScript's garbage collecting mechanism. Consequently, if you need to perform a full cleanup, you must ensure that all references to this MapView are removed.

  • Apply a visitor function to all tiles in the cache.

    Parameters

    • visitor: ((tile) => void)

      Visitor function

        • (tile): void
        • Parameters

          Returns void

    Returns void

  • Apply visitor to all visible tiles.

    Parameters

    • fun: ((tile) => void)

      Visitor function

        • (tile): void
        • Parameters

          Returns void

    Returns void

  • Same as getGeoCoordinatesAt but always returning a geo coordinate.

    Parameters

    • x: number
    • y: number
    • fallback: true

    Returns GeoCoordinates

  • Returns the @xyzmaps/harp-geoutils#GeoCoordinates from the given screen position.

    Parameters

    • x: number

      The X position in css/client coordinates (without applied display ratio).

    • y: number

      The Y position in css/client coordinates (without applied display ratio).

    • Optional fallback: boolean

      Whether to compute a fallback position if the earth surface is not hit.

    Returns null | GeoCoordinates

    Un-normalized geo coordinates

    Remarks

    If fallback !== true the return value can be null, in case the camera has a high tilt and the given (x, y) value is not intersecting the ground plane. If fallback === true the return value will always exist but it might not be on the earth surface. If tileWrappingEnabled is true the returned geo coordinates will have a longitude clamped to [-180,180] degrees. The returned geo coordinates are not normalized so that a map object placed at that position will be below the (x,y) screen coordinates, regardless which world repetition was on screen.

  • Returns the normalized screen coordinates from the given pixel position.

    Parameters

    • x: number

      The X position in css/client coordinates (without applied display ratio).

    • y: number

      The Y position in css/client coordinates (without applied display ratio).

    Returns Vector3

  • Returns the world space position from the given screen position.

    Parameters

    • x: number

      The X position in css/client coordinates (without applied display ratio).

    • y: number

      The Y position in css/client coordinates (without applied display ratio).

    • fallback: true

      Whether to compute a fallback position if the earth surface is not hit.

    Returns Vector3

    Remarks

    If fallback !== true the return value can be null, in case the camera has a high tilt and the given (x, y) value is not intersecting the ground plane. If fallback === true the return value will always exist but it might not be on the earth surface.

  • Returns the world space position from the given screen position.

    Parameters

    • x: number

      The X position in css/client coordinates (without applied display ratio).

    • y: number

      The Y position in css/client coordinates (without applied display ratio).

    • Optional fallback: boolean

      Whether to compute a fallback position if the earth surface is not hit.

    Returns null | Vector3

    Remarks

    If fallback !== true the return value can be null, in case the camera has a high tilt and the given (x, y) value is not intersecting the ground plane. If fallback === true the return value will always exist but it might not be on the earth surface.

  • Checks if listener is added to an event type.

    Parameters

    • type: string

      The type of event to listen to.

    • Optional listener: ((event) => void)

      The function that gets called when the event is fired.

        • (event): void
        • Parameters

          • event: Event

          Returns void

    Returns boolean

  • Do a raycast on all objects in the scene. Useful for picking.

    Parameters

    • x: number

      The X position in css/client coordinates (without applied display ratio).

    • y: number

      The Y position in css/client coordinates (without applied display ratio).

    • Optional parameters: IntersectParams

      The intersection test behaviour may be adjusted by providing an instance of IntersectParams.

    Returns PickResult[]

    The list of intersection results.

    Remarks

    Limited to objects that THREE.js can raycast, the solid lines that get their geometry in the shader cannot be tested for intersection.

    Note, if a DataSource adds an [[Object3D]] to a Tile, it will be only pickable once MapView.render has been called, this is because MapView.render method creates the internal three.js root [[Object3D]] which is used in the [[PickHandler]] internally. This method will not test for intersection custom objects added to the scene by for example calling directly the [[scene.add]] method from THREE.

  • Loads a post effects definition file.

    Parameters

    • postEffectsFile: string

      File URL describing the post effects.

    Returns void

  • Adjusts the camera to look at a given geo coordinate with tilt and heading angles.

    Parameters

    Returns void

    Remarks

    Note on target and bounds

    If bounds are specified, zoomLevel and distance parameters are ignored and lookAt calculates best zoomLevel (and possibly target) to fit given bounds.

    Following table shows how relation between bounds and target.

    bounds target actual target
    @xyzmaps/harp-geoutils#GeoBox defined params.target is used
    @xyzmaps/harp-geoutils#GeoBox undefined bounds.center is used as new target
    @xyzmaps/harp-geoutils#GeoBoxExtentLike undefined current MapView.target is used
    @xyzmaps/harp-geoutils#GeoBoxExtentLike defined params.target is used
    [[GeoCoordLike]][] undefined new target is calculated as center of world box covering given points
    [[GeoCoordLike]][] defined params.target is used and zoomLevel is adjusted to view all given geo points

    In each case, lookAt finds minimum zoomLevel that covers given extents or geo points.

    With flat projection, if bounds represents points on both sides of anti-meridian, and tileWrappingEnabled is used, lookAt will use this knowledge and find minimal view that may cover "next" or "previous" world.

    With sphere projection if bounds represents points on both sides of globe, best effort method is used to find best `target``.

    Examples

    mapView.lookAt({heading: 90})
    // look east retaining current `target`, `zoomLevel` and `tilt`

    mapView.lookAt({lat: 40.707, lng: -74.01})
    // look at Manhattan, New York retaining other view params

    mapView.lookAt(bounds: { latitudeSpan: 10, longitudeSpan: 10})
    // look at current `target`, but extending zoomLevel so we see 10 degrees of lat/long span

    @see More examples in [[LookAtExample]].

    @param params - {@link LookAtParams}

    {@labels WITH_PARAMS}

  • The method that sets the camera to the desired angle (tiltDeg) and distance (in meters) to the target location, from a certain heading (headingAngle).

    Parameters

    • target: GeoCoordLike

      The location to look at.

    • distance: number

      The distance of the camera to the target in meters.

    • Optional tiltDeg: number

      The camera tilt angle in degrees (0 is vertical), curbed below 89deg

    • Optional headingDeg: number

      The camera heading angle in degrees and clockwise (as opposed to yaw)

    Returns void

    Remarks

    Default

    0
    

    Default

    0
    starting north.

    Deprecated

    Use lookAt version with LookAtParams object parameter.

  • Visit each tile in visible, rendered, and cached sets.

    Parameters

    • Optional dataSource: DataSource

      If passed, only the tiles from this DataSource instance are processed. If undefined, tiles from all DataSources are processed.

    • Optional filter: ((tile) => boolean)

      Optional tile filter

        • (tile): boolean
        • Parameters

          Returns boolean

    Returns void

    Remarks

    • Visible and temporarily rendered tiles will be marked for update and retained.
    • Cached but not rendered/visible will be evicted.
  • Transfer the NDC point to view space.

    Parameters

    • vector: Vector3Like

      Vector to transform.

    • result: Vector3

      Result to place calculation.

    Returns Vector3

  • Removes the given dynamic property from this MapView.

    Parameters

    • name: string

      The name of the property to remove.

    Returns void

    Remarks

    Property names starting with a $-sign are reserved and any attempt to change their value will result in an error.

  • Removes an event listener. There are various events that are sent before or after a new frame is rendered.

    Parameters

    • type: MapViewEventNames

      One of the [[MapViewEventNames]] strings.

    • Optional listener: ((event) => void)

      The callback invoked when the MapView needs to render a new frame.

        • (event): void
        • Parameters

          Returns void

    Returns void

    See

    [[MapViewEventNames]].

    Example

    mapView.removeEventListener(MapViewEventNames.Render, listener);
    
  • Redraws scene immediately

    Parameters

    • Optional frameStartTime: number

      Optional timestamp for start of frame. Default: [[PerformanceTimer.now()]]

    Returns void

    Remarks

    Note

    Before using this method, set synchronousRendering to true in the MapViewOptions

  • Internal

    Parameters

    • Optional fontCatalogs: FontCatalogConfig[]
    • Optional textStyles: TextStyleDefinition[]
    • Optional defaultTextStyle: TextStyleDefinition

    Returns Promise<void>

  • Resize the HTML canvas element and the THREE.js WebGLRenderer.

    Parameters

    • width: number

      The new width.

    • height: number

      The new height.

    Returns void

  • Sets the cache size in number of tiles.

    Parameters

    • size: number

      The cache size in tiles.

    • Optional numVisibleTiles: number

      The number of tiles visible, which is size/2 by default.

    Returns void

  • Moves the camera to the specified @xyzmaps/harp-geoutils#GeoCoordinates, sets the desired zoomLevel and adjusts the yaw and pitch.

    Parameters

    • geoPos: GeoCoordinates

      Geolocation to move the camera to.

    • zoomLevel: number

      Desired zoom level.

    • yawDeg: number = 0

      Camera yaw in degrees, counter-clockwise (as opposed to heading), starting north.

    • pitchDeg: number = 0

      Camera pitch in degrees.

    Returns void

    Remarks

    The pitch of the camera is always curbed so that the camera cannot look above the horizon. This paradigm is necessary in @xyzmaps/harp-map-controls#MapControls, where the center of the screen is used for the orbiting interaction (3 fingers / right mouse button).

    Deprecated

    Use (MapView.lookAt:WITH_PARAMS) instead.

  • Updates the value of a dynamic property.

    Parameters

    • name: string

      The name of the property.

    • value: Value

      The value of the property.

    Returns void

    Remarks

    Property names starting with a $-sign are reserved and any attempt to change their value will result in an error.

    Themes can access dynamic properties using the Expr operator ["dynamic-properties"], for example:

    ["get", "property name", ["dynamic-properties"]]

  • Sets the DataSource which contains the elevations, the elevation range source, and the elevation provider.

    Parameters

    • elevationSource: DataSource

      The datasource containing the terrain tiles.

    • elevationRangeSource: ElevationRangeSource

      Allows access to the elevation min / max per tile.

    • elevationProvider: ElevationProvider

      Allows access to the elevation at a given location or a ray from the camera.

    Returns Promise<void>

    Remarks

    Only a single elevation source is possible per MapView. If the terrain-datasource is merged with this repository, we could internally construct the ElevationRangeSource and the ElevationProvider and access would be granted to the application when it asks for it, to simplify the API.

  • Set's the way in which the fov is calculated on the map view.

    Parameters

    Returns void

    Remarks

    Note, for this to take visual effect, the map should be rendered after calling this function.

Generated using TypeDoc