News Examples Documentation Download Buy Forum Contact

zRadar Plugin zradar.js WebGL + HTML5 only
by indexofrefraction - (send forum message)

Description

zRadar is a plugin to create
  • a customisable radar icon showing the view direction and angle (fov)
  • a customisable compass icon showing the view direction
  • an image based compass using images for a compass needle and background
zRadar is loaded
  • as layer with a dynamically created SVG scaleable to any size
  • as hotspot providing a canvas mode to support webgl hotspots
    this enables all features in WebVR as well ! (requires krpano 1.21+)
In both modes the icon can get custom styled individually by path attributes,
and can get combined with images to personalize the design.

zRadar is pure javascript, has no dependecies and is very simple to use !

You can check out the Examples below!

zRadar 1.5.9 / 2025-11-24 - indexofrefraction

Syntax / XML Usage Example

  • Add zradar.js to your project folder
  • In your html (index/tour.html) ensure that you embedd krpano with html5:"only+webgl"
    embedpano({ html5:"only+webgl", ... });
  • In your main xml (tour.xml) add the plugin
    <plugin name="zradar" url="zradar.js"
    	preload="true" keep="true" regkey="abcdef" />
  • regular krpano plugin/layer attributes will give the radar svg a position and size
    this code is enough to display the default radar!
    (note: you can skew the radar by setting the height different than the width)
    <plugin name="zradar" url="zradar.js"
    	preload="true" keep="true" regkey="abcdef"
    	align="bottomright" edge="center"
    	x="100" y="100" width="100" height="100" />
  • the created svg has five paths which can get styled individually.
    i.e. to use path 1 as a borderless black background you would set these attributes:
    <plugin name="zradar" url="zradar.js"
    	preload="true" keep="true" regkey="abcdef"
    	align="bottomright" edge="center"
    	x="100" y="100" width="100" height="100"
    	line1alpha="0" fill1color="0x000000" fill1alpha="0.5" />
  • for each of the five paths you can set the line width, color, alpha, fill color and alpha
    and a radius attribute which allows to define the paths shape.
    the styling possibilites are shown in the examples
  • the provided reset view action can be used in the onclick attribute
    <plugin name="zradar" url="zradar.js"
    	preload="true" keep="true" regkey="abcdef"
    	align="bottomright" edge="center"
    	x="100" y="100" width="100" height="100"
    	fill1color="0xff0000" fill1alpha="0.5"
    	onclick="zradar_resetview()" />
  • about plugins, layers, hotspots and WebVR:
    plugins/layers and hotspots with renderer="css3d" do not show in inWebVR
    in WebVR only hotspots with renderer="webgl" can be displayed.

    for this zRadar has to be loaded as hotspot (requires krpano 1.21+)
    <hotspot name="zradar" url="zradar.js"
    	preload="true" keep="true" regkey="abcdef" />

    note: krpano <layer> or <plugin> elements are the same, only with different names!
    (also see documentation of the <plugin> and <hotspot> elements)
  • about the display size:
    sizing and positioning generally works as with any regular krpano plugin and hotspot
    (see documentation of the <plugin> and <hotspot> elements)
    note: the display size is set by the plugins or hotspots width and height,
    not by the internal svgsize or canvassize values!
  • about positioning:
    sizing and positioning generally works as with any regular krpano plugin and hotspot
    (see documentation of the <plugin> and <hotspot> elements)
    additionally zRadar allows unified align positioning on desktop and WebVR for hotspots
    using the zalign, zx/zy and vrscale attributes

    this is an example of an align positioned flying hotspot (requires krpano 1.21+)
    <hotspot name="zradar" url="zradar.js"
    	preload="true" keep="true" regkey="abcdef"
    	flying="1.0" zalign="topleft" zx="100" zy="100" />
  • about svg and canvas mode:
    for plugins/layers and hotspots with renderer="css3d" an SVG is used
    for hotspots with renderer="webgl" (needed for WebVR) a canvas element is used
    forcecanvas="true" will force canvas mode for layers and css3d hotspots
  • about the foreground and background images:
    these images are intended to create a pixel based compass
    the fg image rotates with the view angle and is normally used for a compass needle
    the svg is always displayed on top (in front of the foreground image)
    svgalpha, fgalpha and bgalpha can be used to blend the components
  • about performance:
    svg mode has better scaling, a better performance and uses less memory!
    for images and canvas size use the smallest size possible!
    foreground and background image sizes and the canvas size
    should match or stay close to the used display size.

Plugin Attributes

