Skip to content

Instantly share code, notes, and snippets.

@goriliukasbuxton
Created September 30, 2015 23:31
Show Gist options
  • Save goriliukasbuxton/c808786ae45afc86e23a to your computer and use it in GitHub Desktop.
Save goriliukasbuxton/c808786ae45afc86e23a to your computer and use it in GitHub Desktop.
define([
'dojo/dom',
'dojo/_base/declare',
'dojo/_base/lang',
'dojo/on',
'dojo/topic',
'esri/InfoTemplate',
'esri/SpatialReference',
'dojo/_base/array',
'esri/request',
'dojo/topic',
'esri/symbols/jsonUtils',
'esri/InfoTemplate',
'esri/tasks/FeatureSet',
'esri/layers/FeatureLayer',
'esri/tasks/Geoprocessor',
"esri/Color",
"esri/graphic",
"esri/graphicsUtils",
"esri/tasks/LinearUnit",
"esri/symbols/SimpleMarkerSymbol",
"esri/symbols/SimpleLineSymbol",
"esri/symbols/SimpleFillSymbol",
'dojo/domReady!'
], function (dom, declare,
lang,
on,
topic,
InfoTemplate,
SpatialReference, array,
esriRequest, topic, jsonUtils,
InfoTemplate, FeatureSet, FeatureLayer, Geoprocessor, Color,
Graphic, graphicsUtils, LinearUnit, SimpleMarkerSymbol, SimpleLineSymbol, SimpleFillSymbol
) {
return declare([_WidgetBase], {
postCreate: function () {
this.inherited(arguments);
var map = this.map;
gp = new Geoprocessor("http://sampleserver6.arcgisonline.com/ArcGIS/rest/services/Elevation/ESRI_Elevation_World/GPServer/Viewshed");
gp.setOutputSpatialReference({
wkid: 102100
});
map.on("click", computeViewShed);
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.distance = 5;
vsDistance.units = "esriMiles";
var params = {
"Input_Observation_Point": featureSet,
"Viewshed_Distance": vsDistance
};
gp.execute(params, drawViewshed);
}
function drawViewshed(results, messages) {
var polySymbol = new SimpleFillSymbol();
polySymbol.setOutline(new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([0, 0, 0, 0.5]), 1));
polySymbol.setColor(new Color([255, 127, 0, 0.7]));
var features = results[0].value.features;
console.log(features);
topic.publish('reportQuery/populateGrid', features);
for (var f = 0, fl = features.length; f < fl; f++) {
var feature = features[f];
feature.setSymbol(polySymbol);
map.graphics.add(feature);
}
map.setExtent(graphicsUtils.graphicsExtent(map.graphics.graphics), true);
}
}
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment