描述

使用ArcGIS Server 几何服务(geometry service)来对绘制在地图上的图形生成缓冲区。几何服务能够在基于浏览器的应用程序中执行缓冲操作(buffering),投影要素(project feature),计算可测量值。

利用几何服务创建缓冲区之前,需创建一个BufferParameters(缓冲参数)的实例,并且明确缓冲距离(distance),单位(unit)以及坐标系统(spatial reference)。通过传入这个参数(parameters)和一个当缓冲执行完成时调用的回调函数(callback)来调用缓冲(buffer)功能。

geometryService.buffer(params,function(features){showBuffer(features)});

注意:

  • 在下面的例子中使用了ArcGIS JavaScript API 自带的绘制工具条,通过工具条产生的几何(geometry)作为缓冲操作的输入几何。如果几何的类型是多边形,则程序会在其作为参数进行缓冲处理之前进行简化(simplify)操作。这是用来找出那些边界线相交的非法拓扑多边形。简化操作能强行将这些多边形转变为合法的多部分的要素(multipart features)。

  • 这个示例医用了一个代理页面,以防几何的GET请求超过了某些Web浏览器强加的2000字符的限制。有关如何建立自己的代理页面,请参阅代理页面的说明。

<!DOCTYPE html>
<!--<html lang="en"> 加入lang会导致dojo的样式错误-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
<title>Buffer</title>
<link rel="stylesheet" href="https://js.arcgis.com/3.20/dijit/themes/claro/claro.css">
<link rel="stylesheet" href="https://js.arcgis.com/3.20/esri/css/esri.css">
<style>
html, body {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
overflow:hidden;
}
#leftPane{
color:#000;
width:250px;
padding-bottom:15px;
}n
#map{
padding:0;
}
.details{
font-size:14px;
font-weight:600;
padding-bottom:20px;
} button{
margin:2px;
cursor:pointer;
}
</style>
<script src="https://js.arcgis.com/3.20/"></script>
<script type="text/javascript">
var map,tb; // AMD模块
require(["dojo/dom", "dojo/_base/array",
"dojo/parser",
"dojo/query",
"dojo/on", "esri/Color",
"esri/config",
"esri/map",
"esri/graphic", "esri/geometry/normalizeUtils",
"esri/tasks/GeometryService",
"esri/tasks/BufferParameters", "esri/toolbars/draw", "esri/symbols/SimpleMarkerSymbol",
"esri/symbols/SimpleLineSymbol",
"esri/symbols/SimpleFillSymbol", "dijit/layout/BorderContainer",
"dijit/layout/ContentPane",
"dijit/form/Button", "dojo/domReady!"
],
function(dom, array, parser, query, on, Color, esriConfig, Map, Graphic, normalizeUtils, GeometryService, BufferParameters, Draw, SimpleMarkerSymbol, SimpleLineSymbol, SimpleFillSymbol){ // dojo根据dom标签的属性实例化控件
parser.parse(); // esriconfig : The default values for all JS API configuration options.
esriConfig.defaults.geometryService = new GeometryService("https://utility.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer"); // proxy 用于跨域
esriConfig.defaults.io.proxyUrl = "/proxy/";
esriConfig.defaults.io.alwaysUseProxy = false; //dojo用于事件绑定
on(dom.byId("clearGraphics"),"click",function(){
if(map){
map.graphics.clear();
}
}); // dojo 的选择器
query(".tool").on("click",function(evt){
if(tb){
tb.activate(evt.target.id);
}
}); map = new Map("map",{
basemap:"streets",
center:[-111.5,39.541],
zoom:7
}); // map加载成功后然后初始化工具条
map.on("load",initToolbar); // evtObj 属于 事件参数
function initToolbar(evtObj){
tb = new Draw(evtObj.map);
tb.on("draw-complete",doBuffer);// 已经不建议使用draw-end事件了,改为draw-complete
} function doBuffer(evtObj){
tb.deactivate();
var geometry = evtObj.geometry,
symbol;
switch(geometry.type){
case "point":
symbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_SQUARE,10,new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([255,0,0]), 1), new Color([0,255,0,0.25]) );
break;
case "polyline":
symbol = new SimpleLineSymbol(SimpleLineSymbol.STYLE_DASH,new Color([255,0,0]),1);
break;
case "polygon":
symbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_NONE,new SimpleLineSymbol(SimpleLineSymbol.STYLE_DASHDOT,new Color([255,0,0]),2),new Color([255,255,0,0.25]));
break; } // 显示画的几何:形状 + 样式
var graphic = new Graphic(geometry,symbol);
map.graphics.add(graphic); // 设立缓冲参数
var params = new BufferParameters();
params.distances = [dom.byId("distance").value]; // 参数为数组
params.outSpatialReference = map.spatialReference;
params.unit = GeometryService[dom.byId("unit").value]; // Normalizes geometries that intersect the central meridian or fall outside the world extent so they stay within the current coordinate system. Only supported for Web Mercator and geographic coordinates.(子午线规范化工具)
normalizeUtils.normalizeCentralMeridian([geometry]).then(function(normalizedGeometries){
var normalizedGeometry = normalizedGeometries[0];
if(normalizedGeometry.type === "polygon"){ // 规范化多边形几何操作
esriConfig.defaults.geometryService.simplify([normalizedGeometry],function(geometries){
params.geometries = geometries; // 进行缓冲操作
esriConfig.defaults.geometryService.buffer(params,showBuffer);// ShowBuffer is callback function
});
}else{
params.geometries = [normalizedGeometry];
esriConfig.defaults.geometryService.buffer(params,showBuffer);
}
}); } function showBuffer(bufferedGeometries){
// 设置缓冲区显示样式
var symbol = new SimpleFillSymbol(
SimpleFillSymbol.STYLE_SOLID,
new SimpleLineSymbol(
SimpleLineSymbol.STYLE_SOLID,
new Color([255,0,0,0.65]),2),
new Color([255,0,0,0.35])
); // dojo 数组遍历
array.forEach(bufferedGeometries,function(geometry){ // 显示地图绘制样式
var graphic = new Graphic(geometry,symbol);
map.graphics.add(graphic);
});
}
});
</script> </head> <body class="claro">
<div data-dojo-type="dijit/layout/BorderContainer"
data-dojo-props="gutters:'true', design:'sidebar'"
style="width:100%;height:100%;"> <div id="map"
data-dojo-type="dijit/layout/ContentPane"
data-dojo-props="region:'center'">
</div> <div id="leftPane"
data-dojo-type="dijit/layout/ContentPane"
data-dojo-props="region:'left'">
<div class="details">Pick a tool and draw on the map. The drawn graphic will be buffered based on the specified parameters.</div>
<button type="button" class="tool" id="line">Line</button>
<button type="button" class="tool" id="polyline">Polyline</button>
<button type="button" class="tool" id="freehandpolyline">Freehand Polyline</button>
<br/>
<button type="button" class="tool" id="polygon">Polygon</button>
<button type="button" class="tool" id="freehandpolygon">Freehand Polygon</button>
<br/><hr />
<div><b>Buffer Parameters</b></div>
Distance:&nbsp;<input type="text" id="distance" size="5" value="25" />
<select id="unit" style="width:100px;">
<option value="UNIT_STATUTE_MILE">Miles</option>
<option value="UNIT_FOOT">Feet</option>
<option value="UNIT_KILOMETER">Kilometers</option>
<option value="UNIT_METER">Meters</option>
<option value="UNIT_NAUTICAL_MILE">Nautical Miles</option>
<option value="UNIT_US_NAUTICAL_MILE">US Nautical Miles</option>
<option value="UNIT_DEGREE">Degrees</option>
</select><br />
<button type="button" id="clearGraphics">Clear Graphics</button>
</div>
</div>
</body>
</html>

