Hi everybody!
I have a function which takes the XY coordinates from a point layer and then passes those coordinates to a couple of variables. Those values are then assigned to other values which compute 4 coordinate pairs which are meant to be used as a list of coordinates to a create polygon via the esri/geometry/Polygon module.
Passing the values works like a charm and the additional variables are all defined. In fact the entire code runs, but it doesn't produce the desired results which is a square.
Side note: I know it's the variables because if I assign some hard numeric values to the addPoly function and not the variables the desired polygon will be produced. Thanks for your time!
Cz
function addPoly(){
//assign values to the square coordinates
var x1 = Number(xpoint + 201.168);
var y1 = Number(ypoint + 201.168);
var x2 = Number(xpoint + 201.168);
var y2 = Number(ypoint - 201.168);
var x3 = Number(xpoint - 201.168);
var y3 = Number(ypoint - 201.168);
var x4 = Number(xpoint - 201.168);
var y4 = Number(ypoint + 201.168);
//check to see if values were assigned
alert("Your values are " + x1 + " " + y1);
//add polygon symbology
var polySymbol = new SimpleFillSymbol().setColor(null).outline.setColor("blue");
var polyLineSymbol = new SimpleLineSymbol();
var polygon = new Polygon({
"rings": [
[
[y1, x1],
[y2, x2],
[y3, x3],
[y4, x4],
[y1, x1]
]
],
"spatialReference": {
"wkid": 102100
}
});
alert("graphic should add next");
map.graphics.add(new Graphic(polygon, polySymbol));
};