Wrld.map(element, apiKey, options)
Extends: L.Map
// Create a map inside the "map" element, centered over San Francisco
var map = Wrld.map("map", "your_api_key_here", {
center: [37.7858, -122.401],
zoom: 16
});
Argument | Type | Description |
---|---|---|
element | HTMLElement | string | The DOM element, or id of the DOM element, to create a map inside. |
apiKey | string | A valid WRLD API key which is required to initialize the map. |
options | object | These are the same options you would pass to L.map with some extensions described below. |
Options
Options | Type | Default | Description |
---|---|---|---|
canvasId | string | “canvas” | The id to give to the generated canvas HTML element that the map is rendered on. |
width | number | * | The initial width of the canvas. Defaults to the width of the element passed to the constructor. |
height | number | * | The initial height of the canvas. Defaults to the height of the element passed to the constructor. |
indoorsEnabled | boolean | false | Whether or not IndoorMap objects and their IndoorMapEntrance objects can be loaded by the map. |
displayEntranceMarkers | boolean | true | Whether or not to automatically represent IndoorMapEntrance objects as interactive markers on the map. |
coverageTreeManifest | string | ”” | The coverage tree manifest URL for the map. By default, the map will load the latest public manifest which is updated regularly. |
environmentThemesManifest | string | ”” | The environment themes manifest URL for the map. By default, the map will load the latest themes manifest which is updated regularly. |
headingDegrees | number | 0 | The initial heading of the map in degrees. |
trafficEnabled | boolean | true | Enables or disables the traffic simulation. |
trafficDisableWhenEnteringIndoorMaps | boolean | true | Whether to disable the traffic simulation when entering an indoor map (this takes precedence over the trafficEnabled option when entering an indoor map). |
indoorLabelsAlwaysHidden | boolean | false | Whether to disable the indoor labels. |
drawClearColor | string | #000000ff |
The color used to clear the canvas prior to drawing the map. |
indoorMapBackgroundColor | string | #000000c0 |
The color of the background overlay when displaying an indoor map. |
viewVerticallyLocked | boolean | false |
If true, forces the map camera viewpoint to look vertically downwards. |
targetVSyncInterval | number | 1 |
Map updates are scheduled using the requestAnimationFrame function with vsync enabled. This value is used as the number of screen swap intervals between map updates. For a 60Hz display, and a targetVSyncInterval value n , this will perform a map update every n/60 seconds. |
frameRateThrottleWhenIdleEnabled | boolean | false |
If true, throttles (reduces) map updates after a period without user input activity. |
idleSecondsBeforeFrameRateThrottle | number | 30.0 |
The time since the most recent user input before frame rate throttling is applied. |
throttledTargetFrameIntervalMilliseconds | number | 1000 |
The duration in milliseconds between each map update when frame rate throttling is applied. |
indoorSelectionTimeoutDuration | number | 30.0 |
The duration in seconds before an indoor map enter request times out. |
Methods
map.getAltitudeAtLatLng(latLng)
Returns the altitude of the terrain in meters above sea level at a given LatLng.
Argument | Type | Description |
---|---|---|
latLng | Wrld.LatLng | The LatLng where the altitude will be returned from. |
map.getCameraDistanceToInterest()
Returns the distance between the camera and the geographical center of the map view in meters.
map.getCameraPitchDegrees()
Returns the pitch of the camera in degrees, where 0 is the horizontal and 90 is the downward vertical.
map.getCameraTiltDegrees()
Returns camera’s tilt. This is the offset from the normal to the earth’s surface. 0 is looking vertically down onto the map.
map.setCameraTiltDegrees(tilt)
Sets the camera’s tilt to a new value.
Argument | Type | Description |
---|---|---|
Tilt | number | This is the offset from the normal to the earth’s surface. 0 is looking vertically down onto the map. |
map.getCameraHeadingDegrees()
Returns the heading of the camera in degrees, where 0 is North and increases clockwise.
map.setCameraHeadingDegrees(heading)
Sets the camera’s heading to a new value.
Argument | Type | Description |
---|---|---|
heading | number | The new heading in degrees. Clockwise with 0 pointing north. |
map.getMaximumPrecacheRadius()
Returns the maximum radius (in meters) which may be passed to map.precache(center, radius, callback) or map.precacheWithDetailedResult(center, radius, callback).
map.precache(center, radius, callback)
Begin an operation to precache a spherical area of the map. This allows that area to load faster in future.
This function returns an object with a cancel()
method to allow you to cancel the precache operation.
Argument | Type | Description |
---|---|---|
center | Wrld.LatLng | The center of the area to precache. |
radius | number | The radius of the area to precache. |
callback | function | The function to call when the precache operation completes. The function will be passed a boolean indicating whether the precache completed successfully. |
map.precacheWithDetailedResult(center, radius, callback)
Begin an operation to precache a spherical area of the map. This allows that area to load faster in future. This version of the function should be preferred to map.precache, as it returns a result type which may be populated with further detail in future.
This function returns an object with a cancel()
method to allow you to cancel the precache operation.
Argument | Type | Description |
---|---|---|
center | Wrld.LatLng | The center of the area to precache. |
radius | number | The radius of the area to precache. |
callback | function | The function to call when the precache operation completes. The function will be passed a PrecacheOperationResult indicating whether the precache completed successfully. |
map.setView
Move the map to a new view.
Argument | Type | Description |
---|---|---|
center | Wrld.LatLng | The center of the new view. |
zoom | number | The zoom of the new view. |
options | function | Optional parameters for the new view. |
Options | Type | Description |
---|---|---|
headingDegrees | number | Angle in degrees clockwise from north. |
tiltDegrees | number | Camera tilt in degrees. The offset from the earth’s normal, with a tilt of 0 looking vertically down at the earth. |
animate | boolean | Flag on whether to animate transition or not. |
durationSeconds | number | Time in seconds for the duration of the animation. |
allowInterruption | boolean | Whether or not the user can interrupt the animation by clicking, dragging or zooming. |
map.setViewVerticallyLocked(isVerticallyLocked)
Modal setting to optionally force the camera viewpoint to point vertically downwards, disregarding any tilt or pitch settings.
Argument | Type | Description |
---|---|---|
isVerticallyLocked | boolean | If true, the map camera viewpoint will always look vertically downwards. |
map.layerPointToLatLng(point)
Converts point on screen to a Wrld.LatLng
Argument | Type | Description |
---|---|---|
point | Wrld.Point | The pixel point on map layer to convert to a latlng. |
map.latLngToLayerPoint(latLng)
Converts a latlng to a Wrld.Point pixel position relative to the top left of the map layer.
Argument | Type | Description |
---|---|---|
latLng | Wrld.LatLng | The latLng to convert to a point. |
map.setMapCollapsed(isMapCollapsed)
Sets whether the map should display with vertical scaling applied so that terrain and other map features appear flattened.
Argument | Type | Description |
---|---|---|
isMapCollapsed | boolean | If true, the map is drawn to appear flattened vertically. |
map.isMapCollapsed()
Returns true if map is currently drawn collapsed, false otherwise (the default).
map.setDrawClearColor(clearColor)
Sets the color used to clear the canvas prior to drawing the map.
Argument | Type | Description |
---|---|---|
clearColor | string | An Html hex color code, in the form #RRGGBB or #RRGGBBAA. Emmet-style abbreviations are also supported (#RGB and #RGBA). |
map.setTargetVSyncInterval(targetVSyncInterval)
Sets the number of screen swap intervals between map updates.
Argument | Type | Description |
---|---|---|
targetVSyncInterval | number | This is equivalent to specifying targetVSyncInterval in the Wrld.map factory options. |
map.setFrameRateThrottleWhenIdleEnabled(frameRateThrottleWhenIdleEnabled)
If frameRateThrottleWhenIdleEnabled
is true, throttles (reduces) map updates after a period without user input activity.
Argument | Type | Description |
---|---|---|
frameRateThrottleWhenIdleEnabled | boolean | This is equivalent to specifying frameRateThrottleWhenIdleEnabled in the Wrld.map factory options. |
map.setIdleSecondsBeforeFrameRateThrottle(idleSecondsBeforeFrameRateThrottle)
Sets the time since the most recent user input before frame rate throttling is applied.
Argument | Type | Description |
---|---|---|
targetVSyncInterval | number | This is equivalent to specifying idleSecondsBeforeFrameRateThrottle in the Wrld.map factory options. |
map.setThrottledTargetFrameIntervalMilliseconds(throttledTargetFrameIntervalMilliseconds)
Sets the duration in milliseconds between each map update when frame rate throttling is applied.
Argument | Type | Description |
---|---|---|
targetVSyncInterval | number | This is equivalent to specifying throttledTargetFrameIntervalMilliseconds in the Wrld.map factory options. |
map.cancelFrameRateThrottle()
Cancels any frame rate throttling that may be applied, and resets the time since the last user input activity.
map.isHardwareAccelerationAvailable()
Returns whether hardware-accelerated WebGL can be used in the current browser. When false, performance may be very poor.
Events
In addition to the standard Leaflet events, Wrld.map
supports the following events.
The following events are supported.
Event | Data | Description |
---|---|---|
initialstreamingcomplete | Event | Fired when the map has finished streaming the minimum resources required to display the initial view. |
update | Event | Fired every frame. |
zoom | Event | Fired repeatedly while the user zooms the map. |
pan | Event | Fired repeatedly while the map is panning (e.g. while the user is dragging the map or while the map is still moving after the user stops dragging the map). |
panstart | Event | Fired when the user starts dragging the map. |
panend | Event | Fired when the map stops moving after the user stops dragging the map. |
rotate | Event | Fired repeatedly while the user rotates the map. |
rotatestart | Event | Fired when the user starts rotating the map. |
rotateend | Event | Fired when the user stops rotating the map. |
tilt | Event | Fired repeatedly while the user tilts the map. |
tiltstart | Event | Fired when the user starts tilting the map. |
tiltend | Event | Fired when the user stops tilting the map. |
transitionstart | Event | Fired when the user calls setView() . |
transitionend | Event | Fired when the camera stops transitioning after setView() has been called. |
Properties
map.indoors
See Wrld.map.indoors
map.themes
See Wrld.map.themes
map.buildings
map.indoorMapEntities
See Wrld.map.indoorMapEntities