selected_Poly = response.features.geometry; //.rings[0];
var polygonSymbol = new esri.symbol.SimpleFillSymbol(
esri.symbol.SimpleFillSymbol.STYLE_SOLID, // or "solid",
new esri.symbol.SimpleLineSymbol("solid", new esri.Color([232, 104, 80]), 2),
new esri.Color([232, 104, 80, 0.25])
);
var graphic = new esri.Graphic(selected_Poly, polygonSymbol); // got attributes, geometry, and symbol null value; what is wrong here? Thanks.
graphic.setSymbol(polygonSymbol);
...
also in debugging
selected_Poly.contains(new esri.geometry.Point([-76.99, 38.88]))
got Object doesn't support property or method 'contains'
where
selected_ContractSection.rings
[-8574575.3238,4706898.530699998,-8574717.6555,4706897.306000002,-8574736.575,4706897.310400002,-8575245.9761,4706912.5276999995,-8575227.622,4707114.234399997,-8575227.5562,4707119.869999997,-8575219.9439,4707238.998999998,-8574736.4339,4707222.973899998,-8574717.4695,4707222.967699997,-8574503.5524,4707224.6489999965,-8574507.9585,4707120.172899999,-8574507.9603,4707114.672899999,-8574535.2586,4706976.1853,-8574575.3238,4706898.530699998]
__proto__: []
length: 1
[0]: [...]
Shaning,
Can you check the instance of selected_Poly using this code?
console.log(selected_Poly instanceof esri.geometry.Polygon);
Should come back as true.
Got selected_Poly != esri.geometry.Polygon. The I tried
var ar2D = new Array();
for (var j=0; j < selected_Poly.length; j++) {
var ar1D = [ selected_Poly
ar2D.push(ar1D);
}
polygon = new esri.geometry.Polygon();
polygon.addRing(ar2D);
Then, I checked the polygon object:
polygon
_ring: 0
cache: undefined
rings: [-8574575.3238,4706898.530699998,-8574717.6555,4706897.306000002,......]
spatialReference: {...}
type: "polygon"
However, still get
polygon.geometry != esri.geometry.Polygon
What's wrong in my code? Thanks.
Shaning,
What is the WKID of your data?
wkid=102100
Shaning,
You are still using Legacy style of coding verses AMD which is what you really should be using in today's day and age (Legacy style of coding is not even supported in JS 4.x api). Here is a very simple sample that shows the contains method. Also you will notice that I have used some of your polygon coordinates with wkid 102100 and they do not plot on the map. So I am not sure your data is 102100.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
<title>Polygon Contains</title>
<link rel="stylesheet" href="https://js.arcgis.com/3.23/dijit/themes/claro/claro.css">
<link rel="stylesheet" href="https://js.arcgis.com/3.23/esri/css/esri.css">
<style>
html, body, #map {
height:100%;
margin: 0;
padding: 0;
width:100%;
overflow:hidden;
}
</style>
<script src="https://js.arcgis.com/3.23/"></script>
<script>
var map, editToolbar, ctxMenuForGraphics, ctxMenuForMap;
var selected, currentLocation;
require([
"esri/map", "esri/geometry/Point", "esri/geometry/Polygon",
"esri/symbols/SimpleLineSymbol",
"esri/symbols/SimpleFillSymbol",
"esri/graphic",
"esri/Color",
"esri/tasks/query", "esri/tasks/QueryTask",
"dojo/domReady!"
], function(
Map, Point, Polygon,
SimpleLineSymbol,
SimpleFillSymbol,
Graphic,
Color,
query,
QueryTask
) {
map = new Map("map", {
basemap: "satellite",
center: [20.039, 62.739],
zoom: 3
});
map.on("load", addGraphics);
function addGraphics() {
// Adds pre-defined geometries to map
var polygonSymbol = new SimpleFillSymbol(
SimpleFillSymbol.STYLE_SOLID,
new SimpleLineSymbol(
SimpleLineSymbol.STYLE_DOT,
new Color([151, 249, 0, 0.8]),
3
),
new Color([151, 249, 0, 0.45])
);
var polygon = new Polygon({
"rings": [
[
[-4226661.916056009, 8496372.808143634],
[-3835304.3312360067, 8731187.359035634],
[-2269873.991956003, 9005137.668409634],
[-1213208.5129420012, 8613780.083589634],
[-1017529.7205320001, 8065879.464841632],
[-1213208.5129420012, 7478843.087611631],
[-2230738.233474003, 6891806.710381631],
[-2935181.8861500043, 6735263.6764536295],
[-3522218.263380006, 6891806.710381631],
[-3952711.606682008, 7165757.01975563],
[-4265797.674538009, 7283164.295201631],
[-4304933.433020009, 7635386.121539632],
[-4304933.433020009, 7674521.880021632],
[-4226661.916056009, 8496372.808143634]
]
],
"spatialReference": {
"wkid": 102100
}
});
var spolygon = new Polygon({
"rings": [
[
[-8574575.3238, 4706898.530699998],
[-8574717.6555, 4706897.306000002],
[-8574736.575, 4706897.310400002],
[-8575245.9761, 4706912.5276999995],
[-8575227.622, 4707114.234399997],
[-8575227.5562, 4707119.869999997],
[-8575219.9439, 4707238.998999998],
[-8574736.4339, 4707222.973899998],
[-8574717.4695, 4707222.967699997],
[-8574503.5524, 4707224.6489999965],
[-8574507.9585, 4707120.172899999],
[-8574507.9603, 4707114.672899999],
[-8574535.2586, 4706976.1853],
[-8574575.3238, 4706898.530699998]
]
],
"spatialReference": {
"wkid": 102100
}
});
map.graphics.add(new Graphic(polygon, polygonSymbol));
map.graphics.add(new Graphic(spolygon, polygonSymbol));
console.info(polygon.contains(new Point([-76.99, 38.88])));
}
});
</script>
</head>
<body class="claro">
<div id="map"></div>
</body>
</html>
GREAT HELP! Thanks a LOT!!!
Rebert: Got an additional prob. (see my email to you). Could you take a look? Thanks.