Line of sight (location)

Loading

Code

import QtQuick 2.6
import QtQuick.Controls 1.4
import QtQuick.Dialogs 1.2
import Esri.ArcGISExtras 1.1
import Esri.ArcGISRuntime 100.3

Rectangle {
    clip: true
    width: 800
    height: 600

    property real scaleFactor: System.displayScaleFactor
    property bool calculating: false

    SceneView {
        id: sceneView
        anchors.fill: parent
        focus: true

        Scene {
            id: scene
            BasemapTopographic {}

            Surface {
                ArcGISTiledElevationSource {
                    url: "http://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer"
                }
            }

            onLoadStatusChanged: {
                if (loadStatus === Enums.LoadStatusLoaded) {
                    setInitialViewpoint();
                }
            }
        }

        // Add an Analysis Overlay
        AnalysisOverlay {
            id: analysisOverlay

            // Declare a LineOfSight and set initial observer and target locations
            LocationLineOfSight {
                id: locationLineOfSight
                visible: true
                observerLocation: Point {
                    x: -73.06958032962375
                    y: -49.253112971555446
                    z: 2000
                    spatialReference: SpatialReference.createWgs84()
                }
                targetLocation: Point {
                    x: -73.079266999709162
                    y: -49.300457676730559
                    z: 1312
                    spatialReference: SpatialReference.createWgs84()
                }

                // Configure the LoS color and width
                Component.onCompleted: {
                    LineOfSight.setVisibleColor("cyan");
                    LineOfSight.setObstructedColor("magenta");
                    LineOfSight.setLineWidth(2);
                }
            }
        }

        // Update the target location as you tap the map
        onMouseClicked: locationLineOfSight.targetLocation = sceneView.screenToBaseSurface(mouse.x, mouse.y);
        onMousePressedAndHeld: calculating = true;
        onMouseReleased: calculating = false;
        onMousePositionChanged: {
            if (!calculating)
                return;

            locationLineOfSight.targetLocation = sceneView.screenToBaseSurface(mouse.x, mouse.y);
        }
    }

    function setInitialViewpoint() {
        // Set a viewpoint
        var point = ArcGISRuntimeEnvironment.createObject("Point", {
                                                              x: -73.0815,
                                                              y: -49.3272,
                                                              z: 4059,
                                                              spatialReference: SpatialReference.createWgs84()
                                                          });

        var camera = ArcGISRuntimeEnvironment.createObject("Camera", {
                                                               location: point,
                                                               heading: 11,
                                                               pitch: 62,
                                                               roll: 0
                                                           });

        sceneView.setViewpointCamera(camera);
    }
}


In this topic
  1. Code