gpt4 book ai didi

javascript - ArcGIS 圆缓冲区

转载 作者:行者123 更新时间:2023-12-03 12:16:45 28 4
gpt4 key购买 nike

我被困住了,试图使用 ArcGIS 绘制一个简单的圆形缓冲区。以下是我设置 basemap 的方法:

dojo.require("esri.map");
dojo.require("esri.tasks.servicearea");
dojo.require("dijit.dijit");
dojo.require("dijit.layout.BorderContainer");
dojo.require("dijit.layout.ContentPane");
dojo.require("esri/layers/FeatureLayer");
dojo.require("esri/symbols/SimpleMarkerSymbol");

var mapLayers = new Array();
var map;
var GL = null;

function setMap() {
function init() {
require(
[
"esri/map",
"dojo/dom-construct",
"dojo/domReady!",
"esri/tasks/GeometryService"
],
function
(
Map,
domConstruct
) {
map = Map("map-canvas",
{
//infoWindow: popup
});
map.setZoom(1);
coreFunctions();
});

}
dojo.ready(init);
dojo.connect(map, "onClick", addCircle);
}

function coreFunctions() {
try {
addLayersToMap();
}
catch (err) {
console.log(err);
}
}
function addLayersToData() {
var layer = new esri.layers.ArcGISTiledMapServiceLayer("https://www.onemap.sg/ArcGIS/rest/services/BASEMAP/MapServer");
mapLayers.push(layer);
var layer2 = new esri.layers.ArcGISTiledMapServiceLayer("http://www.onemap.sg/ArcGIS/rest/services/LOT_VIEW/MapServer");
mapLayers.push(layer2);
layer2.hide();
}

function addLayersToMap() {
addLayersToData();
for (var a = 0; a < mapLayers.length; a++) {
map.addLayer(mapLayers[a]);
}
map.setZoom(1);
}

所以这是我尝试在 map 上绘制圆形图形的另一种方法:

function addCircle(e) {
sym = new esri.symbol.SimpleFillSymbol().setColor(new dojo.Color([180, 0, 180, 1.0]));

console.log("clicked the map: ", e);
var pt, radius, circle, ring, pts, angle;

pt = e.mapPoint;
circle = new esri.geometry.Polygon(map.spatialReference);
ring = []; // point that make up the circle
pts = 40; // number of points on the circle
angle = 360 / pts; // used to compute points on the circle
for (var i = 1; i <= pts; i++) {
// convert angle to raidans
var radians = i * angle * Math.PI / 180;;
// add point to the circle
ring.push([pt.x + radius * Math.cos(radians), pt.y + radius * Math.sin(radians)]);
console.log(ring[i]);
}
ring.push(ring[0]); // start point needs to == end point
circle.addRing(ring);
map.graphics.add(new esri.Graphic(circle, sym));
console.log("added a graphic");
}

它确实执行了该函数,但 map 上没有绘制圆圈,也没有错误消息。我想知道我的哪一部分逻辑出了问题?

提前致谢。

最佳答案

在 API 版本 3.8 中,已经有一个用于此任务的类 https://developers.arcgis.com/javascript/jsapi/circle-amd.html通过这个类,您甚至可以绘制测地线圆。

关于javascript - ArcGIS 圆缓冲区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24654704/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com