Photo Sphere Viewer includes a markers system since version 3.1. It allows to define points of interest on the Photo Sphere with optional tooltip and description. It also allows to dynamically add and remove markers on user click/tap.
There are four types of markers :
- HTML defined with the
html
attribute - Images defined with the
image
attribute - SVGs defined with the
rect
,circle
,ellipse
orpath
attribute - Dynamic polygons & polylines defined with the
polygon_px
/polygon_rad
/polyline_px
/polyline_rad
attribute
Demo
The following example contains all types of markers. Click anywhere on the panorama to add a red marker, click again to remove it.
Usage
Configuration
Markers can be added at startup with the markers
option or after load with the methods detailed further in this page.
In both case the markers attributes are :
Name | type | default | description |
---|---|---|---|
id | string | required | Unique identifier of the marker. |
image | string | one required | Path to the image representing the marker. Requires width and height . |
html | string | HTML content of the marker. | |
rect | int[] | Object | Size of the rectangle. Eg: [10, 5] or {width: 10, height: 5} .
|
|
circle | int | Radius of the circle. | |
ellipse | int[] | Object | Radiuses of the ellipse. Eg: [10, 5] or {cx: 10, cy: 5} . |
|
path | string | Definition of the path (0,0 will be placed at the defined x/y or longitude/latitude). | |
polygon_px | int[][] | Array of points defining the polygon in pixel coordinates on the panorama image. Eg: [[100, 200], [150, 300], [300, 200]] |
|
polygon_rad | double[][] | Same as above but coordinates are in longitude and latitude. Eg: [[0.2, 0.4], [0.9, 1.1], [1.5, 0.7]] |
|
polyline_px | int[][] | Array of points defining the polyline in pixel coordinates on the panorama image. Eg: [[100, 200], [150, 300]] |
|
polyline_rad | double[][] | Same as above but coordinates are in longitude and latitude. Eg: [[0.2, 0.4], [0.9, 1.1]] |
|
width & height | int | recommended required for images |
Size of the marker. Ignored for polygons/polylines |
x & y | int | required x/y or latitude/longitude | Position of the marker in texture coordinates (pixels). Ignored for polygons/polylines |
latitude & longitude | double | Position of the marker in spherical coordinates (radians). Ignored for polygons/polylines |
|
scale | double | double[2] | 1 (constant) | Scale factor multiplied by the zoom level. Provide an array of two values for min and max. |
className | string | Optional CSS class(es) added to the marker element. | |
anchor | string | 'center center' | Defines where the marker is placed toward its position. Any CSS position is valid like bottom
center or 20% 80% Ignored for polygons/polylines. |
visible | boolean | true | Is the marker visible once added. If hidden, the marker will have to be edited through
getMarker method later.
|
tooltip | string | Object | Tooltip content of the marker or object defining the tooltip. | |
tooltip.content | string | Tooltip content. | |
tooltip.position | string | 'top center' | Tooltip position toward the marker. Accepted values are combinations of top, center, bottom and
left, center, right with the exception of center center .
|
style | Object | CSS properties to set on the marker (background, border, etc.).
|
|
svgStyle | Object | SVG properties to set on the marker (fill, stroke, etc.). Only for SVG and polygons/polylines markers. |
|
content | string | HTML content that will be displayed on the side panel when the marker is clicked. | |
data | Object | Any custom data you want to attach to the marker. |
Methods
Check the API documentation to learn more about additional methods dedicated to the markers.
Events
More events are also available for markers.