GP service

5395
32
Jump to solution
08-19-2015 08:37 AM
TerryGustafson
Occasional Contributor II

I'm trying to use a gp service to return a point and values from a gp service and can't seem to get the define point to return.  Can anyone help?

<!DOCTYPE html>
<html>
 
<head>
   
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
   
<!--The viewport meta tag is used to improve the presentation and behavior of the samples
     
on iOS devices-->
   
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
   
<title>Geometry Service: Relation</title>

   
<link rel="stylesheet" href="http://js.arcgis.com/3.14/esri/css/esri.css">

   
<style>
     
html, body, #mapDiv {
       
height: 100%;
       
margin: 0;
       
padding: 0;
       
width: 100%;
     
}
     
#info {
        bottom: 20px;
       
color: #444;
       
height: auto;
       
font-family: arial;
       
left: 20px;
       
margin: 5px;
       
padding: 10px;
       
position: absolute;
       
text-align: left;
       
width: 200px;
       
z-index: 40;
     
}
     
.label {
       
display: inline-block;
       
width: 4em;
     
}
   
</style>
  
   
<script src="http://js.arcgis.com/3.14compact/"></script>

   
<script>
   
     
   
var map, gp;
   
     
require([ "dojo/dom",
               
"dojo/_base/array",
               
"dojo/promise/all",
               
"dojo/json",
               
"esri/map",
               
"esri/domUtils",
               
"esri/graphic",
               
"esri/graphicsUtils",
               
"esri/geometry/Point",
               
"esri/SpatialReference",
               
"esri/tasks/GeometryService",
               
"esri/tasks/Geoprocessor",
               
"esri/tasks/FeatureSet",
               
"esri/tasks/RelationParameters",
               
"esri/Color", "esri/symbols/SimpleLineSymbol",
               
"esri/symbols/SimpleMarkerSymbol",
               
"esri/symbols/SimpleFillSymbol",
               
"esri/config",
               
"esri/request", "dojo/domReady!"
               
],
               
       
function(
       
dom, array, all, JSON,
       
Map, domUtils, Graphic, graphicsUtils,
       
Point, SpatialReference, GeometryService, Geoprocessor,
       
FeatureSet, RelationParameters,
       
Color, SimpleLineSymbol,
       
SimpleMarkerSymbol, SimpleFillSymbol,
       
config, Request) {
       
       
       
var geometryService, geometries, baseGraphics;

       
map = new esri.Map("mapDiv", {
         
basemap: "topo",
         
center: [-111.185, 46.052],
         
zoom: 15
       
});
       
       
map.on("click", executeGP);
       
       
gp = new Geoprocessor("http://app.mdt.mt.gov/arcgis/rest/services/LRS/LocateFeaturesOnDCandRM/GPServer/Locate%20features%20...");
       
       
gp.setOutputSpatialReference({
           
wkid: 102100       
       
       
})
       
     
      
       
       
function executeGP(run){
           
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(run.mapPoint, pointSymbol);
           
map.graphics.add(graphic);
           
           
var features = [];
           
           
var featureSet = new FeatureSet();
           
featureSet.features = features;
           
           
var params = {
           
               
"f": json,
               
"outSR" : 102100,
               
"City_Centers" : featureSet,
               
"geometryType" : esriGeometryPoint,
               
"features" : [{        
               
"geometry" : {
               
"x": -12180856.426452411,
               
"y":  5952832.259593694,
               
"spatialReference": {
               
"wkid": 102100
                                   
}
                            
}     
                            
}],
               
               
"sr": {
                   
"wkid": 102100
               
}
                   
               
"Search_Radius": {
                   
"distance": 50,
                   
"units": esriFeet
               
}
               
               
"Keep_only_closest_route_location": false
               
//'distance_field': true,
                //'zero_length_events': true,
                //'in_fields': true,
                //'m_direction_offsetting': true
            };
           
           
gp.submitJob(params, processGP);
           
           
function processGP(jobInfo){   
           
gp.getResultData(jobInfo.jobId, "LRM_DC_RM_MI1", renderResult);
           
           
};
           
           
function renderResult(result, message){
           
alert(result);
           
};
           
   
</script>

 
</head>

 
<body class="claro">
   
<div id="mapDiv"></div>
   
<div id="LatLng" >
       
Enter the lat/long:
       
   
</div>
 
</body>
</html>

0 Kudos
32 Replies
TerryGustafson
Occasional Contributor II

ok I will try and download them and see what I can find. Thank you..

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Terry,

  Here is a starting point for you. I have taken your code and re-coded using WAB widget coding conventions and added some code to add and remove the map click event based on if the widget is open or not. I personally would not use a map click event I would look at using the jimu drawbox dijit. I still don't know where to click in the map to get some actual results so I can help much there, but the GP is firing and running fine.

TerryGustafson
Occasional Contributor II

Thank you so much!!  I can start to see the logic now.  :I was just starting with the map click event, my goal is to be able to have the user enter a set of coordinates and lick a button and be taken to that location and show them the return value for the route in the output tab.  I would guess I would use dojogrid for that but need to learn that as well.  Which leads me to apologize for not telling you the return data is offset information.  So if you were to click on any route it returns our corridor route and offset.  So my goal is to get this working for Lat/Long and then for the other two tabs.  On a side not I did install the plugins for brackets like you said I should do.  I have read the getting started with brackets, seems like it will be a powerful tool when I learn how to use it.  So do the plugins automatically run when they are installed?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Terry,

    The interactive linter runs all the time automatically. The beautifier has to be run manually from the edit menu or you can set it to beautify on save.

TerryGustafson
Occasional Contributor II

Robert,

I added a couple of textbox's that the user will enter the coordinates in.  If I want to align those textbox's do I perform that in the html or the css?  I see the style="width: 10em;"

<input id="LatTextBox" data-dojo-type="dijit/form/TextBox" value="this is lat value" placeholder="47.063616320200374" data-dojo-attach-point="LatTextBox" data-dojo-props="intermediateChanges:true, "style="width: 10em;" >

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Terry,

   My preference is to add styling like that to the css so you only have to hunt for it in one file latter when you want to make a change.

0 Kudos
TerryGustafson
Occasional Contributor II

I can’t figure out what class to call to make the position of the textbox to be centered and aligned..

Is it?

dijit dijitReset dijitInline dijitLeft dijitTextBox

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Terry,

   You should try not to mess with the dojo dijit css. Instead wrap the textbox in a div and then work with the div in css.

TerryGustafson
Occasional Contributor II

Ok, so I made some changes to the wdget.js file. I was hoping you had a minute to look at it. I know I’m missing something. I was thinking the getPointValues function would get the coordinated from the textbox. Then when latlong was clicked it would plot the point and run the evt function. I was also hoping you could explain the JSLint Problems that are listed. I show 43 errors. But some of them don’t make sense to me. Like the first one says “ Expected 'dojo/_base/declare' at column 5, not column 3. 'dojo/_base/declare', “ there are actually several like that. Do I disregard these?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Terry,

  1. Line 90 you have function in front of the function name and this is an issue. (look at your other functions convention).
  2. Line 97 of the Widget.js has a semicolon at the end and it should be a comma.
  3. Actually the whole getPointValues function is not needed or used.
  4. You do not need any ids on your html elements in the html page and you get access to the elements in your html by using data-dojo-attach-point's
  5. I re-worked your first tab using css and inline styles instead of all your br's and &nbsp's, so that you could see how that is done.
0 Kudos