龙空技术网

ArcGIS api—用缓存区查询地图

山石林 149

前言:

目前我们对“arcgisjsapi”都比较注重,姐妹们都想要知道一些“arcgisjsapi”的相关资讯。那么小编也在网上汇集了一些对于“arcgisjsapi””的相关知识,希望各位老铁们能喜欢,咱们一起来学习一下吧!

描述

本例展示了如何在另外一个任务里使用一个任务的结果。单击地图查看被单击的点的1公里范围内的缓存(如果需要可以修改这个默认的缓存距离)。也可以看缓存区的这些点的人口普查街区信息。单击一个点查看更多的人口普查街区的信息。

通过GeometryService, QueryTask和一些事件监听器实现了所有的功能:

·GeometryService对象提供访问到ArcGIS Server的几何服务,该服务可以缓冲,投影和简化几何体。·QueryTask能根据地理或属性条件从地图图层检索要素。在本例中,查询基于地理(在缓存中的区域)。有趣是,地图图层(人口普查街区组点)不是初始显示在地图上的。对很多这样的查询任务,可以仅仅显示需要的结果元素。·事件监听器帮助脚本知道事件什么时候发生。监听器说,“当A发生,做B”。监听器可以将几个操作连在一起,查询后缓存。每当见到dojo.connect()方法,脚本正在监听一个事件。这有一个监听器的例子:

· dojo.connect(map, "onClick", function(evt) {....}

这三个参数表示对象的事件将在哪发生(the map),本身是什么事件(a mouse click)和当事件发生时运行什么函数。

下面是本例中事情发生的顺序:

1.某人单击地图,触发地图的"onClick"事件

2.几何服务缓存点,触发几何服务的"onBufferComplete"事件

3.缓存的虚线符号被增加到地图上并且查询任务执行,触发查询任务的"onComplete"事件

4.人口普查区被增加到地图上,使用函数sumPopulation统计人口

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" ";><html>  <head>    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>    <meta http-equiv="X-UA-Compatible" content="IE=7" />    <title>QueryTask with query geometry from another task</title>    <link rel="stylesheet" type="text/css"    href=";>    <script type="text/javascript" src=";></script>    <script type="text/javascript">      dojo.require("esri.map");      dojo.require("esri.tasks.query");      dojo.require("esri.tasks.geometry");      function init() {        var startExtent = new esri.geometry.Extent(-95.271, 38.933, -95.228,38.976, new esri.SpatialReference({wkid:4326}) );        var map = new esri.Map("mapDiv", { extent: startExtent });        //加载地图时添加查询功能        dojo.connect(map, "onLoad", initFunctionality);        var streetMap = new esri.layers.ArcGISTiledMapServiceLayer(";);        //var censusMap = new esri.layers.ArcGISDynamicMapServiceLayer(";);        map.addLayer(streetMap);      }        //初始化功能      function initFunctionality(map) {        var queryTask = new esri.tasks.QueryTask(";);        //确定代理页面使用toJson几何服务并且载荷大于2000        //如果不是可用的缓冲区,则会请求一个http Post代理.        esriConfig.defaults.io.proxyUrl= "/arcgisserver/apis/javascript/proxy/proxy.ashx";        esriConfig.defaults.io.alwaysUseProxy = false;        //查询        var query = new esri.tasks.Query();        query.returnGeometry = true;        query.outFields = ["POP2000","HOUSEHOLDS","HSE_UNITS", "TRACT", "BLOCK"];        //几何服务端点        var gsvc = new esri.tasks.GeometryService(";);        // +++++监听地图的onClick事件+++++        dojo.connect(map, "onClick", function(evt) {          map.graphics.clear();          var symbol = new esri.symbol.SimpleMarkerSymbol();          var graphic = new esri.Graphic(evt.mapPoint, symbol);          var params = new esri.tasks.BufferParameters();          params.features = [ graphic ];          // 缓冲线性单位(米,公里...)          params.distances = [ dojo.byId('bufferDistance').value ];          params.unit = esri.tasks.BufferParameters.UNIT_KILOMETER;          params.bufferSpatialReference = new esri.SpatialReference({wkid: 102113});          gsvc.buffer(params);          dojo.byId('messages').innerHTML = "<b>Creating Buffer Using GeometryService...</b>";        });        // +++++监听GeometryService类的onBufferComplete方法+++++        dojo.connect(gsvc, "onBufferComplete", function(graphics) {          var symbol = new esri.symbol.SimpleFillSymbol(                  "none",                new esri.symbol.SimpleLineSymbol(                    "dashdot",                    new dojo.Color([255,0,0]),                    2),                new dojo.Color([255,255,0,0.25]));          var graphic = new esri.Graphic(graphics[0].geometry,symbol);          map.graphics.add(graphic);          query.geometry = graphic.geometry;          queryTask.execute(query);          dojo.byId('messages').innerHTML = "<b>Executing Query with Result BufferGeometry...</b>";        });        // +++++监听QueryTask中的executecomplete事件+++++        dojo.connect(queryTask, "onComplete", function(fset) {          //创建所选标记的图形          var symbol = new esri.symbol.SimpleMarkerSymbol();          symbol.style = esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE;          symbol.setSize(8);          symbol.setColor(new dojo.Color([255,255,0,0.5]));          var infoTemplate = new esri.InfoTemplate("Block: ${BLOCK}","${'*'}");          var resultFeatures = fset.features;          for (var i=0, il=resultFeatures.length; i<il; i++) {            var graphic = resultFeatures[i];            graphic.setSymbol(symbol);            graphic.setInfoTemplate(infoTemplate);            map.graphics.add(graphic);          }          var totalPopulation = sumPopulation(fset);          var r = "";          r = "<b>The total Census Block population within the buffer is <i>"               + totalPopulation + "</i>.</b>";          dojo.byId('messages').innerHTML = r;        });      }      function sumPopulation(fset) {        var features = fset.features;        var popTotal = 0;        for (var x = 0; x < features.length; x++) {          popTotal = popTotal + features[x].attributes['POP2000'];        }        return popTotal;      }      dojo.addOnLoad(init);    </script>  </head>  <body class="tundra">    Zoom to area and click on map to select census block points within the buffered circle.<br/>    Buffer distance (in kilometers): <input type="text" id="bufferDistance" value="1" size="5"/>    <div id="mapDiv" style="width: 500px; height:500px;"></div>    <span id="messages"></span>  </body></html>

标签: #arcgisjsapi