<plugin name="zradar"
	url="zradar.js"
	preload="true"
	keep="true"
	regkey=""
	☞ basic settings
	mode="radar"
	heading="0"
	headingoffset="90"
	invert="false"
	svgsize="100"
	canvassize="256"
	canvaspixelratio="auto"
	forcecanvas="false"
	refreshrate="0"
	drag="false"
	☞ svg and image settings
	svgalpha="1.0"
	fgurl="" fgalpha="1.0"
	bgurl="" bgalpha="1.0"
	rscale="true"
	lscale="1.0"
	dscale="1.0"
	pathorder="12345"
	☞ path settings
	radius1="1.0"          radius2="0.9"          radius3="0.2|0.8|0.2"  radius4="0.2|0.8|0.2"  radius5="0.1"
	line1width="1.5"       line2width="1.5"       line3width="1.5"       line4width="3.0"       line5width="1.5"
	line1color="0xffffff"  line2olor="0xffffff"   line3color="0xffffff"  line4color="0xffffff"  line5color="0xffffff"
	line1alpha="0.0"       line2alpha="1.0"       line3alpha="1.0"       line4alpha="1.0"       line5alpha="1.0"
	fill1color="0xffffff"  fill2color="0xffffff"  fill3color="0xffffff"  fill4color="0xffffff"  fill5color="0xffffff"
	fill1alpha="0.2"       fill2alpha="0.0"       fill3alpha="0.0"       fill4alpha="0.5"       fill5alpha="0.0"
	line1cap="round"       line2cap="round"       line3cap="round"       line4cap="round"       line5cap="round"
	line1join="round"      line2join="round"      line3join="round"      line4join="round"      line5join="round"
	line1dash=""           line2dash=""           line3dash=""           line4dash=""           line5dash=""
	line1gradient="..."    line2gradient="..."    line3gradient="..."    line4gradient="..."    line5gradient=""
	fill1gradient="..."    fill2gradient="..."    fill3gradient="..."    fill4gradient="..."    fill5gradient=""
	☞ positioning settings
	zalign=""
	zx="0" zy="0"
	vrscale="1.0"
        />
    
|0.5|0.5
Attribute nameTypeValue
ready (read only)Booleantrue | false
version (read only)Stringthe plugin version
urlStringzradar.js
preloadBooleantrue
keepBooleantrue
regkeyString
  • ready is true if the plugin is loaded and ready
  • version holds the plugins version number
  • url must point to the plugin (documentation)
  • preload should be set to true (documentation)
  • keep should be true for most cases (documentation)
  • regkey is used to register the plugin with your personal registration key
Attribute nameTypeDefault valueMinMax
modeStringradarradarcompass
headingNumber0.0
headingoffsetNumber90.0
invertBooleanfalse
svgsizeNumber100101000
canvassizeNumber256321024
canvaspixelratioStringauto1.04.0
forcecanvasBooleanfalse
refreshrateNumber25.00.030.0
dragBooleanfalse
  • mode - radar (default) or compass design for svg paths3 and 4
    the view angle (fov) is only shown in radar mode
  • heading - base rotation for the svg
    to align the pano orientation with the radar/compass
    note: heading=auto uses the active scene heading, if present
  • headingoffset - rotation offset for the radar/compass
    default is 90, which means heading=0 is pointing to right/east by default
    headingoffset=0 lets heading=0 point to top/north
  • invert - exchanges all styles for the svg paths3 and 4
    (this is a short cut for exchanging the path styles directly)
  • svgsize - the size of the svg in pixels
    note: this is an internal setting, to set the display size use the plugins width and height !
    note: the line width and dash values are interpreted in relation to the used svg size,
    therefore changing svgsize scales these values accordingly
  • canvassize - the size of the canvas in pixels
    note: this is an internal setting, to set the display size use the plugins width and height !
    note: on retina displays the internal size is 2-4x the given canvas size !
    to save performance the canvas size should be always as small as possible
  • canvaspixelratio - allows to override the pixelratio for the canvas
    canvaspixelratio="auto" uses device.pixelratio (default) note: setting the pixelratio to 1.0 would save memory and performance,
    but also results in antialising issues on retina screens
  • forcecanvas - can be used to prioritize canvas over svg mode
    forcecanvas="false" will use svg mode whenever possible (default)
    forcecanvas="true" forces canvas mode for layers and css3d hotspots
    note: by default canvas mode is only used for webgl hotspots
    note: using svg or canvas mode is decided on plugin init
    and can not be changed dynamically later on.
  • refreshrate - the refresh / update rate per second
    if set to 0 (default) the onviewchanged event is used
    note: this is an internal setting, for performance reasons best left at default
  • drag - enable dragging / steer view by radar
