Select to view content in your preferred language

GP service

6098
32
Jump to solution
08-19-2015 08:37 AM
TerryGustafson
Frequent Contributor

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
Frequent Contributor

Can I add a create graphic and zoom to it within the _onlatlongClicked function? Or do I need to create a separate function to perform that?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Terry,

   Why would you need to?.. The executeGP function does this and the _onlatlongClicked calls the executeGP function.

0 Kudos
TerryGustafson
Frequent Contributor

I was wanting to have it so that if they clicked on the map the graphic is created (which it does now) and if the user enters the coordinates into the textbox and clicks get location the map zooms to the entered coordinate.. I’m working on the return table for the information returned from the GP service. I would like the table to return something that says no offset information available if the coordinates they entered do not land within the 50 feet of the route but stumped on that..

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Terry,

   Since the executeGP creates the graphic and adds it to the map for you then all you need to do is add code to the _onlatlongClicked for zooming the map to the LocPoint. As far as the return table question that should be as simple as checking the length of the result features array and if it is 0 then display your message.

TerryGustafson
Frequent Contributor

I thought this would work but I get a “Object doesn’t support this action” error..

_onlatlongClicked: function (evt) {

this.map.graphics.clear();

var pointSymbol = new SimpleMarkerSymbol();

pointSymbol.setSize(14);

pointSymbol.setOutline(new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color(), 1));

pointSymbol.setColor(new Color());

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

this.map.graphics.add(graphic);

var point = ;

var locPoint = new LocPoint();

locPoint.point = point;

var Lat = this.LatTextBox.value,

Long = this.LongTextBox.value,

LocPoint = new Point(Long, Lat),

mp = {

mapPoint: LocPoint

};

this.executeGP(mp);

},

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Terry,

   You really have to study the code and you will see as I post in both of my previous responses there is no need for you to add the graphic to the map in the _onlatlongClicked function as this is done for you when the _onlatlongClicked function calls this.executeGP(mp); (look at the executeGP function and you will see the code for adding the graphic to the map).

TerryGustafson
Frequent Contributor

Ok thank you, I get it now.. I just needed to add the following so that it would zoom to the selected location.

this.maxZoom = this.map.getMaxZoom();

this.map.centerAndZoom(graphic.geometry, this.maxZoom - 1);

Thank you..

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Terry,

    What ever you posted did not come through.

0 Kudos
TerryGustafson
Frequent Contributor

Robert,

I was able to return my array but now see the importance of CSS..  What would be a better way to bring in the results other then a div with an id?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Terry,

   You will need to use the GeometryService to project the coords you get from the user to web mercator so that they can be added to the map.