Powered by Zoomin Software. For more details please contactZoomin

HERE Maps API for JavaScript - API Reference

Product category
Technology
Doc type
Version
Product lifecycle
This publication

HERE Maps API for JavaScript - API Reference: Class: Map

Table of Contents

Class: Map

H.Map

new H.Map (element, baseLayer, opt_options)

The Map class defines a map instance. By creating this object, you initialize a visible map attached to a DOM element. The Map class is the entry point to all operations involving layers, map objects and geo-screen transformations. Use the options argument to initialize the map with a specific map view.

Throws:

if the element is not a HTMLElement

Type
H.lang.InvalidArgumentError
Example
var platform = new H.service.Platform({
  apikey: '{YOUR_API_KEY}'
});

// Obtain the default map types from the platform
var maptypes = platform.createDefaultLayers();

// Instantiate and display a map
var map = new H.Map(document.getElementById('mapdiv'), maptypes.vector.normal.map, {
  center: {lat: 0, lng: 51},
  zoom: 8
});

Extends

Members

H.Map.EngineState number static

States of the render engine.

Properties:
Name Description
IDLE

The engine is currently idle (rendering completed).

BUSY

The engine is actively rendering.

H.Map.EngineType number static

Properties:

draggable boolean

Indicates whether the map will be considered as target for drag events. The default value is false

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.

addLayer (layer, opt_idx)H.Map

This method adds a layer to the map. If the layer was already added before, it will be moved above the most recently added layer.

Name Type Description
layer H.map.layer.Layer

The map layer to be added

opt_idx number optional

index at which the new layer should be inserted

Returns:
Type Description
H.Map current map instance

addObject (mapObject)H.map.Object

This method adds a map object to the map. The map object can be a marker or a spatial object such as a polygon or polyline.

Name Type Description
mapObject H.map.Object

The map object to add

Throws:

This method throws an error if the mapObject parameter is not a map object.

Type
Error
Returns:
Type Description
H.map.Object The added map object

addObjects (mapObjects)H.Map

This method adds an array of objects or an object group to the map.

Note: Objects which were added to the map previously won't be added again.

Name Type Description
mapObjects Array.<!H.map.Object>
Throws:

if the argument is not an Array of H.map.Object instances

Type
H.lang.InvalidArgumentError
Returns:
Type Description
H.Map The current map instance

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

capture (callback, opt_capturables, opt_x1, opt_y1, opt_x2, opt_y2)

This method captures the desired region of the map and the associated map objects. The method returns an HTML5 Canvas element. The origin of coordinate system is the top-left corner of the viewport.

In order to see any captured UI controls in the output, pass in a reference to H.ui.UI object. At present, only H.ui.ScaleBar UI element supports the feature.

Note that instances of H.map.Icon taint the output canvas if images from different origins are used. When an image source sets CORS headers, H.map.Icon supports a flag that enables image loading with cross-origin parameters. Internet Explorer always taints the canvas element when SVG images are used. CORS support for images starts only from IE11.

Throws:

This method throws an error if the callback parameter is not a function

Type
Error
Example
var platform = new H.service.Platform({
  apikey: '{YOUR_API_KEY}'
});
var maptypes = platform.createDefaultLayers();
var map = new H.Map(mapContainer, maptypes.vector.normal.map, {
  center: {lat: -40, lng: 178},
  zoom: 2
});
var ui = H.ui.UI.createDefault(map, maptypes);
map.capture(function(canvas) {
  // Here we have the canvas with desired area of the map,
  // (from top left (0,0) corner to the bottom right (100,100) corner)
}, [ui], 0, 0, 100, 100);

clearContent (opt_onprogress)H.util.Request

This method clears the entire stored content.

Name Type Description
opt_onprogress function(H.util.Request) optional

A callback which is invoked each time the progress state of the returned clear request changes

See:
Returns:
Type Description
H.util.Request A handle to the created flush request

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.

geoToScreen (geoPoint)H.math.Point

This method retrieves the screen coordinates corresponding to the geographical coordinates supplied by the caller.

Name Type Description
geoPoint H.geo.IPoint

point on the map

Returns:
Type Description
H.math.Point

getBaseLayer ()H.map.layer.Layer

This method gets the current base map layer.

Returns:
Type Description
H.map.layer.Layer representing the current base map layer.

getCenter ()H.geo.Point

This method returns the current center of the map.

Returns:
Type Description
H.geo.Point

getElement ()HTMLElement

This method retrieves the map root HTML element.

Returns:
Type Description
HTMLElement

getImprint ()H.map.Imprint

This method retrieves the imprint object for this map.

Returns:
Type Description
H.map.Imprint

getLayers ()H.map.DataModel

This method retrieves the map's current layer collection.

Returns:
Type Description
H.map.DataModel

getObjectAt (x, y, callback)

To obtain the top-most z-ordered map object found at the specified screen coordinates. Coordinates are viewport pixel coordinates starting from top-left corner as origin (0, 0).

getObjects (opt_recursive)Array.<!H.map.Object>

This method obtains a list of all objects that have been added to the map. See H.map.Group#getObjects.

Unless opt_recursive parameter is set to true, this method will return only first level objects, for example if group with a marker is added to the map, only the group will be returned and not the marker.

Note: Adding or removing objects on the obtained list doesn't affect the map. Use the map's addObject and removeObjects methods instead.

Name Type Description
opt_recursive boolean optional

Indicates whether objects in sub-groups are also collected.