ArcGIS JavaScriptAPI----- 缓冲区操作的更多相关文章

  1. arcgis地图窗口操作

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  2. ArcGIS 10.2 操作SQLite

    SQLite,是一款轻型的数据库,是遵守ACID的关联式数据库管理系统,它的设计目标是嵌入式的,而且目前已经在很多嵌入式产品中使用了它.ArcGIS 10.2 提供了对SQLite数据库的支持,这对那 ...

  3. 基于直接缓冲区和非直接缓冲区的javaIO文件操作

    基本概念: 1. 非直接缓冲区:  指的是通过jvm来缓存数据的,应用程序要读取本地数据要经历从本地磁盘到物理内存,然后copy到jvm中,然后再通过流的方式读取到应用程序中,写的操作正好与之相反. ...

  4. ArcGIS Server开发教程系列(1) Arcgis server 10.1 的安装

    本系列所使用的软件版本如下: Windows 7 X64 / Windows server 2008 X64 Arcgis for Desktop 10.1 Arcgis 10.1 for serve ...

  5. arcgis如何制作DEM数据

    DEM描述的是地面高程信息,它在测绘.水文.气象.地貌.地质.土壤.工程建设.通讯.军事等国民经济和国防建设以及人文和自然科学领域有着广泛的应用.如在工程建设上,可用于如土方量计算.通视分析等:在防洪 ...

  6. ArcGIS学习推荐

    1.  Arcgis Desktop 10帮助库 ArcGIS 系统的帮助库.该帮助库已经过编译,可为 ArcGIS 各方面的应用提供综合文档.建立该库的目的是满足以下各类主要用户的需求: GIS 专 ...

  7. ArcGIS如何将表连接到空间数据上

    当我们有一些空间数据和一些业务数据(表),希望把业务数据和空间数据连接起来时,可以采用ArcGIS Desktop进行操作.本文将介绍如何在ArcGIS Destop中将表和空间数据关联起来. Arc ...

  8. 《Java核心技术卷二》笔记(二)文件操作和内存映射文件

    文件操作 上一篇已经总结了流操作,其中也包括文件的读写.文件系统除了读写以为还有很多其他的操作,如复制.移动.删除.目录浏览.属性读写等.在Java7之前,一直使用File类用于文件的操作.Java7 ...

  9. Java nio 笔记:系统IO、缓冲区、流IO、socket通道

    一.Java IO 和 系统 IO 不匹配 在大多数情况下,Java 应用程序并非真的受着 I/O 的束缚.操作系统并非不能快速传送数据,让 Java 有事可做:相反,是 JVM 自身在 I/O 方面 ...

  10. C 语言文件操作

    C 语言文件操作 1. 数据流:     程序与数据的交互以流的形式进行.fopen 即打开数据流,fclose 即刷新数据流.     所谓数据流,是一种抽象,表示这段数据像流一样,需要逐步接收,不 ...

