948ESRI Javascript多边形

时间:2013-07-27 10:35:45

标签: javascript arcgis esri arcgis-js-api

我正在使用esri javascript 3.5。我有一个点列表,我想把它绘制成一个多边形。我找到了https://developers.arcgis.com/en/javascript/jssamples/util_relation.html,但我不知道如何使用它。我可以知道在哪里可以获得样品吗?说我有一系列要点......

     dojo.require("esri.map");
  dojo.require("esri.graphic");

  var map ; 
  function init() {
     map = new esri.Map("map",{
      basemap:"topo",
      center:[103.8, 1.35], //long, lat
      zoom:13
    });
                dojo.connect(map,"onLoad", loadData);
  }//end init
  function loadData(){
     var arr =[];
var p = new esri.geometry.Point(103.8, 1.35);
arr.push(p);
p = new esri.geometry.Point(103.8, 1.35222);
arr.push(p);
var polySymbolRed = new esri.symbol.SimpleFillSymbol(
                esri.symbol.SimpleLineSymbol.STYLE_SOLID,
                new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID,
                new dojo.Color([0, 0, 0, 1]), 1),
                new dojo.Color([255, 0, 0, 0.2])
        );

var gra = new esri.Graphic(arr,polySymbolRed);
map.graphics.add(gra);


  }

2 个答案:

答案 0 :(得分:1)

你非常接近,你只需要在创建.Graphic之前按一下该阵列:

var poly = new esri.geometry.Polygon({
                "spatialReference": {" wkid":4326 },
                "fields": [{
                    "name": "FID",
                    "type": "esriFieldTypeOID",
                    "alias": "FID",
                    "domain": null          
                },...]
            });
var ring = new Array();

//push points into array

poly.addRing(ring);

var gra = new esri.Graphic(poly,polySymbolRed);
//Maybe:
//var gra = new esri.Graphic(esri.geometry.geographicToWebMercator(poly),polySymbolRed);
//depending on what SR your map is using...

答案 1 :(得分:-1)

var polygon = new Polygon(new SpatialReference({wkid:4326}));
polygon.addRing([[-120,30],[-120,40],[-110,40],[-110,30],[-120,30]])

var point = new Point(-115, 35, {"spatialReference":{"wkid":4326 }})
polygon.contains(point); //returns true