主页代码:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>图形查询属性</title>
<link rel="stylesheet" href="http://js.arcgis.com/3.9/js/dojo/dijit/themes/claro/claro.css">
<link rel="stylesheet" href="http://js.arcgis.com/3.9/js/esri/css/esri.css">
<script src="http://js.arcgis.com/3.9/"></script>
<script src="Identify.js"></script>
</head>
<body class="claro">
<button data-dojo-type="dijit/form/Button">点</button>
<button data-dojo-type="dijit/form/Button">线</button>
<button data-dojo-type="dijit/form/Button">多边形</button>
<div id="mapDiv" style="width:900px; height:600px; border:1px solid #000;"></div> <!-- info window tabs -->
<div id="tabs" data-dojo-type="dijit/layout/TabContainer" style="width:385px;height:150px;">
<div id="layer2Tab" data-dojo-type="dijit/layout/ContentPane" title="州"></div>
<div id="layer1Tab" data-dojo-type="dijit/layout/ContentPane" title="河流"></div>
<div id="layer0Tab" data-dojo-type="dijit/layout/ContentPane" title="城市"></div>
</div>
</body>
</html>

Identify.js代码:

var map, identifyTask, identifyParams;
var pointSym, lineSym, polygonSym;
var layer2results, layer1results, layer0results; require(["dojo/parser", "dijit/registry", "esri/map", "esri/layers/ArcGISDynamicMapServiceLayer", "esri/toolbars/draw",
"esri/symbols/SimpleMarkerSymbol", "esri/symbols/SimpleLineSymbol", "esri/symbols/SimpleFillSymbol", "esri/Color",
"esri/tasks/IdentifyTask", "esri/tasks/IdentifyParameters", "esri/geometry/screenUtils",
"dijit/form/Button", "dijit/layout/TabContainer", "dijit/layout/ContentPane", "dojo/domReady!"],
function (parser, registry, Map, ArcGISDynamicMapServiceLayer, Draw,
SimpleMarkerSymbol, SimpleLineSymbol, SimpleFillSymbol, Color,
IdentifyTask, IdentifyParameters, screenUtils) { parser.parse(); map = new Map("mapDiv");
//var url = "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer";
var url = "http://localhost:6080/arcgis/rest/services/bluechina/MapServer";
var agoLayer = new ArcGISDynamicMapServiceLayer(url);
map.addLayer(agoLayer);
map.on("load", initIdentify); var redColor = new Color([255, 0, 0]);
var halfFillYellow = new Color([255, 255, 0, 0.5]);
pointSym = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_DIAMOND, 10,
new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, redColor, 1),
halfFillYellow);
lineSym = new SimpleLineSymbol(SimpleLineSymbol.STYLE_DASHDOT, redColor, 2);
polygonSym = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID,
new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, redColor, 2),
halfFillYellow); map.infoWindow.on("show", function () {
registry.byId("tabs").resize();
}); var tb = new Draw(map);
tb.on("draw-end", doIdentify); registry.forEach(function (d) {
if (d.declaredClass === "dijit.form.Button") {
d.on("click", activateTool);
}
}); function activateTool() {
var tool = null;
switch (this.label) {
case "点":
tool = "POINT";
break;
case "线":
tool = "POLYLINE";
break;
case "多边形":
tool = "POLYGON";
break;
}
tb.activate(Draw[tool]);
map.hideZoomSlider();
} function initIdentify(evt) {
// 实例化IdentifyTask
identifyTask = new IdentifyTask(url);
// IdentifyTask参数设置
identifyParams = new IdentifyParameters();
// 冗余范围
identifyParams.tolerance = 3;
// 返回地理元素
identifyParams.returnGeometry = true;
// 进行Identify的图层
identifyParams.layerIds = [2, 1, 0];
// 进行Identify的图层为全部
identifyParams.layerOption = IdentifyParameters.LAYER_OPTION_ALL; // 设置infoWindow的大小
evt.map.infoWindow.resize(415, 200);
// 设置infoWindow的标题头
evt.map.infoWindow.setTitle("Identify结果");
evt.map.infoWindow.setContent(registry.byId("tabs").domNode);
} // 进行Identify
function doIdentify(evt) {
// 清除上一次的高亮显示
map.graphics.clear();
// Identify的geometry
identifyParams.geometry = evt.geometry;
// Identify范围
identifyParams.mapExtent = map.extent;
identifyTask.execute(identifyParams, function (idResults) {
addToMap(idResults, evt.geometry);
});
} // 在infoWindow中显示Identify结果
function addToMap(idResults, geometry) {
layer2results = { displayFieldName: null, features: [] };
layer1results = { displayFieldName: null, features: [] };
layer0results = { displayFieldName: null, features: [] };
for (var i = 0, il = idResults.length; i < il; i++) {
var idResult = idResults[i];
if (idResult.layerId === 2) {
if (!layer2results.displayFieldName) {
layer2results.displayFieldName = idResult.displayFieldName;
}
layer2results.features.push(idResult.feature);
} else if (idResult.layerId === 1) {
if (!layer1results.displayFieldName) {
layer1results.displayFieldName = idResult.displayFieldName;
}
layer1results.features.push(idResult.feature);
} else if (idResult.layerId === 0) {
if (!layer0results.displayFieldName) {
layer0results.displayFieldName = idResult.displayFieldName;
}
layer0results.features.push(idResult.feature);
}
}
registry.byId("layer2Tab").setContent(layerTabContent(layer2results, "layer2results"));
registry.byId("layer1Tab").setContent(layerTabContent(layer1results, "layer1results"));
registry.byId("layer0Tab").setContent(layerTabContent(layer0results, "layer0results")); // 设置infoWindow显示
var firstPt;
if (geometry.type == "point")
firstPt = geometry;
else
firstPt = geometry.getPoint(0, 0);
var screenPoint = screenUtils.toScreenPoint(map.extent, map.width, map.height, firstPt);
map.infoWindow.show(screenPoint, map.getInfoWindowAnchor(screenPoint));
} function layerTabContent(layerResults, layerName) {
var content = "<i>选中要素数目为:" + layerResults.features.length + "</i>";
switch (layerName) {
case "layer2results":
content += "<table border='1'><tr><th>ID</th><th>州名</th><th>面积</th></tr>";
for (var i = 0, il = layerResults.features.length; i < il; i++) {
content += "<tr><td>" + layerResults.features[i].attributes['FID'] + " <a href='#' onclick='showFeature(" + layerName + ".features[" + i + "]); return false;'>(显示)</a></td>";
content += "<td>" + layerResults.features[i].attributes['NAME'] + "</td>";
content += "<td>" + layerResults.features[i].attributes['AREA'] + "</td>";
}
content += "</tr></table>";
break;
case "layer1results":
content += "<table border='1'><tr><th>ID</th><th>名称</th></tr>";
for (var i = 0, il = layerResults.features.length; i < il; i++) {
content += "<tr><td>" + layerResults.features[i].attributes['FID'] + " <a href='#' onclick='showFeature(" + layerName + ".features[" + i + "]); return false;'>(显示)</a></td>";
content += "<td>" + layerResults.features[i].attributes['NAME'] + "</td>";
}
content += "</tr></table>";
break;
case "layer0results":
content += "<table border='1'><tr><th>ID</th><th>形状</th><th>省名</th><th>面积</th></tr>";
for (var i = 0, il = layerResults.features.length; i < il; i++) {
content += "<tr><td>" + layerResults.features[i].attributes['FID'] + " <a href='#' onclick='showFeature(" + layerName + ".features[" + i + "]); return false;'>(显示)</a></td>";
content += "<td>" + layerResults.features[i].attributes['Shape'] + "</td>";
content += "<td>" + layerResults.features[i].attributes['NAME'] + "</td>";
content += "<td>" + layerResults.features[i].attributes['AREA'] + "</td>";
}
content += "</tr></table>";
break;
}
return content;
}
}); // 高亮显示选中元素
function showFeature(feature) {
map.graphics.clear();
var symbol;
// 将几何对象加入到地图中
switch (feature.geometry.type) {
case "point":
symbol = pointSym;
break;
case "polyline":
symbol = lineSym;
break;
case "polygon":
symbol = polygonSym;
break;
} feature.setSymbol(symbol);
map.graphics.add(feature);
}

