Jump and zoom to point

Need help in implementing some specific function to your LightningChart Ultimate powered application? Post a question and get code snippets from other LightningChart Ultimate community members.

Moderator: Arction_LasseP

Posts: 5
Joined: Sun May 05, 2019 2:02 pm

Jump and zoom to point

Post by JamesD » Sun May 05, 2019 3:24 pm

I'm displaying a 3D map of the world (SurfaceGridSeries3D) with ranges Z: -180 to +180 and X: -90 to +90 degrees. Y is the elevation above/below sea level.

I also display a globe which allows the user to select a location (Lat/Long in degrees, e.g.. 27.2 Lat , -79.5 Long).

I would like to center the world map display on the selected location and zoom in, but cannot figure what I need to set to do this. Any help would be appreciated.

Attached pictures illustrate before and after clicking a location on the globe.

Click on globe:
ClickWorld.jpg (466.29 KiB) Viewed 4200 times
Result.jpg (301.51 KiB) Viewed 4200 times

Posts: 113
Joined: Wed Mar 27, 2019 1:05 pm

Re: Jump and zoom to point

Post by Arction_LasseP » Mon May 06, 2019 9:25 am

Hello James,

As your map is a SurfaceGridSeries3D, I'd say the easiest way to zoom to the selected location is to move the camera target in code according to the coordinates. You can use chart.View3D.Camera.Target.SetValues(x, y, z) to change the target of the camera (in this case the x- and z-values of the camera target should be changed), and chart.View3D.Camera.ViewDistance to change its distance to achieve the zoom effect. Note that there is also a MinimumViewDistance -property that could affect zooming in some cases so it is best set to a low value.

To zoom back you can either use chart.View3D.ZoomToFit(ZoomArea3D.DataAndLabelsArea), which is available from LightningChart version 8.4 onwards, or use the same SetValues -method as above with some default values.

After this it is just a question of finding the correct calculations to convert the globe coordinates to camera coordinates, for example Latitude equals z and Longitude equals x.

Hope this is helpful.

Posts: 5
Joined: Sun May 05, 2019 2:02 pm

Re: Jump and zoom to point

Post by JamesD » Mon May 06, 2019 8:59 pm

Thanks. That was the tip I needed - convert lat/long to camera position. I was just setting the camera to the lat/long.

Code: Select all

        public void SetPosition(Single Latitude, Single Longitude)
            Single pixsdeglat = _chart.View3D.Dimensions.X / 180f;
            Single pixsdeglong = _chart.View3D.Dimensions.Z / 360f;

            Single Zpos = Longitude * pixsdeglong;
            Single Xpos = -1 * Latitude * pixsdeglat;

            // Set Y to zero to ensure proper position regardless of rotation
            _chart.View3D.Camera.Target.SetValues(Xpos, 0, Zpos);
            _chart.View3D.Camera.ViewDistance = 250;
Here's the final result.