随机推荐

  1. [Swift]LeetCode351. 安卓解锁模式 $ Android Unlock Patterns

    Given an Android 3x3 key lock screen and two integers m and n, where 1 ≤ m ≤ n ≤ 9, count the total ...

  2. [Swift]LeetCode404. 左叶子之和 | Sum of Left Leaves

    Find the sum of all left leaves in a given binary tree. Example: 3 / \ 9 20 / \ 15 7 There are two l ...

  3. [Swift]LeetCode1016. 子串能表示从 1 到 N 数字的二进制串 | Binary String With Substrings Representing 1 To N

    Given a binary string S (a string consisting only of '0' and '1's) and a positive integer N, return ...

  4. awk小例子_2_数值统计脚本

    通信公司工作,经常处理各种协议接口,在统计协议接口字段内容时,需要统计字段填写的内容是否正确,和占比是多少.要是单次统计,估计会把人累死,写个脚本统计,轻松便捷. 举例:接口内容 这是一条话单,这样的 ...

  5. 【异常】Servlet.service() for servlet [springMvc] in context with path [/orderdishessystem] threw exception [Handler processing failed; nested exception is java.lang.NoClassDefFoundError: net/sf/ezmorph/M

    今天做登录的时候,引入json-lib-2.1-jdk15.jar的包时,执行到JSONObject jsonObject = new JSONObject()对象就报标题的那个错. 原来是除了要导入 ...

  6. iOS学习——页面的传值方式

    一.简述 在iOS开发过程中,页面跳转时在页面之间进行数据传递是很常见的事情,我们称这个过程为页面传值.页面跳转过程中,从主页面跳转到子页面的数据传递称之为正向传值:反之,从子页面返回主页面时的数据传 ...

  7. linux字符测试以及for循环

    1.字符测试 常用的测试字符的命令: == .=都表示测试字符相等,格式为[ A = B ]需要注意的是变量与等号之间需要有空格,不然测试的结果不正确示例如下 若字符与等号不加空格,假设变量A=ab  ...

  8. Python内置函数(36)——iter

    英文文档: iter(object[, sentinel]) Return an iterator object. The first argument is interpreted very dif ...

  9. java代码之美(10)---Java8 Map中的computeIfAbsent方法

    Map中的computeIfAbsent方法 Map接口的实现类如HashMap,ConcurrentHashMap,HashTable等继承了此方法,通过此方法可以在特定需求下,让你的代码更加简洁. ...

  10. Solr 12 - 部署SolrCloud中遇到的问题 + 解决方法

    目录 1 ZooKeeper管理配置文件的另一种方法 2 Solr服务不能访问 3 部分节点处于"Recovering"或"Gone"状态 4 Solr集群不稳 ...