I've created a script tool, geoprocessing service that takes three input parameters as strings; latitude, longitude and location. Using the GP tool in popup as an example, I'm trying to pass the lat/lon strings in from a click event, and the location name from a user prompt. I've looked at the API reference for GP service parameters, but I'm not sure if I'm getting the syntax right. The only sandbox examples I can find take features or geometries as inputs, but not strings. When I test this, I get the error "TypeError: Cannot set property 'innerHTML' of null" as soon as the map loads.
I'm also thinking I need to make my variables mp, x, and y global so they can be passed in to the different functions.
Here is the section of my script:
map.on("click", function(evt){
var mp = webMercatorUtils.webMercatorToGeographic(evt.mapPoint);
var x = mp.x.toFixed(3);
var y = mp.y.toFixed(3);
map.graphics.clear();
var graphic = new Graphic(evt.mapPoint);
map.graphics.add(graphic);
map.infoWindow.setFeatures([graphic]);
map.infoWindow.setContent(" Longitude: " + x.toString() + " <br>Latitude: " + y.toString());
map.infoWindow.show(evt.mapPoint)
});
var link = domConstruct.create("a",{
"class": "action",
"id": "statsLink",
"innerHTML": "Chart Test",
"href": "javascript: void(0);"
}, query(".actionList", map.infoWindow.domNode)[0]);
on(link, "click",createChart);
domAttr.set(dom.byId("statsLink"), "innerHTML", "Calculating...");
window.gp_chart = new Geoprocessor("http://gis.mymetcon.com/arcgis/rest/services/Chart_Test/GPServer/ChartTest");
function createChart(evt){
var mp = webMercatorUtils.webMercatorToGeographic(evt.mapPoint);
var x = mp.x.toFixed(3);
var y = mp.y.toFixed(3);
var lat,lon,location = new GPString();
lat.value = x.toString();
lon.value = y.toString();
location.value = prompt("Enter Location Name", "Location");
var taskParams = {
"Latitude":lat,
"Longitude":lon,
"Location":location
};
window.gp_chart.execute(taskParams);
};