I'm using this example to draw a polygon which will kick off a GP tool that generates a report based on the area of polygon. I've got it working but I'm having an issue with an interval function. I have another script that makes reports based on clicked countries. When a GP tool link is clicked in the infoWindow, it says "Generating Report..." dot dot dot, etc until the report is finished. I'm trying to use this same method, but this time there is no link to click on. The infoWindow will pop up once the polygon is drawn and the GP tool kicks off. I just can't get this to work. When I run this, the infoWindow pops up but immediately disappears. I can see the text "generating report..." hovering over the map.
function generateReport(evtObj) {
var geometry = evtObj.geometry;
var mp = webMercatorUtils.webMercatorToGeographic(geometry);
var extent = mp.getExtent();
var center = geometry.getCentroid();
var xmin = extent.xmin.toFixed(2); //west_lon
var ymin = extent.ymin.toFixed(2); //south_lat
var xmax = extent.xmax.toFixed(2); //east_lon
var ymax = extent.ymax.toFixed(2); //north_lat
var location = prompt("Please Enter a Region Name","");
var taskParams = {
"region_name": location,
"west_lon": xmin,
"south_lat": ymin,
"east_lon": xmax,
"north_lat": ymax
};
var symbol = new SimpleFillSymbol("none", new SimpleLineSymbol("dashdot", new Color([255,0,0]), 2), new Color([255,255,0,0.25]));
var graphic = new Graphic(geometry,symbol);
map.graphics.add(graphic);
toolbar.deactivate();
var features= [];
features.push(graphic);
gpReport.execute(taskParams);
map.graphics.clear();
map.infoWindow.resize(256,256);
map.infoWindow.show(center,map.getInfoWindowAnchor(center));
map.infoWindow.setTitle("Forecast Report");
map.infoWindow.setContent("Forecast Analysis Report")
var dots = window.setInterval( function() {
var wait = map.infoWindow.domNode,
msg = "Generating Report",
msgLen = msg.length;
if (wait.innerHTML.length > (msgLen + 2))
wait.innerHTML = msg;
else
wait.innerHTML += ".";
}, 400);
}
In my other script var wait = document.getElementById("reportLink"); I've tried giving the infoWindow div an ID, but that doesn't work. I've also tried to use map.infoWindow.innerHTML;
Solved! Go to Solution.
Lloyd,
Ahh, I did not catch that.
map.infoWindow.resize(256,256);
map.infoWindow.show(center,map.getInfoWindowAnchor(center));
map.infoWindow.setTitle("Forecast Report");
map.infoWindow.setContent("Forecast Analysis Report")
var msg = "Generating Report";
window.setInterval( function() {
if (msg === "Generating Report..."){
msg = "Generating Report";
}
map.infoWindow.setContent(msg);
msg += ".";
}, 400);
Lloyd,
It would be:
map.infoWindow.resize(256,256);
map.infoWindow.show(center,map.getInfoWindowAnchor(center));
map.infoWindow.setTitle("Forecast Report");
map.infoWindow.setContent("Forecast Analysis Report")
var dots = window.setInterval( function() {
var wait = map.infoWindow.domNode,
msg = "Generating Report",
msgLen = msg.length;
if (wait.innerHTML.length > (msgLen + 2))
map.infoWindow.setContent = msg;
else
msg += ".";
map.infoWindow.setContent msg;
}, 400);
}
There is a syntax error here on the last line. If I change it to map.infoWindow.setContent(msg); It just stays on "Generating Report" with no dots.
Lloyd,
After taking another look I would recommend trying this code then:
map.infoWindow.resize(256,256);
map.infoWindow.show(center,map.getInfoWindowAnchor(center));
map.infoWindow.setTitle("Forecast Report");
map.infoWindow.setContent("Forecast Analysis Report")
var msg = "Generating Report";
window.setInterval( function() {
map.infoWindow.setContent = msg;
msg += ".";
}, 400);
OK. It just stays on "Forecast Analysis Report."
Lloyd,
I see the mistake:
map.infoWindow.resize(256,256);
map.infoWindow.show(center,map.getInfoWindowAnchor(center));
map.infoWindow.setTitle("Forecast Report");
map.infoWindow.setContent("Forecast Analysis Report")
var msg = "Generating Report";
window.setInterval( function() {
map.infoWindow.setContent(msg);
msg += ".";
}, 400);
Ah, thanks. This works, but it adds dots forever. the Original version went dot dot dot, dot dot dot, etc.
Lloyd,
Ahh, I did not catch that.
map.infoWindow.resize(256,256);
map.infoWindow.show(center,map.getInfoWindowAnchor(center));
map.infoWindow.setTitle("Forecast Report");
map.infoWindow.setContent("Forecast Analysis Report")
var msg = "Generating Report";
window.setInterval( function() {
if (msg === "Generating Report..."){
msg = "Generating Report";
}
map.infoWindow.setContent(msg);
msg += ".";
}, 400);
Perfect, thanks Robert!