OSMBuildings

Static

Events

Global

Documentation

Class

OSMBuildings

Parameters
NameTypeDefaultOptionalDescription
options Object optional OSMBuildings options
options.container String A DOM Element or its id to append the viewer to
options.minZoom Number 14.5 Global minimum allowed zoom
options.maxZoom Number 20 Global maximum allowed zoom
options.bounds Object optional A bounding box to restrict the map to
options.state Boolean false Store the map state in the URL
options.disabled Boolean false Disable user input
options.attribution String optional An attribution string
options.zoom Number minZoom..maxZoom Initial zoom, default is middle between global minZoom and maxZoom
options.rotation Number 0 Initial rotation
options.tilt Number 0 Initial tilt
options.position Object optional Initial position
options.position.latitude Number 52.520000 position latitude
options.position.longitude Number 13.410000 Position longitude
options.baseURL String '.' DEPRECATED For locating assets. This is relative to calling html page
options.showBackfaces Boolean false DEPRECATED Render front and backsides of polygons. false increases performance, true might be needed for bad geometries
options.fogColor String '#e8e0d8' Color to be used for sky gradients, distance fog and color benath the map
options.highlightColor String '#f08000' DEPRECATED Default color for highlighting features
options.effects Array optional DEPRECATED Which effects to enable. The only effect at the moment is 'shadows'
options.backgroundColor String optional DEPRECATED Overall background color
options.fastMode Boolean false Enables faster rendering at cost of image quality.
options.style Object optional Sets the default building style
options.style.color String 'rgb(220, 210, 200)' Sets the default building color

Methods

appendTo

DEPRECATED

on

Adds an event listener

Parameters
NameTypeDefaultOptionalDescription
type String Event type to listen for
fn eventCallback Callback function

off

Removes an event listener

Parameters
NameTypeDefaultOptionalDescription
type String Event type to listen for
fn eventCallback optional If callback is given, only remove that particular listener

emit

Triggers a specific event

Parameters
NameTypeDefaultOptionalDescription
event String Event type to listen for

setDate

Set date for shadow calculations

Parameters
NameTypeDefaultOptionalDescription
date Date

project

Gets 2d screen position from a 3d point

Parameters
NameTypeDefaultOptionalDescription
latitude Number Latitude of the point
longitude Number Longitude of the point
altitude Number Altitude of the point
Returns
TypeDescription
Object Screen position in pixels { x, y }

unproject

Turns a screen point (x, y) into a geographic position (latitude/longitude/altitude=0). Returns 'undefined' if point would be invisible or lies above horizon.

Parameters
NameTypeDefaultOptionalDescription
x Number X position on screen
y Number Y position om screen
Returns
TypeDescription
Object Geographic position { latitude, longitude }

remove

Removes a feature, layer or marker from the map.

addOBJ

Adds an 3d object (OBJ format) file to the map. Important objects with exactly the same url are cached and only loaded once.

Parameters
NameTypeDefaultOptionalDescription
url String Absolute URL to OBJ file
position Object Where to render the object
position.latitude Number Position latitude for the object
position.longitude Number Position longitude for the object
options Object {} optional Options for rendering the object
options.scale Number 1 Scale the model by this value before rendering
options.rotation Number 0 Rotate the model by this much before rendering
options.altitude Number 0 The height above ground to place the model at
options.id String optional An identifier for the object. This is used for getting info about the object later
options.color String optional A color to apply to the model
options.swapYZ Boolean optional Swap y and z coordinates. Use this if your model is standing upright on one side
Returns
TypeDescription
Object The added object

addGeoJSON

Adds a GeoJSON object to the map.

Parameters
NameTypeDefaultOptionalDescription
url String Absolute URL to GeoJSON file or a JavaScript Object representing a GeoJSON FeatureCollection
options Object optional Options to apply to the GeoJSON being rendered
options.scale Number 1 Scale the model by this value before rendering
options.rotation Number 0 Rotate the model by this much before rendering
options.altitude Number 0 The height above ground to place the model at
options.id String optional An identifier for the object. This is used for getting info about the object later
options.color String optional A color to apply to the model
options.minZoom Number 14.5 Minimum zoom level to show this feature, defaults to and limited by global minZoom
options.maxZoom Number maxZoom Maximum zoom level to show this feature, defaults to and limited by global maxZoom
options.fadeIn Boolean true DEPRECATED Fade GeoJSON features; if false, then display immediately
Returns
TypeDescription
Object The added object