Returns:
Type Description
Array.<!H.map.Object> the list of all user objects which are currently on the map.

getObjectsAt (x, y, callback, opt_allowDuplicates)

To obtain a list of map objects in descending z-order found at the specified screen coordinates. The coordinates are viewport pixel coordinates starting from top left corner as origin (0, 0).

getObjectsWithin (area, callback, opt_options)

To obtain a list of map objects which intersect the provided area.

getViewModel ()H.map.ViewModel

This method retrieves current view model. View model can be used to modify the current view or camera. H.map.ViewModel

Returns:
Type Description
H.map.ViewModel

getViewPort ()H.map.ViewPort

This method retrieves the current map viewport. The viewport can be used to modify padding and margin, which reflect the position of the viewport center and the amount of extra data loaded (for margin)

Returns:
Type Description
H.map.ViewPort

getZoom ()number

This method retrieves the current map zoom level.

Returns:
Type Description
number

removeEventListener (type, handler, opt_capture, opt_scope) inherited

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

removeLayer (layer)H.Map

This method removes a layer from the map.

Name Type Description
layer H.map.layer.Layer

The map layer to be removed

Returns:
Type Description
H.Map current map instance

removeObject (mapObject)H.map.Object

This method removes previously added map object from the map. Note that method can be used to remove only direct children of the root group of the default object layer.

Name Type Description
mapObject H.map.Object

The map object to remove

Throws:

This method throws an error if the mapObject parameter is not a map object.

Type
Error
Returns:
Type Description
H.map.Object The removed map object

removeObjects (mapObjects)H.Map

This method removes an array of map objects from the map. Note that method can be used to remove only direct children of the root group of the default object layer.

Name Type Description
mapObjects Array.<!H.map.Object>
Throws:

This method throws an error if the mapObjects parameter is not an array of map objects

Type
Error
Returns:
Type Description
H.Map The current map instance

screenToGeo (x, y)H.geo.Point

This method retrieves the geographical coordinates corresponding to the screen coordinates supplied by the caller.

Name Type Description
x number

Map viewport x-axis pixel coordinate

y number

Map viewport y-axis pixel coordinate

Returns:
Type Description
H.geo.Point object containing the screen coordinates for the specified geographical location.

screenToLookAtData (x, y)H.map.ViewModel.ILookAtData

This method retrieves LookAtData according to the given screen coordinates. The method converts screen pixel coordinates to correct LookAtData object.

Name Type Description
x number

map viewport x-axis pixel coordinate

y number

map viewport y-axis pixel coordinate

Returns:
Type Description
H.map.ViewModel.ILookAtData

setBaseLayer (layer)H.Map

This method sets the provided layer as base map. The layer is inserted as the bottom-most layer in the map.

Name Type Description
layer H.map.layer.Layer

The layer to use as base map

Returns:
Type Description
H.Map the instance itself

setCenter (center, opt_animate)H.Map

This method sets the center of the map.

Name Type Description
center H.geo.IPoint

An object containing the coordinates of the new map center

opt_animate boolean optional

A value indicating if an animated transition should be applied, default is false

Returns:
Type Description
H.Map the instance itself

setZoom (zoom, opt_animate)H.Map

This method sets the zoom level of the map. Every zoom level represents a different scale. The map at zoom level 2 is twice as large as the map at zoom level 1.

Name Type Description
zoom number

A value indicating the new map zoom level

opt_animate boolean optional

A value indicating if an animated transition should be applied, default is false

Returns:
Type Description
H.Map the instance itself

storeContent (opt_onprogress, opt_boundingBox, opt_min, opt_max, opt_layer)H.util.Request

This method persistently stores the content of a map layer for a given area and range of zoom levels. It can be used to enable map rendering when no internet connection is available and also to reduce the download traffic for frequently visited map areas.

Specified opt_min and opt_max values are clamped to the provider [min,max] range. Note that specifying a big range will cause many tile requests to the server and might greatly affect the performance of the browser.

Throws:

If the browser or the passed layer does not support persistent storage of map layer content

Type
H.lang.IllegalOperationError
Returns:
Type Description
H.util.Request A handle to the created storage request

zoomAt (zoom, x, y)

This method changes the map zoom level while keeping the map location under the specified screen coordinates (x,y) fixed in the viewport.

Type Definitions

H.Map.BackgroundRange Object

This variable defines the number of lower and higher zoom levels, where cached content of the base map is rendered while content of the current zoom level is still loading. For example, if range is set to {lower: 3, higher: 2} and current level is 10, then the rendering engine tries to display cached tiles from the lower zoom levels 7, 8, 9 and the higher levels 11 and 12.

Properties:
Name Type Description
lower number

The number of lower zoom levels to take into account, default is 0

higher number

The number of higher zoom levels to take into account, default is 0

H.Map.GetObjectsWithinOptions Object

This type defines options that can be used for H.Map#getObjectsWithin calls.

Properties:

H.Map.Options Object

This type defines options that can be used to initialize the map.

Properties:

Events

baselayerchange

Event fired when the map base layer changes.

Type:

enginestatechange

Event fired when state of the render engine has been changed.

Type:

mapviewchange

Event fired when changes to the current map view are ongoing.

Type:

mapviewchangeend

Event fired when changes to the current map view are ending.

Type:

mapviewchangestart

Event fired when changes to the current map view are starting.

Type:
Was this article helpful?
TitleResults for “How to create a CRG?”Also Available inAlert