0

ArcGIS を使用して単純なサークル バッファーを描画しようとして、行き詰まりました。ベースマップを設定する方法は次のとおりです。

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);
}

そこで、地図上に円のグラフィックを描画しようとする別の方法を次に示します。

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");
}

関数は実行されましたが、マップ上に円がプロットされず、エラー メッセージも表示されません。私の論理のどの部分が間違っていたのだろうか?

前もって感謝します。

4

2 に答える 2

1

API バージョン 3.8 には、このタスクのクラスが既にありますhttps://developers.arcgis.com/javascript/jsapi/circle-amd.htmlこのクラスを使用すると、測地円を描くこともできます。

于 2014-07-14T05:19:50.240 に答える