user903772 user903772 - 1 year ago 93
Javascript Question

948ESRI Javascript polygon

I am using esri javascript 3.5. I have a list of points that I want to draw it into a polyon. I found this but I don't know how to use it. Can I know where I can get a sample? Say I have a array of points...


var map ;
function init() {
map = new esri.Map("map",{
center:[103.8, 1.35], //long, lat
dojo.connect(map,"onLoad", loadData);
}//end init
function loadData(){
var arr =[];
var p = new esri.geometry.Point(103.8, 1.35);
p = new esri.geometry.Point(103.8, 1.35222);
var polySymbolRed = new esri.symbol.SimpleFillSymbol(
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);;


Answer Source

You're very close, you just need to massage that array a bit before creating the .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


var gra = new esri.Graphic(poly,polySymbolRed);
//var gra = new esri.Graphic(esri.geometry.geographicToWebMercator(poly),polySymbolRed);
//depending on what SR your map is using...
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download