Attribute nameTypeDefault valueMinMax
svgalphaNumber1.00.01.0
fgurlString
fgalphaNumber1.00.01.0
bgurlString
bgalphaNumber1.00.01.0
rscaleBooleantrue
lscaleNumber1.00.110.0
dscaleNumber1.00.110.0
pathorderString12345
  • svgalpha - the icons's opacity
    can be used to hide the icon in favour of a foreground (compass needle) image
    note: the display order is icon, foreground, background image and can't be changed.
  • fgurl - the url for a foreground image (typically used for a compass needle)
    the foreground image rotates with the view angle
  • fgalpha - the foreground image's opacity
  • bgurl - the url for a background image (typically used for a compass background)
    the background image is fixed and doesnt rotate
  • bgalpha - the background image's opacity
  • rscale - globally scales all radiuses so that the largest path fits the svg size
  • lscale - globally scales the line widths for all paths
  • dscale - globally scales the dash values for all paths
  • pathorder - the svg path order from bottom to top
    e.g. pathorder="12435" would switch the order for paths 3 and 4
Attribute nameTypeDefault value
radius1String1.0
radius2String0.2
radius3String0.2|0.8|0.2
radius4String0.2|0.8|0.2
radius5String0.9
  • radius1 - radius5 can hold multiple values (eg. "0.5", "0.2|0.8", "0.2|0.8|0.2")
  • the larger of the first two values is used as outer, the smaller as inner radius
    using one value creates a circle, two values a ring shape
  • in mode="radius" (default)
    radius1, 2 and 5 are circles or ring shapes
    radius3 and 4 are a cut circles (or rings) showing the field of view (fov)
  • in mode="compass"
    radius1, 2 and 5 are circles or ring shapes
    radius3 and 4 are defining the compass needles (tip and base position)
    the 3rd value is used for the needles base width
  • the value range for all values is 0.0 to 1.0
    with the exception that in compass mode the inner radius can be negative
Attribute nameTypeDefault value
line1colorNumber0xffffff
line2colorNumber0xffffff
line3colorNumber0xffffff
line4colorNumber0xffffff
line5colorNumber0xffffff
fill1colorNumber0xffffff
fill2colorNumber0xffffff
fill3colorNumber0xffffff
fill4colorNumber0xffffff
fill5colorNumber0xffffff
  • line1color - line5color are the svg line colors
  • fill1color - fill5color are the svg fill colors
  • both rgb and rgba values are supported.
    rgba value have an additional byte to the right, which defines the alpha
    example: 0xffffff80 = white at 50% alpha
    rgba value are multiplied with the according alpha
    example: fill1 effective alpha = fill1color * fill1alpha
  • to define a gradient, two colors can be passed like
    fill3color="0xff0000|0x00ff00" (red to green) fill4color="0xffffff00|0xffffff00 (white to transparent)
Attribute nameTypeDefault value
line1alphaNumber1.0
line2alphaNumber1.0
line3alphaNumber1.0
line4alphaNumber1.0
line5alphaNumber1.0
fill1alphaNumber0.2
fill2alphaNumber0.0
fill3alphaNumber0.0
fill4alphaNumber0.5
fill5alphaNumber0.0
  • line1alpha - line5alpha are svg line alpha values
  • fill1alpha - fill5alpha are svg fill alpha values
Attribute nameTypeDefault value
line1widthNumber1.5
line2widthNumber1.5
line3widthNumber1.5
line4widthNumber3.0
line5widthNumber1.5
  • line1width - line5width are svg line widths
    note: the width values are interpreted in relation to the used svg size
Attribute nameTypeDefault value
line1capStringround
line2capStringround
line3capStringround
line4capStringround
line5capStringround
line1joinStringround
line2joinStringround
line3joinStringround
line4joinStringround
line5joinStringround
  • line1cap - line5cap is the stroke shape at the end of open paths
    possible values are: butt, round, square
    (see developer.mozilla.org stroke-linecap)
    note: with all paths closed this setting is only visible with dashed lines
  • line1join - line5join is the stroke shape to be used at path corners
    possible values are: crop, arcs, bevel, miter, round
    (see developer.mozilla.org stroke-linejoin)
Attribute nameTypeDefault value
line1dashString
line2dashString
line3dashString
line4dashString
line5dashString
  • line1dash - line5dash is the stroke dash
    example line1dash="10" or line1dash="20|10"
    (see developer.mozilla.org stroke-dasharray)
    note: the dash values are interpreted in relation to the used svg size
