arcgis 点线面操作
<!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 点线面操作的更多相关文章
- ArcGIS软件操作——地图制图
ArcGIS软件操作系列二(地图制图) 2016年毕业,参加工作,除了平时出差,大部分时间都在使用ArcGIS处理数据.制图,在此,先将一些制图的小心得撰写出来,希望能与各位共同交流. 1 数据准备: ...
- Arcgis案例操作教程——去掉Z值和M值
Arcgis案例操作教程--去掉Z值和M值 商务合作,科技咨询,版权转让:向日葵,135-4855__4328,xiexiaokui#qq.com 处理前 处理后: 处理方法 商务合作,科技咨 ...
- ArcGIS JavaScriptAPI----- 缓冲区操作
描述 使用ArcGIS Server 几何服务(geometry service)来对绘制在地图上的图形生成缓冲区.几何服务能够在基于浏览器的应用程序中执行缓冲操作(buffering),投影要素(p ...
- ArcGIS软件操作——地图配准
初次写博文,出现措词不当.表述不明确等之类的问题,敬请见谅,但会努力做好.同时,也欢迎各位提出意见,共同交流,共同进步! 直奔主题——运用ArcGIS软件对地图进行配准! 1 数据准备:网络下载的中国 ...
- CAD到ArcGIS相关操作
1.Ctrl+N(新建图形)→复制原数据,粘贴到原坐标 2.将CAD数据转为矢量数据方法众多,此处将提供三种方法: 方法一:CAD转地理数据库注记 在[ArcToolBox]窗口中,双击[转换工具]→ ...
- ArcGIS Engine开发之地图基本操作(4)
ArcGIS Engine开发中数据库的加载 1.加载个人地理数据库数据 个人地理数据库(Personal Geodatabase)使用Miscrosoft Access文件(*.mdb)进行空间数据 ...
- ArcGIS工具之ET GeoWizards、GeoTools、GeoTools
简介 ET GeoWizards是ET SpatialTechniques一套基于ArcGIS的工具集,从2002年开始,其设计的初衷: (1)让ArcView用户拥有ArcEditor甚至ArcIn ...
- ArcGIS统计栅格像元值并转换为矢量图层
很多时候,我们需要得到矢量数据区域所对应栅格数据的像元统计值(求平均.求和等),然后将获得的统计值赋给矢量图层的属性表,在ArcGIS中操作如下:(PS:第一次写技术文章,望大家多多体谅与支持,么么哒 ...
- 【ArcGIS笔记】数据处理
1.ARCGIS在导入Excel坐标点的时候出现"没有注册类"的情况怎么办? 确保你本机上装有office,并且版本要能够识别XLSX格式.2007以上. 2.导入excel时re ...
随机推荐
- Java +支付宝 +接入
说下业务场景, 公司之前的支付宝业务是PHP对接的现在改成 Java ,在接入出现不同的问题.之前PHP用的是老的移动支付, 现在Java的新接口 , 需要签约. 跟运维沟通好几次, 说签约不了, 只 ...
- python 筛选序列中的元素
列表生成式 a = [1, 2, 3, 4, -1, -2] b = [i for i in a if a > 0] 如果数据量很大,会产生一个庞大的结果.这时可以用生成器表达式: b = (i ...
- [COCI2019] Mobitel
题目 显然不小于\(n\)这个东西我们不是很好搞,考虑正难则反,求出有多少条路径小于\(n\),之后拿\(C_{n+m}^m\)一减就好了 于是状态为\(dp[i][j][k]\)表示到\((i,j) ...
- string主要操作函数
参考博客:http://blog.csdn.net/zhenyusoso/article/details/7286456 std::string illegal(" \t\f\v\n\r\\ ...
- 在ubuntu中安装phpstorm
安装参考网址 https://blog.csdn.net/mrgong_/article/details/77200225 注意:不需要安装java相关 激活phpstorm 2018 参考网址:ht ...
- Delphi 设计模式:《HeadFirst设计模式》Delphi7代码---迭代器模式之DinerMenu[转]
容器的主要职责有两个:存放元素和浏览元素.根据单一职责原则(SRP)要将二者分开,于是将浏览功能打包封装就有了迭代器. 用迭代器封装对动态数组的遍历: 1 2{<HeadFirst设计模式& ...
- Shell 工具之 sed
sed编辑器称为流编辑器(stream editor).可以根据输入命令行的命令或者存储在命令文本文件中的命令处理数据.每次从输入读取一行数据,将该数据与所提供的编辑器命令进行匹配,根据命令修改数据流 ...
- JDK配置环境变量 (JDK安装成功后进行配置)
"我的电脑" -- 右键"属性" --- "高级系统设置" --- “环境变量” 第一步:配置 JAVA_HOME 变量 找到 变量 ...
- oracle数据库忘记sys密码如何改密码
ORACLE服务器操作: 1.win+R打开dos窗口cmd 2.输入 sqlplus/nolog出现 3.输入 conn / as sysdba 出现 4. alter user sys ident ...
- Python学习之字典--三级菜单
效果图: 实现代码: dic = { '人物':{ '帽子':{'前年玄铁帽'}, '武器':{'屠龙宝刀'} }, '属性':{ '力量':{35}, '敏捷':{66} }, '任务':{ '主线 ...