Viewshed observer Height

1310
15
Jump to solution
12-20-2017 09:07 AM
jaykapalczynski
Frequent Contributor

Using this: CreateViewshed | API Reference | ArcGIS API for JavaScript 3.23 

I think I am defining the parameters for Height incorrectly and cant seem to find them in the documentation

vsHeight.height

"observerHeight": vsHeight,
"observerHeightUnits": "feet"

Trying this:

<input type="radio" name="DistanceVS" value="1" checked="checked">1 Mile</input>
<input type="radio" name="HeightVS" value="1" checked="checked">1 Meter</input>


var radios = document.getElementsByName('DistanceVS');
var w = parseInt(radios);
vsDistance.distance = (w);

var height = document.getElementsByName('HeightVS');
var h = parseInt(height);
vsHeight.height = (h);
            
vsDistance.units = "esriMiles";
var params = {
    "Input_Observation_Point": featureSet,
    "Viewshed_Distance": vsDistance,
    "observerHeight": vsHeight,
    "observerHeightUnits": "feet"
};‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Jay,

   So if you are trying to get the value of a selected radio in a group of radios then this is what you need:

HTML

<div>
   <input type="radio" name="DistanceVS" value="1" checked="checked">1 Mile</input>
   <input type="radio" name="DistanceVS" value="3">3 Miles</input>
   <input type="radio" name="DistanceVS" value="5">5 Miles</input>
   <input type="radio" name="DistanceVS" value="10">10 Miles</input>
</div>

<div>
   <div>
      <input type="radio" name="HeightVS" value="1" checked="checked">1 Meter</input>
      <input type="radio" name="HeightVS" value="3">3 Meters</input>                                  
      <input type="radio" name="HeightVS" value="5">5 Meters</input>
      <input type="radio" name="HeightVS" value="10">10 Meters</input>
   </div>
</div>

JS

function computeViewShed(evt) {
   map.graphics.clear();
   var pointSymbol = new SimpleMarkerSymbol();
   pointSymbol.setSize(14);
   pointSymbol.setOutline(new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([255, 0, 0]), 1));
   pointSymbol.setColor(new Color([0, 255, 0, 0.25]));

   var graphic = new Graphic(evt.mapPoint, pointSymbol);
   map.graphics.add(graphic);

   var features = [];
   features.push(graphic);
   var featureSet = new FeatureSet();
   featureSet.features = features;
   var vsDistance = new LinearUnit();
   vsDistance.units = "esriMiles";
   var vsHeight = new LinearUnit();
   vsHeight.units = "esriMeters";

   var distInt, i;
   var distVS = document.getElementsByName('DistanceVS');
   for (i = 0; i < distVS.length; ++i) {
     if (distVS[i].checked) {
       distInt= parseInt(distVS[i].value);
     }
   }
   alert(distInt);
   vsDistance.distance = (distInt);

   var heightInt;
   var heightVS = document.getElementsByName('HeightVS');
   for (i = 0; i < heightVS.length; ++i) {
     if (heightVS[i].checked) {
       heightInt= parseInt(heightVS.value);
     }
   }
   alert(heightInt);
   vsHeight.distance = (heightInt);
         
   vsDistance.units = "esriMiles";
   vsHeight.units = "esriMeters";
   var params = {
      "Input_Observation_Point": featureSet,
      "Viewshed_Distance": vsDistance,
      "observerHeight": vsHeight
  };
  gp.execute(params, drawViewshed, errorViewShed);
}
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

View solution in original post

0 Kudos
15 Replies
jaykapalczynski
Frequent Contributor

I think I got it working....Can someone pass their eyes over this and see if they see anything out of place...

//SNIP

var vsDistance = new LinearUnit();
var vsHeight = new LinearUnit();
             
       
var radiodistance = document.getElementsByName('DistanceVS');
var w = parseInt(radiodistance);
vsDistance.distance = (w);

var radioheight = document.getElementsByName('HeightVS');
var h = parseInt(radioheight);
vsHeight.distance = (h);

               
vsDistance.units = "esriMiles";
vsHeight.units = "esrifeet";
          
var params = {
    "Input_Observation_Point": featureSet,
    "Viewshed_Distance": vsDistance,
    "observerHeight": vsHeight
};
 gp.execute(params, drawViewshed, errorViewShed);
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
jaykapalczynski
Frequent Contributor

No I dont think I have it...seems that the user defined input is not being used in the Viewshed.  

I changed them and ran from the same point and get the same result no mater what distance I choose or what height I try and push to the variables. hmmmm

