-1

I'm using ESRI JavaScript API 3.5. My polygon cannot load. Please help.

  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);
   }  
  • 6
    Your polygon has fewer than 3 vertices, and is therefore not a polygon – tomfumb Jul 28 '13 at 1:25
3

What you want to draw, isn't a polygon, it's a polyline! Like tomfumb already said, a polygon needs at least 3 vertices.

There are two solutions: 1. Add at least a 3 vertex, everything should work then. 2. Draw a polyline instead of the polygon:

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 polyline = new esri.geometry.Polyline(new esri.SpatialReference({wkid:4326}));
     polyline.addPath([new esri.geometry.Point(103.8, 1.35), 
          new esri.geometry.Point(103.8, 1.35222);]);      

     var polylineSymbol = new esri.symbol.SimpleLineSymbol(
     esri.symbol.SimpleLineSymbol.STYLE_SOLID, 
     new dojo.Color([0,0,0]), 1);  

     var gra = new esri.Graphic(polyline, polylineSymbol);
     map.graphics.add(gra);
   }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.