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"
};
Solved! Go to Solution.
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);
}
OK I came to the same realization that I was not handling the radio buttons correctly pertaining to retrieving the values and assigning them to variables.
I came up with something similar and then checked back here to see your response
var RadioDistance = document.getElementsByName('DistanceVS'); var Distance_value; for(var i = 0; i < RadioDistance.length; i++){ if(RadioDistance[i].checked){ Distance_value = RadioDistance[i].value; } } alert(Distance_value); vsDistance.distance = (Distance_value);
MY question is....
Am I using the correct parameter to change the observation height....
I clicked on an intersection with a 10 mile distance and 1 meter height
I then clicked on the same intersection with a 10 mile distance and a 1000 meter height.
The result is the same...I find that hard to believe the Viewshed would be the same at 1 meter and 1000 meters.
Am I using the wrong parameter or setting it incorrectly? I want the Viewshed to take into account the increase elevation of an observation point and then adjust the viewshed result.
Say I was standing on a 80 ft tower, what could I see
I will tag yours as the answer.
Jay,
I now see that you are mixing two different things here.
You are using a GP that has set end defined parameters
then you are referencing the
CreateViewshed | API Reference | ArcGIS API for JavaScript 3.23
Analysis dijit which is a whole other thing.
You need to look at the GP rest end point and see what parameters and parameter types it is expecting.
Using this ESRI service...not sure how to access it to see these parameters
know any more that are out there for free?
Jay,
Here is the json for that service and there is no parameter to observer height.
I am not aware of another free service that allows for that level of control.
{
"name": "Viewshed",
"displayName": "Viewshed",
"description": "Calculates the viewshed of a point given a user defined location and viewing distance.",
"category": "",
"helpUrl": "https://sampleserver6.arcgisonline.com/arcgis/rest/directories/arcgisoutput/Elevation/ESRI_Elevation...",
"executionType": "esriExecutionTypeSynchronous",
"parameters": [
{
"name": "Input_Observation_Point",
"dataType": "GPFeatureRecordSetLayer",
"displayName": "Input_Observation_Point",
"description": "The input location from which the viewshed should be calculated.",
"direction": "esriGPParameterDirectionInput",
"defaultValue": {
"displayFieldName": "",
"geometryType": "esriGeometryPoint",
"spatialReference": {
"wkid": 54003,
"latestWkid": 54003
},
"fields": [
{
"name": "OBJECTID",
"type": "esriFieldTypeOID",
"alias": "OBJECTID"
},
{
"name": "OffsetA",
"type": "esriFieldTypeSmallInteger",
"alias": "OffsetA"
}
],
"features": [],
"exceededTransferLimit": false
},
"parameterType": "esriGPParameterTypeRequired",
"category": ""
},
{
"name": "Viewshed_Distance",
"dataType": "GPLinearUnit",
"displayName": "Viewshed_Distance",
"description": " The maximum distance from the input point for which the viewshed should be calculated. The maximum allowed distance is 20000 meters.",
"direction": "esriGPParameterDirectionInput",
"defaultValue": {
"distance": 15000,
"units": "esriMeters"
},
"parameterType": "esriGPParameterTypeRequired",
"category": ""
},
{
"name": "Viewshed_Result",
"dataType": "GPFeatureRecordSetLayer",
"displayName": "Viewshed_Result",
"description": "The resulting viewshed feature class given the user location and maximum distance.",
"direction": "esriGPParameterDirectionOutput",
"defaultValue": {
"displayFieldName": "",
"geometryType": "esriGeometryPolygon",
"spatialReference": {
"wkid": 54003,
"latestWkid": 54003
},
"fields": [
{
"name": "OBJECTID",
"type": "esriFieldTypeOID",
"alias": "OBJECTID"
},
{
"name": "Id",
"type": "esriFieldTypeInteger",
"alias": "Id"
},
{
"name": "grid_code",
"type": "esriFieldTypeInteger",
"alias": "grid_code"
},
{
"name": "Shape_Length",
"type": "esriFieldTypeDouble",
"alias": "Shape_Length"
},
{
"name": "Shape_Area",
"type": "esriFieldTypeDouble",
"alias": "Shape_Area"
}
],
"features": [],
"exceededTransferLimit": false
},
"parameterType": "esriGPParameterTypeRequired",
"category": ""
}
]
}
OK thanks for all your help....much appreciated...