Attribute nameTypeDefault value
line1gradientString0.5|0.0|1.0|0.5|0.5
line2gradientString0.5|0.0|1.0|0.5|0.5
line3gradientString0.5|0.0|1.0|0.5|0.5
line4gradientString0.5|0.0|1.0|0.5|0.5
line5gradientString0.5|0.0|1.0|0.5|0.5
fill1gradientString0.5|0.0|1.0|0.5|0.5
fill2gradientString0.5|0.0|1.0|0.5|0.5
fill3gradientString0.5|0.0|1.0|0.5|0.5
fill4gradientString0.5|0.0|1.0|0.5|0.5
fill5gradientString0.5|0.0|1.0|0.5|0.5
  • line1gradient/fill1gradient - line5gradient/fill5gradient define the gradient details
    if a gradient is used by setting line1color/fill1color - line5color/fill5color to two colors. the first value is the gradient radius,
    the 2nd and 3rd value are the stop offsets
    the 4th and 5th value are the center coordinates
    example fill3gradient="1.0|0.0|1.0|1.0|0.5" will move the center to the right and increase the radius to 1.0
    (see developer.mozilla.org radial gradient)
Attribute nameTypeDefault valueMinMax
zalignString
zxString0
zyString0
vrscaleString1.0
  • zalign - corresponds to the regular hotspot align attribute (krpano 1.21+)
    but with support for fakeVR and WebVR
  • zx/zy - corresponds to the regular hotspot ox/oy attributes
    supports pixel or percent values
  • vrscale - allows to scale the stage extents
    for WebVR or separately for mobileVR and trueVR
    vrscale="webVR" or
    vrscale="x webVR|y webVR" or
    vrscale="x mobileVR|y mobileVR|trueVR"
    vrscale="x mobileVR|y mobileVR|x trueVR|y trueVR"
    supports numbers only, eg. vrscale="0.9|1"
align positioning for hotspots:
  • in general zradars are placed like any regular krpano layer/hotspot !
    hotspot align was introduced with krpano 1.21+, but it doesn't support WebVR
    zalign allows unified align positioning on desktop and WebVR for hotspots
    this also works on krpano 1.20+ which has no support for hotspot align at all
  • eg. <hotspot name="..." flying="1" align="right" ox="100" />
    works in krpano 1.21+ but only on desktop, not in WebVR
    eg. <hotspot name="..." flying="1" zalign="right" zx="100" />
    works in krpano 1.20+, on desktop and in WebVR
  • zalign is only used with hotspots and if a value is set !
    in this case the hotspots align/ox/oy values are controlled by zalign/zx/zy
  • the vrscale values scale the stage extents in webvr
    the default of "1.25|1.0|0.25|0.25" scales the x direction by 1.25 in mobileVR
    and both directions by 0.25 for trueVR
  • note: for flying hotspots zradar automatically controls hotspot.scaleflying:
    desktop and fakeVR : scaleflying = true
    mobileVR and trueVR : scaleflying = false
  • note: another way to influence the scale in VR is display.hotspotvrflying

Plugin Actions

zradar_resetview(*time, *tweentype)

resets or tweens the view to the initial scene view
the time parameter is optional and defaults to 3 (seconds)
the tweentype parameter is optional and defaults to easeinoutquad

typically used with onclick="zradar_resetview()"

Buy / Order the plugin

This is a commercial plugin - to use it, it must be purchased.
Before you buy, please check the Compatibility / Requirements / Limitations!

Compatibility / Requirements / Limitations
  • krpano 1.20 or newer, html5 only! (Flash is not supported)
    support for all features requires krpano 1.21 or higher
  • canvas mode for webgl hotspots (support for WebVR) requires krpano 1.21 or newer
  • hotspot align positioning (zalign) is experimental and comes without warranty
  • zRadar is tied to your krpano license (needs a registered version of krpano)
License & Withdrawal period

Examples

Radar and Compass examples
Various designs for radar and compass mode.
xml: tour.xml, use right-click to enable fullscreen
CLICK TO VIEW EXAMPLE

Image based compass example
A fully image based compass to the right and a mixed svg / image based compass to the left.
xml: tour.xml, use right-click to enable fullscreen
CLICK TO VIEW EXAMPLE

Hotspots example
Svg and image based examples as hotspots, working in webvr!
xml: tour.xml, use right-click to enable fullscreen
CLICK TO VIEW EXAMPLE

zalign positioning example
align positioning with support for desktop and WebVR (krpano 1.20+)
xml: tour.xml, use right-click to enable fullscreen
CLICK TO VIEW EXAMPLE

Path options example
Circle and ring shape path possibilites in radar and compass mode.
xml: tour.xml, use right-click to enable fullscreen
CLICK TO VIEW EXAMPLE

default pathorder="12345" (bottom to top):
path 5circle or ring shapee.g. center pin
path 4partial circle or ring shaperadar fov / compass north
path 3partial circle or ring shaperadar fov negative / compass south
path 2circle or ring shapee.g. border circle
path 1circle or ring shapee.g. background

Panorama image (licensed under CC BY-SA 3.0)
© The Ocean Agency / XL Catlin Seaview Survey / Christophe Bailhache