how to display geometry in Camera in SceneView

974
4
Jump to solution
05-24-2018 10:32 AM
MarekFlorianczyk
New Contributor III

Hi,

I have switched to SceneView and Camera, after I solve route I would like to changte camera view to show whole route. With MapView I could set geometry for view with scene I basically move the camera when navigating, but how to create view for camera when route.routeGeometry is all I have.

Best,

Marek

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
LucasDanzinger
Esri Frequent Contributor

Marek-

To show the full route, the best thing to do would be to not use Camera, and just use the GeoView.setViewpoint function and pass in a ViewpointExtent (which you could create from the route geometry's full extent:

GeoView QML Type | ArcGIS for Developers 

ViewpointExtent QML Type | ArcGIS for Developers 

View solution in original post

4 Replies
LucasDanzinger
Esri Frequent Contributor

With the camera, you'll have to set a few additional things:

- location - set this to the center of your route geometry (or optionally to some other vertex along the route). You can get the center by taking the geometry from the route and getting the Envelope (.extent), then getting the center Point (.center)

- pitch - this is your vertical angle you want the camera. 0 will look straight down. 90 will look straight across.

- heading - this is the heading direction you want the camera

- distance - this is how far you want the camera to be from the specified location.

- roll - this is the side to side angle. This is less commonly used.

0 Kudos
MarekFlorianczyk
New Contributor III

Hi

Most of these I already use. Since Camera object is immutable I create Camera each time gpsCoords arrive.

This is short version of my function, currFlatPoint is for currPositionGraphic marker and for distance calculation, currPoint is for camera with addidtional z coordinate

function gpsCoord(latitude,longitude,direction,speed) {
    if(!currPoint && sceneView.drawStatus!=Enums.DrawStatusCompleted)
        return;
    currPoint=ArcGISRuntimeEnvironment.createObject("Point", {x:longitude, y:latitude,z:point_z[curr_z_idx], spatialReference: mapPage.spat_ref});
    currFlatPoint=ArcGISRuntimeEnvironment.createObject("Point", {x:longitude, y:latitude, spatialReference: mapPage.spat_ref});
    if(speed>=2) {
        mapPage.heading=direction //dont rotate on low speed
    }
    camera=ArcGISRuntimeEnvironment.createObject("Camera",{pitch:pitch,roll:0,heading:mapPage.heading,location:currPoint,distance:camera_z[curr_z_idx]});
    sceneView.setViewpointCameraAndSeconds(camera,cam_speed)
}

I'm changing variable curr_z_idx depending on how far from the next maneuver, I want camera to be closer when approaching turn (or any maneuver). By trial and error I came up with these values for currPoint z variable and Camera distance

property var point_z:[150,100,70,30]
property var camera_z:[450,350,250,150]
property int curr_z_idx:0_

So, to show whole route I need to get center point of the route, put camera with 0 pitch and some heading and some "distance" value, distance must be large enought to show whole route. I'm not sure how to calculate distance, I could use some trigonometric functions, had I known camera angle of view, but I don't

As You can see there is also an issue with tiles, with MapView they refresh much faster.

Best,

Marek

0 Kudos
LucasDanzinger
Esri Frequent Contributor

Marek-

To show the full route, the best thing to do would be to not use Camera, and just use the GeoView.setViewpoint function and pass in a ViewpointExtent (which you could create from the route geometry's full extent:

GeoView QML Type | ArcGIS for Developers 

ViewpointExtent QML Type | ArcGIS for Developers 

MarekFlorianczyk
New Contributor III

Lucas,

Thanks

var vp= ArcGISRuntimeEnvironment.createObject("ViewpointExtent", {extent: route.routeGeometry.extent});
sceneView.setViewpoint(vp);

Best,
Marek
0 Kudos