function selectByCouncil() { var localCouncils = new FeatureLayer("feature layer with polygons", { mode: FeatureLayer.MODE_SNAPSHOT, outFields: ["*"] }); map.addLayer(localCouncils); var highlightSymbol = new SimpleFillSymbol( SimpleFillSymbol.STYLE_SOLID, new SimpleLineSymbol( SimpleLineSymbol.STYLE_SOLID, new Color([255, 0, 0]), 1), new Color([125, 125, 125, 0.35]) ); map.on("load", function () { map.graphics.enableMouseEvents(); }); localCouncils.on("click", function (evt) { map.graphics.clear(); var highlightGraphic = new Graphic(evt.graphic.geometry, highlightSymbol); map.graphics.add(highlightGraphic); var query = new Query(); var queryTask = new QueryTask(feature layer with points); query.geometry = evt.graphic.geometry; query.returnGeometry = true; var countOfFeatures = 0; queryTask.execute(query, function (results) { dojo.forEach(results.features, function (feature) { countOfFeatures++; }); alert("Number of points in polygon " + countOfFeatures); }); }); }
Solved! Go to Solution.
var polygonFeature= new FeatureLayer(my feature layer with polygons, { mode: FeatureLayer.MODE_ONDEMAND, outFields: ["*"] }); map.addLayer(polygonFeature); map.on("update-end", function(){ array.forEach(polygonFeature.graphics, function(feature){ var OID = feature.attributes.OBJECTID; var query = new Query(); var queryTask = new QueryTask("url to points"); query.geometry = feature.geometry query.returnGeometry = true; queryTask.executeForCount(query, function(count){ console.log("ObjectID " + OID + " has " + count + " points"); }) }) })
function showPolyVertices(graphic) { var geom = graphic.geometry; var output = ""; for (var ringNum = 0; ringNum < geom.rings.length; ringNum++) { output += "ring number: " + ringNum + "\n"; var ring = geom.rings[ringNum]; for (var vertexNum = 0; vertexNum < ring.length; vertexNum++) { var vertex = ring[vertexNum]; output += vertex[0] + ", " + vertex[1]; output += "\n"; } } alert(output); }
localCouncils.on("click", function (evt) { map.graphics.clear(); var highlightGraphic = new Graphic(evt.graphic.geometry, highlightSymbol); map.graphics.add(highlightGraphic); var query = new Query(); var queryTask = new QueryTask("feature layer with points"); query.geometry = evt.graphic.geometry; query.returnGeometry = true; queryTask.executeForCount(query, function(count){ alert(count); }) })
on(map, "load", selectByPolygon); function selectByPolygon() { var polygonFeature= new FeatureLayer(my feature layer with polygons, { mode: FeatureLayer.MODE_ONDEMAND, outFields: ["*"] }); map.addLayer(polygonFeature); polygonFeature.on("graphic-draw", function (evt) { var query = new Query(); var queryTask = new QueryTask(my feature layer with points); query.geometry = evt.graphic.geometry; query.returnGeometry = true; query.outSpatialReference = map.spatialReference; query.outFields = ["*"]; queryTask.execute(query, function (results) { console.log(results.features.length); }); }); }
var polygonFeature= new FeatureLayer(my feature layer with polygons, { mode: FeatureLayer.MODE_ONDEMAND, outFields: ["*"] }); map.addLayer(polygonFeature); map.on("update-end", function(){ array.forEach(polygonFeature.graphics, function(feature){ var OID = feature.attributes.OBJECTID; var query = new Query(); var queryTask = new QueryTask("url to points"); query.geometry = feature.geometry query.returnGeometry = true; queryTask.executeForCount(query, function(count){ console.log("ObjectID " + OID + " has " + count + " points"); }) }) })