///---------------------------------------------------------- //前置条件:地图全局变量的名称为map //功能:对行政区划地图中的县城图层 // 查询当前操作的县城 // 通过查询,使当前地图视图为该县城的范围,达到缩放至图层的效果 require(["dojo/parser", "dijit/registry", 'dojo/on', "dojo/dom", "esri/map", "esri/layers/ArcGISDynamicMapServiceLayer", "esri/tasks/FindTask", "esri/tasks/FindParameters", "esri/symbols/SimpleLineSymbol", "esri/symbols/SimpleFillSymbol", "esri/graphic", "dojo/domReady!"], function (parser, registry, on, dom, Map, ArcGISDynamicMapServiceLayer, FindTask, FindParameters, SimpleLineSymbol, SimpleFillSymbol) { //parser.parse(); var findTask = new FindTask("http://localhost:6080/arcgis/rest/services/henan/MapServer"); var FindParameters = new FindParameters(); var xzFieldName = ["xxx"];//字段名称 var xzFieldValue = "xxxx";//县名 on(dom.byId("BtnSetExtent"), "click", FindByField); //对字段进行查询 function FindByField() { FindParameters.returnGeometry = true; FindParameters.layerIds = [0]; FindParameters.searchFields = xzFieldName; FindParameters.searchText = xzFieldValue; findTask.execute(FindParameters, ShowFindResult); //alert("3"); } //属性查询结果处理 function ShowFindResult(queryResult) { if (queryResult.length > 0) { var feature = queryResult[0].feature;//[0].feature; //创建线符号 var lineSymbol = new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new dojo.Color([54, 141, 58]), 2); //创建面符号 var fill = new SimpleFillSymbol(SimpleFillSymbol.STYLE_NULL, lineSymbol); //赋予相应的符号 feature.setSymbol(fill); pMap.graphics.clear(); pMap.graphics.add(feature); var sGeometry = feature.geometry; var ftGeoExt = sGeometry.getExtent(); pMap.setExtent(ftGeoExt); } } });