Class: ViewModel
- Last UpdatedDec 5, 2024
- 5 minute read
Class: 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
ordispose
on the given object when you no longer need it. -
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
-
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 viaH.map.ViewModel#endControl
-
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. -
To finish the control of a look-at-point animation. See also
H.map.ViewModel#startControl
andH.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 ofP2D
engine, otherwise bounds is of typeH.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. -
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 isH.geo.Polygon
, then the exterior of the polygon defines visible area, otherwise the bounding box of the given bounds geometry.Fires:
- H.map.ViewModel#event:update
Returns:
Type Description H.map.ViewModel this view model object -
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 ofH.map.ViewModel#endControl
Type Definitions
-
An Interface to describe a look-at data set.
Properties: