Select to view content in your preferred language

Polygon not showing

2372
5
04-25-2014 10:11 AM
DiptiSheth
Emerging Contributor
Hi,

My polygon data is in following format coming from db

var thisLocs = new Array();
var thisLocs = [[174.605111568859, -37.119413675388707], [174.6051123299834, -37.119449718193458], [174.60515905129122, -37.119530204987136], [174.60540067619004, -37.119779304335452], [174.60554255499551, -37.120101860545844], [174.60568043759687, -37.120235191897571], [174.60572696965184, -37.1203066677341], [174.60572849253467, -37.120378753310746], [174.60570674933629, -37.120415100973361], [174.60560757225889, -37.120515590528086], [174.60554177129595, -37.120597601350227], [174.60549026791193, -37.120823630882519], [174.6054873903158, -37.121220253972716], [174.6055119446122, -37.122382633739591], [174.60513274122792, -37.119350295725816], [174.605111568859, -37.119413675388707]];

If I hard-code this:

var singleRingPolygon = new Polygon([[174.605111568859, -37.119413675388707], [174.6051123299834, -37.119449718193458], [174.60515905129122, -37.119530204987136], [174.60540067619004, -37.119779304335452], [174.60554255499551, -37.120101860545844], [174.60568043759687, -37.120235191897571], [174.60572696965184, -37.1203066677341], [174.60572849253467, -37.120378753310746], [174.60570674933629, -37.120415100973361], [174.60560757225889, -37.120515590528086], [174.60554177129595, -37.120597601350227], [174.60549026791193, -37.120823630882519], [174.6054873903158, -37.121220253972716], [174.6055119446122, -37.122382633739591], [174.60513274122792, -37.119350295725816], [174.605111568859, -37.119413675388707]]);
var gra = new Graphic(singleRingPolygon, sfs);
            map.graphics.add(gra);

It shows polygon.


But, if I pass it as var singleRingPolygon = new Polygon(thisLocs);

It does not show up polygon.

Please any body guide me..why its happening so.

I'm re-posting this question as I didn't get any positive answers yet.

Thanks,
Dipti Sheth
0 Kudos
5 Replies
MichaelVolz
Esteemed Contributor
Maybe you need to specify a spatial reference using the wkid of the basemap that you are using.
0 Kudos
RobertBurke
Esri Contributor
Since thisLocs is an Array(), do you need a [0] to get the first (and only) item in the array?

singleRingPolygon = new Polygon(thisLocs[0]);
Rob Burke
0 Kudos
DiptiSheth
Emerging Contributor
Maybe you need to specify a spatial reference using the wkid of the basemap that you are using.


Hi,

Thanks for your replies. I've tried both the things i.e. adding web mercator as well as adding  'new polygon(thisLocs[0])'
as thisLocs is an array. But, still it doesn't work.

Please find the attached file containing complete code here.

Please help me to find out the solution. Its really urgent.

Thanks a lot,

Dipti Sheth
0 Kudos
RobertBurke
Esri Contributor
Hi Dipti,

I worked up your code in a jsfiddle sample that appears to work using your variable defined as an array.

http://jsfiddle.net/QAeHM/1/

The polygon seems to draw.

Can you see where your code varies from mine?  May be in the Load area. 

Rob
Rob Burke
0 Kudos
DiptiSheth
Emerging Contributor
Hi Dipti,

I worked up your code in a jsfiddle sample that appears to work using your variable defined as an array.

http://jsfiddle.net/QAeHM/1/

The polygon seems to draw.

Can you see where your code varies from mine?  May be in the Load area. 

Rob




Hi Robert,

Many thanks for your reply. Yes, you are right, its load area where my code varies from yours.

Its not working on my side. I replaced my code with yours, but I guess may be due to load part i.e.

ready(function () {
     
            map.on("load", function (evt) {

it is not working.

Can you please tell me when ready() should be used?

In my app, ESRI maps should be loaded on calling of function LoadEsriTrees(), when a dropdown button 'Load ESRI Maps' is clicked. Can you please guide me further how to modify it as per my code?


Thanks a lot,
Dipti  Sheth
0 Kudos