LineOfSightViewModel

AMD: require(["esri/widgets/LineOfSight/LineOfSightViewModel"], (LineOfSightViewModel) => { /* code goes here */ });
ESM: import LineOfSightViewModel from "@arcgis/core/widgets/LineOfSight/LineOfSightViewModel";
Class: esri/widgets/LineOfSight/LineOfSightViewModel
Inheritance: LineOfSightViewModel Accessor
Since: ArcGIS API for JavaScript 4.14

Provides the logic for the LineOfSight widget. Use it to create your own widget or to get access to the observer, targets and intersections.

Using the LineOfSightViewModel you can programmatically set the observer and targets for a line of sight analysis.

// instantiate a new view model
const losViewModel = new LineOfSightViewModel({
 view: view
});

// set an observer
losViewModel.observer = new Point({
  latitude: 42.3521,
  longitude: -71.0559,
  z: 147.139
});

// set a target by passing in a LineOfSightTarget to the targets collection
losViewModel.targets = [new LineOfSightTarget({
   location: new Point({
     latitude: 42.352,
     longitude: -71.051,
     z: 0
   })
})];

// when using JavaScript LineOfSightTarget can be autocast
losViewModel.targets = [{
   location: {
     latitude: 42.352,
     longitude: -71.051,
     z: 0
   }
}];

The view model can also be used to control the different states of the analysis: start() enters the creation state where the user can add the observer and targets. stop() enters the created state where the user can't add new targets but they can still move the observer and existing target.

viewModel.start();

The LineOfSightViewModel also allows you to watch for changes (for example when the user moves the observer or the targets) and gives you access to the intersected graphic and the location where the intersection occurred. The observer is just a Point, so you can simply watch the observer property on the view model to know when an observer gets added or moved.

losViewModel.watch("observer", function(value) {
 // do something with the value
});

// watch when a target is added or removed
viewModel.targets.on("change", function(event) {
  // for each target watch when the intersected location changes
  event.added.forEach((target) => {
    target.watch("intersectedLocation", function() {
      // get access to intersected graphic and location
      if (target.intersectedGraphic) {
        // highlight the graphic
        lyrView.highlight(target.intersectedGraphic);
      }
      // get access to intersected location
      console.log(target.intersectedLocation);
    });
  });
});

A target contains information about the location of the target, whether it's visible or not, which graphic it intersects and the location where it intersects that graphic, an integrated mesh or the ground. The LineOfSightTarget class is used to represent a target.

See also:

Constructors

new LineOfSightViewModel(properties)
Parameter:
properties Object
optional

See the properties for a list of all the properties that may be passed into the constructor.

Property Overview

Any properties can be set, retrieved or listened to. See the Working with Properties topic.
Show inherited properties Hide inherited properties
Name Type Summary Class
Stringmore details

The name of the class.

more detailsAccessor
Pointmore details

The observer's viewpoint from which lines of sight will be drawn towards the targets.

more detailsLineOfSightViewModel
Stringmore details

The view model's state.

more detailsLineOfSightViewModel
Collection<LineOfSightTarget>more details

A collection of LineOfSightTarget containing the target location and the analysis results.

more detailsLineOfSightViewModel
SceneViewmore details

The view from which the widget will operate.

more detailsLineOfSightViewModel

Property Details

declaredClass Stringreadonly inherited

The name of the class. The declared class name is formatted as esri.folder.className.

observer Point

The observer's viewpoint from which lines of sight will be drawn towards the targets.

state Stringreadonly

The view model's state.

Value Description
disabled not ready yet
ready ready for analysis
creating observer/target points are being placed
created finished analysis

Possible Values:"disabled"|"ready"|"creating"|"created"

Default Value:disabled

A collection of LineOfSightTarget containing the target location and the analysis results.

view SceneView

The view from which the widget will operate.

Method Overview

Name Return Type Summary Class
more details

Clears the current analysis results.

more detailsLineOfSightViewModel
more details

If stopped, this method continues the line of sight analysis and the user can add more targets.

more detailsLineOfSightViewModel
more details

Starts a new line of sight analysis.

more detailsLineOfSightViewModel
more details

Stops the current line of sight analysis, keeping the results in the view.

more detailsLineOfSightViewModel

Method Details

clear()

Clears the current analysis results. After calling this method, the user can set a new observer and targets.

continue()

If stopped, this method continues the line of sight analysis and the user can add more targets.

start()

Starts a new line of sight analysis.

stop()

Stops the current line of sight analysis, keeping the results in the view. Users can still interact with existing targets and the observer but they can't place new target points.

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.