属性查询图形FindTask

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>属性查询图形</title>
    <script src="../js/jsConfigVS.js"></script>
    <link rel="stylesheet" type="text/css" href="../arcgis_js_api/library/3.17/esri/css/esri.css" />
    <link rel="stylesheet" type="text/css" href="../arcgis_js_api/library/3.17/dijit/themes/claro/claro.css">
    <link rel="stylesheet" href="Layout.css" />
    <script src="../arcgis_js_api/library/3.17/init.js" type="text/javascript"></script>
    <style type="text/css">
        html, body {
            height: 100%;
            width: 100%;
            margin: 0; 
            padding: 0;
        }
        body {
        background-color:#777;
        overflow:hidden;
        font-family: "Trebuchet MS";
        font-size:9pt;
        }
        .dijitAccordionTitle {
            background-color:#777;
        overflow:hidden;
        font-family: "Trebuchet MS";
        font-size:12pt;
        }
        #header {
        background-color:#444;
        color:white;
        font-size:20pt;
        text-align:center;
        font-weight:bold;
        }
        #attributionText {
        background-color:whitesmoke;
        color:black;
        font-size:7pt;
        text-align:left;
        margin:5px;
        }
        #divNeighborhoodName {
        background-color:white;
        color:black;
        font-size:16pt;
        text-align:center;
        font-weight:bold;
        }
        #footer {
        background-color:#444;
        color:yellow;
        font-size:10pt;
        text-align:center;
        }
    </style>
    <script>
        var map;
        
        require(["dojo/parser",
            "dojo/on",
            "dojo/dom",
            "esri/basemaps",
            "esri/map",
            "esri/geometry/Extent",
            "esri/SpatialReference",
            "esri/layers/ArcGISTiledMapServiceLayer",
            "esri/layers/ArcGISDynamicMapServiceLayer",
            "esri/geometry/Point",
            "esri/tasks/FindTask",
            "esri/tasks/FindParameters",
            "esri/InfoTemplate",
            "esri/symbols/SimpleMarkerSymbol",
            "esri/symbols/SimpleLineSymbol",
            "esri/symbols/SimpleFillSymbol",
            "esri/Color",
            "dijit/layout/BorderContainer",
            "dijit/layout/ContentPane",
            "dojo/domReady!"],
            function (
                parser,
                on,
                dom,
                esriBasemaps,
                Map,
                Extent,
                SpatialReference,
                ArcGISTiledMapServiceLayer,
                ArcGISDynamicMapServiceLayer,
                Point,
                FindTask,
                FindParameters,
                InfoTemplate,
                SimpleMarkerSymbol,
                SimpleLineSymbol,
                SimpleFillSymbol,
                Color)
            {
                parser.parse();
                esriBasemaps.XjOnline = {
                    baseMapLayers: [{ url: xjuConfig.vectorLayers }],
                    thumbnailUrl: "images/topo.jpg",
                    title: "矢量图"
                };
                esriBasemaps.XjRaster = {
                    baseMapLayers: [{ url: xjuConfig.imageLayers }],
                    thumbnailUrl: "images/satellite.jpg",
                    title: "卫星图"
                };
                var startExtent = new Extent({
                    "xmin": 73.441277,
                    "ymin": 34.334934,
                    "xmax": 96.388373,
                    "ymax": 49.178574,
                    "spatialReference": { "wkid": 4326 }
                });
                //加载底图       
                map = new Map("mapDiv", {
                    extent: startExtent,
                    zoom: 0,
                    basemap: "XjRaster",
                    sliderStyle: "large",
                    logo: false
                });
                // 实例化FindTask        
                var findTask = new FindTask("http://localhost:6080/arcgis/rest/services/BaseMap/XjOnline/MapServer");
                // FindTask的参数
                var findParams = new FindParameters();
                // 返回Geometry
                findParams.returnGeometry = true;
                // 查询的图层id
                findParams.layerIds = [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, 33, 34, 35, 36, 37, 46];
                //findParams.layerIds = [27,28,29,30,31,33,34,35,36,37,46];
                // 查询字段
                findParams.searchFields = ["NAME"];
                var ptSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_DIAMOND, 10, new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([255, 0, 0]), 1), new Color([0, 255, 0, 0.25]));
                var lineSymbol = new SimpleLineSymbol(SimpleLineSymbol.STYLE_DASH, new Color([255, 0, 0]), 1);
                on(dom.byId("findBtn"), "click", function () {
                    execute(dom.byId(‘searchText‘).value);
                });
                // 根据输入的关键字进行findTask操作
                function execute(searchText) {
                    findParams.searchText = searchText;
                    findTask.execute(findParams, showResults);
                }
                // 显示findTask的结果
                function showResults(results) {
                    // 清除上一次的高亮显示
                    map.graphics.clear();
                    //输出统计结果值
                    dom.byId(‘totalSearchNum‘).innerHTML = results.length;
                    var innerHtml = "";
                    var symbol;
                    for (var i = 0; i < results.length; i++) {
                        var curFeature = results[i];
                        var graphic = curFeature.feature;
                        var infoTemplate = null;
                        // 根据类型设置显示样式
                        switch (graphic.geometry.type) {
                            case "point":
                                symbol = ptSymbol;
                                infoTemplate = new InfoTemplate("${NAME}", "${*}");
                                break;
                            case "polyline":
                                symbol = lineSymbol;
                                infoTemplate = new InfoTemplate("${NAME}", "${*}");
                                break;                            
                        }
                        // 设置显示样式
                        graphic.setSymbol(symbol);
                        graphic.setInfoTemplate(infoTemplate);
                        // 添加到graphics进行高亮显示
                        map.graphics.add(graphic);
                        innerHtml += "<a href=\"javascript:positionFeature(" + graphic.attributes.OBJECTID;
                        if (graphic.attributes.Name) {
                            innerHtml += ",\‘" + graphic.attributes.Name + "\‘)\">" + graphic.attributes.Name + "</a><br>";
                        }
                        else {
                            innerHtml += ",\‘" + graphic.attributes.NAME + "\‘)\">" + graphic.attributes.NAME + "</a><br>";
                        }                        
                    }
                    dom.byId("contentsContainer").innerHTML = innerHtml;
                    
                }
                window.positionFeature = function (id, name) {                    
                    var sGrapphic;
                    //遍历地图的图形查找FID和点击行的FID相同的图形
                    for (var i = 0; i < map.graphics.graphics.length; i++) {
                        var cGrapphic = map.graphics.graphics[i];
                        var sGName = "";
                        if (cGrapphic.attributes.NAME) {
                            sGName = cGrapphic.attributes.NAME;
                        }
                        else {
                            sGName = cGrapphic.attributes.Name;
                        }
                        if ((cGrapphic.attributes) && cGrapphic.attributes.OBJECTID == id && sGName == name) {
                            sGrapphic = cGrapphic;
                            break;
                        }
                    }              
                    // 当点击的名称对应的图形为点类型时进行地图中心定位显示
                    if (sGrapphic.geometry.type == "point") {
                        var cPoint = new Point(sGrapphic.geometry.x, sGrapphic.geometry.y);
                        var p = map.toScreen(cPoint);
                        var iw = map.infoWindow;
                        iw.setTitle(sGrapphic.getTitle());
                        iw.setContent(sGrapphic.getContent());
                        iw.show(p, map.getInfoWindowAnchor(p));
                        map.centerAt(cPoint);
                                              
                    }                        
                    else {                        
                        var cPoint = new Point(sGrapphic.geometry.paths[0][0][0], sGrapphic.geometry.paths[0][0][1]);
                        var p = map.toScreen(cPoint);
                        var iw = map.infoWindow;
                        iw.setTitle(sGrapphic.getTitle());
                        iw.setContent(sGrapphic.getContent());
                        iw.show(p, map.getInfoWindowAnchor(p));
                        map.centerAt(cPoint);
                    }
                };
            });
    </script>
