AnsweredAssumed Answered

Adding Polygon

Question asked by meenu.monu on Oct 11, 2015
Latest reply on Oct 12, 2015 by meenu.monu

Hi all, Thank U.

 

I am trying to add a polygon in a button click.The below code wrote in button click.But the polygon not showing. If I will pass some points direct like this then it is working perfect.Where is the problem??

polygon1.addRing([[58.4245719470205, 23.582511030118049], [58.423799470824214, 23.594545845196812],[58.44002147094627, 23.5743298721676], [58.443798021239232, 23.578735174416867], [58.4245719470205, 23.582511030118049]]);

 

while (CMt <= (list.d.length - 1))

{

                                

                                    if (Points1 != "") {

                                        Points1 = Points1 + ",";

                                    }

                                    Points1 = Points1 + "[" + list.d[CMt].EPolyLong + "," + list.d[CMt].EPolyLat + "]";

                                    gname = list.d[CMt].EPolyGname;

                                    GDesc = list.d[CMt].EPolyGDesc;

                                    CMt = CMt + 1;

                                };

 

                                if( Points1 != "")

                                {

                                    AddPolygonGraphics(Points1, gname, GDesc);

                                    Points1 = "";

                                }

 

 

            function AddPolygonGraphics(Points1, gname, GDesc) {

                Points1 = "[" + Points1 + "]"

                var polygon1 = new Polygon(new SpatialReference({ wkid: 4326 }));

                 //polygon1.addRing([[58.4245719470205, 23.582511030118049], [58.423799470824214, 23.594545845196812],[58.44002147094627, 23.5743298721676], [58.443798021239232, 23.578735174416867], [58.4245719470205, 23.582511030118049]]);

                polygon1.addRing(Points1);

//                alert(polygon1.rings[0].length);

                // map is in web mercator so transform the geometry 

                var poly_wm = webMercatorUtils.geographicToWebMercator(polygon1);

                var symbol = new SimpleFillSymbol();

                var strhotspot = (gname.trim());

                if (GDesc != "")

                {

                    strhotspot = strhotspot + "," + (GDesc.trim());

                }

                var infoTemplate = new InfoTemplate();

                infoTemplate.content = strhotspot;

                var graphic = new Graphic(poly_wm, symbol);

                graphic.setInfoTemplate(infoTemplate);

                MyGraphicsLayerGL.add(graphic);

                mapDiv.style.visibility = "visible";

                DivesriLogoImage.style.visibility = "hidden";

             

 

            }

Outcomes