图形查询属性(IdentifyTask实现查询)//查询本地服务的更多相关文章

  1. matlab中get查询图形对象属性

    来源:https://ww2.mathworks.cn/help/matlab/ref/get.html?searchHighlight=get&s_tid=doc_srchtitle get ...

  2. QueryTask,FindTask,IdentifyTask三种查询的区别

    1:QueryTask是一个进行空间和属性查询的功能类,它可以在某个地图服务的某个子图层内进行查询,顺便需要提一下的是,QueryTask进行查询的地图服务并不必项加载到Map中进行显示.QueryT ...

  3. ArcGIS Engine 创建索引(属性索引)——提高查询效率

    转自原文 ArcGIS Engine 创建索引(属性索引)——提高查询效率 众所周知,建立索引可以提高查询的效率,当对FeatureClass中的某一列频繁的查找,且数据量比较大时,建立索引是非常有必 ...

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

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

  5. Hibernate第十篇【Hibernate查询详解、分页查询】

    前言 在Hibernate的第二篇中只是简单地说了Hibernate的几种查询方式-.到目前为止,我们都是使用一些简单的主键查询阿-使用HQL查询所有的数据-.本博文主要讲解Hibernate的查询操 ...

  6. Hibernate_day04--课程安排_Hibernate查询方式_对象导航查询_OID查询

    Hibernate_day04 上节内容 今天内容 Hibernate查询方式 对象导航查询 OID查询 HQL查询 查询所有 条件查询 排序查询 分页查询 投影查询 聚集函数使用 QBC查询 查询所 ...

  7. mongodb_查询操作使用_条件查询、where子句等(转)

    <?php /*  mongodb_查询操作使用_条件查询.where子句等(转并学习)   1.find()/findOne() mongodb数据库的查询操作即使用find()或者findO ...

  8. 22Mybatis_订单商品数据模型_多对多查询以及对多对多查询的总结

    之前讲了一对一,一对多查询,这篇文章讲的是多对多. 先给出需求:查询用户及用户购买商品信息. 我们由之前的文章知道,这个需求是多对多的. 还是那个终止我们的mybatis所做的不管是之前的一对一还是一 ...

  9. T-SQL查询语句(二):嵌套查询

    一个select...From...Where查询语句块可以嵌套在另一个select...From...Where查询块的Where子句中,称为嵌套查询.外层查询称为父查询,主查询.内层查询称为子查询 ...

随机推荐

  1. RK3288 开机动画旋转

    CPU:RK3288 系统:Android 5.1 如果开机动画与屏显示方向不一致,有两种方法可以更改开机动画方向. 一.RK3288默认的开机动画是由两张图片组合而成的,可以直接旋转两张图片的方向. ...

  2. linux编程基本

    库的使用头文件:.h 里面的函数及变量的声明 比如#include <stdio.h> ,Linux下默认头文件的搜索路径 系统定义的头文件: /usr/include /usr/loca ...

  3. Java--普通代码块静态代码块执行顺序

    class B { public B() { super(); System.out.println("构造器B"); } { System.out.println("普 ...

  4. 马士兵Spring-声明式事务管理-annotation

    1.事务加在DAO层还是service层? service中可能多涉及多种DAO的操作,比如存了一个User之后,需要保存一条日志信息:如果在DAO中分别设置事务的话,一个DAO下面方法抛出异常了,但 ...

  5. Bootstrap-Plugin:标签页(Tab)插件

    ylbtech-Bootstrap-Plugin:标签页(Tab)插件 1.返回顶部 1. Bootstrap 标签页(Tab)插件 标签页(Tab)在 Bootstrap 导航元素 一章中介绍过.通 ...

  6. Oracle 11g 新特性 -- Oracle Restart 说明(转载)

    转载:http://blog.csdn.net/tianlesoftware/article/details/8435670 一.  OHASD 说明 Oracle 的Restart 特性是Oracl ...

  7. selenium+python自动化83-pip安装selenium报Read time out HTTPSConnectionPool(host='pypi.python.org' port443)

    遇到问题 1.有些小伙伴在用pip安装selenium时候报 Read time out HTTPSConnectionPool(host='pypi.python.org' port443) 2.估 ...

  8. TDataset.CopyFields

    Description Often when manipulating datasets with similar structures, you need to copy the records f ...

  9. ManagedProperty not injected in @FacesConverter

    I'm trying to inject a ManagedBean in my FacesConverted the following way: @ManagedBean @RequestScop ...

  10. 下拉列表插件bootstrap-select使用实例

    网页实例 http://www.jq22.com/yanshi302 使用bootstrap-select插件来实现下来菜单搜索匹配功能,如图 实现代码如下 <html> <head ...