</head>
<body class="claro">
    <div id="mainWindow" data-dojo-type="dijit/layout/BorderContainer" data-dojo-props="design:‘headline‘,gutters:false" style="width:100%; height:100%;">
      <!--标题区域-->
      <div id="header" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:‘top‘" style="height:50px;">
          属性查询图形
      </div>
      
      <!--中间地图区域-->
      <div id="mapDiv" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:‘center‘" style="margin:5px;">
      </div>
      <!--右边为属性查询与结果显示区域-->
      <div data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:‘right‘" style="width:35%;margin:5px;background-color:whitesmoke;">     
          输入查询文本
          <input id="searchText" value="胜利路" type="text" />
          <input id="findBtn" type="button" value="查 找" />
          <div>查询到的结果数为:<span id="totalSearchNum" style="font-weight:800;">0</span></div>
          <div id="contentsContainer"></div>
      </div>        
    </div>
</body>
</html>

结果:

时间: 2024-10-18 04:16:06

属性查询图形FindTask的相关文章

openlayers实现wfs属性查询和空间查询

概述: 一直在寻求openlayers中wfs加载和属性查询的相关操作,功夫不负有心人,蓦然回首,那人却在灯火阑珊处,找到了这篇博文:http://blog.csdn.net/longshengguoji/article/details/39377931,试了下,在IE8中正常运行,但是在chrom中涉及到跨域的问题,待后期接解决吧.本文讲解如何通过wfs实现属性的查询与展示. 效果: 初始化状态 属性查询结果 空间查询结果 数据表: 关键代码: 添加wfs图层 wfs = new OpenLa

