Class: ViewModel

H.map.ViewModel

new H.map.ViewModel ()

This class represents a view of the map. It consists of a look-at point which has a position in geo-space and orientation angles (heading, tilt and incline). The view model allows to change the values of this object in order to move or rotate the map or zoom in and out.

Modifying the view of a map is asynchronous as the view model notifies the renderer of a change in its state and triggers the renderer.

A map renderer can choose to ignore or even correct certain values depending on its capabilities. For example a 2D map renderer will ignore tilt values and correct tilt values to be 0 on the view model in order to keep the integrity of the view model.

In order to be notified of changes to the model that originate from the renderer, the view model dispatches a "sync" event whenever the renderer synchronizes the requested changes to the view with its own internal state.

Extends

Implements

Methods

addEventListener (type, handler, opt_capture, opt_scope) inherited

This method adds a listener for a specific event.

Note that to prevent potential memory leaks, you must either call removeEventListener or dispose on the given object when you no longer need it.

Name Type Description
type string

The name of the event

handler function

An event handler function

opt_capture boolean optional

true indicates that the method should listen in the capture phase (bubble otherwise)

opt_scope Object optional

An object defining the scope for the handler function

addOnDisposeCallback (callback, opt_scope) inherited

This method adds a callback which is triggered when the EventTarget object is being disposed.

Name Type Description
callback function

The callback function.

opt_scope Object optional

An optional scope for the callback function

control (moveX, moveY, moveZ, rotateX, rotateY, rotateZ)

To control a look-at-point animation in screen space. Before the look-at-point can be controlled the method H.map.ViewModel#startControl must be invoked once. The animation can be finished via H.map.ViewModel#endControl

Name Type Description
moveX number

The movement along the x-axis in pixels per second

moveY number

The movement along the y-axis in pixels per second

moveZ number

The movement along the z-axis in zoom-levels per second

rotateX number

The rotation around the x-axis in degrees per second

rotateY number

The rotation around the y-axis in degrees per second

rotateZ number

The rotation around the z-axis in degrees per second

dispatchEvent (evt) inherited

This method dispatches an event on the EventTarget object.

Name Type Description
evt H.util.Event | string

An object representing the event or a string with the event name

dispose () inherited

This method removes listeners from the given object. Classes that extend EventTarget may need to override this method in order to remove references to DOM Elements and additional listeners.

endControl (opt_preventKinetics, opt_adjustView)

To finish the control of a look-at-point animation. See also H.map.ViewModel#startControl and H.map.ViewModel#control

Name Type Description
opt_preventKinetics boolean optional

Indicates whether a kinetic effect at the end of the controlled animation is prevented.

opt_adjustView function(H.map.ViewModel.ILookAtData) optional

A custom function to adjust the final view. It receives the last requested look-at data from the view model and has to return a possibly modified H.map.ViewModel.ILookAtData which is used instead.

Example
//prevent kinetics
viewModel.endControl(true);

//prevent kinetics and set adjusted view
viewModel.endControl(true, function(requested) {
  requested.zoom = Math.round(requested.zoom);
});

getLookAtData ()H.map.ViewModel.ILookAtData

This method retrieves the current rendered look-at data. It returns H.geo.Rect as bounds in case of P2D engine, otherwise bounds is of type H.geo.Polygon.

Returns:
Type Description
H.map.ViewModel.ILookAtData The current rendered look-at data

removeEventListener (type, handler, opt_capture, opt_scope) inherited

This method removes a previously added listener from the EventTarget instance.

Name Type Description
type string

The name of the event

handler function

A previously added event handler

opt_capture boolean optional

true indicates that the method should listen in the capture phase (bubble otherwise)

opt_scope Object optional

An object defining the scope for the handler function

setLookAtData (data, opt_animate, opt_integerZoom)H.map.ViewModel

To set new look-at data for the view model. This method supports any type of geometry. In case of P2D engine type, the bounding box of the geometry is used. In case of other engine types: if the bounds type is H.geo.Polygon, then the exterior of the polygon defines visible area, otherwise the bounding box of the given bounds geometry.

Name Type Description
data H.map.ViewModel.ILookAtData

The values to be modified. Here are some of the main possibilities to reposition the camera at a given look-at point:

  • position - use existing (default) zoom and change map center
  • zoom - use existing (default) map center and change zoom
  • position & zoom - use specified position as map center and zoom
  • bounds - set center of the bounds as a new map center and calculate zoom such that bounds are visible
  • bounds & position - set specified position as map center and calculate zoom such that bounds are visible
  • bounds & zoom - set center of the bounds as a new map center and set specified zoom
  • bounds & position & zoom - ignore bounds and use specified position and zoom
  • tilt, heading, incline - set look-at angles
opt_animate boolean | number optional

A boolean indicating if an animated transition should be applied. Alternatively, a positive number representing a speed factor that's multiplied to the default animation speed computed by the rendering engine. Valid for vector engines only. Examples:

  • 1.1 means 10% faster than the default animation speed.
  • 0.5 means 50% slower.

Default is false.

opt_integerZoom boolean optional

Indicates if the resulting zoom level should be rounded down. It is only applied in case that the LookAtData's zoom level is not specified but bounds are. This can be used to prevent blurry raster tile maps when set the "look at" to specified bounds.

Default is false.

Fires:
  • H.map.ViewModel#event:update
Returns:
Type Description
H.map.ViewModel this view model object

startControl (opt_kinetics, opt_atX, opt_atY)

To start the controlling of the look-at-point animation. After this method was invoked, the look-at-point animation can be controlled by several calls of H.map.ViewModel#control and finished by a call of H.map.ViewModel#endControl

Name Type Description
opt_kinetics H.util.kinetics.IKinetics optional

Kinetics settings

opt_atX number optional

The x screen coordinate at which control starts

opt_atY number optional

The y screen coordinate at which control starts

Type Definitions

H.map.ViewModel.ILookAtData Object

An Interface to describe a look-at data set.

Properties:
Name Type Argument Description
position H.geo.IPoint <optional>

This property represents the look-at position in geographical space.

zoom number <optional>

This property represents the zoom level. The maximum and minimum zoom levels of the current base layer are defined during its creation and might differ depending on the map layer and its specific configuration.

bounds H.geo.AbstractGeometry <optional>

This property represents the visible area.

heading number <optional>

This property represents the rotation angle relative to North. A positive angle increases southward. The range is from 0 to 360 but it can be restricted by the render engine capabilities. 0 - looks from the North; 90 - looks from the East; 180 - looks from the South; 270 - looks from the West.

incline number <optional>

This property represents the angle between the look-at vector and normal to the surface along x-axis. The range is from -180 to +180, but it can be restricted by the render engine capabilities. 0 - no incline, 90 - left incline, -90 - right incline.

tilt number <optional>

This property represents the angle between the look-at vector and normal to the surface along z-axis. The range is from 0 to 90, but it can be restricted by the render engine capabilities. 0 - looks down; 90 - looks straight.