addGeoJSONTiles

Adds a GeoJSON tile layer to the map. This is for continuous building coverage.

Parameters
NameTypeDefaultOptionalDescription
url String https://{s}.data.osmbuildings.org/0.2/{k}/tile/{z}/{x}/{y}.json url The URL of the GeoJSON tile server
options Object {} optional
options.fixedZoom Number 15 Tiles are fetched for this zoom level only. Other zoom levels are scaled up/down to this value
options.minZoom Number 14.5 Minimum zoom level to show features from this layer. Defaults to and limited by global minZoom.
options.maxZoom Number maxZoom Maximum zoom level to show features from this layer. Defaults to and limited by global maxZoom.
Returns
TypeDescription
Object The added layer object

addMapTiles

Adds a 2d base map source. This renders below the buildings.

Parameters
NameTypeDefaultOptionalDescription
url String The URL of the map server. This could be from Mapbox or other tile servers
Returns
TypeDescription
Object The added layer object

highlight

This replaces any previous highlighting.

hide

This replaces any previous show/hide rule.

show

DEPRECATED

getTarget

DEPRECATED

screenshot

DEPRECATED

setDisabled

Disables map interaction

Parameters
NameTypeDefaultOptionalDescription
flag Boolean

isDisabled

Checks for map interaction disabled

Returns
TypeDescription
Boolean flag

getBounds

Returns geographical bounds of the current view

Returns
TypeDescription
Array Bounding coordinates in unspecific order { latitude, longitude }, ...

setZoom

Set zoom level

Parameters
NameTypeDefaultOptionalDescription
zoom Number The new zoom level

getZoom

Get current zoom level

Returns
TypeDescription
Number zoom level

setPosition

Set map's geographic position

Parameters
NameTypeDefaultOptionalDescription
pos Object The new position
pos.latitude Number
pos.longitude Number

getPosition

Get map's current geographic position

Returns
TypeDescription
Object Geographic position { latitude, longitude }

setSize

Set map view's size in pixels

Parameters
NameTypeDefaultOptionalDescription
width Integer
height Integer
size Object DEPRECATED
size.width Integer DEPRECATED
size.height Integer DEPRECATED

getSize

Get map's current view size in pixels

Returns
TypeDescription
Object View size { width, height }

setRotation

Set map's rotation

Parameters
NameTypeDefaultOptionalDescription
rotation Number The new rotation angle in degrees

getRotation

Get map's current rotation

Returns
TypeDescription
Number Rotation in degrees

setTilt

Set map's tilt

Parameters
NameTypeDefaultOptionalDescription
tilt Number The new tilt in degree

getTilt

Get map's current tilt

Returns
TypeDescription
Number Tilt in degrees

addMarker

Adds a marker to the map in 3d space.

Parameters
NameTypeDefaultOptionalDescription
position Object geographic position including altitude
position.latitude Number latitude
position.longitude Number longitude
position.altitude Number 0 altitude in meters
data Object optional custom data properties to attach to the marker, i.e. an id
options Object optional additional options
options.url String optional url to an SVG file to use as custom marker. Currently only path properties are supported. Overlapping path's may create strange results.
options.color String optional color which whole marker will be tinted
Returns
TypeDescription
Object Marker

destroy

Destroys the map

Static

VERSION

(String) OSMBuildings version

ATTRIBUTION

(String) OSMBuildings attribution

Events

loadfeature

Fired when a 3d object has been loaded

zoom

Fired when map has been zoomed

rotate

Fired when map view has been rotated

tilt

Fired when map view has been tilted

change

Fired when map view has been changed, i.e. zoom, pan, tilt, rotation

resize

Fired when map container has been resized

doubleclick

Fired when map container has been double clicked/tapped

pointerdown

Fired when map container has been clicked/tapped

pointermove

Fired when mouse/finger has been moved

pointerup

Fired when mouse button/finger been lifted

gesture

Fired when gesture has been performed on the map

busy

DEPRECATED Fired when data loading starts

idle

DEPRECATED Fired when data loading ends

Global

eventCallback

User defined function that will be called when an event is fired

Parameters
NameTypeDefaultOptionalDescription
type String Event type
payload any optional Payload of any type

selectorCallback

User defined function that will be called on each feature, for modification before rendering

Parameters
NameTypeDefaultOptionalDescription
id String The feature's id
feature Object The feature