Doesnt seem like I am getting the value of the radio buttons to the variable and then to the Params

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Looks good to me.

0 Kudos
jaykapalczynski
Frequent Contributor

If I add an alert on the 

var radiodistance = document.getElementsByName('DistanceVS');
var w = parseInt(radiodistance);
alert(w);

I get

0 Kudos
jaykapalczynski
Frequent Contributor

If I alert here

var radiodistance = document.getElementsByName('DistanceVS');
alert(radiodistance);

if gives me:

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Jay,

   So the issue is you are returning the dom element and not the value:

var height = document.getElementsByName('HeightVS').value;
0 Kudos
jaykapalczynski
Frequent Contributor

I get the below response for each of the alerts below.

undefined

NaN

var radiodistance = document.getElementsByName('DistanceVS').value;
alert(radiodistance);
var w = parseInt(radiodistance);
alert(w);
vsDistance.distance = (w);

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Jay,

   Well I really needed to look over your code better... You are using 

var radiodistance = document.getElementsByName('DistanceVS')

document.getElementsByName returns an array/collection of node that have that name. You can use this but the more standard way is to give you dom elements an id and then use document.getElementById('DistanceVS').value.

<input type="radio" id="DistanceVS" value="1" checked="checked">1 Mile</input>
<input type="radio" id="HeightVS" value="1" checked="checked">1 Meter</input>


var radios = dom.byId('DistanceVS').value;
var w = parseInt(radios);
vsDistance.distance = (w);

var height = dom.byId('HeightVS').value;
var h = parseInt(height);
vsHeight.height = (h);
            
vsDistance.units = "esriMiles";
var params = {
    "Input_Observation_Point": featureSet,
    "Viewshed_Distance": vsDistance,
    "observerHeight": vsHeight,
    "observerHeightUnits": "feet"
};
0 Kudos
jaykapalczynski
Frequent Contributor
  1. I am trying to give the user a selection of radio buttons to choose the distsance
  2. Grab that value in JS and write it to a variable
  3. Use that variable in as a parameter for Viewshed Distance and Viewshed Observer Height

Not sure why I cant get the radio button variable.  Not sure if I use ID or NAME...I dont think I can use ID with a radio button selection

<div>
   <input type="radio" id="DistanceVS" name="DistanceVS" value="1" checked="checked">1 Mile</input>
   <input type="radio" id="DistanceVS" name="DistanceVS" value="3" >3 Miles</input>
   <input type="radio" id="DistanceVS" name="DistanceVS" value="5" >5 Miles</input>
   <input type="radio" id="DistanceVS" name="DistanceVS" value="10" >10 Miles</input>
</div>

<div>
   <div>
      <input type="radio" name="HeightVS" value="1" checked="checked">1 Meter</input>
      <input type="radio" name="HeightVS" value="3" >3 Meters</input>
   </div>
   <div>                                   
      <input type="radio" name="HeightVS" value="5" >5 Meters</input>
      <input type="radio" name="HeightVS" value="10" >10 Meters</input>
   </div>
</div>

‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

function computeViewShed(evt) {
   map.graphics.clear();
   var pointSymbol = new SimpleMarkerSymbol();
   pointSymbol.setSize(14);
   pointSymbol.setOutline(new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([255, 0, 0]), 1));
   pointSymbol.setColor(new Color([0, 255, 0, 0.25]));

   var graphic = new Graphic(evt.mapPoint, pointSymbol);
   map.graphics.add(graphic);

   var features = [];
   features.push(graphic);
   var featureSet = new FeatureSet();
   featureSet.features = features;
   var vsDistance = new LinearUnit();
   var vsHeight = new LinearUnit();



// TRYING TO GRAB THE VALUE AND ASSIGN TO VARIABLE AND ALERT
   var radiodistance = document.getElementsByName('DistanceVS').value;
// OR
   var radiodistance = dom.byId('DistanceVS').value;

   alert(radiodistance);
   var w = parseInt(radiodistance);
   alert(w);
   vsDistance.distance = (w);


   // SAME AS THE ABOVE DISTANCE VARIABLE
   var radioheight = document.getElementsByName('HeightVS').value;
   var h = parseInt(radioheight);
   vsHeight.distance = (h);
     

          
   vsDistance.units = "esriMiles";
   vsHeight.units = "esriMeters";
   var params = {
      "Input_Observation_Point": featureSet,
      "Viewshed_Distance": vsDistance,
      "observerHeight": vsHeight
};
  gp.execute(params, drawViewshed, errorViewShed);
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos