1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"> <title>Query State Info without Map</title>
<script src="https://js.arcgis.com/3.37/"></script> <script> require([ "dojo/dom", "dojo/on", "esri/tasks/query", "esri/tasks/QueryTask", "dojo/domReady!" ], function (dom, on, Query, QueryTask) { var queryTask = new QueryTask("https://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/5");
var query = new Query(); query.returnGeometry = true; query.outFields = [ "SQMI", "STATE_NAME", "STATE_FIPS", "SUB_REGION", "STATE_ABBR", "POP2000", "POP2007", "POP00_SQMI", "POP07_SQMI", "HOUSEHOLDS", "MALES", "FEMALES", "WHITE", "BLACK", "AMERI_ES", "ASIAN", "OTHER", "HISPANIC", "AGE_UNDER5", "AGE_5_17", "AGE_18_21", "AGE_22_29", "AGE_30_39", "AGE_40_49", "AGE_50_64", "AGE_65_UP" ]; query.where = "1=1"; queryTask.execute(query, showResults);
function showResults (results) { let resultCount = results.features.length; for (let i = 0; i < resultCount; i++) { console.log(results.features[i]); } } }); </script> </head> <body> <h2>API参考:https://developers.arcgis.com/javascript/3/jsapi/querytask-amd.html</h2> </body> </html>
|