Sign in

Rotation

You can rotate the map with the mouse right button or with a multi touch two finger combination. But if You need to make Your own interface there is a little how to:

We will now create a slider to rotate the camera.
First, we must create a slider control in the body.

<input id="rotationSlider" type="range" min="0" max="1" step="0.01"></input>

Then in the main function we add the following. This makes it so, that a function is called when we change the value of the slider.

$('#rotationSlider').change(changeRotation);

And now we create the changeRotation function to be called. Wayfinder has a component called orbitController, which is the camera we use to look at the scene. We can manually set the rotation of the camera from code by accessing the orbitController’s rotation with wayfinder.orbitController.rotation.
This rotation has three components: pitch, yaw and roll.

We use the slider value as a multiplier between 0 and 2π and use it to set the yaw of the camera.

function changeRotation() {
    var val = parseFloat($('#rotationSlider').val());
    wayfinder.orbitController.rotation[1] = Math.PI * 2.0 * val;
}

Full example code

<html>
    <body>
        <canvas id="map" width="1024" height="768"></canvas>
        <div style="float:right; position:relative; top:50%; transform:translateY(-50%);">
            <input id="rotationSlider" type="range" min="0" max="1" step="0.01"></input>
        </div>
        <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
        <script src="//cdnjs.cloudflare.com/ajax/libs/jquery-mousewheel/3.1.11/jquery.mousewheel.min.js"></script>
        <script src="http://static.3dwayfinder.com/projects/shared/js/minified/frak-stable.min.js"></script>
        <script src="http://static.3dwayfinder.com/projects/shared/js/minified/Wayfinder3D.min.js"></script>
        <script type="text/javascript">
            var wayfinder = false;
            function changeRotation() {
                var val = parseFloat($('#rotationSlider').val());
                wayfinder.orbitController.rotation[1] = Math.PI * 2.0 * val;
            }
            $(function() {  // Make sure the document is loaded, aka the "main" function
                wayfinder = new Wayfinder3D();
                wayfinder.open();
                $('#rotationSlider').change(changeRotation);
            });
        </script>
    </body>
</html>