首页 > 代码库 > ArcGIS JS之查询一个图层的全部信息

ArcGIS JS之查询一个图层的全部信息

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>QueryTask</title>
    <link rel="stylesheet" type="text/css"
          href="http://10.0.0.92:8002/arcgis_js_api/library/3.17/3.17/dijit/themes/tundra/tundra.css"
            />
    <link rel="stylesheet" type="text/css"
          href="http://10.0.0.92:8002/arcgis_js_api/library/3.17/3.17/esri/css/esri.css"/>
    <script type="text/Javascript" src="http://10.0.0.92:8002/arcgis_js_api/library/3.17/3.17/init.js"></script>

    <style type="text/css">
        .MapClass {
            width: 100%;
            height: 600px;
            border: 1px solid #000;
        }
    </style>
    <script type="text/javascript">

        require(["esri/map",
                    "esri/layers/ArcGISDynamicMapServiceLayer",
                    "dojo/dom",
                    "dojo/on",
                    "esri/tasks/QueryTask",
                    "esri/tasks/query",
                    "esri/symbols/SimpleLineSymbol",
                    "esri/symbols/SimpleFillSymbol",
                    "esri/graphic",
                    "dojo/domReady!"],
                function (Map, ArcGISDynamicMapServiceLayer, dom, on,
                          QueryTask, Query,
                          SimpleLineSymbol, SimpleFillSymbol, Graphic) {
                    //根据div的id属性创建地图
                    var map = new Map("mapDiv");
                    //定义一个动态地图服务
                    var layer = new ArcGISDynamicMapServiceLayer("http://10.0.0.92:6080/arcgis/rest/services/xinyu/MapServer");
                    //将图层添加到地图
                    map.addLayer(layer)
                    //给属性查询按钮添加click事件
                    on(dom.byId("Btn"), "click", function (e) {
                        //定义查询对象
                        var queryTask = new QueryTask("http://10.0.0.92:6080/arcgis/rest/services/xinyu/MapServer/17");
                        //定义查询参数对象
                        var query = new Query();
                        //查询条件,类似于sql语句的where子句
                        query.where = "1 =1";
                        //返回的字段信息:*代表返回全部字段
                        query.outFields = ["*"];
                        //是否返回几何形状
                        query.returnGeometry = true;
                        //执行属性查询
                        queryTask.execute(query, showQueryResult);
                    })
                    //属性查询完成之后,用showQueryResult来处理返回的结果
                    function showQueryResult(queryResult) {

                    }

                });


    </script>
</head>
<body>
<div id="mapDiv" class="MapClass"></div>
<input type="button" value="属性查询" id="Btn"/>

<div id="divShowResult"></div>
</body>
</html>

效果:

技术分享

ArcGIS JS之查询一个图层的全部信息