<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Label Points</title>
<link rel="stylesheet" href="http://js.arcgis.com/3.9/js/dojo/dijit/themes/tundra/tundra.css" />
<link rel="stylesheet" href="http://js.arcgis.com/3.9/js/esri/css/esri.css" />
<style>
html, body{
padding: 0;
margin: 0;
width: 100%;
height: 100%;
}
</style>
<script>
var dojoConfig = {
packages: [{
name: "myApp",
location: location.pathname.replace(/\/[^/]+$/, "") + "/js/myApp"
}]
};
</script>
<script src="http://js.arcgis.com/3.9/"></script>
<script type="text/javascript">
var map, tb, markerSymbol, lineSymbol, fillSymbol;
var bMapIsDegrees = true;
var geometryService = null;
var displayDistUnits = "Kilometers", displayDistUnitsAbbr = "km";
var displayAreaUnits = "Kilometers", displayAreaUnitsAbbr = "sq km";
var fontFace = "Arial"; require(["dojo/parser", "dijit/registry", "esri/geometry/Point",
"esri/map", "esri/layers/ArcGISTiledMapServiceLayer", "esri/toolbars/draw", "esri/graphic", "esri/SpatialReference",
"esri/symbols/SimpleMarkerSymbol", "esri/symbols/SimpleLineSymbol", "esri/symbols/SimpleFillSymbol",
"esri/symbols/TextSymbol",
"esri/Color", "esri/tasks/ProjectParameters", "esri/tasks/AreasAndLengthsParameters",
"esri/tasks/GeometryService", "myApp/measure",
"dojo/domReady!"],
function (parser, registry, Point, Map, ArcGISTiledMapServiceLayer, Draw, Graphic, SpatialReference,
SimpleMarkerSymbol, SimpleLineSymbol, SimpleFillSymbol, TextSymbol, Color, ProjectParameters,
AreasAndLengthsParameters, GeometryService, measure) {
parser.parse(); map = new Map("mapDiv");
var agoServiceURL = "http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer";
var agoLayer = new ArcGISTiledMapServiceLayer(agoServiceURL);
map.addLayer(agoLayer); markerSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_X, 25,
new SimpleLineSymbol(SimpleLineSymbol.STYLE_DOT,
new Color([0, 0, 255]), 2)); lineSymbol = new SimpleLineSymbol(SimpleLineSymbol.STYLE_DASHDOT,
new Color([255, 0, 0]), 2); fillSymbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID,
new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([0, 0, 0]), 2),
new Color([0, 0, 255, 0.5])
); var geometryUrl = "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer";
geometryService = new GeometryService(geometryUrl); map.on("load", createToolbar); registry.forEach(function (d) {
if (d.declaredClass === "dijit.form.Button") {
d.on("click", activateTool);
}
}); function createToolbar(themap) {
toolbar = new Draw(map);
toolbar.on("draw-end", addToMap);
} function activateTool() {
var tool = null;
switch (this.label) {
case "点":
tool = "POINT";
break;
case "多点":
tool = "MULTIPOINT";
break;
case "线":
tool = "POLYLINE";
break;
case "徒手线":
tool = "FREEHAND_POLYLINE";
break;
case "多边形":
tool = "POLYGON";
break;
}
toolbar.activate(Draw[tool]);
map.hideZoomSlider();
} function addToMap(evt) {
map.graphics.clear(); var geometry = evt.geometry;
var symbol;
// 将用户绘制的几何对象加入到地图中
switch (geometry.type) {
case "point":
symbol = markerSymbol;
break;
case "multipoint":
symbol = markerSymbol;
break;
case "polyline":
symbol = lineSymbol;
break;
case "polygon":
symbol = fillSymbol;
break;
} var graphic = new Graphic(geometry, symbol);
map.graphics.add(graphic); // 增加标注
addLabel(geometry);
} function addLabel(geometry) {
var x, y, g;
switch (geometry.type) {
case "point":
x = measure.round(geometry.x, 2);
y = measure.round(geometry.y, 2);
g = getPointLabel(x + ", " + y, geometry);
map.graphics.add(g);
break; case "multipoint":
for (var i in geometry.points) {
var coords = geometry.points[i];
x = measure.round(coords[0], 2);
y = measure.round(coords[1], 2);
g = getPointLabel(x + ", " + y, new Point(coords, geometry.spatialReference));
map.graphics.add(g);
}
break; case "polyline":
if (displayDistUnits) {
var length = measure.calculateLength(geometry, bMapIsDegrees);
for (var i in geometry.paths) {
if (bMapIsDegrees) {
mapUnits = "Meters";
}
var len = measure.convertDistanceUnits(length[i], mapUnits, displayDistUnits);
var text = measure.significantDigits(len, 4) + " " + displayDistUnitsAbbr;
g = getPathLabel(text, geometry, i);
map.graphics.add(g);
}
}
break; case "polygon":
if (displayDistUnits || displayAreaUnits) {
var measureFunc = function (result) {
for (var i in result.areas) {
var perimeter = result.lengths[i];
var area = result.areas[i];
// 标注周长
if (displayDistUnits) {
var peri = measure.convertDistanceUnits(perimeter, mapUnits, displayDistUnits);
var text = measure.significantDigits(peri, 4) + " " + displayDistUnitsAbbr;
map.graphics.add(getPathLabel(text, geometry, i));
}
// 标注面积
if (displayAreaUnits) {
var a = measure.convertAreaUnits(area, mapUnits, displayAreaUnits);
text = measure.significantDigits(a, 6) + " " + displayAreaUnitsAbbr;
map.graphics.add(getAreaLabel(text, geometry, i));
}
}
}; var polyGraphic = new Graphic(geometry);
if (bMapIsDegrees) {
mapUnits = "Meters";
var outSR = new SpatialReference({
wkid: 54034 //World_Cylindrical_Equal_Area
});
var params = new ProjectParameters();
params.geometries = [geometry];
params.outSR = outSR; geometryService.project(params, function (geometries) {
var areasAndLengthParams = new AreasAndLengthsParameters();
areasAndLengthParams.lengthUnit = GeometryService.UNIT_METER;
areasAndLengthParams.areaUnit = GeometryService.UNIT_SQUARE_METERS;
areasAndLengthParams.polygons = geometries;
geometryService.areasAndLengths(areasAndLengthParams, measureFunc);
});
}
else {
geometryService.areasAndLengths([geometry], measureFunc);
}
}
break;
}
} function getFont() {
var size = 10;
var f = new esri.symbol.Font(size + "pt",
esri.symbol.Font.STYLE_NORMAL,
esri.symbol.Font.VARIANT_NORMAL,
esri.symbol.Font.WEIGHT_BOLD,
fontFace);
return f;
} function getPointLabel(text, point) {
var sym = new TextSymbol(text, getFont(), new Color([255, 0, 0]));
sym.setAlign(TextSymbol.ALIGN_START);
var g = new Graphic(point, sym);
return g;
} function getPathLabel(text, polyline, pathIndex) {
try {
var sym = new TextSymbol(text, getFont(), new Color([255, 0, 0]));
if (polyline.paths) {
var path = polyline.paths[pathIndex];
}
else {
var path = polyline.rings[pathIndex];
}
var idx = Math.floor(path.length / 2);
var p1 = polyline.getPoint(pathIndex, idx - 1);
var p2 = polyline.getPoint(pathIndex, idx);
var point = measure.getMidPoint(p1, p2);
var angle = measure.getAngle(p1, p2);
sym.setAngle(angle);
sym.setOffset(0, 2);
var g = new Graphic(point, sym);
return g;
}
catch (err) {
console.error("创建标注出错:", err);
}
} function getAreaLabel(text, polygon, ringIndex) {
try {
var sym = new TextSymbol(text, getFont(), new Color([255, 0, 0]));
var point = measure.getRingExtent(polygon, ringIndex).getCenter();
var g = new Graphic(point, sym);
return g;
}
catch (err) {
console.error("创建面积标注出错:", err);
}
}
}
);
</script>
</head> <body class="tundra">
<button data-dojo-type="dijit/form/Button">点</button>
<button data-dojo-type="dijit/form/Button">多点</button>
<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>
</body>
</html>

