Class: FlatView

FlatView(params, limiter)

A view implementing an orthogonal projection for flat images.

Constructor

new FlatView(params, limiter)

Parameters:
Name Type Description
params Object

the initial view parameters.

Properties
Name Type Attributes Default Description
mediaAspectRatio number

image aspect ratio. When mediaAspectRatio === 1, the image width equals its height. When mediaAspectRatio < 1, the image width is less than its height. When mediaAspectRatio > 1, the image height is less than its width.

x number <optional>
0.5

horizontal coordinate of the image point at the viewport center, in the [0, 1] range. When x === 0.5, the image is centered horizontally. When x === 0, the left edge of the image is at the viewport center. When x === 1, the right edge of the image is at the viewport center.

y number <optional>
0.5

vertical coordinate of the image point at the viewport center, in the [0, 1] range. When y === 0.5, the image is centered vertically. When y === 0, the top edge of the image is at the viewport center. When y === 1, the bottom edge of the image is at the viewport center.

zoom number <optional>
1

the horizontal zoom, in the [0, ∞] range. When zoom === 1, the image is exactly as wide as the viewport. when zoom < 1, the image is zoomed in. when zoom > 1, the image is zoomed out.

limiter function

the view limiting function.

Implements:

Namespaces

limit

Methods

coordinatesToScreen(coords) → {Object|number|number}

Convert view coordinates into screen position. If a result argument is supplied, the object is filled in with the result and returned. Otherwise, a fresh object is returned.

Parameters:
Name Type Description
coords Object
Properties
Name Type Description
x number
y number
Returns:
  • result

    Type
    Object
  • result.x

    Type
    number
  • result.y

    Type
    number

destroy()

Destructor.

height() → {number}

Get the viewport height.

Returns:
Type
number

intersects(rectangle)

Return whether the view frustum intersects the given rectangle. This function may return false positives, but never false negatives. It is used for frustum culling, i.e., excluding invisible tiles from the rendering process.

Parameters:
Name Type Description
rectangle Array.<vec4>
Returns:

whether the rectangle intersects the view frustum.

limiter() → {function}

Get the view limiter.

Returns:
Type
function

mediaAspectRatio() → {number}

Get the media aspect ratio.

Returns:
Type
number

offsetX(xOffset)

Add xOffset to the x parameter.

Parameters:
Name Type Description
xOffset number

offsetY(yOffset)

Add yOffset to the y parameter.

Parameters:
Name Type Description
yOffset number

offsetZoom(zoomOffset)

Add zoomOffset to the zoom value.

Parameters:
Name Type Description
zoomOffset number

parameters() → {Object|number|number|number|number}

Get the view parameters. If an object argument is supplied, the object is filled in with the result and returned. Otherwise, a fresh object is returned.

Returns:
  • obj

    Type
    Object
  • obj.x

    Type
    number
  • obj.y

    Type
    number
  • obj.zoom

    Type
    number
  • obj.mediaAspectRatio

    Type
    number

projection() → {mat4}

Compute and return the projection matrix for the current view.

Returns:
Type
mat4

screenToCoordinates(screen) → {Object|number|number}

Convert screen position into view coordinates. If a result argument is supplied, the object is filled in with the result and returned. Otherwise, a fresh object is returned.

Parameters:
Name Type Description
screen Object
Properties
Name Type Description
x number
y number
Returns:
  • result

    Type
    Object
  • result.x

    Type
    number
  • result.y

    Type
    number

selectLevel(levelList) → {Level}

Select the level that should be used to render the view.

Parameters:
Name Type Description
levelList Array.<Level>

the list of levels from which to select.

Returns:

the selected level.

Type
Level

setLimiter(limiter)

Set the view limiter.

Parameters:
Name Type Description
limiter function

setMediaAspectRatio(mediaAspectRatio)

Set the media aspect ratio.

Parameters:
Name Type Description
mediaAspectRatio number

setParameters(obj)

Set the view parameters. Unspecified parameters are left unchanged.

Parameters:
Name Type Description
obj Object
Properties
Name Type Description
x number
y number
zoom number
mediaAspectRatio number

setSize(obj)

Set the viewport dimensions.

Parameters:
Name Type Description
obj Object
Properties
Name Type Description
width number
height number

setX(x)

Set the x parameter.

Parameters:
Name Type Description
x number

setY(y)

Set the y parameter.

Parameters:
Name Type Description
y number

setZoom(zoom)

Set the zoom value.

Parameters:
Name Type Description
zoom number

size() → {Object|number|number}

Get the viewport dimensions. If an object argument is supplied, the object is filled in with the result and returned. Otherwise, a fresh object is returned.

Returns:
  • obj

    Type
    Object
  • obj.width

    Type
    number
  • obj.height

    Type
    number

width() → {number}

Get the viewport width.

Returns:
Type
number

x() → {number}

Get the x parameter.

Returns:
Type
number

y() → {number}

Get the y parameter.

Returns:
Type
number

zoom() → {number}

Get the zoom value.

Returns:
Type
number