Custom UX
Smplr.js provides a few options that help you customize the map experience to your requirements. We're regularly adding new options, so reach out and share what you'd like to do with it.
Adapting the look & feel and experience
Render options
To customize how the map viewer renders the spaces, you can pass in a number of options to the rendering engine. Below are the options currently exposed. Render options can be updated dynamically as described further.
interface MapSpaceRenderOptions {
footprint?: {
render?: boolean
color?: string
}
walls?: {
render?: boolean
}
grounds?: {
render?: boolean
}
windows?: {
render?: boolean
}
}
Viewer controls
Update render options dynamically
Render options are described in details in Render options. You can update them dynamically with the methods below:
map.updateRenderOptions(options: MapSpaceRenderOptions) => void
map.resetRenderOptionsToDefault() => void
updateRenderOptionsis used to update specific values, while keeping the others unchanged.optionsis an object of theMapSpaceRenderOptionsinterface, which is deeply merged with the current options used by the viewer. To "unset" an optional value, you can passundefinedexplicitely.
resetRenderOptionsToDefaultreverts all values to the Smplrspace defaults.
Show/hide level picker
This is the programmatic equivalent of setting hideLevelPicker in startViewer:
map.showLevelPicker() => void
map.hideLevelPicker() => void
Navigate levels
To programmatically choose which levels are visible on the map, you may use the following functions:
map.showUpToLevel(levelIndex: number) => void
levelIndex- zero-based index of the top level you want to see. For example, settinglevelIndexto2is equivalent to pressing theL3button in the space viewer.
You can also reset the viewer back to showing all the levels with:
map.showAllLevels() => void
Camera controls
Get the camera placement
map.setCameraPlacement lets you position the camera. You would typically embed the map viewer and have an interface to retrieve one or more placement(s) to be stored in your database. You can then load any placement object from your database to set the initial value. The camera placement can be retrieved with the following function:
map.getCameraPlacement() => ({
pitch: number
bearing: number
zoom: number
center: {
lng: number
lat: number
}
})
The "placement" is a Javascript object that includes the position and direction of the camera. It is defined as an orbit position (pitch, bearing, zoom) around a center point which the camera points towards. It is fully compatible with the native Mapbox camera values.
pitchis the angle given in degrees of the camera's position in the vertical plane.0corresponds to a top down view, while90corresponds to a view from the ground.bearingis the angle given in degrees of the camera's position in the horizontal plane.0faces North,90faces East, and-90or270faces West.zoomrepresents the distance to the center point. It has a value between0and22, with0showing the whole Earth, and15showing buildings.centercontains the GPS coordinates of the center point in{ lat, lng }format.
Set the camera placement
You can move the camera to a specific position and have it target a specific point as well by calling the following function:
map.setCameraPlacement({
pitch?: number
bearing?: number
zoom?: number
center?: {
lng: number
lat: number
}
animate?: boolean
speed?: number
}) => void
- placement parameters (see description above) are the new desired value. All parameters are optional and the ones that are not provided will keep their current value.
animate- optional - should be set to false to jump to the new placement and true to animate the camera to the new placement. Default value: falsespeed- optional - defines the speed of the camera animation and should be used with animate set to true. Default value: 1.2
Zoom in/out
This is the programmatic equivalent to pressing the zoom buttons:
map.zoomIn() => void
map.zoomOut() => void