arcgis 点线面操作的更多相关文章

  1. ArcGIS软件操作——地图制图

    ArcGIS软件操作系列二(地图制图) 2016年毕业,参加工作,除了平时出差,大部分时间都在使用ArcGIS处理数据.制图,在此,先将一些制图的小心得撰写出来,希望能与各位共同交流. 1 数据准备: ...

  2. Arcgis案例操作教程——去掉Z值和M值

    Arcgis案例操作教程--去掉Z值和M值 商务合作,科技咨询,版权转让:向日葵,135-4855__4328,xiexiaokui#qq.com 处理前 处理后: 处理方法     商务合作,科技咨 ...

  3. ArcGIS JavaScriptAPI----- 缓冲区操作

    描述 使用ArcGIS Server 几何服务(geometry service)来对绘制在地图上的图形生成缓冲区.几何服务能够在基于浏览器的应用程序中执行缓冲操作(buffering),投影要素(p ...

  4. ArcGIS软件操作——地图配准

    初次写博文,出现措词不当.表述不明确等之类的问题,敬请见谅,但会努力做好.同时,也欢迎各位提出意见,共同交流,共同进步! 直奔主题——运用ArcGIS软件对地图进行配准! 1 数据准备:网络下载的中国 ...

  5. CAD到ArcGIS相关操作

    1.Ctrl+N(新建图形)→复制原数据,粘贴到原坐标 2.将CAD数据转为矢量数据方法众多,此处将提供三种方法: 方法一:CAD转地理数据库注记 在[ArcToolBox]窗口中,双击[转换工具]→ ...

  6. ArcGIS Engine开发之地图基本操作(4)

    ArcGIS Engine开发中数据库的加载 1.加载个人地理数据库数据 个人地理数据库(Personal Geodatabase)使用Miscrosoft Access文件(*.mdb)进行空间数据 ...

  7. ArcGIS工具之ET GeoWizards、GeoTools、GeoTools

    简介 ET GeoWizards是ET SpatialTechniques一套基于ArcGIS的工具集,从2002年开始,其设计的初衷: (1)让ArcView用户拥有ArcEditor甚至ArcIn ...

  8. ArcGIS统计栅格像元值并转换为矢量图层

    很多时候,我们需要得到矢量数据区域所对应栅格数据的像元统计值(求平均.求和等),然后将获得的统计值赋给矢量图层的属性表,在ArcGIS中操作如下:(PS:第一次写技术文章,望大家多多体谅与支持,么么哒 ...

  9. 【ArcGIS笔记】数据处理

    1.ARCGIS在导入Excel坐标点的时候出现"没有注册类"的情况怎么办? 确保你本机上装有office,并且版本要能够识别XLSX格式.2007以上. 2.导入excel时re ...

随机推荐

  1. elasticsearch 中文API 索引(三)

    索引API 索引API允许开发者索引类型化的JSON文档到一个特定的索引,使其可以被搜索. 生成JSON文档 有几种不同的方式生成JSON文档 利用byte[]或者作为一个String手动生成 利用一 ...

  2. 2019-5-24-WPF-源代码-从零开始写一个-UI-框架

    title author date CreateTime categories WPF 源代码 从零开始写一个 UI 框架 lindexi 2019-05-24 15:54:36 +0800 2018 ...

  3. idea debug技巧

    1 给对象设置值

  4. 微信小程序之组件的集合(四)

    这个主要是来开发book的这个大模块的,看看如何优雅的开发出booked模块! 一.book模块的创建 这个就很简单了,创建一个大的框架是很简单的 二.组件的编写 (1)wxml组件页面的编码 首先是 ...

  5. 洛谷 P1155 双栈排序

    题面 解题思路 这道题乍一看还以为是个模拟..怒写一发30分(noip提高组t4有模拟吗?). 其实很好hack,如 10 10 2 8 1 7 9 3 4 5 6 按模拟的思路,应该是10入第一个栈 ...

  6. 尝试一下LLJ大佬的理论AC大法

    1.BZOJ 3522 Poi2014 Hotel DFS 给定一棵树,求有多少无序三元组(x,y,z)满足x,y,z互不相等且Dis(x,y)=Dis(y,z)=Dis(x,z) 枚举中心点,分别d ...

  7. JavaSE_01_Exception类

    1.1 异常概念 指的是程序在执行过程中,出现的非正常的情况,最终会导致JVM的非正常停止. 在Java等面向对象的编程语言中,异常本身是一个类,产生异常就是创建异常对象并抛出了一个异常对象.Java ...

  8. php基础学习过程

    1.基础知识 a.注释: <?php // 这是单行注释 # 这也是单行注释 /* 这是多行注释块 它横跨了 多行 */ ?> b.大小写敏感: 在 PHP 中,所有用户定义的函数.类和关 ...

  9. 【vuex】vue2-happyfri

    我发现我对使用vuex并不擅长,现在跟我一起多多研究项目,好好补补vuex吧 这个开源项目地址为:https://github.com/bailicangdu/vue2-happyfri 这是一个答题 ...

  10. Ubuntu下使用sshfs挂载远程目录到本地

    访问局域网中其他Ubuntu机器,在不同机器间跳来跳去,很是麻烦,如果能够把远程目录映射到本地无疑会大大方面使用,就像Windows下的网络映射盘一样.在Linux的世界无疑也会有这种机制和方式,最近 ...