ArcGIS javascript API中,怎么得到graphic 中的point?
1个回答
2016-03-13 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
关注
展开全部
ArcGIS javascript API中得到graphic中的point的方法:
思路:利用arcgis中的点阵队列,定义一个坐标,最后映射成一个point就就取到值了。
参考代码如下:
<!DOCTYPE html>
<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>Points in Extent</title>
<link rel="stylesheet" href="js.arcgis.com/3.16/dijit/themes/claro/claro.css">
<link rel="stylesheet" href="js.arcgis.com/3.16/esri/css/esri.css">
<script src="js.arcgis.com/3.16/"></script> //引入js.arcgis.com
<script>
dojo.require("esri.map");
dojo.require("esri.toolbars.draw");
dojo.require("esri.tasks.query");
//全局变量
var map, defaultSymbol, highlightSymbol, resultTemplate;
function init() {
//创建map,设置初始值并且阻止window默认行为
map = new esri.Map("map", {
basemap: "streets",
center: [-120.275, 47.485],
zoom: 6,
slider: false,
showInfoWindowOnClick:false
});
dojo.connect(map, "onLoad", initToolbar);
//初始化symbology
defaultSymbol = new esri.symbol.SimpleMarkerSymbol().setColor(new dojo.Color([0,0,255]));
highlightSymbol = new esri.symbol.SimpleMarkerSymbol().setColor(new dojo.Color([255,0,0]));
//执行查询
var queryTask = new esri.tasks.QueryTask("sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer/0");
var query = new esri.tasks.Query();
query.where = "STATE_NAME = 'Washington'";
query.outSpatialReference = {wkid:102100};
query.returnGeometry = true;
query.outFields = ["CITY_NAME"];
queryTask.execute(query, addPointsToMap);
//获取point后返回
resultTemplate = new esri.InfoTemplate("City", "<tr><td>${CITY_NAME}</tr></td>");
}
//初始化drawing bar
function initToolbar(map) {
var tb = new esri.toolbars.Draw(map);
//find points in Extent when user completes drawing extent
dojo.connect(tb, "onDrawEnd", findPointsInExtent);
//set drawing mode to extent
tb.activate(esri.toolbars.Draw.EXTENT);
}
//add points to map and set their symbology + info template
function addPointsToMap(featureSet) {
dojo.forEach(featureSet.features,function(feature){
map.graphics.add(feature.setSymbol(defaultSymbol).setInfoTemplate(resultTemplate));
});
}
//显示点数
dojo.byId("inextent").innerHTML = results.length;
//显示所有的点列表
dojo.byId("results").innerHTML = "<table><tbody>" + results.join("") + "</tbody></table>";
}
dojo.addOnLoad(init);
</script>
</head>
<body class="claro">
Draw an Extent on the map to find all points within this extent
<div id="map" style="width:800px; height:400px; border:1px solid #000;"></div>
<br />
<b># of points in extent = <span id="inextent">0</span></b>
<div id="results" style="width:400px; height:200px; border:1px solid #000; overflow:auto;">
</div>
</body>
</html>
思路:利用arcgis中的点阵队列,定义一个坐标,最后映射成一个point就就取到值了。
参考代码如下:
<!DOCTYPE html>
<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>Points in Extent</title>
<link rel="stylesheet" href="js.arcgis.com/3.16/dijit/themes/claro/claro.css">
<link rel="stylesheet" href="js.arcgis.com/3.16/esri/css/esri.css">
<script src="js.arcgis.com/3.16/"></script> //引入js.arcgis.com
<script>
dojo.require("esri.map");
dojo.require("esri.toolbars.draw");
dojo.require("esri.tasks.query");
//全局变量
var map, defaultSymbol, highlightSymbol, resultTemplate;
function init() {
//创建map,设置初始值并且阻止window默认行为
map = new esri.Map("map", {
basemap: "streets",
center: [-120.275, 47.485],
zoom: 6,
slider: false,
showInfoWindowOnClick:false
});
dojo.connect(map, "onLoad", initToolbar);
//初始化symbology
defaultSymbol = new esri.symbol.SimpleMarkerSymbol().setColor(new dojo.Color([0,0,255]));
highlightSymbol = new esri.symbol.SimpleMarkerSymbol().setColor(new dojo.Color([255,0,0]));
//执行查询
var queryTask = new esri.tasks.QueryTask("sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer/0");
var query = new esri.tasks.Query();
query.where = "STATE_NAME = 'Washington'";
query.outSpatialReference = {wkid:102100};
query.returnGeometry = true;
query.outFields = ["CITY_NAME"];
queryTask.execute(query, addPointsToMap);
//获取point后返回
resultTemplate = new esri.InfoTemplate("City", "<tr><td>${CITY_NAME}</tr></td>");
}
//初始化drawing bar
function initToolbar(map) {
var tb = new esri.toolbars.Draw(map);
//find points in Extent when user completes drawing extent
dojo.connect(tb, "onDrawEnd", findPointsInExtent);
//set drawing mode to extent
tb.activate(esri.toolbars.Draw.EXTENT);
}
//add points to map and set their symbology + info template
function addPointsToMap(featureSet) {
dojo.forEach(featureSet.features,function(feature){
map.graphics.add(feature.setSymbol(defaultSymbol).setInfoTemplate(resultTemplate));
});
}
//显示点数
dojo.byId("inextent").innerHTML = results.length;
//显示所有的点列表
dojo.byId("results").innerHTML = "<table><tbody>" + results.join("") + "</tbody></table>";
}
dojo.addOnLoad(init);
</script>
</head>
<body class="claro">
Draw an Extent on the map to find all points within this extent
<div id="map" style="width:800px; height:400px; border:1px solid #000;"></div>
<br />
<b># of points in extent = <span id="inextent">0</span></b>
<div id="results" style="width:400px; height:200px; border:1px solid #000; overflow:auto;">
</div>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询