Arcgis for Js之featurelayer实现空间查询和属性查询

空间查询和属性查询是常用的两种对数据的检索与查询方式,在本节,将讲述Arcgis for Js下如何实现featurelayer的这两种查询方式,先贴图给大家看看: 实现界面 属性查询 空间查询 看完了效果,下面说说我的实现思路. 首先,实现查询的关键是Query,属性查询时query.where来实现,空间查询时query.geometry来实现,具体代码如下: 1.属性查询 on(dom.byId("query"), "click", function(even

使用resultMap实现ibatis复合数据结构查询(1.多重属性查询;2.属性中含有列表查询)

以订单为例(订单详情包括了订单的基本信息,配送物流信息,商品信息),直接上代码: 1.多重属性查询 java实体 public class OrderDetail { @XmlElement(required = true) protected String orderSn; @XmlElement(required = true) protected String orderAmount; @XmlElement(required = true) protected String orderS

HQL属性查询语法?

上面的HQL:"from Street" ,将取出Steet的所有对象记录,对应的SQL语句为"select * from street"在Hibernate中执行查询的时候,如果实体存在继承关系,将会进行继承关系判定,如:"from Street"将返回所有Street以及Street子类的记录假设:系统中存在Street的两个子类StreetA和StreetB,那么from Street返回的记录将包含这两个子类的所有数据,即使StreetA

【HQL】属性查询、条件查询

单一属性: //返回结果集属性列表,元素类型和实体类中的属性类型一致 List students = session.createQuery("select name from Student").list(); for (Iterator iter=students.iterator(); iter.hasNext();) { String name = (String)iter.next(); System.out.println(name); } 多个属性: //查询多个属性,返

hdu 1754 splay tree伸展树 初战(单点更新,区间属性查询)

题意:与区间查询点更新,点有20W个,询问区间的最大值.曾经用线段树,1000+ms,今天的伸展树,890没ms,差不多. 第一次学习伸展树,一共花了2个单位时间,感觉伸展树真很有用,也很好玩.现在只学了一点点.切个点更新试试. 大致思路:用编号(数组)作为树的键值建树,每插一个数,沿路节点更新最大值(每个结点有一个附加信息标记以之为子树的树所有点的最大值).所以,查询时[i,j],只要把i-1伸展到树根,把j+1伸展到I-1下面,那么j+1的左子树就是要的区间了!查该子树根值信息即可(特判端点

利用 Task\Query 实现定位 , FeatureLayer 的属性查询

放纵了几天,又有了学习的动力.今天实现了利用对 FeatureLayer 进行属性查询在地图上进行跳转. 一.我下载了一幅浙江省的县界面地图,存在NAME字段,利用Name就能进行查询了: var name = tb.value; if(name!="") { var query = new esri.tasks.Query(); query.where = "NAME = '"+name+"'"; fl.queryFeatures(query,

Win7删除右键菜单中“图形属性”和“图形选项”

完win7操作系统后,打完驱动在桌面右键会出现如下两个选项,平时没啥用又占用空间,那么如何删掉这两个选项呢? 操作步骤: 1.在运行中输入 regedit 确定打开注册表: 2.依次单击展开HKEY_CLASSES_ROOTDirectoryBackgroundshellexContextMenuHandlers 3.删除其中的 igfxcui 键,删完后马上生效,搞定. 上面就是Win7删除右键菜单中“图形属性”和“图形选项”的方法. 原文地址:https://www.cnblogs.com/

cesium 结合 geoserver 实现地图属性查询(附源码下载)

前言 cesium 官网的api文档介绍地址cesium官网api,里面详细的介绍 cesium 各个类的介绍,还有就是在线例子:cesium 官网在线例子,这个也是学习 cesium 的好素材. 内容概览 1.cesium 结合 geoserver 实现地图属性查询2.源代码 demo 下载 效果图如下: 实现思路:首先利用 geoserver 发布的图斑 WFS 服务,通过 url 的 rest 请求,构造属性查询形式,获取 geojson 数据源:然后调用cesium api 的 Cesi